@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
@@ -1,11 +1,9 @@
1
- import JSONError from './JSONError-BkHRnInH.js';
2
-
3
1
  const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
4
- const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
2
+ const rawProcess = globalThis.process ?? /* @__PURE__ */ Object.create(null);
5
3
  const processShims = {
6
4
  versions: {}
7
5
  };
8
- const process = new Proxy(_process, {
6
+ const process = /* @__PURE__ */ new Proxy(rawProcess, {
9
7
  get(target, property) {
10
8
  if (property in target) {
11
9
  return target[property];
@@ -80,9 +78,9 @@ const codeFrame = (source, loc, options) => {
80
78
  ...options?.color
81
79
  }
82
80
  };
83
- const hasColumns = loc.start && typeof loc.start.column === "number";
81
+ const hasColumns = typeof loc.start.column === "number";
84
82
  let lines = normalizeLF(source).split("\n");
85
- if (typeof config?.tabWidth === "number") {
83
+ if (typeof config.tabWidth === "number") {
86
84
  lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
87
85
  }
88
86
  const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
@@ -91,7 +89,7 @@ const codeFrame = (source, loc, options) => {
91
89
  let frame = lines.slice(start, end).map((line, index) => {
92
90
  const number = start + 1 + index;
93
91
  const hasMarker = markerLines[number];
94
- const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
92
+ const paddedNumber = ` ${String(number)}`.slice(-numberMaxWidth);
95
93
  const lastMarkerLine = !markerLines[number + 1];
96
94
  const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
97
95
  if (hasMarker) {
@@ -137,9 +135,10 @@ const binarySearch = (element, array) => {
137
135
  }
138
136
  return m;
139
137
  };
138
+ const LINE_BREAK_REGEX = /\n|\r(?!\n)/;
140
139
  const getLineStartIndexes = (string_) => (
141
140
  // eslint-disable-next-line unicorn/no-array-reduce
142
- string_.split(/\n|\r(?!\n)/).reduce(
141
+ string_.split(LINE_BREAK_REGEX).reduce(
143
142
  (accumulator, current) => {
144
143
  accumulator.push(accumulator.at(-1) + current.length + 1);
145
144
  return accumulator;
@@ -169,63 +168,4 @@ const indexToLineColumn = (input, index, options) => {
169
168
  };
170
169
  };
171
170
 
172
- const getCodePoint = (character) => String.raw`\u{${character.codePointAt(0).toString(16)}}`;
173
- const generateCodeFrame = (source, location, options) => codeFrame(
174
- source,
175
- { start: location },
176
- {
177
- tabWidth: false,
178
- ...options
179
- }
180
- );
181
- const getErrorLocation = (source, message) => {
182
- const match = /in JSON at position (?<index>\d+)(?: \(line (?<line>\d+) column (?<column>\d+)\))?$/.exec(message);
183
- if (!match) {
184
- return void 0;
185
- }
186
- let { column, index, line } = match.groups;
187
- if (line && column) {
188
- return { column: Number(column), line: Number(line) };
189
- }
190
- index = Number(index);
191
- if (index === source.length) {
192
- index = source.length - 1;
193
- }
194
- return indexToLineColumn(source, index);
195
- };
196
- const addCodePointToUnexpectedToken = (message) => message.replace(
197
- // The token is always quoted after Node.js 20, but we handle both cases for compatibility
198
- // eslint-disable-next-line regexp/no-potentially-useless-backreference
199
- /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/,
200
- (_, _quote, token) => `"${token}"(${getCodePoint(token)})`
201
- );
202
- function parseJson(string, reviver, fileName, options) {
203
- if (typeof reviver === "string") {
204
- if (typeof fileName === "object") {
205
- options = fileName;
206
- }
207
- fileName = reviver;
208
- reviver = void 0;
209
- }
210
- let message;
211
- try {
212
- return JSON.parse(string, reviver);
213
- } catch (error) {
214
- message = error.message;
215
- }
216
- let location;
217
- if (string) {
218
- location = getErrorLocation(string, message);
219
- message = addCodePointToUnexpectedToken(message);
220
- } else {
221
- message += " while parsing empty string";
222
- }
223
- const jsonError = new JSONError(message);
224
- jsonError.fileName = fileName;
225
- if (location) {
226
- jsonError.codeFrame = generateCodeFrame(string, location, options);
227
- }
228
- throw jsonError;
229
- }
230
-
231
- export { parseJson as default };
171
+ export { codeFrame as c, indexToLineColumn as i };
@@ -0,0 +1,251 @@
1
+ const BLANK_OR_COMMENT_REGEX = /^\s*(?:[;#].*)?$/;
2
+ const SECTION_HEADER_REGEX = /^\s*\[([^\]]+)\]\s*$/;
3
+ const LINE_SPLIT_REGEX = /\r?\n/;
4
+ const TRAILING_EOL_REGEX = /\r?\n$/;
5
+ const ENTRY_REGEX = /^[^=]+=/;
6
+ const isWhitespace = (character) => character === " " || character === " ";
7
+ const splitLeadingWhitespace = (source) => {
8
+ let index = 0;
9
+ while (index < source.length && isWhitespace(source[index])) {
10
+ index += 1;
11
+ }
12
+ return { indent: source.slice(0, index), rest: source.slice(index) };
13
+ };
14
+ const splitTrailingWhitespace = (source) => {
15
+ let index = source.length;
16
+ while (index > 0 && isWhitespace(source[index - 1])) {
17
+ index -= 1;
18
+ }
19
+ return { rest: source.slice(0, index), trailing: source.slice(index) };
20
+ };
21
+ const parseKeyValue = (raw) => {
22
+ const equalsIndex = raw.indexOf("=");
23
+ if (equalsIndex === -1) {
24
+ return void 0;
25
+ }
26
+ const leftSide = raw.slice(0, equalsIndex);
27
+ const rightSide = raw.slice(equalsIndex + 1);
28
+ const { indent, rest: keyAndBefore } = splitLeadingWhitespace(leftSide);
29
+ const { rest: key, trailing: before } = splitTrailingWhitespace(keyAndBefore);
30
+ if (key === "" || key.startsWith(";") || key.startsWith("#") || key.startsWith("[")) {
31
+ return void 0;
32
+ }
33
+ const { indent: after, rest: valueAndTrailing } = splitLeadingWhitespace(rightSide);
34
+ const { rest: value, trailing } = splitTrailingWhitespace(valueAndTrailing);
35
+ return { after, before, indent, key, trailing, value };
36
+ };
37
+ const countStyleMatches = (text) => {
38
+ let spaced = 0;
39
+ let unspaced = 0;
40
+ for (const line of text.split(LINE_SPLIT_REGEX)) {
41
+ if (BLANK_OR_COMMENT_REGEX.test(line) || SECTION_HEADER_REGEX.test(line)) {
42
+ continue;
43
+ }
44
+ const parts = parseKeyValue(line);
45
+ if (!parts) {
46
+ continue;
47
+ }
48
+ if (parts.before === " " && parts.after === " ") {
49
+ spaced += 1;
50
+ } else if (parts.before === "" && parts.after === "") {
51
+ unspaced += 1;
52
+ }
53
+ }
54
+ return { spaced, unspaced };
55
+ };
56
+ const getSection = (data, section) => {
57
+ if (!data) {
58
+ return void 0;
59
+ }
60
+ if (section === void 0) {
61
+ return data;
62
+ }
63
+ let cursor = data;
64
+ for (const part of section.split(".")) {
65
+ if (cursor && typeof cursor === "object" && !Array.isArray(cursor)) {
66
+ cursor = cursor[part];
67
+ } else {
68
+ return void 0;
69
+ }
70
+ }
71
+ return cursor && typeof cursor === "object" && !Array.isArray(cursor) ? cursor : void 0;
72
+ };
73
+ const extractValueToken = (serialized, key) => {
74
+ for (const candidate of serialized.split(LINE_SPLIT_REGEX)) {
75
+ if (!candidate || candidate.startsWith("[")) {
76
+ continue;
77
+ }
78
+ const match = ENTRY_REGEX.exec(candidate);
79
+ if (!match) {
80
+ continue;
81
+ }
82
+ const candidateKey = candidate.slice(0, match[0].length - 1).trim();
83
+ if (candidateKey === key || candidateKey === `${key}[]`) {
84
+ return candidate.slice(match[0].length).trimStart();
85
+ }
86
+ }
87
+ return "";
88
+ };
89
+ const classifyLine = (raw, currentSection) => {
90
+ if (raw.trim() === "") {
91
+ return { line: { kind: "blank", raw, section: currentSection }, nextSection: currentSection };
92
+ }
93
+ const trimmed = raw.trimStart();
94
+ if (trimmed.startsWith(";") || trimmed.startsWith("#")) {
95
+ return { line: { kind: "comment", raw, section: currentSection }, nextSection: currentSection };
96
+ }
97
+ const headerMatch = SECTION_HEADER_REGEX.exec(raw);
98
+ if (headerMatch) {
99
+ const nextSection = headerMatch[1];
100
+ return { line: { kind: "header", raw, section: nextSection }, nextSection };
101
+ }
102
+ const parts = parseKeyValue(raw);
103
+ if (parts) {
104
+ return { line: { key: parts.key, kind: "key", raw, section: currentSection }, nextSection: currentSection };
105
+ }
106
+ return { line: { kind: "unknown", raw, section: currentSection }, nextSection: currentSection };
107
+ };
108
+ const parseLines = (original) => {
109
+ const stripped = original.replace(TRAILING_EOL_REGEX, "");
110
+ const rawLines = stripped.split(LINE_SPLIT_REGEX);
111
+ const parsed = [];
112
+ let currentSection;
113
+ for (const raw of rawLines) {
114
+ const { line, nextSection } = classifyLine(raw, currentSection);
115
+ parsed.push(line);
116
+ currentSection = nextSection;
117
+ }
118
+ return parsed;
119
+ };
120
+ const renderChangedKey = (line, newValue, freshStringify) => {
121
+ const parts = parseKeyValue(line.raw);
122
+ if (!parts || !line.key) {
123
+ return line.raw;
124
+ }
125
+ const serialized = freshStringify({ [line.key]: newValue });
126
+ const valueToken = extractValueToken(serialized, line.key);
127
+ return `${parts.indent}${parts.key}${parts.before}=${parts.after}${valueToken}${parts.trailing}`;
128
+ };
129
+ const collectSections = (data, prefix = []) => {
130
+ const sections = [];
131
+ for (const [key, value] of Object.entries(data)) {
132
+ if (value && typeof value === "object" && !Array.isArray(value)) {
133
+ const path = [...prefix, key];
134
+ sections.push(path.join("."), ...collectSections(value, path));
135
+ }
136
+ }
137
+ return sections;
138
+ };
139
+ const pickScalars = (data, skip) => {
140
+ const scalars = {};
141
+ for (const [key, value] of Object.entries(data)) {
142
+ if (skip.has(key) || value && typeof value === "object" && !Array.isArray(value)) {
143
+ continue;
144
+ }
145
+ scalars[key] = value;
146
+ }
147
+ return scalars;
148
+ };
149
+ const appendSerialized = (outputLines, serialized) => {
150
+ const added = [];
151
+ for (const line of serialized.split(LINE_SPLIT_REGEX)) {
152
+ if (line !== "") {
153
+ added.push(line);
154
+ }
155
+ }
156
+ if (added.length > 0) {
157
+ outputLines.push(...added);
158
+ }
159
+ };
160
+ const processKeyLine = (context) => {
161
+ const { line, markWritten, nextData, oldData, renderValue } = context;
162
+ if (!line.key) {
163
+ return line.raw;
164
+ }
165
+ const newSection = getSection(nextData, line.section);
166
+ if (!newSection || !(line.key in newSection)) {
167
+ return void 0;
168
+ }
169
+ markWritten(line.section, line.key);
170
+ const oldSection = getSection(oldData, line.section);
171
+ const oldValue = oldSection?.[line.key];
172
+ const newValue = newSection[line.key];
173
+ if (JSON.stringify(oldValue) === JSON.stringify(newValue)) {
174
+ return line.raw;
175
+ }
176
+ return renderValue(line, newValue);
177
+ };
178
+ const flushAdditions = (outputLines, section, writtenPerSection, nextData, freshStringify) => {
179
+ const sectionData = getSection(nextData, section);
180
+ if (!sectionData) {
181
+ return;
182
+ }
183
+ const written = writtenPerSection.get(section) ?? /* @__PURE__ */ new Set();
184
+ const additions = pickScalars(sectionData, written);
185
+ if (Object.keys(additions).length === 0) {
186
+ return;
187
+ }
188
+ appendSerialized(outputLines, freshStringify(additions));
189
+ };
190
+ const flushNewSections = (outputLines, parsedLines, nextData, freshStringify) => {
191
+ const existingSections = new Set(parsedLines.filter((line) => line.kind === "header" && line.section).map((line) => line.section));
192
+ for (const section of collectSections(nextData)) {
193
+ if (existingSections.has(section)) {
194
+ continue;
195
+ }
196
+ const sectionData = getSection(nextData, section);
197
+ if (!sectionData || Object.keys(sectionData).length === 0) {
198
+ continue;
199
+ }
200
+ const scalars = pickScalars(sectionData, /* @__PURE__ */ new Set());
201
+ if (Object.keys(scalars).length === 0) {
202
+ continue;
203
+ }
204
+ appendSerialized(outputLines, freshStringify(scalars, section));
205
+ }
206
+ };
207
+ const detectIniStyle = (text) => {
208
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
209
+ const { spaced, unspaced } = countStyleMatches(text);
210
+ return { eol, whitespace: spaced > 0 && spaced >= unspaced };
211
+ };
212
+ const mergeIniPreservingLines = (original, oldData, nextData, freshStringify, style) => {
213
+ const { eol } = style;
214
+ const endsWithEol = TRAILING_EOL_REGEX.test(original);
215
+ const parsedLines = parseLines(original);
216
+ const writtenPerSection = /* @__PURE__ */ new Map();
217
+ const sectionLastIndex = /* @__PURE__ */ new Map();
218
+ for (const [index, line] of parsedLines.entries()) {
219
+ if (line.kind !== "blank") {
220
+ sectionLastIndex.set(line.section, index);
221
+ }
222
+ }
223
+ const markWritten = (section, key) => {
224
+ let set = writtenPerSection.get(section);
225
+ if (!set) {
226
+ set = /* @__PURE__ */ new Set();
227
+ writtenPerSection.set(section, set);
228
+ }
229
+ set.add(key);
230
+ };
231
+ const renderValue = (line, value) => renderChangedKey(line, value, freshStringify);
232
+ const outputLines = [];
233
+ for (const [index, line] of parsedLines.entries()) {
234
+ if (line.kind === "key") {
235
+ const rendered = processKeyLine({ line, markWritten, nextData, oldData, renderValue });
236
+ if (rendered !== void 0) {
237
+ outputLines.push(rendered);
238
+ }
239
+ continue;
240
+ }
241
+ outputLines.push(line.raw);
242
+ if (sectionLastIndex.get(line.section) === index) {
243
+ flushAdditions(outputLines, line.section, writtenPerSection, nextData, freshStringify);
244
+ }
245
+ }
246
+ flushNewSections(outputLines, parsedLines, nextData, freshStringify);
247
+ const joined = outputLines.join(eol);
248
+ return endsWithEol && !joined.endsWith(eol) ? `${joined}${eol}` : joined;
249
+ };
250
+
251
+ export { detectIniStyle as d, mergeIniPreservingLines as m };
@@ -21,7 +21,7 @@ const {
21
21
  access
22
22
  } = __cjs_getBuiltinModule("node:fs/promises");
23
23
  import { toPath } from '@visulima/path/utils';
24
- import { F_OK } from './F_OK-BalxCn9n.js';
24
+ import { F_OK } from './F_OK-MldBaGxb.js';
25
25
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
26
26
 
27
27
  async function isAccessible(path, mode = F_OK) {
@@ -21,7 +21,7 @@ const {
21
21
  accessSync
22
22
  } = __cjs_getBuiltinModule("node:fs");
23
23
  import { toPath } from '@visulima/path/utils';
24
- import { F_OK } from './F_OK-BalxCn9n.js';
24
+ import { F_OK } from './F_OK-MldBaGxb.js';
25
25
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
26
26
 
27
27
  function isAccessibleSync(path, mode = F_OK) {
@@ -17,9 +17,9 @@ const __cjs_getBuiltinModule = (module) => {
17
17
  return __cjs_require(module);
18
18
  };
19
19
 
20
- const y = __cjs_getBuiltinModule("fs");
21
- const h = __cjs_getBuiltinModule("os");
22
- const u = __cjs_getBuiltinModule("path");
20
+ const nativeFs__default = __cjs_getBuiltinModule("fs");
21
+ const require$$2 = __cjs_getBuiltinModule("os");
22
+ const require$$1 = __cjs_getBuiltinModule("path");
23
23
 
24
24
  var l = Object.defineProperty;
25
25
  var s = (i, t) => l(i, "name", { value: t, configurable: true });
@@ -33,7 +33,7 @@ const a = s((i) => {
33
33
  }, "invertCase");
34
34
  const c = /* @__PURE__ */ new Map();
35
35
  const p = s((i, t) => {
36
- const e = u.join(i, `.is-fs-case-sensitive-test-${process.pid}`);
36
+ const e = require$$1.join(i, `.is-fs-case-sensitive-test-${process.pid}`);
37
37
  try {
38
38
  return t.writeFileSync(e, ""), !t.existsSync(a(e));
39
39
  } finally {
@@ -47,11 +47,11 @@ const m = s((i, t, e) => {
47
47
  try {
48
48
  return p(i, e);
49
49
  } catch (r) {
50
- if (t === void 0) return p(h.tmpdir(), e);
50
+ if (t === void 0) return p(require$$2.tmpdir(), e);
51
51
  throw r;
52
52
  }
53
53
  }, "checkDirectoryCaseWithFallback");
54
- const S = s((i, t = y, e = true) => {
54
+ const S = s((i, t = nativeFs__default, e = true) => {
55
55
  const r = i ?? process.cwd();
56
56
  if (e && c.has(r)) return c.get(r);
57
57
  let o;
@@ -0,0 +1,10 @@
1
+ declare class JSONError extends Error {
2
+ #private;
3
+ fileName: string | undefined;
4
+ codeFrame: string | undefined;
5
+ readonly name = "JSONError";
6
+ constructor(message: string);
7
+ get message(): string;
8
+ set message(message: string);
9
+ }
10
+ export { JSONError as J };
@@ -0,0 +1,72 @@
1
+ import { parse, modify, applyEdits } from 'jsonc-parser';
2
+
3
+ const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
+ const applyModification = (context, path, value) => {
5
+ const edits = modify(context.text, path, value, { formattingOptions: context.formattingOptions });
6
+ context.text = applyEdits(context.text, edits);
7
+ };
8
+ const walkObject = (context, oldValue, newValue, path, walk) => {
9
+ const keys = /* @__PURE__ */ new Set([...Object.keys(oldValue), ...Object.keys(newValue)]);
10
+ for (const key of keys) {
11
+ const keyPath = [...path, key];
12
+ if (key in newValue) {
13
+ if (key in oldValue) {
14
+ walk(context, oldValue[key], newValue[key], keyPath);
15
+ } else {
16
+ applyModification(context, keyPath, newValue[key]);
17
+ }
18
+ } else {
19
+ applyModification(context, keyPath, void 0);
20
+ }
21
+ }
22
+ };
23
+ const walkValue = (context, oldValue, newValue, path) => {
24
+ if (oldValue === newValue) {
25
+ return;
26
+ }
27
+ if (isPlainObject(oldValue) && isPlainObject(newValue)) {
28
+ walkObject(context, oldValue, newValue, path, walkValue);
29
+ return;
30
+ }
31
+ if (Array.isArray(oldValue) && Array.isArray(newValue) && oldValue.length === newValue.length) {
32
+ for (const [index, oldItem] of oldValue.entries()) {
33
+ walkValue(context, oldItem, newValue[index], [...path, index]);
34
+ }
35
+ return;
36
+ }
37
+ if (JSON.stringify(oldValue) === JSON.stringify(newValue)) {
38
+ return;
39
+ }
40
+ applyModification(context, path, newValue);
41
+ };
42
+ const mergeJsoncPreservingComments = (original, next, formattingOptions) => {
43
+ const existing = parse(original, [], { allowTrailingComma: true });
44
+ const context = { formattingOptions, text: original };
45
+ walkValue(context, existing, next, []);
46
+ return context.text;
47
+ };
48
+ const formattingFromIndent = (indent) => {
49
+ if (typeof indent === "number") {
50
+ return { insertSpaces: true, tabSize: indent };
51
+ }
52
+ if (typeof indent === "string") {
53
+ if (indent === " " || indent.includes(" ")) {
54
+ return { insertSpaces: false, tabSize: indent.length || 1 };
55
+ }
56
+ return { insertSpaces: true, tabSize: indent.length || 2 };
57
+ }
58
+ return { insertSpaces: true, tabSize: 2 };
59
+ };
60
+ const buildJsoncOutput = (existingText, data, preserveComments, indent, trailingNewline, formattingOptions, replacer) => {
61
+ if (preserveComments && existingText !== void 0) {
62
+ const resolvedFormatting = { ...formattingFromIndent(indent), ...formattingOptions };
63
+ let merged = mergeJsoncPreservingComments(existingText, data, resolvedFormatting);
64
+ if (trailingNewline && !merged.endsWith("\n")) {
65
+ merged += trailingNewline;
66
+ }
67
+ return merged;
68
+ }
69
+ return `${JSON.stringify(data, replacer, indent)}${trailingNewline}`;
70
+ };
71
+
72
+ export { buildJsoncOutput as b };
@@ -28,14 +28,14 @@ const {
28
28
  unlink
29
29
  } = __cjs_getBuiltinModule("node:fs/promises");
30
30
  import { dirname, resolve } from '@visulima/path';
31
- import isAccessible from './isAccessible-iOp0Bou6.js';
31
+ import isAccessible from './isAccessible-DuVrTNFV.js';
32
32
  const {
33
33
  mkdirSync,
34
34
  renameSync: renameSync$1,
35
35
  copyFileSync,
36
36
  unlinkSync
37
37
  } = __cjs_getBuiltinModule("node:fs");
38
- import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
38
+ import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
39
39
 
40
40
  class SameDirectoryError extends Error {
41
41
  constructor(source, destination) {
@@ -0,0 +1,63 @@
1
+ import JSONError from './JSONError-BkHRnInH.js';
2
+ import { i as indexToLineColumn, c as codeFrame } from './indexToLineColumn-BUb0GPKl-BF770uX7.js';
3
+
4
+ const getCodePoint = (character) => String.raw`\u{${character.codePointAt(0).toString(16)}}`;
5
+ const generateCodeFrame = (source, location, options) => codeFrame(
6
+ source,
7
+ { start: location },
8
+ {
9
+ tabWidth: false,
10
+ ...options
11
+ }
12
+ );
13
+ const JSON_POSITION_REGEX = /in JSON at position (\d+)(?: \(line (\d+) column (\d+)\))?$/;
14
+ const getErrorLocation = (source, message) => {
15
+ const match = JSON_POSITION_REGEX.exec(message);
16
+ if (!match) {
17
+ return void 0;
18
+ }
19
+ const [, indexString, lineString, columnString] = match;
20
+ if (lineString && columnString) {
21
+ return { column: Number(columnString), line: Number(lineString) };
22
+ }
23
+ let index = Number(indexString);
24
+ if (index === source.length) {
25
+ index = source.length - 1;
26
+ }
27
+ return indexToLineColumn(source, index);
28
+ };
29
+ const UNEXPECTED_TOKEN_REGEX = /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/;
30
+ const addCodePointToUnexpectedToken = (message) => message.replace(
31
+ UNEXPECTED_TOKEN_REGEX,
32
+ (_, _quote, token) => `"${token}"(${getCodePoint(token)})`
33
+ );
34
+ function parseJson(string, reviver, fileName, options) {
35
+ if (typeof reviver === "string") {
36
+ if (typeof fileName === "object") {
37
+ options = fileName;
38
+ }
39
+ fileName = reviver;
40
+ reviver = void 0;
41
+ }
42
+ let message;
43
+ try {
44
+ return JSON.parse(string, reviver);
45
+ } catch (error) {
46
+ message = error.message;
47
+ }
48
+ let location;
49
+ if (string) {
50
+ location = getErrorLocation(string, message);
51
+ message = addCodePointToUnexpectedToken(message);
52
+ } else {
53
+ message += " while parsing empty string";
54
+ }
55
+ const jsonError = new JSONError(message);
56
+ jsonError.fileName = fileName;
57
+ if (location) {
58
+ jsonError.codeFrame = generateCodeFrame(string, location, options);
59
+ }
60
+ throw jsonError;
61
+ }
62
+
63
+ export { parseJson as default };
@@ -25,9 +25,9 @@ const {
25
25
  brotliDecompress
26
26
  } = __cjs_getBuiltinModule("node:zlib");
27
27
  import { toPath } from '@visulima/path/utils';
28
- import { R_OK } from './F_OK-BalxCn9n.js';
28
+ import { R_OK } from './F_OK-MldBaGxb.js';
29
29
  import PermissionError from './PermissionError-CjoiJgip.js';
30
- import isAccessible from './isAccessible-iOp0Bou6.js';
30
+ import isAccessible from './isAccessible-DuVrTNFV.js';
31
31
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
32
32
 
33
33
  const decompressionMethods = {
@@ -25,9 +25,9 @@ const {
25
25
  brotliDecompressSync
26
26
  } = __cjs_getBuiltinModule("node:zlib");
27
27
  import { toPath } from '@visulima/path/utils';
28
- import { R_OK } from './F_OK-BalxCn9n.js';
28
+ import { R_OK } from './F_OK-MldBaGxb.js';
29
29
  import PermissionError from './PermissionError-CjoiJgip.js';
30
- import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
30
+ import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
31
31
  import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
32
32
 
33
33
  const decompressionMethods = {
@@ -46,7 +46,8 @@ const readFileSync = (path, options) => {
46
46
  }
47
47
  const { buffer, compression, encoding, flag } = options ?? {};
48
48
  const content = readFileSync$1(path, flag ? { encoding, flag } : { encoding });
49
- const decompressed = decompressionMethods[compression ?? "none"](content);
49
+ const decompress = decompressionMethods[compression ?? "none"];
50
+ const decompressed = decompress(content);
50
51
  return buffer ? decompressed : decompressed.toString();
51
52
  };
52
53
 
@@ -0,0 +1,10 @@
1
+ import { parse } from 'ini';
2
+ import readFile from './readFile-Iz7kvCCk.js';
3
+
4
+ const readIni = async (path, options) => {
5
+ const { bracketedArray = true, ...readOptions } = options ?? {};
6
+ const content = await readFile(path, { encoding: "utf8", ...readOptions });
7
+ return parse(content, { bracketedArray });
8
+ };
9
+
10
+ export { readIni as default };
@@ -0,0 +1,10 @@
1
+ import { parse } from 'ini';
2
+ import readFileSync from './readFileSync-gm9yfIhh.js';
3
+
4
+ const readIniSync = (path, options) => {
5
+ const { bracketedArray = true, ...readOptions } = options ?? {};
6
+ const content = readFileSync(path, { encoding: "utf8", ...readOptions });
7
+ return parse(content, { bracketedArray });
8
+ };
9
+
10
+ export { readIniSync as default };
@@ -1,6 +1,6 @@
1
1
  import { toPath } from '@visulima/path/utils';
2
- import parseJson from './parseJson-C8xb-3LR.js';
3
- import readFile from './readFile-BcK0rkht.js';
2
+ import parseJson from './parseJson-BIp89Xjo.js';
3
+ import readFile from './readFile-Iz7kvCCk.js';
4
4
 
5
5
  async function readJson(path, reviver, options) {
6
6
  if (typeof reviver === "object") {
@@ -0,0 +1,15 @@
1
+ import JSON5 from 'json5';
2
+ import readFile from './readFile-Iz7kvCCk.js';
3
+
4
+ async function readJson5(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 = await readFile(path, { buffer, compression, encoding, flag });
11
+ const input = typeof beforeParse === "function" ? beforeParse(content) : content;
12
+ return JSON5.parse(input, reviver);
13
+ }
14
+
15
+ export { readJson5 as default };