@visulima/fs 5.0.0-alpha.3 → 5.0.0-alpha.31

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 (223) hide show
  1. package/CHANGELOG.md +377 -0
  2. package/LICENSE.md +208 -131
  3. package/dist/eol.d.ts +31 -30
  4. package/dist/eol.js +3 -26
  5. package/dist/error.d.ts +273 -7
  6. package/dist/error.js +1 -7
  7. package/dist/glob-parent.d.ts +35 -0
  8. package/dist/glob-parent.js +1 -0
  9. package/dist/glob.d.ts +4 -0
  10. package/dist/glob.js +1 -0
  11. package/dist/index.d.ts +857 -36
  12. package/dist/index.js +1 -33
  13. package/dist/ini.d.ts +70 -0
  14. package/dist/ini.js +1 -0
  15. package/dist/is-glob.d.ts +34 -0
  16. package/dist/is-glob.js +1 -0
  17. package/dist/json5.d.ts +36 -0
  18. package/dist/json5.js +1 -0
  19. package/dist/jsonc.d.ts +65 -0
  20. package/dist/jsonc.js +1 -0
  21. package/dist/match.d.ts +80 -0
  22. package/dist/match.js +1 -0
  23. package/dist/packem_shared/AlreadyExistsError-DEb3UWja.js +1 -0
  24. package/dist/packem_shared/DirectoryError-BtwSTLmT.js +1 -0
  25. package/dist/packem_shared/F_OK-CAwY1qU7.js +1 -0
  26. package/dist/packem_shared/JSONError-Cvp9ycba.js +4 -0
  27. package/dist/packem_shared/NotEmptyError-DZ1Ix089.js +1 -0
  28. package/dist/packem_shared/NotFoundError-CnRY6lVp.js +1 -0
  29. package/dist/packem_shared/PermissionError-DJ_2VWEj.js +1 -0
  30. package/dist/packem_shared/WalkError-B8qTd-v-.js +1 -0
  31. package/dist/packem_shared/_commonjsHelpers-CWAkuNXM.js +1 -0
  32. package/dist/packem_shared/assertValidFileContents-CbIN7sy7.js +1 -0
  33. package/dist/packem_shared/assertValidFileOrDirectoryPath-BTlt945W.js +1 -0
  34. package/dist/packem_shared/build-rm-options-avnusYx-.js +1 -0
  35. package/dist/packem_shared/collect-VHN_VRLN.js +1 -0
  36. package/dist/packem_shared/collectSync-C28T6vrY.js +1 -0
  37. package/dist/packem_shared/emptyDir-C7lyd1lW.js +1 -0
  38. package/dist/packem_shared/emptyDirSync-B8EYpmO9.js +1 -0
  39. package/dist/packem_shared/ensureDir-DGarVZw8.js +1 -0
  40. package/dist/packem_shared/ensureDirSync-CsgPrsDH.js +1 -0
  41. package/dist/packem_shared/ensureFile-CMugWljp.js +1 -0
  42. package/dist/packem_shared/ensureFileSync-CJYTEx2r.js +1 -0
  43. package/dist/packem_shared/ensureLink-ChShf3lf.js +1 -0
  44. package/dist/packem_shared/ensureLinkSync-DPpq0I2Z.js +1 -0
  45. package/dist/packem_shared/ensureSymlink-y4FZjfxA.js +1 -0
  46. package/dist/packem_shared/ensureSymlinkSync-TcHssCH7.js +1 -0
  47. package/dist/packem_shared/findUp-D49u53m9.js +1 -0
  48. package/dist/packem_shared/findUpSync-C2oAKTw1.js +1 -0
  49. package/dist/packem_shared/get-file-info-type-DzWpohDB.js +1 -0
  50. package/dist/packem_shared/glob-D_7bct6p.js +1 -0
  51. package/dist/packem_shared/glob-sync.d-BgJM6l8W.d.ts +54 -0
  52. package/dist/packem_shared/globSync-f-4jVwn9.js +1 -0
  53. package/dist/packem_shared/index-B2MhYg3r.js +1 -0
  54. package/dist/packem_shared/index-BHy3Kcr7.js +11 -0
  55. package/dist/packem_shared/index-BspkXADC.js +1 -0
  56. package/dist/packem_shared/index-CChvzByK.js +1 -0
  57. package/dist/packem_shared/indexToLineColumn-BRSZFC6I-B2OZwR8G.js +6 -0
  58. package/dist/packem_shared/ini-preserve-D1DopDLd.js +4 -0
  59. package/dist/packem_shared/is-stats-identical-l1GRN4Qu.js +1 -0
  60. package/dist/packem_shared/isAccessible-DV2K-m2B.js +1 -0
  61. package/dist/packem_shared/isAccessibleSync-BCjiSxHj.js +1 -0
  62. package/dist/packem_shared/isFsCaseSensitive-j6UlSSM7.js +1 -0
  63. package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +52 -0
  64. package/dist/packem_shared/jsonc-merge-Bkw73TLW.js +2 -0
  65. package/dist/packem_shared/move-CvE-ntXL.js +1 -0
  66. package/dist/packem_shared/parseJson-vUriP0eD.js +1 -0
  67. package/dist/packem_shared/readFile-ZXEXbVU5.js +1 -0
  68. package/dist/packem_shared/readFileSync-DseCu8sg.js +1 -0
  69. package/dist/packem_shared/readIni-CQK8HYxE.js +1 -0
  70. package/dist/packem_shared/readIniSync-l9LoYPoP.js +1 -0
  71. package/dist/packem_shared/readJson-T0hatQjC.js +1 -0
  72. package/dist/packem_shared/readJson5-CHbnB73J.js +1 -0
  73. package/dist/packem_shared/readJson5Sync-BsyhQYi8.js +1 -0
  74. package/dist/packem_shared/readJsonSync-Drti0sPY.js +1 -0
  75. package/dist/packem_shared/readJsonc-1woJjNLd.js +1 -0
  76. package/dist/packem_shared/readJsoncSync-TILCPRUQ.js +1 -0
  77. package/dist/packem_shared/readToml-Dawx4pqK.js +1 -0
  78. package/dist/packem_shared/readTomlSync-hnDlOU7g.js +1 -0
  79. package/dist/packem_shared/readYaml-DuXAtLKY.js +1 -0
  80. package/dist/packem_shared/readYamlSync-KlhBWm72.js +1 -0
  81. package/dist/packem_shared/remove-DmEfBrzp.js +1 -0
  82. package/dist/packem_shared/removeSync--c4qlu32.js +1 -0
  83. package/dist/packem_shared/resolve-symlink-target-CWrn0v4P.js +1 -0
  84. package/dist/packem_shared/sanitize-DGZ3w-_w.js +1 -0
  85. package/dist/packem_shared/stripJsonComments-gXl-1fAs.js +1 -0
  86. package/dist/packem_shared/to-uint-8-array-BBchIT6g.js +1 -0
  87. package/dist/packem_shared/types.d-C1ygRkw1.d.ts +1660 -0
  88. package/dist/packem_shared/walk-CxKfBzrV.js +1 -0
  89. package/dist/packem_shared/walk-include-BXhGSn6t.js +1 -0
  90. package/dist/packem_shared/walkSync-JkSkFL-F.js +1 -0
  91. package/dist/packem_shared/writeFile-CM-OVzxG.js +1 -0
  92. package/dist/packem_shared/writeFileSync-CNaAkXSP.js +1 -0
  93. package/dist/packem_shared/writeIni-B1NVnZkX.js +4 -0
  94. package/dist/packem_shared/writeIniSync-CwS1da1r.js +4 -0
  95. package/dist/packem_shared/writeJson-DC1V8Afe.js +4 -0
  96. package/dist/packem_shared/writeJson5--_qaVjxW.js +4 -0
  97. package/dist/packem_shared/writeJson5Sync-DPOk8wWz.js +4 -0
  98. package/dist/packem_shared/writeJsonSync-CUt49Wp1.js +4 -0
  99. package/dist/packem_shared/writeJsonc-DXuAO3_X.js +4 -0
  100. package/dist/packem_shared/writeJsoncSync-BEeqh1ry.js +4 -0
  101. package/dist/packem_shared/writeToml-BFD91-Sv.js +1 -0
  102. package/dist/packem_shared/writeTomlSync-D30hzuuu.js +1 -0
  103. package/dist/packem_shared/writeYaml-BD9JVGkk.js +1 -0
  104. package/dist/packem_shared/writeYamlSync-BobkRsmd.js +1 -0
  105. package/dist/size.d.ts +246 -246
  106. package/dist/size.js +1 -144
  107. package/dist/toml.d.ts +63 -0
  108. package/dist/toml.js +1 -0
  109. package/dist/utils.d.ts +103 -6
  110. package/dist/utils.js +1 -6
  111. package/dist/yaml.d.ts +13 -5
  112. package/dist/yaml.js +1 -4
  113. package/package.json +69 -18
  114. package/dist/constants.d.ts +0 -42
  115. package/dist/ensure/ensure-dir-sync.d.ts +0 -14
  116. package/dist/ensure/ensure-dir.d.ts +0 -14
  117. package/dist/ensure/ensure-file-sync.d.ts +0 -15
  118. package/dist/ensure/ensure-file.d.ts +0 -27
  119. package/dist/ensure/ensure-link-sync.d.ts +0 -16
  120. package/dist/ensure/ensure-link.d.ts +0 -16
  121. package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
  122. package/dist/ensure/ensure-symlink.d.ts +0 -23
  123. package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
  124. package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
  125. package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
  126. package/dist/error/already-exists-error.d.ts +0 -39
  127. package/dist/error/directory-error.d.ts +0 -47
  128. package/dist/error/json-error.d.ts +0 -52
  129. package/dist/error/not-empty-error.d.ts +0 -51
  130. package/dist/error/not-found-error.d.ts +0 -44
  131. package/dist/error/permission-error.d.ts +0 -45
  132. package/dist/error/walk-error.d.ts +0 -51
  133. package/dist/find/collect-sync.d.ts +0 -31
  134. package/dist/find/collect.d.ts +0 -35
  135. package/dist/find/find-up-sync.d.ts +0 -42
  136. package/dist/find/find-up.d.ts +0 -46
  137. package/dist/find/utils/glob-to-regexp.d.ts +0 -2
  138. package/dist/find/utils/walk-include.d.ts +0 -2
  139. package/dist/find/walk-sync.d.ts +0 -34
  140. package/dist/find/walk.d.ts +0 -37
  141. package/dist/is-accessible-sync.d.ts +0 -3
  142. package/dist/is-accessible.d.ts +0 -29
  143. package/dist/move/index.d.ts +0 -68
  144. package/dist/move/types.d.ts +0 -36
  145. package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
  146. package/dist/move/utils/internal-move-file.d.ts +0 -3
  147. package/dist/move/utils/validate-same-directory.d.ts +0 -2
  148. package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
  149. package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
  150. package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
  151. package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
  152. package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
  153. package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
  154. package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
  155. package/dist/packem_shared/WalkError-DUdQd6FT.js +0 -24
  156. package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
  157. package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
  158. package/dist/packem_shared/collect-DcBwsYYd.js +0 -14
  159. package/dist/packem_shared/collectSync-Bkjf9Dbm.js +0 -14
  160. package/dist/packem_shared/emptyDir-CYB5Tict.js +0 -43
  161. package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +0 -41
  162. package/dist/packem_shared/ensureDir-C_kuQ5Ik.js +0 -53
  163. package/dist/packem_shared/ensureDirSync-CI5g-uBI.js +0 -53
  164. package/dist/packem_shared/ensureFile-BUtXGlGT.js +0 -47
  165. package/dist/packem_shared/ensureFileSync-C8hASR-1.js +0 -47
  166. package/dist/packem_shared/ensureLink-BPnAG5-P.js +0 -54
  167. package/dist/packem_shared/ensureLinkSync-B-Z7X0ub.js +0 -54
  168. package/dist/packem_shared/ensureSymlink-U5B6J0BN.js +0 -73
  169. package/dist/packem_shared/ensureSymlinkSync-DHnZj-9F.js +0 -74
  170. package/dist/packem_shared/findUp-BSnyGqer.js +0 -85
  171. package/dist/packem_shared/findUpSync-jRHbSCMV.js +0 -85
  172. package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
  173. package/dist/packem_shared/index-CHM-in-V.js +0 -100
  174. package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
  175. package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
  176. package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
  177. package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +0 -62
  178. package/dist/packem_shared/move-DbpW5_vA.js +0 -134
  179. package/dist/packem_shared/parseJson-C8xb-3LR.js +0 -231
  180. package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
  181. package/dist/packem_shared/readFileSync-6GEIrOnl.js +0 -53
  182. package/dist/packem_shared/readJson-vddQ97Ll.js +0 -22
  183. package/dist/packem_shared/readJsonSync-DzeAdYZl.js +0 -22
  184. package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
  185. package/dist/packem_shared/readYamlSync-DMV4U-gi.js +0 -10
  186. package/dist/packem_shared/remove-_oDY3uKo.js +0 -38
  187. package/dist/packem_shared/removeSync-DETRj7Qn.js +0 -38
  188. package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
  189. package/dist/packem_shared/sanitize-lOzE6k2A.js +0 -205
  190. package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
  191. package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
  192. package/dist/packem_shared/walk-BhTbpr3y.js +0 -115
  193. package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
  194. package/dist/packem_shared/walkSync-DDBq95s8.js +0 -114
  195. package/dist/packem_shared/writeFile-DSHERs0Z.js +0 -83
  196. package/dist/packem_shared/writeFileSync-CJp1kXQR.js +0 -83
  197. package/dist/packem_shared/writeJson-C0OfLDbe.js +0 -50
  198. package/dist/packem_shared/writeJsonSync-Cs21FE7v.js +0 -50
  199. package/dist/packem_shared/writeYaml-n4xzYN9a.js +0 -24
  200. package/dist/packem_shared/writeYamlSync-DnOEnP10.js +0 -24
  201. package/dist/read/read-file-sync.d.ts +0 -37
  202. package/dist/read/read-file.d.ts +0 -41
  203. package/dist/read/read-json-sync.d.ts +0 -5
  204. package/dist/read/read-json.d.ts +0 -5
  205. package/dist/read/read-yaml-sync.d.ts +0 -4
  206. package/dist/read/read-yaml.d.ts +0 -4
  207. package/dist/remove/empty-dir-sync.d.ts +0 -23
  208. package/dist/remove/empty-dir.d.ts +0 -28
  209. package/dist/remove/remove-sync.d.ts +0 -27
  210. package/dist/remove/remove.d.ts +0 -32
  211. package/dist/sanitize.d.ts +0 -31
  212. package/dist/types.d.ts +0 -304
  213. package/dist/utils/assert-valid-file-contents.d.ts +0 -27
  214. package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
  215. package/dist/utils/parse-json.d.ts +0 -5
  216. package/dist/utils/strip-json-comments.d.ts +0 -44
  217. package/dist/write/utils/to-uint-8-array.d.ts +0 -2
  218. package/dist/write/write-file-sync.d.ts +0 -30
  219. package/dist/write/write-file.d.ts +0 -30
  220. package/dist/write/write-json-sync.d.ts +0 -29
  221. package/dist/write/write-json.d.ts +0 -30
  222. package/dist/write/write-yaml-sync.d.ts +0 -4
  223. package/dist/write/write-yaml.d.ts +0 -4
@@ -1,16 +0,0 @@
1
- /**
2
- * Ensures that the hard link exists.
3
- * If the directory structure does not exist, it is created.
4
- * @param source The path to the source file or directory.
5
- * @param destination The path to the destination link.
6
- * @example
7
- * ```javascript
8
- * import { ensureLink } from "@visulima/fs";
9
- * import { join } from "node:path";
10
- *
11
- * // ensure the link /tmp/foo/bar-link.txt points to /tmp/foo/bar.txt
12
- * await ensureLink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
13
- * ```
14
- */
15
- declare const ensureLink: (source: URL | string, destination: URL | string) => Promise<void>;
16
- export default ensureLink;
@@ -1,23 +0,0 @@
1
- import type { symlink } from "node:fs";
2
- /**
3
- * Ensures that the link exists, and points to a valid file.
4
- * If the directory structure does not exist, it is created.
5
- * If the link already exists, it is not modified but error is thrown if it is not point to the given target.
6
- * @param target the source file path
7
- * @param linkName the destination link path
8
- * @param type the type of the symlink, or null to use automatic detection
9
- * @returns A void.
10
- * @example
11
- * ```javascript
12
- * import { ensureSymlinkSync } from "@visulima/fs";
13
- * import { join } from "node:path";
14
- *
15
- * // Ensure a symlink /tmp/foo/link-to-bar.txt points to /tmp/foo/bar.txt
16
- * ensureSymlinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-bar.txt"));
17
- *
18
- * // Ensure a directory symlink /tmp/foo/link-to-baz-dir points to /tmp/foo/baz-dir
19
- * ensureSymlinkSync(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
20
- * ```
21
- */
22
- declare const ensureSymlinkSync: (target: URL | string, linkName: URL | string, type?: symlink.Type) => void;
23
- export default ensureSymlinkSync;
@@ -1,23 +0,0 @@
1
- import type { symlink as symlinkSync } from "node:fs";
2
- /**
3
- * Ensures that the link exists, and points to a valid file.
4
- * If the directory structure does not exist, it is created.
5
- * If the link already exists, it is not modified but error is thrown if it is not point to the given target.
6
- * @param target the source file path
7
- * @param linkName the destination link path
8
- * @param type the type of the symlink, or null to use automatic detection
9
- * @returns A void promise that resolves once the link exists.
10
- * @example
11
- * ```javascript
12
- * import { ensureSymlink } from "@visulima/fs";
13
- * import { join } from "node:path";
14
- *
15
- * // Ensure a symlink /tmp/foo/link-to-bar.txt points to /tmp/foo/bar.txt
16
- * await ensureSymlink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-bar.txt"));
17
- *
18
- * // Ensure a directory symlink /tmp/foo/link-to-baz-dir points to /tmp/foo/baz-dir
19
- * await ensureSymlink(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
20
- * ```
21
- */
22
- declare const ensureSymlink: (target: URL | string, linkName: URL | string, type?: symlinkSync.Type) => Promise<void>;
23
- export default ensureSymlink;
@@ -1,7 +0,0 @@
1
- import type { Stats } from "node:fs";
2
- export type PathType = "dir" | "file" | "symlink";
3
- /**
4
- * Get a human-readable file type string.
5
- * @param fileInfo A FileInfo describes a file and is returned by `stat`, `lstat`
6
- */
7
- export declare const getFileInfoType: (fileInfo: Stats) => PathType | undefined;
@@ -1,3 +0,0 @@
1
- import type { Stats } from "node:fs";
2
- declare const isStatsIdentical: (sourceStat: Stats, destinationStat: Stats) => boolean;
3
- export default isStatsIdentical;
@@ -1,2 +0,0 @@
1
- declare const resolveSymlinkTarget: (target: URL | string, linkName: URL | string) => URL | string;
2
- export default resolveSymlinkTarget;
@@ -1,39 +0,0 @@
1
- /**
2
- * Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
3
- * @example
4
- * ```javascript
5
- * import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly
6
- * import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this
7
- * import { join } from "node:path";
8
- *
9
- * try {
10
- * // Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
11
- * // For demonstration, let's assume someFunction internally throws it:
12
- * const someFunctionThatMightThrow = (path) => {
13
- * if (path === "/tmp/existing-file.txt") { // Simulate a check
14
- * throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
15
- * }
16
- * }
17
- * someFunctionThatMightThrow("/tmp/existing-file.txt");
18
- * } catch (error) {
19
- * if (error instanceof AlreadyExistsError) {
20
- * console.error(`Operation failed because path exists: ${error.message}`);
21
- * console.error(`Error code: ${error.code}`); // EEXIST
22
- * } else {
23
- * console.error("An unexpected error occurred:", error);
24
- * }
25
- * }
26
- * ```
27
- */
28
- declare class AlreadyExistsError extends Error {
29
- /**
30
- * Creates a new instance.
31
- * @param message
32
- */
33
- constructor(message: string);
34
- get code(): string;
35
- set code(_name: string);
36
- get name(): string;
37
- set name(_name: string);
38
- }
39
- export default AlreadyExistsError;
@@ -1,47 +0,0 @@
1
- /**
2
- * Error thrown when an operation that is not allowed on a directory is attempted.
3
- * This typically occurs when a file-specific operation is used on a directory path.
4
- * @example
5
- * ```javascript
6
- * import { DirectoryError } from "@visulima/fs/error";
7
- * import { readFile } from "@visulima/fs"; // Or any function that might throw this
8
- * import { join } from "node:path";
9
- *
10
- * const attemptToReadFileFromDir = async () => {
11
- * try {
12
- * // Attempting to read a directory as if it were a file
13
- * // This is a conceptual example; readFile might throw a different error first
14
- * // depending on its internal checks, but EISDIR is the underlying system error.
15
- * // Forcing the scenario:
16
- * const pretendReadFileOnDir = (path) => {
17
- * if (path === "/tmp/my-directory") { // Simulate a directory path
18
- * throw new DirectoryError(`read '/tmp/my-directory'`);
19
- * }
20
- * }
21
- * pretendReadFileOnDir("/tmp/my-directory");
22
- * // await readFile(join("/tmp", "my-directory"));
23
- * } catch (error) {
24
- * if (error instanceof DirectoryError) {
25
- * console.error(`Operation failed, path is a directory: ${error.message}`);
26
- * console.error(`Error code: ${error.code}`); // EISDIR
27
- * } else {
28
- * console.error("An unexpected error occurred:", error);
29
- * }
30
- * }
31
- * };
32
- *
33
- * attemptToReadFileFromDir();
34
- * ```
35
- */
36
- declare class DirectoryError extends Error {
37
- /**
38
- * Creates a new instance.
39
- * @param message
40
- */
41
- constructor(message: string);
42
- get code(): string;
43
- set code(_name: string);
44
- get name(): string;
45
- set name(_name: string);
46
- }
47
- export default DirectoryError;
@@ -1,52 +0,0 @@
1
- /**
2
- * Custom error class for handling JSON parsing or related errors.
3
- * It can optionally include a file name and a code frame for better debugging.
4
- * @example
5
- * ```javascript
6
- * import { JSONError } from "@visulima/fs/error";
7
- * import { readJsonSync } from "@visulima/fs"; // Or any function that might throw this
8
- * import { join } from "node:path";
9
- *
10
- * try {
11
- * // Imagine readJsonSync encounters a malformed JSON file and throws JSONError
12
- * // Forcing the scenario for demonstration:
13
- * const simulateJsonError = (filePath, content) => {
14
- * const err = new JSONError(`Unexpected token '}' at position 15`);
15
- * err.fileName = filePath;
16
- * // A real implementation might generate a code frame using a library
17
- * err.codeFrame = ` 13 | "key": "value",
18
- * > 14 | "anotherKey": "anotherValue",}
19
- * | ^
20
- * 15 | "lastKey": "end"
21
- * `;
22
- * throw err;
23
- * };
24
- *
25
- * simulateJsonError(join("path", "to", "corrupted.json"), '{ "key": "value", "anotherKey": "anotherValue",} ');
26
- * // const jsonData = readJsonSync(join("path", "to", "corrupted.json"));
27
- * } catch (error) {
28
- * if (error instanceof JSONError) {
29
- * console.error(`JSON Error: ${error.message}`);
30
- * // message property will include fileName and codeFrame if they were set.
31
- * // console.error(`File: ${error.fileName}`);
32
- * // console.error(`Code Frame:\n${error.codeFrame}`);
33
- * } else {
34
- * console.error("An unexpected error occurred:", error);
35
- * }
36
- * }
37
- * ```
38
- */
39
- declare class JSONError extends Error {
40
- #private;
41
- fileName: string | undefined;
42
- codeFrame: string | undefined;
43
- readonly name = "JSONError";
44
- /**
45
- * Creates a new JSONError instance.
46
- * @param message The primary error message.
47
- */
48
- constructor(message: string);
49
- get message(): string;
50
- set message(message: string);
51
- }
52
- export default JSONError;
@@ -1,51 +0,0 @@
1
- /**
2
- * Error thrown when a directory is not empty.
3
- * @example
4
- * ```javascript
5
- * import { NotEmptyError } from "@visulima/fs/error";
6
- * import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error
7
- * import { join } from "node:path";
8
- *
9
- * const attemptToRemoveNonEmptyDir = async () => {
10
- * const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
11
- * try {
12
- * // Forcing the scenario for demonstration, as rmdir might throw its own specific error.
13
- * // Node.js fs operations that encounter a non-empty directory when expecting an empty one
14
- * // typically throw an error with code ENOTEMPTY.
15
- * const simulateNotEmpty = (path) => {
16
- * if (path === dirPath) { // Simulate check for non-empty
17
- * throw new NotEmptyError(`rmdir '${dirPath}'`);
18
- * }
19
- * }
20
- * simulateNotEmpty(dirPath);
21
- * // await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
22
- * } catch (error) {
23
- * if (error instanceof NotEmptyError) {
24
- * console.error(`Operation failed, directory is not empty: ${error.message}`);
25
- * console.error(`Error code: ${error.code}`); // ENOTEMPTY
26
- * } else {
27
- * console.error("An unexpected error occurred:", error);
28
- * }
29
- * }
30
- * };
31
- *
32
- * // You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
33
- * // import { ensureDirSync, writeFileSync } from "@visulima/fs";
34
- * // ensureDirSync(dirPath);
35
- * // writeFileSync(join(dirPath, "somefile.txt"), "content");
36
- *
37
- * attemptToRemoveNonEmptyDir();
38
- * ```
39
- */
40
- declare class NotEmptyError extends Error {
41
- /**
42
- * Creates a new instance.
43
- * @param message
44
- */
45
- constructor(message: string);
46
- get code(): string;
47
- set code(_name: string);
48
- get name(): string;
49
- set name(_name: string);
50
- }
51
- export default NotEmptyError;
@@ -1,44 +0,0 @@
1
- /**
2
- * Error thrown when a file or directory is not found at a specified path.
3
- * @example
4
- * ```javascript
5
- * import { NotFoundError } from "@visulima/fs/error";
6
- * import { readFile } from "@visulima/fs"; // Or any function that might throw this
7
- * import { join } from "node:path";
8
- *
9
- * const tryReadingNonExistentFile = async () => {
10
- * const filePath = join("/tmp", "this-file-does-not-exist.txt");
11
- * try {
12
- * // Forcing the scenario for demonstration, as readFile itself would throw this.
13
- * const simulateNotFound = (path) => {
14
- * if (path === filePath) {
15
- * throw new NotFoundError(`no such file or directory, open '${filePath}'`);
16
- * }
17
- * }
18
- * simulateNotFound(filePath);
19
- * // await readFile(filePath);
20
- * } catch (error) {
21
- * if (error instanceof NotFoundError) {
22
- * console.error(`Operation failed, path not found: ${error.message}`);
23
- * console.error(`Error code: ${error.code}`); // ENOENT
24
- * } else {
25
- * console.error("An unexpected error occurred:", error);
26
- * }
27
- * }
28
- * };
29
- *
30
- * tryReadingNonExistentFile();
31
- * ```
32
- */
33
- declare class NotFoundError extends Error {
34
- /**
35
- * Creates a new instance.
36
- * @param message
37
- */
38
- constructor(message: string);
39
- get code(): string;
40
- set code(_name: string);
41
- get name(): string;
42
- set name(_name: string);
43
- }
44
- export default NotFoundError;
@@ -1,45 +0,0 @@
1
- /**
2
- * Error thrown when an operation is not permitted due to insufficient privileges
3
- * or other access control restrictions.
4
- * @example
5
- * ```javascript
6
- * import { PermissionError } from "@visulima/fs/error";
7
- * import { writeFile } from "@visulima/fs"; // Or any function that might throw this
8
- * import { join } from "node:path";
9
- *
10
- * const tryWritingToProtectedFile = async () => {
11
- * const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
12
- * try {
13
- * // Forcing the scenario for demonstration, as writeFile itself would throw this.
14
- * const simulatePermissionError = (path) => {
15
- * if (path === filePath) {
16
- * throw new PermissionError(`open '${filePath}'`);
17
- * }
18
- * }
19
- * simulatePermissionError(filePath);
20
- * // await writeFile(filePath, "test content");
21
- * } catch (error) {
22
- * if (error instanceof PermissionError) {
23
- * console.error(`Operation not permitted: ${error.message}`);
24
- * console.error(`Error code: ${error.code}`); // EPERM
25
- * } else {
26
- * console.error("An unexpected error occurred:", error);
27
- * }
28
- * }
29
- * };
30
- *
31
- * tryWritingToProtectedFile();
32
- * ```
33
- */
34
- declare class PermissionError extends Error {
35
- /**
36
- * Creates a new instance.
37
- * @param message
38
- */
39
- constructor(message: string);
40
- get code(): string;
41
- set code(_name: string);
42
- get name(): string;
43
- set name(_name: string);
44
- }
45
- export default PermissionError;
@@ -1,51 +0,0 @@
1
- /**
2
- * Error thrown in {@linkcode walk} or {@linkcode walkSync} during iteration.
3
- * @example
4
- * ```javascript
5
- * import { WalkError } from "@visulima/fs/error";
6
- * import { walk } from "@visulima/fs";
7
- * import { join } from "node:path";
8
- *
9
- * const processDirectory = async () => {
10
- * const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
11
- * try {
12
- * // Forcing the scenario: walk might throw a WalkError if it encounters an issue
13
- * // like a directory it cannot read during the walk process.
14
- * const simulateWalkError = async (rootDir) => {
15
- * // Let's say readdir inside walk fails for a subdirectory.
16
- * const underlyingError = new Error("Permission denied reading subdirectory");
17
- * throw new WalkError(underlyingError, rootDir);
18
- * }
19
- * // This is conceptual. In a real scenario, 'walk' itself would throw.
20
- * // for await (const entry of walk(dirToWalk)) {
21
- * // console.log(entry.path);
22
- * // }
23
- * await simulateWalkError(dirToWalk);
24
- * } catch (error) {
25
- * if (error instanceof WalkError) {
26
- * console.error(`Error during directory walk of "${error.root}": ${error.message}`);
27
- * if (error.cause) {
28
- * console.error(`Underlying cause: ${error.cause}`);
29
- * }
30
- * } else {
31
- * console.error("An unexpected error occurred:", error);
32
- * }
33
- * }
34
- * };
35
- *
36
- * processDirectory();
37
- * ```
38
- */
39
- declare class WalkError extends Error {
40
- /** File path of the root that's being walked. */
41
- root: string;
42
- /**
43
- * Constructs a new instance.
44
- * @param cause The underlying error or reason for the walk failure.
45
- * @param root The root directory path where the walk operation started or encountered the error.
46
- */
47
- constructor(cause: unknown, root: string);
48
- get name(): string;
49
- set name(_name: string);
50
- }
51
- export default WalkError;
@@ -1,31 +0,0 @@
1
- import type { WalkOptions } from "../types.d.ts";
2
- /**
3
- * Synchronously collects all file paths within a directory that match the specified criteria.
4
- * By default, it searches for JavaScript and TypeScript file extensions.
5
- * @param directory The root directory to start collecting files from.
6
- * @param options Optional configuration to control the collection process. See {@link WalkOptions}.
7
- * @returns An array of absolute file paths.
8
- * @example
9
- * ```javascript
10
- * import { collectSync } from "@visulima/fs";
11
- * import { join } from "node:path";
12
- *
13
- * // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
14
- * const files = collectSync(join("/tmp", "docs"), {
15
- * extensions: ["txt", "md"],
16
- * maxDepth: 2,
17
- * includeDirs: false, // Only collect files
18
- * });
19
- * console.log(files);
20
- * // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
21
- *
22
- * // Collect all .js files, excluding anything in node_modules
23
- * const jsFiles = collectSync(join("/tmp", "project"), {
24
- * extensions: ["js"],
25
- * skip: [/node_modules/],
26
- * });
27
- * console.log(jsFiles);
28
- * ```
29
- */
30
- declare const collectSync: (directory: string, options?: WalkOptions) => string[];
31
- export default collectSync;
@@ -1,35 +0,0 @@
1
- import type { WalkOptions } from "../types.d.ts";
2
- /**
3
- * Asynchronously collects all file paths within a directory that match the specified criteria.
4
- * By default, it searches for JavaScript and TypeScript file extensions.
5
- * @param directory The root directory to start collecting files from.
6
- * @param options Optional configuration to control the collection process. See {@link WalkOptions}.
7
- * @returns A promise that resolves to an array of absolute file paths.
8
- * @example
9
- * ```javascript
10
- * import { collect } from "@visulima/fs";
11
- * import { join } from "node:path";
12
- *
13
- * const collectFiles = async () => {
14
- * // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
15
- * const files = await collect(join("/tmp", "docs"), {
16
- * extensions: ["txt", "md"],
17
- * maxDepth: 2,
18
- * includeDirs: false, // Only collect files
19
- * });
20
- * console.log(files);
21
- * // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
22
- *
23
- * // Collect all .js files, excluding anything in node_modules
24
- * const jsFiles = await collect(join("/tmp", "project"), {
25
- * extensions: ["js"],
26
- * skip: [/node_modules/],
27
- * });
28
- * console.log(jsFiles);
29
- * };
30
- *
31
- * collectFiles();
32
- * ```
33
- */
34
- declare const collect: (directory: string, options?: WalkOptions) => Promise<string[]>;
35
- export default collect;
@@ -1,42 +0,0 @@
1
- import type { FindUpNameSync, FindUpOptions } from "../types.d.ts";
2
- /**
3
- * Synchronously finds a file or directory by walking up parent directories.
4
- * @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
5
- * @param options Optional configuration for the search. See {@link FindUpOptions}.
6
- * @returns The absolute path of the first found file/directory, or `undefined` if not found.
7
- * @example
8
- * ```javascript
9
- * import { findUpSync } from "@visulima/fs";
10
- * import { join } from "node:path";
11
- *
12
- * // Find the closest package.json, starting from /tmp/foo/bar/baz
13
- * const projectRoot = findUpSync("package.json", {
14
- * cwd: join("/tmp", "foo", "bar", "baz"),
15
- * type: "file",
16
- * });
17
- * console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
18
- *
19
- * // Find the closest .git directory or a README.md file
20
- * const gitDirOrReadme = findUpSync([".git", "README.md"], {
21
- * cwd: join("/tmp", "foo", "bar"),
22
- * });
23
- * console.log(gitDirOrReadme);
24
- *
25
- * // Find using a custom function, stopping at /tmp
26
- * const customFound = findUpSync(
27
- * (directory) => {
28
- * if (directory === join("/tmp", "foo")) {
29
- * return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
30
- * }
31
- * return undefined;
32
- * },
33
- * {
34
- * cwd: join("/tmp", "foo", "bar", "baz"),
35
- * stopAt: join("/tmp"),
36
- * }
37
- * );
38
- * console.log(customFound);
39
- * ```
40
- */
41
- declare const findUpSync: (name: FindUpNameSync, options?: FindUpOptions) => string | undefined;
42
- export default findUpSync;
@@ -1,46 +0,0 @@
1
- import type { FindUpName, FindUpOptions } from "../types.d.ts";
2
- /**
3
- * Asynchronously finds a file or directory by walking up parent directories.
4
- * @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
5
- * @param options Optional configuration for the search. See {@link FindUpOptions}.
6
- * @returns A promise that resolves to the absolute path of the first found file/directory, or `undefined` if not found.
7
- * @example
8
- * ```javascript
9
- * import { findUp } from "@visulima/fs";
10
- * import { join } from "node:path";
11
- *
12
- * const findProjectRoot = async () => {
13
- * // Find the closest package.json, starting from /tmp/foo/bar/baz
14
- * const projectRoot = await findUp("package.json", {
15
- * cwd: join("/tmp", "foo", "bar", "baz"),
16
- * type: "file",
17
- * });
18
- * console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
19
- *
20
- * // Find the closest .git directory or a README.md file
21
- * const gitDirOrReadme = await findUp([".git", "README.md"], {
22
- * cwd: join("/tmp", "foo", "bar"),
23
- * });
24
- * console.log(gitDirOrReadme);
25
- *
26
- * // Find using a custom function, stopping at /tmp
27
- * const customFound = await findUp(
28
- * (directory) => {
29
- * if (directory === join("/tmp", "foo")) {
30
- * return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
31
- * }
32
- * return undefined;
33
- * },
34
- * {
35
- * cwd: join("/tmp", "foo", "bar", "baz"),
36
- * stopAt: join("/tmp"),
37
- * }
38
- * );
39
- * console.log(customFound);
40
- * };
41
- *
42
- * findProjectRoot();
43
- * ```
44
- */
45
- declare const findUp: (name: FindUpName, options?: FindUpOptions) => Promise<string | undefined>;
46
- export default findUp;
@@ -1,2 +0,0 @@
1
- declare const globToRegExp: (glob: string) => RegExp;
2
- export default globToRegExp;
@@ -1,2 +0,0 @@
1
- declare const walkInclude: (path: string, extensions?: string[], match?: RegExp[], skip?: RegExp[]) => boolean;
2
- export default walkInclude;
@@ -1,34 +0,0 @@
1
- import type { WalkEntry, WalkOptions } from "../types.d.ts";
2
- /**
3
- * Synchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
4
- * This is the synchronous version of the {@linkcode walk} function.
5
- * @param directory The root directory to start walking from.
6
- * @param options Optional configuration to control the walking process. See {@link WalkOptions}.
7
- * @param options.extensions List of file extensions used to filter entries.
8
- * @param options.followSymlinks Indicates whether symlinks should be resolved or not.
9
- * @param options.includeDirs Indicates whether directory entries should be included or not.
10
- * @param options.includeFiles Indicates whether file entries should be included or not.
11
- * @param options.includeSymlinks Indicates whether symlink entries should be included or not.
12
- * @param options.match List of regular expression or glob patterns used to filter entries.
13
- * @param options.maxDepth Maximum depth to walk. Defaults to infinity.
14
- * @param options.skip List of regular expression or glob patterns used to skip entries.
15
- * @returns An iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
16
- * @example
17
- * ```javascript
18
- * import { walkSync } from "@visulima/fs";
19
- * import { join } from "node:path";
20
- *
21
- * // Walk through /tmp/my-project, looking for .ts files, max depth 2
22
- * for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
23
- * console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
24
- * }
25
- *
26
- * // Walk, including only directories, and skip any node_modules folders
27
- * for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
28
- * if (entry.isDirectory()) {
29
- * console.log(`Directory: ${entry.path}`);
30
- * }
31
- * }
32
- * ```
33
- */
34
- export default function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;
@@ -1,37 +0,0 @@
1
- import type { WalkEntry, WalkOptions } from "../types.d.ts";
2
- /**
3
- * Asynchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
4
- * @param directory The root directory to start walking from.
5
- * @param options Optional configuration to control the walking process. See {@link WalkOptions}.
6
- * @param options.extensions List of file extensions used to filter entries.
7
- * @param options.followSymlinks Indicates whether symlinks should be resolved or not.
8
- * @param options.includeDirs Indicates whether directory entries should be included or not.
9
- * @param options.includeFiles Indicates whether file entries should be included or not.
10
- * @param options.includeSymlinks Indicates whether symlink entries should be included or not.
11
- * @param options.match List of regular expression or glob patterns used to filter entries.
12
- * @param options.maxDepth Maximum depth to walk. Defaults to infinity.
13
- * @param options.skip List of regular expression or glob patterns used to skip entries.
14
- * @returns An async iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
15
- * @example
16
- * ```javascript
17
- * import { walk } from "@visulima/fs";
18
- * import { join } from "node:path";
19
- *
20
- * const printEntries = async () => {
21
- * // Walk through /tmp/my-project, looking for .ts files, max depth 2
22
- * for await (const entry of walk(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
23
- * console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
24
- * }
25
- *
26
- * // Walk, including only directories, and skip any node_modules folders
27
- * for await (const entry of walk(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
28
- * if (entry.isDirectory()) {
29
- * console.log(`Directory: ${entry.path}`);
30
- * }
31
- * }
32
- * };
33
- *
34
- * printEntries();
35
- * ```
36
- */
37
- export default function walk(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): AsyncIterableIterator<WalkEntry>;