@effect/platform-node 0.33.2 → 0.33.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Command from "@effect/platform/Command";
|
|
2
2
|
import * as CommandExecutor from "@effect/platform/CommandExecutor";
|
|
3
3
|
import * as FileSystem from "@effect/platform/FileSystem";
|
|
4
|
+
import * as Deferred from "effect/Deferred";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
6
|
import { constUndefined, pipe } from "effect/Function";
|
|
6
7
|
import * as Layer from "effect/Layer";
|
|
@@ -33,7 +34,7 @@ const runCommand = fileSystem => command => {
|
|
|
33
34
|
Option.match(command.cwd, {
|
|
34
35
|
onNone: () => Effect.unit,
|
|
35
36
|
onSome: dir => fileSystem.access(dir)
|
|
36
|
-
}), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.flatMap(env => Effect.
|
|
37
|
+
}), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.zip(Deferred.make()), Effect.flatMap(([env, exitCode]) => Effect.acquireRelease(Effect.sync(() => {
|
|
37
38
|
const handle = ChildProcess.spawn(command.command, command.args, {
|
|
38
39
|
stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
|
|
39
40
|
cwd: Option.getOrElse(command.cwd, constUndefined),
|
|
@@ -43,13 +44,18 @@ const runCommand = fileSystem => command => {
|
|
|
43
44
|
...Object.fromEntries(command.env)
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
exited = true;
|
|
47
|
+
handle.once("exit", () => {
|
|
48
|
+
Deferred.unsafeDone(exitCode, Effect.succeed([handle.exitCode, handle.signalCode]));
|
|
49
49
|
});
|
|
50
|
+
return [handle, exitCode];
|
|
51
|
+
}), ([handle, exitCode]) => Effect.flatMap(Deferred.isDone(exitCode), done => done ? Effect.unit : Effect.suspend(() => {
|
|
52
|
+
if (handle.pid && handle.kill("SIGTERM")) {
|
|
53
|
+
return Deferred.await(exitCode);
|
|
54
|
+
}
|
|
55
|
+
return Effect.unit;
|
|
56
|
+
})))), Effect.flatMap(([handle, exitCodeDeferred]) => Effect.async(resume => {
|
|
50
57
|
// If starting the process throws an error, make sure to capture it
|
|
51
58
|
handle.on("error", err => {
|
|
52
|
-
handle.kill("SIGKILL");
|
|
53
59
|
resume(Effect.fail(toPlatformError("spawn", err, command)));
|
|
54
60
|
});
|
|
55
61
|
// If the process is assigned a process identifier, then we know it
|
|
@@ -59,38 +65,17 @@ const runCommand = fileSystem => command => {
|
|
|
59
65
|
if (handle.stdin !== null) {
|
|
60
66
|
stdin = fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
|
|
61
67
|
}
|
|
62
|
-
const exitCode = Effect.
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
68
|
+
const exitCode = Effect.flatMap(Deferred.await(exitCodeDeferred), ([code, signal]) => {
|
|
69
|
+
if (code !== null) {
|
|
70
|
+
return Effect.succeed(CommandExecutor.ExitCode(code));
|
|
65
71
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// If code is `null`, then `signal` must be defined. See the NodeJS
|
|
71
|
-
// documentation for the `"exit"` event on a `child_process`.
|
|
72
|
-
// https://nodejs.org/api/child_process.html#child_process_event_exit
|
|
73
|
-
resume(Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command)));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
// Make sure to terminate the running process if the fiber is
|
|
77
|
-
// terminated
|
|
78
|
-
return Effect.sync(() => {
|
|
79
|
-
handle.kill("SIGKILL");
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
const isRunning = Effect.sync(() => handle.exitCode === null && handle.signalCode === null && !handle.killed);
|
|
83
|
-
const kill = (signal = "SIGTERM") => Effect.async(resume => {
|
|
84
|
-
handle.kill(signal);
|
|
85
|
-
handle.on("exit", () => {
|
|
86
|
-
resume(Effect.unit);
|
|
87
|
-
});
|
|
88
|
-
// Make sure to terminate the running process if the fiber
|
|
89
|
-
// is terminated
|
|
90
|
-
return Effect.sync(() => {
|
|
91
|
-
handle.kill("SIGKILL");
|
|
92
|
-
});
|
|
72
|
+
// If code is `null`, then `signal` must be defined. See the NodeJS
|
|
73
|
+
// documentation for the `"exit"` event on a `child_process`.
|
|
74
|
+
// https://nodejs.org/api/child_process.html#child_process_event_exit
|
|
75
|
+
return Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command));
|
|
93
76
|
});
|
|
77
|
+
const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred));
|
|
78
|
+
const kill = (signal = "SIGTERM") => Effect.flatMap(Effect.sync(() => handle.kill(signal)), success => success ? Effect.asUnit(Deferred.await(exitCodeDeferred)) : Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command)));
|
|
94
79
|
resume(Effect.sync(() => {
|
|
95
80
|
const pid = CommandExecutor.ProcessId(handle.pid);
|
|
96
81
|
const stderr = fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
|
|
@@ -111,14 +96,6 @@ const runCommand = fileSystem => command => {
|
|
|
111
96
|
};
|
|
112
97
|
}));
|
|
113
98
|
}
|
|
114
|
-
return Effect.async(resume => {
|
|
115
|
-
if (handle.pid) {
|
|
116
|
-
handle.kill("SIGTERM");
|
|
117
|
-
}
|
|
118
|
-
handle.on("exit", () => {
|
|
119
|
-
resume(Effect.unit);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
99
|
})), Effect.tap(process => Option.match(command.stdin, {
|
|
123
100
|
onNone: () => Effect.unit,
|
|
124
101
|
onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
|
|
@@ -134,7 +111,7 @@ const runCommand = fileSystem => command => {
|
|
|
134
111
|
const tail = flattened.slice(1);
|
|
135
112
|
const initial = tail.slice(0, tail.length - 1);
|
|
136
113
|
const last = tail[tail.length - 1];
|
|
137
|
-
const stream = initial.reduce((stdin, command) => pipe(Command.stdin(command, stdin), runCommand(fileSystem),
|
|
114
|
+
const stream = initial.reduce((stdin, command) => pipe(Command.stdin(command, stdin), runCommand(fileSystem), Effect.map(process => process.stdout), Stream.unwrapScoped), pipe(runCommand(fileSystem)(head), Effect.map(process => process.stdout), Stream.unwrapScoped));
|
|
138
115
|
return pipe(Command.stdin(last, stream), runCommand(fileSystem));
|
|
139
116
|
}
|
|
140
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandExecutor.js","names":["Command","CommandExecutor","FileSystem","Effect","constUndefined","pipe","Layer","Option","Sink","Stream","ChildProcess","handleErrnoException","fromWritable","fromReadable","inputToStdioOption","stdin","match","onNone","onSome","outputToStdioOption","output","toError","err","globalThis","Error","String","toPlatformError","method","error","command","flattened","flatten","reduce","acc","curr","args","join","length","runCommand","fileSystem","_tag","cwd","unit","dir","access","zipRight","sync","process","env","flatMap","
|
|
1
|
+
{"version":3,"file":"commandExecutor.js","names":["Command","CommandExecutor","FileSystem","Deferred","Effect","constUndefined","pipe","Layer","Option","Sink","Stream","ChildProcess","handleErrnoException","fromWritable","fromReadable","inputToStdioOption","stdin","match","onNone","onSome","outputToStdioOption","output","toError","err","globalThis","Error","String","toPlatformError","method","error","command","flattened","flatten","reduce","acc","curr","args","join","length","runCommand","fileSystem","_tag","cwd","unit","dir","access","zipRight","sync","process","env","zip","make","flatMap","exitCode","acquireRelease","handle","spawn","stdio","stdout","stderr","getOrElse","shell","Object","fromEntries","once","unsafeDone","succeed","signalCode","isDone","done","suspend","pid","kill","await","exitCodeDeferred","async","resume","on","fail","drain","code","signal","ExitCode","isRunning","negate","success","asUnit","ProcessId","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","map","unwrapScoped","layer","effect","makeExecutor"],"sources":["../../../src/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AC/BK,IAAI,CACFJ,UAAU,CAACA,UAAU,eACrBE,MAAM,CAAC+F,GAAG,CAAE3D,UAAU,IAAKvC,eAAe,CAACsG,YAAY,CAAChE,UAAU,CAACC,UAAU,CAAC,CAAC,CAAC,CACjF,CACF"}
|
|
@@ -7,6 +7,7 @@ exports.layer = void 0;
|
|
|
7
7
|
var Command = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Command"));
|
|
8
8
|
var CommandExecutor = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/CommandExecutor"));
|
|
9
9
|
var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem"));
|
|
10
|
+
var Deferred = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Deferred"));
|
|
10
11
|
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
11
12
|
var _Function = /*#__PURE__*/require("effect/Function");
|
|
12
13
|
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
@@ -64,7 +65,7 @@ const runCommand = fileSystem => command => {
|
|
|
64
65
|
Option.match(command.cwd, {
|
|
65
66
|
onNone: () => Effect.unit,
|
|
66
67
|
onSome: dir => fileSystem.access(dir)
|
|
67
|
-
}), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.flatMap(env => Effect.
|
|
68
|
+
}), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.zip(Deferred.make()), Effect.flatMap(([env, exitCode]) => Effect.acquireRelease(Effect.sync(() => {
|
|
68
69
|
const handle = ChildProcess.spawn(command.command, command.args, {
|
|
69
70
|
stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
|
|
70
71
|
cwd: Option.getOrElse(command.cwd, _Function.constUndefined),
|
|
@@ -74,13 +75,18 @@ const runCommand = fileSystem => command => {
|
|
|
74
75
|
...Object.fromEntries(command.env)
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
exited = true;
|
|
78
|
+
handle.once("exit", () => {
|
|
79
|
+
Deferred.unsafeDone(exitCode, Effect.succeed([handle.exitCode, handle.signalCode]));
|
|
80
80
|
});
|
|
81
|
+
return [handle, exitCode];
|
|
82
|
+
}), ([handle, exitCode]) => Effect.flatMap(Deferred.isDone(exitCode), done => done ? Effect.unit : Effect.suspend(() => {
|
|
83
|
+
if (handle.pid && handle.kill("SIGTERM")) {
|
|
84
|
+
return Deferred.await(exitCode);
|
|
85
|
+
}
|
|
86
|
+
return Effect.unit;
|
|
87
|
+
})))), Effect.flatMap(([handle, exitCodeDeferred]) => Effect.async(resume => {
|
|
81
88
|
// If starting the process throws an error, make sure to capture it
|
|
82
89
|
handle.on("error", err => {
|
|
83
|
-
handle.kill("SIGKILL");
|
|
84
90
|
resume(Effect.fail(toPlatformError("spawn", err, command)));
|
|
85
91
|
});
|
|
86
92
|
// If the process is assigned a process identifier, then we know it
|
|
@@ -90,38 +96,17 @@ const runCommand = fileSystem => command => {
|
|
|
90
96
|
if (handle.stdin !== null) {
|
|
91
97
|
stdin = (0, _sink.fromWritable)(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
|
|
92
98
|
}
|
|
93
|
-
const exitCode = Effect.
|
|
94
|
-
if (
|
|
95
|
-
return
|
|
99
|
+
const exitCode = Effect.flatMap(Deferred.await(exitCodeDeferred), ([code, signal]) => {
|
|
100
|
+
if (code !== null) {
|
|
101
|
+
return Effect.succeed(CommandExecutor.ExitCode(code));
|
|
96
102
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// If code is `null`, then `signal` must be defined. See the NodeJS
|
|
102
|
-
// documentation for the `"exit"` event on a `child_process`.
|
|
103
|
-
// https://nodejs.org/api/child_process.html#child_process_event_exit
|
|
104
|
-
resume(Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command)));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
// Make sure to terminate the running process if the fiber is
|
|
108
|
-
// terminated
|
|
109
|
-
return Effect.sync(() => {
|
|
110
|
-
handle.kill("SIGKILL");
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
const isRunning = Effect.sync(() => handle.exitCode === null && handle.signalCode === null && !handle.killed);
|
|
114
|
-
const kill = (signal = "SIGTERM") => Effect.async(resume => {
|
|
115
|
-
handle.kill(signal);
|
|
116
|
-
handle.on("exit", () => {
|
|
117
|
-
resume(Effect.unit);
|
|
118
|
-
});
|
|
119
|
-
// Make sure to terminate the running process if the fiber
|
|
120
|
-
// is terminated
|
|
121
|
-
return Effect.sync(() => {
|
|
122
|
-
handle.kill("SIGKILL");
|
|
123
|
-
});
|
|
103
|
+
// If code is `null`, then `signal` must be defined. See the NodeJS
|
|
104
|
+
// documentation for the `"exit"` event on a `child_process`.
|
|
105
|
+
// https://nodejs.org/api/child_process.html#child_process_event_exit
|
|
106
|
+
return Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command));
|
|
124
107
|
});
|
|
108
|
+
const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred));
|
|
109
|
+
const kill = (signal = "SIGTERM") => Effect.flatMap(Effect.sync(() => handle.kill(signal)), success => success ? Effect.asUnit(Deferred.await(exitCodeDeferred)) : Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command)));
|
|
125
110
|
resume(Effect.sync(() => {
|
|
126
111
|
const pid = CommandExecutor.ProcessId(handle.pid);
|
|
127
112
|
const stderr = (0, _stream.fromReadable)(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
|
|
@@ -142,14 +127,6 @@ const runCommand = fileSystem => command => {
|
|
|
142
127
|
};
|
|
143
128
|
}));
|
|
144
129
|
}
|
|
145
|
-
return Effect.async(resume => {
|
|
146
|
-
if (handle.pid) {
|
|
147
|
-
handle.kill("SIGTERM");
|
|
148
|
-
}
|
|
149
|
-
handle.on("exit", () => {
|
|
150
|
-
resume(Effect.unit);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
130
|
})), Effect.tap(process => Option.match(command.stdin, {
|
|
154
131
|
onNone: () => Effect.unit,
|
|
155
132
|
onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
|
|
@@ -165,7 +142,7 @@ const runCommand = fileSystem => command => {
|
|
|
165
142
|
const tail = flattened.slice(1);
|
|
166
143
|
const initial = tail.slice(0, tail.length - 1);
|
|
167
144
|
const last = tail[tail.length - 1];
|
|
168
|
-
const stream = initial.reduce((stdin, command) => (0, _Function.pipe)(Command.stdin(command, stdin), runCommand(fileSystem),
|
|
145
|
+
const stream = initial.reduce((stdin, command) => (0, _Function.pipe)(Command.stdin(command, stdin), runCommand(fileSystem), Effect.map(process => process.stdout), Stream.unwrapScoped), (0, _Function.pipe)(runCommand(fileSystem)(head), Effect.map(process => process.stdout), Stream.unwrapScoped));
|
|
169
146
|
return (0, _Function.pipe)(Command.stdin(last, stream), runCommand(fileSystem));
|
|
170
147
|
}
|
|
171
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandExecutor.js","names":["Command","_interopRequireWildcard","require","CommandExecutor","FileSystem","Effect","_Function","Layer","Option","Sink","Stream","ChildProcess","_error","_sink","_stream","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","inputToStdioOption","stdin","match","onNone","onSome","outputToStdioOption","output","toError","err","globalThis","Error","String","toPlatformError","method","error","command","flattened","flatten","reduce","acc","curr","args","join","length","handleErrnoException","runCommand","fileSystem","_tag","pipe","cwd","unit","dir","access","zipRight","sync","process","env","flatMap","
|
|
1
|
+
{"version":3,"file":"commandExecutor.js","names":["Command","_interopRequireWildcard","require","CommandExecutor","FileSystem","Deferred","Effect","_Function","Layer","Option","Sink","Stream","ChildProcess","_error","_sink","_stream","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","inputToStdioOption","stdin","match","onNone","onSome","outputToStdioOption","output","toError","err","globalThis","Error","String","toPlatformError","method","error","command","flattened","flatten","reduce","acc","curr","args","join","length","handleErrnoException","runCommand","fileSystem","_tag","pipe","cwd","unit","dir","access","zipRight","sync","process","env","zip","make","flatMap","exitCode","acquireRelease","handle","spawn","stdio","stdout","stderr","getOrElse","constUndefined","shell","fromEntries","once","unsafeDone","succeed","signalCode","isDone","done","suspend","pid","kill","await","exitCodeDeferred","async","resume","on","fail","drain","fromWritable","code","signal","ExitCode","isRunning","negate","success","asUnit","ProcessId","fromReadable","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","map","unwrapScoped","layer","exports","effect","makeExecutor"],"sources":["../src/internal/commandExecutor.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,OAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,eAAA,gBAAAF,uBAAA,eAAAC,OAAA;AAEA,IAAAE,UAAA,gBAAAH,uBAAA,eAAAC,OAAA;AACA,IAAAG,QAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AACA,IAAAI,MAAA,gBAAAL,uBAAA,eAAAC,OAAA;AACA,IAAAK,SAAA,gBAAAL,OAAA;AACA,IAAAM,KAAA,gBAAAP,uBAAA,eAAAC,OAAA;AACA,IAAAO,MAAA,gBAAAR,uBAAA,eAAAC,OAAA;AAEA,IAAAQ,IAAA,gBAAAT,uBAAA,eAAAC,OAAA;AACA,IAAAS,MAAA,gBAAAV,uBAAA,eAAAC,OAAA;AACA,IAAAU,YAAA,gBAAAX,uBAAA,eAAAC,OAAA;AACA,IAAAW,MAAA,gBAAAX,OAAA;AACA,IAAAY,KAAA,gBAAAZ,OAAA;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ED,IAAI,CAAC5D,MAAM,GAAG,CAAC,CAAC;QAC9C,MAAM+D,IAAI,GAAGH,IAAI,CAACA,IAAI,CAAC5D,MAAM,GAAG,CAAC,CAAC;QAClC,MAAMgE,MAAM,GAAGF,OAAO,CAACnE,MAAM,CAC3B,CAACjB,KAAK,EAAEc,OAAO,KACb,IAAA7C,SAAA,CAAA0D,IAAI,EACFjE,OAAO,CAACsC,KAAK,CAACc,OAAO,EAAEd,KAAK,CAAC,EAC7BwB,UAAU,CAACC,UAAU,CAAC,EACtBzD,MAAM,CAACuH,GAAG,CAAErD,OAAO,IAAKA,OAAO,CAACU,MAAM,CAAC,EACvCvE,MAAM,CAACmH,YAAY,CACpB,EACH,IAAAvH,SAAA,CAAA0D,IAAI,EACFH,UAAU,CAACC,UAAU,CAAC,CAACwD,IAAI,CAAC,EAC5BjH,MAAM,CAACuH,GAAG,CAAErD,OAAO,IAAKA,OAAO,CAACU,MAAM,CAAC,EACvCvE,MAAM,CAACmH,YAAY,CACpB,CACF;QACD,OAAO,IAAAvH,SAAA,CAAA0D,IAAI,EAACjE,OAAO,CAACsC,KAAK,CAACqF,IAAI,EAAEC,MAAM,CAAC,EAAE9D,UAAU,CAACC,UAAU,CAAC,CAAC;MAClE;EACF;AACF,CAAC;AAEH;AACO,MAAMgE,KAAK,GAAAC,OAAA,CAAAD,KAAA,gBAA+EvH,KAAK,CAACyH,MAAM,CAC3G9H,eAAe,CAACA,eAAe,eAC/B,IAAAI,SAAA,CAAA0D,IAAI,EACF7D,UAAU,CAACA,UAAU,eACrBE,MAAM,CAACuH,GAAG,CAAE9D,UAAU,IAAK5D,eAAe,CAAC+H,YAAY,CAACpE,UAAU,CAACC,UAAU,CAAC,CAAC,CAAC,CACjF,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform-node",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.3",
|
|
4
4
|
"description": "Unified interfaces for common platform-specific services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"mime": "^3.0.0",
|
|
14
14
|
"multipasta": "^0.1.19",
|
|
15
|
-
"@effect/platform": "0.32.
|
|
15
|
+
"@effect/platform": "0.32.2"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"effect": "2.0.0-next.58"
|
|
@@ -2,10 +2,12 @@ import * as Command from "@effect/platform/Command"
|
|
|
2
2
|
import * as CommandExecutor from "@effect/platform/CommandExecutor"
|
|
3
3
|
import type * as Error from "@effect/platform/Error"
|
|
4
4
|
import * as FileSystem from "@effect/platform/FileSystem"
|
|
5
|
+
import * as Deferred from "effect/Deferred"
|
|
5
6
|
import * as Effect from "effect/Effect"
|
|
6
7
|
import { constUndefined, pipe } from "effect/Function"
|
|
7
8
|
import * as Layer from "effect/Layer"
|
|
8
9
|
import * as Option from "effect/Option"
|
|
10
|
+
import type * as Scope from "effect/Scope"
|
|
9
11
|
import * as Sink from "effect/Sink"
|
|
10
12
|
import * as Stream from "effect/Stream"
|
|
11
13
|
import * as ChildProcess from "node:child_process"
|
|
@@ -35,7 +37,7 @@ const toPlatformError = (
|
|
|
35
37
|
|
|
36
38
|
const runCommand =
|
|
37
39
|
(fileSystem: FileSystem.FileSystem) =>
|
|
38
|
-
(command: Command.Command): Effect.Effect<
|
|
40
|
+
(command: Command.Command): Effect.Effect<Scope.Scope, Error.PlatformError, CommandExecutor.Process> => {
|
|
39
41
|
switch (command._tag) {
|
|
40
42
|
case "StandardCommand": {
|
|
41
43
|
return pipe(
|
|
@@ -45,26 +47,39 @@ const runCommand =
|
|
|
45
47
|
onSome: (dir) => fileSystem.access(dir)
|
|
46
48
|
}),
|
|
47
49
|
Effect.zipRight(Effect.sync(() => globalThis.process.env)),
|
|
48
|
-
Effect.
|
|
50
|
+
Effect.zip(Deferred.make<never, readonly [code: number | null, signal: NodeJS.Signals | null]>()),
|
|
51
|
+
Effect.flatMap(([env, exitCode]) =>
|
|
52
|
+
Effect.acquireRelease(
|
|
53
|
+
Effect.sync(() => {
|
|
54
|
+
const handle = ChildProcess.spawn(command.command, command.args, {
|
|
55
|
+
stdio: [
|
|
56
|
+
inputToStdioOption(command.stdin),
|
|
57
|
+
outputToStdioOption(command.stdout),
|
|
58
|
+
outputToStdioOption(command.stderr)
|
|
59
|
+
],
|
|
60
|
+
cwd: Option.getOrElse(command.cwd, constUndefined),
|
|
61
|
+
shell: command.shell,
|
|
62
|
+
env: { ...env, ...Object.fromEntries(command.env) }
|
|
63
|
+
})
|
|
64
|
+
handle.once("exit", () => {
|
|
65
|
+
Deferred.unsafeDone(exitCode, Effect.succeed([handle.exitCode, handle.signalCode] as const))
|
|
66
|
+
})
|
|
67
|
+
return [handle, exitCode] as const
|
|
68
|
+
}),
|
|
69
|
+
([handle, exitCode]) =>
|
|
70
|
+
Effect.flatMap(Deferred.isDone(exitCode), (done) =>
|
|
71
|
+
done ? Effect.unit : Effect.suspend(() => {
|
|
72
|
+
if (handle.pid && handle.kill("SIGTERM")) {
|
|
73
|
+
return Deferred.await(exitCode)
|
|
74
|
+
}
|
|
75
|
+
return Effect.unit
|
|
76
|
+
}))
|
|
77
|
+
)
|
|
78
|
+
),
|
|
79
|
+
Effect.flatMap(([handle, exitCodeDeferred]) =>
|
|
49
80
|
Effect.async<never, Error.PlatformError, CommandExecutor.Process>((resume) => {
|
|
50
|
-
const handle = ChildProcess.spawn(command.command, command.args, {
|
|
51
|
-
stdio: [
|
|
52
|
-
inputToStdioOption(command.stdin),
|
|
53
|
-
outputToStdioOption(command.stdout),
|
|
54
|
-
outputToStdioOption(command.stderr)
|
|
55
|
-
],
|
|
56
|
-
cwd: Option.getOrElse(command.cwd, constUndefined),
|
|
57
|
-
shell: command.shell,
|
|
58
|
-
env: { ...env, ...Object.fromEntries(command.env) }
|
|
59
|
-
})
|
|
60
|
-
let exited = false
|
|
61
|
-
handle.on("exit", () => {
|
|
62
|
-
exited = true
|
|
63
|
-
})
|
|
64
|
-
|
|
65
81
|
// If starting the process throws an error, make sure to capture it
|
|
66
82
|
handle.on("error", (err) => {
|
|
67
|
-
handle.kill("SIGKILL")
|
|
68
83
|
resume(Effect.fail(toPlatformError("spawn", err, command)))
|
|
69
84
|
})
|
|
70
85
|
|
|
@@ -80,64 +95,35 @@ const runCommand =
|
|
|
80
95
|
)
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
const exitCode: CommandExecutor.Process["exitCode"] = Effect.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
handle.exitCode !== null
|
|
87
|
-
? Effect.succeed(CommandExecutor.ExitCode(handle.exitCode))
|
|
88
|
-
: Effect.fail(
|
|
89
|
-
toPlatformError(
|
|
90
|
-
"exitCode",
|
|
91
|
-
new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`),
|
|
92
|
-
command
|
|
93
|
-
)
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
handle.on("exit", (code, signal) => {
|
|
98
|
+
const exitCode: CommandExecutor.Process["exitCode"] = Effect.flatMap(
|
|
99
|
+
Deferred.await(exitCodeDeferred),
|
|
100
|
+
([code, signal]) => {
|
|
99
101
|
if (code !== null) {
|
|
100
|
-
|
|
101
|
-
} else {
|
|
102
|
-
// If code is `null`, then `signal` must be defined. See the NodeJS
|
|
103
|
-
// documentation for the `"exit"` event on a `child_process`.
|
|
104
|
-
// https://nodejs.org/api/child_process.html#child_process_event_exit
|
|
105
|
-
resume(
|
|
106
|
-
Effect.fail(
|
|
107
|
-
toPlatformError(
|
|
108
|
-
"exitCode",
|
|
109
|
-
new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`),
|
|
110
|
-
command
|
|
111
|
-
)
|
|
112
|
-
)
|
|
113
|
-
)
|
|
102
|
+
return Effect.succeed(CommandExecutor.ExitCode(code))
|
|
114
103
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
!handle.killed
|
|
104
|
+
// If code is `null`, then `signal` must be defined. See the NodeJS
|
|
105
|
+
// documentation for the `"exit"` event on a `child_process`.
|
|
106
|
+
// https://nodejs.org/api/child_process.html#child_process_event_exit
|
|
107
|
+
return Effect.fail(
|
|
108
|
+
toPlatformError(
|
|
109
|
+
"exitCode",
|
|
110
|
+
new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`),
|
|
111
|
+
command
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
}
|
|
127
115
|
)
|
|
128
116
|
|
|
117
|
+
const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred))
|
|
118
|
+
|
|
129
119
|
const kill: CommandExecutor.Process["kill"] = (signal = "SIGTERM") =>
|
|
130
|
-
Effect.
|
|
131
|
-
handle.kill(signal)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return Effect.sync(() => {
|
|
138
|
-
handle.kill("SIGKILL")
|
|
139
|
-
})
|
|
140
|
-
})
|
|
120
|
+
Effect.flatMap(
|
|
121
|
+
Effect.sync(() => handle.kill(signal)),
|
|
122
|
+
(success) =>
|
|
123
|
+
success
|
|
124
|
+
? Effect.asUnit(Deferred.await(exitCodeDeferred))
|
|
125
|
+
: Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command))
|
|
126
|
+
)
|
|
141
127
|
|
|
142
128
|
resume(Effect.sync<CommandExecutor.Process>(() => {
|
|
143
129
|
const pid = CommandExecutor.ProcessId(handle.pid!)
|
|
@@ -168,14 +154,6 @@ const runCommand =
|
|
|
168
154
|
}
|
|
169
155
|
}))
|
|
170
156
|
}
|
|
171
|
-
return Effect.async<never, never, void>((resume) => {
|
|
172
|
-
if (handle.pid) {
|
|
173
|
-
handle.kill("SIGTERM")
|
|
174
|
-
}
|
|
175
|
-
handle.on("exit", () => {
|
|
176
|
-
resume(Effect.unit)
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
157
|
})
|
|
180
158
|
),
|
|
181
159
|
Effect.tap((process) =>
|
|
@@ -200,11 +178,13 @@ const runCommand =
|
|
|
200
178
|
pipe(
|
|
201
179
|
Command.stdin(command, stdin),
|
|
202
180
|
runCommand(fileSystem),
|
|
203
|
-
|
|
181
|
+
Effect.map((process) => process.stdout),
|
|
182
|
+
Stream.unwrapScoped
|
|
204
183
|
),
|
|
205
184
|
pipe(
|
|
206
185
|
runCommand(fileSystem)(head),
|
|
207
|
-
|
|
186
|
+
Effect.map((process) => process.stdout),
|
|
187
|
+
Stream.unwrapScoped
|
|
208
188
|
)
|
|
209
189
|
)
|
|
210
190
|
return pipe(Command.stdin(last, stream), runCommand(fileSystem))
|