@visulima/fs 4.0.3 → 4.0.5

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 (177) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE.md +4 -1
  3. package/dist/constants.d.ts +42 -0
  4. package/dist/ensure/ensure-dir-sync.d.ts +14 -0
  5. package/dist/ensure/ensure-dir.d.ts +14 -0
  6. package/dist/ensure/ensure-file-sync.d.ts +15 -0
  7. package/dist/ensure/ensure-file.d.ts +27 -0
  8. package/dist/ensure/ensure-link-sync.d.ts +16 -0
  9. package/dist/ensure/ensure-link.d.ts +16 -0
  10. package/dist/ensure/ensure-symlink-sync.d.ts +23 -0
  11. package/dist/ensure/ensure-symlink.d.ts +23 -0
  12. package/dist/ensure/utils/get-file-info-type.d.ts +7 -0
  13. package/dist/ensure/utils/is-stats-identical.d.ts +3 -0
  14. package/dist/ensure/utils/resolve-symlink-target.d.ts +2 -0
  15. package/dist/eol.d.ts +35 -7
  16. package/dist/eol.js +26 -3
  17. package/dist/error/already-exists-error.d.ts +39 -0
  18. package/dist/error/directory-error.d.ts +47 -0
  19. package/dist/error/json-error.d.ts +52 -0
  20. package/dist/error/not-empty-error.d.ts +51 -0
  21. package/dist/error/not-found-error.d.ts +44 -0
  22. package/dist/error/permission-error.d.ts +45 -0
  23. package/dist/error/walk-error.d.ts +51 -0
  24. package/dist/error.d.ts +7 -50
  25. package/dist/error.js +7 -1
  26. package/dist/find/collect-sync.d.ts +31 -0
  27. package/dist/find/collect.d.ts +35 -0
  28. package/dist/find/find-up-sync.d.ts +42 -0
  29. package/dist/find/find-up.d.ts +46 -0
  30. package/dist/find/utils/glob-to-regex.d.ts +2 -0
  31. package/dist/find/utils/walk-include.d.ts +2 -0
  32. package/dist/find/walk-sync.d.ts +26 -0
  33. package/dist/find/walk.d.ts +29 -0
  34. package/dist/index.d.ts +34 -136
  35. package/dist/index.js +32 -1
  36. package/dist/is-accessible-sync.d.ts +3 -0
  37. package/dist/is-accessible.d.ts +29 -0
  38. package/dist/move/index.d.ts +70 -0
  39. package/dist/move/types.d.ts +38 -0
  40. package/dist/move/utils/internal-move-file-sync.d.ts +3 -0
  41. package/dist/move/utils/internal-move-file.d.ts +3 -0
  42. package/dist/move/utils/validate-same-directory.d.ts +2 -0
  43. package/dist/packem_shared/AlreadyExistsError-D5BGeeNR.js +27 -0
  44. package/dist/packem_shared/DirectoryError-CaUV2Pbk.js +27 -0
  45. package/dist/packem_shared/F_OK-BalxCn9n.js +8 -0
  46. package/dist/packem_shared/JSONError-BkHRnInH.js +26 -0
  47. package/dist/packem_shared/NotEmptyError-mOHWXE0m.js +27 -0
  48. package/dist/packem_shared/NotFoundError-D4llRgRs.js +27 -0
  49. package/dist/packem_shared/PermissionError-1qs0skfo.js +27 -0
  50. package/dist/packem_shared/WalkError-DUdQd6FT.js +24 -0
  51. package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +7 -0
  52. package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +7 -0
  53. package/dist/packem_shared/collect-DcBwsYYd.js +14 -0
  54. package/dist/packem_shared/collectSync-Bkjf9Dbm.js +14 -0
  55. package/dist/packem_shared/emptyDir-CYB5Tict.js +43 -0
  56. package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +41 -0
  57. package/dist/packem_shared/ensureDir-C_kuQ5Ik.js +53 -0
  58. package/dist/packem_shared/ensureDirSync-CI5g-uBI.js +53 -0
  59. package/dist/packem_shared/ensureFile-BUtXGlGT.js +47 -0
  60. package/dist/packem_shared/ensureFileSync-C8hASR-1.js +47 -0
  61. package/dist/packem_shared/ensureLink-BPnAG5-P.js +54 -0
  62. package/dist/packem_shared/ensureLinkSync-B-Z7X0ub.js +54 -0
  63. package/dist/packem_shared/ensureSymlink-BGz6W-Wa.js +73 -0
  64. package/dist/packem_shared/ensureSymlinkSync-C5Gk8QYi.js +74 -0
  65. package/dist/packem_shared/findUp-Lv9mZCIQ.js +85 -0
  66. package/dist/packem_shared/findUpSync-BsK4Nrrq.js +85 -0
  67. package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +14 -0
  68. package/dist/packem_shared/index-CHM-in-V.js +100 -0
  69. package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +3 -0
  70. package/dist/packem_shared/isAccessible-iOp0Bou6.js +38 -0
  71. package/dist/packem_shared/isAccessibleSync-38BmiIcx.js +38 -0
  72. package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +62 -0
  73. package/dist/packem_shared/move-BD6JbYSu.js +134 -0
  74. package/dist/packem_shared/parseJson-CqUuRguZ.js +231 -0
  75. package/dist/packem_shared/readFile-XVOjAw8r.js +65 -0
  76. package/dist/packem_shared/readFileSync-B9Zg5PSF.js +53 -0
  77. package/dist/packem_shared/readJson-Dra2m6s-.js +22 -0
  78. package/dist/packem_shared/readJsonSync-B6Dl1I_6.js +22 -0
  79. package/dist/packem_shared/readYaml-Bu1nsexB.js +10 -0
  80. package/dist/packem_shared/readYamlSync-Di88aMME.js +10 -0
  81. package/dist/packem_shared/remove-_oDY3uKo.js +38 -0
  82. package/dist/packem_shared/removeSync-DETRj7Qn.js +38 -0
  83. package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +16 -0
  84. package/dist/packem_shared/stripJsonComments-21XWVDwP.js +19 -0
  85. package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +19 -0
  86. package/dist/packem_shared/walk-BhTbpr3y.js +115 -0
  87. package/dist/packem_shared/walk-include-CZco7BvN.js +16 -0
  88. package/dist/packem_shared/walkSync-DDBq95s8.js +114 -0
  89. package/dist/packem_shared/writeFile-NT1fLEEe.js +83 -0
  90. package/dist/packem_shared/writeFileSync-Bj5UDSf0.js +83 -0
  91. package/dist/packem_shared/writeJson-DQLdAi0d.js +50 -0
  92. package/dist/packem_shared/writeJsonSync-DvTCjVUi.js +50 -0
  93. package/dist/packem_shared/writeYaml-BMY0kOPf.js +24 -0
  94. package/dist/packem_shared/writeYamlSync-DqPu8cCd.js +24 -0
  95. package/dist/read/read-file-sync.d.ts +37 -0
  96. package/dist/read/read-file.d.ts +41 -0
  97. package/dist/read/read-json-sync.d.ts +5 -0
  98. package/dist/read/read-json.d.ts +5 -0
  99. package/dist/read/read-yaml-sync.d.ts +4 -0
  100. package/dist/read/read-yaml.d.ts +4 -0
  101. package/dist/remove/empty-dir-sync.d.ts +24 -0
  102. package/dist/remove/empty-dir.d.ts +28 -0
  103. package/dist/remove/remove-sync.d.ts +28 -0
  104. package/dist/remove/remove.d.ts +32 -0
  105. package/dist/size.d.ts +245 -12
  106. package/dist/size.js +144 -1
  107. package/dist/types.d.ts +299 -0
  108. package/dist/utils/assert-valid-file-contents.d.ts +27 -0
  109. package/dist/utils/assert-valid-file-or-directory-path.d.ts +26 -0
  110. package/dist/utils/parse-json.d.ts +5 -0
  111. package/dist/utils/strip-json-comments.d.ts +44 -0
  112. package/dist/utils.d.ts +6 -19
  113. package/dist/utils.js +6 -1
  114. package/dist/write/utils/to-uint-8-array.d.ts +2 -0
  115. package/dist/write/write-file-sync.d.ts +30 -0
  116. package/dist/write/write-file.d.ts +30 -0
  117. package/dist/write/write-json-sync.d.ts +30 -0
  118. package/dist/write/write-json.d.ts +30 -0
  119. package/dist/write/write-yaml-sync.d.ts +4 -0
  120. package/dist/write/write-yaml.d.ts +4 -0
  121. package/dist/yaml.d.ts +5 -17
  122. package/dist/yaml.js +4 -1
  123. package/package.json +2 -3
  124. package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.js +0 -1
  125. package/dist/packem_shared/DirectoryError-ddlbUV8C.js +0 -1
  126. package/dist/packem_shared/F_OK-CAwY1qU7.js +0 -1
  127. package/dist/packem_shared/JSONError-D7h6PNWc.js +0 -4
  128. package/dist/packem_shared/NotEmptyError-DMh1o7UL.js +0 -1
  129. package/dist/packem_shared/NotFoundError-BPiW0icm.js +0 -1
  130. package/dist/packem_shared/PermissionError-B1Emi5a9.js +0 -1
  131. package/dist/packem_shared/WalkError-BsngoIKJ.js +0 -1
  132. package/dist/packem_shared/assertValidFileContents-BZFnXa7K.js +0 -1
  133. package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.js +0 -1
  134. package/dist/packem_shared/collect-DO31RsLs.js +0 -1
  135. package/dist/packem_shared/collectSync-Cy7ULmjZ.js +0 -1
  136. package/dist/packem_shared/emptyDir-zBLHyPsJ.js +0 -1
  137. package/dist/packem_shared/emptyDirSync-DZ8nTo6g.js +0 -1
  138. package/dist/packem_shared/ensureDir-CwcwvbZ0.js +0 -1
  139. package/dist/packem_shared/ensureDirSync-DsFhH5oQ.js +0 -1
  140. package/dist/packem_shared/ensureFile-DwcEQVDX.js +0 -1
  141. package/dist/packem_shared/ensureFileSync-KnrH51Ox.js +0 -1
  142. package/dist/packem_shared/ensureLink-5rjQGEBb.js +0 -1
  143. package/dist/packem_shared/ensureLinkSync-CYXpscf2.js +0 -1
  144. package/dist/packem_shared/ensureSymlink-GATTbE5c.js +0 -1
  145. package/dist/packem_shared/ensureSymlinkSync-CvXgTFrl.js +0 -1
  146. package/dist/packem_shared/findUp-Di7Az07S.js +0 -1
  147. package/dist/packem_shared/findUpSync-iV97v14Q.js +0 -1
  148. package/dist/packem_shared/get-file-info-type-CaWGXRjY.js +0 -1
  149. package/dist/packem_shared/index-CYIVJA0W.js +0 -1
  150. package/dist/packem_shared/is-stats-identical-CohsLtWy.js +0 -1
  151. package/dist/packem_shared/isAccessible-CDFxsAAo.js +0 -1
  152. package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +0 -1
  153. package/dist/packem_shared/isFsCaseSensitive-Drl8fHLV.js +0 -1
  154. package/dist/packem_shared/json-error-ZPgZIXcg.d.ts +0 -11
  155. package/dist/packem_shared/move-Bz4gSIjp.js +0 -1
  156. package/dist/packem_shared/parseJson-Cj4v3qzl.js +0 -6
  157. package/dist/packem_shared/readFile-CbxFM_zp.js +0 -1
  158. package/dist/packem_shared/readFileSync-B9iv2Sb8.js +0 -1
  159. package/dist/packem_shared/readJson-BgC3msx-.js +0 -1
  160. package/dist/packem_shared/readJsonSync-DHO1vjAG.js +0 -1
  161. package/dist/packem_shared/readYaml-D5mtfANg.js +0 -1
  162. package/dist/packem_shared/readYamlSync-D0igCVDE.js +0 -1
  163. package/dist/packem_shared/remove-BUqZUj1W.js +0 -1
  164. package/dist/packem_shared/removeSync-BbT4vmDi.js +0 -1
  165. package/dist/packem_shared/resolve-symlink-target-BofZSDIc.js +0 -1
  166. package/dist/packem_shared/stripJsonComments-DbMjL4qv.js +0 -1
  167. package/dist/packem_shared/to-uint-8-array-DwgaTasY.js +0 -1
  168. package/dist/packem_shared/types-T308NKwz.d.ts +0 -90
  169. package/dist/packem_shared/walk-ZrZngpc4.js +0 -1
  170. package/dist/packem_shared/walk-include-DCiVAwMP.js +0 -1
  171. package/dist/packem_shared/walkSync-BQa4NKSG.js +0 -1
  172. package/dist/packem_shared/writeFile-D5OYEMHu.js +0 -1
  173. package/dist/packem_shared/writeFileSync-CO4ySqUn.js +0 -1
  174. package/dist/packem_shared/writeJson-DfmgiY_s.js +0 -4
  175. package/dist/packem_shared/writeJsonSync-Ck1pmmj_.js +0 -4
  176. package/dist/packem_shared/writeYaml-BJeyUpyY.js +0 -1
  177. package/dist/packem_shared/writeYamlSync-D87XCS7Y.js +0 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Modified functions from https://github.com/sindresorhus/move-file
3
+ *
4
+ * The original functions are licensed under the MIT License:
5
+ *
6
+ * MIT License
7
+ *
8
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
9
+ */
10
+ import type { Options } from './types.d.ts';
11
+ /**
12
+ * Move a file asynchronously.
13
+ * @param sourcePath The file you want to move.
14
+ * @param destinationPath Where you want the file moved.
15
+ * @param options Configuration options.
16
+ * @returns A `Promise` that resolves when the file has been moved.
17
+ * @example
18
+ * ```
19
+ * import { move } from '@visulima/fs';
20
+ *
21
+ * await move('source/test.png', 'destination/test.png');
22
+ * console.log('The file has been moved');
23
+ * ```
24
+ */
25
+ export declare const move: (sourcePath: string, destinationPath: string, options?: Options) => Promise<void>;
26
+ /**
27
+ * Move a file synchronously.
28
+ * @param sourcePath The file you want to move.
29
+ * @param destinationPath Where you want the file moved.
30
+ * @param options Configuration options.
31
+ * @returns Nothing is returned.
32
+ * @example
33
+ * ```
34
+ * import { moveSync } from '@visulima/fs';
35
+ *
36
+ * moveSync('source/test.png', 'destination/test.png');
37
+ * console.log('The file has been moved');
38
+ * ```
39
+ */
40
+ export declare const moveSync: (sourcePath: string, destinationPath: string, options?: Options) => void;
41
+ /**
42
+ * Rename a file asynchronously.
43
+ * @param source The file you want to rename.
44
+ * @param destination The name of the renamed file.
45
+ * @param options Configuration options.
46
+ * @returns A `Promise` that resolves when the file has been renamed.
47
+ * @example
48
+ * ```
49
+ * import { rename } from '@visulima/fs';
50
+ *
51
+ * await rename('test.png', 'tests.png', {cwd: 'source'});
52
+ * console.log('The file has been renamed');
53
+ * ```
54
+ */
55
+ export declare const rename: (source: string, destination: string, options?: Options) => Promise<void>;
56
+ /**
57
+ * Rename a file synchronously.
58
+ * @param source The file you want to rename.
59
+ * @param destination The name of the renamed file.
60
+ * @param options Configuration options.
61
+ * @returns A `Promise` that resolves when the file has been renamed.
62
+ * @example
63
+ * ```
64
+ * import { renameSync } from '@visulima/fs';
65
+ *
66
+ * renameSync('test.png', 'tests.png', {cwd: 'source'});
67
+ * console.log('The file has been renamed');
68
+ * ```
69
+ */
70
+ export declare const renameSync: (source: string, destination: string, options?: Options) => void;
@@ -0,0 +1,38 @@
1
+ type FilePermissions = number;
2
+ export type Options = {
3
+ /**
4
+ * The working directory to find source files.
5
+ * The source and destination path are relative to this.
6
+ * @default process.cwd()
7
+ */
8
+ cwd?: URL | string;
9
+ /**
10
+ * [Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
11
+ *
12
+ * It has no effect on Windows.
13
+ * @default 0o777
14
+ */
15
+ readonly directoryMode?: FilePermissions;
16
+ /**
17
+ * Overwrite existing destination file.
18
+ * @default true
19
+ */
20
+ readonly overwrite?: boolean;
21
+ };
22
+ /**
23
+ * Internal options used by the move/rename implementation.
24
+ * Extends the public Options type with additional internal properties.
25
+ */
26
+ export type InternalOptions = Options & {
27
+ /**
28
+ * Resolved working directory path.
29
+ * URLs from the Options type are converted to string paths.
30
+ */
31
+ cwd: string;
32
+ /**
33
+ * Whether to validate the directory structure before operation.
34
+ * @internal
35
+ */
36
+ validateDirectory?: boolean;
37
+ };
38
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { InternalOptions } from "../types.d.ts";
2
+ declare const internalMoveFileSync: (sourcePath: string, destinationPath: string, { cwd, directoryMode, overwrite, validateDirectory }: InternalOptions) => void;
3
+ export default internalMoveFileSync;
@@ -0,0 +1,3 @@
1
+ import type { InternalOptions } from "../types.d.ts";
2
+ declare const internalMoveFile: (sourcePath: string, destinationPath: string, { cwd, directoryMode, overwrite, validateDirectory }: InternalOptions) => Promise<void>;
3
+ export default internalMoveFile;
@@ -0,0 +1,2 @@
1
+ declare const validateSameDirectory: (source: string, destination: string) => void;
2
+ export default validateSameDirectory;
@@ -0,0 +1,27 @@
1
+ class AlreadyExistsError extends Error {
2
+ /**
3
+ * Creates a new instance.
4
+ * @param message The error message.
5
+ */
6
+ constructor(message) {
7
+ super(`EEXIST: ${message}`);
8
+ }
9
+ // eslint-disable-next-line class-methods-use-this
10
+ get code() {
11
+ return "EEXIST";
12
+ }
13
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
14
+ set code(_name) {
15
+ throw new Error("Cannot overwrite code EEXIST");
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ get name() {
19
+ return "AlreadyExistsError";
20
+ }
21
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
22
+ set name(_name) {
23
+ throw new Error("Cannot overwrite name of AlreadyExistsError");
24
+ }
25
+ }
26
+
27
+ export { AlreadyExistsError as default };
@@ -0,0 +1,27 @@
1
+ class DirectoryError extends Error {
2
+ /**
3
+ * Creates a new instance.
4
+ * @param message The error message.
5
+ */
6
+ constructor(message) {
7
+ super(`EISDIR: Illegal operation on a directory, ${message}`);
8
+ }
9
+ // eslint-disable-next-line class-methods-use-this
10
+ get code() {
11
+ return "EISDIR";
12
+ }
13
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
14
+ set code(_name) {
15
+ throw new Error("Cannot overwrite code EISDIR");
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ get name() {
19
+ return "DirectoryError";
20
+ }
21
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
22
+ set name(_name) {
23
+ throw new Error("Cannot overwrite name of DirectoryError");
24
+ }
25
+ }
26
+
27
+ export { DirectoryError as default };
@@ -0,0 +1,8 @@
1
+ const F_OK = 0;
2
+ const R_OK = 4;
3
+ const W_OK = 2;
4
+ const X_OK = 1;
5
+ const FIND_UP_STOP = Symbol("findUpStop");
6
+ const INTERNAL_STRIP_JSON_REGEX = /"(?:[^"\\]|\\.)*"|\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g;
7
+
8
+ export { FIND_UP_STOP, F_OK, INTERNAL_STRIP_JSON_REGEX, R_OK, W_OK, X_OK };
@@ -0,0 +1,26 @@
1
+ class JSONError extends Error {
2
+ fileName;
3
+ codeFrame;
4
+ // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
5
+ name = "JSONError";
6
+ #message;
7
+ /**
8
+ * Creates a new JSONError instance.
9
+ * @param message The primary error message.
10
+ */
11
+ constructor(message) {
12
+ super();
13
+ this.#message = message;
14
+ }
15
+ get message() {
16
+ return `${this.#message}${this.fileName ? ` in ${this.fileName}` : ""}${this.codeFrame ? `
17
+
18
+ ${this.codeFrame}
19
+ ` : ""}`;
20
+ }
21
+ set message(message) {
22
+ this.#message = message;
23
+ }
24
+ }
25
+
26
+ export { JSONError as default };
@@ -0,0 +1,27 @@
1
+ class NotEmptyError extends Error {
2
+ /**
3
+ * Creates a new instance.
4
+ * @param message The error message.
5
+ */
6
+ constructor(message) {
7
+ super(`ENOTEMPTY: Directory not empty, ${message}`);
8
+ }
9
+ // eslint-disable-next-line class-methods-use-this
10
+ get code() {
11
+ return "ENOTEMPTY";
12
+ }
13
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
14
+ set code(_name) {
15
+ throw new Error("Cannot overwrite code ENOTEMPTY");
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ get name() {
19
+ return "NotEmptyError";
20
+ }
21
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
22
+ set name(_name) {
23
+ throw new Error("Cannot overwrite name of NotEmptyError");
24
+ }
25
+ }
26
+
27
+ export { NotEmptyError as default };
@@ -0,0 +1,27 @@
1
+ class NotFoundError extends Error {
2
+ /**
3
+ * Creates a new instance.
4
+ * @param message The error message.
5
+ */
6
+ constructor(message) {
7
+ super(`ENOENT: ${message}`);
8
+ }
9
+ // eslint-disable-next-line class-methods-use-this
10
+ get code() {
11
+ return "ENOENT";
12
+ }
13
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
14
+ set code(_name) {
15
+ throw new Error("Cannot overwrite code ENOENT");
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ get name() {
19
+ return "NotFoundError";
20
+ }
21
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
22
+ set name(_name) {
23
+ throw new Error("Cannot overwrite name of NotFoundError");
24
+ }
25
+ }
26
+
27
+ export { NotFoundError as default };
@@ -0,0 +1,27 @@
1
+ class PermissionError extends Error {
2
+ /**
3
+ * Creates a new instance.
4
+ * @param message The error message.
5
+ */
6
+ constructor(message) {
7
+ super(`EPERM: Operation not permitted, ${message}`);
8
+ }
9
+ // eslint-disable-next-line class-methods-use-this
10
+ get code() {
11
+ return "EPERM";
12
+ }
13
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
14
+ set code(_name) {
15
+ throw new Error("Cannot overwrite code EPERM");
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ get name() {
19
+ return "PermissionError";
20
+ }
21
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
22
+ set name(_name) {
23
+ throw new Error("Cannot overwrite name of PermissionError");
24
+ }
25
+ }
26
+
27
+ export { PermissionError as default };
@@ -0,0 +1,24 @@
1
+ class WalkError extends Error {
2
+ /** File path of the root that's being walked. */
3
+ root;
4
+ /**
5
+ * Constructs a new instance.
6
+ * @param cause The underlying error or reason for the walk failure.
7
+ * @param root The root directory path where the walk operation started or encountered the error.
8
+ */
9
+ constructor(cause, root) {
10
+ super(`${cause instanceof Error ? cause.message : cause} for path "${root}"`);
11
+ this.cause = cause;
12
+ this.root = root;
13
+ }
14
+ // eslint-disable-next-line class-methods-use-this
15
+ get name() {
16
+ return "WalkError";
17
+ }
18
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
19
+ set name(_name) {
20
+ throw new Error("Cannot overwrite name of WalkError");
21
+ }
22
+ }
23
+
24
+ export { WalkError as default };
@@ -0,0 +1,7 @@
1
+ const assertValidFileContents = (contents) => {
2
+ if (typeof contents !== "string" && !(contents instanceof ArrayBuffer) && !ArrayBuffer.isView(contents)) {
3
+ throw new TypeError("File contents must be a string, ArrayBuffer, or ArrayBuffer view.");
4
+ }
5
+ };
6
+
7
+ export { assertValidFileContents as default };
@@ -0,0 +1,7 @@
1
+ const assertValidFileOrDirectoryPath = (fileOrDirectoryPath) => {
2
+ if (!fileOrDirectoryPath || !(fileOrDirectoryPath instanceof URL) && typeof fileOrDirectoryPath !== "string") {
3
+ throw new TypeError("Path must be a non-empty string or URL.");
4
+ }
5
+ };
6
+
7
+ export { assertValidFileOrDirectoryPath as default };
@@ -0,0 +1,14 @@
1
+ import walk from './walk-BhTbpr3y.js';
2
+
3
+ const collect = async (directory, options = {}) => {
4
+ if (!Array.isArray(options.extensions)) {
5
+ options.extensions = ["js", "mjs", "cjs", "ts"];
6
+ }
7
+ const entries = [];
8
+ for await (const entry of walk(directory, options)) {
9
+ entries.push(entry.path);
10
+ }
11
+ return entries;
12
+ };
13
+
14
+ export { collect as default };
@@ -0,0 +1,14 @@
1
+ import walkSync from './walkSync-DDBq95s8.js';
2
+
3
+ const collectSync = (directory, options = {}) => {
4
+ if (!Array.isArray(options.extensions)) {
5
+ options.extensions = ["js", "mjs", "cjs", "ts"];
6
+ }
7
+ const entries = [];
8
+ for (const entry of walkSync(directory, options)) {
9
+ entries.push(entry.path);
10
+ }
11
+ return entries;
12
+ };
13
+
14
+ export { collectSync as default };
@@ -0,0 +1,43 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ existsSync
22
+ } = __cjs_getBuiltinModule("node:fs");
23
+ const {
24
+ mkdir,
25
+ readdir,
26
+ rm
27
+ } = __cjs_getBuiltinModule("node:fs/promises");
28
+ import { join } from '@visulima/path';
29
+ import { toPath } from '@visulima/path/utils';
30
+ import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
31
+
32
+ const emptyDir = async (dir, options) => {
33
+ assertValidFileOrDirectoryPath(dir);
34
+ if (!existsSync(dir)) {
35
+ await mkdir(dir, { recursive: true });
36
+ return;
37
+ }
38
+ for await (const item of await readdir(dir)) {
39
+ await rm(join(toPath(dir), item), { ...options, force: true, recursive: true });
40
+ }
41
+ };
42
+
43
+ export { emptyDir as default };
@@ -0,0 +1,41 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ existsSync,
22
+ mkdirSync,
23
+ readdirSync,
24
+ rmSync
25
+ } = __cjs_getBuiltinModule("node:fs");
26
+ import { join } from '@visulima/path';
27
+ import { toPath } from '@visulima/path/utils';
28
+ import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
29
+
30
+ const emptyDirSync = (dir, options) => {
31
+ assertValidFileOrDirectoryPath(dir);
32
+ if (!existsSync(dir)) {
33
+ mkdirSync(dir, { recursive: true });
34
+ return;
35
+ }
36
+ for (const item of readdirSync(dir)) {
37
+ rmSync(join(toPath(dir), item), { ...options, force: true, recursive: true });
38
+ }
39
+ };
40
+
41
+ export { emptyDirSync as default };
@@ -0,0 +1,53 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ lstat,
22
+ mkdir
23
+ } = __cjs_getBuiltinModule("node:fs/promises");
24
+ import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
25
+ import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
26
+
27
+ const ensureDir = async (directory) => {
28
+ assertValidFileOrDirectoryPath(directory);
29
+ try {
30
+ const fileInfo = await lstat(directory);
31
+ if (!fileInfo.isDirectory()) {
32
+ throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
33
+ }
34
+ return;
35
+ } catch (error) {
36
+ if (error.code !== "ENOENT") {
37
+ throw error;
38
+ }
39
+ }
40
+ try {
41
+ await mkdir(directory, { recursive: true });
42
+ } catch (error) {
43
+ if (error.code !== "EEXIST") {
44
+ throw error;
45
+ }
46
+ const fileInfo = await lstat(directory);
47
+ if (!fileInfo.isDirectory()) {
48
+ throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
49
+ }
50
+ }
51
+ };
52
+
53
+ export { ensureDir as default };
@@ -0,0 +1,53 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ lstatSync,
22
+ mkdirSync
23
+ } = __cjs_getBuiltinModule("node:fs");
24
+ import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
25
+ import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
26
+
27
+ const ensureDirSync = (directory) => {
28
+ assertValidFileOrDirectoryPath(directory);
29
+ try {
30
+ const fileInfo = lstatSync(directory);
31
+ if (!fileInfo.isDirectory()) {
32
+ throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
33
+ }
34
+ return;
35
+ } catch (error) {
36
+ if (error.code !== "ENOENT") {
37
+ throw error;
38
+ }
39
+ }
40
+ try {
41
+ mkdirSync(directory, { recursive: true });
42
+ } catch (error) {
43
+ if (error.code !== "EEXIST") {
44
+ throw error;
45
+ }
46
+ const fileInfo = lstatSync(directory);
47
+ if (!fileInfo.isDirectory()) {
48
+ throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
49
+ }
50
+ }
51
+ };
52
+
53
+ export { ensureDirSync as default };
@@ -0,0 +1,47 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ lstat,
22
+ writeFile
23
+ } = __cjs_getBuiltinModule("node:fs/promises");
24
+ import { dirname } from '@visulima/path';
25
+ import { toPath } from '@visulima/path/utils';
26
+ import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
27
+ import ensureDir from './ensureDir-C_kuQ5Ik.js';
28
+ import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
29
+
30
+ const ensureFile = async (filePath) => {
31
+ assertValidFileOrDirectoryPath(filePath);
32
+ try {
33
+ const stat = await lstat(filePath);
34
+ if (!stat.isFile()) {
35
+ throw new Error(`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`);
36
+ }
37
+ } catch (error) {
38
+ if (error.code === "ENOENT") {
39
+ await ensureDir(dirname(toPath(filePath)));
40
+ await writeFile(filePath, new Uint8Array());
41
+ return;
42
+ }
43
+ throw error;
44
+ }
45
+ };
46
+
47
+ export { ensureFile as default };
@@ -0,0 +1,47 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ lstatSync,
22
+ writeFileSync
23
+ } = __cjs_getBuiltinModule("node:fs");
24
+ import { dirname } from '@visulima/path';
25
+ import { toPath } from '@visulima/path/utils';
26
+ import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
27
+ import ensureDirSync from './ensureDirSync-CI5g-uBI.js';
28
+ import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
29
+
30
+ const ensureFileSync = (filePath) => {
31
+ assertValidFileOrDirectoryPath(filePath);
32
+ try {
33
+ const stat = lstatSync(filePath);
34
+ if (!stat.isFile()) {
35
+ throw new Error(`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`);
36
+ }
37
+ } catch (error) {
38
+ if (error.code === "ENOENT") {
39
+ ensureDirSync(dirname(toPath(filePath)));
40
+ writeFileSync(filePath, new Uint8Array());
41
+ return;
42
+ }
43
+ throw error;
44
+ }
45
+ };
46
+
47
+ export { ensureFileSync as default };