Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '16, 18.19.0, 18, 20, 22'
version: '16, 18.19.0, 18, 20, 22, 24'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
12 changes: 9 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ on:
push:
branches: [ master ]

permissions:
contents: write
deployments: write
issues: write
pull-requests: write
id-token: write

jobs:
release:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
name: NPM Release
uses: node-modules/github-actions/.github/workflows/npm-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NPM_TOKEN secret was removed but may still be required by the npm-release workflow. Verify that the new workflow doesn't need NPM authentication or ensure the token is passed through a different mechanism.

Suggested change
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Copilot uses AI. Check for mistakes.
22 changes: 19 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { debuglog } from 'node:util';
import { isMainThread, parentPort } from 'node:worker_threads';
import { EventEmitter } from 'node:events';
import cluster from 'node:cluster';

const debug = debuglog('sendmessage');

Expand Down Expand Up @@ -54,11 +55,26 @@ export default function sendmessage(child: ChildProcessOrWorker, message: unknow
}

// cluster.fork(): child.process is process
if (child.process?.connected) {
debug('child is cluster.fork() process, send: %j', message);
return child.send!(message);
}

// childprocess.fork(): child is process
const connected = child.process ? child.process.connected : child.connected;
if (child.connected) {
debug('child.connected: %s, cluster.isWorker: %s', child.connected, cluster.isWorker);
if (cluster.isWorker) {
debug('child is cluster.fork() process, send: %j', message);
return child.send!(message);
}

if (connected) {
debug('child is process, send: %j', message);
if (process.env.VITEST === 'true' && process.env.VITEST_WORKER_ID) {
debug('child is vitest worker process, VITEST_WORKER_ID: %s, emit sendmessage-to-self: %j',
process.env.VITEST_WORKER_ID, message);
// use `sendmessage-to-self` event to send message to self, avoid vitest worker use the `message` event
return setImmediate(child.emit.bind(child, 'sendmessage-to-self', message));
}
debug('child is childprocess.fork() process, send: %j', message);
return child.send!(message);
}

Expand Down
Loading