{"_id":"sync-child-process","_rev":"3985104","name":"sync-child-process","description":"Run a subprocess synchronously and interactively in Node.js","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"nex3","email":"nex342@gmail.com"}],"time":{"modified":"2025-09-01T02:04:16.000Z","created":"2024-10-31T22:17:41.774Z","1.0.2":"2024-11-04T21:03:32.727Z","1.0.1":"2024-11-04T20:28:35.172Z","1.0.0":"2024-10-31T22:17:41.774Z"},"users":{},"author":{"name":"Google Inc."},"repository":{"type":"git","url":"git+https://github.com/sass/sync-child-process.git"},"versions":{"1.0.2":{"name":"sync-child-process","version":"1.0.2","description":"Run a subprocess synchronously and interactively in Node.js","repository":{"type":"git","url":"git+https://github.com/sass/sync-child-process.git"},"author":{"name":"Google Inc."},"license":"MIT","exports":{"types":"./dist/lib/index.d.ts","default":"./dist/lib/index.js"},"main":"dist/lib/index.js","types":"dist/lib/index.d.ts","engines":{"node":">=16.0.0"},"scripts":{"check":"npm-run-all check:gts check:tsc","check:gts":"gts check","check:tsc":"tsc --noEmit","clean":"gts clean","compile":"tsc -p tsconfig.build.json","doc":"typedoc lib/index.ts","fix":"gts fix","test":"jest"},"devDependencies":{"@types/jest":"^29.4.0","@types/node":"^22.0.0","gts":"^6.0.2","jest":"^29.4.1","npm-run-all":"^4.1.5","ts-jest":"^29.0.5","ts-node":"^10.2.1","typedoc":"^0.26.11","typescript":"^5.0.2"},"dependencies":{"sync-message-port":"^1.0.0"},"_id":"sync-child-process@1.0.2","gitHead":"a1924b347d16dd49c40993480c9726772697b1c1","bugs":{"url":"https://github.com/sass/sync-child-process/issues"},"homepage":"https://github.com/sass/sync-child-process#readme","_nodeVersion":"22.11.0","_npmVersion":"10.9.0","dist":{"shasum":"45e7c72e756d1243e80b547ea2e17957ab9e367f","size":19391,"noattachment":false,"key":"/sync-child-process/-/sync-child-process-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/sync-child-process/download/sync-child-process-1.0.2.tgz"},"_npmUser":{"name":"nex3","email":"nex342@gmail.com"},"directories":{},"maintainers":[{"name":"nex3","email":"nex342@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sync-child-process_1.0.2_1730754212564_0.37212100385481417"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-11-04T21:03:32.727Z","publish_time":1730754212727,"_source_registry_name":"default","_cnpm_publish_time":1730754212727},"1.0.1":{"name":"sync-child-process","version":"1.0.1","description":"Run a subprocess synchronously and interactively in Node.js","repository":{"type":"git","url":"git+https://github.com/sass/sync-child-process.git"},"author":{"name":"Google Inc."},"license":"MIT","exports":{"types":"./dist/lib/index.d.ts","default":"./dist/lib/index.js"},"main":"dist/lib/index.js","types":"dist/lib/index.d.ts","engines":{"node":">=16.0.0"},"scripts":{"check":"npm-run-all check:gts check:tsc","check:gts":"gts check","check:tsc":"tsc --noEmit","clean":"gts clean","compile":"tsc -p tsconfig.build.json","fix":"gts fix","test":"jest"},"devDependencies":{"@types/jest":"^29.4.0","@types/node":"^22.0.0","gts":"^6.0.2","jest":"^29.4.1","npm-run-all":"^4.1.5","ts-jest":"^29.0.5","ts-node":"^10.2.1","typedoc":"^0.26.11","typescript":"^5.0.2"},"dependencies":{"sync-message-port":"^1.0.0"},"_id":"sync-child-process@1.0.1","gitHead":"df51425d5b0a5a4cb15f1d641191fdf08a68f28a","bugs":{"url":"https://github.com/sass/sync-child-process/issues"},"homepage":"https://github.com/sass/sync-child-process#readme","_nodeVersion":"22.11.0","_npmVersion":"10.9.0","dist":{"shasum":"74d298fe5449db09e39cdb318262c8a31191f8a9","size":19378,"noattachment":false,"key":"/sync-child-process/-/sync-child-process-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/sync-child-process/download/sync-child-process-1.0.1.tgz"},"_npmUser":{"name":"nex3","email":"nex342@gmail.com"},"directories":{},"maintainers":[{"name":"nex3","email":"nex342@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sync-child-process_1.0.1_1730752115008_0.9401003514741739"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-11-04T20:28:35.172Z","publish_time":1730752115172,"_source_registry_name":"default","_cnpm_publish_time":1730752115172},"1.0.0":{"name":"sync-child-process","version":"1.0.0","description":"Run a subprocess synchronously and interactively in Node.js","repository":{"type":"git","url":"git+https://github.com/sass/sync-child-process.git"},"author":{"name":"Google Inc."},"license":"MIT","exports":{"types":"./dist/lib/index.d.ts","default":"./dist/lib/index.js"},"main":"dist/lib/index.js","types":"dist/lib/index.d.ts","engines":{"node":">=16.0.0"},"scripts":{"check":"npm-run-all check:gts check:tsc","check:gts":"gts check","check:tsc":"tsc --noEmit","clean":"gts clean","compile":"tsc -p tsconfig.build.json","fix":"gts fix","test":"jest"},"devDependencies":{"@types/jest":"^29.4.0","@types/node":"^22.0.0","gts":"^6.0.2","jest":"^29.4.1","npm-run-all":"^4.1.5","ts-jest":"^29.0.5","ts-node":"^10.2.1","typescript":"^5.0.2"},"dependencies":{"sync-message-port":"^1.0.0"},"_id":"sync-child-process@1.0.0","gitHead":"5b8e9bbb11d421e5bc4eada78b1b437ee1f9f4df","bugs":{"url":"https://github.com/sass/sync-child-process/issues"},"homepage":"https://github.com/sass/sync-child-process#readme","_nodeVersion":"22.2.0","_npmVersion":"10.7.0","dist":{"shasum":"1b29d5e33d7606d960ace7c08fd1b4944e6f900b","size":19132,"noattachment":false,"key":"/sync-child-process/-/sync-child-process-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/sync-child-process/download/sync-child-process-1.0.0.tgz"},"_npmUser":{"name":"nex3","email":"nex342@gmail.com"},"directories":{},"maintainers":[{"name":"nex3","email":"nex342@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sync-child-process_1.0.0_1730413061479_0.7451385408934939"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-10-31T22:17:41.774Z","publish_time":1730413061774,"_source_registry_name":"default","_cnpm_publish_time":1730413061774}},"readme":"# `sync-child-process`\n\nThis package exposes a `SyncChildProcess` class that allows Node.js to run a\nsubprocess synchronously *and* interactively.\n\n[**API Docs**]\n\n[**API Docs**]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html\n\n## Usage\n\nUse [`new SyncChildProcess()`] to start running a subprocess. This supports the\nsame API as [`child_process.spawn()`] other than a few options. You can send\ninput to the process using [`process.stdin`], and receive events from it\n(stdout, stderr, or exit) using [`process.next()`]. This implements [the\niterator protocol], but *not* the iterable protocol because it's intrinsically\nstateful.\n\n[`new SyncChildProcess()`]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html#constructor\n[`child_process.spawn()`]: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options\n[`process.stdin`]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html#stdin\n[`process.next()`]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html#next\n[the iterator protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol\n\n```js\nimport {SyncChildProcess} from 'sync-child-process';\n// or\n// const {SyncChildProcess} = require('sync-child-process');\n\nconst node = new SyncChildProcess('node', ['--interactive']);\n\nfor (;;) {\n  if (node.next().value.data.toString().endsWith('> ')) break;\n}\n\nnode.stdin.write(\"41 * Math.pow(2, 5)\\n\");\nconsole.log((node.next().value.data.toString().split(\"\\n\")[0]));\nnode.stdin.write(\".exit\\n\");\nconsole.log(`Node exited with exit code ${node.next().value.code}`);\n```\n\n## Why synchrony?\n\nSee [the `sync-message-port` documentation] for an explanation of why running\ncode synchronously can be valuable even in an asynchronous ecosystem like\nNode.js\n\n[the `sync-message-port` documentation]: https://github.com/sass/sync-message-port?tab=readme-ov-file#why-synchrony\n\n### Why not `child_process.spawnSync()`?\n\nAlthough Node's built-in [`child_process.spawnSync()`] function does run\nsynchronously, it's not interactive. It only returns once the process has run to\ncompletion and exited, which means it's not suitable for any long-lived\nsubprocess that interleaves sending and receiving data, such as when using the\n[embedded Sass protocol].\n\n[`child_process.spawnSync()`]: https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options\n[embedded Sass protocol]: https://github.com/sass/sass/blob/main/spec/embedded-protocol.md\n\n---\n\nDisclaimer: this is not an official Google product.\n","_attachments":{},"homepage":"https://github.com/sass/sync-child-process#readme","bugs":{"url":"https://github.com/sass/sync-child-process/issues"},"license":"MIT"}