Skip to content

Commit 34ad0d0

Browse files
authored
fix: export sendmessage function (#7)
1 parent 618ed26 commit 34ad0d0

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
1313
with:
1414
os: 'ubuntu-latest, macos-latest, windows-latest'
15-
version: '18.19.0, 18, 20, 22'
15+
version: '16, 18.19.0, 18, 20, 22'
1616
secrets:
1717
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ coverage/
1717
.tshy*
1818
.eslintcache
1919
dist
20+
package-lock.json

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ npm install sendmessage --save
2727

2828
```ts
2929
import { fork } from 'node:child_process';
30-
import sendmessage from 'sendmessage';
30+
import { sendmessage } from 'sendmessage';
3131

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

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

3939
```ts
40-
import sendmessage from 'sendmessage';
40+
import { sendmessage } from 'sendmessage';
4141

4242
sendmessage(process, { hello: 'this is a message to master' });
4343
```

package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
"ci": "c8 -r lcov -r text -r text-summary npm test",
1313
"prepublishOnly": "tshy && tshy-after"
1414
},
15-
"dependencies": {},
1615
"devDependencies": {
17-
"@arethetypeswrong/cli": "^0.15.3",
16+
"@arethetypeswrong/cli": "^0.17.1",
1817
"@eggjs/tsconfig": "1",
1918
"@types/mocha": "10",
20-
"@types/node": "20",
19+
"@types/node": "22",
2120
"c8": "^10.1.2",
2221
"eslint": "8",
23-
"eslint-config-egg": "13",
22+
"eslint-config-egg": "14",
2423
"mm": "3",
25-
"mocha": "^10.4.0",
26-
"tshy": "1",
24+
"mocha": "^11.0.1",
25+
"tshy": "^3.0.2",
2726
"tshy-after": "1",
2827
"typescript": "5"
2928
},
@@ -54,12 +53,10 @@
5453
"exports": {
5554
".": {
5655
"import": {
57-
"source": "./src/index.ts",
5856
"types": "./dist/esm/index.d.ts",
5957
"default": "./dist/esm/index.js"
6058
},
6159
"require": {
62-
"source": "./src/index.ts",
6360
"types": "./dist/commonjs/index.d.ts",
6461
"default": "./dist/commonjs/index.js"
6562
}
@@ -71,5 +68,6 @@
7168
"src"
7269
],
7370
"types": "./dist/commonjs/index.d.ts",
74-
"main": "./dist/commonjs/index.js"
71+
"main": "./dist/commonjs/index.js",
72+
"module": "./dist/esm/index.js"
7573
}

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ export default function sendmessage(child: ChildProcessOrWorker, message: unknow
6868
console.warn('[%s][sendmessage] WARN pid#%s channel closed, nothing send\nstack: %s',
6969
Date(), pid, err.stack);
7070
}
71+
72+
export { sendmessage };

test/sendmessage.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import childprocess from 'node:child_process';
55
import cluster from 'node:cluster';
66
import workerThreads from 'node:worker_threads';
77
import mm from 'mm';
8-
import sendmessage from '../dist/esm/index.js';
8+
import sendmessage, { sendmessage as sendmessage2 } from '../dist/esm/index.js';
99

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

38-
sendmessage(child, {
38+
sendmessage2(child, {
3939
from: 'master',
4040
reply: 'this is a reply message send to child',
4141
});

0 commit comments

Comments
 (0)