@effect/platform-node-shared 0.3.29 → 0.4.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 (51) hide show
  1. package/dist/cjs/NodeFileSystem/ParcelWatcher.js +44 -0
  2. package/dist/cjs/NodeFileSystem/ParcelWatcher.js.map +1 -0
  3. package/dist/cjs/NodeSocket.js +3 -3
  4. package/dist/cjs/NodeSocket.js.map +1 -1
  5. package/dist/cjs/internal/commandExecutor.js +5 -5
  6. package/dist/cjs/internal/commandExecutor.js.map +1 -1
  7. package/dist/cjs/internal/fileSystem/parcelWatcher.js +92 -0
  8. package/dist/cjs/internal/fileSystem/parcelWatcher.js.map +1 -0
  9. package/dist/cjs/internal/fileSystem.js +9 -54
  10. package/dist/cjs/internal/fileSystem.js.map +1 -1
  11. package/dist/cjs/internal/runtime.js +1 -1
  12. package/dist/cjs/internal/runtime.js.map +1 -1
  13. package/dist/cjs/internal/sink.js +1 -1
  14. package/dist/cjs/internal/sink.js.map +1 -1
  15. package/dist/cjs/internal/stream.js +10 -10
  16. package/dist/cjs/internal/stream.js.map +1 -1
  17. package/dist/cjs/internal/terminal.js +1 -1
  18. package/dist/cjs/internal/terminal.js.map +1 -1
  19. package/dist/dts/NodeFileSystem/ParcelWatcher.d.ts +13 -0
  20. package/dist/dts/NodeFileSystem/ParcelWatcher.d.ts.map +1 -0
  21. package/dist/dts/NodeSocket.d.ts.map +1 -1
  22. package/dist/dts/internal/fileSystem/parcelWatcher.d.ts +4 -0
  23. package/dist/dts/internal/fileSystem/parcelWatcher.d.ts.map +1 -0
  24. package/dist/esm/NodeFileSystem/ParcelWatcher.js +12 -0
  25. package/dist/esm/NodeFileSystem/ParcelWatcher.js.map +1 -0
  26. package/dist/esm/NodeSocket.js +3 -3
  27. package/dist/esm/NodeSocket.js.map +1 -1
  28. package/dist/esm/internal/commandExecutor.js +5 -5
  29. package/dist/esm/internal/commandExecutor.js.map +1 -1
  30. package/dist/esm/internal/fileSystem/parcelWatcher.js +61 -0
  31. package/dist/esm/internal/fileSystem/parcelWatcher.js.map +1 -0
  32. package/dist/esm/internal/fileSystem.js +9 -54
  33. package/dist/esm/internal/fileSystem.js.map +1 -1
  34. package/dist/esm/internal/runtime.js +1 -1
  35. package/dist/esm/internal/runtime.js.map +1 -1
  36. package/dist/esm/internal/sink.js +1 -1
  37. package/dist/esm/internal/sink.js.map +1 -1
  38. package/dist/esm/internal/stream.js +10 -10
  39. package/dist/esm/internal/stream.js.map +1 -1
  40. package/dist/esm/internal/terminal.js +1 -1
  41. package/dist/esm/internal/terminal.js.map +1 -1
  42. package/package.json +3 -3
  43. package/src/NodeFileSystem/ParcelWatcher.ts +15 -0
  44. package/src/NodeSocket.ts +3 -3
  45. package/src/internal/commandExecutor.ts +5 -5
  46. package/src/internal/fileSystem/parcelWatcher.ts +62 -0
  47. package/src/internal/fileSystem.ts +39 -82
  48. package/src/internal/runtime.ts +1 -1
  49. package/src/internal/sink.ts +1 -1
  50. package/src/internal/stream.ts +10 -10
  51. package/src/internal/terminal.ts +1 -1
@@ -1,8 +1,7 @@
1
1
  import { effectify } from "@effect/platform/Effectify"
2
2
  import * as Error from "@effect/platform/Error"
3
3
  import * as FileSystem from "@effect/platform/FileSystem"
4
- import type * as ParcelWatcher from "@parcel/watcher"
5
- import * as Chunk from "effect/Chunk"
4
+ import type * as Context from "effect/Context"
6
5
  import * as Effect from "effect/Effect"
7
6
  import { pipe } from "effect/Function"
8
7
  import * as Layer from "effect/Layer"
@@ -349,7 +348,7 @@ const makeFile = (() => {
349
348
  this.position = this.position + BigInt(bytesWritten)
350
349
  }
351
350
 
352
- return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : Effect.unit
351
+ return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : Effect.void
353
352
  }
354
353
  )
355
354
  }
@@ -524,49 +523,6 @@ const utimes = (() => {
524
523
 
525
524
  // == watch
526
525
 
527
- const watchParcel = (Watcher: typeof ParcelWatcher, path: string) =>
528
- Stream.asyncScoped<FileSystem.WatchEvent, Error.PlatformError>((emit) =>
529
- Effect.acquireRelease(
530
- Effect.tryPromise({
531
- try: () =>
532
- Watcher.subscribe(path, (error, events) => {
533
- if (error) {
534
- emit.fail(Error.SystemError({
535
- reason: "Unknown",
536
- module: "FileSystem",
537
- method: "watch",
538
- pathOrDescriptor: path,
539
- message: error.message
540
- }))
541
- } else {
542
- emit.chunk(Chunk.unsafeFromArray(events.map((event) => {
543
- switch (event.type) {
544
- case "create": {
545
- return FileSystem.WatchEventCreate({ path: event.path })
546
- }
547
- case "update": {
548
- return FileSystem.WatchEventUpdate({ path: event.path })
549
- }
550
- case "delete": {
551
- return FileSystem.WatchEventRemove({ path: event.path })
552
- }
553
- }
554
- })))
555
- }
556
- }),
557
- catch: (error) =>
558
- Error.SystemError({
559
- reason: "Unknown",
560
- module: "FileSystem",
561
- method: "watch",
562
- pathOrDescriptor: path,
563
- message: (error as Error).message
564
- })
565
- }),
566
- (sub) => Effect.promise(() => sub.unsubscribe())
567
- )
568
- )
569
-
570
526
  const watchNode = (path: string) =>
571
527
  Stream.asyncScoped<FileSystem.WatchEvent, Error.PlatformError>((emit) =>
572
528
  Effect.acquireRelease(
@@ -605,15 +561,13 @@ const watchNode = (path: string) =>
605
561
  )
606
562
  )
607
563
 
608
- const watch = (path: string) =>
564
+ const watch = (backend: Option.Option<Context.Tag.Service<FileSystem.WatchBackend>>, path: string) =>
609
565
  stat(path).pipe(
610
- Effect.flatMap((stat) =>
611
- stat.type === "Directory" ?
612
- Effect.matchCause(Effect.promise(() => import("@parcel/watcher")), {
613
- onSuccess: (Watcher) => watchParcel(Watcher, path),
614
- onFailure: (_) => watchNode(path)
615
- }) :
616
- Effect.succeed(watchNode(path))
566
+ Effect.map((stat) =>
567
+ backend.pipe(
568
+ Option.flatMap((_) => _.register(path, stat)),
569
+ Option.getOrElse(() => watchNode(path))
570
+ )
617
571
  ),
618
572
  Stream.unwrap
619
573
  )
@@ -631,7 +585,7 @@ const writeFile = (path: string, data: Uint8Array, options?: FileSystem.WriteFil
631
585
  if (err) {
632
586
  resume(Effect.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])))
633
587
  } else {
634
- resume(Effect.unit)
588
+ resume(Effect.void)
635
589
  }
636
590
  })
637
591
  } catch (err) {
@@ -639,32 +593,35 @@ const writeFile = (path: string, data: Uint8Array, options?: FileSystem.WriteFil
639
593
  }
640
594
  })
641
595
 
642
- const fileSystemImpl = FileSystem.make({
643
- access,
644
- chmod,
645
- chown,
646
- copy,
647
- copyFile,
648
- link,
649
- makeDirectory,
650
- makeTempDirectory,
651
- makeTempDirectoryScoped,
652
- makeTempFile,
653
- makeTempFileScoped,
654
- open,
655
- readDirectory,
656
- readFile,
657
- readLink,
658
- realPath,
659
- remove,
660
- rename,
661
- stat,
662
- symlink,
663
- truncate,
664
- utimes,
665
- watch,
666
- writeFile
667
- })
596
+ const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) =>
597
+ FileSystem.make({
598
+ access,
599
+ chmod,
600
+ chown,
601
+ copy,
602
+ copyFile,
603
+ link,
604
+ makeDirectory,
605
+ makeTempDirectory,
606
+ makeTempDirectoryScoped,
607
+ makeTempFile,
608
+ makeTempFileScoped,
609
+ open,
610
+ readDirectory,
611
+ readFile,
612
+ readLink,
613
+ realPath,
614
+ remove,
615
+ rename,
616
+ stat,
617
+ symlink,
618
+ truncate,
619
+ utimes,
620
+ watch(path) {
621
+ return watch(backend, path)
622
+ },
623
+ writeFile
624
+ }))
668
625
 
669
626
  /** @internal */
670
- export const layer = Layer.succeed(FileSystem.FileSystem, fileSystemImpl)
627
+ export const layer = Layer.effect(FileSystem.FileSystem, makeFileSystem)
@@ -15,7 +15,7 @@ export const runMain: RunMain = (
15
15
  effect :
16
16
  Effect.tapErrorCause(effect, (cause) => {
17
17
  if (Cause.isInterruptedOnly(cause)) {
18
- return Effect.unit
18
+ return Effect.void
19
19
  }
20
20
  return Effect.logError(cause)
21
21
  })
@@ -33,7 +33,7 @@ export const fromWritableChannel = <IE, OE, A>(
33
33
  writable,
34
34
  (cause) => Deferred.failCause(deferred, cause),
35
35
  options,
36
- Deferred.complete(deferred, Effect.unit)
36
+ Deferred.complete(deferred, Effect.void)
37
37
  )
38
38
  )
39
39
  )
@@ -224,21 +224,21 @@ export const writeInput = <IE, A>(
224
224
  writable: Writable | NodeJS.WritableStream,
225
225
  onFailure: (cause: Cause.Cause<IE>) => Effect.Effect<void>,
226
226
  { encoding, endOnDone = true }: FromWritableOptions = {},
227
- onDone = Effect.unit
227
+ onDone = Effect.void
228
228
  ): AsyncInput.AsyncInputProducer<IE, Chunk.Chunk<A>, unknown> => {
229
229
  const write = writeEffect(writable, encoding)
230
230
  const close = endOnDone
231
231
  ? Effect.async<void>((resume) => {
232
232
  if ("closed" in writable && writable.closed) {
233
- resume(Effect.unit)
233
+ resume(Effect.void)
234
234
  } else {
235
- writable.once("finish", () => resume(Effect.unit))
235
+ writable.once("finish", () => resume(Effect.void))
236
236
  writable.end()
237
237
  }
238
238
  })
239
- : Effect.unit
239
+ : Effect.void
240
240
  return {
241
- awaitRead: () => Effect.unit,
241
+ awaitRead: () => Effect.void,
242
242
  emit: write,
243
243
  error: (cause) => Effect.zipRight(close, onFailure(cause)),
244
244
  done: (_) => Effect.zipRight(close, onDone)
@@ -252,7 +252,7 @@ export const writeEffect = <A>(
252
252
  ) =>
253
253
  (chunk: Chunk.Chunk<A>) =>
254
254
  chunk.length === 0 ?
255
- Effect.unit :
255
+ Effect.void :
256
256
  Effect.async<void>((resume) => {
257
257
  const iterator = chunk[Symbol.iterator]()
258
258
  let next = iterator.next()
@@ -261,7 +261,7 @@ export const writeEffect = <A>(
261
261
  next = iterator.next()
262
262
  const success = writable.write(item.value, encoding as any)
263
263
  if (next.done) {
264
- resume(Effect.unit)
264
+ resume(Effect.void)
265
265
  } else if (success) {
266
266
  loop()
267
267
  } else {
@@ -287,7 +287,7 @@ const readableOffer = <E>(
287
287
  queue.unsafeOffer(Either.left(Exit.fail(onError(err))))
288
288
  })
289
289
  readable.on("end", () => {
290
- queue.unsafeOffer(Either.left(Exit.unit))
290
+ queue.unsafeOffer(Either.left(Exit.void))
291
291
  })
292
292
  if (readable.readable) {
293
293
  queue.unsafeOffer(Either.right(void 0))
@@ -305,7 +305,7 @@ const readableTake = <E, A>(
305
305
  Either.match({
306
306
  onLeft: Exit.match({
307
307
  onFailure: Channel.failCause,
308
- onSuccess: (_) => Channel.unit
308
+ onSuccess: (_) => Channel.void
309
309
  }),
310
310
  onRight: (_) => Channel.flatMap(read, () => loop)
311
311
  })
@@ -376,7 +376,7 @@ class StreamAdapter<E, R> extends Readable {
376
376
  }
377
377
 
378
378
  _destroy(_error: Error | null, callback: (error?: Error | null | undefined) => void): void {
379
- Runtime.runFork(this.runtime)(Scope.close(this.scope, Exit.unit)).addObserver((exit) => {
379
+ Runtime.runFork(this.runtime)(Scope.close(this.scope, Exit.void)).addObserver((exit) => {
380
380
  callback(exit._tag === "Failure" ? Cause.squash(exit.cause) as any : null)
381
381
  })
382
382
  }
@@ -102,7 +102,7 @@ export const make = (
102
102
  message: (err as Error).message ?? String(err)
103
103
  })))
104
104
  }
105
- resume(Effect.unit)
105
+ resume(Effect.void)
106
106
  })
107
107
  })
108
108
  )