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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AsyncOption, MaybeSyncOption, PoweredFileSystem, SyncOption } from '../powered-file-system';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a path to its canonical absolute location.
|
|
4
|
+
*/
|
|
5
|
+
export declare function realpath(this: PoweredFileSystem, src: string, options: SyncOption & {
|
|
6
|
+
encoding?: BufferEncoding;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function realpath(this: PoweredFileSystem, src: string, options?: AsyncOption & {
|
|
9
|
+
encoding?: BufferEncoding;
|
|
10
|
+
}): Promise<string>;
|
|
11
|
+
export declare function realpath(this: PoweredFileSystem, src: string, options?: MaybeSyncOption & {
|
|
12
|
+
encoding?: BufferEncoding;
|
|
13
|
+
}): string | Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.realpath = realpath;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
function realpath(src, options) {
|
|
9
|
+
const { sync = false, encoding = 'utf8' } = options ?? {};
|
|
10
|
+
if (sync) {
|
|
11
|
+
return node_fs_1.default.realpathSync(this.resolve(src), { encoding });
|
|
12
|
+
}
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
try {
|
|
15
|
+
src = this.resolve(src);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
reject(err);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
node_fs_1.default.realpath(src, { encoding }, (err, resolved) => {
|
|
22
|
+
if (err) {
|
|
23
|
+
return reject(err);
|
|
24
|
+
}
|
|
25
|
+
resolve(resolved);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const node_test_1 = require("node:test");
|
|
10
|
+
const index_1 = require("../index");
|
|
11
|
+
const test_utils_1 = require("../test-utils");
|
|
12
|
+
/**
|
|
13
|
+
* Verifies canonical path resolution through symbolic links.
|
|
14
|
+
*/
|
|
15
|
+
(0, node_test_1.describe)('realpath(src [, options])', () => {
|
|
16
|
+
const chance = new chance_1.default();
|
|
17
|
+
let tmpDir = '';
|
|
18
|
+
(0, node_test_1.beforeEach)(() => {
|
|
19
|
+
tmpDir = (0, test_utils_1.createTmpDir)();
|
|
20
|
+
(0, test_utils_1.fmock)({
|
|
21
|
+
[node_path_1.default.join(tmpDir, 'tings.txt')]: {
|
|
22
|
+
type: 'file',
|
|
23
|
+
data: chance.string()
|
|
24
|
+
},
|
|
25
|
+
[node_path_1.default.join(tmpDir, 'flexapp')]: {
|
|
26
|
+
type: 'symlink',
|
|
27
|
+
target: node_path_1.default.join(tmpDir, 'tings.txt')
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
(0, node_test_1.afterEach)(() => {
|
|
32
|
+
(0, test_utils_1.restore)(tmpDir);
|
|
33
|
+
});
|
|
34
|
+
(0, node_test_1.it)('Positive: Resolves the canonical target path', async () => {
|
|
35
|
+
const target = await index_1.pfs.realpath(node_path_1.default.join(tmpDir, 'flexapp'));
|
|
36
|
+
(0, node_assert_1.default)(target === node_path_1.default.join(tmpDir, 'tings.txt'));
|
|
37
|
+
});
|
|
38
|
+
(0, node_test_1.it)('[sync] Positive: Resolves the canonical target path', () => {
|
|
39
|
+
const target = index_1.pfs.realpath(node_path_1.default.join(tmpDir, 'flexapp'), {
|
|
40
|
+
sync: true
|
|
41
|
+
});
|
|
42
|
+
(0, node_assert_1.default)(target === node_path_1.default.join(tmpDir, 'tings.txt'));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PoweredFileSystem } from '../powered-file-system';
|
|
1
|
+
import type { AsyncOption, MaybeSyncOption, PoweredFileSystem, SyncOption } from '../powered-file-system';
|
|
2
2
|
/**
|
|
3
|
-
* Removes a path relative to the instance
|
|
3
|
+
* Removes a path relative to the instance base path.
|
|
4
4
|
*/
|
|
5
|
-
export declare function remove
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function remove(this: PoweredFileSystem, src: string, options: SyncOption): void;
|
|
6
|
+
export declare function remove(this: PoweredFileSystem, src: string, options?: AsyncOption): Promise<void>;
|
|
7
|
+
export declare function remove(this: PoweredFileSystem, src: string, options?: MaybeSyncOption): void | Promise<void>;
|
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.remove = remove;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
4
|
const recurse_io_1 = require("../recurse-io");
|
|
10
5
|
const recurse_io_sync_1 = require("../recurse-io-sync");
|
|
11
|
-
/**
|
|
12
|
-
* Removes a path relative to the instance root, preferring native recursive APIs when available.
|
|
13
|
-
*/
|
|
14
6
|
function remove(src, options) {
|
|
15
|
-
src = node_path_1.default.resolve(this.pwd, src);
|
|
16
7
|
const { sync = false } = options ?? {};
|
|
17
8
|
if (sync) {
|
|
18
|
-
(0, recurse_io_sync_1.removeSync)(src);
|
|
19
|
-
return
|
|
9
|
+
(0, recurse_io_sync_1.removeSync)(this.resolve(src));
|
|
10
|
+
return;
|
|
20
11
|
}
|
|
21
12
|
return new Promise((resolve, reject) => {
|
|
22
|
-
|
|
13
|
+
try {
|
|
14
|
+
src = this.resolve(src);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
reject(err);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
(0, recurse_io_1.remove)(src, (err) => {
|
|
23
21
|
if (err) {
|
|
24
22
|
return reject(err);
|
|
25
23
|
}
|
|
26
24
|
resolve();
|
|
27
|
-
};
|
|
28
|
-
if ('rm' in node_fs_1.default) {
|
|
29
|
-
// Prefer the native recursive removal when the runtime supports it.
|
|
30
|
-
node_fs_1.default.rm(src, { recursive: true }, callback);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
(0, recurse_io_1.remove)(src, callback);
|
|
34
|
-
}
|
|
25
|
+
});
|
|
35
26
|
});
|
|
36
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PoweredFileSystem } from '../powered-file-system';
|
|
1
|
+
import type { AsyncOption, MaybeSyncOption, PoweredFileSystem, SyncOption } from '../powered-file-system';
|
|
2
2
|
/**
|
|
3
|
-
* Resolves both paths against the instance
|
|
3
|
+
* Resolves both paths against the instance base path before delegating to Node's rename API.
|
|
4
4
|
*/
|
|
5
|
-
export declare function rename
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function rename(this: PoweredFileSystem, src: string, dest: string, options: SyncOption): void;
|
|
6
|
+
export declare function rename(this: PoweredFileSystem, src: string, dest: string, options?: AsyncOption): Promise<void>;
|
|
7
|
+
export declare function rename(this: PoweredFileSystem, src: string, dest: string, options?: MaybeSyncOption): void | Promise<void>;
|
|
@@ -5,19 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.rename = rename;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
/**
|
|
10
|
-
* Resolves both paths against the instance root before delegating to Node's rename API.
|
|
11
|
-
*/
|
|
12
8
|
function rename(src, dest, options) {
|
|
13
|
-
src = node_path_1.default.resolve(this.pwd, src);
|
|
14
|
-
dest = node_path_1.default.resolve(this.pwd, dest);
|
|
15
9
|
const { sync = false } = options ?? {};
|
|
16
10
|
if (sync) {
|
|
11
|
+
src = this.resolve(src);
|
|
12
|
+
dest = this.resolve(dest);
|
|
17
13
|
node_fs_1.default.renameSync(src, dest);
|
|
18
|
-
return
|
|
14
|
+
return;
|
|
19
15
|
}
|
|
20
16
|
return new Promise((resolve, reject) => {
|
|
17
|
+
try {
|
|
18
|
+
src = this.resolve(src);
|
|
19
|
+
dest = this.resolve(dest);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
21
25
|
node_fs_1.default.rename(src, dest, (err) => {
|
|
22
26
|
if (err) {
|
|
23
27
|
return reject(err);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PoweredFileSystem, Stats } from '../powered-file-system';
|
|
1
|
+
import type { AsyncOption, MaybeSyncOption, PoweredFileSystem, Stats, SyncOption } from '../powered-file-system';
|
|
2
2
|
/**
|
|
3
3
|
* Returns `lstat` data so symlinks are reported as links instead of followed targets.
|
|
4
4
|
*/
|
|
5
|
-
export declare function stat
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function stat(this: PoweredFileSystem, src: string, options: SyncOption): Stats;
|
|
6
|
+
export declare function stat(this: PoweredFileSystem, src: string, options?: AsyncOption): Promise<Stats>;
|
|
7
|
+
export declare function stat(this: PoweredFileSystem, src: string, options?: MaybeSyncOption): Stats | Promise<Stats>;
|
|
@@ -5,17 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.stat = stat;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
/**
|
|
10
|
-
* Returns `lstat` data so symlinks are reported as links instead of followed targets.
|
|
11
|
-
*/
|
|
12
8
|
function stat(src, options) {
|
|
13
9
|
const { sync = false } = options ?? {};
|
|
14
|
-
src = node_path_1.default.resolve(this.pwd, src);
|
|
15
10
|
if (sync) {
|
|
16
|
-
return node_fs_1.default.lstatSync(src);
|
|
11
|
+
return node_fs_1.default.lstatSync(this.resolve(src));
|
|
17
12
|
}
|
|
18
13
|
return new Promise((resolve, reject) => {
|
|
14
|
+
try {
|
|
15
|
+
src = this.resolve(src);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
reject(err);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
19
21
|
node_fs_1.default.lstat(src, (err, stats) => {
|
|
20
22
|
if (err) {
|
|
21
23
|
return reject(err);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PoweredFileSystem } from '../powered-file-system';
|
|
2
|
-
export declare function symlink
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { AsyncOption, MaybeSyncOption, PoweredFileSystem, SyncOption } from '../powered-file-system';
|
|
2
|
+
export declare function symlink(this: PoweredFileSystem, src: string, dest: string, options: SyncOption): void;
|
|
3
|
+
export declare function symlink(this: PoweredFileSystem, src: string, dest: string, options?: AsyncOption): Promise<void>;
|
|
4
|
+
export declare function symlink(this: PoweredFileSystem, src: string, dest: string, options?: MaybeSyncOption): void | Promise<void>;
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.symlink = symlink;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
8
|
/**
|
|
10
9
|
* Windows requires an explicit link type. Non-Windows platforms infer it.
|
|
11
10
|
*/
|
|
@@ -17,15 +16,23 @@ function resolveSymlinkType(src) {
|
|
|
17
16
|
return stats.isDirectory() ? 'junction' : 'file';
|
|
18
17
|
}
|
|
19
18
|
function symlink(src, dest, options) {
|
|
20
|
-
src = node_path_1.default.resolve(this.pwd, src);
|
|
21
|
-
dest = node_path_1.default.resolve(this.pwd, dest);
|
|
22
19
|
const { sync = false } = options ?? {};
|
|
23
20
|
if (sync) {
|
|
21
|
+
src = this.resolve(src);
|
|
22
|
+
dest = this.resolve(dest);
|
|
24
23
|
const type = resolveSymlinkType(src);
|
|
25
24
|
node_fs_1.default.symlinkSync(src, dest, type);
|
|
26
|
-
return
|
|
25
|
+
return;
|
|
27
26
|
}
|
|
28
27
|
return new Promise((resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
src = this.resolve(src);
|
|
30
|
+
dest = this.resolve(dest);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
reject(err);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
29
36
|
if (process.platform === 'win32') {
|
|
30
37
|
node_fs_1.default.lstat(src, (err, stats) => {
|
|
31
38
|
if (err) {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { Mode, PoweredFileSystem } from '../powered-file-system';
|
|
1
|
+
import type { AsyncOption, MaybeSyncOption, Mode, PoweredFileSystem, SyncOption } from '../powered-file-system';
|
|
2
2
|
/**
|
|
3
|
-
* Thin wrapper around `fs.access` that resolves paths against the instance
|
|
3
|
+
* Thin wrapper around `fs.access` that resolves paths against the instance base path.
|
|
4
4
|
*/
|
|
5
|
-
export declare function test
|
|
6
|
-
sync?: T;
|
|
5
|
+
export declare function test(this: PoweredFileSystem, src: string, options: SyncOption & {
|
|
7
6
|
flag?: Mode;
|
|
8
|
-
}):
|
|
7
|
+
}): boolean;
|
|
8
|
+
export declare function test(this: PoweredFileSystem, src: string, options?: AsyncOption & {
|
|
9
|
+
flag?: Mode;
|
|
10
|
+
}): Promise<boolean>;
|
|
11
|
+
export declare function test(this: PoweredFileSystem, src: string, options?: MaybeSyncOption & {
|
|
12
|
+
flag?: Mode;
|
|
13
|
+
}): boolean | Promise<boolean>;
|
|
@@ -5,16 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.test = test;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
/**
|
|
10
|
-
* Thin wrapper around `fs.access` that resolves paths against the instance root.
|
|
11
|
-
*/
|
|
12
8
|
function test(src, options) {
|
|
13
9
|
const { sync = false, flag = 'e' } = options ?? {};
|
|
14
10
|
const mode = this.constants[flag];
|
|
15
|
-
src = node_path_1.default.resolve(this.pwd, src);
|
|
16
11
|
if (sync) {
|
|
17
12
|
try {
|
|
13
|
+
src = this.resolve(src);
|
|
18
14
|
node_fs_1.default.accessSync(src, mode);
|
|
19
15
|
return true;
|
|
20
16
|
}
|
|
@@ -23,6 +19,13 @@ function test(src, options) {
|
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
21
|
return new Promise((resolve) => {
|
|
22
|
+
try {
|
|
23
|
+
src = this.resolve(src);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
resolve(false);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
26
29
|
node_fs_1.default.access(src, mode, (err) => {
|
|
27
30
|
resolve(!err);
|
|
28
31
|
});
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { Flag, PoweredFileSystem } from '../powered-file-system';
|
|
2
|
-
|
|
3
|
-
* Writes a file relative to `pwd` and then reapplies the computed permissions explicitly.
|
|
4
|
-
*/
|
|
5
|
-
export declare function write<T extends boolean = false>(this: PoweredFileSystem, src: string, data: Buffer | string, options?: {
|
|
6
|
-
sync?: T;
|
|
1
|
+
import type { AsyncOption, Flag, MaybeSyncOption, PoweredFileSystem, SyncOption } from '../powered-file-system';
|
|
2
|
+
type WriteOptions = {
|
|
7
3
|
encoding?: BufferEncoding | null;
|
|
8
4
|
umask?: number;
|
|
9
5
|
flag?: Flag;
|
|
10
|
-
}
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Writes a file relative to `pwd` and then reapplies the computed permissions explicitly.
|
|
9
|
+
*/
|
|
10
|
+
export declare function write(this: PoweredFileSystem, src: string, data: Buffer | string, options: SyncOption & WriteOptions): void;
|
|
11
|
+
export declare function write(this: PoweredFileSystem, src: string, data: Buffer | string, options?: AsyncOption & WriteOptions): Promise<void>;
|
|
12
|
+
export declare function write(this: PoweredFileSystem, src: string, data: Buffer | string, options?: MaybeSyncOption & WriteOptions): void | Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -5,21 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.write = write;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
/**
|
|
10
|
-
* Writes a file relative to `pwd` and then reapplies the computed permissions explicitly.
|
|
11
|
-
*/
|
|
12
8
|
function write(src, data, options) {
|
|
13
9
|
const { sync = false, encoding = 'utf8', umask = 0o000, flag = 'w', } = options ?? {};
|
|
14
|
-
src = node_path_1.default.resolve(this.pwd, src);
|
|
15
10
|
const mode = 0o666 & ~umask;
|
|
16
11
|
if (sync) {
|
|
12
|
+
src = this.resolve(src);
|
|
17
13
|
// Apply chmod explicitly so the final mode is deterministic across runtimes.
|
|
18
14
|
node_fs_1.default.writeFileSync(src, data, { encoding, mode, flag });
|
|
19
15
|
node_fs_1.default.chmodSync(src, mode);
|
|
20
|
-
return
|
|
16
|
+
return;
|
|
21
17
|
}
|
|
22
18
|
return new Promise((resolve, reject) => {
|
|
19
|
+
try {
|
|
20
|
+
src = this.resolve(src);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
reject(err);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
23
26
|
node_fs_1.default.writeFile(src, data, { encoding, mode, flag }, (err) => {
|
|
24
27
|
if (err) {
|
|
25
28
|
return reject(err);
|
|
@@ -6,6 +6,28 @@ import { bitmask } from './bitmask';
|
|
|
6
6
|
export type Mode = keyof IConstants;
|
|
7
7
|
export type Flag = Extract<fs.OpenMode, string>;
|
|
8
8
|
export type Stats = fs.Stats;
|
|
9
|
+
export type CopyFilter = (src: string, dest: string) => boolean;
|
|
10
|
+
export type SyncResult<T extends boolean, TResult> = T extends true ? TResult : Promise<TResult>;
|
|
11
|
+
export type SyncOption = {
|
|
12
|
+
sync: true;
|
|
13
|
+
};
|
|
14
|
+
export type AsyncOption = {
|
|
15
|
+
sync?: false;
|
|
16
|
+
};
|
|
17
|
+
export type MaybeSyncOption = {
|
|
18
|
+
sync?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type ReadResult<TEncoding> = TEncoding extends null ? Buffer : string;
|
|
21
|
+
export type ReaddirResult<TEncoding> = TEncoding extends null ? Buffer[] : string[];
|
|
22
|
+
export type ReadOptions<TSync extends boolean = boolean, TEncoding extends BufferEncoding | null = BufferEncoding> = {
|
|
23
|
+
sync?: TSync;
|
|
24
|
+
encoding?: TEncoding;
|
|
25
|
+
flag?: Flag;
|
|
26
|
+
};
|
|
27
|
+
export type ReaddirOptions<TSync extends boolean = boolean, TEncoding extends BufferEncoding | null = BufferEncoding> = {
|
|
28
|
+
sync?: TSync;
|
|
29
|
+
encoding?: TEncoding;
|
|
30
|
+
};
|
|
9
31
|
export * from './bitmask';
|
|
10
32
|
export interface IConstants {
|
|
11
33
|
e: number;
|
|
@@ -16,8 +38,7 @@ export interface IConstants {
|
|
|
16
38
|
/**
|
|
17
39
|
* Path-aware wrapper around Node's file system APIs.
|
|
18
40
|
*
|
|
19
|
-
*
|
|
20
|
-
* suitable for sandboxed or virtual working-directory workflows.
|
|
41
|
+
* Relative paths are resolved against `pwd`; absolute paths are preserved.
|
|
21
42
|
*/
|
|
22
43
|
export declare class PoweredFileSystem {
|
|
23
44
|
readonly pwd: string;
|
|
@@ -33,95 +54,144 @@ export declare class PoweredFileSystem {
|
|
|
33
54
|
* @param pwd Base directory used to resolve all relative paths.
|
|
34
55
|
*/
|
|
35
56
|
constructor(pwd?: string);
|
|
57
|
+
/**
|
|
58
|
+
* Resolves relative paths against `pwd` while preserving absolute paths.
|
|
59
|
+
*/
|
|
60
|
+
resolve(src: string): string;
|
|
36
61
|
/**
|
|
37
62
|
* Checks whether the given path is accessible with the requested mode.
|
|
38
63
|
*/
|
|
39
|
-
test
|
|
40
|
-
|
|
64
|
+
test(src: string, options: SyncOption & {
|
|
65
|
+
flag?: Mode;
|
|
66
|
+
}): boolean;
|
|
67
|
+
test(src: string, options?: AsyncOption & {
|
|
41
68
|
flag?: Mode;
|
|
42
|
-
}):
|
|
69
|
+
}): Promise<boolean>;
|
|
43
70
|
/**
|
|
44
71
|
* Returns `lstat` information for a path.
|
|
45
72
|
*/
|
|
46
|
-
stat
|
|
47
|
-
|
|
48
|
-
}): T extends true ? Stats : Promise<Stats>;
|
|
73
|
+
stat(src: string, options: SyncOption): Stats;
|
|
74
|
+
stat(src: string, options?: AsyncOption): Promise<Stats>;
|
|
49
75
|
/**
|
|
50
76
|
* Applies a mode recursively to a file or directory tree.
|
|
51
77
|
*/
|
|
52
|
-
chmod
|
|
53
|
-
|
|
54
|
-
}): T extends true ? void : Promise<void>;
|
|
78
|
+
chmod(src: string, mode: number, options: SyncOption): void;
|
|
79
|
+
chmod(src: string, mode: number, options?: AsyncOption): Promise<void>;
|
|
55
80
|
/**
|
|
56
81
|
* Applies ownership recursively to a file or directory tree.
|
|
57
82
|
*/
|
|
58
|
-
chown
|
|
59
|
-
sync?: T;
|
|
83
|
+
chown(src: string, options: SyncOption & {
|
|
60
84
|
uid?: number;
|
|
61
85
|
gid?: number;
|
|
62
|
-
}):
|
|
86
|
+
}): void;
|
|
87
|
+
chown(src: string, options?: AsyncOption & {
|
|
88
|
+
uid?: number;
|
|
89
|
+
gid?: number;
|
|
90
|
+
}): Promise<void>;
|
|
63
91
|
/**
|
|
64
92
|
* Creates a symbolic link from `dest` to `src`.
|
|
65
93
|
*/
|
|
66
|
-
symlink
|
|
67
|
-
|
|
68
|
-
}): T extends true ? void : Promise<void>;
|
|
94
|
+
symlink(src: string, dest: string, options: SyncOption): void;
|
|
95
|
+
symlink(src: string, dest: string, options?: AsyncOption): Promise<void>;
|
|
69
96
|
/**
|
|
70
97
|
* Copies `src` into the destination directory.
|
|
71
98
|
*/
|
|
72
|
-
copy
|
|
73
|
-
|
|
99
|
+
copy(src: string, dest: string, options: SyncOption & {
|
|
100
|
+
umask?: number;
|
|
101
|
+
overwrite?: boolean;
|
|
102
|
+
filter?: CopyFilter;
|
|
103
|
+
}): void;
|
|
104
|
+
copy(src: string, dest: string, options?: AsyncOption & {
|
|
74
105
|
umask?: number;
|
|
75
|
-
|
|
106
|
+
overwrite?: boolean;
|
|
107
|
+
filter?: CopyFilter;
|
|
108
|
+
}): Promise<void>;
|
|
76
109
|
/**
|
|
77
110
|
* Renames or moves a file system node.
|
|
78
111
|
*/
|
|
79
|
-
rename
|
|
80
|
-
|
|
81
|
-
}): T extends true ? void : Promise<void>;
|
|
112
|
+
rename(src: string, dest: string, options: SyncOption): void;
|
|
113
|
+
rename(src: string, dest: string, options?: AsyncOption): Promise<void>;
|
|
82
114
|
/**
|
|
83
115
|
* Removes a file system node recursively.
|
|
84
116
|
*/
|
|
85
|
-
remove
|
|
86
|
-
|
|
87
|
-
}): T extends true ? void : Promise<void>;
|
|
117
|
+
remove(src: string, options: SyncOption): void;
|
|
118
|
+
remove(src: string, options?: AsyncOption): Promise<void>;
|
|
88
119
|
/**
|
|
89
|
-
*
|
|
120
|
+
* Removes all directory entries while preserving the directory itself.
|
|
90
121
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
122
|
+
emptyDir(src: string, options: SyncOption): void;
|
|
123
|
+
emptyDir(src: string, options?: AsyncOption): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Reads a file relative to the current instance path.
|
|
126
|
+
*/
|
|
127
|
+
read(src: string, options: SyncOption & ReadOptions<true, null> & {
|
|
128
|
+
encoding: null;
|
|
129
|
+
}): Buffer;
|
|
130
|
+
read(src: string, options: SyncOption & ReadOptions<true, BufferEncoding>): string;
|
|
131
|
+
read(src: string, options: AsyncOption & ReadOptions<false, null> & {
|
|
132
|
+
encoding: null;
|
|
133
|
+
}): Promise<Buffer>;
|
|
134
|
+
read(src: string, options?: AsyncOption & ReadOptions<false, BufferEncoding>): Promise<string>;
|
|
96
135
|
/**
|
|
97
136
|
* Writes a file and applies the resulting permissions explicitly.
|
|
98
137
|
*/
|
|
99
|
-
write
|
|
100
|
-
sync?: T;
|
|
138
|
+
write(src: string, data: Buffer | string, options: SyncOption & {
|
|
101
139
|
encoding?: BufferEncoding | null;
|
|
102
140
|
umask?: number;
|
|
103
141
|
flag?: Flag;
|
|
104
|
-
}):
|
|
142
|
+
}): void;
|
|
143
|
+
write(src: string, data: Buffer | string, options?: AsyncOption & {
|
|
144
|
+
encoding?: BufferEncoding | null;
|
|
145
|
+
umask?: number;
|
|
146
|
+
flag?: Flag;
|
|
147
|
+
}): Promise<void>;
|
|
105
148
|
/**
|
|
106
149
|
* @deprecated Use `write(..., { flag: 'a' })` instead.
|
|
107
150
|
*/
|
|
108
|
-
append
|
|
109
|
-
sync?: T;
|
|
151
|
+
append(src: string, data: Buffer | string, options: SyncOption & {
|
|
110
152
|
encoding?: BufferEncoding | null;
|
|
111
153
|
umask?: number;
|
|
112
|
-
}):
|
|
154
|
+
}): void;
|
|
155
|
+
append(src: string, data: Buffer | string, options?: AsyncOption & {
|
|
156
|
+
encoding?: BufferEncoding | null;
|
|
157
|
+
umask?: number;
|
|
158
|
+
}): Promise<void>;
|
|
113
159
|
/**
|
|
114
|
-
* Lists directory entries relative to the current instance
|
|
160
|
+
* Lists directory entries relative to the current instance path.
|
|
115
161
|
*/
|
|
116
|
-
readdir
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
readdir(dir: string, options: SyncOption & ReaddirOptions<true, null> & {
|
|
163
|
+
encoding: null;
|
|
164
|
+
}): Buffer[];
|
|
165
|
+
readdir(dir: string, options: SyncOption & ReaddirOptions<true, BufferEncoding>): string[];
|
|
166
|
+
readdir(dir: string, options: AsyncOption & ReaddirOptions<false, null> & {
|
|
167
|
+
encoding: null;
|
|
168
|
+
}): Promise<Buffer[]>;
|
|
169
|
+
readdir(dir: string, options?: AsyncOption & ReaddirOptions<false, BufferEncoding>): Promise<string[]>;
|
|
120
170
|
/**
|
|
121
|
-
*
|
|
171
|
+
* Resolves the target of a symbolic link.
|
|
122
172
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
173
|
+
readlink(src: string, options: SyncOption & {
|
|
174
|
+
encoding?: BufferEncoding;
|
|
175
|
+
}): string;
|
|
176
|
+
readlink(src: string, options?: AsyncOption & {
|
|
177
|
+
encoding?: BufferEncoding;
|
|
178
|
+
}): Promise<string>;
|
|
179
|
+
/**
|
|
180
|
+
* Resolves a path to its canonical absolute location.
|
|
181
|
+
*/
|
|
182
|
+
realpath(src: string, options: SyncOption & {
|
|
183
|
+
encoding?: BufferEncoding;
|
|
184
|
+
}): string;
|
|
185
|
+
realpath(src: string, options?: AsyncOption & {
|
|
186
|
+
encoding?: BufferEncoding;
|
|
187
|
+
}): Promise<string>;
|
|
188
|
+
/**
|
|
189
|
+
* Creates a directory tree relative to the current instance path.
|
|
190
|
+
*/
|
|
191
|
+
mkdir(dir: string, options: SyncOption & {
|
|
192
|
+
umask?: number;
|
|
193
|
+
}): void;
|
|
194
|
+
mkdir(dir: string, options?: AsyncOption & {
|
|
125
195
|
umask?: number;
|
|
126
|
-
}):
|
|
196
|
+
}): Promise<void>;
|
|
127
197
|
}
|