@effectionx/process 0.6.2 → 0.7.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/CHANGELOG.md +269 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.d.ts.map +1 -0
- package/{esm → dist}/src/daemon.d.ts +1 -1
- package/dist/src/daemon.d.ts.map +1 -0
- package/{script → dist}/src/exec/api.d.ts +2 -4
- package/dist/src/exec/api.d.ts.map +1 -0
- package/{script → dist}/src/exec/error.d.ts +1 -1
- package/dist/src/exec/error.d.ts.map +1 -0
- package/dist/src/exec/error.js +29 -0
- package/dist/src/exec/posix.d.ts +3 -0
- package/dist/src/exec/posix.d.ts.map +1 -0
- package/{esm → dist}/src/exec/posix.js +12 -13
- package/{esm → dist}/src/exec/win32.d.ts +1 -1
- package/dist/src/exec/win32.d.ts.map +1 -0
- package/{esm → dist}/src/exec/win32.js +20 -13
- package/{script → dist}/src/exec.d.ts +3 -3
- package/dist/src/exec.d.ts.map +1 -0
- package/{esm → dist}/src/exec.js +2 -4
- package/dist/src/helpers.d.ts +4 -0
- package/dist/src/helpers.d.ts.map +1 -0
- package/dist/src/helpers.js +10 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/mod.ts +2 -0
- package/package.json +25 -19
- package/src/daemon.ts +34 -0
- package/src/exec/api.ts +83 -0
- package/src/exec/error.ts +43 -0
- package/src/exec/posix.ts +133 -0
- package/src/exec/win32.ts +217 -0
- package/src/exec.ts +100 -0
- package/src/helpers.ts +12 -0
- package/test/daemon.test.ts +106 -0
- package/test/eventemitter.test.ts +82 -0
- package/test/exec.test.ts +481 -0
- package/test/fixtures/dump-args.js +13 -0
- package/test/fixtures/echo-server.ts +49 -0
- package/test/fixtures/hello-world-failed.js +5 -0
- package/test/fixtures/hello-world.js +5 -0
- package/test/helpers.ts +69 -0
- package/test/output-stream.test.ts +73 -0
- package/tsconfig.json +20 -0
- package/esm/mod.d.ts +0 -3
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/src/daemon.d.ts.map +0 -1
- package/esm/src/eventemitter.d.ts +0 -22
- package/esm/src/eventemitter.d.ts.map +0 -1
- package/esm/src/eventemitter.js +0 -40
- package/esm/src/exec/api.d.ts +0 -70
- package/esm/src/exec/api.d.ts.map +0 -1
- package/esm/src/exec/error.d.ts +0 -14
- package/esm/src/exec/error.d.ts.map +0 -1
- package/esm/src/exec/error.js +0 -54
- package/esm/src/exec/posix.d.ts +0 -3
- package/esm/src/exec/posix.d.ts.map +0 -1
- package/esm/src/exec/win32.d.ts.map +0 -1
- package/esm/src/exec.d.ts +0 -16
- package/esm/src/exec.d.ts.map +0 -1
- package/esm/src/helpers.d.ts +0 -12
- package/esm/src/helpers.d.ts.map +0 -1
- package/esm/src/helpers.js +0 -71
- package/script/mod.d.ts +0 -3
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js +0 -20
- package/script/package.json +0 -3
- package/script/src/daemon.d.ts +0 -11
- package/script/src/daemon.d.ts.map +0 -1
- package/script/src/daemon.js +0 -23
- package/script/src/eventemitter.d.ts +0 -22
- package/script/src/eventemitter.d.ts.map +0 -1
- package/script/src/eventemitter.js +0 -44
- package/script/src/exec/api.d.ts.map +0 -1
- package/script/src/exec/api.js +0 -2
- package/script/src/exec/error.d.ts.map +0 -1
- package/script/src/exec/error.js +0 -59
- package/script/src/exec/posix.d.ts +0 -3
- package/script/src/exec/posix.d.ts.map +0 -1
- package/script/src/exec/posix.js +0 -117
- package/script/src/exec/win32.d.ts +0 -4
- package/script/src/exec/win32.d.ts.map +0 -1
- package/script/src/exec/win32.js +0 -177
- package/script/src/exec.d.ts.map +0 -1
- package/script/src/exec.js +0 -114
- package/script/src/helpers.d.ts +0 -12
- package/script/src/helpers.d.ts.map +0 -1
- package/script/src/helpers.js +0 -76
- /package/{esm → dist}/mod.js +0 -0
- /package/{esm → dist}/src/daemon.js +0 -0
- /package/{esm → dist}/src/exec/api.js +0 -0
package/script/src/exec/posix.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createPosixProcess = void 0;
|
|
7
|
-
const node_child_process_1 = require("node:child_process");
|
|
8
|
-
const effection_1 = require("effection");
|
|
9
|
-
const node_process_1 = __importDefault(require("node:process"));
|
|
10
|
-
const eventemitter_js_1 = require("../eventemitter.js");
|
|
11
|
-
const helpers_js_1 = require("../helpers.js");
|
|
12
|
-
const error_js_1 = require("./error.js");
|
|
13
|
-
const createPosixProcess = (command, options) => {
|
|
14
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
15
|
-
let processResult = (0, effection_1.withResolvers)();
|
|
16
|
-
// Killing all child processes started by this command is surprisingly
|
|
17
|
-
// tricky. If a process spawns another processes and we kill the parent,
|
|
18
|
-
// then the child process is NOT automatically killed. Instead we're using
|
|
19
|
-
// the `detached` option to force the child into its own process group,
|
|
20
|
-
// which all of its children in turn will inherit. By sending the signal to
|
|
21
|
-
// `-pid` rather than `pid`, we are sending it to the entire process group
|
|
22
|
-
// instead. This will send the signal to all processes started by the child
|
|
23
|
-
// process.
|
|
24
|
-
//
|
|
25
|
-
// More information here: https://unix.stackexchange.com/questions/14815/process-descendants
|
|
26
|
-
let childProcess = (0, node_child_process_1.spawn)(command, options.arguments || [], {
|
|
27
|
-
detached: true,
|
|
28
|
-
shell: options.shell,
|
|
29
|
-
env: options.env,
|
|
30
|
-
cwd: options.cwd,
|
|
31
|
-
stdio: "pipe",
|
|
32
|
-
});
|
|
33
|
-
let { pid } = childProcess;
|
|
34
|
-
let io = {
|
|
35
|
-
stdout: yield* (0, helpers_js_1.useReadable)(childProcess.stdout),
|
|
36
|
-
stderr: yield* (0, helpers_js_1.useReadable)(childProcess.stderr),
|
|
37
|
-
stdoutDone: (0, effection_1.withResolvers)(),
|
|
38
|
-
stderrDone: (0, effection_1.withResolvers)(),
|
|
39
|
-
};
|
|
40
|
-
let stdout = (0, effection_1.createSignal)();
|
|
41
|
-
let stderr = (0, effection_1.createSignal)();
|
|
42
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
43
|
-
let next = yield* io.stdout.next();
|
|
44
|
-
while (!next.done) {
|
|
45
|
-
stdout.send(next.value);
|
|
46
|
-
next = yield* io.stdout.next();
|
|
47
|
-
}
|
|
48
|
-
stdout.close();
|
|
49
|
-
io.stdoutDone.resolve();
|
|
50
|
-
});
|
|
51
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
52
|
-
let next = yield* io.stderr.next();
|
|
53
|
-
while (!next.done) {
|
|
54
|
-
stderr.send(next.value);
|
|
55
|
-
next = yield* io.stderr.next();
|
|
56
|
-
}
|
|
57
|
-
stderr.close();
|
|
58
|
-
io.stderrDone.resolve();
|
|
59
|
-
});
|
|
60
|
-
let stdin = {
|
|
61
|
-
send(data) {
|
|
62
|
-
childProcess.stdin.write(data);
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
yield* (0, effection_1.spawn)(function* trapError() {
|
|
66
|
-
let [error] = yield* (0, eventemitter_js_1.once)(childProcess, "error");
|
|
67
|
-
processResult.resolve((0, effection_1.Err)(error));
|
|
68
|
-
});
|
|
69
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
70
|
-
let value = yield* (0, eventemitter_js_1.once)(childProcess, "close");
|
|
71
|
-
processResult.resolve((0, effection_1.Ok)(value));
|
|
72
|
-
});
|
|
73
|
-
function* join() {
|
|
74
|
-
let result = yield* processResult.operation;
|
|
75
|
-
if (result.ok) {
|
|
76
|
-
let [code, signal] = result.value;
|
|
77
|
-
return { command, options, code, signal };
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
throw result.error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function* expect() {
|
|
84
|
-
let status = yield* join();
|
|
85
|
-
if (status.code != 0) {
|
|
86
|
-
throw new error_js_1.ExecError(status, command, options);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return status;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
yield* provide({
|
|
94
|
-
pid: pid,
|
|
95
|
-
stdin,
|
|
96
|
-
stdout,
|
|
97
|
-
stderr,
|
|
98
|
-
join,
|
|
99
|
-
expect,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
try {
|
|
104
|
-
if (typeof childProcess.pid === "undefined") {
|
|
105
|
-
// deno-lint-ignore no-unsafe-finally
|
|
106
|
-
throw new Error("no pid for childProcess");
|
|
107
|
-
}
|
|
108
|
-
node_process_1.default.kill(-childProcess.pid, "SIGTERM");
|
|
109
|
-
yield* (0, effection_1.all)([io.stdoutDone.operation, io.stderrDone.operation]);
|
|
110
|
-
}
|
|
111
|
-
catch (_e) {
|
|
112
|
-
// do nothing, process is probably already dead
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
exports.createPosixProcess = createPosixProcess;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../../src/src/exec/win32.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,UAAU,CAAC;AAkBtE,eAAO,MAAM,kBAAkB,EAAE,eA4KhC,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,OAAiC,CAAC"}
|
package/script/src/exec/win32.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWin32 = exports.createWin32Process = void 0;
|
|
4
|
-
const node_os_1 = require("node:os");
|
|
5
|
-
const effection_1 = require("effection");
|
|
6
|
-
// @ts-types="npm:@types/cross-spawn@6.0.6"
|
|
7
|
-
const cross_spawn_1 = require("cross-spawn");
|
|
8
|
-
const ctrlc_windows_1 = require("ctrlc-windows");
|
|
9
|
-
const eventemitter_js_1 = require("../eventemitter.js");
|
|
10
|
-
const helpers_js_1 = require("../helpers.js");
|
|
11
|
-
const error_js_1 = require("./error.js");
|
|
12
|
-
function* killTree(pid) {
|
|
13
|
-
try {
|
|
14
|
-
const killer = (0, cross_spawn_1.spawn)("cmd.exe", ["/c", "taskkill", "/PID", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
15
|
-
yield* (0, eventemitter_js_1.once)(killer, "close");
|
|
16
|
-
}
|
|
17
|
-
catch (_) {
|
|
18
|
-
// best-effort; ignore errors
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const createWin32Process = (command, options) => {
|
|
22
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
23
|
-
let processResult = (0, effection_1.withResolvers)();
|
|
24
|
-
// Windows-specific process spawning with different options than POSIX
|
|
25
|
-
let childProcess = (0, cross_spawn_1.spawn)(command, options.arguments || [], {
|
|
26
|
-
// We lose exit information and events if this is detached in windows
|
|
27
|
-
// and it opens a window in windows+powershell.
|
|
28
|
-
detached: false,
|
|
29
|
-
// The `shell` option is passed to `cross-spawn` to control whether a shell is used.
|
|
30
|
-
// On Windows, `shell: true` is necessary to run command strings, as it uses
|
|
31
|
-
// `cmd.exe` to parse the command and find executables in the PATH.
|
|
32
|
-
// Using a boolean `true` was previously disabled, causing ENOENT errors for
|
|
33
|
-
// commands that were not a direct path to an executable.
|
|
34
|
-
shell: options.shell || false,
|
|
35
|
-
// With stdio as pipe, windows gets stuck where neither the child nor the
|
|
36
|
-
// parent wants to close the stream, so we call it ourselves in the exit event.
|
|
37
|
-
stdio: "pipe",
|
|
38
|
-
// Hide the child window so that killing it will not block the parent
|
|
39
|
-
// with a Terminate Batch Process (Y/n)
|
|
40
|
-
windowsHide: true,
|
|
41
|
-
env: options.env,
|
|
42
|
-
cwd: options.cwd,
|
|
43
|
-
});
|
|
44
|
-
let { pid } = childProcess;
|
|
45
|
-
let io = {
|
|
46
|
-
stdout: yield* (0, helpers_js_1.useReadable)(childProcess.stdout),
|
|
47
|
-
stderr: yield* (0, helpers_js_1.useReadable)(childProcess.stderr),
|
|
48
|
-
stdoutDone: (0, effection_1.withResolvers)(),
|
|
49
|
-
stderrDone: (0, effection_1.withResolvers)(),
|
|
50
|
-
};
|
|
51
|
-
const stdout = (0, effection_1.createSignal)();
|
|
52
|
-
const stderr = (0, effection_1.createSignal)();
|
|
53
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
54
|
-
let next = yield* io.stdout.next();
|
|
55
|
-
while (!next.done) {
|
|
56
|
-
stdout.send(next.value);
|
|
57
|
-
next = yield* io.stdout.next();
|
|
58
|
-
}
|
|
59
|
-
stdout.close();
|
|
60
|
-
io.stdoutDone.resolve();
|
|
61
|
-
});
|
|
62
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
63
|
-
let next = yield* io.stderr.next();
|
|
64
|
-
while (!next.done) {
|
|
65
|
-
stderr.send(next.value);
|
|
66
|
-
next = yield* io.stderr.next();
|
|
67
|
-
}
|
|
68
|
-
stderr.close();
|
|
69
|
-
io.stderrDone.resolve();
|
|
70
|
-
});
|
|
71
|
-
let stdin = {
|
|
72
|
-
send(data) {
|
|
73
|
-
childProcess.stdin.write(data);
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
yield* (0, effection_1.spawn)(function* trapError() {
|
|
77
|
-
const [error] = yield* (0, eventemitter_js_1.once)(childProcess, "error");
|
|
78
|
-
processResult.resolve((0, effection_1.Err)(error));
|
|
79
|
-
});
|
|
80
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
81
|
-
let value = yield* (0, eventemitter_js_1.once)(childProcess, "close");
|
|
82
|
-
yield* (0, effection_1.all)([io.stdoutDone.operation, io.stderrDone.operation]);
|
|
83
|
-
processResult.resolve((0, effection_1.Ok)(value));
|
|
84
|
-
});
|
|
85
|
-
function* join() {
|
|
86
|
-
let result = yield* processResult.operation;
|
|
87
|
-
if (result.ok) {
|
|
88
|
-
let [code, signal] = result.value;
|
|
89
|
-
return { command, options, code, signal };
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
throw result.error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function* expect() {
|
|
96
|
-
let status = yield* join();
|
|
97
|
-
if (status.code != 0) {
|
|
98
|
-
throw new error_js_1.ExecError(status, command, options);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return status;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
yield* provide({
|
|
106
|
-
pid: pid,
|
|
107
|
-
stdin,
|
|
108
|
-
stdout,
|
|
109
|
-
stderr,
|
|
110
|
-
join,
|
|
111
|
-
expect,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
finally {
|
|
115
|
-
try {
|
|
116
|
-
// Only try to kill the process if it hasn't exited yet
|
|
117
|
-
if (childProcess.exitCode === null &&
|
|
118
|
-
childProcess.signalCode === null) {
|
|
119
|
-
if (typeof childProcess.pid === "undefined") {
|
|
120
|
-
// deno-lint-ignore no-unsafe-finally
|
|
121
|
-
throw new Error("no pid for childProcess");
|
|
122
|
-
}
|
|
123
|
-
let stdinStream = childProcess.stdin;
|
|
124
|
-
// Try graceful shutdown with ctrlc
|
|
125
|
-
try {
|
|
126
|
-
(0, ctrlc_windows_1.ctrlc)(childProcess.pid);
|
|
127
|
-
if (stdinStream.writable) {
|
|
128
|
-
try {
|
|
129
|
-
// Terminate batch process (Y/N)
|
|
130
|
-
stdinStream.write("Y\n");
|
|
131
|
-
}
|
|
132
|
-
catch (_err) {
|
|
133
|
-
// not much we can do here
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch (_err) {
|
|
138
|
-
// ctrlc might fail
|
|
139
|
-
}
|
|
140
|
-
// Close stdin to allow process to exit cleanly
|
|
141
|
-
try {
|
|
142
|
-
stdinStream.end();
|
|
143
|
-
}
|
|
144
|
-
catch (_err) {
|
|
145
|
-
// stdin might already be closed
|
|
146
|
-
}
|
|
147
|
-
// If process still hasn't exited, escalate
|
|
148
|
-
if (childProcess.exitCode === null &&
|
|
149
|
-
childProcess.signalCode === null) {
|
|
150
|
-
// Try regular kill first
|
|
151
|
-
try {
|
|
152
|
-
childProcess.kill();
|
|
153
|
-
}
|
|
154
|
-
catch (_err) {
|
|
155
|
-
// process might already be dead
|
|
156
|
-
}
|
|
157
|
-
// If still alive after kill, force-kill entire process tree
|
|
158
|
-
// This is necessary for bash on Windows where ctrlc doesn't work
|
|
159
|
-
// and child.kill() only kills the shell, leaving grandchildren alive
|
|
160
|
-
if (childProcess.exitCode === null &&
|
|
161
|
-
childProcess.signalCode === null) {
|
|
162
|
-
yield* killTree(childProcess.pid);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Wait for streams to finish
|
|
166
|
-
yield* (0, effection_1.all)([io.stdoutDone.operation, io.stderrDone.operation]);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
catch (_e) {
|
|
170
|
-
// do nothing, process is probably already dead
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
exports.createWin32Process = createWin32Process;
|
|
176
|
-
const isWin32 = () => (0, node_os_1.platform)() === "win32";
|
|
177
|
-
exports.isWin32 = isWin32;
|
package/script/src/exec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/src/exec.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAS,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAEV,WAAW,EAEX,OAAO,EACP,aAAa,EACd,MAAM,eAAe,CAAC;AAIvB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAEhC,MAAM,WAAW,IAAK,SAAQ,SAAS,CAAC,OAAO,CAAC;IAC9C,IAAI,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC;IACjC,MAAM,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC;CACpC;AAUD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAiErE"}
|
package/script/src/exec.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.exec = exec;
|
|
40
|
-
const shellwords = __importStar(require("shellwords"));
|
|
41
|
-
const effection_1 = require("effection");
|
|
42
|
-
const posix_js_1 = require("./exec/posix.js");
|
|
43
|
-
const win32_js_1 = require("./exec/win32.js");
|
|
44
|
-
__exportStar(require("./exec/api.js"), exports);
|
|
45
|
-
__exportStar(require("./exec/error.js"), exports);
|
|
46
|
-
const createProcess = (cmd, opts) => {
|
|
47
|
-
if ((0, win32_js_1.isWin32)()) {
|
|
48
|
-
return (0, win32_js_1.createWin32Process)(cmd, opts);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return (0, posix_js_1.createPosixProcess)(cmd, opts);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Execute `command` with `options`. You should use this operation for processes
|
|
56
|
-
* that have a finite lifetime and on which you may wish to synchronize on the
|
|
57
|
-
* exit status. If you want to start a process like a server that spins up and runs
|
|
58
|
-
* forever, consider using `daemon()`
|
|
59
|
-
*/
|
|
60
|
-
function exec(command, options = {}) {
|
|
61
|
-
let [cmd, ...args] = options.shell ? [command] : shellwords.split(command);
|
|
62
|
-
let opts = { ...options, arguments: args.concat(options.arguments || []) };
|
|
63
|
-
return {
|
|
64
|
-
*[Symbol.iterator]() {
|
|
65
|
-
return yield* createProcess(cmd, opts);
|
|
66
|
-
},
|
|
67
|
-
*join() {
|
|
68
|
-
const process = yield* createProcess(cmd, opts);
|
|
69
|
-
let stdout = "";
|
|
70
|
-
let stderr = "";
|
|
71
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
72
|
-
let subscription = yield* process.stdout;
|
|
73
|
-
let next = yield* subscription.next();
|
|
74
|
-
while (!next.done) {
|
|
75
|
-
stdout += next.value;
|
|
76
|
-
next = yield* subscription.next();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
80
|
-
let subscription = yield* process.stderr;
|
|
81
|
-
let next = yield* subscription.next();
|
|
82
|
-
while (!next.done) {
|
|
83
|
-
stderr += next.value;
|
|
84
|
-
next = yield* subscription.next();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
let status = yield* process.join();
|
|
88
|
-
return { ...status, stdout, stderr };
|
|
89
|
-
},
|
|
90
|
-
*expect() {
|
|
91
|
-
const process = yield* createProcess(cmd, opts);
|
|
92
|
-
let stdout = "";
|
|
93
|
-
let stderr = "";
|
|
94
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
95
|
-
let subscription = yield* process.stdout;
|
|
96
|
-
let next = yield* subscription.next();
|
|
97
|
-
while (!next.done) {
|
|
98
|
-
stdout += next.value;
|
|
99
|
-
next = yield* subscription.next();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
103
|
-
let subscription = yield* process.stderr;
|
|
104
|
-
let next = yield* subscription.next();
|
|
105
|
-
while (!next.done) {
|
|
106
|
-
stderr += next.value;
|
|
107
|
-
next = yield* subscription.next();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
let status = yield* process.expect();
|
|
111
|
-
return { ...status, stdout, stderr };
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
package/script/src/helpers.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type Operation, type Result, type Stream } from "effection";
|
|
2
|
-
import type { Readable } from "node:stream";
|
|
3
|
-
export type OutputStream = Stream<Uint8Array, void>;
|
|
4
|
-
export declare function useReadable(target: Readable | null): Stream<Uint8Array, void>;
|
|
5
|
-
interface Remainder<T> {
|
|
6
|
-
remainder: string;
|
|
7
|
-
result: T;
|
|
8
|
-
}
|
|
9
|
-
export declare function lines(): <T extends Uint8Array, TReturn>(stream: Stream<T, TReturn>) => Stream<string, Remainder<TReturn>>;
|
|
10
|
-
export declare function box<T>(op: () => Operation<T>): Operation<Result<T>>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EAEd,KAAK,MAAM,EACX,KAAK,MAAM,EACZ,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAEpD,wBAAgB,WAAW,CACzB,MAAM,EAAE,QAAQ,GAAG,IAAI,GACtB,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAoB1B;AAED,UAAU,SAAS,CAAC,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,CAAC;CACX;AAED,wBAAgB,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,EAAE,OAAO,EACrD,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,KACvB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAyCtC;AAED,wBAAiB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAOpE"}
|
package/script/src/helpers.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useReadable = useReadable;
|
|
4
|
-
exports.lines = lines;
|
|
5
|
-
exports.box = box;
|
|
6
|
-
const effection_1 = require("effection");
|
|
7
|
-
function useReadable(target) {
|
|
8
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
9
|
-
let signal = (0, effection_1.createSignal)();
|
|
10
|
-
let listener = (chunk) => {
|
|
11
|
-
signal.send(chunk);
|
|
12
|
-
};
|
|
13
|
-
target?.on("data", listener);
|
|
14
|
-
target?.on("end", signal.close);
|
|
15
|
-
try {
|
|
16
|
-
yield* provide(yield* signal);
|
|
17
|
-
}
|
|
18
|
-
finally {
|
|
19
|
-
target?.off("data", listener);
|
|
20
|
-
target?.off("end", signal.close);
|
|
21
|
-
signal.close();
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function lines() {
|
|
26
|
-
const decoder = new TextDecoder();
|
|
27
|
-
return function (stream) {
|
|
28
|
-
return {
|
|
29
|
-
*[Symbol.iterator]() {
|
|
30
|
-
let subscription = yield* stream;
|
|
31
|
-
let buffer = [];
|
|
32
|
-
let remainder = "";
|
|
33
|
-
return {
|
|
34
|
-
*next() {
|
|
35
|
-
while (buffer.length === 0) {
|
|
36
|
-
let next = yield* subscription.next();
|
|
37
|
-
if (next.done) {
|
|
38
|
-
return {
|
|
39
|
-
done: true,
|
|
40
|
-
value: {
|
|
41
|
-
remainder,
|
|
42
|
-
result: next.value,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
let current = remainder + decoder.decode(next.value);
|
|
48
|
-
let lines = current.split("\n");
|
|
49
|
-
if (lines.length > 0) {
|
|
50
|
-
buffer.push(...lines.slice(0, -1));
|
|
51
|
-
remainder = lines.slice(-1)[0];
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
remainder = current;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
done: false,
|
|
60
|
-
value: buffer.pop(),
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function* box(op) {
|
|
69
|
-
try {
|
|
70
|
-
let value = yield* op();
|
|
71
|
-
return (0, effection_1.Ok)(value);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
return (0, effection_1.Err)(e);
|
|
75
|
-
}
|
|
76
|
-
}
|
/package/{esm → dist}/mod.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|