@visulima/fs 5.0.0-alpha.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.md +491 -0
  2. package/LICENSE.md +236 -5
  3. package/README.md +65 -0
  4. package/dist/eol.d.ts +31 -30
  5. package/dist/eol.js +3 -26
  6. package/dist/error.d.ts +273 -7
  7. package/dist/error.js +1 -7
  8. package/dist/glob-parent.d.ts +35 -0
  9. package/dist/glob-parent.js +1 -0
  10. package/dist/glob.d.ts +4 -0
  11. package/dist/glob.js +1 -0
  12. package/dist/index.d.ts +930 -36
  13. package/dist/index.js +1 -33
  14. package/dist/ini.d.ts +70 -0
  15. package/dist/ini.js +1 -0
  16. package/dist/is-glob.d.ts +34 -0
  17. package/dist/is-glob.js +1 -0
  18. package/dist/json5.d.ts +36 -0
  19. package/dist/json5.js +1 -0
  20. package/dist/jsonc.d.ts +65 -0
  21. package/dist/jsonc.js +1 -0
  22. package/dist/match.d.ts +80 -0
  23. package/dist/match.js +1 -0
  24. package/dist/packem_shared/AlreadyExistsError-DEb3UWja.js +1 -0
  25. package/dist/packem_shared/DirectoryError-BtwSTLmT.js +1 -0
  26. package/dist/packem_shared/FIND_UP_STOP-CAwY1qU7.js +1 -0
  27. package/dist/packem_shared/JSONError-Cvp9ycba.js +4 -0
  28. package/dist/packem_shared/NotEmptyError-DZ1Ix089.js +1 -0
  29. package/dist/packem_shared/NotFoundError-CnRY6lVp.js +1 -0
  30. package/dist/packem_shared/PermissionError-DJ_2VWEj.js +1 -0
  31. package/dist/packem_shared/WalkError-B8qTd-v-.js +1 -0
  32. package/dist/packem_shared/_commonjsHelpers-CWAkuNXM.js +1 -0
  33. package/dist/packem_shared/assertValidFileContents-CbIN7sy7.js +1 -0
  34. package/dist/packem_shared/assertValidFileOrDirectoryPath-BTlt945W.js +1 -0
  35. package/dist/packem_shared/build-rm-options-avnusYx-.js +1 -0
  36. package/dist/packem_shared/collect-CIKDOMiD.js +1 -0
  37. package/dist/packem_shared/collectSync-D0FRLLqg.js +1 -0
  38. package/dist/packem_shared/copy-Beb64BYG.js +1 -0
  39. package/dist/packem_shared/copySync-CagcIEBi.js +1 -0
  40. package/dist/packem_shared/emptyDir-C7lyd1lW.js +1 -0
  41. package/dist/packem_shared/emptyDirSync-B8EYpmO9.js +1 -0
  42. package/dist/packem_shared/ensureDir-DGarVZw8.js +1 -0
  43. package/dist/packem_shared/ensureDirSync-CsgPrsDH.js +1 -0
  44. package/dist/packem_shared/ensureFile-CMugWljp.js +1 -0
  45. package/dist/packem_shared/ensureFileSync-CJYTEx2r.js +1 -0
  46. package/dist/packem_shared/ensureLink-ChShf3lf.js +1 -0
  47. package/dist/packem_shared/ensureLinkSync-DPpq0I2Z.js +1 -0
  48. package/dist/packem_shared/ensureSymlink-y4FZjfxA.js +1 -0
  49. package/dist/packem_shared/ensureSymlinkSync-TcHssCH7.js +1 -0
  50. package/dist/packem_shared/findUp-Cii5ATt5.js +1 -0
  51. package/dist/packem_shared/findUpSync-C9Lkh7-v.js +1 -0
  52. package/dist/packem_shared/get-file-info-type-DzWpohDB.js +1 -0
  53. package/dist/packem_shared/glob-fqg4KepW.js +1 -0
  54. package/dist/packem_shared/glob-sync.d-hXe38TnZ.d.ts +54 -0
  55. package/dist/packem_shared/globSync-B8_ne93E.js +1 -0
  56. package/dist/packem_shared/index-B2MhYg3r.js +1 -0
  57. package/dist/packem_shared/index-BHy3Kcr7.js +11 -0
  58. package/dist/packem_shared/index-BLg3XWiD.js +1 -0
  59. package/dist/packem_shared/index-D8MDd0tv.js +1 -0
  60. package/dist/packem_shared/ini-preserve-D1DopDLd.js +4 -0
  61. package/dist/packem_shared/is-stats-identical-l1GRN4Qu.js +1 -0
  62. package/dist/packem_shared/isAccessible-PmWJhV6I.js +1 -0
  63. package/dist/packem_shared/isAccessibleSync-BrbOtwdr.js +1 -0
  64. package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +52 -0
  65. package/dist/packem_shared/jsonc-merge-Bkw73TLW.js +2 -0
  66. package/dist/packem_shared/map-read-error-CR3rQUxx.js +1 -0
  67. package/dist/packem_shared/move-DopmzT-2.js +1 -0
  68. package/dist/packem_shared/parseJson-EASgP4J9.js +1 -0
  69. package/dist/packem_shared/readFile-BswaBgM0.js +1 -0
  70. package/dist/packem_shared/readFileSync-_fDF6Oj1.js +1 -0
  71. package/dist/packem_shared/readIni-BsXudu2r.js +1 -0
  72. package/dist/packem_shared/readIniSync-DKwRbbs9.js +1 -0
  73. package/dist/packem_shared/readJson-CcAsHxE5.js +1 -0
  74. package/dist/packem_shared/readJson5-CM1TIiHd.js +1 -0
  75. package/dist/packem_shared/readJson5Sync-Bc26c3Fy.js +1 -0
  76. package/dist/packem_shared/readJsonSync-DuMMeB3s.js +1 -0
  77. package/dist/packem_shared/readJsonc-BZjMw_0f.js +1 -0
  78. package/dist/packem_shared/readJsoncSync-C-xzeZz4.js +1 -0
  79. package/dist/packem_shared/readToml-D4jpe9q_.js +1 -0
  80. package/dist/packem_shared/readTomlSync-B5PIYT9z.js +1 -0
  81. package/dist/packem_shared/readYaml-DvPxndW_.js +1 -0
  82. package/dist/packem_shared/readYamlSync-DZ-0hSbZ.js +1 -0
  83. package/dist/packem_shared/remove-CSbrd0dl.js +1 -0
  84. package/dist/packem_shared/removeSync-BoLAzRQE.js +1 -0
  85. package/dist/packem_shared/renderError-B3ePOoBG-Bi9WKMjv.js +6 -0
  86. package/dist/packem_shared/resolve-symlink-target-CWrn0v4P.js +1 -0
  87. package/dist/packem_shared/sanitize-DGZ3w-_w.js +1 -0
  88. package/dist/packem_shared/stripJsonComments-Bfcn2PKv.js +1 -0
  89. package/dist/packem_shared/to-uint-8-array-BImOQNXm.js +1 -0
  90. package/dist/packem_shared/types.d-BMdL_ygj.d.ts +1773 -0
  91. package/dist/packem_shared/walk-OX4-6oCP.js +1 -0
  92. package/dist/packem_shared/walk-include-BXhGSn6t.js +1 -0
  93. package/dist/packem_shared/walkSync-BPs6czIM.js +1 -0
  94. package/dist/packem_shared/writeFile-BrMtsJY7.js +1 -0
  95. package/dist/packem_shared/writeFileSync-W7Mf4BNy.js +1 -0
  96. package/dist/packem_shared/writeIni-BWX3cP1K.js +4 -0
  97. package/dist/packem_shared/writeIniSync-fOdgPFfL.js +4 -0
  98. package/dist/packem_shared/writeJson-bEVi25gX.js +4 -0
  99. package/dist/packem_shared/writeJson5-Ch8TpNPI.js +4 -0
  100. package/dist/packem_shared/writeJson5Sync-BrctV_Mk.js +4 -0
  101. package/dist/packem_shared/writeJsonSync-DkGnd416.js +4 -0
  102. package/dist/packem_shared/writeJsonc-CefrwsOc.js +4 -0
  103. package/dist/packem_shared/writeJsoncSync-BskDjn8o.js +4 -0
  104. package/dist/packem_shared/writeToml-IuMO-yDu.js +1 -0
  105. package/dist/packem_shared/writeTomlSync-DhL7hHzB.js +1 -0
  106. package/dist/packem_shared/writeYaml-ClQgvQID.js +1 -0
  107. package/dist/packem_shared/writeYamlSync-DrXtHQQq.js +1 -0
  108. package/dist/size.d.ts +246 -246
  109. package/dist/size.js +1 -146
  110. package/dist/toml.d.ts +63 -0
  111. package/dist/toml.js +1 -0
  112. package/dist/utils.d.ts +103 -6
  113. package/dist/utils.js +1 -6
  114. package/dist/yaml.d.ts +13 -5
  115. package/dist/yaml.js +1 -4
  116. package/package.json +68 -17
  117. package/dist/constants.d.ts +0 -42
  118. package/dist/ensure/ensure-dir-sync.d.ts +0 -14
  119. package/dist/ensure/ensure-dir.d.ts +0 -14
  120. package/dist/ensure/ensure-file-sync.d.ts +0 -15
  121. package/dist/ensure/ensure-file.d.ts +0 -27
  122. package/dist/ensure/ensure-link-sync.d.ts +0 -16
  123. package/dist/ensure/ensure-link.d.ts +0 -16
  124. package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
  125. package/dist/ensure/ensure-symlink.d.ts +0 -23
  126. package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
  127. package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
  128. package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
  129. package/dist/error/already-exists-error.d.ts +0 -39
  130. package/dist/error/directory-error.d.ts +0 -47
  131. package/dist/error/json-error.d.ts +0 -52
  132. package/dist/error/not-empty-error.d.ts +0 -51
  133. package/dist/error/not-found-error.d.ts +0 -44
  134. package/dist/error/permission-error.d.ts +0 -45
  135. package/dist/error/walk-error.d.ts +0 -51
  136. package/dist/find/collect-sync.d.ts +0 -31
  137. package/dist/find/collect.d.ts +0 -35
  138. package/dist/find/find-up-sync.d.ts +0 -42
  139. package/dist/find/find-up.d.ts +0 -46
  140. package/dist/find/utils/glob-to-regexp.d.ts +0 -2
  141. package/dist/find/utils/walk-include.d.ts +0 -2
  142. package/dist/find/walk-sync.d.ts +0 -34
  143. package/dist/find/walk.d.ts +0 -37
  144. package/dist/is-accessible-sync.d.ts +0 -3
  145. package/dist/is-accessible.d.ts +0 -29
  146. package/dist/move/index.d.ts +0 -68
  147. package/dist/move/types.d.ts +0 -36
  148. package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
  149. package/dist/move/utils/internal-move-file.d.ts +0 -3
  150. package/dist/move/utils/validate-same-directory.d.ts +0 -2
  151. package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
  152. package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
  153. package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
  154. package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
  155. package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
  156. package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
  157. package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
  158. package/dist/packem_shared/WalkError-DER5A43G.js +0 -24
  159. package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
  160. package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
  161. package/dist/packem_shared/collect-CqQ3eVab.js +0 -14
  162. package/dist/packem_shared/collectSync-noE08NNv.js +0 -14
  163. package/dist/packem_shared/emptyDir-Df4Tfjtk.js +0 -44
  164. package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +0 -41
  165. package/dist/packem_shared/ensureDir-DNlPftys.js +0 -53
  166. package/dist/packem_shared/ensureDirSync-DcPZFMy5.js +0 -53
  167. package/dist/packem_shared/ensureFile-BRQpUOUM.js +0 -47
  168. package/dist/packem_shared/ensureFileSync-SBY7A9-C.js +0 -47
  169. package/dist/packem_shared/ensureLink-DJQeauEn.js +0 -55
  170. package/dist/packem_shared/ensureLinkSync-D9RVAglV.js +0 -55
  171. package/dist/packem_shared/ensureSymlink-CoRYDRwr.js +0 -80
  172. package/dist/packem_shared/ensureSymlinkSync-CFimFlgh.js +0 -81
  173. package/dist/packem_shared/findUp-YcNLKdfV.js +0 -84
  174. package/dist/packem_shared/findUpSync-BfA5fheN.js +0 -83
  175. package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
  176. package/dist/packem_shared/index-CHM-in-V.js +0 -100
  177. package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
  178. package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
  179. package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
  180. package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +0 -62
  181. package/dist/packem_shared/move-DbpW5_vA.js +0 -134
  182. package/dist/packem_shared/parseJson-BedVi91S.js +0 -232
  183. package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
  184. package/dist/packem_shared/readFileSync-gm9yfIhh.js +0 -54
  185. package/dist/packem_shared/readJson-D0G0ndHL.js +0 -22
  186. package/dist/packem_shared/readJsonSync-B7oicPaL.js +0 -22
  187. package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
  188. package/dist/packem_shared/readYamlSync-BKX-PAfq.js +0 -10
  189. package/dist/packem_shared/remove-CNkjFFkQ.js +0 -38
  190. package/dist/packem_shared/removeSync-AnawYpPv.js +0 -38
  191. package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
  192. package/dist/packem_shared/sanitize-BZoLN9Fg.js +0 -205
  193. package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
  194. package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
  195. package/dist/packem_shared/walk-CSZgCuDx.js +0 -124
  196. package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
  197. package/dist/packem_shared/walkSync-C4Cy28xb.js +0 -123
  198. package/dist/packem_shared/writeFile-B8HX0JIQ.js +0 -81
  199. package/dist/packem_shared/writeFileSync-DB8vv8xR.js +0 -81
  200. package/dist/packem_shared/writeJson-Bo7C2UHw.js +0 -50
  201. package/dist/packem_shared/writeJsonSync-BKZ_9Acr.js +0 -50
  202. package/dist/packem_shared/writeYaml-BWCOome-.js +0 -24
  203. package/dist/packem_shared/writeYamlSync-DBVnXmuY.js +0 -24
  204. package/dist/read/read-file-sync.d.ts +0 -37
  205. package/dist/read/read-file.d.ts +0 -41
  206. package/dist/read/read-json-sync.d.ts +0 -5
  207. package/dist/read/read-json.d.ts +0 -5
  208. package/dist/read/read-yaml-sync.d.ts +0 -4
  209. package/dist/read/read-yaml.d.ts +0 -4
  210. package/dist/remove/empty-dir-sync.d.ts +0 -23
  211. package/dist/remove/empty-dir.d.ts +0 -28
  212. package/dist/remove/remove-sync.d.ts +0 -27
  213. package/dist/remove/remove.d.ts +0 -32
  214. package/dist/sanitize.d.ts +0 -31
  215. package/dist/types.d.ts +0 -304
  216. package/dist/utils/assert-valid-file-contents.d.ts +0 -27
  217. package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
  218. package/dist/utils/parse-json.d.ts +0 -5
  219. package/dist/utils/strip-json-comments.d.ts +0 -44
  220. package/dist/write/utils/to-uint-8-array.d.ts +0 -2
  221. package/dist/write/write-file-sync.d.ts +0 -30
  222. package/dist/write/write-file.d.ts +0 -30
  223. package/dist/write/write-json-sync.d.ts +0 -29
  224. package/dist/write/write-json.d.ts +0 -30
  225. package/dist/write/write-yaml-sync.d.ts +0 -4
  226. package/dist/write/write-yaml.d.ts +0 -4
package/dist/error.d.ts CHANGED
@@ -1,7 +1,273 @@
1
- export { default as AlreadyExistsError } from "./error/already-exists-error.d.ts";
2
- export { default as DirectoryError } from "./error/directory-error.d.ts";
3
- export { default as JSONError } from "./error/json-error.d.ts";
4
- export { default as NotEmptyError } from "./error/not-empty-error.d.ts";
5
- export { default as NotFoundError } from "./error/not-found-error.d.ts";
6
- export { default as PermissionError } from "./error/permission-error.d.ts";
7
- export { default as WalkError } from "./error/walk-error.d.ts";
1
+ export { J as JSONError } from "./packem_shared/json-error.d-DVILOyHc.js";
2
+ /**
3
+ * Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
4
+ * @example
5
+ * ```javascript
6
+ * import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly
7
+ * import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this
8
+ * import { join } from "node:path";
9
+ *
10
+ * try {
11
+ * // Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
12
+ * // For demonstration, let's assume someFunction internally throws it:
13
+ * const someFunctionThatMightThrow = (path) => {
14
+ * if (path === "/tmp/existing-file.txt") { // Simulate a check
15
+ * throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
16
+ * }
17
+ * }
18
+ * someFunctionThatMightThrow("/tmp/existing-file.txt");
19
+ * } catch (error) {
20
+ * if (error instanceof AlreadyExistsError) {
21
+ * console.error(`Operation failed because path exists: ${error.message}`);
22
+ * console.error(`Error code: ${error.code}`); // EEXIST
23
+ * } else {
24
+ * console.error("An unexpected error occurred:", error);
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ declare class AlreadyExistsError extends Error {
30
+ /**
31
+ * Creates a new instance.
32
+ * @param message
33
+ */
34
+ constructor(message: string);
35
+ get code(): string;
36
+ set code(_name: string);
37
+ override get name(): string;
38
+ override set name(_name: string);
39
+ }
40
+ /**
41
+ * Error thrown when an operation that is not allowed on a directory is attempted.
42
+ * This typically occurs when a file-specific operation is used on a directory path.
43
+ * @example
44
+ * ```javascript
45
+ * import { DirectoryError } from "@visulima/fs/error";
46
+ * import { readFile } from "@visulima/fs"; // Or any function that might throw this
47
+ * import { join } from "node:path";
48
+ *
49
+ * const attemptToReadFileFromDir = async () => {
50
+ * try {
51
+ * // Attempting to read a directory as if it were a file
52
+ * // This is a conceptual example; readFile might throw a different error first
53
+ * // depending on its internal checks, but EISDIR is the underlying system error.
54
+ * // Forcing the scenario:
55
+ * const pretendReadFileOnDir = (path) => {
56
+ * if (path === "/tmp/my-directory") { // Simulate a directory path
57
+ * throw new DirectoryError(`read '/tmp/my-directory'`);
58
+ * }
59
+ * }
60
+ * pretendReadFileOnDir("/tmp/my-directory");
61
+ * // await readFile(join("/tmp", "my-directory"));
62
+ * } catch (error) {
63
+ * if (error instanceof DirectoryError) {
64
+ * console.error(`Operation failed, path is a directory: ${error.message}`);
65
+ * console.error(`Error code: ${error.code}`); // EISDIR
66
+ * } else {
67
+ * console.error("An unexpected error occurred:", error);
68
+ * }
69
+ * }
70
+ * };
71
+ *
72
+ * attemptToReadFileFromDir();
73
+ * ```
74
+ */
75
+ declare class DirectoryError extends Error {
76
+ /**
77
+ * Creates a new instance.
78
+ * @param message
79
+ */
80
+ constructor(message: string);
81
+ get code(): string;
82
+ set code(_name: string);
83
+ override get name(): string;
84
+ override set name(_name: string);
85
+ }
86
+ /**
87
+ * Error thrown when a directory is not empty.
88
+ * @example
89
+ * ```javascript
90
+ * import { NotEmptyError } from "@visulima/fs/error";
91
+ * import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error
92
+ * import { join } from "node:path";
93
+ *
94
+ * const attemptToRemoveNonEmptyDir = async () => {
95
+ * const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
96
+ * try {
97
+ * // Forcing the scenario for demonstration, as rmdir might throw its own specific error.
98
+ * // Node.js fs operations that encounter a non-empty directory when expecting an empty one
99
+ * // typically throw an error with code ENOTEMPTY.
100
+ * const simulateNotEmpty = (path) => {
101
+ * if (path === dirPath) { // Simulate check for non-empty
102
+ * throw new NotEmptyError(`rmdir '${dirPath}'`);
103
+ * }
104
+ * }
105
+ * simulateNotEmpty(dirPath);
106
+ * // await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
107
+ * } catch (error) {
108
+ * if (error instanceof NotEmptyError) {
109
+ * console.error(`Operation failed, directory is not empty: ${error.message}`);
110
+ * console.error(`Error code: ${error.code}`); // ENOTEMPTY
111
+ * } else {
112
+ * console.error("An unexpected error occurred:", error);
113
+ * }
114
+ * }
115
+ * };
116
+ *
117
+ * // You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
118
+ * // import { ensureDirSync, writeFileSync } from "@visulima/fs";
119
+ * // ensureDirSync(dirPath);
120
+ * // writeFileSync(join(dirPath, "somefile.txt"), "content");
121
+ *
122
+ * attemptToRemoveNonEmptyDir();
123
+ * ```
124
+ */
125
+ declare class NotEmptyError extends Error {
126
+ /**
127
+ * Creates a new instance.
128
+ * @param message
129
+ */
130
+ constructor(message: string);
131
+ get code(): string;
132
+ set code(_name: string);
133
+ override get name(): string;
134
+ override set name(_name: string);
135
+ }
136
+ /**
137
+ * Error thrown when a file or directory is not found at a specified path.
138
+ * @example
139
+ * ```javascript
140
+ * import { NotFoundError } from "@visulima/fs/error";
141
+ * import { readFile } from "@visulima/fs"; // Or any function that might throw this
142
+ * import { join } from "node:path";
143
+ *
144
+ * const tryReadingNonExistentFile = async () => {
145
+ * const filePath = join("/tmp", "this-file-does-not-exist.txt");
146
+ * try {
147
+ * // Forcing the scenario for demonstration, as readFile itself would throw this.
148
+ * const simulateNotFound = (path) => {
149
+ * if (path === filePath) {
150
+ * throw new NotFoundError(`no such file or directory, open '${filePath}'`);
151
+ * }
152
+ * }
153
+ * simulateNotFound(filePath);
154
+ * // await readFile(filePath);
155
+ * } catch (error) {
156
+ * if (error instanceof NotFoundError) {
157
+ * console.error(`Operation failed, path not found: ${error.message}`);
158
+ * console.error(`Error code: ${error.code}`); // ENOENT
159
+ * } else {
160
+ * console.error("An unexpected error occurred:", error);
161
+ * }
162
+ * }
163
+ * };
164
+ *
165
+ * tryReadingNonExistentFile();
166
+ * ```
167
+ */
168
+ declare class NotFoundError extends Error {
169
+ /**
170
+ * Creates a new instance.
171
+ * @param message
172
+ */
173
+ constructor(message: string);
174
+ get code(): string;
175
+ set code(_name: string);
176
+ override get name(): string;
177
+ override set name(_name: string);
178
+ }
179
+ /**
180
+ * Error thrown when an operation is not permitted due to insufficient privileges
181
+ * or other access control restrictions.
182
+ * @example
183
+ * ```javascript
184
+ * import { PermissionError } from "@visulima/fs/error";
185
+ * import { writeFile } from "@visulima/fs"; // Or any function that might throw this
186
+ * import { join } from "node:path";
187
+ *
188
+ * const tryWritingToProtectedFile = async () => {
189
+ * const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
190
+ * try {
191
+ * // Forcing the scenario for demonstration, as writeFile itself would throw this.
192
+ * const simulatePermissionError = (path) => {
193
+ * if (path === filePath) {
194
+ * throw new PermissionError(`open '${filePath}'`);
195
+ * }
196
+ * }
197
+ * simulatePermissionError(filePath);
198
+ * // await writeFile(filePath, "test content");
199
+ * } catch (error) {
200
+ * if (error instanceof PermissionError) {
201
+ * console.error(`Operation not permitted: ${error.message}`);
202
+ * console.error(`Error code: ${error.code}`); // EPERM
203
+ * } else {
204
+ * console.error("An unexpected error occurred:", error);
205
+ * }
206
+ * }
207
+ * };
208
+ *
209
+ * tryWritingToProtectedFile();
210
+ * ```
211
+ */
212
+ declare class PermissionError extends Error {
213
+ /**
214
+ * Creates a new instance.
215
+ * @param message
216
+ */
217
+ constructor(message: string);
218
+ get code(): string;
219
+ set code(_name: string);
220
+ override get name(): string;
221
+ override set name(_name: string);
222
+ }
223
+ /**
224
+ * Error thrown in walk or walkSync during iteration.
225
+ * @example
226
+ * ```javascript
227
+ * import { WalkError } from "@visulima/fs/error";
228
+ * import { walk } from "@visulima/fs";
229
+ * import { join } from "node:path";
230
+ *
231
+ * const processDirectory = async () => {
232
+ * const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
233
+ * try {
234
+ * // Forcing the scenario: walk might throw a WalkError if it encounters an issue
235
+ * // like a directory it cannot read during the walk process.
236
+ * const simulateWalkError = async (rootDir) => {
237
+ * // Let's say readdir inside walk fails for a subdirectory.
238
+ * const underlyingError = new Error("Permission denied reading subdirectory");
239
+ * throw new WalkError(underlyingError, rootDir);
240
+ * }
241
+ * // This is conceptual. In a real scenario, 'walk' itself would throw.
242
+ * // for await (const entry of walk(dirToWalk)) {
243
+ * // console.log(entry.path);
244
+ * // }
245
+ * await simulateWalkError(dirToWalk);
246
+ * } catch (error) {
247
+ * if (error instanceof WalkError) {
248
+ * console.error(`Error during directory walk of "${error.root}": ${error.message}`);
249
+ * if (error.cause) {
250
+ * console.error(`Underlying cause: ${error.cause}`);
251
+ * }
252
+ * } else {
253
+ * console.error("An unexpected error occurred:", error);
254
+ * }
255
+ * }
256
+ * };
257
+ *
258
+ * processDirectory();
259
+ * ```
260
+ */
261
+ declare class WalkError extends Error {
262
+ /** File path of the root that's being walked. */
263
+ root: string;
264
+ /**
265
+ * Constructs a new instance.
266
+ * @param cause The underlying error or reason for the walk failure.
267
+ * @param root The root directory path where the walk operation started or encountered the error.
268
+ */
269
+ constructor(cause: unknown, root: string);
270
+ override get name(): string;
271
+ override set name(_name: string);
272
+ }
273
+ export { AlreadyExistsError, DirectoryError, NotEmptyError, NotFoundError, PermissionError, WalkError };
package/dist/error.js CHANGED
@@ -1,7 +1 @@
1
- export { default as AlreadyExistsError } from './packem_shared/AlreadyExistsError-6Y9hjgMn.js';
2
- export { default as DirectoryError } from './packem_shared/DirectoryError-BfYPkIYP.js';
3
- export { default as JSONError } from './packem_shared/JSONError-BkHRnInH.js';
4
- export { default as NotEmptyError } from './packem_shared/NotEmptyError-B21RUlVr.js';
5
- export { default as NotFoundError } from './packem_shared/NotFoundError-BIp61X6k.js';
6
- export { default as PermissionError } from './packem_shared/PermissionError-CjoiJgip.js';
7
- export { default as WalkError } from './packem_shared/WalkError-DER5A43G.js';
1
+ import{default as t}from"./packem_shared/AlreadyExistsError-DEb3UWja.js";import{default as a}from"./packem_shared/DirectoryError-BtwSTLmT.js";import{default as s}from"./packem_shared/JSONError-Cvp9ycba.js";import{default as l}from"./packem_shared/NotEmptyError-DZ1Ix089.js";import{default as E}from"./packem_shared/NotFoundError-CnRY6lVp.js";import{default as u}from"./packem_shared/PermissionError-DJ_2VWEj.js";import{default as i}from"./packem_shared/WalkError-B8qTd-v-.js";export{t as AlreadyExistsError,a as DirectoryError,s as JSONError,l as NotEmptyError,E as NotFoundError,u as PermissionError,i as WalkError};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Options accepted by {@link globParent}.
3
+ */
4
+ interface GlobParentOptions {
5
+ /**
6
+ * On Windows, flip backslashes to forward slashes before analysing the pattern.
7
+ *
8
+ * Disable when the input contains backslash escape sequences you want to preserve.
9
+ * @default true
10
+ */
11
+ flipBackslashes?: boolean;
12
+ }
13
+ /**
14
+ * Extracts the non-glob parent directory from a glob pattern.
15
+ *
16
+ * Useful when you need to know which directory to watch or walk for a given pattern — for example
17
+ * `src/**\/*.ts` → `src`, `foo/{a,b}/*.js` → `foo`. Patterns without glob characters are returned
18
+ * unchanged.
19
+ *
20
+ * Powered by [`glob-parent`](https://github.com/gulpjs/glob-parent) which is bundled into the built output so
21
+ * it does not appear as a runtime dependency of `@visulima/fs`.
22
+ * @param pattern The glob pattern to inspect.
23
+ * @param options Optional configuration. See {@link GlobParentOptions}.
24
+ * @returns The static parent path of the glob.
25
+ * @example
26
+ * ```javascript
27
+ * import { globParent } from "@visulima/fs";
28
+ *
29
+ * globParent("src/**\/*.ts"); // "src"
30
+ * globParent("foo/{a,b}/*.js"); // "foo"
31
+ * globParent("foo/bar.js"); // "foo/bar.js"
32
+ * ```
33
+ */
34
+ declare const globParent: (pattern: string, options?: GlobParentOptions) => string;
35
+ export { type GlobParentOptions, globParent as default };
@@ -0,0 +1 @@
1
+ import{createRequire as g}from"node:module";import{g as _}from"./packem_shared/_commonjsHelpers-CWAkuNXM.js";import{r as v}from"./packem_shared/index-BHy3Kcr7.js";const h=g(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=s=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[r,o]=i.versions.node.split(".").map(Number);if(r>22||r===22&&o>=3||r===20&&o>=16)return i.getBuiltinModule(s)}return h(s)},q=f("path"),j=f("os");var l,u;function x(){if(u)return l;u=1;var s=v(),r=q.posix.dirname,o=j.platform()==="win32",n="/",p=/\\/g,d=/\\([!*?|[\](){}])/g;l=function(e,a){var t=Object.assign({flipBackslashes:!0},a);t.flipBackslashes&&o&&e.indexOf(n)<0&&(e=e.replace(p,n)),b(e)&&(e+=n),e+="a";do e=r(e);while(m(e));return e.replace(d,"$1")};function b(e){var a=e.slice(-1),t;switch(a){case"}":t="{";break;case"]":t="[";break;default:return!1}var c=e.indexOf(t);return c<0?!1:e.slice(c+1,-1).includes(n)}function m(e){return/\([^()]+$/.test(e)||e[0]==="{"||e[0]==="["||/[^\\][{[]/.test(e)?!0:s(e)}return l}var P=x();const $=_(P),B=(s,r)=>$(s,r);export{B as default};
package/dist/glob.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { g as glob, a as globSync } from "./packem_shared/glob-sync.d-hXe38TnZ.js";
2
+ export type { G as GlobOptions } from "./packem_shared/types.d-BMdL_ygj.js";
3
+ import 'node:fs';
4
+ import 'fdir';
package/dist/glob.js ADDED
@@ -0,0 +1 @@
1
+ import{default as e}from"./packem_shared/glob-fqg4KepW.js";import{default as l}from"./packem_shared/globSync-B8_ne93E.js";export{e as glob,l as globSync};