@visulima/fs 5.0.0-alpha.9 → 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 (198) hide show
  1. package/CHANGELOG.md +459 -0
  2. package/LICENSE.md +81 -4
  3. package/README.md +65 -0
  4. package/dist/eol.d.ts +30 -0
  5. package/dist/eol.js +3 -26
  6. package/dist/error.d.ts +243 -13
  7. package/dist/error.js +1 -7
  8. package/dist/glob-parent.d.ts +30 -0
  9. package/dist/glob-parent.js +1 -90
  10. package/dist/glob.d.ts +3 -4
  11. package/dist/glob.js +1 -2
  12. package/dist/index.d.ts +877 -28
  13. package/dist/index.js +1 -38
  14. package/dist/ini.d.ts +64 -4
  15. package/dist/ini.js +1 -4
  16. package/dist/is-glob.d.ts +29 -0
  17. package/dist/is-glob.js +1 -9
  18. package/dist/json5.d.ts +28 -4
  19. package/dist/json5.js +1 -4
  20. package/dist/jsonc.d.ts +59 -4
  21. package/dist/jsonc.js +1 -4
  22. package/dist/match.d.ts +77 -2
  23. package/dist/match.js +1 -15
  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 +244 -0
  109. package/dist/size.js +1 -146
  110. package/dist/toml.d.ts +57 -3
  111. package/dist/toml.js +1 -4
  112. package/dist/utils.d.ts +92 -4
  113. package/dist/utils.js +1 -6
  114. package/dist/yaml.d.ts +3 -4
  115. package/dist/yaml.js +1 -4
  116. package/package.json +20 -23
  117. package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
  118. package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
  119. package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
  120. package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
  121. package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
  122. package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
  123. package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
  124. package/dist/packem_shared/WalkError-DER5A43G.js +0 -24
  125. package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
  126. package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
  127. package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
  128. package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +0 -12
  129. package/dist/packem_shared/collect-CqQ3eVab.js +0 -14
  130. package/dist/packem_shared/collectSync-noE08NNv.js +0 -14
  131. package/dist/packem_shared/emptyDir-DnwENOaV.js +0 -46
  132. package/dist/packem_shared/emptyDirSync-6WiHBo8a.js +0 -43
  133. package/dist/packem_shared/ensureDir-DNlPftys.js +0 -53
  134. package/dist/packem_shared/ensureDirSync-DcPZFMy5.js +0 -53
  135. package/dist/packem_shared/ensureFile-BRQpUOUM.js +0 -47
  136. package/dist/packem_shared/ensureFileSync-SBY7A9-C.js +0 -47
  137. package/dist/packem_shared/ensureLink-DJQeauEn.js +0 -55
  138. package/dist/packem_shared/ensureLinkSync-D9RVAglV.js +0 -55
  139. package/dist/packem_shared/ensureSymlink-CoRYDRwr.js +0 -80
  140. package/dist/packem_shared/ensureSymlinkSync-CFimFlgh.js +0 -81
  141. package/dist/packem_shared/findUp-YcNLKdfV.js +0 -84
  142. package/dist/packem_shared/findUpSync-BfA5fheN.js +0 -83
  143. package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
  144. package/dist/packem_shared/glob-DY8l7izD.js +0 -5
  145. package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +0 -4
  146. package/dist/packem_shared/globSync-5P2KJf_g.js +0 -5
  147. package/dist/packem_shared/index-C8W8sfzP.js +0 -830
  148. package/dist/packem_shared/index-CHM-in-V.js +0 -100
  149. package/dist/packem_shared/index-bhgnhm4u.js +0 -167
  150. package/dist/packem_shared/index-xe4o3cYi.js +0 -1784
  151. package/dist/packem_shared/indexToLineColumn-BUb0GPKl-BF770uX7.js +0 -171
  152. package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +0 -251
  153. package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
  154. package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
  155. package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
  156. package/dist/packem_shared/isFsCaseSensitive-DunL7Iry.js +0 -62
  157. package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +0 -10
  158. package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +0 -72
  159. package/dist/packem_shared/move-DbpW5_vA.js +0 -134
  160. package/dist/packem_shared/parseJson-BIp89Xjo.js +0 -63
  161. package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
  162. package/dist/packem_shared/readFileSync-gm9yfIhh.js +0 -54
  163. package/dist/packem_shared/readIni-CJ2xfpjB.js +0 -10
  164. package/dist/packem_shared/readIniSync-9LUjaSSp.js +0 -10
  165. package/dist/packem_shared/readJson-C_rwm-wq.js +0 -22
  166. package/dist/packem_shared/readJson5-mBoTZppy.js +0 -15
  167. package/dist/packem_shared/readJson5Sync-8WS2yUok.js +0 -15
  168. package/dist/packem_shared/readJsonSync-BMEmCcJ6.js +0 -22
  169. package/dist/packem_shared/readJsonc-j-OS-APg.js +0 -28
  170. package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +0 -16
  171. package/dist/packem_shared/readToml-B2MHaSes.js +0 -9
  172. package/dist/packem_shared/readTomlSync-DNbK8NEb.js +0 -9
  173. package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
  174. package/dist/packem_shared/readYamlSync-BKX-PAfq.js +0 -10
  175. package/dist/packem_shared/remove-C8_gl3jF.js +0 -39
  176. package/dist/packem_shared/removeSync-BJR_wTwN.js +0 -39
  177. package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
  178. package/dist/packem_shared/sanitize-BZoLN9Fg.js +0 -205
  179. package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
  180. package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
  181. package/dist/packem_shared/types.d-dP-lAGNn.d.ts +0 -145
  182. package/dist/packem_shared/walk-CSZgCuDx.js +0 -124
  183. package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
  184. package/dist/packem_shared/walkSync-C4Cy28xb.js +0 -123
  185. package/dist/packem_shared/writeFile-B8HX0JIQ.js +0 -81
  186. package/dist/packem_shared/writeFileSync-DB8vv8xR.js +0 -81
  187. package/dist/packem_shared/writeIni-i55QrL8y.js +0 -65
  188. package/dist/packem_shared/writeIniSync-CLqJE5t3.js +0 -64
  189. package/dist/packem_shared/writeJson-Bo7C2UHw.js +0 -50
  190. package/dist/packem_shared/writeJson5-vVmHUQOd.js +0 -53
  191. package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +0 -53
  192. package/dist/packem_shared/writeJsonSync-BKZ_9Acr.js +0 -50
  193. package/dist/packem_shared/writeJsonc-BufH_oC5.js +0 -60
  194. package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +0 -59
  195. package/dist/packem_shared/writeToml-DgTW_-7F.js +0 -8
  196. package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +0 -8
  197. package/dist/packem_shared/writeYaml-BWCOome-.js +0 -24
  198. package/dist/packem_shared/writeYamlSync-DBVnXmuY.js +0 -24
package/README.md CHANGED
@@ -66,6 +66,71 @@ pnpm add yaml
66
66
 
67
67
  ## Usage
68
68
 
69
+ ### Quickstart by subpath
70
+
71
+ `@visulima/fs` ships one entry per concern. Import from the narrowest subpath you
72
+ need so the optional parser peers (`yaml`, `smol-toml`, `jsonc-parser`, `json5`,
73
+ `ini`) stay tree-shaken.
74
+
75
+ ```typescript
76
+ // Core fs surface: walk, glob, findUp, ensure*, read/writeFile, copy, move, remove, emptyDir, isAccessible, sanitize, EOL.
77
+ import { copy, ensureDir, findUp, readFile, walk, writeFile } from "@visulima/fs";
78
+
79
+ // Typed error classes (NotFoundError, AlreadyExistsError, PermissionError, …).
80
+ import { NotFoundError } from "@visulima/fs/error";
81
+
82
+ // Parser-backed helpers — each needs its peer dependency installed.
83
+ import { readYaml, writeYaml } from "@visulima/fs/yaml";
84
+ import { readJsonc, writeJsonc } from "@visulima/fs/jsonc";
85
+
86
+ // Glob primitives and size/eol helpers.
87
+ import { glob } from "@visulima/fs/glob";
88
+ import { gzipSize } from "@visulima/fs/size";
89
+ ```
90
+
91
+ ### Copy a file or directory
92
+
93
+ ```typescript
94
+ import { copy } from "@visulima/fs";
95
+
96
+ // Copy a template directory, skipping node_modules and overwriting existing files.
97
+ await copy("templates/app", "out/app", {
98
+ filter: (source) => !source.includes("node_modules"),
99
+ });
100
+
101
+ // Refuse to overwrite an existing destination.
102
+ import { AlreadyExistsError } from "@visulima/fs/error";
103
+
104
+ try {
105
+ await copy("a.txt", "b.txt", { overwrite: false });
106
+ } catch (error) {
107
+ if (error instanceof AlreadyExistsError) {
108
+ console.error("destination already exists");
109
+ }
110
+ }
111
+ ```
112
+
113
+ ### Coming from `fs-extra`?
114
+
115
+ | `fs-extra` | `@visulima/fs` |
116
+ | ------------------------------ | ----------------------------------------------------------------------- |
117
+ | `copy` / `copySync` | `copy` / `copySync` |
118
+ | `move` / `moveSync` | `move` / `moveSync` |
119
+ | `remove` / `removeSync` | `remove` / `removeSync` (real `EACCES`/`EBUSY` errors propagate) |
120
+ | `emptyDir` / `emptyDirSync` | `emptyDir` / `emptyDirSync` |
121
+ | `ensureFile` / `ensureDir` / … | `ensureFile` / `ensureDir` / `ensureLink` / `ensureSymlink` (+ `*Sync`) |
122
+ | `readJson` / `writeJson` | `readJson` / `writeJson` (+ `*Sync`) |
123
+ | `pathExists` | `isAccessible` / `isAccessibleSync` |
124
+
125
+ > **`writeFile` notes:** `overwrite` defaults to `true`. With `overwrite: false`,
126
+ > `writeFile` throws `AlreadyExistsError` if the target exists instead of
127
+ > overwriting it. To keep a copy of the previous file before overwriting, pass
128
+ > `{ backup: true }` — the old contents are renamed to `${path}.bak`.
129
+ >
130
+ > **`readFile` errors:** a missing file throws `NotFoundError` (`ENOENT`); a file
131
+ > that cannot be read for permission reasons throws `PermissionError`
132
+ > (`EACCES`/`EPERM`).
133
+
69
134
  ## walk
70
135
 
71
136
  ```typescript
package/dist/eol.d.ts CHANGED
@@ -1,6 +1,36 @@
1
+ /** End-of-line character for POSIX platforms such as macOS and Linux. */
1
2
  declare const LF: "\n";
3
+ /** End-of-line character for Windows platforms. */
2
4
  declare const CRLF: "\r\n";
5
+ /**
6
+ * End-of-line character evaluated for the current platform.
7
+ */
3
8
  declare const EOL: "\n" | "\r\n";
9
+ /**
10
+ * Detect the EOL character for string input.
11
+ * Returns null if no newline.
12
+ * @param content The string content to detect the EOL from.
13
+ * @example
14
+ * ```javascript
15
+ * import { detect } from "@visulima/fs/eol";
16
+ *
17
+ * detect("Hello\r\nWorld"); // "\r\n"
18
+ * detect("Hello\nWorld"); // "\n"
19
+ * detect("HelloWorld"); // null
20
+ * ```
21
+ */
4
22
  declare const detect: (content: string) => typeof EOL | null;
23
+ /**
24
+ * Format the file to the targeted EOL.
25
+ * @param content The string content to format.
26
+ * @param eol The target EOL character.
27
+ * @example
28
+ * ```javascript
29
+ * import { format, LF, CRLF } from "@visulima/fs/eol";
30
+ *
31
+ * format("Hello\r\nWorld\nUnix", LF); // "Hello\nWorld\nUnix"
32
+ * format("Hello\nWorld\r\nWindows", CRLF); // "Hello\r\nWorld\r\nWindows"
33
+ * ```
34
+ */
5
35
  declare const format: (content: string, eol: typeof EOL) => string;
6
36
  export { CRLF, EOL, LF, detect, format };
package/dist/eol.js CHANGED
@@ -1,26 +1,3 @@
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 {
8
- platform
9
- } = __cjs_getProcess;
10
-
11
- const regDetect = /\r?\n/g;
12
- const LF = "\n";
13
- const CRLF = "\r\n";
14
- const EOL = platform === "win32" ? CRLF : LF;
15
- const detect = (content) => {
16
- const matched = content.match(regDetect);
17
- if (!matched || matched.length === 0) {
18
- return null;
19
- }
20
- const crlf = matched.filter((newline) => newline === CRLF).length;
21
- const lf = matched.length - crlf;
22
- return crlf > lf ? CRLF : LF;
23
- };
24
- const format = (content, eol) => content.replaceAll(regDetect, eol);
25
-
26
- export { CRLF, EOL, LF, detect, format };
1
+ import{createRequire as i}from"node:module";const u=i(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,{platform:p}=a,s=/\r?\n/g,c=`
2
+ `,r=`\r
3
+ `,_=p==="win32"?r:c,g=t=>{const e=t.match(s);if(!e||e.length===0)return null;const o=e.filter(l=>l===r).length,n=e.length-o;return o>n?r:c},h=(t,e)=>t.replaceAll(s,e);export{r as CRLF,_ as EOL,c as LF,g as detect,h as format};
package/dist/error.d.ts CHANGED
@@ -1,43 +1,273 @@
1
- export { J as JSONError } from "./packem_shared/json-error.d-DgKaeuIf.js";
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
+ */
2
29
  declare class AlreadyExistsError extends Error {
30
+ /**
31
+ * Creates a new instance.
32
+ * @param message
33
+ */
3
34
  constructor(message: string);
4
35
  get code(): string;
5
36
  set code(_name: string);
6
- get name(): string;
7
- set name(_name: string);
37
+ override get name(): string;
38
+ override set name(_name: string);
8
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
+ */
9
75
  declare class DirectoryError extends Error {
76
+ /**
77
+ * Creates a new instance.
78
+ * @param message
79
+ */
10
80
  constructor(message: string);
11
81
  get code(): string;
12
82
  set code(_name: string);
13
- get name(): string;
14
- set name(_name: string);
83
+ override get name(): string;
84
+ override set name(_name: string);
15
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
+ */
16
125
  declare class NotEmptyError extends Error {
126
+ /**
127
+ * Creates a new instance.
128
+ * @param message
129
+ */
17
130
  constructor(message: string);
18
131
  get code(): string;
19
132
  set code(_name: string);
20
- get name(): string;
21
- set name(_name: string);
133
+ override get name(): string;
134
+ override set name(_name: string);
22
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
+ */
23
168
  declare class NotFoundError extends Error {
169
+ /**
170
+ * Creates a new instance.
171
+ * @param message
172
+ */
24
173
  constructor(message: string);
25
174
  get code(): string;
26
175
  set code(_name: string);
27
- get name(): string;
28
- set name(_name: string);
176
+ override get name(): string;
177
+ override set name(_name: string);
29
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
+ */
30
212
  declare class PermissionError extends Error {
213
+ /**
214
+ * Creates a new instance.
215
+ * @param message
216
+ */
31
217
  constructor(message: string);
32
218
  get code(): string;
33
219
  set code(_name: string);
34
- get name(): string;
35
- set name(_name: string);
220
+ override get name(): string;
221
+ override set name(_name: string);
36
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
+ */
37
261
  declare class WalkError extends Error {
262
+ /** File path of the root that's being walked. */
38
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
+ */
39
269
  constructor(cause: unknown, root: string);
40
- get name(): string;
41
- set name(_name: string);
270
+ override get name(): string;
271
+ override set name(_name: string);
42
272
  }
43
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};
@@ -1,5 +1,35 @@
1
+ /**
2
+ * Options accepted by {@link globParent}.
3
+ */
1
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
+ */
2
11
  flipBackslashes?: boolean;
3
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
+ */
4
34
  declare const globParent: (pattern: string, options?: GlobParentOptions) => string;
5
35
  export { type GlobParentOptions, globParent as default };
@@ -1,90 +1 @@
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
- import { g as getDefaultExportFromCjs } from './packem_shared/_commonjsHelpers-BqLXS_qQ.js';
21
- import { r as requireIsGlob } from './packem_shared/index-bhgnhm4u.js';
22
- const require$$1 = __cjs_getBuiltinModule("path");
23
- const require$$2 = __cjs_getBuiltinModule("os");
24
-
25
- var globParent$1;
26
- var hasRequiredGlobParent;
27
-
28
- function requireGlobParent () {
29
- if (hasRequiredGlobParent) return globParent$1;
30
- hasRequiredGlobParent = 1;
31
- var isGlob = requireIsGlob();
32
- var pathPosixDirname = require$$1.posix.dirname;
33
- var isWin32 = require$$2.platform() === "win32";
34
- var slash = "/";
35
- var backslash = /\\/g;
36
- var escaped = /\\([!*?|[\](){}])/g;
37
- globParent$1 = function globParent(str, opts) {
38
- var options = Object.assign({ flipBackslashes: true }, opts);
39
- if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
40
- str = str.replace(backslash, slash);
41
- }
42
- if (isEnclosure(str)) {
43
- str += slash;
44
- }
45
- str += "a";
46
- do {
47
- str = pathPosixDirname(str);
48
- } while (isGlobby(str));
49
- return str.replace(escaped, "$1");
50
- };
51
- function isEnclosure(str) {
52
- var lastChar = str.slice(-1);
53
- var enclosureStart;
54
- switch (lastChar) {
55
- case "}":
56
- enclosureStart = "{";
57
- break;
58
- case "]":
59
- enclosureStart = "[";
60
- break;
61
- default:
62
- return false;
63
- }
64
- var foundIndex = str.indexOf(enclosureStart);
65
- if (foundIndex < 0) {
66
- return false;
67
- }
68
- return str.slice(foundIndex + 1, -1).includes(slash);
69
- }
70
- function isGlobby(str) {
71
- if (/\([^()]+$/.test(str)) {
72
- return true;
73
- }
74
- if (str[0] === "{" || str[0] === "[") {
75
- return true;
76
- }
77
- if (/[^\\][{[]/.test(str)) {
78
- return true;
79
- }
80
- return isGlob(str);
81
- }
82
- return globParent$1;
83
- }
84
-
85
- var globParentExports = requireGlobParent();
86
- const globParentImpl = /*@__PURE__*/getDefaultExportFromCjs(globParentExports);
87
-
88
- const globParent = (pattern, options) => globParentImpl(pattern, options);
89
-
90
- export { globParent as default };
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 CHANGED
@@ -1,5 +1,4 @@
1
- export { g as glob, a as globSync } from "./packem_shared/glob-sync.d-B83kqwUd.js";
2
- export { type G as GlobOptions } from "./packem_shared/types.d-dP-lAGNn.js";
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
3
  import 'node:fs';
4
- import 'tinyglobby';
5
- import './options';
4
+ import 'fdir';
package/dist/glob.js CHANGED
@@ -1,2 +1 @@
1
- export { default as glob } from './packem_shared/glob-DY8l7izD.js';
2
- export { default as globSync } from './packem_shared/globSync-5P2KJf_g.js';
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};