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

NodePath.ts

60 lines1.9 KB

1/**
2 * Node.js layers for Effect's `Path` service.
3 *
4 * This module adapts Node's path and file URL behavior to the
5 * platform-independent `Path` service. Provide one of its layers when a Node
6 * program needs to build, normalize, parse, resolve, or convert paths without
7 * depending directly on `node:path`.
8 *
9 * **Mental model**
10 *
11 * `Path` is a syntactic service: it manipulates strings and `file:` URLs. It
12 * does not read the filesystem, check permissions, or validate that paths
13 * exist. The selected layer decides which separator, drive-letter, UNC, and URL
14 * conversion rules are used.
15 *
16 * **Common tasks**
17 *
18 * Use `layer` for host-platform Node semantics, `layerPosix` for stable POSIX
19 * behavior, and `layerWin32` for stable Windows behavior. `NodeServices.layer`
20 * already includes `layer`, so import this module directly when a program wants
21 * only path support or a platform-specific variant.
22 *
23 * **Gotchas**
24 *
25 * Results that are correct on one platform may not be portable to another.
26 * `fromFileUrl` and `toFileUrl` use Node's `node:url` conversion rules and
27 * report invalid conversions as `BadArgument` failures.
28 *
29 * @since 4.0.0
30 */
31import * as NodePath from "@effect/platform-node-shared/NodePath"
32import type * as Layer from "effect/Layer"
33import type { Path } from "effect/Path"
34​
35/**
36 * Provides the default Node `Path` service using the platform's `node:path`
37 * implementation.
38 *
39 * @category layers
40 * @since 4.0.0
41 */
42export const layer: Layer.Layer<Path> = NodePath.layer
43​
44/**
45 * Provides the `Path` service using Node's POSIX path implementation,
46 * regardless of the host platform.
47 *
48 * @category layers
49 * @since 4.0.0
50 */
51export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
52​
53/**
54 * Provides the `Path` service using Node's Windows path implementation,
55 * regardless of the host platform.
56 *
57 * @category layers
58 * @since 4.0.0
59 */
60export const layerWin32: Layer.Layer<Path> = NodePath.layerWin32