@visulima/fs 5.0.0-alpha.9 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +459 -0
- package/LICENSE.md +81 -4
- package/README.md +65 -0
- package/dist/eol.d.ts +30 -0
- package/dist/eol.js +3 -26
- package/dist/error.d.ts +243 -13
- package/dist/error.js +1 -7
- package/dist/glob-parent.d.ts +30 -0
- package/dist/glob-parent.js +1 -90
- package/dist/glob.d.ts +3 -4
- package/dist/glob.js +1 -2
- package/dist/index.d.ts +877 -28
- package/dist/index.js +1 -38
- package/dist/ini.d.ts +64 -4
- package/dist/ini.js +1 -4
- package/dist/is-glob.d.ts +29 -0
- package/dist/is-glob.js +1 -9
- package/dist/json5.d.ts +28 -4
- package/dist/json5.js +1 -4
- package/dist/jsonc.d.ts +59 -4
- package/dist/jsonc.js +1 -4
- package/dist/match.d.ts +77 -2
- package/dist/match.js +1 -15
- package/dist/packem_shared/AlreadyExistsError-DEb3UWja.js +1 -0
- package/dist/packem_shared/DirectoryError-BtwSTLmT.js +1 -0
- package/dist/packem_shared/FIND_UP_STOP-CAwY1qU7.js +1 -0
- package/dist/packem_shared/JSONError-Cvp9ycba.js +4 -0
- package/dist/packem_shared/NotEmptyError-DZ1Ix089.js +1 -0
- package/dist/packem_shared/NotFoundError-CnRY6lVp.js +1 -0
- package/dist/packem_shared/PermissionError-DJ_2VWEj.js +1 -0
- package/dist/packem_shared/WalkError-B8qTd-v-.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-CWAkuNXM.js +1 -0
- package/dist/packem_shared/assertValidFileContents-CbIN7sy7.js +1 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-BTlt945W.js +1 -0
- package/dist/packem_shared/build-rm-options-avnusYx-.js +1 -0
- package/dist/packem_shared/collect-CIKDOMiD.js +1 -0
- package/dist/packem_shared/collectSync-D0FRLLqg.js +1 -0
- package/dist/packem_shared/copy-Beb64BYG.js +1 -0
- package/dist/packem_shared/copySync-CagcIEBi.js +1 -0
- package/dist/packem_shared/emptyDir-C7lyd1lW.js +1 -0
- package/dist/packem_shared/emptyDirSync-B8EYpmO9.js +1 -0
- package/dist/packem_shared/ensureDir-DGarVZw8.js +1 -0
- package/dist/packem_shared/ensureDirSync-CsgPrsDH.js +1 -0
- package/dist/packem_shared/ensureFile-CMugWljp.js +1 -0
- package/dist/packem_shared/ensureFileSync-CJYTEx2r.js +1 -0
- package/dist/packem_shared/ensureLink-ChShf3lf.js +1 -0
- package/dist/packem_shared/ensureLinkSync-DPpq0I2Z.js +1 -0
- package/dist/packem_shared/ensureSymlink-y4FZjfxA.js +1 -0
- package/dist/packem_shared/ensureSymlinkSync-TcHssCH7.js +1 -0
- package/dist/packem_shared/findUp-Cii5ATt5.js +1 -0
- package/dist/packem_shared/findUpSync-C9Lkh7-v.js +1 -0
- package/dist/packem_shared/get-file-info-type-DzWpohDB.js +1 -0
- package/dist/packem_shared/glob-fqg4KepW.js +1 -0
- package/dist/packem_shared/glob-sync.d-hXe38TnZ.d.ts +54 -0
- package/dist/packem_shared/globSync-B8_ne93E.js +1 -0
- package/dist/packem_shared/index-B2MhYg3r.js +1 -0
- package/dist/packem_shared/index-BHy3Kcr7.js +11 -0
- package/dist/packem_shared/index-BLg3XWiD.js +1 -0
- package/dist/packem_shared/index-D8MDd0tv.js +1 -0
- package/dist/packem_shared/ini-preserve-D1DopDLd.js +4 -0
- package/dist/packem_shared/is-stats-identical-l1GRN4Qu.js +1 -0
- package/dist/packem_shared/isAccessible-PmWJhV6I.js +1 -0
- package/dist/packem_shared/isAccessibleSync-BrbOtwdr.js +1 -0
- package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +52 -0
- package/dist/packem_shared/jsonc-merge-Bkw73TLW.js +2 -0
- package/dist/packem_shared/map-read-error-CR3rQUxx.js +1 -0
- package/dist/packem_shared/move-DopmzT-2.js +1 -0
- package/dist/packem_shared/parseJson-EASgP4J9.js +1 -0
- package/dist/packem_shared/readFile-BswaBgM0.js +1 -0
- package/dist/packem_shared/readFileSync-_fDF6Oj1.js +1 -0
- package/dist/packem_shared/readIni-BsXudu2r.js +1 -0
- package/dist/packem_shared/readIniSync-DKwRbbs9.js +1 -0
- package/dist/packem_shared/readJson-CcAsHxE5.js +1 -0
- package/dist/packem_shared/readJson5-CM1TIiHd.js +1 -0
- package/dist/packem_shared/readJson5Sync-Bc26c3Fy.js +1 -0
- package/dist/packem_shared/readJsonSync-DuMMeB3s.js +1 -0
- package/dist/packem_shared/readJsonc-BZjMw_0f.js +1 -0
- package/dist/packem_shared/readJsoncSync-C-xzeZz4.js +1 -0
- package/dist/packem_shared/readToml-D4jpe9q_.js +1 -0
- package/dist/packem_shared/readTomlSync-B5PIYT9z.js +1 -0
- package/dist/packem_shared/readYaml-DvPxndW_.js +1 -0
- package/dist/packem_shared/readYamlSync-DZ-0hSbZ.js +1 -0
- package/dist/packem_shared/remove-CSbrd0dl.js +1 -0
- package/dist/packem_shared/removeSync-BoLAzRQE.js +1 -0
- package/dist/packem_shared/renderError-B3ePOoBG-Bi9WKMjv.js +6 -0
- package/dist/packem_shared/resolve-symlink-target-CWrn0v4P.js +1 -0
- package/dist/packem_shared/sanitize-DGZ3w-_w.js +1 -0
- package/dist/packem_shared/stripJsonComments-Bfcn2PKv.js +1 -0
- package/dist/packem_shared/to-uint-8-array-BImOQNXm.js +1 -0
- package/dist/packem_shared/types.d-BMdL_ygj.d.ts +1773 -0
- package/dist/packem_shared/walk-OX4-6oCP.js +1 -0
- package/dist/packem_shared/walk-include-BXhGSn6t.js +1 -0
- package/dist/packem_shared/walkSync-BPs6czIM.js +1 -0
- package/dist/packem_shared/writeFile-BrMtsJY7.js +1 -0
- package/dist/packem_shared/writeFileSync-W7Mf4BNy.js +1 -0
- package/dist/packem_shared/writeIni-BWX3cP1K.js +4 -0
- package/dist/packem_shared/writeIniSync-fOdgPFfL.js +4 -0
- package/dist/packem_shared/writeJson-bEVi25gX.js +4 -0
- package/dist/packem_shared/writeJson5-Ch8TpNPI.js +4 -0
- package/dist/packem_shared/writeJson5Sync-BrctV_Mk.js +4 -0
- package/dist/packem_shared/writeJsonSync-DkGnd416.js +4 -0
- package/dist/packem_shared/writeJsonc-CefrwsOc.js +4 -0
- package/dist/packem_shared/writeJsoncSync-BskDjn8o.js +4 -0
- package/dist/packem_shared/writeToml-IuMO-yDu.js +1 -0
- package/dist/packem_shared/writeTomlSync-DhL7hHzB.js +1 -0
- package/dist/packem_shared/writeYaml-ClQgvQID.js +1 -0
- package/dist/packem_shared/writeYamlSync-DrXtHQQq.js +1 -0
- package/dist/size.d.ts +244 -0
- package/dist/size.js +1 -146
- package/dist/toml.d.ts +57 -3
- package/dist/toml.js +1 -4
- package/dist/utils.d.ts +92 -4
- package/dist/utils.js +1 -6
- package/dist/yaml.d.ts +3 -4
- package/dist/yaml.js +1 -4
- package/package.json +20 -23
- package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
- package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
- package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
- package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
- package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
- package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
- package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
- package/dist/packem_shared/WalkError-DER5A43G.js +0 -24
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +0 -12
- package/dist/packem_shared/collect-CqQ3eVab.js +0 -14
- package/dist/packem_shared/collectSync-noE08NNv.js +0 -14
- package/dist/packem_shared/emptyDir-DnwENOaV.js +0 -46
- package/dist/packem_shared/emptyDirSync-6WiHBo8a.js +0 -43
- package/dist/packem_shared/ensureDir-DNlPftys.js +0 -53
- package/dist/packem_shared/ensureDirSync-DcPZFMy5.js +0 -53
- package/dist/packem_shared/ensureFile-BRQpUOUM.js +0 -47
- package/dist/packem_shared/ensureFileSync-SBY7A9-C.js +0 -47
- package/dist/packem_shared/ensureLink-DJQeauEn.js +0 -55
- package/dist/packem_shared/ensureLinkSync-D9RVAglV.js +0 -55
- package/dist/packem_shared/ensureSymlink-CoRYDRwr.js +0 -80
- package/dist/packem_shared/ensureSymlinkSync-CFimFlgh.js +0 -81
- package/dist/packem_shared/findUp-YcNLKdfV.js +0 -84
- package/dist/packem_shared/findUpSync-BfA5fheN.js +0 -83
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
- package/dist/packem_shared/glob-DY8l7izD.js +0 -5
- package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +0 -4
- package/dist/packem_shared/globSync-5P2KJf_g.js +0 -5
- package/dist/packem_shared/index-C8W8sfzP.js +0 -830
- package/dist/packem_shared/index-CHM-in-V.js +0 -100
- package/dist/packem_shared/index-bhgnhm4u.js +0 -167
- package/dist/packem_shared/index-xe4o3cYi.js +0 -1784
- package/dist/packem_shared/indexToLineColumn-BUb0GPKl-BF770uX7.js +0 -171
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +0 -251
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
- package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
- package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
- package/dist/packem_shared/isFsCaseSensitive-DunL7Iry.js +0 -62
- package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +0 -10
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +0 -72
- package/dist/packem_shared/move-DbpW5_vA.js +0 -134
- package/dist/packem_shared/parseJson-BIp89Xjo.js +0 -63
- package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
- package/dist/packem_shared/readFileSync-gm9yfIhh.js +0 -54
- package/dist/packem_shared/readIni-CJ2xfpjB.js +0 -10
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +0 -10
- package/dist/packem_shared/readJson-C_rwm-wq.js +0 -22
- package/dist/packem_shared/readJson5-mBoTZppy.js +0 -15
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +0 -15
- package/dist/packem_shared/readJsonSync-BMEmCcJ6.js +0 -22
- package/dist/packem_shared/readJsonc-j-OS-APg.js +0 -28
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +0 -16
- package/dist/packem_shared/readToml-B2MHaSes.js +0 -9
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +0 -9
- package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
- package/dist/packem_shared/readYamlSync-BKX-PAfq.js +0 -10
- package/dist/packem_shared/remove-C8_gl3jF.js +0 -39
- package/dist/packem_shared/removeSync-BJR_wTwN.js +0 -39
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
- package/dist/packem_shared/sanitize-BZoLN9Fg.js +0 -205
- package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
- package/dist/packem_shared/types.d-dP-lAGNn.d.ts +0 -145
- package/dist/packem_shared/walk-CSZgCuDx.js +0 -124
- package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
- package/dist/packem_shared/walkSync-C4Cy28xb.js +0 -123
- package/dist/packem_shared/writeFile-B8HX0JIQ.js +0 -81
- package/dist/packem_shared/writeFileSync-DB8vv8xR.js +0 -81
- package/dist/packem_shared/writeIni-i55QrL8y.js +0 -65
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +0 -64
- package/dist/packem_shared/writeJson-Bo7C2UHw.js +0 -50
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +0 -53
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +0 -53
- package/dist/packem_shared/writeJsonSync-BKZ_9Acr.js +0 -50
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +0 -60
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +0 -59
- package/dist/packem_shared/writeToml-DgTW_-7F.js +0 -8
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +0 -8
- package/dist/packem_shared/writeYaml-BWCOome-.js +0 -24
- package/dist/packem_shared/writeYamlSync-DBVnXmuY.js +0 -24
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
|
|
2
|
-
const rawProcess = globalThis.process ?? /* @__PURE__ */ Object.create(null);
|
|
3
|
-
const processShims = {
|
|
4
|
-
versions: {}
|
|
5
|
-
};
|
|
6
|
-
const process = /* @__PURE__ */ new Proxy(rawProcess, {
|
|
7
|
-
get(target, property) {
|
|
8
|
-
if (property in target) {
|
|
9
|
-
return target[property];
|
|
10
|
-
}
|
|
11
|
-
if (property in processShims) {
|
|
12
|
-
return processShims[property];
|
|
13
|
-
}
|
|
14
|
-
return void 0;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const getMarkerLines = (loc, source, linesAbove, linesBelow) => {
|
|
18
|
-
const startLoc = {
|
|
19
|
-
column: 0,
|
|
20
|
-
// @ts-expect-error Can be overwritten
|
|
21
|
-
line: -1,
|
|
22
|
-
...loc.start
|
|
23
|
-
};
|
|
24
|
-
const endLoc = {
|
|
25
|
-
...startLoc,
|
|
26
|
-
...loc.end
|
|
27
|
-
};
|
|
28
|
-
const startLine = startLoc.line;
|
|
29
|
-
const startColumn = startLoc.column;
|
|
30
|
-
const endLine = endLoc.line;
|
|
31
|
-
const endColumn = endLoc.column;
|
|
32
|
-
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
33
|
-
let end = Math.min(source.length, endLine + linesBelow);
|
|
34
|
-
if (startLine === -1) {
|
|
35
|
-
start = 0;
|
|
36
|
-
}
|
|
37
|
-
if (endLine === -1) {
|
|
38
|
-
end = source.length;
|
|
39
|
-
}
|
|
40
|
-
const lineDiff = endLine - startLine;
|
|
41
|
-
const markerLines = {};
|
|
42
|
-
if (lineDiff) {
|
|
43
|
-
for (let index = 0; index <= lineDiff; index++) {
|
|
44
|
-
const lineNumber = index + startLine;
|
|
45
|
-
if (!startColumn) {
|
|
46
|
-
markerLines[lineNumber] = true;
|
|
47
|
-
} else if (index === 0) {
|
|
48
|
-
const sourceLength = source[lineNumber - 1]?.length;
|
|
49
|
-
markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
|
|
50
|
-
} else if (index === lineDiff) {
|
|
51
|
-
markerLines[lineNumber] = [0, endColumn];
|
|
52
|
-
} else {
|
|
53
|
-
const sourceLength = source[lineNumber - index]?.length;
|
|
54
|
-
markerLines[lineNumber] = [0, sourceLength];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
} else if (startColumn === endColumn) {
|
|
58
|
-
markerLines[startLine] = startColumn ? [startColumn, 0] : true;
|
|
59
|
-
} else {
|
|
60
|
-
markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
|
|
61
|
-
}
|
|
62
|
-
return { end, markerLines, start };
|
|
63
|
-
};
|
|
64
|
-
const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
|
|
65
|
-
const codeFrame = (source, loc, options) => {
|
|
66
|
-
const config = {
|
|
67
|
-
// grab 2 lines before, and 3 lines after focused line
|
|
68
|
-
linesAbove: 2,
|
|
69
|
-
linesBelow: 3,
|
|
70
|
-
prefix: "",
|
|
71
|
-
showGutter: true,
|
|
72
|
-
tabWidth: 4,
|
|
73
|
-
...options,
|
|
74
|
-
color: {
|
|
75
|
-
gutter: (value) => value,
|
|
76
|
-
marker: (value) => value,
|
|
77
|
-
message: (value) => value,
|
|
78
|
-
...options?.color
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const hasColumns = typeof loc.start.column === "number";
|
|
82
|
-
let lines = normalizeLF(source).split("\n");
|
|
83
|
-
if (typeof config.tabWidth === "number") {
|
|
84
|
-
lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
|
|
85
|
-
}
|
|
86
|
-
const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
|
|
87
|
-
const numberMaxWidth = String(end).length;
|
|
88
|
-
const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
|
|
89
|
-
let frame = lines.slice(start, end).map((line, index) => {
|
|
90
|
-
const number = start + 1 + index;
|
|
91
|
-
const hasMarker = markerLines[number];
|
|
92
|
-
const paddedNumber = ` ${String(number)}`.slice(-numberMaxWidth);
|
|
93
|
-
const lastMarkerLine = !markerLines[number + 1];
|
|
94
|
-
const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
|
|
95
|
-
if (hasMarker) {
|
|
96
|
-
let markerLine = "";
|
|
97
|
-
if (Array.isArray(hasMarker)) {
|
|
98
|
-
const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
|
|
99
|
-
const numberOfMarkers = hasMarker[1] || 1;
|
|
100
|
-
markerLine = [
|
|
101
|
-
"\n ",
|
|
102
|
-
config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
|
|
103
|
-
" ",
|
|
104
|
-
markerSpacing,
|
|
105
|
-
colorizeMarker("^").repeat(numberOfMarkers)
|
|
106
|
-
].join("");
|
|
107
|
-
if (lastMarkerLine && config.message) {
|
|
108
|
-
markerLine += ` ${colorizeMessage(config.message)}`;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
112
|
-
}
|
|
113
|
-
return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
|
|
114
|
-
}).join("\n");
|
|
115
|
-
if (config.message && !hasColumns) {
|
|
116
|
-
frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
|
|
117
|
-
${frame}`;
|
|
118
|
-
}
|
|
119
|
-
return frame;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const binarySearch = (element, array) => {
|
|
123
|
-
let m = 0;
|
|
124
|
-
let n = array.length - 2;
|
|
125
|
-
while (m < n) {
|
|
126
|
-
const key = m + (n - m >> 1);
|
|
127
|
-
if (element < array[key]) {
|
|
128
|
-
n = key - 1;
|
|
129
|
-
} else if (element >= array[key + 1]) {
|
|
130
|
-
m = key + 1;
|
|
131
|
-
} else {
|
|
132
|
-
m = key;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return m;
|
|
137
|
-
};
|
|
138
|
-
const LINE_BREAK_REGEX = /\n|\r(?!\n)/;
|
|
139
|
-
const getLineStartIndexes = (string_) => (
|
|
140
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
141
|
-
string_.split(LINE_BREAK_REGEX).reduce(
|
|
142
|
-
(accumulator, current) => {
|
|
143
|
-
accumulator.push(accumulator.at(-1) + current.length + 1);
|
|
144
|
-
return accumulator;
|
|
145
|
-
},
|
|
146
|
-
[0]
|
|
147
|
-
)
|
|
148
|
-
);
|
|
149
|
-
const indexToLineColumn = (input, index, options) => {
|
|
150
|
-
if ((!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
|
|
151
|
-
return { column: 0, line: 0 };
|
|
152
|
-
}
|
|
153
|
-
if ((typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
|
|
154
|
-
return { column: 0, line: 0 };
|
|
155
|
-
}
|
|
156
|
-
if (typeof input === "string") {
|
|
157
|
-
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
158
|
-
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
159
|
-
return {
|
|
160
|
-
column: index - startIndexesOfEachLine[line2] + 1,
|
|
161
|
-
line: line2 + 1
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
const line = binarySearch(index, input);
|
|
165
|
-
return {
|
|
166
|
-
column: index - input[line] + 1,
|
|
167
|
-
line: line + 1
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
export { codeFrame as c, indexToLineColumn as i };
|
|
@@ -1,251 +0,0 @@
|
|
|
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 };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
access
|
|
22
|
-
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
23
|
-
import { toPath } from '@visulima/path/utils';
|
|
24
|
-
import { F_OK } from './F_OK-MldBaGxb.js';
|
|
25
|
-
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
26
|
-
|
|
27
|
-
async function isAccessible(path, mode = F_OK) {
|
|
28
|
-
assertValidFileOrDirectoryPath(path);
|
|
29
|
-
path = toPath(path);
|
|
30
|
-
try {
|
|
31
|
-
await access(path, mode);
|
|
32
|
-
return true;
|
|
33
|
-
} catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { isAccessible as default };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
accessSync
|
|
22
|
-
} = __cjs_getBuiltinModule("node:fs");
|
|
23
|
-
import { toPath } from '@visulima/path/utils';
|
|
24
|
-
import { F_OK } from './F_OK-MldBaGxb.js';
|
|
25
|
-
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
26
|
-
|
|
27
|
-
function isAccessibleSync(path, mode = F_OK) {
|
|
28
|
-
assertValidFileOrDirectoryPath(path);
|
|
29
|
-
path = toPath(path);
|
|
30
|
-
try {
|
|
31
|
-
accessSync(path, mode);
|
|
32
|
-
return true;
|
|
33
|
-
} catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { isAccessibleSync as default };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const nativeFs__default = __cjs_getBuiltinModule("fs");
|
|
21
|
-
const require$$2 = __cjs_getBuiltinModule("os");
|
|
22
|
-
const require$$1 = __cjs_getBuiltinModule("path");
|
|
23
|
-
|
|
24
|
-
var l = Object.defineProperty;
|
|
25
|
-
var s = (i, t) => l(i, "name", { value: t, configurable: true });
|
|
26
|
-
const a = s((i) => {
|
|
27
|
-
let t = "";
|
|
28
|
-
for (let e = 0; e < i.length; e += 1) {
|
|
29
|
-
const r = i[e], o = r.toUpperCase();
|
|
30
|
-
t += r === o ? r.toLowerCase() : o;
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
}, "invertCase");
|
|
34
|
-
const c = /* @__PURE__ */ new Map();
|
|
35
|
-
const p = s((i, t) => {
|
|
36
|
-
const e = require$$1.join(i, `.is-fs-case-sensitive-test-${process.pid}`);
|
|
37
|
-
try {
|
|
38
|
-
return t.writeFileSync(e, ""), !t.existsSync(a(e));
|
|
39
|
-
} finally {
|
|
40
|
-
try {
|
|
41
|
-
t.unlinkSync(e);
|
|
42
|
-
} catch {
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}, "checkDirectoryCaseWithWrite");
|
|
46
|
-
const m = s((i, t, e) => {
|
|
47
|
-
try {
|
|
48
|
-
return p(i, e);
|
|
49
|
-
} catch (r) {
|
|
50
|
-
if (t === void 0) return p(require$$2.tmpdir(), e);
|
|
51
|
-
throw r;
|
|
52
|
-
}
|
|
53
|
-
}, "checkDirectoryCaseWithFallback");
|
|
54
|
-
const S = s((i, t = nativeFs__default, e = true) => {
|
|
55
|
-
const r = i ?? process.cwd();
|
|
56
|
-
if (e && c.has(r)) return c.get(r);
|
|
57
|
-
let o;
|
|
58
|
-
const n = a(r);
|
|
59
|
-
return n !== r && t.existsSync(r) ? o = !t.existsSync(n) : o = m(r, i, t), e && c.set(r, o), o;
|
|
60
|
-
}, "isFsCaseSensitive");
|
|
61
|
-
|
|
62
|
-
export { S as isFsCaseSensitive };
|
|
@@ -1,10 +0,0 @@
|
|
|
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 };
|
|
@@ -1,72 +0,0 @@
|
|
|
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 };
|