pwd-fs 3.3.5 → 3.5.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/powered-file-system/append.d.ts +9 -6
- package/dist/powered-file-system/append.js +4 -4
- package/dist/powered-file-system/chmod.d.ts +4 -4
- package/dist/powered-file-system/chmod.js +9 -10
- package/dist/powered-file-system/chown.d.ts +7 -4
- package/dist/powered-file-system/chown.js +18 -8
- package/dist/powered-file-system/copy.d.ts +10 -5
- package/dist/powered-file-system/copy.js +13 -13
- package/dist/powered-file-system/copy.test.js +46 -0
- package/dist/powered-file-system/empty-dir.d.ts +7 -0
- package/dist/powered-file-system/empty-dir.js +27 -0
- package/dist/powered-file-system/empty-dir.test.d.ts +1 -0
- package/dist/powered-file-system/empty-dir.test.js +61 -0
- package/dist/powered-file-system/mkdir.d.ts +9 -6
- package/dist/powered-file-system/mkdir.js +9 -10
- package/dist/powered-file-system/read.d.ts +10 -6
- package/dist/powered-file-system/read.js +9 -5
- package/dist/powered-file-system/readdir.d.ts +11 -6
- package/dist/powered-file-system/readdir.js +8 -6
- package/dist/powered-file-system/readlink.d.ts +13 -0
- package/dist/powered-file-system/readlink.js +28 -0
- package/dist/powered-file-system/readlink.test.d.ts +1 -0
- package/dist/powered-file-system/readlink.test.js +44 -0
- package/dist/powered-file-system/realpath.d.ts +13 -0
- package/dist/powered-file-system/realpath.js +28 -0
- package/dist/powered-file-system/realpath.test.d.ts +1 -0
- package/dist/powered-file-system/realpath.test.js +44 -0
- package/dist/powered-file-system/remove.d.ts +5 -5
- package/dist/powered-file-system/remove.js +11 -20
- package/dist/powered-file-system/rename.d.ts +5 -5
- package/dist/powered-file-system/rename.js +11 -7
- package/dist/powered-file-system/stat.d.ts +4 -4
- package/dist/powered-file-system/stat.js +8 -6
- package/dist/powered-file-system/symlink.d.ts +4 -4
- package/dist/powered-file-system/symlink.js +11 -4
- package/dist/powered-file-system/test.d.ts +10 -5
- package/dist/powered-file-system/test.js +8 -5
- package/dist/powered-file-system/write.d.ts +10 -7
- package/dist/powered-file-system/write.js +9 -6
- package/dist/powered-file-system.d.ts +117 -47
- package/dist/powered-file-system.js +17 -39
- package/dist/powered-file-system.test.js +25 -0
- package/dist/recurse-io-sync.d.ts +7 -2
- package/dist/recurse-io-sync.js +38 -32
- package/dist/recurse-io.d.ts +11 -2
- package/dist/recurse-io.js +122 -57
- package/dist/suite.test.js +1 -1
- package/package.json +11 -16
- package/readme.md +133 -12
package/readme.md
CHANGED
|
@@ -12,11 +12,11 @@ It provides:
|
|
|
12
12
|
- matching synchronous variants via `{ sync: true }`
|
|
13
13
|
- recursive helpers for copy, remove, chmod, chown, and mkdir
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Relative paths are resolved against `pfs.pwd`. Absolute paths are used as-is, so `pfs.pwd` is a convenience base path, not a sandbox.
|
|
16
16
|
|
|
17
17
|
## Why Use It
|
|
18
18
|
|
|
19
|
-
Use `pwd-fs` when you want file system operations to be
|
|
19
|
+
Use `pwd-fs` when you want file system operations to be rooted at a specific working directory without manually calling `path.resolve()` before every operation.
|
|
20
20
|
|
|
21
21
|
It is especially useful for:
|
|
22
22
|
|
|
@@ -31,6 +31,43 @@ It is especially useful for:
|
|
|
31
31
|
npm install pwd-fs
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
- [Quick Start](#quick-start)
|
|
37
|
+
- [Common Recipes](#common-recipes)
|
|
38
|
+
- [Compatibility](#compatibility)
|
|
39
|
+
- [Exports](#exports)
|
|
40
|
+
- [API](#api)
|
|
41
|
+
- [`new PoweredFileSystem(pwd?)`](#new-poweredfilesystempwd)
|
|
42
|
+
- [`pfs.pwd`](#pfspwd)
|
|
43
|
+
- [`pfs.resolve(src)`](#pfsresolvesrc)
|
|
44
|
+
- [`pfs.constants`](#pfsconstants)
|
|
45
|
+
- [`PoweredFileSystem.bitmask(mode)`](#poweredfilesystembitmaskmode)
|
|
46
|
+
- [`pfs.test(src, options?)`](#pfstestsrc-options)
|
|
47
|
+
- [`pfs.stat(src, options?)`](#pfsstatsrc-options)
|
|
48
|
+
- [`pfs.chmod(src, mode, options?)`](#pfschmodsrc-mode-options)
|
|
49
|
+
- [`pfs.chown(src, options?)`](#pfschownsrc-options)
|
|
50
|
+
- [`pfs.symlink(src, dest, options?)`](#pfssymlinksrc-dest-options)
|
|
51
|
+
- [`pfs.copy(src, dest, options?)`](#pfscopysrc-dest-options)
|
|
52
|
+
- [`pfs.rename(src, dest, options?)`](#pfsrenamesrc-dest-options)
|
|
53
|
+
- [`pfs.remove(src, options?)`](#pfsremovesrc-options)
|
|
54
|
+
- [`pfs.emptyDir(src, options?)`](#pfsemptydirsrc-options)
|
|
55
|
+
- [`pfs.read(src, options?)`](#pfsreadsrc-options)
|
|
56
|
+
- [`pfs.write(src, data, options?)`](#pfswritesrc-data-options)
|
|
57
|
+
- [`pfs.append(src, data, options?)`](#pfsappendsrc-data-options)
|
|
58
|
+
- [`pfs.readdir(dir, options?)`](#pfsreaddirdir-options)
|
|
59
|
+
- [`pfs.readlink(src, options?)`](#pfsreadlinksrc-options)
|
|
60
|
+
- [`pfs.realpath(src, options?)`](#pfsrealpathsrc-options)
|
|
61
|
+
- [`pfs.mkdir(dir, options?)`](#pfsmkdirdir-options)
|
|
62
|
+
- [Sync Mode](#sync-mode)
|
|
63
|
+
- [Error Behavior](#error-behavior)
|
|
64
|
+
- [Umask Behavior](#umask-behavior)
|
|
65
|
+
- [Notes](#notes)
|
|
66
|
+
- [Platform Caveats](#platform-caveats)
|
|
67
|
+
- [When To Use Native `fs`](#when-to-use-native-fs)
|
|
68
|
+
- [Development](#development)
|
|
69
|
+
- [License](#license)
|
|
70
|
+
|
|
34
71
|
## Quick Start
|
|
35
72
|
|
|
36
73
|
```ts
|
|
@@ -41,7 +78,7 @@ await pfs.mkdir('./own/project'); // recursively create the directory
|
|
|
41
78
|
|
|
42
79
|
## Common Recipes
|
|
43
80
|
|
|
44
|
-
### Work inside a
|
|
81
|
+
### Work inside a project directory
|
|
45
82
|
|
|
46
83
|
```ts
|
|
47
84
|
import { PoweredFileSystem } from 'pwd-fs';
|
|
@@ -65,6 +102,19 @@ Result:
|
|
|
65
102
|
- destination directory: `./dist`
|
|
66
103
|
- created output: `./dist/assets`
|
|
67
104
|
|
|
105
|
+
### Empty a directory but keep it
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
await pfs.emptyDir('./cache');
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Resolve a symlink target
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const target = await pfs.readlink('./current');
|
|
115
|
+
const resolved = await pfs.realpath('./current');
|
|
116
|
+
```
|
|
117
|
+
|
|
68
118
|
### Append to a file
|
|
69
119
|
|
|
70
120
|
```ts
|
|
@@ -88,7 +138,7 @@ if (await pfs.test('./tmp')) {
|
|
|
88
138
|
|
|
89
139
|
## Compatibility
|
|
90
140
|
|
|
91
|
-
- package `engines`: Node.js `>=
|
|
141
|
+
- package `engines`: Node.js `>=18`
|
|
92
142
|
- module format: CommonJS package output with TypeScript declarations
|
|
93
143
|
- platform notes:
|
|
94
144
|
- `chown()` is effectively a no-op on Windows apart from path validation
|
|
@@ -109,7 +159,7 @@ import PoweredFileSystem, { pfs, bitmask } from 'pwd-fs';
|
|
|
109
159
|
|
|
110
160
|
### `new PoweredFileSystem(pwd?)`
|
|
111
161
|
|
|
112
|
-
Creates a new instance
|
|
162
|
+
Creates a new instance with `pwd` as the base directory for relative paths.
|
|
113
163
|
|
|
114
164
|
- `pwd?: string`
|
|
115
165
|
- default: `process.cwd()`
|
|
@@ -122,7 +172,22 @@ const pfs = new PoweredFileSystem('./workspace');
|
|
|
122
172
|
|
|
123
173
|
### `pfs.pwd`
|
|
124
174
|
|
|
125
|
-
Absolute base directory used to resolve
|
|
175
|
+
Absolute base directory used to resolve relative paths.
|
|
176
|
+
|
|
177
|
+
### `pfs.resolve(src)`
|
|
178
|
+
|
|
179
|
+
Resolves `src` against `pfs.pwd`.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const pfs = new PoweredFileSystem('/workspace/project');
|
|
183
|
+
const file = pfs.resolve('./src/index.ts');
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Absolute paths are preserved:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
pfs.resolve('/tmp/outside.txt'); // '/tmp/outside.txt'
|
|
190
|
+
```
|
|
126
191
|
|
|
127
192
|
### `pfs.constants`
|
|
128
193
|
|
|
@@ -232,7 +297,12 @@ Copies `src` into the destination directory.
|
|
|
232
297
|
copy<T extends boolean = false>(
|
|
233
298
|
src: string,
|
|
234
299
|
dest: string,
|
|
235
|
-
options?: {
|
|
300
|
+
options?: {
|
|
301
|
+
sync?: T;
|
|
302
|
+
umask?: number;
|
|
303
|
+
overwrite?: boolean;
|
|
304
|
+
filter?: (src: string, dest: string) => boolean;
|
|
305
|
+
}
|
|
236
306
|
): T extends true ? void : Promise<void>
|
|
237
307
|
```
|
|
238
308
|
|
|
@@ -241,6 +311,8 @@ Behavior:
|
|
|
241
311
|
- copying a file creates `dest/<basename(src)>`
|
|
242
312
|
- copying a directory creates `dest/<basename(src)>` recursively
|
|
243
313
|
- the target must not already exist
|
|
314
|
+
- `overwrite: true` replaces an existing target entry with the same basename
|
|
315
|
+
- `filter()` can skip specific source entries during the copy
|
|
244
316
|
|
|
245
317
|
```ts
|
|
246
318
|
await pfs.copy('./assets', './dist');
|
|
@@ -248,6 +320,13 @@ await pfs.copy('./assets', './dist');
|
|
|
248
320
|
|
|
249
321
|
This creates `./dist/assets`, not a direct rename to `./dist`.
|
|
250
322
|
|
|
323
|
+
```ts
|
|
324
|
+
await pfs.copy('./assets', './dist', {
|
|
325
|
+
overwrite: true,
|
|
326
|
+
filter: (src) => !src.endsWith('.map')
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
251
330
|
### `pfs.rename(src, dest, options?)`
|
|
252
331
|
|
|
253
332
|
Renames or moves a file system entry.
|
|
@@ -276,6 +355,21 @@ Behavior:
|
|
|
276
355
|
- directories are removed recursively
|
|
277
356
|
- symbolic links are unlinked without deleting the target
|
|
278
357
|
|
|
358
|
+
### `pfs.emptyDir(src, options?)`
|
|
359
|
+
|
|
360
|
+
Removes all entries inside a directory while preserving the directory itself.
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
emptyDir<T extends boolean = false>(
|
|
364
|
+
src: string,
|
|
365
|
+
options?: { sync?: T }
|
|
366
|
+
): T extends true ? void : Promise<void>
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
await pfs.emptyDir('./tmp');
|
|
371
|
+
```
|
|
372
|
+
|
|
279
373
|
### `pfs.read(src, options?)`
|
|
280
374
|
|
|
281
375
|
Reads a file.
|
|
@@ -363,6 +457,28 @@ readdir<T extends boolean = false>(
|
|
|
363
457
|
|
|
364
458
|
- default `encoding`: `'utf8'`
|
|
365
459
|
|
|
460
|
+
### `pfs.readlink(src, options?)`
|
|
461
|
+
|
|
462
|
+
Reads the stored target path from a symbolic link.
|
|
463
|
+
|
|
464
|
+
```ts
|
|
465
|
+
readlink<T extends boolean = false>(
|
|
466
|
+
src: string,
|
|
467
|
+
options?: { sync?: T; encoding?: BufferEncoding }
|
|
468
|
+
): T extends true ? string : Promise<string>
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### `pfs.realpath(src, options?)`
|
|
472
|
+
|
|
473
|
+
Resolves a path to its canonical absolute location.
|
|
474
|
+
|
|
475
|
+
```ts
|
|
476
|
+
realpath<T extends boolean = false>(
|
|
477
|
+
src: string,
|
|
478
|
+
options?: { sync?: T; encoding?: BufferEncoding }
|
|
479
|
+
): T extends true ? string : Promise<string>
|
|
480
|
+
```
|
|
481
|
+
|
|
366
482
|
### `pfs.mkdir(dir, options?)`
|
|
367
483
|
|
|
368
484
|
Creates a directory tree recursively.
|
|
@@ -400,11 +516,14 @@ Typical cases:
|
|
|
400
516
|
- `test()` is the exception:
|
|
401
517
|
it returns `false` for inaccessible or missing paths instead of rejecting or throwing
|
|
402
518
|
- `read()`, `stat()`, `readdir()`, `chmod()`, `chown()`, `rename()`, and `remove()` fail for missing paths
|
|
519
|
+
- `readlink()` and `realpath()` fail for missing paths
|
|
403
520
|
- `read()` fails when the target is a directory
|
|
404
521
|
- `readdir()` fails when the target is not a directory
|
|
522
|
+
- `emptyDir()` fails when the target is not a directory
|
|
405
523
|
- `write()` fails when the target path points to a directory
|
|
406
524
|
- `copy()` fails when the source does not exist
|
|
407
|
-
- `copy()`
|
|
525
|
+
- `copy()` fails when the destination already contains an entry with the same basename as the source, unless `overwrite: true` is used
|
|
526
|
+
- `copy()` fails when a directory is copied into itself
|
|
408
527
|
- `symlink()` fails when the destination already exists
|
|
409
528
|
- `mkdir()` accepts an existing directory, but fails when a path segment is a file
|
|
410
529
|
|
|
@@ -433,7 +552,8 @@ Effective permissions:
|
|
|
433
552
|
|
|
434
553
|
## Notes
|
|
435
554
|
|
|
436
|
-
- Relative paths are
|
|
555
|
+
- Relative paths are resolved against `pfs.pwd`
|
|
556
|
+
- Absolute paths are not constrained by `pfs.pwd`
|
|
437
557
|
- `stat()` returns `lstat()` data
|
|
438
558
|
- `remove()` does not follow symbolic links
|
|
439
559
|
- `append()` is kept for backward compatibility and is deprecated
|
|
@@ -460,9 +580,10 @@ Prefer native `node:fs` APIs directly when you need:
|
|
|
460
580
|
## Development
|
|
461
581
|
|
|
462
582
|
```bash
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
583
|
+
yarn install --frozen-lockfile
|
|
584
|
+
yarn lint
|
|
585
|
+
yarn build
|
|
586
|
+
yarn test
|
|
466
587
|
```
|
|
467
588
|
|
|
468
589
|
## License
|