{"name":"sendmessage","version":"3.0.0","engines":{"node":">= 18.19.0"},"description":"Send a cross process message if message channel is connected.","scripts":{"lint":"eslint --cache src --ext .ts","pretest":"npm run prepublishOnly && attw --pack","test":"npm run lint && mocha --exit -t 5000 test/*.test.js","ci":"c8 -r lcov -r text -r text-summary npm test","prepublishOnly":"tshy && tshy-after"},"dependencies":{},"devDependencies":{"@arethetypeswrong/cli":"^0.15.3","@eggjs/tsconfig":"1","@types/mocha":"10","@types/node":"20","c8":"^10.1.2","eslint":"8","eslint-config-egg":"13","mm":"3","mocha":"^10.4.0","tshy":"1","tshy-after":"1","typescript":"5"},"homepage":"https://github.com/node-modules/sendmessage","repository":{"type":"git","url":"git://github.com/node-modules/sendmessage.git"},"bugs":{"url":"https://github.com/node-modules/sendmessage/issues"},"keywords":["sendmessage","send","cluster","message","channel closed"],"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"},"license":"MIT","type":"module","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"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"}},"./package.json":"./package.json"},"types":"./dist/commonjs/index.d.ts","main":"./dist/commonjs/index.js","_id":"sendmessage@3.0.0","gitHead":"618ed26c0cf908434d18140ffc5300df76834bdd","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-09rAtW1NAYSw3QFEMJiBjzQCo6wssqw8xW7r7wNQB1BDSQt14wrJMuJYqmO0Xn+k1Tr5yWY3ckpnhSjlvAAmlw==","shasum":"ff816fc9183a5f17aa7b3d60c20b331de822329a","tarball":"http://registry-npm.ywwl.com/sendmessage/download/sendmessage-3.0.0.tgz","fileCount":10,"unpackedSize":17770,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/sendmessage@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+yTATGakpMs4S061knfIni5XmFfkRptCXNS3kv8K4QAIgaByV5HeLYVv/grk80aTMJFxlBWjuukPTbdxwaLAECpI="}],"size":4845,"noattachment":false,"key":"/sendmessage/-/sendmessage-3.0.0.tgz"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sendmessage_3.0.0_1719160308612_0.4524045958336569"},"_hasShrinkwrap":false,"readme":"# sendmessage\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/node-modules/sendmessage/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/sendmessage/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/sendmessage.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/sendmessage\n[download-image]: https://img.shields.io/npm/dm/sendmessage.svg?style=flat-square\n[download-url]: https://npmjs.org/package/sendmessage\n[codecov-image]: https://codecov.io/gh/node-modules/sendmessage/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/node-modules/sendmessage\n\nSend a cross process message if message channel is connected.\nAvoid [channel closed](https://github.com/joyent/node/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/child_process.js#L411) error throw out.\n\n## Install\n\n```bash\nnpm install sendmessage --save\n```\n\n## Usage\n\n### master.js\n\n```ts\nimport { fork } from 'node:child_process';\nimport sendmessage from 'sendmessage';\n\nconst worker = fork('./worker.js');\n\nsendmessage(worker, { hi: 'this is a message to worker' });\n```\n\n### worker.js\n\n```ts\nimport sendmessage from 'sendmessage';\n\nsendmessage(process, { hello: 'this is a message to master' });\n```\n\n## API\n\n### #sendmessage(childProcess, message)\n\nSend a cross process message.\nIf a process is not child process, this will just call `process.emit('message', message)` instead.\n\n- childProcess: child process instance\n- message: the message need to send\n\n```js\nsendmessage(process, { hello: 'this is a message to master' });\n```\n\nYou can switch to `process.emit('message', message)` using `process.env.SENDMESSAGE_ONE_PROCESS`\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=node-modules/sendmessage)](https://github.com/node-modules/sendmessage/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1719160308786,"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"}],"_cnpm_publish_time":1719160308786,"dist-tags":{"latest":"3.0.2"}}