soda-nodejs 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils/spawnAsync.d.ts +26 -21
- package/dist/cjs/utils/spawnAsync.js +9 -7
- package/dist/cjs/utils/spawnAsync.js.map +2 -2
- package/dist/esm/utils/spawnAsync.d.ts +26 -21
- package/dist/esm/utils/spawnAsync.js +12 -7
- package/dist/esm/utils/spawnAsync.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/spawnAsync.ts +110 -29
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function spawnAsync(command: string, options
|
|
9
|
-
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<
|
|
10
|
-
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<
|
|
11
|
-
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<
|
|
12
|
-
export declare function spawnAsync(command: string, options:
|
|
13
|
-
export declare function spawnAsync(command: string,
|
|
14
|
-
export declare function spawnAsync(command: string,
|
|
15
|
-
export declare function spawnAsync(command: string,
|
|
16
|
-
export declare function spawnAsync(command: string,
|
|
17
|
-
export declare function spawnAsync(command: string,
|
|
18
|
-
export declare function spawnAsync(command: string, args
|
|
19
|
-
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<
|
|
20
|
-
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<
|
|
21
|
-
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<
|
|
22
|
-
export declare function spawnAsync(command: string, args: readonly string[], options:
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
|
|
4
|
+
import { Readable, Writable } from "stream";
|
|
5
|
+
export interface PromiseWithChildProcess<T> extends Promise<T> {
|
|
6
|
+
child: T;
|
|
7
|
+
}
|
|
8
|
+
export declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
|
|
9
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
|
|
10
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
|
|
11
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
|
|
12
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
|
|
13
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
|
|
14
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
|
|
15
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
|
|
16
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
|
|
17
|
+
export declare function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
|
|
18
|
+
export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
|
|
19
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
|
|
20
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
|
|
21
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
|
|
22
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
|
|
23
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
|
|
24
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
|
|
25
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
|
|
26
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
|
|
27
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
|
|
@@ -23,17 +23,19 @@ __export(spawnAsync_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(spawnAsync_exports);
|
|
25
25
|
var import_child_process = require("child_process");
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
function spawnAsync(command, args, options) {
|
|
27
|
+
const promise = new Promise((resolve, reject) => {
|
|
28
28
|
const child = (0, import_child_process.spawn)(command, args, options);
|
|
29
|
+
promise.child = child;
|
|
29
30
|
child.on("exit", (code) => {
|
|
30
|
-
if (code
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
31
|
+
if (code === 0)
|
|
32
|
+
return resolve(child);
|
|
33
|
+
console.error(`"${command}" Command failed with code ${code}`);
|
|
34
|
+
reject(new Error(`"${command}" Command failed with code ${code}`));
|
|
35
|
+
return;
|
|
35
36
|
});
|
|
36
37
|
});
|
|
38
|
+
return promise;
|
|
37
39
|
}
|
|
38
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
41
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/spawnAsync.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n ChildProcess,\n ChildProcessByStdio,\n ChildProcessWithoutNullStreams,\n SpawnOptions,\n SpawnOptionsWithStdioTuple,\n SpawnOptionsWithoutStdio,\n StdioNull,\n StdioPipe,\n spawn,\n} from \"child_process\"\nimport { Readable, Writable } from \"stream\"\n\nexport interface PromiseWithChildProcess<T> extends Promise<T> {\n child: T\n}\n\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\nexport function spawnAsync(\n command: string,\n args?: readonly string[],\n options?: SpawnOptionsWithoutStdio,\n): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\n\n/**\n * @description wait for the command to exit\n * @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.\n */\nexport function spawnAsync(command: string, args?: any, options?: any): Promise<any> {\n const promise = new Promise<any>((resolve, reject) => {\n const child = spawn(command, args, options)\n promise.child = child\n child.on(\"exit\", code => {\n if (code === 0) return resolve(child)\n console.error(`\"${command}\" Command failed with code ${code}`)\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\n return\n })\n }) as PromiseWithChildProcess<any>\n return promise\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAUO;AA4FA,SAAS,WAAW,SAAiB,MAAY,SAA6B;AACjF,QAAM,UAAU,IAAI,QAAa,CAAC,SAAS,WAAW;AAClD,UAAM,YAAQ,4BAAM,SAAS,MAAM,OAAO;AAC1C,YAAQ,QAAQ;AAChB,UAAM,GAAG,QAAQ,UAAQ;AACrB,UAAI,SAAS;AAAG,eAAO,QAAQ,KAAK;AACpC,cAAQ,MAAM,IAAI,qCAAqC,MAAM;AAC7D,aAAO,IAAI,MAAM,IAAI,qCAAqC,MAAM,CAAC;AACjE;AAAA,IACJ,CAAC;AAAA,EACL,CAAC;AACD,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function spawnAsync(command: string, options
|
|
9
|
-
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<
|
|
10
|
-
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<
|
|
11
|
-
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<
|
|
12
|
-
export declare function spawnAsync(command: string, options:
|
|
13
|
-
export declare function spawnAsync(command: string,
|
|
14
|
-
export declare function spawnAsync(command: string,
|
|
15
|
-
export declare function spawnAsync(command: string,
|
|
16
|
-
export declare function spawnAsync(command: string,
|
|
17
|
-
export declare function spawnAsync(command: string,
|
|
18
|
-
export declare function spawnAsync(command: string, args
|
|
19
|
-
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<
|
|
20
|
-
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<
|
|
21
|
-
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<
|
|
22
|
-
export declare function spawnAsync(command: string, args: readonly string[], options:
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
|
|
4
|
+
import { Readable, Writable } from "stream";
|
|
5
|
+
export interface PromiseWithChildProcess<T> extends Promise<T> {
|
|
6
|
+
child: T;
|
|
7
|
+
}
|
|
8
|
+
export declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
|
|
9
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
|
|
10
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
|
|
11
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
|
|
12
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
|
|
13
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
|
|
14
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
|
|
15
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
|
|
16
|
+
export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
|
|
17
|
+
export declare function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
|
|
18
|
+
export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
|
|
19
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
|
|
20
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
|
|
21
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
|
|
22
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
|
|
23
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
|
|
24
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
|
|
25
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
|
|
26
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
|
|
27
|
+
export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @description wait for the command to exit
|
|
4
|
+
* @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.
|
|
5
|
+
*/
|
|
6
|
+
export function spawnAsync(command, args, options) {
|
|
7
|
+
const promise = new Promise((resolve, reject) => {
|
|
4
8
|
const child = spawn(command, args, options);
|
|
9
|
+
promise.child = child;
|
|
5
10
|
child.on("exit", code => {
|
|
6
|
-
if (code
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
resolve();
|
|
11
|
+
if (code === 0) return resolve(child);
|
|
12
|
+
console.error(`"${command}" Command failed with code ${code}`);
|
|
13
|
+
reject(new Error(`"${command}" Command failed with code ${code}`));
|
|
14
|
+
return;
|
|
11
15
|
});
|
|
12
16
|
});
|
|
17
|
+
return promise;
|
|
13
18
|
}
|
|
14
19
|
//# sourceMappingURL=spawnAsync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["spawn","spawnAsync","command","args","options","Promise","resolve","reject","child","on","code","Error"],"sources":["../../../src/utils/spawnAsync.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["spawn","spawnAsync","command","args","options","promise","Promise","resolve","reject","child","on","code","console","error","Error"],"sources":["../../../src/utils/spawnAsync.ts"],"sourcesContent":["import {\n ChildProcess,\n ChildProcessByStdio,\n ChildProcessWithoutNullStreams,\n SpawnOptions,\n SpawnOptionsWithStdioTuple,\n SpawnOptionsWithoutStdio,\n StdioNull,\n StdioPipe,\n spawn,\n} from \"child_process\"\nimport { Readable, Writable } from \"stream\"\n\nexport interface PromiseWithChildProcess<T> extends Promise<T> {\n child: T\n}\n\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\nexport function spawnAsync(\n command: string,\n args?: readonly string[],\n options?: SpawnOptionsWithoutStdio,\n): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\n\n/**\n * @description wait for the command to exit\n * @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.\n */\nexport function spawnAsync(command: string, args?: any, options?: any): Promise<any> {\n const promise = new Promise<any>((resolve, reject) => {\n const child = spawn(command, args, options)\n promise.child = child\n child.on(\"exit\", code => {\n if (code === 0) return resolve(child)\n console.error(`\"${command}\" Command failed with code ${code}`)\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\n return\n })\n }) as PromiseWithChildProcess<any>\n return promise\n}\n"],"mappings":"AAAA,SASIA,KAAK,QACF,eAAe;AAwFtB;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,OAAe,EAAEC,IAAU,EAAEC,OAAa,EAAgB;EACjF,MAAMC,OAAO,GAAG,IAAIC,OAAO,CAAM,CAACC,OAAO,EAAEC,MAAM,KAAK;IAClD,MAAMC,KAAK,GAAGT,KAAK,CAACE,OAAO,EAAEC,IAAI,EAAEC,OAAO,CAAC;IAC3CC,OAAO,CAACI,KAAK,GAAGA,KAAK;IACrBA,KAAK,CAACC,EAAE,CAAC,MAAM,EAAEC,IAAI,IAAI;MACrB,IAAIA,IAAI,KAAK,CAAC,EAAE,OAAOJ,OAAO,CAACE,KAAK,CAAC;MACrCG,OAAO,CAACC,KAAK,CAAE,IAAGX,OAAQ,8BAA6BS,IAAK,EAAC,CAAC;MAC9DH,MAAM,CAAC,IAAIM,KAAK,CAAE,IAAGZ,OAAQ,8BAA6BS,IAAK,EAAC,CAAC,CAAC;MAClE;IACJ,CAAC,CAAC;EACN,CAAC,CAAiC;EAClC,OAAON,OAAO;AAClB"}
|
package/package.json
CHANGED
package/src/utils/spawnAsync.ts
CHANGED
|
@@ -1,34 +1,115 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ChildProcess,
|
|
3
|
+
ChildProcessByStdio,
|
|
4
|
+
ChildProcessWithoutNullStreams,
|
|
5
|
+
SpawnOptions,
|
|
6
|
+
SpawnOptionsWithStdioTuple,
|
|
7
|
+
SpawnOptionsWithoutStdio,
|
|
8
|
+
StdioNull,
|
|
9
|
+
StdioPipe,
|
|
10
|
+
spawn,
|
|
11
|
+
} from "child_process"
|
|
12
|
+
import { Readable, Writable } from "stream"
|
|
2
13
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export function spawnAsync(command: string, options
|
|
8
|
-
export function spawnAsync(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export function spawnAsync(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export function spawnAsync(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export function spawnAsync(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
export interface PromiseWithChildProcess<T> extends Promise<T> {
|
|
15
|
+
child: T
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>
|
|
19
|
+
export function spawnAsync(
|
|
20
|
+
command: string,
|
|
21
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
|
22
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>
|
|
23
|
+
export function spawnAsync(
|
|
24
|
+
command: string,
|
|
25
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
|
26
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>
|
|
27
|
+
export function spawnAsync(
|
|
28
|
+
command: string,
|
|
29
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
|
30
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>
|
|
31
|
+
export function spawnAsync(
|
|
32
|
+
command: string,
|
|
33
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
|
34
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>
|
|
35
|
+
export function spawnAsync(
|
|
36
|
+
command: string,
|
|
37
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
|
38
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>
|
|
39
|
+
export function spawnAsync(
|
|
40
|
+
command: string,
|
|
41
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
|
42
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>
|
|
43
|
+
export function spawnAsync(
|
|
44
|
+
command: string,
|
|
45
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
|
46
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>
|
|
47
|
+
export function spawnAsync(
|
|
48
|
+
command: string,
|
|
49
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
|
50
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>
|
|
51
|
+
export function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>
|
|
52
|
+
export function spawnAsync(
|
|
53
|
+
command: string,
|
|
54
|
+
args?: readonly string[],
|
|
55
|
+
options?: SpawnOptionsWithoutStdio,
|
|
56
|
+
): PromiseWithChildProcess<ChildProcessWithoutNullStreams>
|
|
57
|
+
export function spawnAsync(
|
|
58
|
+
command: string,
|
|
59
|
+
args: readonly string[],
|
|
60
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
|
61
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>
|
|
62
|
+
export function spawnAsync(
|
|
63
|
+
command: string,
|
|
64
|
+
args: readonly string[],
|
|
65
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
|
66
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>
|
|
67
|
+
export function spawnAsync(
|
|
68
|
+
command: string,
|
|
69
|
+
args: readonly string[],
|
|
70
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
|
71
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>
|
|
72
|
+
export function spawnAsync(
|
|
73
|
+
command: string,
|
|
74
|
+
args: readonly string[],
|
|
75
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
|
76
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>
|
|
77
|
+
export function spawnAsync(
|
|
78
|
+
command: string,
|
|
79
|
+
args: readonly string[],
|
|
80
|
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
|
81
|
+
): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>
|
|
82
|
+
export function spawnAsync(
|
|
83
|
+
command: string,
|
|
84
|
+
args: readonly string[],
|
|
85
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
|
86
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>
|
|
87
|
+
export function spawnAsync(
|
|
88
|
+
command: string,
|
|
89
|
+
args: readonly string[],
|
|
90
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
|
91
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>
|
|
92
|
+
export function spawnAsync(
|
|
93
|
+
command: string,
|
|
94
|
+
args: readonly string[],
|
|
95
|
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
|
96
|
+
): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>
|
|
97
|
+
export function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @description wait for the command to exit
|
|
101
|
+
* @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.
|
|
102
|
+
*/
|
|
103
|
+
export function spawnAsync(command: string, args?: any, options?: any): Promise<any> {
|
|
104
|
+
const promise = new Promise<any>((resolve, reject) => {
|
|
25
105
|
const child = spawn(command, args, options)
|
|
106
|
+
promise.child = child
|
|
26
107
|
child.on("exit", code => {
|
|
27
|
-
if (code
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
resolve()
|
|
108
|
+
if (code === 0) return resolve(child)
|
|
109
|
+
console.error(`"${command}" Command failed with code ${code}`)
|
|
110
|
+
reject(new Error(`"${command}" Command failed with code ${code}`))
|
|
111
|
+
return
|
|
32
112
|
})
|
|
33
|
-
})
|
|
113
|
+
}) as PromiseWithChildProcess<any>
|
|
114
|
+
return promise
|
|
34
115
|
}
|