@visulima/fs 5.0.0-alpha.7 → 5.0.0-alpha.9
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.
- package/CHANGELOG.md +46 -0
- package/LICENSE.md +155 -126
- package/dist/eol.d.ts +6 -35
- package/dist/error.d.ts +43 -7
- package/dist/glob-parent.d.ts +5 -0
- package/dist/glob-parent.js +90 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +2 -0
- package/dist/index.d.ts +81 -36
- package/dist/index.js +16 -11
- package/dist/ini.d.ts +10 -0
- package/dist/ini.js +4 -0
- package/dist/is-glob.d.ts +5 -0
- package/dist/is-glob.js +9 -0
- package/dist/json5.d.ts +12 -0
- package/dist/json5.js +4 -0
- package/dist/jsonc.d.ts +10 -0
- package/dist/jsonc.js +4 -0
- package/dist/match.d.ts +5 -0
- package/dist/match.js +15 -0
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +12 -0
- package/dist/packem_shared/{collect-BnUYRrRI.js → collect-CqQ3eVab.js} +1 -1
- package/dist/packem_shared/{collectSync-D5G2RGDI.js → collectSync-noE08NNv.js} +1 -1
- package/dist/packem_shared/{emptyDir-Df4Tfjtk.js → emptyDir-DnwENOaV.js} +3 -1
- package/dist/packem_shared/{emptyDirSync-BD8-1Ytl.js → emptyDirSync-6WiHBo8a.js} +3 -1
- package/dist/packem_shared/glob-DY8l7izD.js +5 -0
- package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +4 -0
- package/dist/packem_shared/globSync-5P2KJf_g.js +5 -0
- package/dist/packem_shared/index-C8W8sfzP.js +830 -0
- package/dist/packem_shared/index-bhgnhm4u.js +167 -0
- package/dist/packem_shared/index-xe4o3cYi.js +1784 -0
- package/dist/packem_shared/{parseJson-BedVi91S.js → indexToLineColumn-BUb0GPKl-BF770uX7.js} +1 -62
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +251 -0
- package/dist/packem_shared/{isFsCaseSensitive-D-ayleCy.js → isFsCaseSensitive-DunL7Iry.js} +6 -6
- package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +10 -0
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +72 -0
- package/dist/packem_shared/parseJson-BIp89Xjo.js +63 -0
- package/dist/packem_shared/readIni-CJ2xfpjB.js +10 -0
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +10 -0
- package/dist/packem_shared/{readJson-D0G0ndHL.js → readJson-C_rwm-wq.js} +1 -1
- package/dist/packem_shared/readJson5-mBoTZppy.js +15 -0
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +15 -0
- package/dist/packem_shared/{readJsonSync-B7oicPaL.js → readJsonSync-BMEmCcJ6.js} +1 -1
- package/dist/packem_shared/readJsonc-j-OS-APg.js +28 -0
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +16 -0
- package/dist/packem_shared/readToml-B2MHaSes.js +9 -0
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +9 -0
- package/dist/packem_shared/{remove-CNkjFFkQ.js → remove-C8_gl3jF.js} +2 -1
- package/dist/packem_shared/{removeSync-AnawYpPv.js → removeSync-BJR_wTwN.js} +2 -1
- package/dist/packem_shared/types.d-dP-lAGNn.d.ts +145 -0
- package/dist/packem_shared/{walk-D5yHruvk.js → walk-CSZgCuDx.js} +10 -3
- package/dist/packem_shared/{walkSync-09nKPVw4.js → walkSync-C4Cy28xb.js} +10 -3
- package/dist/packem_shared/writeIni-i55QrL8y.js +65 -0
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +64 -0
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +53 -0
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +53 -0
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +60 -0
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +59 -0
- package/dist/packem_shared/writeToml-DgTW_-7F.js +8 -0
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +8 -0
- package/dist/size.d.ts +10 -254
- package/dist/toml.d.ts +9 -0
- package/dist/toml.js +4 -0
- package/dist/utils.d.ts +15 -6
- package/dist/utils.js +1 -1
- package/dist/yaml.d.ts +14 -5
- package/package.json +58 -4
- package/dist/constants.d.ts +0 -42
- package/dist/ensure/ensure-dir-sync.d.ts +0 -14
- package/dist/ensure/ensure-dir.d.ts +0 -14
- package/dist/ensure/ensure-file-sync.d.ts +0 -15
- package/dist/ensure/ensure-file.d.ts +0 -27
- package/dist/ensure/ensure-link-sync.d.ts +0 -16
- package/dist/ensure/ensure-link.d.ts +0 -16
- package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
- package/dist/ensure/ensure-symlink.d.ts +0 -23
- package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
- package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
- package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
- package/dist/error/already-exists-error.d.ts +0 -39
- package/dist/error/directory-error.d.ts +0 -47
- package/dist/error/json-error.d.ts +0 -52
- package/dist/error/not-empty-error.d.ts +0 -51
- package/dist/error/not-found-error.d.ts +0 -44
- package/dist/error/permission-error.d.ts +0 -45
- package/dist/error/walk-error.d.ts +0 -51
- package/dist/find/collect-sync.d.ts +0 -31
- package/dist/find/collect.d.ts +0 -35
- package/dist/find/find-up-sync.d.ts +0 -42
- package/dist/find/find-up.d.ts +0 -46
- package/dist/find/utils/glob-to-regexp.d.ts +0 -2
- package/dist/find/utils/walk-include.d.ts +0 -2
- package/dist/find/walk-sync.d.ts +0 -34
- package/dist/find/walk.d.ts +0 -37
- package/dist/is-accessible-sync.d.ts +0 -3
- package/dist/is-accessible.d.ts +0 -29
- package/dist/move/index.d.ts +0 -68
- package/dist/move/types.d.ts +0 -36
- package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
- package/dist/move/utils/internal-move-file.d.ts +0 -3
- package/dist/move/utils/validate-same-directory.d.ts +0 -2
- package/dist/read/read-file-sync.d.ts +0 -37
- package/dist/read/read-file.d.ts +0 -41
- package/dist/read/read-json-sync.d.ts +0 -5
- package/dist/read/read-json.d.ts +0 -5
- package/dist/read/read-yaml-sync.d.ts +0 -4
- package/dist/read/read-yaml.d.ts +0 -4
- package/dist/remove/empty-dir-sync.d.ts +0 -23
- package/dist/remove/empty-dir.d.ts +0 -28
- package/dist/remove/remove-sync.d.ts +0 -27
- package/dist/remove/remove.d.ts +0 -32
- package/dist/sanitize.d.ts +0 -31
- package/dist/types.d.ts +0 -304
- package/dist/utils/assert-valid-file-contents.d.ts +0 -27
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
- package/dist/utils/parse-json.d.ts +0 -5
- package/dist/utils/strip-json-comments.d.ts +0 -44
- package/dist/write/utils/to-uint-8-array.d.ts +0 -2
- package/dist/write/write-file-sync.d.ts +0 -30
- package/dist/write/write-file.d.ts +0 -30
- package/dist/write/write-json-sync.d.ts +0 -29
- package/dist/write/write-json.d.ts +0 -30
- package/dist/write/write-yaml-sync.d.ts +0 -4
- package/dist/write/write-yaml.d.ts +0 -4
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import JSONError from './JSONError-BkHRnInH.js';
|
|
2
|
-
|
|
3
1
|
const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
|
|
4
2
|
const rawProcess = globalThis.process ?? /* @__PURE__ */ Object.create(null);
|
|
5
3
|
const processShims = {
|
|
@@ -170,63 +168,4 @@ const indexToLineColumn = (input, index, options) => {
|
|
|
170
168
|
};
|
|
171
169
|
};
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
const generateCodeFrame = (source, location, options) => codeFrame(
|
|
175
|
-
source,
|
|
176
|
-
{ start: location },
|
|
177
|
-
{
|
|
178
|
-
tabWidth: false,
|
|
179
|
-
...options
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
const JSON_POSITION_REGEX = /in JSON at position (\d+)(?: \(line (\d+) column (\d+)\))?$/;
|
|
183
|
-
const getErrorLocation = (source, message) => {
|
|
184
|
-
const match = JSON_POSITION_REGEX.exec(message);
|
|
185
|
-
if (!match) {
|
|
186
|
-
return void 0;
|
|
187
|
-
}
|
|
188
|
-
const [, indexString, lineString, columnString] = match;
|
|
189
|
-
if (lineString && columnString) {
|
|
190
|
-
return { column: Number(columnString), line: Number(lineString) };
|
|
191
|
-
}
|
|
192
|
-
let index = Number(indexString);
|
|
193
|
-
if (index === source.length) {
|
|
194
|
-
index = source.length - 1;
|
|
195
|
-
}
|
|
196
|
-
return indexToLineColumn(source, index);
|
|
197
|
-
};
|
|
198
|
-
const UNEXPECTED_TOKEN_REGEX = /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/;
|
|
199
|
-
const addCodePointToUnexpectedToken = (message) => message.replace(
|
|
200
|
-
UNEXPECTED_TOKEN_REGEX,
|
|
201
|
-
(_, _quote, token) => `"${token}"(${getCodePoint(token)})`
|
|
202
|
-
);
|
|
203
|
-
function parseJson(string, reviver, fileName, options) {
|
|
204
|
-
if (typeof reviver === "string") {
|
|
205
|
-
if (typeof fileName === "object") {
|
|
206
|
-
options = fileName;
|
|
207
|
-
}
|
|
208
|
-
fileName = reviver;
|
|
209
|
-
reviver = void 0;
|
|
210
|
-
}
|
|
211
|
-
let message;
|
|
212
|
-
try {
|
|
213
|
-
return JSON.parse(string, reviver);
|
|
214
|
-
} catch (error) {
|
|
215
|
-
message = error.message;
|
|
216
|
-
}
|
|
217
|
-
let location;
|
|
218
|
-
if (string) {
|
|
219
|
-
location = getErrorLocation(string, message);
|
|
220
|
-
message = addCodePointToUnexpectedToken(message);
|
|
221
|
-
} else {
|
|
222
|
-
message += " while parsing empty string";
|
|
223
|
-
}
|
|
224
|
-
const jsonError = new JSONError(message);
|
|
225
|
-
jsonError.fileName = fileName;
|
|
226
|
-
if (location) {
|
|
227
|
-
jsonError.codeFrame = generateCodeFrame(string, location, options);
|
|
228
|
-
}
|
|
229
|
-
throw jsonError;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
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 };
|
|
@@ -17,9 +17,9 @@ const __cjs_getBuiltinModule = (module) => {
|
|
|
17
17
|
return __cjs_require(module);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
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 =
|
|
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(
|
|
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 =
|
|
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 };
|
|
@@ -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 };
|
|
@@ -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 };
|
|
@@ -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 };
|
|
@@ -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 };
|
|
@@ -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 };
|
|
@@ -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,
|
|
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,
|
|
34
|
+
rmSync(path, buildRmOptions(options));
|
|
34
35
|
} catch {
|
|
35
36
|
}
|
|
36
37
|
};
|