sync-child-process
Advanced tools
Comparing version
@@ -8,3 +8,3 @@ import * as stream from 'stream'; | ||
*/ | ||
export declare class SyncProcess implements Iterator<StderrEvent | StdoutEvent, ExitEvent | undefined> { | ||
export declare class SyncChildProcess implements Iterator<StderrEvent | StdoutEvent, ExitEvent | undefined> { | ||
/** The port that communicates with the worker thread. */ | ||
@@ -11,0 +11,0 @@ private readonly port; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SyncProcess = void 0; | ||
exports.SyncChildProcess = void 0; | ||
const fs = require("fs"); | ||
@@ -19,4 +19,4 @@ const p = require("path"); | ||
return 'isMarkedAsUntransferable' in worker_threads | ||
// TODO - DefinitelyTyped/DefinitelyTyped#71033: Remove this cast | ||
? worker_threads.isMarkedAsUntransferable(object) | ||
? // TODO - DefinitelyTyped/DefinitelyTyped#71033: Remove this cast | ||
worker_threads.isMarkedAsUntransferable(object) | ||
: false; | ||
@@ -28,3 +28,3 @@ } | ||
*/ | ||
class SyncProcess { | ||
class SyncChildProcess { | ||
/** The port that communicates with the worker thread. */ | ||
@@ -78,5 +78,9 @@ port; | ||
case 'stdout': | ||
return { value: { type: 'stdout', data: Buffer.from(message.data.buffer) } }; | ||
return { | ||
value: { type: 'stdout', data: Buffer.from(message.data.buffer) }, | ||
}; | ||
case 'stderr': | ||
return { value: { type: 'stderr', data: Buffer.from(message.data.buffer) } }; | ||
return { | ||
value: { type: 'stderr', data: Buffer.from(message.data.buffer) }, | ||
}; | ||
case 'error': | ||
@@ -108,3 +112,3 @@ this.close(); | ||
} | ||
exports.SyncProcess = SyncProcess; | ||
exports.SyncChildProcess = SyncChildProcess; | ||
/** | ||
@@ -111,0 +115,0 @@ * Spawns a worker for the given `fileWithoutExtension` in either a JS or TS |
{ | ||
"name": "sync-child-process", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Run a subprocess synchronously and interactively in Node.js", | ||
@@ -37,2 +37,3 @@ "repository": "sass/sync-child-process", | ||
"ts-node": "^10.2.1", | ||
"typedoc": "^0.26.11", | ||
"typescript": "^5.0.2" | ||
@@ -39,0 +40,0 @@ }, |
@@ -6,12 +6,20 @@ # `sync-child-process` | ||
[**API Docs**] | ||
[**API Docs**]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html | ||
## Usage | ||
Use `new SyncChildProcess()` to start running a subprocess. This supports the | ||
Use [`new SyncChildProcess()`] to start running a subprocess. This supports the | ||
same API as [`child_process.spawn()`] other than a few options. You can send | ||
input to the process using `process.stdin`, and receive events from it (stdout, | ||
stderr, or exit) using `process.next()`. This implements [the iterator | ||
protocol], but *not* the iterable protocol because it's intrinsically stateful. | ||
input to the process using [`process.stdin`], and receive events from it | ||
(stdout, stderr, or exit) using [`process.next()`]. This implements [the | ||
iterator protocol], but *not* the iterable protocol because it's intrinsically | ||
stateful. | ||
[`new SyncChildProcess()`]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html#constructor | ||
[`child_process.spawn()`]: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options | ||
[`process.stdin`]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html#stdin | ||
[`process.next()`]: https://sass.github.io/sync-child-process/classes/SyncChildProcess.html#next | ||
[the iterator protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol | ||
[`child_process.spawn()`]: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options | ||
@@ -18,0 +26,0 @@ ```js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58725
1.75%290
1.4%64
14.29%9
12.5%