@effect/platform-node 0.19.9 → 0.20.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.
Files changed (112) hide show
  1. package/Command/dist/effect-platform-node-Command.cjs.dev.js +32 -32
  2. package/Command/dist/effect-platform-node-Command.cjs.prod.js +32 -32
  3. package/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.dev.js +184 -16
  4. package/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.prod.js +184 -16
  5. package/CommandExecutor/dist/effect-platform-node-CommandExecutor.esm.js +158 -13
  6. package/Effectify/dist/effect-platform-node-Effectify.cjs.dev.js +2 -2
  7. package/Effectify/dist/effect-platform-node-Effectify.cjs.prod.js +2 -2
  8. package/Error/dist/effect-platform-node-Error.cjs.dev.js +6 -6
  9. package/Error/dist/effect-platform-node-Error.cjs.prod.js +6 -6
  10. package/FileSystem/dist/effect-platform-node-FileSystem.cjs.dev.js +423 -17
  11. package/FileSystem/dist/effect-platform-node-FileSystem.cjs.prod.js +423 -17
  12. package/FileSystem/dist/effect-platform-node-FileSystem.esm.js +395 -12
  13. package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.dev.js +3 -3
  14. package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.prod.js +3 -3
  15. package/Http/FormData/dist/effect-platform-node-Http-FormData.esm.js +3 -3
  16. package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.dev.js +4 -4
  17. package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.prod.js +4 -4
  18. package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.esm.js +4 -4
  19. package/Http/Platform/dist/effect-platform-node-Http-Platform.cjs.dev.js +2 -2
  20. package/Http/Platform/dist/effect-platform-node-Http-Platform.cjs.prod.js +2 -2
  21. package/Http/Platform/dist/effect-platform-node-Http-Platform.esm.js +2 -2
  22. package/Http/Server/dist/effect-platform-node-Http-Server.cjs.dev.js +8 -7
  23. package/Http/Server/dist/effect-platform-node-Http-Server.cjs.prod.js +8 -7
  24. package/Http/Server/dist/effect-platform-node-Http-Server.esm.js +8 -7
  25. package/HttpClient/dist/effect-platform-node-HttpClient.cjs.dev.js +19 -19
  26. package/HttpClient/dist/effect-platform-node-HttpClient.cjs.prod.js +19 -19
  27. package/HttpClient/dist/effect-platform-node-HttpClient.esm.js +4 -4
  28. package/HttpServer/dist/effect-platform-node-HttpServer.cjs.dev.js +23 -23
  29. package/HttpServer/dist/effect-platform-node-HttpServer.cjs.prod.js +23 -23
  30. package/HttpServer/dist/effect-platform-node-HttpServer.esm.js +8 -8
  31. package/KeyValueStore/dist/effect-platform-node-KeyValueStore.cjs.dev.js +39 -9
  32. package/KeyValueStore/dist/effect-platform-node-KeyValueStore.cjs.prod.js +39 -9
  33. package/KeyValueStore/dist/effect-platform-node-KeyValueStore.esm.js +18 -4
  34. package/NodeContext/dist/effect-platform-node-NodeContext.cjs.dev.js +39 -7
  35. package/NodeContext/dist/effect-platform-node-NodeContext.cjs.prod.js +39 -7
  36. package/NodeContext/dist/effect-platform-node-NodeContext.esm.js +22 -6
  37. package/Path/dist/effect-platform-node-Path.cjs.dev.js +91 -11
  38. package/Path/dist/effect-platform-node-Path.cjs.prod.js +91 -11
  39. package/Path/dist/effect-platform-node-Path.esm.js +68 -6
  40. package/Runtime/dist/effect-platform-node-Runtime.cjs.dev.js +57 -6
  41. package/Runtime/dist/effect-platform-node-Runtime.cjs.prod.js +57 -6
  42. package/Runtime/dist/effect-platform-node-Runtime.esm.js +38 -3
  43. package/Sink/dist/effect-platform-node-Sink.cjs.dev.js +15 -3
  44. package/Sink/dist/effect-platform-node-Sink.cjs.prod.js +15 -3
  45. package/Sink/dist/effect-platform-node-Sink.esm.js +18 -2
  46. package/Stream/dist/effect-platform-node-Stream.cjs.dev.js +29 -5
  47. package/Stream/dist/effect-platform-node-Stream.cjs.prod.js +29 -5
  48. package/Stream/dist/effect-platform-node-Stream.esm.js +30 -2
  49. package/dist/{FormData-053407d4.cjs.dev.js → FormData-15af6672.cjs.dev.js} +1 -1
  50. package/dist/{FormData-bafc0b9a.esm.js → FormData-5ea8a8b6.esm.js} +1 -1
  51. package/dist/{FormData-c7339a7b.cjs.prod.js → FormData-d91e8016.cjs.prod.js} +1 -1
  52. package/dist/{NodeClient-ea1a9ab0.cjs.prod.js → NodeClient-3432a6a8.cjs.prod.js} +2 -2
  53. package/dist/{NodeClient-e349733e.esm.js → NodeClient-cd56cae8.esm.js} +2 -2
  54. package/dist/{NodeClient-1df9d813.cjs.dev.js → NodeClient-ebd71893.cjs.dev.js} +2 -2
  55. package/dist/{Server-ea100887.cjs.prod.js → Server-33a0b014.cjs.prod.js} +17 -13
  56. package/dist/{Server-264c702d.cjs.dev.js → Server-cf266586.cjs.dev.js} +17 -13
  57. package/dist/{Server-5237fa52.esm.js → Server-eb4f8a51.esm.js} +16 -13
  58. package/dist/declarations/src/index.d.ts.map +1 -1
  59. package/dist/effect-platform-node.cjs.dev.js +58 -86
  60. package/dist/effect-platform-node.cjs.prod.js +58 -86
  61. package/dist/effect-platform-node.esm.js +26 -73
  62. package/dist/{formData-fac89256.cjs.dev.js → formData-632b1146.cjs.dev.js} +1 -1
  63. package/dist/{formData-4330f230.esm.js → formData-dd75bbe1.esm.js} +1 -1
  64. package/dist/{formData-09ad7f6d.cjs.prod.js → formData-ecf6742b.cjs.prod.js} +1 -1
  65. package/dist/{incomingMessage-12764c2c.esm.js → incomingMessage-11c9bea6.esm.js} +1 -1
  66. package/dist/{incomingMessage-8a9a29f7.cjs.prod.js → incomingMessage-86bcf94d.cjs.dev.js} +1 -1
  67. package/dist/{incomingMessage-d7f144e7.cjs.dev.js → incomingMessage-f56be93e.cjs.prod.js} +1 -1
  68. package/dist/{platform-f3d31bb1.esm.js → platform-2c00c2c5.esm.js} +1 -1
  69. package/dist/{platform-1c31462c.cjs.dev.js → platform-5b27475e.cjs.dev.js} +1 -1
  70. package/dist/{platform-d09ef04f.cjs.prod.js → platform-80b90f07.cjs.prod.js} +1 -1
  71. package/package.json +8 -5
  72. package/src/index.ts +13 -13
  73. package/src/internal/http/server.ts +24 -16
  74. package/dist/Command-15b84341.cjs.dev.js +0 -29
  75. package/dist/Command-2fc875e9.cjs.prod.js +0 -29
  76. package/dist/Command-56d67f13.esm.js +0 -27
  77. package/dist/CommandExecutor-b7cb55b8.cjs.dev.js +0 -195
  78. package/dist/CommandExecutor-bccc7563.cjs.prod.js +0 -195
  79. package/dist/CommandExecutor-cfc0af4b.esm.js +0 -165
  80. package/dist/Effectify-1676f59e.cjs.prod.js +0 -14
  81. package/dist/Effectify-24bba5b0.esm.js +0 -12
  82. package/dist/Effectify-c94620ca.cjs.dev.js +0 -14
  83. package/dist/Error-1e8c05fb.esm.js +0 -14
  84. package/dist/Error-243639ac.cjs.dev.js +0 -16
  85. package/dist/Error-eaa907c8.cjs.prod.js +0 -16
  86. package/dist/FileSystem-a207377d.cjs.prod.js +0 -433
  87. package/dist/FileSystem-d4a3521c.esm.js +0 -403
  88. package/dist/FileSystem-d7b8eeac.cjs.dev.js +0 -433
  89. package/dist/HttpClient-11e2237f.esm.js +0 -26
  90. package/dist/HttpClient-19998c5e.cjs.dev.js +0 -54
  91. package/dist/HttpClient-1ad217ea.cjs.prod.js +0 -54
  92. package/dist/HttpServer-08393436.esm.js +0 -34
  93. package/dist/HttpServer-6652ce27.cjs.dev.js +0 -64
  94. package/dist/HttpServer-d510f888.cjs.prod.js +0 -64
  95. package/dist/KeyValueStore-35cb6494.cjs.prod.js +0 -62
  96. package/dist/KeyValueStore-66bca5fd.esm.js +0 -38
  97. package/dist/KeyValueStore-af7495b6.cjs.dev.js +0 -62
  98. package/dist/NodeContext-3c96e955.cjs.dev.js +0 -50
  99. package/dist/NodeContext-4bca6ed4.esm.js +0 -27
  100. package/dist/NodeContext-dff7bc0b.cjs.prod.js +0 -50
  101. package/dist/Path-7a81561f.esm.js +0 -76
  102. package/dist/Path-bf4c3b07.cjs.prod.js +0 -104
  103. package/dist/Path-feae3dcf.cjs.dev.js +0 -104
  104. package/dist/Runtime-3bc7ee1e.esm.js +0 -44
  105. package/dist/Runtime-6aeac6f0.cjs.dev.js +0 -68
  106. package/dist/Runtime-e746c66d.cjs.prod.js +0 -68
  107. package/dist/Sink-536c2b16.cjs.dev.js +0 -26
  108. package/dist/Sink-554d2819.esm.js +0 -23
  109. package/dist/Sink-735101fa.cjs.prod.js +0 -26
  110. package/dist/Stream-2d5b1ece.esm.js +0 -37
  111. package/dist/Stream-53f57af5.cjs.dev.js +0 -42
  112. package/dist/Stream-7424efca.cjs.prod.js +0 -42
@@ -1,195 +0,0 @@
1
- 'use strict';
2
-
3
- var Command = require('@effect/platform/Command');
4
- var CommandExecutor$1 = require('@effect/platform/CommandExecutor');
5
- var FileSystem = require('@effect/platform/FileSystem');
6
- var Effect = require('effect/Effect');
7
- var Function = require('effect/Function');
8
- var Layer = require('effect/Layer');
9
- var Option = require('effect/Option');
10
- var Sink = require('effect/Sink');
11
- var Stream = require('effect/Stream');
12
- var ChildProcess = require('node:child_process');
13
- var error = require('./error-e477c10b.cjs.dev.js');
14
- var sink = require('./sink-daf9e0e5.cjs.dev.js');
15
- var stream = require('./stream-1456ece0.cjs.dev.js');
16
-
17
- function _interopNamespace(e) {
18
- if (e && e.__esModule) return e;
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
27
- });
28
- }
29
- });
30
- }
31
- n["default"] = e;
32
- return Object.freeze(n);
33
- }
34
-
35
- var Command__namespace = /*#__PURE__*/_interopNamespace(Command);
36
- var CommandExecutor__namespace = /*#__PURE__*/_interopNamespace(CommandExecutor$1);
37
- var FileSystem__namespace = /*#__PURE__*/_interopNamespace(FileSystem);
38
- var Effect__namespace = /*#__PURE__*/_interopNamespace(Effect);
39
- var Layer__namespace = /*#__PURE__*/_interopNamespace(Layer);
40
- var Option__namespace = /*#__PURE__*/_interopNamespace(Option);
41
- var Sink__namespace = /*#__PURE__*/_interopNamespace(Sink);
42
- var Stream__namespace = /*#__PURE__*/_interopNamespace(Stream);
43
- var ChildProcess__namespace = /*#__PURE__*/_interopNamespace(ChildProcess);
44
-
45
- const inputToStdioOption = stdin => Option__namespace.match(stdin, {
46
- onNone: () => "inherit",
47
- onSome: () => "pipe"
48
- });
49
- const outputToStdioOption = output => typeof output === "string" ? output : "pipe";
50
- const toError = err => err instanceof globalThis.Error ? err : new globalThis.Error(String(err));
51
- const toPlatformError = (method, error$1, command) => {
52
- const flattened = Command__namespace.flatten(command).reduce((acc, curr) => {
53
- const command = `${curr.command} ${curr.args.join(" ")}`;
54
- return acc.length === 0 ? command : `${acc} | ${command}`;
55
- }, "");
56
- return error.handleErrnoException("Command", method)(error$1, [flattened]);
57
- };
58
- const runCommand = fileSystem => command => {
59
- switch (command._tag) {
60
- case "StandardCommand":
61
- {
62
- return Function.pipe(
63
- // Validate that the directory is accessible
64
- Option__namespace.match(command.cwd, {
65
- onNone: () => Effect__namespace.unit,
66
- onSome: dir => fileSystem.access(dir)
67
- }), Effect__namespace.zipRight(Effect__namespace.sync(() => globalThis.process.env)), Effect__namespace.flatMap(env => Effect__namespace.async(resume => {
68
- const handle = ChildProcess__namespace.spawn(command.command, command.args, {
69
- stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
70
- cwd: Option__namespace.getOrElse(command.cwd, Function.constUndefined),
71
- env: {
72
- ...env,
73
- ...Object.fromEntries(command.env)
74
- }
75
- });
76
- let exited = false;
77
- handle.on("exit", () => {
78
- exited = true;
79
- });
80
-
81
- // If starting the process throws an error, make sure to capture it
82
- handle.on("error", err => {
83
- handle.kill("SIGKILL");
84
- resume(Effect__namespace.fail(toPlatformError("spawn", err, command)));
85
- });
86
-
87
- // If the process is assigned a process identifier, then we know it
88
- // was spawned successfully
89
- if (handle.pid) {
90
- let stdin = Sink__namespace.drain;
91
- if (handle.stdin !== null) {
92
- stdin = sink.fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
93
- }
94
- const exitCode = Effect__namespace.async(resume => {
95
- if (exited) {
96
- return resume(handle.exitCode !== null ? Effect__namespace.succeed(CommandExecutor__namespace.ExitCode(handle.exitCode)) : Effect__namespace.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`), command)));
97
- }
98
- handle.on("exit", (code, signal) => {
99
- if (code !== null) {
100
- resume(Effect__namespace.succeed(CommandExecutor__namespace.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(Effect__namespace.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command)));
106
- }
107
- });
108
- // Make sure to terminate the running process if the fiber is
109
- // terminated
110
- return Effect__namespace.sync(() => {
111
- handle.kill("SIGKILL");
112
- });
113
- });
114
- const isRunning = Effect__namespace.sync(() => handle.exitCode === null && handle.signalCode === null && !handle.killed);
115
- const kill = (signal = "SIGTERM") => Effect__namespace.async(resume => {
116
- handle.kill(signal);
117
- handle.on("exit", () => {
118
- resume(Effect__namespace.unit);
119
- });
120
- // Make sure to terminate the running process if the fiber
121
- // is terminated
122
- return Effect__namespace.sync(() => {
123
- handle.kill("SIGKILL");
124
- });
125
- });
126
- resume(Effect__namespace.sync(() => {
127
- const pid = CommandExecutor__namespace.ProcessId(handle.pid);
128
- const stderr = stream.fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
129
- let stdout = stream.fromReadable(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
130
- // TODO: add Sink.isSink
131
- if (typeof command.stdout !== "string") {
132
- stdout = Stream__namespace.transduce(stdout, command.stdout);
133
- }
134
- return {
135
- [CommandExecutor__namespace.ProcessTypeId]: CommandExecutor__namespace.ProcessTypeId,
136
- pid,
137
- exitCode,
138
- isRunning,
139
- kill,
140
- stdin,
141
- stderr,
142
- stdout
143
- };
144
- }));
145
- }
146
- return Effect__namespace.async(resume => {
147
- if (handle.pid) {
148
- handle.kill("SIGTERM");
149
- }
150
- handle.on("exit", () => {
151
- resume(Effect__namespace.unit);
152
- });
153
- });
154
- })), Effect__namespace.tap(process => Option__namespace.match(command.stdin, {
155
- onNone: () => Effect__namespace.unit,
156
- onSome: stdin => Effect__namespace.forkDaemon(Stream__namespace.run(stdin, process.stdin))
157
- })));
158
- }
159
- case "PipedCommand":
160
- {
161
- const flattened = Command__namespace.flatten(command);
162
- if (flattened.length === 1) {
163
- return Function.pipe(flattened[0], runCommand(fileSystem));
164
- }
165
- const head = flattened[0];
166
- const tail = flattened.slice(1);
167
- const initial = tail.slice(0, tail.length - 1);
168
- const last = tail[tail.length - 1];
169
- const stream = initial.reduce((stdin, command) => Function.pipe(Command__namespace.stdin(command, stdin), runCommand(fileSystem), Stream__namespace.flatMap(process => process.stdout)), Function.pipe(runCommand(fileSystem)(head), Stream__namespace.flatMap(process => process.stdout)));
170
- return Function.pipe(Command__namespace.stdin(last, stream), runCommand(fileSystem));
171
- }
172
- }
173
- };
174
-
175
- /** @internal */
176
- const layer$1 = /*#__PURE__*/Layer__namespace.effect(CommandExecutor__namespace.CommandExecutor, /*#__PURE__*/Function.pipe(FileSystem__namespace.FileSystem, /*#__PURE__*/Effect__namespace.map(fileSystem => CommandExecutor__namespace.makeExecutor(runCommand(fileSystem)))));
177
-
178
- /**
179
- * @since 1.0.0
180
- */
181
-
182
- /**
183
- * @since 1.0.0
184
- * @category layer
185
- */
186
- const layer = layer$1;
187
-
188
- var CommandExecutor = /*#__PURE__*/Object.freeze({
189
- __proto__: null,
190
- layer: layer,
191
- CommandExecutor: CommandExecutor$1.CommandExecutor
192
- });
193
-
194
- exports.CommandExecutor = CommandExecutor;
195
- exports.layer = layer;
@@ -1,195 +0,0 @@
1
- 'use strict';
2
-
3
- var Command = require('@effect/platform/Command');
4
- var CommandExecutor$1 = require('@effect/platform/CommandExecutor');
5
- var FileSystem = require('@effect/platform/FileSystem');
6
- var Effect = require('effect/Effect');
7
- var Function = require('effect/Function');
8
- var Layer = require('effect/Layer');
9
- var Option = require('effect/Option');
10
- var Sink = require('effect/Sink');
11
- var Stream = require('effect/Stream');
12
- var ChildProcess = require('node:child_process');
13
- var error = require('./error-4f074a3a.cjs.prod.js');
14
- var sink = require('./sink-da49e187.cjs.prod.js');
15
- var stream = require('./stream-ef8b6a66.cjs.prod.js');
16
-
17
- function _interopNamespace(e) {
18
- if (e && e.__esModule) return e;
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
27
- });
28
- }
29
- });
30
- }
31
- n["default"] = e;
32
- return Object.freeze(n);
33
- }
34
-
35
- var Command__namespace = /*#__PURE__*/_interopNamespace(Command);
36
- var CommandExecutor__namespace = /*#__PURE__*/_interopNamespace(CommandExecutor$1);
37
- var FileSystem__namespace = /*#__PURE__*/_interopNamespace(FileSystem);
38
- var Effect__namespace = /*#__PURE__*/_interopNamespace(Effect);
39
- var Layer__namespace = /*#__PURE__*/_interopNamespace(Layer);
40
- var Option__namespace = /*#__PURE__*/_interopNamespace(Option);
41
- var Sink__namespace = /*#__PURE__*/_interopNamespace(Sink);
42
- var Stream__namespace = /*#__PURE__*/_interopNamespace(Stream);
43
- var ChildProcess__namespace = /*#__PURE__*/_interopNamespace(ChildProcess);
44
-
45
- const inputToStdioOption = stdin => Option__namespace.match(stdin, {
46
- onNone: () => "inherit",
47
- onSome: () => "pipe"
48
- });
49
- const outputToStdioOption = output => typeof output === "string" ? output : "pipe";
50
- const toError = err => err instanceof globalThis.Error ? err : new globalThis.Error(String(err));
51
- const toPlatformError = (method, error$1, command) => {
52
- const flattened = Command__namespace.flatten(command).reduce((acc, curr) => {
53
- const command = `${curr.command} ${curr.args.join(" ")}`;
54
- return acc.length === 0 ? command : `${acc} | ${command}`;
55
- }, "");
56
- return error.handleErrnoException("Command", method)(error$1, [flattened]);
57
- };
58
- const runCommand = fileSystem => command => {
59
- switch (command._tag) {
60
- case "StandardCommand":
61
- {
62
- return Function.pipe(
63
- // Validate that the directory is accessible
64
- Option__namespace.match(command.cwd, {
65
- onNone: () => Effect__namespace.unit,
66
- onSome: dir => fileSystem.access(dir)
67
- }), Effect__namespace.zipRight(Effect__namespace.sync(() => globalThis.process.env)), Effect__namespace.flatMap(env => Effect__namespace.async(resume => {
68
- const handle = ChildProcess__namespace.spawn(command.command, command.args, {
69
- stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
70
- cwd: Option__namespace.getOrElse(command.cwd, Function.constUndefined),
71
- env: {
72
- ...env,
73
- ...Object.fromEntries(command.env)
74
- }
75
- });
76
- let exited = false;
77
- handle.on("exit", () => {
78
- exited = true;
79
- });
80
-
81
- // If starting the process throws an error, make sure to capture it
82
- handle.on("error", err => {
83
- handle.kill("SIGKILL");
84
- resume(Effect__namespace.fail(toPlatformError("spawn", err, command)));
85
- });
86
-
87
- // If the process is assigned a process identifier, then we know it
88
- // was spawned successfully
89
- if (handle.pid) {
90
- let stdin = Sink__namespace.drain;
91
- if (handle.stdin !== null) {
92
- stdin = sink.fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
93
- }
94
- const exitCode = Effect__namespace.async(resume => {
95
- if (exited) {
96
- return resume(handle.exitCode !== null ? Effect__namespace.succeed(CommandExecutor__namespace.ExitCode(handle.exitCode)) : Effect__namespace.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`), command)));
97
- }
98
- handle.on("exit", (code, signal) => {
99
- if (code !== null) {
100
- resume(Effect__namespace.succeed(CommandExecutor__namespace.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(Effect__namespace.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command)));
106
- }
107
- });
108
- // Make sure to terminate the running process if the fiber is
109
- // terminated
110
- return Effect__namespace.sync(() => {
111
- handle.kill("SIGKILL");
112
- });
113
- });
114
- const isRunning = Effect__namespace.sync(() => handle.exitCode === null && handle.signalCode === null && !handle.killed);
115
- const kill = (signal = "SIGTERM") => Effect__namespace.async(resume => {
116
- handle.kill(signal);
117
- handle.on("exit", () => {
118
- resume(Effect__namespace.unit);
119
- });
120
- // Make sure to terminate the running process if the fiber
121
- // is terminated
122
- return Effect__namespace.sync(() => {
123
- handle.kill("SIGKILL");
124
- });
125
- });
126
- resume(Effect__namespace.sync(() => {
127
- const pid = CommandExecutor__namespace.ProcessId(handle.pid);
128
- const stderr = stream.fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
129
- let stdout = stream.fromReadable(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
130
- // TODO: add Sink.isSink
131
- if (typeof command.stdout !== "string") {
132
- stdout = Stream__namespace.transduce(stdout, command.stdout);
133
- }
134
- return {
135
- [CommandExecutor__namespace.ProcessTypeId]: CommandExecutor__namespace.ProcessTypeId,
136
- pid,
137
- exitCode,
138
- isRunning,
139
- kill,
140
- stdin,
141
- stderr,
142
- stdout
143
- };
144
- }));
145
- }
146
- return Effect__namespace.async(resume => {
147
- if (handle.pid) {
148
- handle.kill("SIGTERM");
149
- }
150
- handle.on("exit", () => {
151
- resume(Effect__namespace.unit);
152
- });
153
- });
154
- })), Effect__namespace.tap(process => Option__namespace.match(command.stdin, {
155
- onNone: () => Effect__namespace.unit,
156
- onSome: stdin => Effect__namespace.forkDaemon(Stream__namespace.run(stdin, process.stdin))
157
- })));
158
- }
159
- case "PipedCommand":
160
- {
161
- const flattened = Command__namespace.flatten(command);
162
- if (flattened.length === 1) {
163
- return Function.pipe(flattened[0], runCommand(fileSystem));
164
- }
165
- const head = flattened[0];
166
- const tail = flattened.slice(1);
167
- const initial = tail.slice(0, tail.length - 1);
168
- const last = tail[tail.length - 1];
169
- const stream = initial.reduce((stdin, command) => Function.pipe(Command__namespace.stdin(command, stdin), runCommand(fileSystem), Stream__namespace.flatMap(process => process.stdout)), Function.pipe(runCommand(fileSystem)(head), Stream__namespace.flatMap(process => process.stdout)));
170
- return Function.pipe(Command__namespace.stdin(last, stream), runCommand(fileSystem));
171
- }
172
- }
173
- };
174
-
175
- /** @internal */
176
- const layer$1 = /*#__PURE__*/Layer__namespace.effect(CommandExecutor__namespace.CommandExecutor, /*#__PURE__*/Function.pipe(FileSystem__namespace.FileSystem, /*#__PURE__*/Effect__namespace.map(fileSystem => CommandExecutor__namespace.makeExecutor(runCommand(fileSystem)))));
177
-
178
- /**
179
- * @since 1.0.0
180
- */
181
-
182
- /**
183
- * @since 1.0.0
184
- * @category layer
185
- */
186
- const layer = layer$1;
187
-
188
- var CommandExecutor = /*#__PURE__*/Object.freeze({
189
- __proto__: null,
190
- layer: layer,
191
- CommandExecutor: CommandExecutor$1.CommandExecutor
192
- });
193
-
194
- exports.CommandExecutor = CommandExecutor;
195
- exports.layer = layer;
@@ -1,165 +0,0 @@
1
- import * as Command from '@effect/platform/Command';
2
- import * as CommandExecutor$1 from '@effect/platform/CommandExecutor';
3
- import { CommandExecutor as CommandExecutor$2 } from '@effect/platform/CommandExecutor';
4
- import * as FileSystem from '@effect/platform/FileSystem';
5
- import * as Effect from 'effect/Effect';
6
- import { pipe, constUndefined } from 'effect/Function';
7
- import * as Layer from 'effect/Layer';
8
- import * as Option from 'effect/Option';
9
- import * as Sink from 'effect/Sink';
10
- import * as Stream from 'effect/Stream';
11
- import * as ChildProcess from 'node:child_process';
12
- import { h as handleErrnoException } from './error-4865cb95.esm.js';
13
- import { f as fromWritable } from './sink-bd7ef408.esm.js';
14
- import { f as fromReadable } from './stream-860139d3.esm.js';
15
-
16
- const inputToStdioOption = stdin => Option.match(stdin, {
17
- onNone: () => "inherit",
18
- onSome: () => "pipe"
19
- });
20
- const outputToStdioOption = output => typeof output === "string" ? output : "pipe";
21
- const toError = err => err instanceof globalThis.Error ? err : new globalThis.Error(String(err));
22
- const toPlatformError = (method, error, command) => {
23
- const flattened = Command.flatten(command).reduce((acc, curr) => {
24
- const command = `${curr.command} ${curr.args.join(" ")}`;
25
- return acc.length === 0 ? command : `${acc} | ${command}`;
26
- }, "");
27
- return handleErrnoException("Command", method)(error, [flattened]);
28
- };
29
- const runCommand = fileSystem => command => {
30
- switch (command._tag) {
31
- case "StandardCommand":
32
- {
33
- return pipe(
34
- // Validate that the directory is accessible
35
- Option.match(command.cwd, {
36
- onNone: () => Effect.unit,
37
- onSome: dir => fileSystem.access(dir)
38
- }), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.flatMap(env => Effect.async(resume => {
39
- const handle = ChildProcess.spawn(command.command, command.args, {
40
- stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
41
- cwd: Option.getOrElse(command.cwd, constUndefined),
42
- env: {
43
- ...env,
44
- ...Object.fromEntries(command.env)
45
- }
46
- });
47
- let exited = false;
48
- handle.on("exit", () => {
49
- exited = true;
50
- });
51
-
52
- // If starting the process throws an error, make sure to capture it
53
- handle.on("error", err => {
54
- handle.kill("SIGKILL");
55
- resume(Effect.fail(toPlatformError("spawn", err, command)));
56
- });
57
-
58
- // If the process is assigned a process identifier, then we know it
59
- // was spawned successfully
60
- if (handle.pid) {
61
- let stdin = Sink.drain;
62
- if (handle.stdin !== null) {
63
- stdin = fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
64
- }
65
- const exitCode = Effect.async(resume => {
66
- if (exited) {
67
- return resume(handle.exitCode !== null ? Effect.succeed(CommandExecutor$1.ExitCode(handle.exitCode)) : Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`), command)));
68
- }
69
- handle.on("exit", (code, signal) => {
70
- if (code !== null) {
71
- resume(Effect.succeed(CommandExecutor$1.ExitCode(code)));
72
- } else {
73
- // If code is `null`, then `signal` must be defined. See the NodeJS
74
- // documentation for the `"exit"` event on a `child_process`.
75
- // https://nodejs.org/api/child_process.html#child_process_event_exit
76
- resume(Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command)));
77
- }
78
- });
79
- // Make sure to terminate the running process if the fiber is
80
- // terminated
81
- return Effect.sync(() => {
82
- handle.kill("SIGKILL");
83
- });
84
- });
85
- const isRunning = Effect.sync(() => handle.exitCode === null && handle.signalCode === null && !handle.killed);
86
- const kill = (signal = "SIGTERM") => Effect.async(resume => {
87
- handle.kill(signal);
88
- handle.on("exit", () => {
89
- resume(Effect.unit);
90
- });
91
- // Make sure to terminate the running process if the fiber
92
- // is terminated
93
- return Effect.sync(() => {
94
- handle.kill("SIGKILL");
95
- });
96
- });
97
- resume(Effect.sync(() => {
98
- const pid = CommandExecutor$1.ProcessId(handle.pid);
99
- const stderr = fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
100
- let stdout = fromReadable(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
101
- // TODO: add Sink.isSink
102
- if (typeof command.stdout !== "string") {
103
- stdout = Stream.transduce(stdout, command.stdout);
104
- }
105
- return {
106
- [CommandExecutor$1.ProcessTypeId]: CommandExecutor$1.ProcessTypeId,
107
- pid,
108
- exitCode,
109
- isRunning,
110
- kill,
111
- stdin,
112
- stderr,
113
- stdout
114
- };
115
- }));
116
- }
117
- return Effect.async(resume => {
118
- if (handle.pid) {
119
- handle.kill("SIGTERM");
120
- }
121
- handle.on("exit", () => {
122
- resume(Effect.unit);
123
- });
124
- });
125
- })), Effect.tap(process => Option.match(command.stdin, {
126
- onNone: () => Effect.unit,
127
- onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
128
- })));
129
- }
130
- case "PipedCommand":
131
- {
132
- const flattened = Command.flatten(command);
133
- if (flattened.length === 1) {
134
- return pipe(flattened[0], runCommand(fileSystem));
135
- }
136
- const head = flattened[0];
137
- const tail = flattened.slice(1);
138
- const initial = tail.slice(0, tail.length - 1);
139
- const last = tail[tail.length - 1];
140
- 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)));
141
- return pipe(Command.stdin(last, stream), runCommand(fileSystem));
142
- }
143
- }
144
- };
145
-
146
- /** @internal */
147
- const layer$1 = /*#__PURE__*/Layer.effect(CommandExecutor$1.CommandExecutor, /*#__PURE__*/pipe(FileSystem.FileSystem, /*#__PURE__*/Effect.map(fileSystem => CommandExecutor$1.makeExecutor(runCommand(fileSystem)))));
148
-
149
- /**
150
- * @since 1.0.0
151
- */
152
-
153
- /**
154
- * @since 1.0.0
155
- * @category layer
156
- */
157
- const layer = layer$1;
158
-
159
- var CommandExecutor = /*#__PURE__*/Object.freeze({
160
- __proto__: null,
161
- layer: layer,
162
- CommandExecutor: CommandExecutor$2
163
- });
164
-
165
- export { CommandExecutor as C, layer as l };
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- var Effectify$1 = require('@effect/platform/Effectify');
4
-
5
- /**
6
- * @since 1.0.0
7
- */
8
-
9
- var Effectify = /*#__PURE__*/Object.freeze({
10
- __proto__: null,
11
- effectify: Effectify$1.effectify
12
- });
13
-
14
- exports.Effectify = Effectify;
@@ -1,12 +0,0 @@
1
- import { effectify } from '@effect/platform/Effectify';
2
-
3
- /**
4
- * @since 1.0.0
5
- */
6
-
7
- var Effectify = /*#__PURE__*/Object.freeze({
8
- __proto__: null,
9
- effectify: effectify
10
- });
11
-
12
- export { Effectify as E };
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- var Effectify$1 = require('@effect/platform/Effectify');
4
-
5
- /**
6
- * @since 1.0.0
7
- */
8
-
9
- var Effectify = /*#__PURE__*/Object.freeze({
10
- __proto__: null,
11
- effectify: Effectify$1.effectify
12
- });
13
-
14
- exports.Effectify = Effectify;
@@ -1,14 +0,0 @@
1
- import { BadArgument, PlatformErrorTypeId, SystemError } from '@effect/platform/Error';
2
-
3
- /**
4
- * @since 1.0.0
5
- */
6
-
7
- var Error = /*#__PURE__*/Object.freeze({
8
- __proto__: null,
9
- BadArgument: BadArgument,
10
- PlatformErrorTypeId: PlatformErrorTypeId,
11
- SystemError: SystemError
12
- });
13
-
14
- export { Error as E };
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- var Error$1 = require('@effect/platform/Error');
4
-
5
- /**
6
- * @since 1.0.0
7
- */
8
-
9
- var Error = /*#__PURE__*/Object.freeze({
10
- __proto__: null,
11
- BadArgument: Error$1.BadArgument,
12
- PlatformErrorTypeId: Error$1.PlatformErrorTypeId,
13
- SystemError: Error$1.SystemError
14
- });
15
-
16
- exports.Error = Error;
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- var Error$1 = require('@effect/platform/Error');
4
-
5
- /**
6
- * @since 1.0.0
7
- */
8
-
9
- var Error = /*#__PURE__*/Object.freeze({
10
- __proto__: null,
11
- BadArgument: Error$1.BadArgument,
12
- PlatformErrorTypeId: Error$1.PlatformErrorTypeId,
13
- SystemError: Error$1.SystemError
14
- });
15
-
16
- exports.Error = Error;