spawn-rx 5.1.1 → 6.0.0
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/biome.json +15 -0
- package/bun.lock +417 -0
- package/esdoc.json +1 -4
- package/lib/{src/index.d.ts → index.d.ts} +67 -75
- package/lib/index.js +451 -0
- package/lib/index.js.map +1 -0
- package/package.json +11 -23
- package/src/index.ts +289 -335
- package/test/{asserttest.ts → asserttest.test.ts} +4 -5
- package/test/{spawn.ts → spawn.test.ts} +47 -75
- package/tsconfig.json +1 -1
- package/eslint.config.mjs +0 -88
- package/lib/src/index.js +0 -384
- package/lib/src/index.js.map +0 -1
- package/src/ambient.d.ts +0 -1
- package/test/support.ts +0 -15
- package/vendor/jobber/Jobber.exe +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
2
|
-
import { expect } from "
|
|
3
|
-
import "./support";
|
|
2
|
+
import { describe, expect, it } from "bun:test";
|
|
4
3
|
|
|
5
4
|
function delay(ms: number) {
|
|
6
5
|
return new Promise((resolve) => {
|
|
@@ -8,9 +7,9 @@ function delay(ms: number) {
|
|
|
8
7
|
});
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
describe("The test runner",
|
|
12
|
-
it("should pass this test", async
|
|
10
|
+
describe("The test runner", () => {
|
|
11
|
+
it("should pass this test", async () => {
|
|
13
12
|
await delay(1000);
|
|
14
|
-
expect(true).
|
|
13
|
+
expect(true).toBeTruthy();
|
|
15
14
|
});
|
|
16
15
|
});
|
|
@@ -1,57 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
3
|
-
import { expect } from "chai";
|
|
4
|
-
import "./support";
|
|
5
|
-
|
|
6
|
-
import { spawn, spawnPromise, spawnDetachedPromise } from "../src/index";
|
|
7
|
-
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
8
2
|
import type { Observable } from "rxjs";
|
|
9
3
|
import { of } from "rxjs";
|
|
4
|
+
import { spawn, spawnPromise } from "../src/index";
|
|
10
5
|
|
|
11
|
-
const uuidRegex =
|
|
12
|
-
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
6
|
+
const uuidRegex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
13
7
|
|
|
14
|
-
describe("The spawnPromise method",
|
|
15
|
-
it("should return a uuid when we call uuid", async
|
|
8
|
+
describe("The spawnPromise method", () => {
|
|
9
|
+
it("should return a uuid when we call uuid", async () => {
|
|
16
10
|
// NB: Since we get run via npm run test, we know that npm bins are in our
|
|
17
11
|
// PATH.
|
|
18
12
|
const result = await spawnPromise("uuid", []);
|
|
19
|
-
expect(result.match(uuidRegex)).
|
|
13
|
+
expect(result.match(uuidRegex)).toBeTruthy();
|
|
20
14
|
});
|
|
21
15
|
|
|
22
|
-
it("should split stdout and stderr when we call uuid", async
|
|
16
|
+
it("should split stdout and stderr when we call uuid", async () => {
|
|
23
17
|
// NB: Since we get run via npm run test, we know that npm bins are in our
|
|
24
18
|
// PATH.
|
|
25
19
|
const result = await spawnPromise("uuid", [], { split: true });
|
|
26
|
-
expect(result[0].match(uuidRegex)).
|
|
27
|
-
expect(result[1].match(uuidRegex)).
|
|
20
|
+
expect(result[0].match(uuidRegex)).toBeTruthy();
|
|
21
|
+
expect(result[1].match(uuidRegex)).toBeFalsy();
|
|
28
22
|
});
|
|
29
23
|
|
|
30
|
-
it("should retur nthe exit code", async
|
|
24
|
+
it("should retur nthe exit code", async () => {
|
|
31
25
|
// NB: Since we get run via npm run test, we know that npm bins are in our
|
|
32
26
|
// PATH.
|
|
33
27
|
try {
|
|
34
28
|
await spawnPromise("false", [], { split: true });
|
|
35
|
-
expect(false).
|
|
36
|
-
} catch (e) {
|
|
37
|
-
expect(e.code).
|
|
29
|
+
expect(false).toBe(true);
|
|
30
|
+
} catch (e: any) {
|
|
31
|
+
expect(e.code).toBe(1);
|
|
38
32
|
}
|
|
39
33
|
});
|
|
40
34
|
|
|
41
|
-
it("should not stdout and stderr when we call uuid with split false", async
|
|
35
|
+
it("should not stdout and stderr when we call uuid with split false", async () => {
|
|
42
36
|
// NB: Since we get run via npm run test, we know that npm bins are in our
|
|
43
37
|
// PATH.
|
|
44
38
|
const result = await spawnPromise("uuid", [], { split: false });
|
|
45
|
-
expect(result.match(uuidRegex)).
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("The spawnDetachedPromise method", function () {
|
|
50
|
-
it("should return a uuid when we call uuid", async function () {
|
|
51
|
-
// NB: Since we get run via npm run test, we know that npm bins are in our
|
|
52
|
-
// PATH.
|
|
53
|
-
const result = await spawnDetachedPromise("uuid", ["--help"]);
|
|
54
|
-
expect(result.length > 10).to.be.ok;
|
|
39
|
+
expect(result.match(uuidRegex)).toBeTruthy();
|
|
55
40
|
});
|
|
56
41
|
});
|
|
57
42
|
|
|
@@ -85,81 +70,68 @@ function wrapSplitObservableInPromise(
|
|
|
85
70
|
});
|
|
86
71
|
}
|
|
87
72
|
|
|
88
|
-
describe("The spawn method",
|
|
89
|
-
it("should return a disposable subscription", async
|
|
73
|
+
describe("The spawn method", () => {
|
|
74
|
+
it("should return a disposable subscription", async () => {
|
|
90
75
|
// this only check the unsubscribe goes w/o error, not that the spawned process is killed
|
|
91
76
|
// (difficult to do that, maybe iterate through child processes and check ?)
|
|
92
77
|
spawn("sleep", ["2"]).subscribe().unsubscribe();
|
|
93
78
|
});
|
|
94
79
|
|
|
95
|
-
it("should return split stderr in a inner tag when called with split", async
|
|
80
|
+
it("should return split stderr in a inner tag when called with split", async () => {
|
|
96
81
|
// provide an invalid param to uuid so it complains on stderr
|
|
97
|
-
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
|
98
|
-
"uuid",
|
|
99
|
-
["foo"],
|
|
100
|
-
{ split: true },
|
|
101
|
-
) as any;
|
|
82
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn("uuid", ["foo"], { split: true }) as any;
|
|
102
83
|
const result = await wrapSplitObservableInPromise(rxSpawn);
|
|
103
|
-
expect(result.stderr.length > 10).
|
|
104
|
-
expect(result.stdout).
|
|
105
|
-
expect(result.error).
|
|
84
|
+
expect(result.stderr.length > 10).toBeTruthy();
|
|
85
|
+
expect(result.stdout).toBe("");
|
|
86
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
106
87
|
});
|
|
107
88
|
|
|
108
|
-
it("should return split stdout in a inner tag when called with split", async
|
|
89
|
+
it("should return split stdout in a inner tag when called with split", async () => {
|
|
109
90
|
const rxSpawn: Observable<{ source: any; text: any }> = spawn("uuid", [], {
|
|
110
91
|
split: true,
|
|
111
92
|
});
|
|
112
93
|
const result = await wrapSplitObservableInPromise(rxSpawn);
|
|
113
|
-
expect(result.stdout.match(uuidRegex)).
|
|
114
|
-
expect(result.stderr).
|
|
115
|
-
expect(result.error).
|
|
94
|
+
expect(result.stdout.match(uuidRegex)).toBeTruthy();
|
|
95
|
+
expect(result.stderr).toBe("");
|
|
96
|
+
expect(result.error).toBeUndefined();
|
|
116
97
|
});
|
|
117
98
|
|
|
118
|
-
it("should ignore stderr if options.stdio = ignore", async
|
|
119
|
-
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
|
120
|
-
|
|
121
|
-
["
|
|
122
|
-
|
|
123
|
-
);
|
|
99
|
+
it("should ignore stderr if options.stdio = ignore", async () => {
|
|
100
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn("uuid", ["foo"], {
|
|
101
|
+
split: true,
|
|
102
|
+
stdio: [null, null, "ignore"],
|
|
103
|
+
});
|
|
124
104
|
const result = await wrapSplitObservableInPromise(rxSpawn);
|
|
125
|
-
expect(result.stderr).
|
|
105
|
+
expect(result.stderr).toBe("");
|
|
126
106
|
});
|
|
127
107
|
|
|
128
|
-
it("should ignore stdout if options.stdio = inherit", async
|
|
108
|
+
it("should ignore stdout if options.stdio = inherit", async () => {
|
|
129
109
|
const rxSpawn: Observable<{ source: any; text: any }> = spawn("uuid", [], {
|
|
130
110
|
split: true,
|
|
131
111
|
stdio: [null, "inherit", null],
|
|
132
112
|
});
|
|
133
113
|
const result = await wrapSplitObservableInPromise(rxSpawn);
|
|
134
|
-
expect(result.stdout).
|
|
114
|
+
expect(result.stdout).toBe("");
|
|
135
115
|
});
|
|
136
116
|
|
|
137
|
-
it("should croak if stdin is provided but stdio.stdin is disabled", async
|
|
117
|
+
it("should croak if stdin is provided but stdio.stdin is disabled", async () => {
|
|
138
118
|
const stdin = of("a");
|
|
139
|
-
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
stdin: stdin,
|
|
145
|
-
stdio: ["ignore", null, null],
|
|
146
|
-
},
|
|
147
|
-
);
|
|
119
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn("marked", [], {
|
|
120
|
+
split: true,
|
|
121
|
+
stdin: stdin,
|
|
122
|
+
stdio: ["ignore", null, null],
|
|
123
|
+
});
|
|
148
124
|
const result = await wrapSplitObservableInPromise(rxSpawn);
|
|
149
|
-
expect(result.error).
|
|
125
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
150
126
|
});
|
|
151
127
|
|
|
152
|
-
it("should subscribe to provided stdin", async
|
|
128
|
+
it("should subscribe to provided stdin", async () => {
|
|
153
129
|
const stdin = of("a");
|
|
154
|
-
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
split: true,
|
|
159
|
-
stdin: stdin,
|
|
160
|
-
},
|
|
161
|
-
);
|
|
130
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn("marked", [], {
|
|
131
|
+
split: true,
|
|
132
|
+
stdin: stdin,
|
|
133
|
+
});
|
|
162
134
|
const result = await wrapSplitObservableInPromise(rxSpawn);
|
|
163
|
-
expect(result.stdout.trim()).
|
|
135
|
+
expect(result.stdout.trim()).toBe("<p>a</p>");
|
|
164
136
|
});
|
|
165
137
|
});
|
package/tsconfig.json
CHANGED
package/eslint.config.mjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
2
|
-
import prettier from "eslint-plugin-prettier";
|
|
3
|
-
import tsParser from "@typescript-eslint/parser";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import js from "@eslint/js";
|
|
7
|
-
import { FlatCompat } from "@eslint/eslintrc";
|
|
8
|
-
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
const compat = new FlatCompat({
|
|
12
|
-
baseDirectory: __dirname,
|
|
13
|
-
recommendedConfig: js.configs.recommended,
|
|
14
|
-
allConfig: js.configs.all,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export default [
|
|
18
|
-
...compat.extends(
|
|
19
|
-
"eslint:recommended",
|
|
20
|
-
"prettier",
|
|
21
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
22
|
-
"plugin:@typescript-eslint/recommended",
|
|
23
|
-
),
|
|
24
|
-
{
|
|
25
|
-
files: ["./src/*.{ts,tsx}", "./test/*.{ts,tsx}"],
|
|
26
|
-
plugins: {
|
|
27
|
-
"@typescript-eslint": typescriptEslint,
|
|
28
|
-
prettier,
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
languageOptions: {
|
|
32
|
-
globals: {},
|
|
33
|
-
parser: tsParser,
|
|
34
|
-
ecmaVersion: 5,
|
|
35
|
-
sourceType: "script",
|
|
36
|
-
|
|
37
|
-
parserOptions: {
|
|
38
|
-
project: "./tsconfig.json",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
rules: {
|
|
43
|
-
"prettier/prettier": "warn",
|
|
44
|
-
|
|
45
|
-
"spaced-comment": [
|
|
46
|
-
"error",
|
|
47
|
-
"always",
|
|
48
|
-
{
|
|
49
|
-
markers: ["/"],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
|
|
53
|
-
"no-fallthrough": "error",
|
|
54
|
-
"@typescript-eslint/ban-ts-comment": "warn",
|
|
55
|
-
|
|
56
|
-
"@typescript-eslint/consistent-type-imports": [
|
|
57
|
-
"error",
|
|
58
|
-
{
|
|
59
|
-
prefer: "type-imports",
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
|
|
63
|
-
"@typescript-eslint/no-inferrable-types": [
|
|
64
|
-
"error",
|
|
65
|
-
{
|
|
66
|
-
ignoreParameters: false,
|
|
67
|
-
ignoreProperties: false,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
|
|
71
|
-
"@typescript-eslint/no-non-null-assertion": "off",
|
|
72
|
-
"@typescript-eslint/no-floating-promises": "error",
|
|
73
|
-
|
|
74
|
-
"@typescript-eslint/no-unused-vars": [
|
|
75
|
-
"warn",
|
|
76
|
-
{
|
|
77
|
-
args: "after-used",
|
|
78
|
-
argsIgnorePattern: "^_",
|
|
79
|
-
varsIgnorePattern: "^_",
|
|
80
|
-
ignoreRestSiblings: true,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
|
|
84
|
-
"@typescript-eslint/no-empty-function": ["error"],
|
|
85
|
-
"@typescript-eslint/restrict-template-expressions": "off",
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
];
|
package/lib/src/index.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
-
if (ar || !(i in from)) {
|
|
27
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
-
ar[i] = from[i];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.findActualExecutable = findActualExecutable;
|
|
35
|
-
exports.spawnDetached = spawnDetached;
|
|
36
|
-
exports.spawn = spawn;
|
|
37
|
-
exports.spawnDetachedPromise = spawnDetachedPromise;
|
|
38
|
-
exports.spawnPromise = spawnPromise;
|
|
39
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
40
|
-
var path = require("path");
|
|
41
|
-
var net = require("net");
|
|
42
|
-
var sfs = require("fs");
|
|
43
|
-
var rxjs_1 = require("rxjs");
|
|
44
|
-
var operators_1 = require("rxjs/operators");
|
|
45
|
-
var child_process_1 = require("child_process");
|
|
46
|
-
var debug_1 = require("debug");
|
|
47
|
-
var isWindows = process.platform === "win32";
|
|
48
|
-
var d = (0, debug_1.default)("spawn-rx"); // tslint:disable-line:no-var-requires
|
|
49
|
-
/**
|
|
50
|
-
* stat a file but don't throw if it doesn't exist
|
|
51
|
-
*
|
|
52
|
-
* @param {string} file The path to a file
|
|
53
|
-
* @return {Stats} The stats structure
|
|
54
|
-
*
|
|
55
|
-
* @private
|
|
56
|
-
*/
|
|
57
|
-
function statSyncNoException(file) {
|
|
58
|
-
try {
|
|
59
|
-
return sfs.statSync(file);
|
|
60
|
-
}
|
|
61
|
-
catch (_a) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Search PATH to see if a file exists in any of the path folders.
|
|
67
|
-
*
|
|
68
|
-
* @param {string} exe The file to search for
|
|
69
|
-
* @return {string} A fully qualified path, or the original path if nothing
|
|
70
|
-
* is found
|
|
71
|
-
*
|
|
72
|
-
* @private
|
|
73
|
-
*/
|
|
74
|
-
function runDownPath(exe) {
|
|
75
|
-
// NB: Windows won't search PATH looking for executables in spawn like
|
|
76
|
-
// Posix does
|
|
77
|
-
// Files with any directory path don't get this applied
|
|
78
|
-
if (exe.match(/[\\/]/)) {
|
|
79
|
-
d("Path has slash in directory, bailing");
|
|
80
|
-
return exe;
|
|
81
|
-
}
|
|
82
|
-
var target = path.join(".", exe);
|
|
83
|
-
if (statSyncNoException(target)) {
|
|
84
|
-
d("Found executable in currect directory: ".concat(target));
|
|
85
|
-
return sfs.realpathSync(target);
|
|
86
|
-
}
|
|
87
|
-
var haystack = process.env.PATH.split(isWindows ? ";" : ":");
|
|
88
|
-
for (var _i = 0, haystack_1 = haystack; _i < haystack_1.length; _i++) {
|
|
89
|
-
var p = haystack_1[_i];
|
|
90
|
-
var needle = path.join(p, exe);
|
|
91
|
-
if (statSyncNoException(needle)) {
|
|
92
|
-
return sfs.realpathSync(needle);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
d("Failed to find executable anywhere in path");
|
|
96
|
-
return exe;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Finds the actual executable and parameters to run on Windows. This method
|
|
100
|
-
* mimics the POSIX behavior of being able to run scripts as executables by
|
|
101
|
-
* replacing the passed-in executable with the script runner, for PowerShell,
|
|
102
|
-
* CMD, and node scripts.
|
|
103
|
-
*
|
|
104
|
-
* This method also does the work of running down PATH, which spawn on Windows
|
|
105
|
-
* also doesn't do, unlike on POSIX.
|
|
106
|
-
*
|
|
107
|
-
* @param {string} exe The executable to run
|
|
108
|
-
* @param {string[]} args The arguments to run
|
|
109
|
-
*
|
|
110
|
-
* @return {Object} The cmd and args to run
|
|
111
|
-
* @property {string} cmd The command to pass to spawn
|
|
112
|
-
* @property {string[]} args The arguments to pass to spawn
|
|
113
|
-
*/
|
|
114
|
-
function findActualExecutable(exe, args) {
|
|
115
|
-
// POSIX can just execute scripts directly, no need for silly goosery
|
|
116
|
-
if (process.platform !== "win32") {
|
|
117
|
-
return { cmd: runDownPath(exe), args: args };
|
|
118
|
-
}
|
|
119
|
-
if (!sfs.existsSync(exe)) {
|
|
120
|
-
// NB: When you write something like `surf-client ... -- surf-build` on Windows,
|
|
121
|
-
// a shell would normally convert that to surf-build.cmd, but since it's passed
|
|
122
|
-
// in as an argument, it doesn't happen
|
|
123
|
-
var possibleExts = [".exe", ".bat", ".cmd", ".ps1"];
|
|
124
|
-
for (var _i = 0, possibleExts_1 = possibleExts; _i < possibleExts_1.length; _i++) {
|
|
125
|
-
var ext = possibleExts_1[_i];
|
|
126
|
-
var possibleFullPath = runDownPath("".concat(exe).concat(ext));
|
|
127
|
-
if (sfs.existsSync(possibleFullPath)) {
|
|
128
|
-
return findActualExecutable(possibleFullPath, args);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (exe.match(/\.ps1$/i)) {
|
|
133
|
-
var cmd = path.join(process.env.SYSTEMROOT, "System32", "WindowsPowerShell", "v1.0", "PowerShell.exe");
|
|
134
|
-
var psargs = [
|
|
135
|
-
"-ExecutionPolicy",
|
|
136
|
-
"Unrestricted",
|
|
137
|
-
"-NoLogo",
|
|
138
|
-
"-NonInteractive",
|
|
139
|
-
"-File",
|
|
140
|
-
exe,
|
|
141
|
-
];
|
|
142
|
-
return { cmd: cmd, args: psargs.concat(args) };
|
|
143
|
-
}
|
|
144
|
-
if (exe.match(/\.(bat|cmd)$/i)) {
|
|
145
|
-
var cmd = path.join(process.env.SYSTEMROOT, "System32", "cmd.exe");
|
|
146
|
-
var cmdArgs = __spreadArray(["/C", exe], args, true);
|
|
147
|
-
return { cmd: cmd, args: cmdArgs };
|
|
148
|
-
}
|
|
149
|
-
if (exe.match(/\.(js)$/i)) {
|
|
150
|
-
var cmd = process.execPath;
|
|
151
|
-
var nodeArgs = [exe];
|
|
152
|
-
return { cmd: cmd, args: nodeArgs.concat(args) };
|
|
153
|
-
}
|
|
154
|
-
// Dunno lol
|
|
155
|
-
return { cmd: exe, args: args };
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Spawns a process but detached from the current process. The process is put
|
|
159
|
-
* into its own Process Group that can be killed by unsubscribing from the
|
|
160
|
-
* return Observable.
|
|
161
|
-
*
|
|
162
|
-
* @param {string} exe The executable to run
|
|
163
|
-
* @param {string[]} params The parameters to pass to the child
|
|
164
|
-
* @param {SpawnOptions & SpawnRxExtras} opts Options to pass to spawn.
|
|
165
|
-
*
|
|
166
|
-
* @return {Observable<string>} Returns an Observable that when subscribed
|
|
167
|
-
* to, will create a detached process. The
|
|
168
|
-
* process output will be streamed to this
|
|
169
|
-
* Observable, and if unsubscribed from, the
|
|
170
|
-
* process will be terminated early. If the
|
|
171
|
-
* process terminates with a non-zero value,
|
|
172
|
-
* the Observable will terminate with onError.
|
|
173
|
-
*/
|
|
174
|
-
function spawnDetached(exe, params, opts) {
|
|
175
|
-
var _a = findActualExecutable(exe, params !== null && params !== void 0 ? params : []), cmd = _a.cmd, args = _a.args;
|
|
176
|
-
if (!isWindows) {
|
|
177
|
-
return spawn(cmd, args, Object.assign({}, opts || {}, { detached: true }));
|
|
178
|
-
}
|
|
179
|
-
var newParams = [cmd].concat(args);
|
|
180
|
-
var target = path.join(__dirname, "..", "..", "vendor", "jobber", "Jobber.exe");
|
|
181
|
-
var options = __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { detached: true, jobber: true });
|
|
182
|
-
d("spawnDetached: ".concat(target, ", ").concat(newParams));
|
|
183
|
-
return spawn(target, newParams, options);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Spawns a process attached as a child of the current process.
|
|
187
|
-
*
|
|
188
|
-
* @param {string} exe The executable to run
|
|
189
|
-
* @param {string[]} params The parameters to pass to the child
|
|
190
|
-
* @param {SpawnOptions & SpawnRxExtras} opts Options to pass to spawn.
|
|
191
|
-
*
|
|
192
|
-
* @return {Observable<string>} Returns an Observable that when subscribed
|
|
193
|
-
* to, will create a child process. The
|
|
194
|
-
* process output will be streamed to this
|
|
195
|
-
* Observable, and if unsubscribed from, the
|
|
196
|
-
* process will be terminated early. If the
|
|
197
|
-
* process terminates with a non-zero value,
|
|
198
|
-
* the Observable will terminate with onError.
|
|
199
|
-
*/
|
|
200
|
-
function spawn(exe, params, opts) {
|
|
201
|
-
opts = opts !== null && opts !== void 0 ? opts : {};
|
|
202
|
-
var spawnObs = new rxjs_1.Observable(function (subj) {
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
204
|
-
var stdin = opts.stdin, jobber = opts.jobber, split = opts.split, encoding = opts.encoding, spawnOpts = __rest(opts, ["stdin", "jobber", "split", "encoding"]);
|
|
205
|
-
var _a = findActualExecutable(exe, params), cmd = _a.cmd, args = _a.args;
|
|
206
|
-
d("spawning process: ".concat(cmd, " ").concat(args.join(), ", ").concat(JSON.stringify(spawnOpts)));
|
|
207
|
-
var proc = (0, child_process_1.spawn)(cmd, args, spawnOpts);
|
|
208
|
-
var bufHandler = function (source) { return function (b) {
|
|
209
|
-
if (b.length < 1) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (opts.echoOutput) {
|
|
213
|
-
(source === "stdout" ? process.stdout : process.stderr).write(b);
|
|
214
|
-
}
|
|
215
|
-
var chunk = "<< String sent back was too long >>";
|
|
216
|
-
try {
|
|
217
|
-
if (typeof b === "string") {
|
|
218
|
-
chunk = b.toString();
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
chunk = b.toString(encoding || "utf8");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
catch (_a) {
|
|
225
|
-
chunk = "<< Lost chunk of process output for ".concat(exe, " - length was ").concat(b.length, ">>");
|
|
226
|
-
}
|
|
227
|
-
subj.next({ source: source, text: chunk });
|
|
228
|
-
}; };
|
|
229
|
-
var ret = new rxjs_1.Subscription();
|
|
230
|
-
if (opts.stdin) {
|
|
231
|
-
if (proc.stdin) {
|
|
232
|
-
ret.add(opts.stdin.subscribe({
|
|
233
|
-
next: function (x) { return proc.stdin.write(x); },
|
|
234
|
-
error: subj.error.bind(subj),
|
|
235
|
-
complete: function () { return proc.stdin.end(); },
|
|
236
|
-
}));
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
subj.error(new Error("opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required"));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
var stderrCompleted = null;
|
|
243
|
-
var stdoutCompleted = null;
|
|
244
|
-
var noClose = false;
|
|
245
|
-
if (proc.stdout) {
|
|
246
|
-
stdoutCompleted = new rxjs_1.AsyncSubject();
|
|
247
|
-
proc.stdout.on("data", bufHandler("stdout"));
|
|
248
|
-
proc.stdout.on("close", function () {
|
|
249
|
-
stdoutCompleted.next(true);
|
|
250
|
-
stdoutCompleted.complete();
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
stdoutCompleted = (0, rxjs_1.of)(true);
|
|
255
|
-
}
|
|
256
|
-
if (proc.stderr) {
|
|
257
|
-
stderrCompleted = new rxjs_1.AsyncSubject();
|
|
258
|
-
proc.stderr.on("data", bufHandler("stderr"));
|
|
259
|
-
proc.stderr.on("close", function () {
|
|
260
|
-
stderrCompleted.next(true);
|
|
261
|
-
stderrCompleted.complete();
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
stderrCompleted = (0, rxjs_1.of)(true);
|
|
266
|
-
}
|
|
267
|
-
proc.on("error", function (e) {
|
|
268
|
-
noClose = true;
|
|
269
|
-
subj.error(e);
|
|
270
|
-
});
|
|
271
|
-
proc.on("close", function (code) {
|
|
272
|
-
noClose = true;
|
|
273
|
-
var pipesClosed = (0, rxjs_1.merge)(stdoutCompleted, stderrCompleted).pipe((0, operators_1.reduce)(function (acc) { return acc; }, true));
|
|
274
|
-
if (code === 0) {
|
|
275
|
-
pipesClosed.subscribe(function () { return subj.complete(); });
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
pipesClosed.subscribe(function () {
|
|
279
|
-
var e = new Error("Failed with exit code: ".concat(code));
|
|
280
|
-
e.exitCode = code;
|
|
281
|
-
e.code = code;
|
|
282
|
-
subj.error(e);
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
ret.add(new rxjs_1.Subscription(function () {
|
|
287
|
-
if (noClose) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
d("Killing process: ".concat(cmd, " ").concat(args.join()));
|
|
291
|
-
if (opts.jobber) {
|
|
292
|
-
// NB: Connecting to Jobber's named pipe will kill it
|
|
293
|
-
net.connect("\\\\.\\pipe\\jobber-".concat(proc.pid));
|
|
294
|
-
setTimeout(function () { return proc.kill(); }, 5 * 1000);
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
proc.kill();
|
|
298
|
-
}
|
|
299
|
-
}));
|
|
300
|
-
return ret;
|
|
301
|
-
});
|
|
302
|
-
return opts.split ? spawnObs : spawnObs.pipe((0, operators_1.map)(function (x) { return x === null || x === void 0 ? void 0 : x.text; }));
|
|
303
|
-
}
|
|
304
|
-
function wrapObservableInPromise(obs) {
|
|
305
|
-
return new Promise(function (res, rej) {
|
|
306
|
-
var out = "";
|
|
307
|
-
obs.subscribe({
|
|
308
|
-
next: function (x) { return (out += x); },
|
|
309
|
-
error: function (e) {
|
|
310
|
-
var err = new Error("".concat(out, "\n").concat(e.message));
|
|
311
|
-
if ("exitCode" in e) {
|
|
312
|
-
err.exitCode = e.exitCode;
|
|
313
|
-
err.code = e.exitCode;
|
|
314
|
-
}
|
|
315
|
-
rej(err);
|
|
316
|
-
},
|
|
317
|
-
complete: function () { return res(out); },
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
function wrapObservableInSplitPromise(obs) {
|
|
322
|
-
return new Promise(function (res, rej) {
|
|
323
|
-
var out = "";
|
|
324
|
-
var err = "";
|
|
325
|
-
obs.subscribe({
|
|
326
|
-
next: function (x) { return (x.source === "stdout" ? (out += x.text) : (err += x.text)); },
|
|
327
|
-
error: function (e) {
|
|
328
|
-
var error = new Error("".concat(out, "\n").concat(e.message));
|
|
329
|
-
if ("exitCode" in e) {
|
|
330
|
-
error.exitCode = e.exitCode;
|
|
331
|
-
error.code = e.exitCode;
|
|
332
|
-
error.stdout = out;
|
|
333
|
-
error.stderr = err;
|
|
334
|
-
}
|
|
335
|
-
rej(error);
|
|
336
|
-
},
|
|
337
|
-
complete: function () { return res([out, err]); },
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Spawns a process but detached from the current process. The process is put
|
|
343
|
-
* into its own Process Group.
|
|
344
|
-
*
|
|
345
|
-
* @param {string} exe The executable to run
|
|
346
|
-
* @param {string[]} params The parameters to pass to the child
|
|
347
|
-
* @param {Object} opts Options to pass to spawn.
|
|
348
|
-
*
|
|
349
|
-
* @return {Promise<string>} Returns an Promise that represents a detached
|
|
350
|
-
* process. The value returned is the process
|
|
351
|
-
* output. If the process terminates with a
|
|
352
|
-
* non-zero value, the Promise will resolve with
|
|
353
|
-
* an Error.
|
|
354
|
-
*/
|
|
355
|
-
function spawnDetachedPromise(exe, params, opts) {
|
|
356
|
-
if (opts === null || opts === void 0 ? void 0 : opts.split) {
|
|
357
|
-
return wrapObservableInSplitPromise(spawnDetached(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: true })));
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
return wrapObservableInPromise(spawnDetached(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: false })));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Spawns a process as a child process.
|
|
365
|
-
*
|
|
366
|
-
* @param {string} exe The executable to run
|
|
367
|
-
* @param {string[]} params The parameters to pass to the child
|
|
368
|
-
* @param {Object} opts Options to pass to spawn.
|
|
369
|
-
*
|
|
370
|
-
* @return {Promise<string>} Returns an Promise that represents a child
|
|
371
|
-
* process. The value returned is the process
|
|
372
|
-
* output. If the process terminates with a
|
|
373
|
-
* non-zero value, the Promise will resolve with
|
|
374
|
-
* an Error.
|
|
375
|
-
*/
|
|
376
|
-
function spawnPromise(exe, params, opts) {
|
|
377
|
-
if (opts === null || opts === void 0 ? void 0 : opts.split) {
|
|
378
|
-
return wrapObservableInSplitPromise(spawn(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: true })));
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
return wrapObservableInPromise(spawn(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: false })));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
//# sourceMappingURL=index.js.map
|