diff --git a/.gitignore b/.gitignore index aad1f5f..ed02cfe 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ coverage/ .tshy* .eslintcache dist +package-lock.json diff --git a/README.md b/README.md index 2573058..6309c57 100644 --- a/README.md +++ b/README.md @@ -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'); @@ -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' }); ``` diff --git a/package.json b/package.json index a3d004c..5d6f559 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } @@ -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" } diff --git a/src/index.ts b/src/index.ts index c8ae5aa..f58101d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 }; diff --git a/test/sendmessage.test.js b/test/sendmessage.test.js index 194f5ca..8dd24f5 100644 --- a/test/sendmessage.test.js +++ b/test/sendmessage.test.js @@ -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); @@ -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', });