@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
@@ -1,38 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- unlink,
22
- rm
23
- } = __cjs_getBuiltinModule("node:fs/promises");
24
- import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
25
-
26
- const remove = async (path, options = {}) => {
27
- assertValidFileOrDirectoryPath(path);
28
- try {
29
- await unlink(path);
30
- } catch {
31
- }
32
- try {
33
- await rm(path, { force: true, maxRetries: options.maxRetries, recursive: true, retryDelay: options.retryDelay });
34
- } catch {
35
- }
36
- };
37
-
38
- export { remove as default };
@@ -1,38 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- unlinkSync,
22
- rmSync
23
- } = __cjs_getBuiltinModule("node:fs");
24
- import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
25
-
26
- const removeSync = (path, options = {}) => {
27
- assertValidFileOrDirectoryPath(path);
28
- try {
29
- unlinkSync(path);
30
- } catch {
31
- }
32
- try {
33
- rmSync(path, { force: true, maxRetries: options.maxRetries, recursive: true, retryDelay: options.retryDelay });
34
- } catch {
35
- }
36
- };
37
-
38
- export { removeSync as default };
@@ -1,16 +0,0 @@
1
- import { resolve, dirname } from '@visulima/path';
2
-
3
- const resolveSymlinkTarget = (target, linkName) => {
4
- if (typeof target !== "string") {
5
- return target;
6
- }
7
- if (target.startsWith("./")) {
8
- return resolve(target);
9
- }
10
- if (typeof linkName === "string") {
11
- return resolve(dirname(linkName), target);
12
- }
13
- return new URL(target, linkName);
14
- };
15
-
16
- export { resolveSymlinkTarget as r };
@@ -1,205 +0,0 @@
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 FALLBACK_NAME = "unnamed";
12
- const MAX_LENGTH = 128;
13
- const REPLACEMENT_CHARACTERS = {
14
- '"': "ˮ",
15
- // 0x02EE - MODIFIER LETTER DOUBLE APOSTROPHE
16
- "*": "⁎",
17
- // 0x204E - LOW ASTERISK
18
- "/": "⁄",
19
- // 0x2044 - FRACTION SLASH
20
- ":": "꞉",
21
- // 0xA789 - MODIFIER LETTER COLON
22
- "<": "‹",
23
- // 0x2039 - SINGLE LEFT-POINTING ANGLE QUOTATION MARK
24
- ">": "›",
25
- // 0x203A - SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
26
- "?": "ʔ",
27
- // 0x0294 - LATIN LETTER GLOTTAL STOP
28
- "\\": "∖",
29
- // 0x2216 - SET MINUS
30
- "|": "ǀ"
31
- // 0x01C0 - LATIN LETTER DENTAL CLICK
32
- };
33
- const CONTROL_CHARS_REGEX = /[\u0000-\u001F\u0080-\u009F]/g;
34
- const RELATIVE_PATHS_REGEX = /^(?:\.+[/\\]+)+|^\.+$/g;
35
- const WINDOWS_SPECIAL_NAMES_REGEX = /^(?:con|prn|aux|nul|com\d|lpt\d)$/i;
36
- const WINDOWS_FORBIDDEN_CHARS_REGEX = /[<>:"/\\|?*]/g;
37
- const UNIX_FORBIDDEN_CHARS_REGEX = /\//g;
38
- const TRIM_CHARS = /* @__PURE__ */ new Set([" ", " ", "."]);
39
- const hasExtension = (name, lastDotIndex) => lastDotIndex > 0 && lastDotIndex < name.length - 1;
40
- const truncateWithExtension = (name, maxLength) => {
41
- const lastDotIndex = name.lastIndexOf(".");
42
- if (!hasExtension(name, lastDotIndex)) {
43
- return name.slice(0, maxLength);
44
- }
45
- const baseName = name.slice(0, lastDotIndex);
46
- const extension = name.slice(lastDotIndex);
47
- const maxBaseLength = maxLength - extension.length;
48
- return maxBaseLength > 0 ? `${baseName.slice(0, maxBaseLength)}${extension}` : name.slice(0, maxLength);
49
- };
50
- const trimSpacesAndPeriods = (input) => {
51
- let start = 0;
52
- let end = input.length;
53
- while (start < end) {
54
- const char = input[start];
55
- if (char === void 0 || !TRIM_CHARS.has(char)) {
56
- break;
57
- }
58
- start += 1;
59
- }
60
- while (end > start) {
61
- const char = input[end - 1];
62
- if (char === void 0 || !TRIM_CHARS.has(char)) {
63
- break;
64
- }
65
- end -= 1;
66
- }
67
- return input.slice(start, end);
68
- };
69
- const cleanWindowsName = (name) => {
70
- const lastDotIndex = name.lastIndexOf(".");
71
- if (hasExtension(name, lastDotIndex)) {
72
- const baseName = name.slice(0, lastDotIndex);
73
- const extension = name.slice(lastDotIndex);
74
- let cleanedBaseName = baseName;
75
- while (cleanedBaseName.length > 0) {
76
- const char = cleanedBaseName.at(-1);
77
- if (char === void 0 || !TRIM_CHARS.has(char)) {
78
- break;
79
- }
80
- cleanedBaseName = cleanedBaseName.slice(0, -1);
81
- }
82
- if (cleanedBaseName.length === 0) {
83
- return extension.slice(1);
84
- }
85
- return `${cleanedBaseName}${extension}`;
86
- }
87
- let cleaned = name;
88
- while (cleaned.length > 0) {
89
- const char = cleaned.at(-1);
90
- if (char === void 0 || !TRIM_CHARS.has(char)) {
91
- break;
92
- }
93
- cleaned = cleaned.slice(0, -1);
94
- }
95
- return cleaned;
96
- };
97
- const isWindowsReservedName = (name) => {
98
- const lastDotIndex = name.lastIndexOf(".");
99
- if (hasExtension(name, lastDotIndex)) {
100
- return false;
101
- }
102
- if (WINDOWS_SPECIAL_NAMES_REGEX.test(name)) {
103
- return true;
104
- }
105
- let trimmed = name;
106
- while (trimmed.length > 0) {
107
- const char = trimmed.at(-1);
108
- if (char === void 0 || !TRIM_CHARS.has(char)) {
109
- break;
110
- }
111
- trimmed = trimmed.slice(0, -1);
112
- }
113
- if (trimmed.length > 0 && WINDOWS_SPECIAL_NAMES_REGEX.test(trimmed)) {
114
- return true;
115
- }
116
- return false;
117
- };
118
- const cleanFat32Name = (name) => {
119
- const lastDotIndex = name.lastIndexOf(".");
120
- if (hasExtension(name, lastDotIndex)) {
121
- const baseName = name.slice(0, lastDotIndex);
122
- const extension = name.slice(lastDotIndex);
123
- const cleanedBaseName = trimSpacesAndPeriods(baseName);
124
- if (cleanedBaseName.length === 0) {
125
- return void 0;
126
- }
127
- return `${cleanedBaseName}${extension}`;
128
- }
129
- const trimmed = name.trim();
130
- if (trimmed.length > 0 && trimmed[0] === "." && trimmed.length <= 5) {
131
- const secondDotIndex = trimmed.indexOf(".", 1);
132
- if (secondDotIndex === -1) {
133
- return void 0;
134
- }
135
- }
136
- const cleaned = trimSpacesAndPeriods(name);
137
- if (cleaned.length === 0) {
138
- return void 0;
139
- }
140
- return cleaned;
141
- };
142
- const getFileSystemType = (options) => {
143
- const filesystem = options?.filesystem ?? "auto";
144
- if (filesystem === "auto") {
145
- return platform === "win32" ? "win32" : "unix";
146
- }
147
- if (filesystem === "darwin") {
148
- return "unix";
149
- }
150
- return filesystem;
151
- };
152
- const sanitize = (name, options) => {
153
- if (typeof name !== "string" || name.length === 0) {
154
- return FALLBACK_NAME;
155
- }
156
- const fileSystemType = getFileSystemType(options);
157
- let sanitized = name;
158
- sanitized = sanitized.replace(CONTROL_CHARS_REGEX, "");
159
- if (sanitized.length === 0) {
160
- return FALLBACK_NAME;
161
- }
162
- sanitized = sanitized.replace(RELATIVE_PATHS_REGEX, "");
163
- if (sanitized.length === 0) {
164
- return FALLBACK_NAME;
165
- }
166
- if (fileSystemType === "win32" || fileSystemType === "fat32") {
167
- const lastDotIndex = sanitized.lastIndexOf(".");
168
- if (!hasExtension(sanitized, lastDotIndex) && WINDOWS_SPECIAL_NAMES_REGEX.test(sanitized)) {
169
- return FALLBACK_NAME;
170
- }
171
- }
172
- sanitized = fileSystemType === "win32" || fileSystemType === "fat32" ? sanitized.replaceAll(WINDOWS_FORBIDDEN_CHARS_REGEX, (char) => REPLACEMENT_CHARACTERS[char] ?? "") : sanitized.replaceAll(UNIX_FORBIDDEN_CHARS_REGEX, REPLACEMENT_CHARACTERS["/"]);
173
- sanitized = sanitized.trim();
174
- if (fileSystemType === "win32" || fileSystemType === "fat32") {
175
- if (isWindowsReservedName(sanitized)) {
176
- return FALLBACK_NAME;
177
- }
178
- if (fileSystemType === "win32") {
179
- sanitized = cleanWindowsName(sanitized);
180
- if (sanitized.length === 0) {
181
- return FALLBACK_NAME;
182
- }
183
- }
184
- }
185
- if (fileSystemType === "fat32") {
186
- const cleaned = cleanFat32Name(sanitized);
187
- if (cleaned === void 0) {
188
- return FALLBACK_NAME;
189
- }
190
- sanitized = cleaned;
191
- }
192
- if (sanitized.length === 0) {
193
- return FALLBACK_NAME;
194
- }
195
- const maxLength = options?.maxLength ?? MAX_LENGTH;
196
- if (sanitized.length > maxLength) {
197
- sanitized = truncateWithExtension(sanitized, maxLength);
198
- if (sanitized.length === 0) {
199
- return FALLBACK_NAME;
200
- }
201
- }
202
- return sanitized;
203
- };
204
-
205
- export { sanitize };
@@ -1,19 +0,0 @@
1
- import { INTERNAL_STRIP_JSON_REGEX } from './F_OK-MldBaGxb.js';
2
-
3
- const stripJsonComments = (jsonString, { whitespace = true } = {}) => (
4
- // This regular expression translates to:
5
- //
6
- // /quoted-string|line-comment|block-comment/g
7
- //
8
- // This means that comment characters inside of strings will match
9
- // as strings, not comments, so we can just skip the whole string
10
- // in the replacer function.
11
- jsonString.replace(INTERNAL_STRIP_JSON_REGEX, (match) => {
12
- if (match.startsWith('"') || match[1] === "*" && !match.endsWith("*/")) {
13
- return match;
14
- }
15
- return whitespace ? match.replaceAll(/\S/g, " ") : "";
16
- })
17
- );
18
-
19
- export { stripJsonComments as default };
@@ -1,19 +0,0 @@
1
- const encoder = new TextEncoder();
2
- const toUint8Array = (contents) => {
3
- if (contents instanceof Uint8Array) {
4
- return contents;
5
- }
6
- if (typeof contents === "string") {
7
- return encoder.encode(contents);
8
- }
9
- if (contents instanceof ArrayBuffer) {
10
- return new Uint8Array(contents);
11
- }
12
- if (ArrayBuffer.isView(contents)) {
13
- const bytes = contents.buffer.slice(contents.byteOffset, contents.byteOffset + contents.byteLength);
14
- return new Uint8Array(bytes);
15
- }
16
- throw new TypeError("Invalid contents type. Expected string or ArrayBuffer.");
17
- };
18
-
19
- export { toUint8Array as t };
@@ -1,124 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- readdir,
22
- realpath,
23
- stat
24
- } = __cjs_getBuiltinModule("node:fs/promises");
25
- import { resolve, join, normalize, basename } from '@visulima/path';
26
- import { toPath } from '@visulima/path/utils';
27
- import WalkError from './WalkError-DER5A43G.js';
28
- import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
29
- import { g as globToRegExp, w as walkInclude } from './walk-include-CZco7BvN.js';
30
-
31
- const _createWalkEntry = async (path) => {
32
- const normalizePath = normalize(path);
33
- const name = basename(normalizePath);
34
- const info = await stat(normalizePath);
35
- return {
36
- isDirectory: () => info.isDirectory(),
37
- isFile: () => info.isFile(),
38
- isSymbolicLink: () => info.isSymbolicLink(),
39
- name,
40
- path: normalizePath
41
- };
42
- };
43
- async function* walk(directory, {
44
- extensions,
45
- followSymlinks = false,
46
- includeDirs: includeDirectories = true,
47
- includeFiles = true,
48
- includeSymlinks = true,
49
- match,
50
- maxDepth = Number.POSITIVE_INFINITY,
51
- skip
52
- } = {}) {
53
- assertValidFileOrDirectoryPath(directory);
54
- if (maxDepth < 0) {
55
- return;
56
- }
57
- const mappedMatch = match ? match.map(
58
- // eslint-disable-next-line no-confusing-arrow
59
- (pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
60
- ) : void 0;
61
- const mappedSkip = skip ? skip.map(
62
- // eslint-disable-next-line no-confusing-arrow
63
- (pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
64
- ) : void 0;
65
- const resolvedDirectory = resolve(toPath(directory));
66
- directory = resolvedDirectory;
67
- if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
68
- yield await _createWalkEntry(directory);
69
- }
70
- if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
71
- return;
72
- }
73
- try {
74
- const entries = await readdir(directory, {
75
- withFileTypes: true
76
- });
77
- for (const entry of entries) {
78
- let path = join(directory, entry.name);
79
- if (entry.isSymbolicLink()) {
80
- if (followSymlinks) {
81
- path = await realpath(path);
82
- } else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
83
- yield {
84
- isDirectory: () => entry.isDirectory(),
85
- isFile: () => entry.isFile(),
86
- isSymbolicLink: () => entry.isSymbolicLink(),
87
- name: entry.name,
88
- path
89
- };
90
- continue;
91
- } else {
92
- continue;
93
- }
94
- }
95
- if (entry.isDirectory()) {
96
- yield* walk(path, {
97
- extensions,
98
- followSymlinks,
99
- includeDirs: includeDirectories,
100
- includeFiles,
101
- includeSymlinks,
102
- match: mappedMatch,
103
- maxDepth: maxDepth - 1,
104
- skip: mappedSkip
105
- });
106
- } else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
107
- yield {
108
- isDirectory: () => entry.isDirectory(),
109
- isFile: () => entry.isFile(),
110
- isSymbolicLink: () => entry.isSymbolicLink(),
111
- name: entry.name,
112
- path
113
- };
114
- }
115
- }
116
- } catch (error) {
117
- if (error instanceof WalkError) {
118
- throw error;
119
- }
120
- throw new WalkError(error, directory);
121
- }
122
- }
123
-
124
- export { walk as default };
@@ -1,16 +0,0 @@
1
- const globToRegExp = (glob) => {
2
- const reString = glob.replace(/\.\*/g, ".([^/]*)").replace(/\*\*/g, "(.*)").replace(/(?<!\.)\*(?!\*)/g, "([^/]*)").replace(/\?/g, "[^/]").replace(/\.(?!\*)/g, String.raw`\.`).replace(/\{/g, "(").replace(/\}/g, ")").replace(/,/g, "|").replace(/\[!(.*?)\]/g, "[^$1]");
3
- return new RegExp(`^${reString}$`);
4
- };
5
-
6
- const walkInclude = (path, extensions, match, skip) => {
7
- if (Array.isArray(extensions) && extensions.length > 0 && !extensions.some((extension) => path.endsWith(extension))) {
8
- return false;
9
- }
10
- if (match && !match.some((pattern) => pattern.test(path))) {
11
- return false;
12
- }
13
- return !skip?.some((pattern) => pattern.test(path));
14
- };
15
-
16
- export { globToRegExp as g, walkInclude as w };
@@ -1,123 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- readdirSync,
22
- realpathSync,
23
- statSync
24
- } = __cjs_getBuiltinModule("node:fs");
25
- import { resolve, join, normalize, basename } from '@visulima/path';
26
- import { toPath } from '@visulima/path/utils';
27
- import WalkError from './WalkError-DER5A43G.js';
28
- import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
29
- import { g as globToRegExp, w as walkInclude } from './walk-include-CZco7BvN.js';
30
-
31
- const _createWalkEntry = (path) => {
32
- const normalizePath = normalize(path);
33
- const info = statSync(normalizePath);
34
- return {
35
- isDirectory: () => info.isDirectory(),
36
- isFile: () => info.isFile(),
37
- isSymbolicLink: () => info.isSymbolicLink(),
38
- name: basename(normalizePath),
39
- path: normalizePath
40
- };
41
- };
42
- function* walkSync(directory, {
43
- extensions,
44
- followSymlinks = false,
45
- includeDirs: includeDirectories = true,
46
- includeFiles = true,
47
- includeSymlinks = true,
48
- match,
49
- maxDepth = Number.POSITIVE_INFINITY,
50
- skip
51
- } = {}) {
52
- assertValidFileOrDirectoryPath(directory);
53
- if (maxDepth < 0) {
54
- return;
55
- }
56
- const mappedMatch = match ? match.map(
57
- // eslint-disable-next-line no-confusing-arrow
58
- (pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
59
- ) : void 0;
60
- const mappedSkip = skip ? skip.map(
61
- // eslint-disable-next-line no-confusing-arrow
62
- (pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
63
- ) : void 0;
64
- const resolvedDirectory = resolve(toPath(directory));
65
- directory = resolvedDirectory;
66
- if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
67
- yield _createWalkEntry(directory);
68
- }
69
- if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
70
- return;
71
- }
72
- try {
73
- const entries = readdirSync(directory, {
74
- withFileTypes: true
75
- });
76
- for (const entry of entries) {
77
- let path = join(directory, entry.name);
78
- if (entry.isSymbolicLink()) {
79
- if (followSymlinks) {
80
- path = realpathSync(path);
81
- } else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
82
- yield {
83
- isDirectory: () => entry.isDirectory(),
84
- isFile: () => entry.isFile(),
85
- isSymbolicLink: () => entry.isSymbolicLink(),
86
- name: entry.name,
87
- path: normalize(path)
88
- };
89
- continue;
90
- } else {
91
- continue;
92
- }
93
- }
94
- if (entry.isDirectory()) {
95
- yield* walkSync(path, {
96
- extensions,
97
- followSymlinks,
98
- includeDirs: includeDirectories,
99
- includeFiles,
100
- includeSymlinks,
101
- match: mappedMatch,
102
- maxDepth: maxDepth - 1,
103
- skip: mappedSkip
104
- });
105
- } else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
106
- yield {
107
- isDirectory: () => entry.isDirectory(),
108
- isFile: () => entry.isFile(),
109
- isSymbolicLink: () => entry.isSymbolicLink(),
110
- name: entry.name,
111
- path: normalize(path)
112
- };
113
- }
114
- }
115
- } catch (error) {
116
- if (error instanceof WalkError) {
117
- throw error;
118
- }
119
- throw new WalkError(error, directory);
120
- }
121
- }
122
-
123
- export { walkSync as default };
@@ -1,81 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- mkdir,
22
- writeFile: writeFile$1,
23
- stat,
24
- rename,
25
- chown,
26
- chmod,
27
- unlink
28
- } = __cjs_getBuiltinModule("node:fs/promises");
29
- import { dirname } from '@visulima/path';
30
- import { toPath } from '@visulima/path/utils';
31
- import { F_OK } from './F_OK-MldBaGxb.js';
32
- import isAccessible from './isAccessible-DuVrTNFV.js';
33
- import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
34
- import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
35
- import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
36
-
37
- const writeFile = async (path, content, options) => {
38
- options = {
39
- encoding: "utf8",
40
- flag: "w",
41
- overwrite: true,
42
- recursive: true,
43
- ...options
44
- };
45
- assertValidFileOrDirectoryPath(path);
46
- assertValidFileContents(content);
47
- path = toPath(path);
48
- const temporaryPath = `${path}.tmp`;
49
- try {
50
- const pathExists = await isAccessible(path, F_OK);
51
- if (!pathExists && options.recursive) {
52
- const directory = dirname(path);
53
- if (!await isAccessible(directory, F_OK)) {
54
- await mkdir(directory, { recursive: true });
55
- }
56
- }
57
- let stat$1;
58
- await writeFile$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
59
- if (pathExists && !options.overwrite) {
60
- stat$1 = await stat(path);
61
- options.chown ??= { gid: stat$1.gid, uid: stat$1.uid };
62
- await rename(path, `${path}.bak`);
63
- }
64
- if (options.chown) {
65
- try {
66
- await chown(temporaryPath, options.chown.uid, options.chown.gid);
67
- } catch {
68
- }
69
- }
70
- await chmod(temporaryPath, stat$1 && !options.mode ? stat$1.mode : options.mode ?? 438);
71
- await rename(temporaryPath, path);
72
- } catch (error) {
73
- throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
74
- } finally {
75
- if (await isAccessible(temporaryPath)) {
76
- await unlink(`${path}.tmp`);
77
- }
78
- }
79
- };
80
-
81
- export { writeFile as default };