@effect/platform-node 0.33.2 → 0.33.4

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";
@@ -28,98 +29,73 @@ const runCommand = fileSystem => command => {
28
29
  switch (command._tag) {
29
30
  case "StandardCommand":
30
31
  {
31
- return pipe(
32
- // Validate that the directory is accessible
33
- Option.match(command.cwd, {
34
- onNone: () => Effect.unit,
35
- onSome: dir => fileSystem.access(dir)
36
- }), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.flatMap(env => Effect.async(resume => {
32
+ const spawn = Effect.flatMap(Deferred.make(), exitCode => Effect.async(resume => {
37
33
  const handle = ChildProcess.spawn(command.command, command.args, {
38
34
  stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
39
35
  cwd: Option.getOrElse(command.cwd, constUndefined),
40
36
  shell: command.shell,
41
37
  env: {
42
- ...env,
38
+ ...process.env,
43
39
  ...Object.fromEntries(command.env)
44
40
  }
45
41
  });
46
- let exited = false;
47
- handle.on("exit", () => {
48
- exited = true;
49
- });
50
- // If starting the process throws an error, make sure to capture it
51
42
  handle.on("error", err => {
52
- handle.kill("SIGKILL");
53
43
  resume(Effect.fail(toPlatformError("spawn", err, command)));
54
44
  });
55
- // If the process is assigned a process identifier, then we know it
56
- // was spawned successfully
57
- if (handle.pid) {
58
- let stdin = Sink.drain;
59
- if (handle.stdin !== null) {
60
- stdin = fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
61
- }
62
- const exitCode = Effect.async(resume => {
63
- if (exited) {
64
- return resume(handle.exitCode !== null ? Effect.succeed(CommandExecutor.ExitCode(handle.exitCode)) : Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`), command)));
65
- }
66
- handle.on("exit", (code, signal) => {
67
- if (code !== null) {
68
- resume(Effect.succeed(CommandExecutor.ExitCode(code)));
69
- } else {
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
- });
93
- });
94
- resume(Effect.sync(() => {
95
- const pid = CommandExecutor.ProcessId(handle.pid);
96
- const stderr = fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
97
- let stdout = fromReadable(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
98
- // TODO: add Sink.isSink
99
- if (typeof command.stdout !== "string") {
100
- stdout = Stream.transduce(stdout, command.stdout);
101
- }
102
- return {
103
- [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
104
- pid,
105
- exitCode,
106
- isRunning,
107
- kill,
108
- stdin,
109
- stderr,
110
- stdout
111
- };
112
- }));
45
+ handle.on("exit", (...args) => {
46
+ Deferred.unsafeDone(exitCode, Effect.succeed(args));
47
+ });
48
+ handle.on("spawn", () => {
49
+ resume(Effect.succeed([handle, exitCode]));
50
+ });
51
+ return Effect.sync(() => {
52
+ handle.kill("SIGTERM");
53
+ });
54
+ }));
55
+ return pipe(
56
+ // Validate that the directory is accessible
57
+ Option.match(command.cwd, {
58
+ onNone: () => Effect.unit,
59
+ onSome: dir => fileSystem.access(dir)
60
+ }), Effect.zipRight(Effect.acquireRelease(spawn, ([handle, exitCode]) => Effect.flatMap(Deferred.isDone(exitCode), done => done ? Effect.unit : Effect.suspend(() => {
61
+ if (handle.kill("SIGTERM")) {
62
+ return Deferred.await(exitCode);
113
63
  }
114
- return Effect.async(resume => {
115
- if (handle.pid) {
116
- handle.kill("SIGTERM");
64
+ return Effect.unit;
65
+ })))), Effect.map(([handle, exitCodeDeferred]) => {
66
+ let stdin = Sink.drain;
67
+ if (handle.stdin !== null) {
68
+ stdin = fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
69
+ }
70
+ const exitCode = Effect.flatMap(Deferred.await(exitCodeDeferred), ([code, signal]) => {
71
+ if (code !== null) {
72
+ return Effect.succeed(CommandExecutor.ExitCode(code));
117
73
  }
118
- handle.on("exit", () => {
119
- resume(Effect.unit);
120
- });
74
+ // If code is `null`, then `signal` must be defined. See the NodeJS
75
+ // documentation for the `"exit"` event on a `child_process`.
76
+ // https://nodejs.org/api/child_process.html#child_process_event_exit
77
+ return Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command));
121
78
  });
122
- })), Effect.tap(process => Option.match(command.stdin, {
79
+ const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred));
80
+ const kill = (signal = "SIGTERM") => Effect.suspend(() => handle.kill(signal) ? Effect.asUnit(Deferred.await(exitCodeDeferred)) : Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command)));
81
+ const pid = CommandExecutor.ProcessId(handle.pid);
82
+ const stderr = fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
83
+ let stdout = fromReadable(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
84
+ // TODO: add Sink.isSink
85
+ if (typeof command.stdout !== "string") {
86
+ stdout = Stream.transduce(stdout, command.stdout);
87
+ }
88
+ return {
89
+ [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
90
+ pid,
91
+ exitCode,
92
+ isRunning,
93
+ kill,
94
+ stdin,
95
+ stderr,
96
+ stdout
97
+ };
98
+ }), Effect.tap(process => Option.match(command.stdin, {
123
99
  onNone: () => Effect.unit,
124
100
  onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
125
101
  })));
@@ -134,7 +110,7 @@ const runCommand = fileSystem => command => {
134
110
  const tail = flattened.slice(1);
135
111
  const initial = tail.slice(0, tail.length - 1);
136
112
  const last = tail[tail.length - 1];
137
- const stream = initial.reduce((stdin, command) => pipe(Command.stdin(command, stdin), runCommand(fileSystem), Stream.flatMap(process => process.stdout)), pipe(runCommand(fileSystem)(head), Stream.flatMap(process => process.stdout)));
113
+ 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
114
  return pipe(Command.stdin(last, stream), runCommand(fileSystem));
139
115
  }
140
116
  }
@@ -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","async","resume","handle","spawn","stdio","stdout","stderr","getOrElse","shell","Object","fromEntries","exited","on","kill","fail","pid","drain","exitCode","succeed","ExitCode","signalCode","code","signal","isRunning","killed","ProcessId","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","layer","effect","map","makeExecutor"],"sources":["../../../src/internal/commandExecutor.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,OAAO,MAAM,0BAA0B;AACnD,OAAO,KAAKC,eAAe,MAAM,kCAAkC;AAEnE,OAAO,KAAKC,UAAU,MAAM,6BAA6B;AACzD,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,cAAc,EAAEC,IAAI,QAAQ,iBAAiB;AACtD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,YAAY,MAAM,oBAAoB;AAClD,SAASC,oBAAoB,QAAQ,YAAY;AACjD,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,YAAY,QAAQ,aAAa;AAE1C,MAAMC,kBAAkB,GAAIC,KAA2C,IACrER,MAAM,CAACS,KAAK,CAACD,KAAK,EAAE;EAAEE,MAAM,EAAEA,CAAA,KAAM,SAAS;EAAEC,MAAM,EAAEA,CAAA,KAAM;AAAM,CAAE,CAAC;AAExE,MAAMC,mBAAmB,GAAIC,MAA8B,IACzD,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG,MAAM;AAE9C,MAAMC,OAAO,GAAIC,GAAY,IAAYA,GAAG,YAAYC,UAAU,CAACC,KAAK,GAAGF,GAAG,GAAG,IAAIC,UAAU,CAACC,KAAK,CAACC,MAAM,CAACH,GAAG,CAAC,CAAC;AAElH,MAAMI,eAAe,GAAGA,CACtBC,MAAc,EACdC,KAA4B,EAC5BC,OAAwB,KACD;EACvB,MAAMC,SAAS,GAAG9B,OAAO,CAAC+B,OAAO,CAACF,OAAO,CAAC,CAACG,MAAM,CAAC,CAACC,GAAG,EAAEC,IAAI,KAAI;IAC9D,MAAML,OAAO,GAAG,GAAGK,IAA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AC3GvF,eAAe,CAACA,eAAe,eAC/BI,IAAI,CACFH,UAAU,CAACA,UAAU,eACrBC,MAAM,CAACsF,GAAG,CAAElD,UAAU,IAAKtC,eAAe,CAACyF,YAAY,CAACpD,UAAU,CAACC,UAAU,CAAC,CAAC,CAAC,CACjF,CACF"}
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","spawn","flatMap","make","exitCode","async","resume","handle","stdio","stdout","stderr","cwd","getOrElse","shell","env","process","Object","fromEntries","on","fail","unsafeDone","succeed","sync","kill","unit","dir","access","zipRight","acquireRelease","isDone","done","suspend","await","map","exitCodeDeferred","drain","code","signal","ExitCode","isRunning","negate","asUnit","pid","ProcessId","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","unwrapScoped","layer","effect","makeExecutor"],"sources":["../../../src/internal/commandExecutor.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,OAAO,MAAM,0BAA0B;AACnD,OAAO,KAAKC,eAAe,MAAM,kCAAkC;AAEnE,OAAO,KAAKC,UAAU,MAAM,6BAA6B;AACzD,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,cAAc,EAAEC,IAAI,QAAQ,iBAAiB;AACtD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,YAAY,MAAM,oBAAoB;AAClD,SAASC,oBAAoB,QAAQ,YAAY;AACj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7BuB,UAAU,CAACC,UAAU,CAAC,EACtBpC,MAAM,CAACsE,GAAG,CAAElB,OAAO,IAAKA,OAAO,CAACN,MAAM,CAAC,EACvCxC,MAAM,CAACsF,YAAY,CACpB,EACH1F,IAAI,CACFiC,UAAU,CAACC,UAAU,CAAC,CAACkD,IAAI,CAAC,EAC5BtF,MAAM,CAACsE,GAAG,CAAElB,OAAO,IAAKA,OAAO,CAACN,MAAM,CAAC,EACvCxC,MAAM,CAACsF,YAAY,CACpB,CACF;QACD,OAAO1F,IAAI,CAACN,OAAO,CAACgB,KAAK,CAAC8E,IAAI,EAAEC,MAAM,CAAC,EAAExD,UAAU,CAACC,UAAU,CAAC,CAAC;MAClE;EACF;AACF,CAAC;AAEH;AACA,OAAO,MAAMyD,KAAK,gBAA+E1F,KAAK,CAAC2F,MAAM,CAC3GjG,eAAe,CAACA,eAAe,eAC/BK,IAAI,CACFJ,UAAU,CAACA,UAAU,eACrBE,MAAM,CAACsE,GAAG,CAAElC,UAAU,IAAKvC,eAAe,CAACkG,YAAY,CAAC5D,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"));
@@ -59,98 +60,73 @@ const runCommand = fileSystem => command => {
59
60
  switch (command._tag) {
60
61
  case "StandardCommand":
61
62
  {
62
- return (0, _Function.pipe)(
63
- // Validate that the directory is accessible
64
- Option.match(command.cwd, {
65
- onNone: () => Effect.unit,
66
- onSome: dir => fileSystem.access(dir)
67
- }), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.flatMap(env => Effect.async(resume => {
63
+ const spawn = Effect.flatMap(Deferred.make(), exitCode => Effect.async(resume => {
68
64
  const handle = ChildProcess.spawn(command.command, command.args, {
69
65
  stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
70
66
  cwd: Option.getOrElse(command.cwd, _Function.constUndefined),
71
67
  shell: command.shell,
72
68
  env: {
73
- ...env,
69
+ ...process.env,
74
70
  ...Object.fromEntries(command.env)
75
71
  }
76
72
  });
77
- let exited = false;
78
- handle.on("exit", () => {
79
- exited = true;
80
- });
81
- // If starting the process throws an error, make sure to capture it
82
73
  handle.on("error", err => {
83
- handle.kill("SIGKILL");
84
74
  resume(Effect.fail(toPlatformError("spawn", err, command)));
85
75
  });
86
- // If the process is assigned a process identifier, then we know it
87
- // was spawned successfully
88
- if (handle.pid) {
89
- let stdin = Sink.drain;
90
- if (handle.stdin !== null) {
91
- stdin = (0, _sink.fromWritable)(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
92
- }
93
- const exitCode = Effect.async(resume => {
94
- if (exited) {
95
- return resume(handle.exitCode !== null ? Effect.succeed(CommandExecutor.ExitCode(handle.exitCode)) : Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`), command)));
96
- }
97
- handle.on("exit", (code, signal) => {
98
- if (code !== null) {
99
- resume(Effect.succeed(CommandExecutor.ExitCode(code)));
100
- } else {
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
- });
124
- });
125
- resume(Effect.sync(() => {
126
- const pid = CommandExecutor.ProcessId(handle.pid);
127
- const stderr = (0, _stream.fromReadable)(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
128
- let stdout = (0, _stream.fromReadable)(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
129
- // TODO: add Sink.isSink
130
- if (typeof command.stdout !== "string") {
131
- stdout = Stream.transduce(stdout, command.stdout);
132
- }
133
- return {
134
- [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
135
- pid,
136
- exitCode,
137
- isRunning,
138
- kill,
139
- stdin,
140
- stderr,
141
- stdout
142
- };
143
- }));
76
+ handle.on("exit", (...args) => {
77
+ Deferred.unsafeDone(exitCode, Effect.succeed(args));
78
+ });
79
+ handle.on("spawn", () => {
80
+ resume(Effect.succeed([handle, exitCode]));
81
+ });
82
+ return Effect.sync(() => {
83
+ handle.kill("SIGTERM");
84
+ });
85
+ }));
86
+ return (0, _Function.pipe)(
87
+ // Validate that the directory is accessible
88
+ Option.match(command.cwd, {
89
+ onNone: () => Effect.unit,
90
+ onSome: dir => fileSystem.access(dir)
91
+ }), Effect.zipRight(Effect.acquireRelease(spawn, ([handle, exitCode]) => Effect.flatMap(Deferred.isDone(exitCode), done => done ? Effect.unit : Effect.suspend(() => {
92
+ if (handle.kill("SIGTERM")) {
93
+ return Deferred.await(exitCode);
144
94
  }
145
- return Effect.async(resume => {
146
- if (handle.pid) {
147
- handle.kill("SIGTERM");
95
+ return Effect.unit;
96
+ })))), Effect.map(([handle, exitCodeDeferred]) => {
97
+ let stdin = Sink.drain;
98
+ if (handle.stdin !== null) {
99
+ stdin = (0, _sink.fromWritable)(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
100
+ }
101
+ const exitCode = Effect.flatMap(Deferred.await(exitCodeDeferred), ([code, signal]) => {
102
+ if (code !== null) {
103
+ return Effect.succeed(CommandExecutor.ExitCode(code));
148
104
  }
149
- handle.on("exit", () => {
150
- resume(Effect.unit);
151
- });
105
+ // If code is `null`, then `signal` must be defined. See the NodeJS
106
+ // documentation for the `"exit"` event on a `child_process`.
107
+ // https://nodejs.org/api/child_process.html#child_process_event_exit
108
+ return Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command));
152
109
  });
153
- })), Effect.tap(process => Option.match(command.stdin, {
110
+ const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred));
111
+ const kill = (signal = "SIGTERM") => Effect.suspend(() => handle.kill(signal) ? Effect.asUnit(Deferred.await(exitCodeDeferred)) : Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command)));
112
+ const pid = CommandExecutor.ProcessId(handle.pid);
113
+ const stderr = (0, _stream.fromReadable)(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
114
+ let stdout = (0, _stream.fromReadable)(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
115
+ // TODO: add Sink.isSink
116
+ if (typeof command.stdout !== "string") {
117
+ stdout = Stream.transduce(stdout, command.stdout);
118
+ }
119
+ return {
120
+ [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
121
+ pid,
122
+ exitCode,
123
+ isRunning,
124
+ kill,
125
+ stdin,
126
+ stderr,
127
+ stdout
128
+ };
129
+ }), Effect.tap(process => Option.match(command.stdin, {
154
130
  onNone: () => Effect.unit,
155
131
  onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
156
132
  })));
@@ -165,7 +141,7 @@ const runCommand = fileSystem => command => {
165
141
  const tail = flattened.slice(1);
166
142
  const initial = tail.slice(0, tail.length - 1);
167
143
  const last = tail[tail.length - 1];
168
- const stream = initial.reduce((stdin, command) => (0, _Function.pipe)(Command.stdin(command, stdin), runCommand(fileSystem), Stream.flatMap(process => process.stdout)), (0, _Function.pipe)(runCommand(fileSystem)(head), Stream.flatMap(process => process.stdout)));
144
+ 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
145
  return (0, _Function.pipe)(Command.stdin(last, stream), runCommand(fileSystem));
170
146
  }
171
147
  }
@@ -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","async","resume","handle","spawn","stdio","stdout","stderr","getOrElse","constUndefined","shell","fromEntries","exited","on","kill","fail","pid","drain","fromWritable","exitCode","succeed","ExitCode","signalCode","code","signal","isRunning","killed","ProcessId","fromReadable","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","layer","exports","effect","map","makeExecutor"],"sources":["../src/internal/commandExecutor.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,OAAA,gBA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EAAEnD,UAAU,CAACC,UAAU,CAAC,CAAC;MAClE;EACF;AACF,CAAC;AAEH;AACO,MAAMmD,KAAK,GAAAC,OAAA,CAAAD,KAAA,gBAA+E1G,KAAK,CAAC4G,MAAM,CAC3GhH,eAAe,CAACA,eAAe,eAC/B,IAAAG,SAAA,CAAA0D,IAAI,EACF5D,UAAU,CAACA,UAAU,eACrBC,MAAM,CAAC+G,GAAG,CAAEtD,UAAU,IAAK3D,eAAe,CAACkH,YAAY,CAACxD,UAAU,CAACC,UAAU,CAAC,CAAC,CAAC,CACjF,CACF"}
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","spawn","flatMap","make","exitCode","async","resume","handle","stdio","stdout","stderr","cwd","getOrElse","constUndefined","shell","env","process","fromEntries","on","fail","unsafeDone","succeed","sync","kill","pipe","unit","dir","access","zipRight","acquireRelease","isDone","done","suspend","await","map","exitCodeDeferred","drain","fromWritable","code","signal","ExitCode","isRunning","negate","asUnit","pid","ProcessId","fromReadable","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","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,g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G,CAAEnC,UAAU,IAAK5D,eAAe,CAAC2H,YAAY,CAAChE,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.2",
3
+ "version": "0.33.4",
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.1"
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"
@@ -33,151 +35,128 @@ const toPlatformError = (
33
35
  return handleErrnoException("Command", method)(error, [flattened])
34
36
  }
35
37
 
38
+ type ExitCode = readonly [code: number | null, signal: NodeJS.Signals | null]
39
+ type ExitCodeDeferred = Deferred.Deferred<never, ExitCode>
40
+
36
41
  const runCommand =
37
42
  (fileSystem: FileSystem.FileSystem) =>
38
- (command: Command.Command): Effect.Effect<never, Error.PlatformError, CommandExecutor.Process> => {
43
+ (command: Command.Command): Effect.Effect<Scope.Scope, Error.PlatformError, CommandExecutor.Process> => {
39
44
  switch (command._tag) {
40
45
  case "StandardCommand": {
46
+ const spawn = Effect.flatMap(
47
+ Deferred.make<never, ExitCode>(),
48
+ (exitCode) =>
49
+ Effect.async<never, Error.PlatformError, readonly [ChildProcess.ChildProcess, ExitCodeDeferred]>(
50
+ (resume) => {
51
+ const handle = ChildProcess.spawn(command.command, command.args, {
52
+ stdio: [
53
+ inputToStdioOption(command.stdin),
54
+ outputToStdioOption(command.stdout),
55
+ outputToStdioOption(command.stderr)
56
+ ],
57
+ cwd: Option.getOrElse(command.cwd, constUndefined),
58
+ shell: command.shell,
59
+ env: { ...process.env, ...Object.fromEntries(command.env) }
60
+ })
61
+ handle.on("error", (err) => {
62
+ resume(Effect.fail(toPlatformError("spawn", err, command)))
63
+ })
64
+ handle.on("exit", (...args) => {
65
+ Deferred.unsafeDone(exitCode, Effect.succeed(args))
66
+ })
67
+ handle.on("spawn", () => {
68
+ resume(Effect.succeed([handle, exitCode]))
69
+ })
70
+ return Effect.sync(() => {
71
+ handle.kill("SIGTERM")
72
+ })
73
+ }
74
+ )
75
+ )
41
76
  return pipe(
42
77
  // Validate that the directory is accessible
43
78
  Option.match(command.cwd, {
44
79
  onNone: () => Effect.unit,
45
80
  onSome: (dir) => fileSystem.access(dir)
46
81
  }),
47
- Effect.zipRight(Effect.sync(() => globalThis.process.env)),
48
- Effect.flatMap((env) =>
49
- 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
- // If starting the process throws an error, make sure to capture it
66
- handle.on("error", (err) => {
67
- handle.kill("SIGKILL")
68
- resume(Effect.fail(toPlatformError("spawn", err, command)))
69
- })
82
+ Effect.zipRight(
83
+ Effect.acquireRelease(
84
+ spawn,
85
+ ([handle, exitCode]) =>
86
+ Effect.flatMap(Deferred.isDone(exitCode), (done) =>
87
+ done ? Effect.unit : Effect.suspend(() => {
88
+ if (handle.kill("SIGTERM")) {
89
+ return Deferred.await(exitCode)
90
+ }
91
+ return Effect.unit
92
+ }))
93
+ )
94
+ ),
95
+ Effect.map(([handle, exitCodeDeferred]): CommandExecutor.Process => {
96
+ let stdin: Sink.Sink<never, Error.PlatformError, unknown, never, void> = Sink.drain
70
97
 
71
- // If the process is assigned a process identifier, then we know it
72
- // was spawned successfully
73
- if (handle.pid) {
74
- let stdin: Sink.Sink<never, Error.PlatformError, unknown, never, void> = Sink.drain
98
+ if (handle.stdin !== null) {
99
+ stdin = fromWritable(
100
+ () => handle.stdin!,
101
+ (err) => toPlatformError("toWritable", toError(err), command)
102
+ )
103
+ }
75
104
 
76
- if (handle.stdin !== null) {
77
- stdin = fromWritable(
78
- () => handle.stdin!,
79
- (err) => toPlatformError("toWritable", toError(err), command)
80
- )
105
+ const exitCode: CommandExecutor.Process["exitCode"] = Effect.flatMap(
106
+ Deferred.await(exitCodeDeferred),
107
+ ([code, signal]) => {
108
+ if (code !== null) {
109
+ return Effect.succeed(CommandExecutor.ExitCode(code))
81
110
  }
82
-
83
- const exitCode: CommandExecutor.Process["exitCode"] = Effect.async((resume) => {
84
- if (exited) {
85
- return resume(
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) => {
99
- if (code !== null) {
100
- resume(Effect.succeed(CommandExecutor.ExitCode(code)))
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
- )
114
- }
115
- })
116
- // Make sure to terminate the running process if the fiber is
117
- // terminated
118
- return Effect.sync(() => {
119
- handle.kill("SIGKILL")
120
- })
121
- })
122
-
123
- const isRunning = Effect.sync(() =>
124
- handle.exitCode === null &&
125
- handle.signalCode === null &&
126
- !handle.killed
111
+ // If code is `null`, then `signal` must be defined. See the NodeJS
112
+ // documentation for the `"exit"` event on a `child_process`.
113
+ // https://nodejs.org/api/child_process.html#child_process_event_exit
114
+ return Effect.fail(
115
+ toPlatformError(
116
+ "exitCode",
117
+ new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`),
118
+ command
119
+ )
127
120
  )
121
+ }
122
+ )
128
123
 
129
- const kill: CommandExecutor.Process["kill"] = (signal = "SIGTERM") =>
130
- Effect.async((resume) => {
131
- handle.kill(signal)
132
- handle.on("exit", () => {
133
- resume(Effect.unit)
134
- })
135
- // Make sure to terminate the running process if the fiber
136
- // is terminated
137
- return Effect.sync(() => {
138
- handle.kill("SIGKILL")
139
- })
140
- })
124
+ const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred))
141
125
 
142
- resume(Effect.sync<CommandExecutor.Process>(() => {
143
- const pid = CommandExecutor.ProcessId(handle.pid!)
144
- const stderr = fromReadable<Error.PlatformError, Uint8Array>(
145
- () => handle.stderr!,
146
- (err) => toPlatformError("fromReadable(stderr)", toError(err), command)
147
- )
148
- let stdout: Stream.Stream<never, Error.PlatformError, Uint8Array> = fromReadable<
149
- Error.PlatformError,
150
- Uint8Array
151
- >(
152
- () => handle.stdout!,
153
- (err) => toPlatformError("fromReadable(stdout)", toError(err), command)
154
- )
155
- // TODO: add Sink.isSink
156
- if (typeof command.stdout !== "string") {
157
- stdout = Stream.transduce(stdout, command.stdout)
158
- }
159
- return {
160
- [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
161
- pid,
162
- exitCode,
163
- isRunning,
164
- kill,
165
- stdin,
166
- stderr,
167
- stdout
168
- }
169
- }))
170
- }
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
- })
180
- ),
126
+ const kill: CommandExecutor.Process["kill"] = (signal = "SIGTERM") =>
127
+ Effect.suspend(() =>
128
+ handle.kill(signal)
129
+ ? Effect.asUnit(Deferred.await(exitCodeDeferred))
130
+ : Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command))
131
+ )
132
+
133
+ const pid = CommandExecutor.ProcessId(handle.pid!)
134
+ const stderr = fromReadable<Error.PlatformError, Uint8Array>(
135
+ () => handle.stderr!,
136
+ (err) => toPlatformError("fromReadable(stderr)", toError(err), command)
137
+ )
138
+ let stdout: Stream.Stream<never, Error.PlatformError, Uint8Array> = fromReadable<
139
+ Error.PlatformError,
140
+ Uint8Array
141
+ >(
142
+ () => handle.stdout!,
143
+ (err) => toPlatformError("fromReadable(stdout)", toError(err), command)
144
+ )
145
+ // TODO: add Sink.isSink
146
+ if (typeof command.stdout !== "string") {
147
+ stdout = Stream.transduce(stdout, command.stdout)
148
+ }
149
+ return {
150
+ [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
151
+ pid,
152
+ exitCode,
153
+ isRunning,
154
+ kill,
155
+ stdin,
156
+ stderr,
157
+ stdout
158
+ }
159
+ }),
181
160
  Effect.tap((process) =>
182
161
  Option.match(command.stdin, {
183
162
  onNone: () => Effect.unit,
@@ -200,11 +179,13 @@ const runCommand =
200
179
  pipe(
201
180
  Command.stdin(command, stdin),
202
181
  runCommand(fileSystem),
203
- Stream.flatMap((process) => process.stdout)
182
+ Effect.map((process) => process.stdout),
183
+ Stream.unwrapScoped
204
184
  ),
205
185
  pipe(
206
186
  runCommand(fileSystem)(head),
207
- Stream.flatMap((process) => process.stdout)
187
+ Effect.map((process) => process.stdout),
188
+ Stream.unwrapScoped
208
189
  )
209
190
  )
210
191
  return pipe(Command.stdin(last, stream), runCommand(fileSystem))