@visulima/fs 4.1.0 → 5.0.0-alpha.10

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 (156) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/LICENSE.md +157 -128
  3. package/README.md +32 -14
  4. package/dist/eol.d.ts +6 -35
  5. package/dist/error.d.ts +43 -7
  6. package/dist/error.js +1 -1
  7. package/dist/glob-parent.d.ts +5 -0
  8. package/dist/glob-parent.js +90 -0
  9. package/dist/glob.d.ts +5 -0
  10. package/dist/glob.js +2 -0
  11. package/dist/index.d.ts +81 -36
  12. package/dist/index.js +37 -32
  13. package/dist/ini.d.ts +10 -0
  14. package/dist/ini.js +4 -0
  15. package/dist/is-glob.d.ts +5 -0
  16. package/dist/is-glob.js +9 -0
  17. package/dist/json5.d.ts +12 -0
  18. package/dist/json5.js +4 -0
  19. package/dist/jsonc.d.ts +10 -0
  20. package/dist/jsonc.js +4 -0
  21. package/dist/match.d.ts +5 -0
  22. package/dist/match.js +15 -0
  23. package/dist/packem_shared/{F_OK-BalxCn9n.js → F_OK-MldBaGxb.js} +1 -1
  24. package/dist/packem_shared/{WalkError-DUdQd6FT.js → WalkError-DER5A43G.js} +1 -1
  25. package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
  26. package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +12 -0
  27. package/dist/packem_shared/{collect-DcBwsYYd.js → collect-CqQ3eVab.js} +1 -1
  28. package/dist/packem_shared/{collectSync-Bkjf9Dbm.js → collectSync-noE08NNv.js} +1 -1
  29. package/dist/packem_shared/{emptyDir-CYB5Tict.js → emptyDir-DnwENOaV.js} +5 -2
  30. package/dist/packem_shared/{emptyDirSync-BD8-1Ytl.js → emptyDirSync-6WiHBo8a.js} +3 -1
  31. package/dist/packem_shared/{ensureDir-C_kuQ5Ik.js → ensureDir-DNlPftys.js} +2 -2
  32. package/dist/packem_shared/{ensureDirSync-CI5g-uBI.js → ensureDirSync-DcPZFMy5.js} +2 -2
  33. package/dist/packem_shared/{ensureFile-BUtXGlGT.js → ensureFile-BRQpUOUM.js} +2 -2
  34. package/dist/packem_shared/{ensureFileSync-C8hASR-1.js → ensureFileSync-SBY7A9-C.js} +2 -2
  35. package/dist/packem_shared/{ensureLink-BPnAG5-P.js → ensureLink-DJQeauEn.js} +4 -3
  36. package/dist/packem_shared/{ensureLinkSync-B-Z7X0ub.js → ensureLinkSync-D9RVAglV.js} +4 -3
  37. package/dist/packem_shared/{ensureSymlink-U5B6J0BN.js → ensureSymlink-CoRYDRwr.js} +10 -3
  38. package/dist/packem_shared/{ensureSymlinkSync-DHnZj-9F.js → ensureSymlinkSync-CFimFlgh.js} +10 -3
  39. package/dist/packem_shared/{findUp-Lv9mZCIQ.js → findUp-YcNLKdfV.js} +4 -5
  40. package/dist/packem_shared/{findUpSync-BsK4Nrrq.js → findUpSync-BfA5fheN.js} +2 -4
  41. package/dist/packem_shared/glob-DY8l7izD.js +5 -0
  42. package/dist/packem_shared/glob-sync.d-CYiamQIr.d.ts +4 -0
  43. package/dist/packem_shared/globSync-5P2KJf_g.js +5 -0
  44. package/dist/packem_shared/index-C8W8sfzP.js +830 -0
  45. package/dist/packem_shared/index-bhgnhm4u.js +167 -0
  46. package/dist/packem_shared/index-xe4o3cYi.js +1784 -0
  47. package/dist/packem_shared/{parseJson-C8xb-3LR.js → indexToLineColumn-BUb0GPKl-BF770uX7.js} +8 -68
  48. package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +251 -0
  49. package/dist/packem_shared/{isAccessible-iOp0Bou6.js → isAccessible-DuVrTNFV.js} +1 -1
  50. package/dist/packem_shared/{isAccessibleSync-38BmiIcx.js → isAccessibleSync-DI8mM0fA.js} +1 -1
  51. package/dist/packem_shared/{isFsCaseSensitive-D-ayleCy.js → isFsCaseSensitive-DunL7Iry.js} +6 -6
  52. package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +10 -0
  53. package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +72 -0
  54. package/dist/packem_shared/{move-BD6JbYSu.js → move-DbpW5_vA.js} +2 -2
  55. package/dist/packem_shared/parseJson-BIp89Xjo.js +63 -0
  56. package/dist/packem_shared/{readFile-BcK0rkht.js → readFile-Iz7kvCCk.js} +2 -2
  57. package/dist/packem_shared/{readFileSync-BDgEnnqT.js → readFileSync-gm9yfIhh.js} +4 -3
  58. package/dist/packem_shared/readIni-CJ2xfpjB.js +10 -0
  59. package/dist/packem_shared/readIniSync-9LUjaSSp.js +10 -0
  60. package/dist/packem_shared/{readJson-ac6N9-5G.js → readJson-C_rwm-wq.js} +2 -2
  61. package/dist/packem_shared/readJson5-mBoTZppy.js +15 -0
  62. package/dist/packem_shared/readJson5Sync-8WS2yUok.js +15 -0
  63. package/dist/packem_shared/{readJsonSync-BTlwqLNV.js → readJsonSync-BMEmCcJ6.js} +2 -2
  64. package/dist/packem_shared/readJsonc-j-OS-APg.js +28 -0
  65. package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +16 -0
  66. package/dist/packem_shared/readToml-B2MHaSes.js +9 -0
  67. package/dist/packem_shared/readTomlSync-DNbK8NEb.js +9 -0
  68. package/dist/packem_shared/{readYaml-Cj6HxRoa.js → readYaml-D5q2a0e1.js} +1 -1
  69. package/dist/packem_shared/{readYamlSync-D3_iAKVv.js → readYamlSync-BKX-PAfq.js} +1 -1
  70. package/dist/packem_shared/{remove-_oDY3uKo.js → remove-C8_gl3jF.js} +2 -1
  71. package/dist/packem_shared/{removeSync-DETRj7Qn.js → removeSync-BJR_wTwN.js} +2 -1
  72. package/dist/packem_shared/{sanitize-lOzE6k2A.js → sanitize-BZoLN9Fg.js} +3 -3
  73. package/dist/packem_shared/{stripJsonComments-21XWVDwP.js → stripJsonComments-vo4k0mpF.js} +1 -1
  74. package/dist/packem_shared/types.d-BrSrwTmO.d.ts +145 -0
  75. package/dist/packem_shared/{walk-BhTbpr3y.js → walk-CSZgCuDx.js} +19 -10
  76. package/dist/packem_shared/{walkSync-DDBq95s8.js → walkSync-C4Cy28xb.js} +25 -16
  77. package/dist/packem_shared/{writeFile-NT1fLEEe.js → writeFile-B8HX0JIQ.js} +3 -5
  78. package/dist/packem_shared/{writeFileSync-Bj5UDSf0.js → writeFileSync-DB8vv8xR.js} +3 -5
  79. package/dist/packem_shared/writeIni-i55QrL8y.js +65 -0
  80. package/dist/packem_shared/writeIniSync-CLqJE5t3.js +64 -0
  81. package/dist/packem_shared/{writeJson-DQLdAi0d.js → writeJson-Bo7C2UHw.js} +3 -3
  82. package/dist/packem_shared/writeJson5-vVmHUQOd.js +53 -0
  83. package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +53 -0
  84. package/dist/packem_shared/{writeJsonSync-DvTCjVUi.js → writeJsonSync-BKZ_9Acr.js} +3 -3
  85. package/dist/packem_shared/writeJsonc-BufH_oC5.js +60 -0
  86. package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +59 -0
  87. package/dist/packem_shared/writeToml-DgTW_-7F.js +8 -0
  88. package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +8 -0
  89. package/dist/packem_shared/{writeYaml-BMY0kOPf.js → writeYaml-BWCOome-.js} +3 -3
  90. package/dist/packem_shared/{writeYamlSync-DqPu8cCd.js → writeYamlSync-DBVnXmuY.js} +3 -3
  91. package/dist/size.d.ts +10 -254
  92. package/dist/size.js +6 -4
  93. package/dist/toml.d.ts +9 -0
  94. package/dist/toml.js +4 -0
  95. package/dist/utils.d.ts +15 -6
  96. package/dist/utils.js +2 -2
  97. package/dist/yaml.d.ts +14 -5
  98. package/dist/yaml.js +4 -4
  99. package/package.json +61 -7
  100. package/dist/constants.d.ts +0 -42
  101. package/dist/ensure/ensure-dir-sync.d.ts +0 -14
  102. package/dist/ensure/ensure-dir.d.ts +0 -14
  103. package/dist/ensure/ensure-file-sync.d.ts +0 -15
  104. package/dist/ensure/ensure-file.d.ts +0 -27
  105. package/dist/ensure/ensure-link-sync.d.ts +0 -16
  106. package/dist/ensure/ensure-link.d.ts +0 -16
  107. package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
  108. package/dist/ensure/ensure-symlink.d.ts +0 -23
  109. package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
  110. package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
  111. package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
  112. package/dist/error/already-exists-error.d.ts +0 -39
  113. package/dist/error/directory-error.d.ts +0 -47
  114. package/dist/error/json-error.d.ts +0 -52
  115. package/dist/error/not-empty-error.d.ts +0 -51
  116. package/dist/error/not-found-error.d.ts +0 -44
  117. package/dist/error/permission-error.d.ts +0 -45
  118. package/dist/error/walk-error.d.ts +0 -51
  119. package/dist/find/collect-sync.d.ts +0 -31
  120. package/dist/find/collect.d.ts +0 -35
  121. package/dist/find/find-up-sync.d.ts +0 -42
  122. package/dist/find/find-up.d.ts +0 -46
  123. package/dist/find/utils/glob-to-regexp.d.ts +0 -2
  124. package/dist/find/utils/walk-include.d.ts +0 -2
  125. package/dist/find/walk-sync.d.ts +0 -34
  126. package/dist/find/walk.d.ts +0 -37
  127. package/dist/is-accessible-sync.d.ts +0 -3
  128. package/dist/is-accessible.d.ts +0 -29
  129. package/dist/move/index.d.ts +0 -68
  130. package/dist/move/types.d.ts +0 -36
  131. package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
  132. package/dist/move/utils/internal-move-file.d.ts +0 -3
  133. package/dist/move/utils/validate-same-directory.d.ts +0 -2
  134. package/dist/read/read-file-sync.d.ts +0 -37
  135. package/dist/read/read-file.d.ts +0 -41
  136. package/dist/read/read-json-sync.d.ts +0 -5
  137. package/dist/read/read-json.d.ts +0 -5
  138. package/dist/read/read-yaml-sync.d.ts +0 -4
  139. package/dist/read/read-yaml.d.ts +0 -4
  140. package/dist/remove/empty-dir-sync.d.ts +0 -23
  141. package/dist/remove/empty-dir.d.ts +0 -28
  142. package/dist/remove/remove-sync.d.ts +0 -27
  143. package/dist/remove/remove.d.ts +0 -32
  144. package/dist/sanitize.d.ts +0 -31
  145. package/dist/types.d.ts +0 -304
  146. package/dist/utils/assert-valid-file-contents.d.ts +0 -27
  147. package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
  148. package/dist/utils/parse-json.d.ts +0 -5
  149. package/dist/utils/strip-json-comments.d.ts +0 -44
  150. package/dist/write/utils/to-uint-8-array.d.ts +0 -2
  151. package/dist/write/write-file-sync.d.ts +0 -30
  152. package/dist/write/write-file.d.ts +0 -30
  153. package/dist/write/write-json-sync.d.ts +0 -29
  154. package/dist/write/write-json.d.ts +0 -30
  155. package/dist/write/write-yaml-sync.d.ts +0 -4
  156. package/dist/write/write-yaml.d.ts +0 -4
@@ -0,0 +1,15 @@
1
+ import JSON5 from 'json5';
2
+ import readFileSync from './readFileSync-gm9yfIhh.js';
3
+
4
+ function readJson5Sync(path, reviver, options) {
5
+ if (reviver && typeof reviver === "object") {
6
+ options = reviver;
7
+ reviver = void 0;
8
+ }
9
+ const { beforeParse, buffer, compression, encoding = "utf8", flag } = options ?? {};
10
+ const content = readFileSync(path, { buffer, compression, encoding, flag });
11
+ const input = typeof beforeParse === "function" ? beforeParse(content) : content;
12
+ return JSON5.parse(input, reviver);
13
+ }
14
+
15
+ export { readJson5Sync as default };
@@ -1,6 +1,6 @@
1
1
  import { toPath } from '@visulima/path/utils';
2
- import parseJson from './parseJson-C8xb-3LR.js';
3
- import readFileSync from './readFileSync-BDgEnnqT.js';
2
+ import parseJson from './parseJson-BIp89Xjo.js';
3
+ import readFileSync from './readFileSync-gm9yfIhh.js';
4
4
 
5
5
  function readJsonSync(path, reviver, options) {
6
6
  if (typeof reviver === "object") {
@@ -0,0 +1,28 @@
1
+ import { toPath } from '@visulima/path/utils';
2
+ import { parse, printParseErrorCode } from 'jsonc-parser';
3
+ import JSONError from './JSONError-BkHRnInH.js';
4
+ import readFile from './readFile-Iz7kvCCk.js';
5
+ import { i as indexToLineColumn, c as codeFrame } from './indexToLineColumn-BUb0GPKl-BF770uX7.js';
6
+
7
+ const throwIfJsoncErrors = (errors, input, filePath, codeFrameOptions) => {
8
+ if (errors.length === 0) {
9
+ return;
10
+ }
11
+ const first = errors[0];
12
+ const location = indexToLineColumn(input, first.offset);
13
+ const jsonError = new JSONError(`${printParseErrorCode(first.error)} at offset ${first.offset}`);
14
+ jsonError.fileName = filePath;
15
+ jsonError.codeFrame = codeFrame(input, { start: location }, { tabWidth: false, ...codeFrameOptions });
16
+ throw jsonError;
17
+ };
18
+ const readJsonc = async (path, options) => {
19
+ const { allowEmptyContent, allowTrailingComma = true, beforeParse, buffer, color, compression, disallowComments, encoding = "utf8", flag } = options ?? {};
20
+ const content = await readFile(path, { buffer, compression, encoding, flag });
21
+ const input = typeof beforeParse === "function" ? beforeParse(content) : content;
22
+ const errors = [];
23
+ const result = parse(input, errors, { allowEmptyContent, allowTrailingComma, disallowComments });
24
+ throwIfJsoncErrors(errors, input, toPath(path), { color });
25
+ return result;
26
+ };
27
+
28
+ export { readJsonc as default, throwIfJsoncErrors };
@@ -0,0 +1,16 @@
1
+ import { toPath } from '@visulima/path/utils';
2
+ import { parse } from 'jsonc-parser';
3
+ import readFileSync from './readFileSync-gm9yfIhh.js';
4
+ import { throwIfJsoncErrors } from './readJsonc-j-OS-APg.js';
5
+
6
+ const readJsoncSync = (path, options) => {
7
+ const { allowEmptyContent, allowTrailingComma = true, beforeParse, buffer, color, compression, disallowComments, encoding = "utf8", flag } = options ?? {};
8
+ const content = readFileSync(path, { buffer, compression, encoding, flag });
9
+ const input = typeof beforeParse === "function" ? beforeParse(content) : content;
10
+ const errors = [];
11
+ const result = parse(input, errors, { allowEmptyContent, allowTrailingComma, disallowComments });
12
+ throwIfJsoncErrors(errors, input, toPath(path), { color });
13
+ return result;
14
+ };
15
+
16
+ export { readJsoncSync as default };
@@ -0,0 +1,9 @@
1
+ import { parse } from 'smol-toml';
2
+ import readFile from './readFile-Iz7kvCCk.js';
3
+
4
+ const readToml = async (path, options) => {
5
+ const content = await readFile(path, { encoding: "utf8", ...options });
6
+ return parse(content);
7
+ };
8
+
9
+ export { readToml as default };
@@ -0,0 +1,9 @@
1
+ import { parse } from 'smol-toml';
2
+ import readFileSync from './readFileSync-gm9yfIhh.js';
3
+
4
+ const readTomlSync = (path, options) => {
5
+ const content = readFileSync(path, { encoding: "utf8", ...options });
6
+ return parse(content);
7
+ };
8
+
9
+ export { readTomlSync as default };
@@ -1,5 +1,5 @@
1
1
  import { parse } from 'yaml';
2
- import readFile from './readFile-BcK0rkht.js';
2
+ import readFile from './readFile-Iz7kvCCk.js';
3
3
 
4
4
  async function readYaml(path, reviver, options) {
5
5
  const { buffer, compression, encoding = "utf8", flag, ...parseOptions } = options ?? {};
@@ -1,5 +1,5 @@
1
1
  import { parse } from 'yaml';
2
- import readFileSync from './readFileSync-BDgEnnqT.js';
2
+ import readFileSync from './readFileSync-gm9yfIhh.js';
3
3
 
4
4
  function readYamlSync(path, reviver, options) {
5
5
  const { buffer, compression, encoding = "utf8", flag, ...parseOptions } = options ?? {};
@@ -22,6 +22,7 @@ const {
22
22
  rm
23
23
  } = __cjs_getBuiltinModule("node:fs/promises");
24
24
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
25
+ import { b as buildRmOptions } from './build-rm-options-Cl3VDY4O.js';
25
26
 
26
27
  const remove = async (path, options = {}) => {
27
28
  assertValidFileOrDirectoryPath(path);
@@ -30,7 +31,7 @@ const remove = async (path, options = {}) => {
30
31
  } catch {
31
32
  }
32
33
  try {
33
- await rm(path, { force: true, maxRetries: options?.maxRetries, recursive: true, retryDelay: options?.retryDelay });
34
+ await rm(path, buildRmOptions(options));
34
35
  } catch {
35
36
  }
36
37
  };
@@ -22,6 +22,7 @@ const {
22
22
  rmSync
23
23
  } = __cjs_getBuiltinModule("node:fs");
24
24
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
25
+ import { b as buildRmOptions } from './build-rm-options-Cl3VDY4O.js';
25
26
 
26
27
  const removeSync = (path, options = {}) => {
27
28
  assertValidFileOrDirectoryPath(path);
@@ -30,7 +31,7 @@ const removeSync = (path, options = {}) => {
30
31
  } catch {
31
32
  }
32
33
  try {
33
- rmSync(path, { force: true, maxRetries: options?.maxRetries, recursive: true, retryDelay: options?.retryDelay });
34
+ rmSync(path, buildRmOptions(options));
34
35
  } catch {
35
36
  }
36
37
  };
@@ -73,7 +73,7 @@ const cleanWindowsName = (name) => {
73
73
  const extension = name.slice(lastDotIndex);
74
74
  let cleanedBaseName = baseName;
75
75
  while (cleanedBaseName.length > 0) {
76
- const char = cleanedBaseName[cleanedBaseName.length - 1];
76
+ const char = cleanedBaseName.at(-1);
77
77
  if (char === void 0 || !TRIM_CHARS.has(char)) {
78
78
  break;
79
79
  }
@@ -86,7 +86,7 @@ const cleanWindowsName = (name) => {
86
86
  }
87
87
  let cleaned = name;
88
88
  while (cleaned.length > 0) {
89
- const char = cleaned[cleaned.length - 1];
89
+ const char = cleaned.at(-1);
90
90
  if (char === void 0 || !TRIM_CHARS.has(char)) {
91
91
  break;
92
92
  }
@@ -104,7 +104,7 @@ const isWindowsReservedName = (name) => {
104
104
  }
105
105
  let trimmed = name;
106
106
  while (trimmed.length > 0) {
107
- const char = trimmed[trimmed.length - 1];
107
+ const char = trimmed.at(-1);
108
108
  if (char === void 0 || !TRIM_CHARS.has(char)) {
109
109
  break;
110
110
  }
@@ -1,4 +1,4 @@
1
- import { INTERNAL_STRIP_JSON_REGEX } from './F_OK-BalxCn9n.js';
1
+ import { INTERNAL_STRIP_JSON_REGEX } from './F_OK-MldBaGxb.js';
2
2
 
3
3
  const stripJsonComments = (jsonString, { whitespace = true } = {}) => (
4
4
  // This regular expression translates to:
@@ -0,0 +1,145 @@
1
+ import { PathLike, Dirent } from 'node:fs';
2
+ import { GlobOptions as GlobOptions$1 } from 'tinyglobby';
3
+ import { DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from './options';
4
+ declare const F_OK: number;
5
+ declare const R_OK: number;
6
+ declare const W_OK: number;
7
+ declare const X_OK: number;
8
+ declare const FIND_UP_STOP: symbol;
9
+ type ColorizeMethod = (value: string) => string;
10
+ type JsoncParseOptions = {
11
+ allowEmptyContent?: boolean;
12
+ allowTrailingComma?: boolean;
13
+ disallowComments?: boolean;
14
+ };
15
+ type JsoncFormattingOptions = {
16
+ eol?: string;
17
+ insertFinalNewline?: boolean;
18
+ insertSpaces?: boolean;
19
+ keepLines?: boolean;
20
+ tabSize?: number;
21
+ };
22
+ type IniEncodeOptions = {
23
+ align?: boolean;
24
+ bracketedArray?: boolean;
25
+ newline?: boolean;
26
+ platform?: string;
27
+ section?: string;
28
+ sort?: boolean;
29
+ whitespace?: boolean;
30
+ };
31
+ type Json5Replacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null;
32
+ type GlobOptions = Omit<GlobOptions$1, "patterns">;
33
+ interface WalkOptions {
34
+ extensions?: string[];
35
+ followSymlinks?: boolean;
36
+ includeDirs?: boolean;
37
+ includeFiles?: boolean;
38
+ includeSymlinks?: boolean;
39
+ match?: (RegExp | string)[];
40
+ maxDepth?: number;
41
+ skip?: (RegExp | string)[];
42
+ }
43
+ interface WalkEntry extends Pick<Dirent, "isDirectory" | "isFile" | "isSymbolicLink" | "name"> {
44
+ path: string;
45
+ }
46
+ type CompressionType = "brotli" | "gzip" | "none";
47
+ type ReadFileEncoding = "ascii" | "base64" | "base64url" | "hex" | "latin1" | "ucs-2" | "ucs2" | "utf-8" | "utf-16le" | "utf8" | "utf16le";
48
+ type ReadFileOptions<C> = {
49
+ buffer?: boolean;
50
+ compression?: C;
51
+ encoding?: ReadFileEncoding;
52
+ flag?: number | string;
53
+ };
54
+ type ContentType<O = undefined> = O extends {
55
+ buffer: true;
56
+ } ? Buffer : string;
57
+ type JsonReviver = Parameters<(typeof JSON)["parse"]>["1"];
58
+ type CodeFrameLocation = {
59
+ column?: number;
60
+ line: number;
61
+ };
62
+ type CodeFrameOptions = {
63
+ color?: {
64
+ gutter?: ColorizeMethod;
65
+ marker?: ColorizeMethod;
66
+ message?: ColorizeMethod;
67
+ };
68
+ };
69
+ type ReadJsonOptions = CodeFrameOptions & {
70
+ beforeParse?: (source: string) => string;
71
+ };
72
+ type WriteFileOptions = {
73
+ chown?: {
74
+ gid: number;
75
+ uid: number;
76
+ };
77
+ encoding?: BufferEncoding | null;
78
+ flag?: string;
79
+ mode?: number;
80
+ overwrite?: boolean;
81
+ recursive?: boolean;
82
+ };
83
+ type JsonReplacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null;
84
+ type YamlReplacer = JsonReplacer;
85
+ type WriteJsonOptions = WriteFileOptions & {
86
+ detectIndent?: boolean;
87
+ indent?: number | string;
88
+ replacer?: JsonReplacer;
89
+ stringify?: (data: unknown, replacer: JsonReplacer, space: number | string | undefined) => string;
90
+ };
91
+ type FindUpOptions = {
92
+ allowSymlinks?: boolean;
93
+ cwd?: URL | string;
94
+ stopAt?: URL | string;
95
+ type?: "directory" | "file";
96
+ };
97
+ type FindUpNameFnResult = PathLike | Promise<PathLike | typeof FIND_UP_STOP> | typeof FIND_UP_STOP | undefined;
98
+ type FindUpName = string[] | string | ((directory: string) => FindUpNameFnResult);
99
+ type FindUpNameSyncFnResult = PathLike | typeof FIND_UP_STOP | undefined;
100
+ type FindUpNameSync = string[] | string | ((directory: string) => FindUpNameSyncFnResult);
101
+ type RetryOptions = {
102
+ maxRetries?: number;
103
+ retryDelay?: number;
104
+ };
105
+ type ReadYamlOptions<C> = DocumentOptions & ParseOptions & ReadFileOptions<C> & SchemaOptions & ToJSOptions;
106
+ type YamlReviver = (key: unknown, value: unknown) => unknown;
107
+ type WriteYamlExtras = {
108
+ replacer?: JsonReplacer;
109
+ space?: number | string;
110
+ };
111
+ type WriteYamlOptions = CreateNodeOptions & DocumentOptions & ParseOptions & SchemaOptions & ToStringOptions & WriteFileOptions & WriteYamlExtras;
112
+ type ReadTomlOptions<C> = ReadFileOptions<C>;
113
+ type WriteTomlOptions = WriteFileOptions;
114
+ type ReadJsoncExtras = {
115
+ beforeParse?: (source: string) => string;
116
+ };
117
+ type ReadJsoncOptions<C> = CodeFrameOptions & JsoncParseOptions & ReadFileOptions<C> & ReadJsoncExtras;
118
+ type WriteJsoncOptions = WriteFileOptions & {
119
+ detectIndent?: boolean;
120
+ formattingOptions?: JsoncFormattingOptions;
121
+ indent?: number | string;
122
+ preserveComments?: boolean;
123
+ replacer?: JsonReplacer;
124
+ };
125
+ type Json5Reviver = (this: unknown, key: string, value: unknown) => unknown;
126
+ type ReadJson5Extras = {
127
+ beforeParse?: (source: string) => string;
128
+ };
129
+ type ReadJson5Options<C> = CodeFrameOptions & ReadFileOptions<C> & ReadJson5Extras;
130
+ type WriteJson5Options = WriteFileOptions & {
131
+ detectIndent?: boolean;
132
+ indent?: number | string;
133
+ quote?: string;
134
+ replacer?: Json5Replacer;
135
+ };
136
+ type ReadIniOptions<C> = ReadFileOptions<C> & {
137
+ bracketedArray?: boolean;
138
+ };
139
+ type IniLineEnding = "\n" | "\r\n";
140
+ type WriteIniExtras = {
141
+ eol?: IniLineEnding;
142
+ preserveStyle?: boolean;
143
+ };
144
+ type WriteIniOptions = IniEncodeOptions & WriteFileOptions & WriteIniExtras;
145
+ export { CodeFrameLocation as A, FIND_UP_STOP as B, CodeFrameOptions as C, F_OK as D, FindUpNameFnResult as E, FindUpName as F, GlobOptions as G, FindUpNameSyncFnResult as H, IniEncodeOptions as I, JsonReviver as J, R_OK as K, ReadFileEncoding as L, W_OK as M, ReadTomlOptions as R, WriteTomlOptions as W, X_OK as X, YamlReviver as Y, CompressionType as a, ReadYamlOptions as b, WriteYamlOptions as c, JsonReplacer as d, YamlReplacer as e, ReadJsoncOptions as f, WriteJsoncOptions as g, JsoncFormattingOptions as h, JsoncParseOptions as i, ReadIniOptions as j, WriteIniOptions as k, IniLineEnding as l, ReadJson5Options as m, Json5Reviver as n, WriteJson5Options as o, Json5Replacer as p, WalkOptions as q, FindUpOptions as r, FindUpNameSync as s, WalkEntry as t, ReadFileOptions as u, ContentType as v, ReadJsonOptions as w, RetryOptions as x, WriteFileOptions as y, WriteJsonOptions as z };
@@ -24,7 +24,7 @@ const {
24
24
  } = __cjs_getBuiltinModule("node:fs/promises");
25
25
  import { resolve, join, normalize, basename } from '@visulima/path';
26
26
  import { toPath } from '@visulima/path/utils';
27
- import WalkError from './WalkError-DUdQd6FT.js';
27
+ import WalkError from './WalkError-DER5A43G.js';
28
28
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
29
29
  import { g as globToRegExp, w as walkInclude } from './walk-include-CZco7BvN.js';
30
30
 
@@ -54,9 +54,16 @@ async function* walk(directory, {
54
54
  if (maxDepth < 0) {
55
55
  return;
56
56
  }
57
- const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
58
- const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
59
- directory = resolve(toPath(directory));
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;
60
67
  if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
61
68
  yield await _createWalkEntry(directory);
62
69
  }
@@ -64,26 +71,28 @@ async function* walk(directory, {
64
71
  return;
65
72
  }
66
73
  try {
67
- for await (const entry of await readdir(directory, {
74
+ const entries = await readdir(directory, {
68
75
  withFileTypes: true
69
- })) {
76
+ });
77
+ for (const entry of entries) {
70
78
  let path = join(directory, entry.name);
71
79
  if (entry.isSymbolicLink()) {
72
80
  if (followSymlinks) {
73
81
  path = await realpath(path);
74
82
  } else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
75
83
  yield {
76
- isDirectory: entry.isDirectory,
77
- isFile: entry.isFile,
78
- isSymbolicLink: entry.isSymbolicLink,
84
+ isDirectory: () => entry.isDirectory(),
85
+ isFile: () => entry.isFile(),
86
+ isSymbolicLink: () => entry.isSymbolicLink(),
79
87
  name: entry.name,
80
88
  path
81
89
  };
90
+ continue;
82
91
  } else {
83
92
  continue;
84
93
  }
85
94
  }
86
- if (entry.isSymbolicLink() || entry.isDirectory()) {
95
+ if (entry.isDirectory()) {
87
96
  yield* walk(path, {
88
97
  extensions,
89
98
  followSymlinks,
@@ -24,7 +24,7 @@ const {
24
24
  } = __cjs_getBuiltinModule("node:fs");
25
25
  import { resolve, join, normalize, basename } from '@visulima/path';
26
26
  import { toPath } from '@visulima/path/utils';
27
- import WalkError from './WalkError-DUdQd6FT.js';
27
+ import WalkError from './WalkError-DER5A43G.js';
28
28
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
29
29
  import { g as globToRegExp, w as walkInclude } from './walk-include-CZco7BvN.js';
30
30
 
@@ -32,9 +32,9 @@ const _createWalkEntry = (path) => {
32
32
  const normalizePath = normalize(path);
33
33
  const info = statSync(normalizePath);
34
34
  return {
35
- isDirectory: info.isDirectory,
36
- isFile: info.isFile,
37
- isSymbolicLink: info.isSymbolicLink,
35
+ isDirectory: () => info.isDirectory(),
36
+ isFile: () => info.isFile(),
37
+ isSymbolicLink: () => info.isSymbolicLink(),
38
38
  name: basename(normalizePath),
39
39
  path: normalizePath
40
40
  };
@@ -53,9 +53,16 @@ function* walkSync(directory, {
53
53
  if (maxDepth < 0) {
54
54
  return;
55
55
  }
56
- const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
57
- const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
58
- directory = resolve(toPath(directory));
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;
59
66
  if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
60
67
  yield _createWalkEntry(directory);
61
68
  }
@@ -63,26 +70,28 @@ function* walkSync(directory, {
63
70
  return;
64
71
  }
65
72
  try {
66
- for (const entry of readdirSync(directory, {
73
+ const entries = readdirSync(directory, {
67
74
  withFileTypes: true
68
- })) {
75
+ });
76
+ for (const entry of entries) {
69
77
  let path = join(directory, entry.name);
70
78
  if (entry.isSymbolicLink()) {
71
79
  if (followSymlinks) {
72
80
  path = realpathSync(path);
73
81
  } else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
74
82
  yield {
75
- isDirectory: entry.isDirectory,
76
- isFile: entry.isFile,
77
- isSymbolicLink: entry.isSymbolicLink,
83
+ isDirectory: () => entry.isDirectory(),
84
+ isFile: () => entry.isFile(),
85
+ isSymbolicLink: () => entry.isSymbolicLink(),
78
86
  name: entry.name,
79
87
  path: normalize(path)
80
88
  };
89
+ continue;
81
90
  } else {
82
91
  continue;
83
92
  }
84
93
  }
85
- if (entry.isSymbolicLink() || entry.isDirectory()) {
94
+ if (entry.isDirectory()) {
86
95
  yield* walkSync(path, {
87
96
  extensions,
88
97
  followSymlinks,
@@ -95,9 +104,9 @@ function* walkSync(directory, {
95
104
  });
96
105
  } else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
97
106
  yield {
98
- isDirectory: entry.isDirectory,
99
- isFile: entry.isFile,
100
- isSymbolicLink: entry.isSymbolicLink,
107
+ isDirectory: () => entry.isDirectory(),
108
+ isFile: () => entry.isFile(),
109
+ isSymbolicLink: () => entry.isSymbolicLink(),
101
110
  name: entry.name,
102
111
  path: normalize(path)
103
112
  };
@@ -28,8 +28,8 @@ const {
28
28
  } = __cjs_getBuiltinModule("node:fs/promises");
29
29
  import { dirname } from '@visulima/path';
30
30
  import { toPath } from '@visulima/path/utils';
31
- import { F_OK } from './F_OK-BalxCn9n.js';
32
- import isAccessible from './isAccessible-iOp0Bou6.js';
31
+ import { F_OK } from './F_OK-MldBaGxb.js';
32
+ import isAccessible from './isAccessible-DuVrTNFV.js';
33
33
  import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
34
34
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
35
35
  import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
@@ -58,9 +58,7 @@ const writeFile = async (path, content, options) => {
58
58
  await writeFile$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
59
59
  if (pathExists && !options.overwrite) {
60
60
  stat$1 = await stat(path);
61
- if (options.chown === void 0) {
62
- options.chown = { gid: stat$1.gid, uid: stat$1.uid };
63
- }
61
+ options.chown ??= { gid: stat$1.gid, uid: stat$1.uid };
64
62
  await rename(path, `${path}.bak`);
65
63
  }
66
64
  if (options.chown) {
@@ -28,8 +28,8 @@ const {
28
28
  } = __cjs_getBuiltinModule("node:fs");
29
29
  import { dirname } from '@visulima/path';
30
30
  import { toPath } from '@visulima/path/utils';
31
- import { F_OK } from './F_OK-BalxCn9n.js';
32
- import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
31
+ import { F_OK } from './F_OK-MldBaGxb.js';
32
+ import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
33
33
  import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
34
34
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
35
35
  import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
@@ -58,9 +58,7 @@ const writeFileSync = (path, content, options) => {
58
58
  writeFileSync$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
59
59
  if (pathExists && !options.overwrite) {
60
60
  stat = statSync(path);
61
- if (options.chown === void 0) {
62
- options.chown = { gid: stat.gid, uid: stat.uid };
63
- }
61
+ options.chown ??= { gid: stat.gid, uid: stat.uid };
64
62
  renameSync(path, `${path}.bak`);
65
63
  }
66
64
  if (options.chown) {
@@ -0,0 +1,65 @@
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
+ readFile
22
+ } = __cjs_getBuiltinModule("node:fs/promises");
23
+ import { parse, stringify } from 'ini';
24
+ import { R_OK } from './F_OK-MldBaGxb.js';
25
+ import isAccessible from './isAccessible-DuVrTNFV.js';
26
+ import { d as detectIniStyle, m as mergeIniPreservingLines } from './ini-preserve-Dq_Q_Jgb.js';
27
+ import writeFile from './writeFile-B8HX0JIQ.js';
28
+
29
+ const writeIni = async (path, data, options = {}) => {
30
+ const { eol, preserveStyle = true, whitespace, ...rest } = options;
31
+ const { align, bracketedArray, newline, platform, section, sort, ...writeOptions } = rest;
32
+ let resolvedEol = eol;
33
+ let resolvedWhitespace = whitespace;
34
+ let existingText;
35
+ let oldData;
36
+ const accessible = preserveStyle ? await isAccessible(path, R_OK) : false;
37
+ if (accessible) {
38
+ try {
39
+ existingText = await readFile(path, "utf8");
40
+ oldData = parse(existingText, { bracketedArray: bracketedArray ?? true });
41
+ const detected = detectIniStyle(existingText);
42
+ resolvedEol ??= detected.eol;
43
+ resolvedWhitespace ??= detected.whitespace;
44
+ } catch (error) {
45
+ if (error.code !== "ENOENT") {
46
+ throw error;
47
+ }
48
+ }
49
+ }
50
+ const encodeOptions = { align, bracketedArray, newline, platform, section, sort, whitespace: resolvedWhitespace };
51
+ const freshStringify = (value, sectionName) => stringify(value, sectionName === void 0 ? encodeOptions : { ...encodeOptions, section: sectionName });
52
+ let output;
53
+ if (existingText !== void 0 && oldData) {
54
+ output = mergeIniPreservingLines(existingText, oldData, data, freshStringify, {
55
+ eol: resolvedEol ?? "\n"});
56
+ } else {
57
+ output = freshStringify(data, section);
58
+ if (resolvedEol === "\r\n") {
59
+ output = output.replaceAll(/\r?\n/g, "\r\n");
60
+ }
61
+ }
62
+ await writeFile(path, output, writeOptions);
63
+ };
64
+
65
+ export { writeIni as default };
@@ -0,0 +1,64 @@
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
+ readFileSync
22
+ } = __cjs_getBuiltinModule("node:fs");
23
+ import { parse, stringify } from 'ini';
24
+ import { R_OK } from './F_OK-MldBaGxb.js';
25
+ import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
26
+ import { d as detectIniStyle, m as mergeIniPreservingLines } from './ini-preserve-Dq_Q_Jgb.js';
27
+ import writeFileSync from './writeFileSync-DB8vv8xR.js';
28
+
29
+ const writeIniSync = (path, data, options = {}) => {
30
+ const { eol, preserveStyle = true, whitespace, ...rest } = options;
31
+ const { align, bracketedArray, newline, platform, section, sort, ...writeOptions } = rest;
32
+ let resolvedEol = eol;
33
+ let resolvedWhitespace = whitespace;
34
+ let existingText;
35
+ let oldData;
36
+ if (preserveStyle && isAccessibleSync(path, R_OK)) {
37
+ try {
38
+ existingText = readFileSync(path, "utf8");
39
+ oldData = parse(existingText, { bracketedArray: bracketedArray ?? true });
40
+ const detected = detectIniStyle(existingText);
41
+ resolvedEol ??= detected.eol;
42
+ resolvedWhitespace ??= detected.whitespace;
43
+ } catch (error) {
44
+ if (error.code !== "ENOENT") {
45
+ throw error;
46
+ }
47
+ }
48
+ }
49
+ const encodeOptions = { align, bracketedArray, newline, platform, section, sort, whitespace: resolvedWhitespace };
50
+ const freshStringify = (value, sectionName) => stringify(value, sectionName === void 0 ? encodeOptions : { ...encodeOptions, section: sectionName });
51
+ let output;
52
+ if (existingText !== void 0 && oldData) {
53
+ output = mergeIniPreservingLines(existingText, oldData, data, freshStringify, {
54
+ eol: resolvedEol ?? "\n"});
55
+ } else {
56
+ output = freshStringify(data, section);
57
+ if (resolvedEol === "\r\n") {
58
+ output = output.replaceAll(/\r?\n/g, "\r\n");
59
+ }
60
+ }
61
+ writeFileSync(path, output, writeOptions);
62
+ };
63
+
64
+ export { writeIniSync as default };