pwd-fs 3.3.0 → 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 (104) hide show
  1. package/dist/bitmask.d.ts +4 -0
  2. package/dist/{src/bitmask.js → bitmask.js} +3 -1
  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 -1
  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/{src/powered-file-system.d.ts → powered-file-system.d.ts} +57 -4
  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} +25 -23
  65. package/dist/{src/recurse-io.d.ts → recurse-io.d.ts} +15 -0
  66. package/dist/{src/recurse-io.js → recurse-io.js} +30 -28
  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 +28 -11
  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.map +0 -1
  77. package/dist/src/index.js.map +0 -1
  78. package/dist/src/powered-file-system.js +0 -252
  79. package/dist/src/powered-file-system.js.map +0 -1
  80. package/dist/src/recurse-io-sync.d.ts +0 -5
  81. package/dist/src/recurse-io-sync.js.map +0 -1
  82. package/dist/src/recurse-io.js.map +0 -1
  83. package/src/bitmask.ts +0 -13
  84. package/src/index.ts +0 -5
  85. package/src/powered-file-system.ts +0 -369
  86. package/src/recurse-io-sync.ts +0 -105
  87. package/src/recurse-io.ts +0 -221
  88. package/test/__fmock.ts +0 -45
  89. package/test/append.spec.ts +0 -45
  90. package/test/bitmask.spec.ts +0 -23
  91. package/test/chmod.spec.ts +0 -77
  92. package/test/chown.spec.ts +0 -92
  93. package/test/constructor.spec.ts +0 -15
  94. package/test/copy.spec.ts +0 -101
  95. package/test/mkdir.spec.ts +0 -121
  96. package/test/read.spec.ts +0 -91
  97. package/test/readdir.spec.ts +0 -86
  98. package/test/remove.spec.ts +0 -78
  99. package/test/rename.spec.ts +0 -84
  100. package/test/stat.spec.ts +0 -99
  101. package/test/symlink.spec.ts +0 -95
  102. package/test/test.spec.ts +0 -80
  103. package/test/write.spec.ts +0 -104
  104. package/tsconfig.json +0 -17
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Normalizes a permission mask to the standard rwxrwxrwx bit set.
3
+ */
4
+ export declare function bitmask(mode: number): number;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bitmask = bitmask;
4
+ /**
5
+ * Normalizes a permission mask to the standard rwxrwxrwx bit set.
6
+ */
4
7
  function bitmask(mode) {
5
8
  if (typeof mode !== 'number') {
6
9
  throw new TypeError(`Expected 'number', got '${typeof mode}'`);
@@ -12,4 +15,3 @@ function bitmask(mode) {
12
15
  return (mode & flag) ? umask + flag : umask;
13
16
  }, 0);
14
17
  }
15
- //# sourceMappingURL=bitmask.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const node_test_1 = require("node:test");
8
+ const index_1 = require("./index");
9
+ /**
10
+ * Covers normalization of permission masks exposed through the public entrypoint.
11
+ */
12
+ (0, node_test_1.describe)('static bitmask(mode: number)', () => {
13
+ (0, node_test_1.it)('Positive: Calculate bitmask', () => {
14
+ (0, node_assert_1.default)((0, index_1.bitmask)(33024) === 0o400);
15
+ (0, node_assert_1.default)((0, index_1.bitmask)(33152) === 0o600);
16
+ (0, node_assert_1.default)((0, index_1.bitmask)(33216) === 0o700);
17
+ (0, node_assert_1.default)((0, index_1.bitmask)(32800) === 0o040);
18
+ (0, node_assert_1.default)((0, index_1.bitmask)(32816) === 0o060);
19
+ (0, node_assert_1.default)((0, index_1.bitmask)(32824) === 0o070);
20
+ (0, node_assert_1.default)((0, index_1.bitmask)(32772) === 0o004);
21
+ (0, node_assert_1.default)((0, index_1.bitmask)(32774) === 0o006);
22
+ (0, node_assert_1.default)((0, index_1.bitmask)(32775) === 0o007);
23
+ });
24
+ (0, node_test_1.it)(`Negative: Throw an exception if the argument is 'null' type`, () => {
25
+ node_assert_1.default.throws(() => {
26
+ (0, index_1.bitmask)(null);
27
+ });
28
+ });
29
+ });
@@ -1,4 +1,7 @@
1
1
  import { PoweredFileSystem } from './powered-file-system';
2
+ /**
3
+ * Default file system instance rooted at the current working directory.
4
+ */
2
5
  export declare const pfs: PoweredFileSystem;
3
6
  export default PoweredFileSystem;
4
7
  export * from './powered-file-system';
@@ -16,7 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.pfs = void 0;
18
18
  const powered_file_system_1 = require("./powered-file-system");
19
+ /**
20
+ * Default file system instance rooted at the current working directory.
21
+ */
19
22
  exports.pfs = new powered_file_system_1.PoweredFileSystem();
20
23
  exports.default = powered_file_system_1.PoweredFileSystem;
21
24
  __exportStar(require("./powered-file-system"), exports);
22
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Backward-compatible append wrapper implemented on top of `write()`.
4
+ */
5
+ export declare function append<T extends boolean = false>(this: PoweredFileSystem, src: string, data: Buffer | string, options?: {
6
+ sync?: T;
7
+ encoding?: BufferEncoding | null;
8
+ umask?: number;
9
+ }): T extends true ? void : Promise<void>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.append = append;
4
+ /**
5
+ * Backward-compatible append wrapper implemented on top of `write()`.
6
+ */
7
+ function append(src, data, options) {
8
+ const { sync = false, encoding = 'utf8', umask = 0o000 } = options ?? {};
9
+ return this.write(src, data, { sync, encoding, umask, flag: 'a' });
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
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 the deprecated append helper in both async and sync modes.
15
+ */
16
+ (0, node_test_1.describe)('append(src, data [, 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: 'hoodie'
25
+ }
26
+ });
27
+ });
28
+ (0, node_test_1.afterEach)(() => {
29
+ (0, test_utils_1.restore)(tmpDir);
30
+ });
31
+ (0, node_test_1.it)('Positive: Must append content to file', async () => {
32
+ const payload = chance.paragraph();
33
+ const filePath = node_path_1.default.join(tmpDir, 'tings.txt');
34
+ await index_1.pfs.append(filePath, payload);
35
+ const { size } = node_fs_1.default.statSync(filePath);
36
+ (0, node_assert_1.default)(payload.length + 6 === size);
37
+ });
38
+ (0, node_test_1.it)('[sync] Positive: Must append content to file', () => {
39
+ const payload = chance.paragraph();
40
+ const filePath = node_path_1.default.join(tmpDir, 'tings.txt');
41
+ index_1.pfs.append(filePath, payload, {
42
+ sync: true
43
+ });
44
+ const { size } = node_fs_1.default.statSync(filePath);
45
+ (0, node_assert_1.default)(payload.length + 6 === size);
46
+ });
47
+ });
@@ -0,0 +1,7 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Resolves the target path and delegates recursive mode updates.
4
+ */
5
+ export declare function chmod<T extends boolean = false>(this: PoweredFileSystem, src: string, mode: number, 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.chmod = chmod;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const recurse_io_1 = require("../recurse-io");
9
+ const recurse_io_sync_1 = require("../recurse-io-sync");
10
+ /**
11
+ * Resolves the target path and delegates recursive mode updates.
12
+ */
13
+ function chmod(src, mode, options) {
14
+ const { sync = false } = options ?? {};
15
+ src = node_path_1.default.resolve(this.pwd, src);
16
+ if (sync) {
17
+ (0, recurse_io_sync_1.chmodSync)(src, mode);
18
+ return undefined;
19
+ }
20
+ return new Promise((resolve, reject) => {
21
+ (0, recurse_io_1.chmod)(src, mode, (err) => {
22
+ if (err) {
23
+ return reject(err);
24
+ }
25
+ resolve();
26
+ });
27
+ });
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
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
+ * Ensures recursive permission updates affect both directories and nested files.
14
+ */
15
+ (0, node_test_1.describe)('chmod(src, mode [, 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
+ });
26
+ });
27
+ (0, node_test_1.afterEach)(() => {
28
+ (0, test_utils_1.restore)(tmpDir);
29
+ });
30
+ (0, node_test_1.it)('Positive: Changes directory and file permissions', async () => {
31
+ await index_1.pfs.chmod(tmpDir, 0o444);
32
+ const writable = index_1.pfs.test(node_path_1.default.join(tmpDir, 'tings.txt'), {
33
+ sync: true,
34
+ flag: 'w'
35
+ });
36
+ (0, node_assert_1.default)(writable === false);
37
+ });
38
+ (0, node_test_1.it)('Negative: Throw if not exists resource', async () => {
39
+ await node_assert_1.default.rejects(async () => {
40
+ await index_1.pfs.chmod('./non-existent-source', 0o744);
41
+ });
42
+ });
43
+ (0, node_test_1.it)('[sync] Positive: Changes permissions of directory', () => {
44
+ index_1.pfs.chmod(tmpDir, 0o444, {
45
+ sync: true
46
+ });
47
+ const writable = index_1.pfs.test(node_path_1.default.join(tmpDir, 'tings.txt'), {
48
+ sync: true,
49
+ flag: 'w'
50
+ });
51
+ (0, node_assert_1.default)(writable === false);
52
+ });
53
+ (0, node_test_1.it)('[sync] Positive: Changes file permissions', () => {
54
+ index_1.pfs.chmod(node_path_1.default.join(tmpDir, 'tings.txt'), 0o444, {
55
+ sync: true
56
+ });
57
+ const writable = index_1.pfs.test(node_path_1.default.join(tmpDir, 'tings.txt'), {
58
+ sync: true,
59
+ flag: 'w'
60
+ });
61
+ (0, node_assert_1.default)(writable === 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.chmod(`./${guid}`, 0o744, {
67
+ sync: true
68
+ });
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,9 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Resolves the target path and applies recursive ownership changes where supported.
4
+ */
5
+ export declare function chown<T extends boolean = false>(this: PoweredFileSystem, src: string, options?: {
6
+ sync?: T;
7
+ uid?: number;
8
+ gid?: number;
9
+ }): T extends true ? void : Promise<void>;
@@ -0,0 +1,45 @@
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.chown = chown;
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
+ * Resolves the target path and applies recursive ownership changes where supported.
13
+ */
14
+ function chown(src, options) {
15
+ const { sync = false, uid = 0, gid = 0 } = options ?? {};
16
+ src = node_path_1.default.resolve(this.pwd, src);
17
+ if (sync) {
18
+ if (process.platform === 'win32') {
19
+ // Windows does not expose POSIX ownership changes; keep existence checks consistent.
20
+ node_fs_1.default.lstatSync(src);
21
+ return undefined;
22
+ }
23
+ (0, recurse_io_sync_1.chownSync)(src, uid, gid);
24
+ return undefined;
25
+ }
26
+ if (process.platform === 'win32') {
27
+ return new Promise((resolve, reject) => {
28
+ // Match Unix behavior by validating the path even when ownership cannot be changed.
29
+ node_fs_1.default.lstat(src, (err) => {
30
+ if (err) {
31
+ return reject(err);
32
+ }
33
+ resolve();
34
+ });
35
+ });
36
+ }
37
+ return new Promise((resolve, reject) => {
38
+ (0, recurse_io_1.chown)(src, uid, gid, (err) => {
39
+ if (err) {
40
+ return reject(err);
41
+ }
42
+ resolve();
43
+ });
44
+ });
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
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
+ * Validates ownership changes while preserving path validation semantics.
15
+ */
16
+ (0, node_test_1.describe)('chown(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
+ (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: Changes the permissions of a file', async () => {
33
+ const filePath = node_path_1.default.join(tmpDir, 'tings.txt');
34
+ const { uid, gid } = node_fs_1.default.statSync(filePath);
35
+ await index_1.pfs.chown(filePath, { uid, gid });
36
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(filePath));
37
+ });
38
+ (0, node_test_1.it)('Positive: Changes the permissions of a directory', async () => {
39
+ const dirPath = node_path_1.default.join(tmpDir, 'digest');
40
+ const { uid, gid } = node_fs_1.default.statSync(dirPath);
41
+ await index_1.pfs.chown(dirPath, { uid, gid });
42
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(dirPath));
43
+ });
44
+ (0, node_test_1.it)('Negative: To a non-existent resource to return an Error', async () => {
45
+ const guid = chance.guid();
46
+ const { uid, gid } = node_fs_1.default.statSync(node_path_1.default.join(tmpDir, 'tings.txt'));
47
+ await node_assert_1.default.rejects(async () => {
48
+ await index_1.pfs.chown(node_path_1.default.join(tmpDir, guid), { uid, gid });
49
+ });
50
+ });
51
+ (0, node_test_1.it)('[sync] Positive: Changes the permissions of a file', () => {
52
+ const filePath = node_path_1.default.join(tmpDir, 'tings.txt');
53
+ const { uid, gid } = node_fs_1.default.statSync(filePath);
54
+ index_1.pfs.chown(filePath, {
55
+ sync: true,
56
+ uid,
57
+ gid
58
+ });
59
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(filePath));
60
+ });
61
+ (0, node_test_1.it)('[sync] Positive: Changes the permissions of a directory', () => {
62
+ const dirPath = node_path_1.default.join(tmpDir, 'digest');
63
+ const { uid, gid } = node_fs_1.default.statSync(dirPath);
64
+ index_1.pfs.chown(dirPath, {
65
+ sync: true,
66
+ uid,
67
+ gid
68
+ });
69
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(dirPath));
70
+ });
71
+ (0, node_test_1.it)('[sync] Negative: To a non-existent resource to return an Error', () => {
72
+ const guid = chance.guid();
73
+ const { uid, gid } = node_fs_1.default.statSync(node_path_1.default.join(tmpDir, 'tings.txt'));
74
+ node_assert_1.default.throws(() => {
75
+ index_1.pfs.chown(node_path_1.default.join(tmpDir, guid), {
76
+ sync: true,
77
+ uid,
78
+ gid
79
+ });
80
+ });
81
+ });
82
+ });
@@ -0,0 +1,8 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Resolves source and destination paths before delegating recursive copy work.
4
+ */
5
+ export declare function copy<T extends boolean = false>(this: PoweredFileSystem, src: string, dest: string, options?: {
6
+ sync?: T;
7
+ umask?: number;
8
+ }): T extends true ? void : Promise<void>;
@@ -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.copy = copy;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const recurse_io_1 = require("../recurse-io");
9
+ const recurse_io_sync_1 = require("../recurse-io-sync");
10
+ /**
11
+ * Resolves source and destination paths before delegating recursive copy work.
12
+ */
13
+ function copy(src, dest, options) {
14
+ src = node_path_1.default.resolve(this.pwd, src);
15
+ dest = node_path_1.default.resolve(this.pwd, dest);
16
+ const { sync = false, umask = 0o000 } = options ?? {};
17
+ if (sync) {
18
+ (0, recurse_io_sync_1.copySync)(src, dest, umask);
19
+ return undefined;
20
+ }
21
+ return new Promise((resolve, reject) => {
22
+ (0, recurse_io_1.copy)(src, dest, umask, (err) => {
23
+ if (err) {
24
+ return reject(err);
25
+ }
26
+ resolve();
27
+ });
28
+ });
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
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 file and directory copy behavior, including collision handling.
15
+ */
16
+ (0, node_test_1.describe)('copy(src, dir [, 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: Copying a item file', async () => {
33
+ await index_1.pfs.copy(node_path_1.default.join(tmpDir, 'tings.txt'), node_path_1.default.join(tmpDir, 'digest'));
34
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'digest', 'tings.txt'));
35
+ (0, node_assert_1.default)(exist);
36
+ });
37
+ (0, node_test_1.it)('Positive: Recursive copying a directory', async () => {
38
+ await index_1.pfs.copy(node_path_1.default.resolve('./src'), tmpDir);
39
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'src'));
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.copy(node_path_1.default.join(tmpDir, guid), tmpDir);
46
+ });
47
+ });
48
+ (0, node_test_1.it)('Negative: An attempt to copy to an existing resource should return an Error', async () => {
49
+ await node_assert_1.default.rejects(async () => {
50
+ await index_1.pfs.copy(tmpDir, node_path_1.default.dirname(tmpDir));
51
+ });
52
+ });
53
+ (0, node_test_1.it)('[sync] Positive: Copying a file', () => {
54
+ index_1.pfs.copy(node_path_1.default.join(tmpDir, 'tings.txt'), node_path_1.default.join(tmpDir, 'digest'), {
55
+ sync: true
56
+ });
57
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'digest', 'tings.txt'));
58
+ (0, node_assert_1.default)(exist);
59
+ });
60
+ (0, node_test_1.it)('[sync] Positive: Recursive copying a directory', () => {
61
+ index_1.pfs.copy(node_path_1.default.resolve('./src'), tmpDir, {
62
+ sync: true
63
+ });
64
+ const exist = node_fs_1.default.existsSync(node_path_1.default.join(tmpDir, 'src'));
65
+ (0, node_assert_1.default)(exist);
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.copy(node_path_1.default.join(tmpDir, guid), tmpDir, {
71
+ sync: true
72
+ });
73
+ });
74
+ });
75
+ (0, node_test_1.it)('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
76
+ node_assert_1.default.throws(() => {
77
+ index_1.pfs.copy(tmpDir, node_path_1.default.dirname(tmpDir), {
78
+ sync: true
79
+ });
80
+ });
81
+ });
82
+ });
@@ -0,0 +1,8 @@
1
+ import type { PoweredFileSystem } from '../powered-file-system';
2
+ /**
3
+ * Creates directories relative to the instance root.
4
+ */
5
+ export declare function mkdir<T extends boolean = false>(this: PoweredFileSystem, dir: string, options?: {
6
+ sync?: T;
7
+ umask?: number;
8
+ }): 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.mkdir = mkdir;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const recurse_io_1 = require("../recurse-io");
9
+ const recurse_io_sync_1 = require("../recurse-io-sync");
10
+ /**
11
+ * Creates directories relative to the instance root.
12
+ */
13
+ function mkdir(dir, options) {
14
+ const { sync = false, umask = 0o000 } = options ?? {};
15
+ dir = node_path_1.default.resolve(this.pwd, dir);
16
+ if (sync) {
17
+ (0, recurse_io_sync_1.mkdirSync)(dir, umask);
18
+ return undefined;
19
+ }
20
+ return new Promise((resolve, reject) => {
21
+ (0, recurse_io_1.mkdir)(dir, umask, (err) => {
22
+ if (err) {
23
+ return reject(err);
24
+ }
25
+ resolve();
26
+ });
27
+ });
28
+ }
@@ -0,0 +1 @@
1
+ export {};