Skip to content

Commit 249b5a5

Browse files
committed
add syncline.d.ts
1 parent c1fdf11 commit 249b5a5

3 files changed

Lines changed: 52 additions & 18 deletions

File tree

lib/syncline.d.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import EventEmitter from 'node:events';
2+
3+
export type SynclineSpawnOptions = {
4+
5+
/**
6+
* Current working directory of the child process. Defaults to the CWD of the current process.
7+
*/
8+
cwd?: string,
9+
10+
/**
11+
* Environment variables. Defaults to the environment variables of the current process.
12+
*/
13+
env?: { [ key: string]: string},
14+
15+
/**
16+
* `argv[0]`, defaults to the command.
17+
*/
18+
argv0?: string
19+
}
20+
21+
export class Syncline extends EventEmitter {
22+
23+
/**
24+
* Spawns a child process with the specified command name and arguments, and returns a {@link Promise} that resolves
25+
* to a {@link Syncline}.
26+
*
27+
* @param command Command name
28+
* @param args Arguments, defaults to empty array
29+
* @param options Spawn options
30+
*/
31+
static async spawn( command: string, args?: string[], options?: SynclineSpawnOptions): Promise< Syncline> {
32+
}
33+
34+
/**
35+
* Sends a line of text to the child process and returns the next line from the child process.
36+
*
37+
* @param inputLine A line of input string
38+
* @param timeout Optional timeout in milliseconds
39+
*/
40+
exchange( inputLine: string, timeout?: number): string {
41+
}
42+
43+
/**
44+
* Terminates the child process, if not already, and returns a {@link Promise} that resolves to one of the following:
45+
*
46+
* * An object with property `code` set to the exit status code of the child process.
47+
* * An object with property `signal` set to the signal that terminated the child process.
48+
*/
49+
async close(): Promise< { code: number} | { signal: string}> {
50+
}
51+
}

lib/syncline.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ const EVENT_EXIT = 'exit';
141141

142142
export class Syncline extends EventEmitter {
143143

144-
/**
145-
* Spawns a child process with the specified command name and arguments, and returns a {@link Promise} that resolves
146-
* to a {@link Syncline}.
147-
*
148-
* @param { string} command Command name
149-
* @param { undefined | string[]} args Arguments, defaults to empty array
150-
* @param { undefined | { cwd?: string, env?: { [ key: string]: string}, argv0?: string}} options See the `spawn()`
151-
* function from `child_process` Node.js module. Only `cwd`, `env`, and `argv0` are supported.
152-
* @returns { Promise< Syncline>}
153-
*/
154144
static async spawn( command, args = [], options = {}) {
155145
// the initial feedback (whether the worker has successfully spawned the child process and whether it is ready to
156146
// receive input) must be done through parentPort and not through SharedArrayBuffer+Atomics, because the main
@@ -258,14 +248,6 @@ export class Syncline extends EventEmitter {
258248
}
259249
}
260250

261-
/**
262-
* Terminates the child process, if not already, and returns a {@link Promise} that resolves to one of the following:
263-
*
264-
* * An object with property `code` set to the exit status code of the child process.
265-
* * An object with property `signal` set to the signal that terminated the child process.
266-
*
267-
* @returns { Promise< { code: number} | { signal: string}>}
268-
*/
269251
async close() {
270252
if( this.#terminated)
271253
return this.#terminated;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"url": "https://github.com/arcticnotes/syncline/issues"
1414
},
1515
"type": "module",
16+
"types": "lib/syncline.d.ts",
1617
"exports": {
1718
".": "./lib/index.js"
1819
}

0 commit comments

Comments
 (0)