pwd-fs 3.2.4 → 3.3.2

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 (101) hide show
  1. package/dist/bitmask.d.ts +4 -0
  2. package/dist/bitmask.js +17 -0
  3. package/dist/bitmask.test.d.ts +1 -0
  4. package/dist/bitmask.test.js +29 -0
  5. package/dist/{src/index.d.ts → index.d.ts} +3 -0
  6. package/dist/{src/index.js → index.js} +3 -0
  7. package/dist/powered-file-system/append.d.ts +9 -0
  8. package/dist/powered-file-system/append.js +10 -0
  9. package/dist/powered-file-system/append.test.d.ts +1 -0
  10. package/dist/powered-file-system/append.test.js +47 -0
  11. package/dist/powered-file-system/chmod.d.ts +7 -0
  12. package/dist/powered-file-system/chmod.js +28 -0
  13. package/dist/powered-file-system/chmod.test.d.ts +1 -0
  14. package/dist/powered-file-system/chmod.test.js +71 -0
  15. package/dist/powered-file-system/chown.d.ts +9 -0
  16. package/dist/powered-file-system/chown.js +45 -0
  17. package/dist/powered-file-system/chown.test.d.ts +1 -0
  18. package/dist/powered-file-system/chown.test.js +82 -0
  19. package/dist/powered-file-system/copy.d.ts +8 -0
  20. package/dist/powered-file-system/copy.js +29 -0
  21. package/dist/powered-file-system/copy.test.d.ts +1 -0
  22. package/dist/powered-file-system/copy.test.js +82 -0
  23. package/dist/powered-file-system/mkdir.d.ts +8 -0
  24. package/dist/powered-file-system/mkdir.js +28 -0
  25. package/dist/powered-file-system/mkdir.test.d.ts +1 -0
  26. package/dist/powered-file-system/mkdir.test.js +116 -0
  27. package/dist/powered-file-system/read.d.ts +9 -0
  28. package/dist/powered-file-system/read.js +29 -0
  29. package/dist/powered-file-system/read.test.d.ts +1 -0
  30. package/dist/powered-file-system/read.test.js +75 -0
  31. package/dist/powered-file-system/readdir.d.ts +8 -0
  32. package/dist/powered-file-system/readdir.js +26 -0
  33. package/dist/powered-file-system/readdir.test.d.ts +1 -0
  34. package/dist/powered-file-system/readdir.test.js +72 -0
  35. package/dist/powered-file-system/remove.d.ts +7 -0
  36. package/dist/powered-file-system/remove.js +36 -0
  37. package/dist/powered-file-system/remove.test.d.ts +1 -0
  38. package/dist/powered-file-system/remove.test.js +78 -0
  39. package/dist/powered-file-system/rename.d.ts +7 -0
  40. package/dist/powered-file-system/rename.js +28 -0
  41. package/dist/powered-file-system/rename.test.d.ts +1 -0
  42. package/dist/powered-file-system/rename.test.js +70 -0
  43. package/dist/powered-file-system/stat.d.ts +7 -0
  44. package/dist/powered-file-system/stat.js +26 -0
  45. package/dist/powered-file-system/stat.test.d.ts +1 -0
  46. package/dist/powered-file-system/stat.test.js +79 -0
  47. package/dist/powered-file-system/symlink.d.ts +4 -0
  48. package/dist/powered-file-system/symlink.js +52 -0
  49. package/dist/powered-file-system/symlink.test.d.ts +1 -0
  50. package/dist/powered-file-system/symlink.test.js +77 -0
  51. package/dist/powered-file-system/test.d.ts +8 -0
  52. package/dist/powered-file-system/test.js +30 -0
  53. package/dist/powered-file-system/test.test.d.ts +1 -0
  54. package/dist/powered-file-system/test.test.js +76 -0
  55. package/dist/powered-file-system/write.d.ts +10 -0
  56. package/dist/powered-file-system/write.js +36 -0
  57. package/dist/powered-file-system/write.test.d.ts +1 -0
  58. package/dist/powered-file-system/write.test.js +97 -0
  59. package/dist/powered-file-system.d.ts +127 -0
  60. package/dist/powered-file-system.js +144 -0
  61. package/dist/powered-file-system.test.d.ts +1 -0
  62. package/dist/powered-file-system.test.js +21 -0
  63. package/dist/recurse-io-sync.d.ts +20 -0
  64. package/dist/{src/recurse-io-sync.js → recurse-io-sync.js} +37 -37
  65. package/dist/{src/recurse-io.d.ts → recurse-io.d.ts} +15 -1
  66. package/dist/{src/recurse-io.js → recurse-io.js} +52 -58
  67. package/dist/suite.test.d.ts +1 -0
  68. package/dist/suite.test.js +40 -0
  69. package/dist/test-utils.d.ts +18 -0
  70. package/dist/test-utils.js +72 -0
  71. package/package.json +31 -14
  72. package/readme.md +331 -246
  73. package/.travis.yml +0 -12
  74. package/appveyor.yml +0 -16
  75. package/dist/src/bitmask.d.ts +0 -1
  76. package/dist/src/bitmask.js +0 -18
  77. package/dist/src/powered-file-system.d.ts +0 -173
  78. package/dist/src/powered-file-system.js +0 -262
  79. package/dist/src/recurse-io-sync.d.ts +0 -5
  80. package/src/bitmask.ts +0 -20
  81. package/src/index.ts +0 -7
  82. package/src/powered-file-system.ts +0 -508
  83. package/src/recurse-io-sync.ts +0 -108
  84. package/src/recurse-io.ts +0 -238
  85. package/test/__fmock.ts +0 -45
  86. package/test/append.spec.ts +0 -71
  87. package/test/bitmask.spec.ts +0 -23
  88. package/test/chmod.spec.ts +0 -77
  89. package/test/chown.spec.ts +0 -92
  90. package/test/constructor.spec.ts +0 -15
  91. package/test/copy.spec.ts +0 -101
  92. package/test/mkdir.spec.ts +0 -121
  93. package/test/read.spec.ts +0 -91
  94. package/test/readdir.spec.ts +0 -86
  95. package/test/remove.spec.ts +0 -78
  96. package/test/rename.spec.ts +0 -84
  97. package/test/stat.spec.ts +0 -99
  98. package/test/symlink.spec.ts +0 -95
  99. package/test/test.spec.ts +0 -80
  100. package/test/write.spec.ts +0 -104
  101. package/tsconfig.json +0 -14
@@ -0,0 +1,116 @@
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_fs_1 = __importDefault(require("node:fs"));
8
+ const node_os_1 = __importDefault(require("node:os"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const chance_1 = __importDefault(require("chance"));
11
+ const node_test_1 = require("node:test");
12
+ const index_1 = require("../index");
13
+ const test_utils_1 = require("../test-utils");
14
+ /**
15
+ * Verifies recursive directory creation for absolute and instance-relative roots.
16
+ */
17
+ (0, node_test_1.describe)('mkdir(src [, options])', () => {
18
+ const chance = new chance_1.default();
19
+ let tmpDir = '';
20
+ let pfs = new index_1.PoweredFileSystem();
21
+ (0, node_test_1.beforeEach)(() => {
22
+ tmpDir = (0, test_utils_1.createTmpDir)();
23
+ pfs = new index_1.PoweredFileSystem();
24
+ (0, test_utils_1.fmock)({
25
+ [node_path_1.default.join(tmpDir, 'tings.txt')]: {
26
+ type: 'file',
27
+ data: chance.string()
28
+ }
29
+ });
30
+ });
31
+ (0, node_test_1.afterEach)(() => {
32
+ (0, test_utils_1.restore)(tmpDir);
33
+ });
34
+ (0, node_test_1.it)('Positive: Create directories in the working directory', async () => {
35
+ const guid = chance.guid();
36
+ const target = node_path_1.default.join(tmpDir, guid);
37
+ await pfs.mkdir(target);
38
+ const exist = node_fs_1.default.existsSync(target);
39
+ (0, node_assert_1.default)(exist);
40
+ });
41
+ (0, node_test_1.it)('Positive: Make current directory', async () => {
42
+ const guid = chance.guid();
43
+ const target = node_path_1.default.join(tmpDir, guid);
44
+ const nextPfs = new index_1.PoweredFileSystem(target);
45
+ await nextPfs.mkdir('.');
46
+ const exist = node_fs_1.default.existsSync(target);
47
+ (0, node_assert_1.default)(exist);
48
+ });
49
+ (0, node_test_1.it)('Positive: Should work fine with the existing directory', async () => {
50
+ const guid = chance.guid();
51
+ const target = node_path_1.default.join(tmpDir, guid);
52
+ for (let i = 2; i; i--) {
53
+ await pfs.mkdir(target);
54
+ }
55
+ const exist = node_fs_1.default.existsSync(target);
56
+ (0, node_assert_1.default)(exist);
57
+ });
58
+ (0, node_test_1.it)('Negative: Throw an exception if trying to create a directory in file', async () => {
59
+ const guid = chance.guid();
60
+ await node_assert_1.default.rejects(async () => {
61
+ await pfs.mkdir(node_path_1.default.join(tmpDir, 'tings.txt', guid));
62
+ });
63
+ });
64
+ (0, node_test_1.it)('[sync] Positive: Create directories in the working directory', () => {
65
+ const guid = chance.guid();
66
+ const target = node_path_1.default.join(tmpDir, guid);
67
+ pfs.mkdir(target, {
68
+ sync: true
69
+ });
70
+ const exist = node_fs_1.default.existsSync(target);
71
+ (0, node_assert_1.default)(exist);
72
+ });
73
+ (0, node_test_1.it)('[sync] Positive: Make current directory', () => {
74
+ const guid = chance.guid();
75
+ const target = node_path_1.default.join(tmpDir, guid);
76
+ const nextPfs = new index_1.PoweredFileSystem(target);
77
+ nextPfs.mkdir('.', {
78
+ sync: true
79
+ });
80
+ const exist = node_fs_1.default.existsSync(target);
81
+ (0, node_assert_1.default)(exist);
82
+ });
83
+ (0, node_test_1.it)('[sync] Positive: Should work fine with the existing directory', () => {
84
+ const guid = chance.guid();
85
+ const target = node_path_1.default.join(tmpDir, guid);
86
+ for (let i = 2; i; i--) {
87
+ pfs.mkdir(target, {
88
+ sync: true
89
+ });
90
+ }
91
+ const exist = node_fs_1.default.existsSync(target);
92
+ (0, node_assert_1.default)(exist);
93
+ });
94
+ (0, node_test_1.it)('[sync] Negative: Throw an exception if trying to create a directory in file', () => {
95
+ const guid = chance.guid();
96
+ node_assert_1.default.throws(() => {
97
+ pfs.mkdir(node_path_1.default.join(tmpDir, 'tings.txt', guid), {
98
+ sync: true
99
+ });
100
+ });
101
+ });
102
+ (0, node_test_1.it)('[sync] Positive: Absolute pwd should create the target directory itself', () => {
103
+ const guid = chance.guid();
104
+ const target = node_path_1.default.join(node_os_1.default.tmpdir(), guid);
105
+ const nextPfs = new index_1.PoweredFileSystem(target);
106
+ try {
107
+ nextPfs.mkdir('.', {
108
+ sync: true
109
+ });
110
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(target));
111
+ }
112
+ finally {
113
+ node_fs_1.default.rmSync(target, { recursive: true, force: true });
114
+ }
115
+ });
116
+ });
@@ -0,0 +1,9 @@
1
+ import type { Flag, PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Reads a file relative to `pwd` and preserves Buffer mode when `encoding` is `null`.
4
+ */
5
+ export declare function read<T extends boolean = false>(this: PoweredFileSystem, src: string, options?: {
6
+ sync?: T;
7
+ encoding?: BufferEncoding | null;
8
+ flag?: Flag;
9
+ }): T extends true ? string | Buffer : Promise<string | Buffer>;
@@ -0,0 +1,29 @@
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.read = read;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ /**
10
+ * Reads a file relative to `pwd` and preserves Buffer mode when `encoding` is `null`.
11
+ */
12
+ function read(src, options) {
13
+ const { sync = false, encoding = 'utf8', flag = 'r' } = options ?? {};
14
+ const resolved = node_path_1.default.resolve(this.pwd, src);
15
+ if (sync) {
16
+ if (encoding === null) {
17
+ return node_fs_1.default.readFileSync(resolved, { encoding: null, flag });
18
+ }
19
+ return node_fs_1.default.readFileSync(resolved, { encoding, flag });
20
+ }
21
+ return new Promise((resolve, reject) => {
22
+ node_fs_1.default.readFile(resolved, { encoding, flag }, (err, raw) => {
23
+ if (err) {
24
+ return reject(err);
25
+ }
26
+ resolve(raw);
27
+ });
28
+ });
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
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
+ * Covers text and binary reads together with failure cases.
14
+ */
15
+ (0, node_test_1.describe)('read(src [, options])', () => {
16
+ const chance = new chance_1.default();
17
+ let sentences = 0;
18
+ let tmpDir = '';
19
+ (0, node_test_1.beforeEach)(() => {
20
+ tmpDir = (0, test_utils_1.createTmpDir)();
21
+ const tingsContent = chance.paragraph();
22
+ sentences = tingsContent.length;
23
+ (0, test_utils_1.fmock)({
24
+ [node_path_1.default.join(tmpDir, 'tings.txt')]: {
25
+ type: 'file',
26
+ data: tingsContent
27
+ }
28
+ });
29
+ });
30
+ (0, node_test_1.afterEach)(() => {
31
+ (0, test_utils_1.restore)(tmpDir);
32
+ });
33
+ (0, node_test_1.it)('Positive: Must read content of file; String type by default', async () => {
34
+ const { length } = await index_1.pfs.read(node_path_1.default.join(tmpDir, 'tings.txt'));
35
+ (0, node_assert_1.default)(length === sentences);
36
+ });
37
+ (0, node_test_1.it)('Positive: Must read Buffer content of file when encoding is null', async () => {
38
+ const buffer = await index_1.pfs.read(node_path_1.default.join(tmpDir, 'tings.txt'), {
39
+ encoding: null
40
+ });
41
+ (0, node_assert_1.default)(buffer instanceof Buffer);
42
+ });
43
+ (0, node_test_1.it)('Negative: Throw if resource is not file', async () => {
44
+ await node_assert_1.default.rejects(async () => {
45
+ await index_1.pfs.read(tmpDir);
46
+ });
47
+ });
48
+ (0, node_test_1.it)('Negative: Throw if not exists resource', async () => {
49
+ const guid = chance.guid();
50
+ await node_assert_1.default.rejects(async () => {
51
+ await index_1.pfs.read(node_path_1.default.join(tmpDir, guid));
52
+ });
53
+ });
54
+ (0, node_test_1.it)('[sync] Positive: Must read content of file; String type by default', () => {
55
+ const { length } = index_1.pfs.read(node_path_1.default.join(tmpDir, 'tings.txt'), {
56
+ sync: true
57
+ });
58
+ (0, node_assert_1.default)(length === sentences);
59
+ });
60
+ (0, node_test_1.it)('[sync] Positive: Must read Buffer content of file when encoding is null', () => {
61
+ const buf = index_1.pfs.read(node_path_1.default.join(tmpDir, 'tings.txt'), {
62
+ sync: true,
63
+ encoding: null
64
+ });
65
+ (0, node_assert_1.default)(buf instanceof Buffer);
66
+ });
67
+ (0, node_test_1.it)('[sync] Negative: Throw if not exists resource', () => {
68
+ const guid = chance.guid();
69
+ node_assert_1.default.throws(() => {
70
+ index_1.pfs.read(node_path_1.default.join(tmpDir, guid), {
71
+ sync: true
72
+ });
73
+ });
74
+ });
75
+ });
@@ -0,0 +1,8 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Lists directory entries relative to the current instance root.
4
+ */
5
+ export declare function readdir<T extends boolean = false>(this: PoweredFileSystem, dir: string, options?: {
6
+ sync?: T;
7
+ encoding?: BufferEncoding | null;
8
+ }): T extends true ? string[] : Promise<string[]>;
@@ -0,0 +1,26 @@
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.readdir = readdir;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ /**
10
+ * Lists directory entries relative to the current instance root.
11
+ */
12
+ function readdir(dir, options) {
13
+ const { sync = false, encoding = 'utf8' } = options ?? {};
14
+ dir = node_path_1.default.resolve(this.pwd, dir);
15
+ if (sync) {
16
+ return node_fs_1.default.readdirSync(dir, { encoding });
17
+ }
18
+ return new Promise((resolve, reject) => {
19
+ node_fs_1.default.readdir(dir, { encoding }, (err, list) => {
20
+ if (err) {
21
+ return reject(err);
22
+ }
23
+ resolve(list);
24
+ });
25
+ });
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
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 directory listing behavior and invalid-target failures.
14
+ */
15
+ (0, node_test_1.describe)('readdir(src[, options])', () => {
16
+ const chance = new chance_1.default();
17
+ let counter = 0;
18
+ let tmpDir = '';
19
+ (0, node_test_1.beforeEach)(() => {
20
+ tmpDir = (0, test_utils_1.createTmpDir)();
21
+ const frame = {
22
+ [node_path_1.default.join(tmpDir, 'tings.txt')]: {
23
+ type: 'file',
24
+ data: chance.string()
25
+ }
26
+ };
27
+ counter = chance.natural({ max: 7 });
28
+ for (let i = 0; i < counter; i++) {
29
+ frame[node_path_1.default.join(tmpDir, String(i))] = { type: 'directory' };
30
+ }
31
+ (0, test_utils_1.fmock)(frame);
32
+ });
33
+ (0, node_test_1.afterEach)(() => {
34
+ (0, test_utils_1.restore)(tmpDir);
35
+ });
36
+ (0, node_test_1.it)('Positive: Must return a directory listing', async () => {
37
+ const { length } = await index_1.pfs.readdir(tmpDir);
38
+ (0, node_assert_1.default)(counter + 1 === length);
39
+ });
40
+ (0, node_test_1.it)('Negative: Throw if resource is not directory', async () => {
41
+ await node_assert_1.default.rejects(async () => {
42
+ await index_1.pfs.readdir(node_path_1.default.join(tmpDir, 'tings.txt'));
43
+ });
44
+ });
45
+ (0, node_test_1.it)('Negative: Throw if not exists resource', async () => {
46
+ const guid = chance.guid();
47
+ await node_assert_1.default.rejects(async () => {
48
+ await index_1.pfs.readdir(node_path_1.default.join(tmpDir, guid));
49
+ });
50
+ });
51
+ (0, node_test_1.it)('[sync] Positive: Must return a directory listing', () => {
52
+ const { length } = index_1.pfs.readdir(tmpDir, {
53
+ sync: true
54
+ });
55
+ (0, node_assert_1.default)(counter + 1 === length);
56
+ });
57
+ (0, node_test_1.it)('Negative: Throw if resource is not directory', () => {
58
+ node_assert_1.default.throws(() => {
59
+ index_1.pfs.readdir(node_path_1.default.join(tmpDir, 'tings.txt'), {
60
+ sync: true
61
+ });
62
+ });
63
+ });
64
+ (0, node_test_1.it)('Negative: Throw if not exists resource', () => {
65
+ const guid = chance.guid();
66
+ node_assert_1.default.throws(() => {
67
+ index_1.pfs.readdir(node_path_1.default.join(tmpDir, guid), {
68
+ sync: true
69
+ });
70
+ });
71
+ });
72
+ });
@@ -0,0 +1,7 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Removes a path relative to the instance root, preferring native recursive APIs when available.
4
+ */
5
+ export declare function remove<T extends boolean = false>(this: PoweredFileSystem, src: string, options?: {
6
+ sync?: T;
7
+ }): T extends true ? void : Promise<void>;
@@ -0,0 +1,36 @@
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.remove = remove;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const recurse_io_1 = require("../recurse-io");
10
+ 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
+ function remove(src, options) {
15
+ src = node_path_1.default.resolve(this.pwd, src);
16
+ const { sync = false } = options ?? {};
17
+ if (sync) {
18
+ (0, recurse_io_sync_1.removeSync)(src);
19
+ return undefined;
20
+ }
21
+ return new Promise((resolve, reject) => {
22
+ const callback = (err) => {
23
+ if (err) {
24
+ return reject(err);
25
+ }
26
+ 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
+ }
35
+ });
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
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_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const chance_1 = __importDefault(require("chance"));
10
+ const node_test_1 = require("node:test");
11
+ const index_1 = require("../index");
12
+ const test_utils_1 = require("../test-utils");
13
+ /**
14
+ * Covers recursive removal, including the symlink edge case.
15
+ */
16
+ (0, node_test_1.describe)('remove(src [, options])', () => {
17
+ const chance = new chance_1.default();
18
+ let tmpDir = '';
19
+ (0, node_test_1.beforeEach)(() => {
20
+ tmpDir = (0, test_utils_1.createTmpDir)();
21
+ const frame = {
22
+ [node_path_1.default.join(tmpDir, 'tings.txt')]: {
23
+ type: 'file',
24
+ data: chance.string()
25
+ },
26
+ [node_path_1.default.join(tmpDir, 'digest')]: { type: 'directory' },
27
+ [node_path_1.default.join(tmpDir, 'flexapp')]: {
28
+ type: 'symlink',
29
+ target: node_path_1.default.join(tmpDir, 'tings.txt')
30
+ },
31
+ [node_path_1.default.join(tmpDir, 'digest-link')]: {
32
+ type: 'symlink',
33
+ target: node_path_1.default.join(tmpDir, 'digest')
34
+ }
35
+ };
36
+ const counter = chance.natural({ max: 7 });
37
+ for (let i = 0; i < counter; i++) {
38
+ frame[node_path_1.default.join(tmpDir, String(i))] = { type: 'directory' };
39
+ }
40
+ (0, test_utils_1.fmock)(frame);
41
+ });
42
+ (0, node_test_1.afterEach)(() => {
43
+ (0, test_utils_1.restore)(tmpDir);
44
+ });
45
+ (0, node_test_1.it)('Positive: Removal a directory with a file', async () => {
46
+ await index_1.pfs.remove(tmpDir);
47
+ const exist = node_fs_1.default.existsSync(tmpDir);
48
+ (0, node_assert_1.default)(exist === false);
49
+ });
50
+ (0, node_test_1.it)('Negative: Throw if not exists resource', async () => {
51
+ const guid = chance.guid();
52
+ await node_assert_1.default.rejects(async () => {
53
+ await index_1.pfs.remove(node_path_1.default.join(tmpDir, guid));
54
+ });
55
+ });
56
+ (0, node_test_1.it)('[sync] Positive: Removal a directory with a file', () => {
57
+ index_1.pfs.remove(tmpDir, {
58
+ sync: true
59
+ });
60
+ const exist = node_fs_1.default.existsSync(tmpDir);
61
+ (0, node_assert_1.default)(exist === false);
62
+ });
63
+ (0, node_test_1.it)('[sync] Negative: Throw if not exists resource', () => {
64
+ const guid = chance.guid();
65
+ node_assert_1.default.throws(() => {
66
+ index_1.pfs.remove(node_path_1.default.join(tmpDir, guid), {
67
+ sync: true
68
+ });
69
+ });
70
+ });
71
+ (0, node_test_1.it)('[sync] Positive: Removing a symlink to a directory should remove only the link', () => {
72
+ index_1.pfs.remove(node_path_1.default.join(tmpDir, 'digest-link'), {
73
+ sync: true
74
+ });
75
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'digest-link')) === false);
76
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'digest')));
77
+ });
78
+ });
@@ -0,0 +1,7 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Resolves both paths against the instance root before delegating to Node's rename API.
4
+ */
5
+ export declare function rename<T extends boolean = false>(this: PoweredFileSystem, src: string, dest: string, options?: {
6
+ sync?: T;
7
+ }): T extends true ? void : Promise<void>;
@@ -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.rename = rename;
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
+ 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
+ const { sync = false } = options ?? {};
16
+ if (sync) {
17
+ node_fs_1.default.renameSync(src, dest);
18
+ return undefined;
19
+ }
20
+ return new Promise((resolve, reject) => {
21
+ node_fs_1.default.rename(src, dest, (err) => {
22
+ if (err) {
23
+ return reject(err);
24
+ }
25
+ resolve();
26
+ });
27
+ });
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
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_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const chance_1 = __importDefault(require("chance"));
10
+ const node_test_1 = require("node:test");
11
+ const index_1 = require("../index");
12
+ const test_utils_1 = require("../test-utils");
13
+ /**
14
+ * Verifies move semantics for both files and directories.
15
+ */
16
+ (0, node_test_1.describe)('rename(src, use [, options])', () => {
17
+ const chance = new chance_1.default();
18
+ let tmpDir = '';
19
+ (0, node_test_1.beforeEach)(() => {
20
+ tmpDir = (0, test_utils_1.createTmpDir)();
21
+ (0, test_utils_1.fmock)({
22
+ [node_path_1.default.join(tmpDir, 'tings.txt')]: {
23
+ type: 'file',
24
+ data: chance.string()
25
+ },
26
+ [node_path_1.default.join(tmpDir, 'digest')]: { type: 'directory' }
27
+ });
28
+ });
29
+ (0, node_test_1.afterEach)(() => {
30
+ (0, test_utils_1.restore)(tmpDir);
31
+ });
32
+ (0, node_test_1.it)('Positive: Must be recursive rename file', async () => {
33
+ await index_1.pfs.rename(node_path_1.default.join(tmpDir, 'tings.txt'), node_path_1.default.join(tmpDir, 'newapp.txt'));
34
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'newapp.txt'));
35
+ (0, node_assert_1.default)(exist);
36
+ });
37
+ (0, node_test_1.it)('Positive: Must be recursive rename directory', async () => {
38
+ await index_1.pfs.rename(node_path_1.default.join(tmpDir, 'digest'), node_path_1.default.join(tmpDir, 'newxbase'));
39
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'newxbase'));
40
+ (0, node_assert_1.default)(exist);
41
+ });
42
+ (0, node_test_1.it)('Negative: Throw if not exists resource', async () => {
43
+ const guid = chance.guid();
44
+ await node_assert_1.default.rejects(async () => {
45
+ await index_1.pfs.rename(node_path_1.default.join(tmpDir, guid), node_path_1.default.join(tmpDir, 'newxbase'));
46
+ });
47
+ });
48
+ (0, node_test_1.it)('[sync] Positive: Must be recursive rename file', () => {
49
+ index_1.pfs.rename(node_path_1.default.join(tmpDir, 'tings.txt'), node_path_1.default.join(tmpDir, 'newapp.txt'), {
50
+ sync: true
51
+ });
52
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'newapp.txt'));
53
+ (0, node_assert_1.default)(exist);
54
+ });
55
+ (0, node_test_1.it)('[sync] Positive: Must be recursive rename directory', () => {
56
+ index_1.pfs.rename(node_path_1.default.join(tmpDir, 'digest'), node_path_1.default.join(tmpDir, 'newxbase'), {
57
+ sync: true
58
+ });
59
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'newxbase'));
60
+ (0, node_assert_1.default)(exist);
61
+ });
62
+ (0, node_test_1.it)('[sync] Negative: Throw if not exists resource', () => {
63
+ const guid = chance.guid();
64
+ node_assert_1.default.throws(() => {
65
+ index_1.pfs.rename(node_path_1.default.join(tmpDir, guid), node_path_1.default.join(tmpDir, 'newxbase'), {
66
+ sync: true
67
+ });
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,7 @@
1
+ import type { PoweredFileSystem, Stats } from '../powered-file-system';
2
+ /**
3
+ * Returns `lstat` data so symlinks are reported as links instead of followed targets.
4
+ */
5
+ export declare function stat<T extends boolean = false>(this: PoweredFileSystem, src: string, options?: {
6
+ sync?: T;
7
+ }): T extends true ? Stats : Promise<Stats>;
@@ -0,0 +1,26 @@
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.stat = stat;
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
+ function stat(src, options) {
13
+ const { sync = false } = options ?? {};
14
+ src = node_path_1.default.resolve(this.pwd, src);
15
+ if (sync) {
16
+ return node_fs_1.default.lstatSync(src);
17
+ }
18
+ return new Promise((resolve, reject) => {
19
+ node_fs_1.default.lstat(src, (err, stats) => {
20
+ if (err) {
21
+ return reject(err);
22
+ }
23
+ resolve(stats);
24
+ });
25
+ });
26
+ }
@@ -0,0 +1 @@
1
+ export {};