@effect/platform-node-shared 0.57.1 → 4.0.0-beta.1

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 (218) hide show
  1. package/README.md +3 -3
  2. package/dist/NodeChildProcessSpawner.d.ts +37 -0
  3. package/dist/NodeChildProcessSpawner.d.ts.map +1 -0
  4. package/dist/NodeChildProcessSpawner.js +567 -0
  5. package/dist/NodeChildProcessSpawner.js.map +1 -0
  6. package/dist/{dts/NodeClusterSocket.d.ts → NodeClusterSocket.d.ts} +4 -7
  7. package/dist/NodeClusterSocket.d.ts.map +1 -0
  8. package/dist/{esm/NodeClusterSocket.js → NodeClusterSocket.js} +9 -10
  9. package/dist/NodeClusterSocket.js.map +1 -0
  10. package/dist/NodeFileSystem.d.ts +8 -0
  11. package/dist/NodeFileSystem.d.ts.map +1 -0
  12. package/dist/{esm/internal/fileSystem.js → NodeFileSystem.js} +125 -96
  13. package/dist/NodeFileSystem.js.map +1 -0
  14. package/dist/NodePath.d.ts +18 -0
  15. package/dist/NodePath.d.ts.map +1 -0
  16. package/dist/NodePath.js +56 -0
  17. package/dist/NodePath.js.map +1 -0
  18. package/dist/NodeRuntime.d.ts +28 -0
  19. package/dist/NodeRuntime.d.ts.map +1 -0
  20. package/dist/{esm/internal/runtime.js → NodeRuntime.js} +8 -8
  21. package/dist/NodeRuntime.js.map +1 -0
  22. package/dist/NodeSink.d.ts +40 -0
  23. package/dist/NodeSink.d.ts.map +1 -0
  24. package/dist/NodeSink.js +50 -0
  25. package/dist/NodeSink.js.map +1 -0
  26. package/dist/{dts/NodeSocket.d.ts → NodeSocket.d.ts} +10 -10
  27. package/dist/NodeSocket.d.ts.map +1 -0
  28. package/dist/{esm/NodeSocket.js → NodeSocket.js} +51 -39
  29. package/dist/NodeSocket.js.map +1 -0
  30. package/dist/{dts/NodeSocketServer.d.ts → NodeSocketServer.d.ts} +8 -10
  31. package/dist/NodeSocketServer.d.ts.map +1 -0
  32. package/dist/NodeSocketServer.js +192 -0
  33. package/dist/NodeSocketServer.js.map +1 -0
  34. package/dist/NodeStdio.d.ts +11 -0
  35. package/dist/NodeStdio.d.ts.map +1 -0
  36. package/dist/NodeStdio.js +43 -0
  37. package/dist/NodeStdio.js.map +1 -0
  38. package/dist/NodeStream.d.ts +127 -0
  39. package/dist/NodeStream.d.ts.map +1 -0
  40. package/dist/NodeStream.js +249 -0
  41. package/dist/NodeStream.js.map +1 -0
  42. package/dist/NodeTerminal.d.ts +15 -0
  43. package/dist/NodeTerminal.d.ts.map +1 -0
  44. package/dist/{esm/internal/terminal.js → NodeTerminal.js} +28 -25
  45. package/dist/NodeTerminal.js.map +1 -0
  46. package/dist/internal/utils.d.ts +2 -0
  47. package/dist/internal/utils.d.ts.map +1 -0
  48. package/dist/{esm/internal/error.js → internal/utils.js} +4 -5
  49. package/dist/internal/utils.js.map +1 -0
  50. package/package.json +53 -124
  51. package/src/NodeChildProcessSpawner.ts +713 -0
  52. package/src/NodeClusterSocket.ts +12 -13
  53. package/src/NodeFileSystem.ts +632 -5
  54. package/src/NodePath.ts +48 -9
  55. package/src/NodeRuntime.ts +53 -4
  56. package/src/NodeSink.ts +65 -62
  57. package/src/NodeSocket.ts +65 -49
  58. package/src/NodeSocketServer.ts +108 -88
  59. package/src/NodeStdio.ts +49 -0
  60. package/src/NodeStream.ts +324 -83
  61. package/src/NodeTerminal.ts +100 -9
  62. package/src/internal/{error.ts → utils.ts} +6 -7
  63. package/NodeClusterSocket/package.json +0 -6
  64. package/NodeCommandExecutor/package.json +0 -6
  65. package/NodeFileSystem/ParcelWatcher/package.json +0 -6
  66. package/NodeFileSystem/package.json +0 -6
  67. package/NodeKeyValueStore/package.json +0 -6
  68. package/NodeMultipart/package.json +0 -6
  69. package/NodePath/package.json +0 -6
  70. package/NodeRuntime/package.json +0 -6
  71. package/NodeSink/package.json +0 -6
  72. package/NodeSocket/package.json +0 -6
  73. package/NodeSocketServer/package.json +0 -6
  74. package/NodeStream/package.json +0 -6
  75. package/NodeTerminal/package.json +0 -6
  76. package/dist/cjs/NodeClusterSocket.js +0 -50
  77. package/dist/cjs/NodeClusterSocket.js.map +0 -1
  78. package/dist/cjs/NodeCommandExecutor.js +0 -14
  79. package/dist/cjs/NodeCommandExecutor.js.map +0 -1
  80. package/dist/cjs/NodeFileSystem/ParcelWatcher.js +0 -20
  81. package/dist/cjs/NodeFileSystem/ParcelWatcher.js.map +0 -1
  82. package/dist/cjs/NodeFileSystem.js +0 -18
  83. package/dist/cjs/NodeFileSystem.js.map +0 -1
  84. package/dist/cjs/NodeKeyValueStore.js +0 -18
  85. package/dist/cjs/NodeKeyValueStore.js.map +0 -1
  86. package/dist/cjs/NodeMultipart.js +0 -24
  87. package/dist/cjs/NodeMultipart.js.map +0 -1
  88. package/dist/cjs/NodePath.js +0 -28
  89. package/dist/cjs/NodePath.js.map +0 -1
  90. package/dist/cjs/NodeRuntime.js +0 -14
  91. package/dist/cjs/NodeRuntime.js.map +0 -1
  92. package/dist/cjs/NodeSink.js +0 -50
  93. package/dist/cjs/NodeSink.js.map +0 -1
  94. package/dist/cjs/NodeSocket.js +0 -153
  95. package/dist/cjs/NodeSocket.js.map +0 -1
  96. package/dist/cjs/NodeSocketServer.js +0 -178
  97. package/dist/cjs/NodeSocketServer.js.map +0 -1
  98. package/dist/cjs/NodeStream.js +0 -76
  99. package/dist/cjs/NodeStream.js.map +0 -1
  100. package/dist/cjs/NodeTerminal.js +0 -19
  101. package/dist/cjs/NodeTerminal.js.map +0 -1
  102. package/dist/cjs/internal/commandExecutor.js +0 -153
  103. package/dist/cjs/internal/commandExecutor.js.map +0 -1
  104. package/dist/cjs/internal/error.js +0 -45
  105. package/dist/cjs/internal/error.js.map +0 -1
  106. package/dist/cjs/internal/fileSystem/parcelWatcher.js +0 -68
  107. package/dist/cjs/internal/fileSystem/parcelWatcher.js.map +0 -1
  108. package/dist/cjs/internal/fileSystem.js +0 -400
  109. package/dist/cjs/internal/fileSystem.js.map +0 -1
  110. package/dist/cjs/internal/multipart.js +0 -147
  111. package/dist/cjs/internal/multipart.js.map +0 -1
  112. package/dist/cjs/internal/path.js +0 -53
  113. package/dist/cjs/internal/path.js.map +0 -1
  114. package/dist/cjs/internal/runtime.js +0 -37
  115. package/dist/cjs/internal/runtime.js.map +0 -1
  116. package/dist/cjs/internal/sink.js +0 -28
  117. package/dist/cjs/internal/sink.js.map +0 -1
  118. package/dist/cjs/internal/stream.js +0 -233
  119. package/dist/cjs/internal/stream.js.map +0 -1
  120. package/dist/cjs/internal/terminal.js +0 -90
  121. package/dist/cjs/internal/terminal.js.map +0 -1
  122. package/dist/dts/NodeClusterSocket.d.ts.map +0 -1
  123. package/dist/dts/NodeCommandExecutor.d.ts +0 -12
  124. package/dist/dts/NodeCommandExecutor.d.ts.map +0 -1
  125. package/dist/dts/NodeFileSystem/ParcelWatcher.d.ts +0 -13
  126. package/dist/dts/NodeFileSystem/ParcelWatcher.d.ts.map +0 -1
  127. package/dist/dts/NodeFileSystem.d.ts +0 -11
  128. package/dist/dts/NodeFileSystem.d.ts.map +0 -1
  129. package/dist/dts/NodeKeyValueStore.d.ts +0 -12
  130. package/dist/dts/NodeKeyValueStore.d.ts.map +0 -1
  131. package/dist/dts/NodeMultipart.d.ts +0 -27
  132. package/dist/dts/NodeMultipart.d.ts.map +0 -1
  133. package/dist/dts/NodePath.d.ts +0 -21
  134. package/dist/dts/NodePath.d.ts.map +0 -1
  135. package/dist/dts/NodeRuntime.d.ts +0 -10
  136. package/dist/dts/NodeRuntime.d.ts.map +0 -1
  137. package/dist/dts/NodeSink.d.ts +0 -36
  138. package/dist/dts/NodeSink.d.ts.map +0 -1
  139. package/dist/dts/NodeSocket.d.ts.map +0 -1
  140. package/dist/dts/NodeSocketServer.d.ts.map +0 -1
  141. package/dist/dts/NodeStream.d.ts +0 -119
  142. package/dist/dts/NodeStream.d.ts.map +0 -1
  143. package/dist/dts/NodeTerminal.d.ts +0 -18
  144. package/dist/dts/NodeTerminal.d.ts.map +0 -1
  145. package/dist/dts/internal/commandExecutor.d.ts +0 -2
  146. package/dist/dts/internal/commandExecutor.d.ts.map +0 -1
  147. package/dist/dts/internal/error.d.ts +0 -2
  148. package/dist/dts/internal/error.d.ts.map +0 -1
  149. package/dist/dts/internal/fileSystem/parcelWatcher.d.ts +0 -4
  150. package/dist/dts/internal/fileSystem/parcelWatcher.d.ts.map +0 -1
  151. package/dist/dts/internal/fileSystem.d.ts +0 -2
  152. package/dist/dts/internal/fileSystem.d.ts.map +0 -1
  153. package/dist/dts/internal/multipart.d.ts +0 -2
  154. package/dist/dts/internal/multipart.d.ts.map +0 -1
  155. package/dist/dts/internal/path.d.ts +0 -2
  156. package/dist/dts/internal/path.d.ts.map +0 -1
  157. package/dist/dts/internal/runtime.d.ts +0 -2
  158. package/dist/dts/internal/runtime.d.ts.map +0 -1
  159. package/dist/dts/internal/sink.d.ts +0 -2
  160. package/dist/dts/internal/sink.d.ts.map +0 -1
  161. package/dist/dts/internal/stream.d.ts +0 -2
  162. package/dist/dts/internal/stream.d.ts.map +0 -1
  163. package/dist/dts/internal/terminal.d.ts +0 -2
  164. package/dist/dts/internal/terminal.d.ts.map +0 -1
  165. package/dist/esm/NodeClusterSocket.js.map +0 -1
  166. package/dist/esm/NodeCommandExecutor.js +0 -7
  167. package/dist/esm/NodeCommandExecutor.js.map +0 -1
  168. package/dist/esm/NodeFileSystem/ParcelWatcher.js +0 -12
  169. package/dist/esm/NodeFileSystem/ParcelWatcher.js.map +0 -1
  170. package/dist/esm/NodeFileSystem.js +0 -10
  171. package/dist/esm/NodeFileSystem.js.map +0 -1
  172. package/dist/esm/NodeKeyValueStore.js +0 -10
  173. package/dist/esm/NodeKeyValueStore.js.map +0 -1
  174. package/dist/esm/NodeMultipart.js +0 -17
  175. package/dist/esm/NodeMultipart.js.map +0 -1
  176. package/dist/esm/NodePath.js +0 -20
  177. package/dist/esm/NodePath.js.map +0 -1
  178. package/dist/esm/NodeRuntime.js +0 -7
  179. package/dist/esm/NodeRuntime.js.map +0 -1
  180. package/dist/esm/NodeSink.js +0 -43
  181. package/dist/esm/NodeSink.js.map +0 -1
  182. package/dist/esm/NodeSocket.js.map +0 -1
  183. package/dist/esm/NodeSocketServer.js +0 -167
  184. package/dist/esm/NodeSocketServer.js.map +0 -1
  185. package/dist/esm/NodeStream.js +0 -69
  186. package/dist/esm/NodeStream.js.map +0 -1
  187. package/dist/esm/NodeTerminal.js +0 -12
  188. package/dist/esm/NodeTerminal.js.map +0 -1
  189. package/dist/esm/internal/commandExecutor.js +0 -146
  190. package/dist/esm/internal/commandExecutor.js.map +0 -1
  191. package/dist/esm/internal/error.js.map +0 -1
  192. package/dist/esm/internal/fileSystem/parcelWatcher.js +0 -61
  193. package/dist/esm/internal/fileSystem/parcelWatcher.js.map +0 -1
  194. package/dist/esm/internal/fileSystem.js.map +0 -1
  195. package/dist/esm/internal/multipart.js +0 -137
  196. package/dist/esm/internal/multipart.js.map +0 -1
  197. package/dist/esm/internal/path.js +0 -46
  198. package/dist/esm/internal/path.js.map +0 -1
  199. package/dist/esm/internal/runtime.js.map +0 -1
  200. package/dist/esm/internal/sink.js +0 -19
  201. package/dist/esm/internal/sink.js.map +0 -1
  202. package/dist/esm/internal/stream.js +0 -217
  203. package/dist/esm/internal/stream.js.map +0 -1
  204. package/dist/esm/internal/terminal.js.map +0 -1
  205. package/dist/esm/package.json +0 -4
  206. package/src/NodeCommandExecutor.ts +0 -13
  207. package/src/NodeFileSystem/ParcelWatcher.ts +0 -15
  208. package/src/NodeKeyValueStore.ts +0 -20
  209. package/src/NodeMultipart.ts +0 -40
  210. package/src/internal/commandExecutor.ts +0 -251
  211. package/src/internal/fileSystem/parcelWatcher.ts +0 -64
  212. package/src/internal/fileSystem.ts +0 -648
  213. package/src/internal/multipart.ts +0 -141
  214. package/src/internal/path.ts +0 -63
  215. package/src/internal/runtime.ts +0 -34
  216. package/src/internal/sink.ts +0 -57
  217. package/src/internal/stream.ts +0 -375
  218. package/src/internal/terminal.ts +0 -104
@@ -1,251 +0,0 @@
1
- import * as Command from "@effect/platform/Command"
2
- import * as CommandExecutor from "@effect/platform/CommandExecutor"
3
- import type * as Error from "@effect/platform/Error"
4
- import * as FileSystem from "@effect/platform/FileSystem"
5
- import * as Deferred from "effect/Deferred"
6
- import * as Effect from "effect/Effect"
7
- import { constUndefined, identity, pipe } from "effect/Function"
8
- import * as Inspectable from "effect/Inspectable"
9
- import * as Layer from "effect/Layer"
10
- import * as Option from "effect/Option"
11
- import type * as Scope from "effect/Scope"
12
- import * as Sink from "effect/Sink"
13
- import * as Stream from "effect/Stream"
14
- import * as ChildProcess from "node:child_process"
15
- import { handleErrnoException } from "./error.js"
16
- import { fromWritable } from "./sink.js"
17
- import { fromReadable } from "./stream.js"
18
-
19
- const inputToStdioOption = (stdin: Command.Command.Input): "pipe" | "inherit" =>
20
- typeof stdin === "string" ? stdin : "pipe"
21
-
22
- const outputToStdioOption = (output: Command.Command.Output): "pipe" | "inherit" =>
23
- typeof output === "string" ? output : "pipe"
24
-
25
- const toError = (err: unknown): Error => err instanceof globalThis.Error ? err : new globalThis.Error(String(err))
26
-
27
- const toPlatformError = (
28
- method: string,
29
- error: NodeJS.ErrnoException,
30
- command: Command.Command
31
- ): Error.PlatformError => {
32
- const flattened = Command.flatten(command).reduce((acc, curr) => {
33
- const command = `${curr.command} ${curr.args.join(" ")}`
34
- return acc.length === 0 ? command : `${acc} | ${command}`
35
- }, "")
36
- return handleErrnoException("Command", method)(error, [flattened])
37
- }
38
-
39
- type ExitCode = readonly [code: number | null, signal: NodeJS.Signals | null]
40
- type ExitCodeDeferred = Deferred.Deferred<ExitCode>
41
-
42
- const ProcessProto = {
43
- [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
44
- ...Inspectable.BaseProto,
45
- toJSON(this: CommandExecutor.Process) {
46
- return {
47
- _id: "@effect/platform/CommandExecutor/Process",
48
- pid: this.pid
49
- }
50
- }
51
- }
52
-
53
- const runCommand =
54
- (fileSystem: FileSystem.FileSystem) =>
55
- (command: Command.Command): Effect.Effect<CommandExecutor.Process, Error.PlatformError, Scope.Scope> => {
56
- switch (command._tag) {
57
- case "StandardCommand": {
58
- const spawn = Effect.flatMap(
59
- Deferred.make<ExitCode>(),
60
- (exitCode) =>
61
- Effect.async<readonly [ChildProcess.ChildProcess, ExitCodeDeferred], Error.PlatformError>(
62
- (resume) => {
63
- const handle = ChildProcess.spawn(command.command, command.args, {
64
- stdio: [
65
- inputToStdioOption(command.stdin),
66
- outputToStdioOption(command.stdout),
67
- outputToStdioOption(command.stderr)
68
- ],
69
- cwd: Option.getOrElse(command.cwd, constUndefined),
70
- shell: command.shell,
71
- env: { ...process.env, ...Object.fromEntries(command.env) },
72
- detached: process.platform !== "win32"
73
- })
74
- handle.on("error", (err) => {
75
- resume(Effect.fail(toPlatformError("spawn", err, command)))
76
- })
77
- handle.on("exit", (...args) => {
78
- Deferred.unsafeDone(exitCode, Effect.succeed(args))
79
- })
80
- handle.on("spawn", () => {
81
- resume(Effect.succeed([handle, exitCode]))
82
- })
83
- return Effect.sync(() => {
84
- handle.kill("SIGTERM")
85
- })
86
- }
87
- )
88
- )
89
-
90
- const killProcessGroup = process.platform === "win32" ?
91
- (handle: ChildProcess.ChildProcess, _: NodeJS.Signals) =>
92
- Effect.async<void, Error.PlatformError>((resume) => {
93
- ChildProcess.exec(`taskkill /pid ${handle.pid} /T /F`, (error) => {
94
- if (error) {
95
- resume(Effect.fail(toPlatformError("kill", toError(error), command)))
96
- } else {
97
- resume(Effect.void)
98
- }
99
- })
100
- })
101
- : (handle: ChildProcess.ChildProcess, signal: NodeJS.Signals) =>
102
- Effect.try({
103
- try: () => process.kill(-handle.pid!, signal),
104
- catch: (error) => toPlatformError("kill", toError(error), command)
105
- })
106
-
107
- const killProcess = (handle: ChildProcess.ChildProcess, signal: NodeJS.Signals) =>
108
- Effect.suspend(() =>
109
- handle.kill(signal) ? Effect.void : Effect.fail(
110
- toPlatformError("kill", new globalThis.Error("Failed to kill process"), command)
111
- )
112
- )
113
-
114
- return pipe(
115
- // Validate that the directory is accessible
116
- Option.match(command.cwd, {
117
- onNone: () => Effect.void,
118
- onSome: (dir) => fileSystem.access(dir)
119
- }),
120
- Effect.zipRight(
121
- Effect.acquireRelease(
122
- spawn,
123
- ([handle, exitCode]) =>
124
- Effect.flatMap(Deferred.isDone(exitCode), (done) => {
125
- if (!done) {
126
- // Process is still running, kill it
127
- return killProcessGroup(handle, "SIGTERM").pipe(
128
- Effect.orElse(() => killProcess(handle, "SIGTERM")),
129
- Effect.zipRight(Deferred.await(exitCode)),
130
- Effect.ignore
131
- )
132
- }
133
-
134
- // Process has already exited, check if we need to clean up children
135
- return Effect.flatMap(Deferred.await(exitCode), ([code]) => {
136
- if (code !== 0 && code !== null) {
137
- // Non-zero exit code, attempt to clean up process group
138
- return killProcessGroup(handle, "SIGTERM").pipe(Effect.ignore)
139
- }
140
-
141
- return Effect.void
142
- })
143
- })
144
- )
145
- ),
146
- Effect.map(([handle, exitCodeDeferred]): CommandExecutor.Process => {
147
- let stdin: Sink.Sink<void, unknown, never, Error.PlatformError> = Sink.drain
148
-
149
- if (handle.stdin !== null) {
150
- stdin = fromWritable(
151
- () => handle.stdin!,
152
- (err) => toPlatformError("toWritable", toError(err), command)
153
- )
154
- }
155
-
156
- const exitCode: CommandExecutor.Process["exitCode"] = Effect.flatMap(
157
- Deferred.await(exitCodeDeferred),
158
- ([code, signal]) => {
159
- if (code !== null) {
160
- return Effect.succeed(CommandExecutor.ExitCode(code))
161
- }
162
- // If code is `null`, then `signal` must be defined. See the NodeJS
163
- // documentation for the `"exit"` event on a `child_process`.
164
- // https://nodejs.org/api/child_process.html#child_process_event_exit
165
- return Effect.fail(
166
- toPlatformError(
167
- "exitCode",
168
- new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`),
169
- command
170
- )
171
- )
172
- }
173
- )
174
-
175
- const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred))
176
-
177
- const kill: CommandExecutor.Process["kill"] = (signal = "SIGTERM") =>
178
- killProcessGroup(handle, signal).pipe(
179
- Effect.orElse(() => killProcess(handle, signal)),
180
- Effect.zipRight(Effect.asVoid(Deferred.await(exitCodeDeferred)))
181
- )
182
-
183
- const pid = CommandExecutor.ProcessId(handle.pid!)
184
- const stderr = fromReadable<Error.PlatformError, Uint8Array>(
185
- () => handle.stderr!,
186
- (err) => toPlatformError("fromReadable(stderr)", toError(err), command)
187
- )
188
- let stdout: Stream.Stream<Uint8Array, Error.PlatformError> = fromReadable<
189
- Error.PlatformError,
190
- Uint8Array
191
- >(
192
- () => handle.stdout!,
193
- (err) => toPlatformError("fromReadable(stdout)", toError(err), command)
194
- )
195
- // TODO: add Sink.isSink
196
- if (typeof command.stdout !== "string") {
197
- stdout = Stream.transduce(stdout, command.stdout)
198
- }
199
- return Object.assign(Object.create(ProcessProto), {
200
- pid,
201
- exitCode,
202
- isRunning,
203
- kill,
204
- stdin,
205
- stderr,
206
- stdout
207
- })
208
- }),
209
- typeof command.stdin === "string"
210
- ? identity
211
- : Effect.tap((process) =>
212
- Effect.forkDaemon(Stream.run(command.stdin as Stream.Stream<Uint8Array>, process.stdin))
213
- )
214
- )
215
- }
216
- case "PipedCommand": {
217
- const flattened = Command.flatten(command)
218
- if (flattened.length === 1) {
219
- return pipe(flattened[0], runCommand(fileSystem))
220
- }
221
- const head = flattened[0]
222
- const tail = flattened.slice(1)
223
- const initial = tail.slice(0, tail.length - 1)
224
- const last = tail[tail.length - 1]
225
- const stream = initial.reduce(
226
- (stdin, command) =>
227
- pipe(
228
- Command.stdin(command, stdin),
229
- runCommand(fileSystem),
230
- Effect.map((process) => process.stdout),
231
- Stream.unwrapScoped
232
- ),
233
- pipe(
234
- runCommand(fileSystem)(head),
235
- Effect.map((process) => process.stdout),
236
- Stream.unwrapScoped
237
- )
238
- )
239
- return pipe(Command.stdin(last, stream), runCommand(fileSystem))
240
- }
241
- }
242
- }
243
-
244
- /** @internal */
245
- export const layer: Layer.Layer<CommandExecutor.CommandExecutor, never, FileSystem.FileSystem> = Layer.effect(
246
- CommandExecutor.CommandExecutor,
247
- pipe(
248
- FileSystem.FileSystem,
249
- Effect.map((fileSystem) => CommandExecutor.makeExecutor(runCommand(fileSystem)))
250
- )
251
- )
@@ -1,64 +0,0 @@
1
- import * as Error from "@effect/platform/Error"
2
- import * as FileSystem from "@effect/platform/FileSystem"
3
- import * as ParcelWatcher from "@parcel/watcher"
4
- import * as Chunk from "effect/Chunk"
5
- import * as Effect from "effect/Effect"
6
- import * as Layer from "effect/Layer"
7
- import * as Option from "effect/Option"
8
- import * as Stream from "effect/Stream"
9
-
10
- const watchParcel = (path: string) =>
11
- Stream.asyncScoped<FileSystem.WatchEvent, Error.PlatformError>((emit) =>
12
- Effect.acquireRelease(
13
- Effect.tryPromise({
14
- try: () =>
15
- ParcelWatcher.subscribe(path, (cause, events) => {
16
- if (cause) {
17
- emit.fail(
18
- new Error.SystemError({
19
- reason: "Unknown",
20
- module: "FileSystem",
21
- method: "watch",
22
- pathOrDescriptor: path,
23
- cause
24
- })
25
- )
26
- } else {
27
- emit.chunk(Chunk.unsafeFromArray(events.map((event) => {
28
- switch (event.type) {
29
- case "create": {
30
- return FileSystem.WatchEventCreate({ path: event.path })
31
- }
32
- case "update": {
33
- return FileSystem.WatchEventUpdate({ path: event.path })
34
- }
35
- case "delete": {
36
- return FileSystem.WatchEventRemove({ path: event.path })
37
- }
38
- }
39
- })))
40
- }
41
- }),
42
- catch: (cause) =>
43
- new Error.SystemError({
44
- reason: "Unknown",
45
- module: "FileSystem",
46
- method: "watch",
47
- pathOrDescriptor: path,
48
- cause
49
- })
50
- }),
51
- (sub) => Effect.promise(() => sub.unsubscribe())
52
- )
53
- )
54
-
55
- const backend = FileSystem.WatchBackend.of({
56
- register(path, stat, _options) {
57
- if (stat.type !== "Directory") {
58
- return Option.none()
59
- }
60
- return Option.some(watchParcel(path))
61
- }
62
- })
63
-
64
- export const layer = Layer.succeed(FileSystem.WatchBackend, backend)