Skip to content

Commit

Permalink
fix: export sendmessage function (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Dec 11, 2024
1 parent 618ed26 commit 34ad0d0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
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: '18.19.0, 18, 20, 22'
version: '16, 18.19.0, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ coverage/
.tshy*
.eslintcache
dist
package-lock.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ npm install sendmessage --save

```ts
import { fork } from 'node:child_process';
import sendmessage from 'sendmessage';
import { sendmessage } from 'sendmessage';

const worker = fork('./worker.js');

Expand All @@ -37,7 +37,7 @@ sendmessage(worker, { hi: 'this is a message to worker' });
### worker.js

```ts
import sendmessage from 'sendmessage';
import { sendmessage } from 'sendmessage';

sendmessage(process, { hello: 'this is a message to master' });
```
Expand Down
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
"ci": "c8 -r lcov -r text -r text-summary npm test",
"prepublishOnly": "tshy && tshy-after"
},
"dependencies": {},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/tsconfig": "1",
"@types/mocha": "10",
"@types/node": "20",
"@types/node": "22",
"c8": "^10.1.2",
"eslint": "8",
"eslint-config-egg": "13",
"eslint-config-egg": "14",
"mm": "3",
"mocha": "^10.4.0",
"tshy": "1",
"mocha": "^11.0.1",
"tshy": "^3.0.2",
"tshy-after": "1",
"typescript": "5"
},
Expand Down Expand Up @@ -54,12 +53,10 @@
"exports": {
".": {
"import": {
"source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"source": "./src/index.ts",
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
Expand All @@ -71,5 +68,6 @@
"src"
],
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js"
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js"
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ export default function sendmessage(child: ChildProcessOrWorker, message: unknow
console.warn('[%s][sendmessage] WARN pid#%s channel closed, nothing send\nstack: %s',
Date(), pid, err.stack);
}

export { sendmessage };
4 changes: 2 additions & 2 deletions test/sendmessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import childprocess from 'node:child_process';
import cluster from 'node:cluster';
import workerThreads from 'node:worker_threads';
import mm from 'mm';
import sendmessage from '../dist/esm/index.js';
import sendmessage, { sendmessage as sendmessage2 } from '../dist/esm/index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('sendmessage.test.js', () => {
hi: 'this is a message send to master',
});

sendmessage(child, {
sendmessage2(child, {
from: 'master',
reply: 'this is a reply message send to child',
});
Expand Down

0 comments on commit 34ad0d0

Please sign in to comment.