Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

NodeFileSystem.ts

39 lines1.6 KB

1/**
2 * Node.js `FileSystem` layer for programs that perform real filesystem I/O.
3 *
4 * The exported layer satisfies the platform-independent `FileSystem` service
5 * with Node-backed operations for files, directories, metadata, permissions,
6 * links, temporary paths, and path watching. Effects still call the service from
7 * `effect/FileSystem`; this module only chooses the Node implementation.
8 *
9 * **Mental model**
10 *
11 * Provide `NodeFileSystem.layer` at the process boundary when filesystem
12 * effects should touch the host filesystem. Use `NodeServices.layer` instead
13 * when the same program also needs the standard Node path, stdio, terminal,
14 * crypto, and child process services. Tests that need isolation can provide a
15 * different `FileSystem` layer without changing the code that performs the
16 * reads and writes.
17 *
18 * **Gotchas**
19 *
20 * Paths are interpreted by Node, so relative paths resolve against the current
21 * working directory and platform-specific path rules apply. Filesystem failures
22 * are reported through Effect platform errors rather than thrown exceptions.
23 * File watching uses `FileSystem.WatchBackend` when one is available; otherwise
24 * it follows `node:fs.watch`, whose recursive support, event batching, and
25 * reported path names vary across operating systems.
26 *
27 * @since 4.0.0
28 */
29import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem"
30import type { FileSystem } from "effect/FileSystem"
31import type * as Layer from "effect/Layer"
32​
33/**
34 * Provides the `FileSystem` service backed by Node filesystem APIs.
35 *
36 * @category layers
37 * @since 4.0.0
38 */
39export const layer: Layer.Layer<FileSystem> = NodeFileSystem.layer