@clearlydev/nx-archweave 0.1.1 → 0.2.1
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/README.md +1 -1
- package/dist/eslint/fsd-boundaries.d.ts +25 -8
- package/dist/eslint/fsd-policy.d.ts +38 -0
- package/dist/eslint/index.d.ts +10 -9
- package/dist/eslint/index.js +227 -34
- package/dist/eslint/slice-groups.d.ts +12 -0
- package/dist/generators/add-agent-rules/generator.js +1175 -23
- package/dist/generators/add-backend/generator.js +1127 -75
- package/dist/generators/add-fsd-lite/generator.js +1274 -96
- package/dist/generators/add-review/files/dependabot.yml +7 -0
- package/dist/generators/add-review/generator.js +1100 -46
- package/dist/generators/doctor/generator.js +780 -96
- package/dist/generators/entity/generator.js +251 -32
- package/dist/generators/feature/generator.js +251 -32
- package/dist/generators/init/generator.js +1955 -549
- package/dist/generators/page/generator.js +251 -32
- package/dist/generators/shared/generator.js +251 -32
- package/dist/generators/widget/generator.js +251 -32
- package/package.json +4 -1
- package/src/generators/add-agent-rules/schema.json +5 -0
- package/src/generators/add-fsd-lite/schema.json +2 -2
- package/src/generators/entity/schema.json +11 -1
- package/src/generators/feature/schema.json +11 -1
- package/src/generators/init/schema.json +13 -2
- package/src/generators/page/schema.json +15 -3
- package/src/generators/shared/schema.json +7 -1
- package/src/generators/widget/schema.json +11 -1
- package/dist/eslint/fsd-boundaries.js +0 -144
- package/dist/eslint/tsconfig-aliases.js +0 -114
- package/dist/generators/add-agent-rules/render.js +0 -46
- package/dist/generators/add-backend/render.js +0 -102
- package/dist/generators/add-fsd-lite/render.js +0 -72
- package/dist/generators/add-github-templates/render.js +0 -26
- package/dist/generators/add-integration/render.js +0 -34
- package/dist/generators/add-review/render.js +0 -96
- package/dist/generators/allow-builds/render.js +0 -82
- package/dist/generators/doctor/integration-report.js +0 -70
- package/dist/generators/doctor/render.js +0 -10
- package/dist/generators/init/render.js +0 -125
- package/dist/generators/init/validation.js +0 -74
- package/dist/generators/install-integration/render.js +0 -128
- package/dist/generators/record-integration/render.js +0 -31
- package/dist/generators/shared/dry-run.js +0 -12
- package/dist/generators/shared/frontend-app.js +0 -57
- package/dist/generators/shared/project-type.js +0 -39
- package/dist/generators/shared/record-pipeline.js +0 -34
- package/dist/generators/shared/run-nx.js +0 -24
- package/dist/generators/shared/template-files.js +0 -38
- package/dist/generators/shared/toolkit-config-file.js +0 -110
- package/dist/generators/slice/core.js +0 -185
- package/dist/generators/slice/render.js +0 -70
- package/dist/lib/nx-plugin.js +0 -7
- package/dist/runtime/integrations-composition-root.js +0 -20
- package/dist/runtime/node-command-runner.js +0 -81
|
@@ -148,6 +148,20 @@ function buildReviewConfigSnippet(input) {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
// ../template-engine/dist/review/action-pins.js
|
|
152
|
+
var ACTION_PINS = {
|
|
153
|
+
"actions/checkout": "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
|
|
154
|
+
"actions/setup-node": "actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0",
|
|
155
|
+
"pnpm/action-setup": "pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0",
|
|
156
|
+
"oven-sh/setup-bun": "oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0",
|
|
157
|
+
"anthropics/claude-code-action": "anthropics/claude-code-action@6b6870e649b5ff408753befeaee5fc7989d4e6a9 # v1.0.258",
|
|
158
|
+
"google-github-actions/run-gemini-cli": "google-github-actions/run-gemini-cli@f77273f4c914e4bf38440cf36a0369cb64a37489 # v0.1.22",
|
|
159
|
+
"openai/codex-action": "openai/codex-action@bdf19a4a223ec2549a3e2274a0cf61556bc07675 # v1.13"
|
|
160
|
+
};
|
|
161
|
+
function pinnedUses(action) {
|
|
162
|
+
return ACTION_PINS[action];
|
|
163
|
+
}
|
|
164
|
+
|
|
151
165
|
// ../template-engine/dist/review/workflow-skeleton.js
|
|
152
166
|
function indentBlock(text, spaces) {
|
|
153
167
|
const pad = " ".repeat(spaces);
|
|
@@ -166,6 +180,17 @@ function renderConcurrencyBlock() {
|
|
|
166
180
|
function renderPermissionsBlock() {
|
|
167
181
|
return ["permissions:", " contents: read", " pull-requests: write", " id-token: write"].join("\n");
|
|
168
182
|
}
|
|
183
|
+
function renderCheckoutStep(gateCondition, extraWith = []) {
|
|
184
|
+
return [
|
|
185
|
+
"- name: Checkout repository",
|
|
186
|
+
` if: ${gateCondition}`,
|
|
187
|
+
` uses: ${pinnedUses("actions/checkout")}`,
|
|
188
|
+
" with:",
|
|
189
|
+
...extraWith.map((line) => ` ${line}`),
|
|
190
|
+
" fetch-depth: 1",
|
|
191
|
+
" persist-credentials: false"
|
|
192
|
+
].join("\n");
|
|
193
|
+
}
|
|
169
194
|
function renderSecretGateStep(secretName) {
|
|
170
195
|
return [
|
|
171
196
|
"- name: Check review secret",
|
|
@@ -189,7 +214,7 @@ function renderRoundGateStep(maxRounds) {
|
|
|
189
214
|
" env:",
|
|
190
215
|
" GH_TOKEN: ${{ github.token }}",
|
|
191
216
|
" run: |",
|
|
192
|
-
` counts=$(gh api "repos/\${{ github.repository }}/issues/\${{ github.event.pull_request.number }}/comments" --paginate --jq '[([.[] | select(.body | contains("${ROUND_MARKER}"))] | length), ([.[].id] | max // 0)]' | jq -s -r '[(map(.[0]) | add // 0), (map(.[1]) | max // 0)] | @tsv')`,
|
|
217
|
+
` counts=$(gh api "repos/\${{ github.repository }}/issues/\${{ github.event.pull_request.number }}/comments" --paginate --jq '[([.[] | select(.user.type == "Bot") | select(.body | contains("${ROUND_MARKER}"))] | length), ([.[].id] | max // 0)]' | jq -s -r '[(map(.[0]) | add // 0), (map(.[1]) | max // 0)] | @tsv')`,
|
|
193
218
|
` rounds=$(printf '%s' "$counts" | cut -f1)`,
|
|
194
219
|
` echo "last-comment-id=$(printf '%s' "$counts" | cut -f2)" >> "$GITHUB_OUTPUT"`,
|
|
195
220
|
` if [ "$rounds" -ge ${maxRounds} ]; then`,
|
|
@@ -221,8 +246,7 @@ function renderVerdictGateStep(maxRounds, locale) {
|
|
|
221
246
|
].join("\n");
|
|
222
247
|
}
|
|
223
248
|
var SETUP_NODE_VERSION = "22";
|
|
224
|
-
var
|
|
225
|
-
var SETUP_BUN_ACTION = "oven-sh/setup-bun@v2";
|
|
249
|
+
var FALLBACK_PNPM_VERSION = "10";
|
|
226
250
|
var INSTALL_LINES = {
|
|
227
251
|
pnpm: [" pnpm install --frozen-lockfile"],
|
|
228
252
|
npm: [" npm ci"],
|
|
@@ -232,19 +256,39 @@ var INSTALL_LINES = {
|
|
|
232
256
|
],
|
|
233
257
|
bun: [" bun install --frozen-lockfile"]
|
|
234
258
|
};
|
|
259
|
+
function renderPnpmVersionStep(gate) {
|
|
260
|
+
return [
|
|
261
|
+
"- name: Detect pnpm version",
|
|
262
|
+
" id: pnpm-version",
|
|
263
|
+
gate,
|
|
264
|
+
" run: |",
|
|
265
|
+
` if [ -n "$(jq -r '.packageManager // empty' package.json)" ]; then`,
|
|
266
|
+
' echo "version=" >> "$GITHUB_OUTPUT"',
|
|
267
|
+
" else",
|
|
268
|
+
` echo "version=${FALLBACK_PNPM_VERSION}" >> "$GITHUB_OUTPUT"`,
|
|
269
|
+
" fi"
|
|
270
|
+
].join("\n");
|
|
271
|
+
}
|
|
235
272
|
function renderWorkspaceSetupSteps(packageManager) {
|
|
236
273
|
const gate = " if: steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'";
|
|
237
274
|
const steps = [];
|
|
238
275
|
if (packageManager === "pnpm") {
|
|
239
|
-
steps.push(
|
|
276
|
+
steps.push(renderPnpmVersionStep(gate));
|
|
277
|
+
steps.push([
|
|
278
|
+
"- name: Set up pnpm",
|
|
279
|
+
gate,
|
|
280
|
+
` uses: ${pinnedUses("pnpm/action-setup")}`,
|
|
281
|
+
" with:",
|
|
282
|
+
" version: ${{ steps.pnpm-version.outputs.version }}"
|
|
283
|
+
].join("\n"));
|
|
240
284
|
}
|
|
241
285
|
if (packageManager === "bun") {
|
|
242
|
-
steps.push(["- name: Set up bun", gate, ` uses: ${
|
|
286
|
+
steps.push(["- name: Set up bun", gate, ` uses: ${pinnedUses("oven-sh/setup-bun")}`].join("\n"));
|
|
243
287
|
}
|
|
244
288
|
steps.push([
|
|
245
289
|
"- name: Set up Node",
|
|
246
290
|
gate,
|
|
247
|
-
|
|
291
|
+
` uses: ${pinnedUses("actions/setup-node")}`,
|
|
248
292
|
" with:",
|
|
249
293
|
` node-version: ${SETUP_NODE_VERSION}`,
|
|
250
294
|
// yarn: no setup-node cache — it would query the runner's global yarn 1 even in a
|
|
@@ -296,17 +340,11 @@ function buildWorkflowYaml(input) {
|
|
|
296
340
|
const steps = [
|
|
297
341
|
renderSecretGateStep(SECRET_NAME),
|
|
298
342
|
renderRoundGateStep(input.maxRounds),
|
|
299
|
-
|
|
300
|
-
"- name: Checkout repository",
|
|
301
|
-
" if: steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'",
|
|
302
|
-
" uses: actions/checkout@v4",
|
|
303
|
-
" with:",
|
|
304
|
-
" fetch-depth: 1"
|
|
305
|
-
].join("\n"),
|
|
343
|
+
renderCheckoutStep("steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'"),
|
|
306
344
|
[
|
|
307
345
|
"- name: Run Claude review",
|
|
308
346
|
" if: steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'",
|
|
309
|
-
|
|
347
|
+
` uses: ${pinnedUses("anthropics/claude-code-action")}`,
|
|
310
348
|
" with:",
|
|
311
349
|
` claude_code_oauth_token: \${{ secrets.${SECRET_NAME} }}`,
|
|
312
350
|
" prompt: |",
|
|
@@ -376,13 +414,7 @@ function buildWorkflowYaml2(input) {
|
|
|
376
414
|
const steps = [
|
|
377
415
|
renderSecretGateStep(SECRET_NAME2),
|
|
378
416
|
renderRoundGateStep(input.maxRounds),
|
|
379
|
-
|
|
380
|
-
"- name: Checkout repository",
|
|
381
|
-
` if: ${gateCondition}`,
|
|
382
|
-
" uses: actions/checkout@v4",
|
|
383
|
-
" with:",
|
|
384
|
-
" fetch-depth: 1"
|
|
385
|
-
].join("\n"),
|
|
417
|
+
renderCheckoutStep(gateCondition),
|
|
386
418
|
[
|
|
387
419
|
"- name: Install cursor-agent CLI",
|
|
388
420
|
` if: ${gateCondition}`,
|
|
@@ -462,17 +494,11 @@ function buildWorkflowYaml3(input) {
|
|
|
462
494
|
const steps = [
|
|
463
495
|
renderSecretGateStep(SECRET_NAME3),
|
|
464
496
|
renderRoundGateStep(input.maxRounds),
|
|
465
|
-
|
|
466
|
-
"- name: Checkout repository",
|
|
467
|
-
" if: steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'",
|
|
468
|
-
" uses: actions/checkout@v4",
|
|
469
|
-
" with:",
|
|
470
|
-
" fetch-depth: 1"
|
|
471
|
-
].join("\n"),
|
|
497
|
+
renderCheckoutStep("steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'"),
|
|
472
498
|
[
|
|
473
499
|
"- name: Run Gemini review",
|
|
474
500
|
" if: steps.secret-gate.outputs.enabled == 'true' && steps.round-gate.outputs.allowed == 'true'",
|
|
475
|
-
|
|
501
|
+
` uses: ${pinnedUses("google-github-actions/run-gemini-cli")}`,
|
|
476
502
|
" env:",
|
|
477
503
|
" GITHUB_TOKEN: ${{ github.token }}",
|
|
478
504
|
" with:",
|
|
@@ -541,15 +567,7 @@ function buildWorkflowYaml4(input) {
|
|
|
541
567
|
const steps = [
|
|
542
568
|
renderSecretGateStep(SECRET_NAME4),
|
|
543
569
|
renderRoundGateStep(input.maxRounds),
|
|
544
|
-
[
|
|
545
|
-
"- name: Checkout repository",
|
|
546
|
-
` if: ${gateCondition}`,
|
|
547
|
-
" uses: actions/checkout@v4",
|
|
548
|
-
" with:",
|
|
549
|
-
" ref: refs/pull/${{ github.event.pull_request.number }}/merge",
|
|
550
|
-
" fetch-depth: 1",
|
|
551
|
-
" persist-credentials: false"
|
|
552
|
-
].join("\n"),
|
|
570
|
+
renderCheckoutStep(gateCondition, ["ref: refs/pull/${{ github.event.pull_request.number }}/merge"]),
|
|
553
571
|
[
|
|
554
572
|
"- name: Fetch base and head refs for the PR",
|
|
555
573
|
` if: ${gateCondition}`,
|
|
@@ -567,7 +585,7 @@ function buildWorkflowYaml4(input) {
|
|
|
567
585
|
"- name: Run Codex review",
|
|
568
586
|
" id: codex-review",
|
|
569
587
|
` if: ${gateCondition}`,
|
|
570
|
-
|
|
588
|
+
` uses: ${pinnedUses("openai/codex-action")}`,
|
|
571
589
|
" with:",
|
|
572
590
|
` openai-api-key: \${{ secrets.${SECRET_NAME4} }}`,
|
|
573
591
|
' permission-profile: ":read-only"',
|
|
@@ -646,7 +664,954 @@ function resolveDryRun(options) {
|
|
|
646
664
|
return process.env["NX_DRY_RUN"] === "true" || (options.dryRun ?? false);
|
|
647
665
|
}
|
|
648
666
|
|
|
649
|
-
// src/generators/shared/
|
|
667
|
+
// src/generators/shared/template-files.ts
|
|
668
|
+
import { existsSync } from "node:fs";
|
|
669
|
+
import { fileURLToPath } from "node:url";
|
|
670
|
+
import { generateFiles } from "@nx/devkit";
|
|
671
|
+
import { createTree } from "@nx/devkit/testing";
|
|
672
|
+
function generatorFilesDir(generator, fromUrl) {
|
|
673
|
+
for (const relative of [`../${generator}/files`, `./generators/${generator}/files`]) {
|
|
674
|
+
const dir = fileURLToPath(new URL(relative, fromUrl));
|
|
675
|
+
if (existsSync(dir)) return dir;
|
|
676
|
+
}
|
|
677
|
+
throw new Error(`The "${generator}" generator's template files are missing next to ${fileURLToPath(fromUrl)}`);
|
|
678
|
+
}
|
|
679
|
+
function renderTemplateFiles(srcFolder, target, substitutions) {
|
|
680
|
+
const scratch = createTree();
|
|
681
|
+
const seeded = new Set(scratch.listChanges().map((change) => change.path));
|
|
682
|
+
generateFiles(scratch, srcFolder, target, substitutions);
|
|
683
|
+
return scratch.listChanges().flatMap(
|
|
684
|
+
(change) => change.type === "CREATE" && change.content !== null && !seeded.has(change.path) ? [{ filePath: change.path, content: change.content.toString("utf-8") }] : []
|
|
685
|
+
).sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
689
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
690
|
+
const len = text.length;
|
|
691
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
692
|
+
function scanHexDigits(count, exact) {
|
|
693
|
+
let digits = 0;
|
|
694
|
+
let value2 = 0;
|
|
695
|
+
while (digits < count || !exact) {
|
|
696
|
+
let ch = text.charCodeAt(pos);
|
|
697
|
+
if (ch >= 48 && ch <= 57) {
|
|
698
|
+
value2 = value2 * 16 + ch - 48;
|
|
699
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
700
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
701
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
702
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
703
|
+
} else {
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
pos++;
|
|
707
|
+
digits++;
|
|
708
|
+
}
|
|
709
|
+
if (digits < count) {
|
|
710
|
+
value2 = -1;
|
|
711
|
+
}
|
|
712
|
+
return value2;
|
|
713
|
+
}
|
|
714
|
+
function setPosition(newPosition) {
|
|
715
|
+
pos = newPosition;
|
|
716
|
+
value = "";
|
|
717
|
+
tokenOffset = 0;
|
|
718
|
+
token = 16;
|
|
719
|
+
scanError = 0;
|
|
720
|
+
}
|
|
721
|
+
function scanNumber() {
|
|
722
|
+
let start = pos;
|
|
723
|
+
if (text.charCodeAt(pos) === 48) {
|
|
724
|
+
pos++;
|
|
725
|
+
} else {
|
|
726
|
+
pos++;
|
|
727
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
728
|
+
pos++;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
732
|
+
pos++;
|
|
733
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
734
|
+
pos++;
|
|
735
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
736
|
+
pos++;
|
|
737
|
+
}
|
|
738
|
+
} else {
|
|
739
|
+
scanError = 3;
|
|
740
|
+
return text.substring(start, pos);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
let end = pos;
|
|
744
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
745
|
+
pos++;
|
|
746
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
747
|
+
pos++;
|
|
748
|
+
}
|
|
749
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
750
|
+
pos++;
|
|
751
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
752
|
+
pos++;
|
|
753
|
+
}
|
|
754
|
+
end = pos;
|
|
755
|
+
} else {
|
|
756
|
+
scanError = 3;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return text.substring(start, end);
|
|
760
|
+
}
|
|
761
|
+
function scanString() {
|
|
762
|
+
let result = "", start = pos;
|
|
763
|
+
while (true) {
|
|
764
|
+
if (pos >= len) {
|
|
765
|
+
result += text.substring(start, pos);
|
|
766
|
+
scanError = 2;
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
const ch = text.charCodeAt(pos);
|
|
770
|
+
if (ch === 34) {
|
|
771
|
+
result += text.substring(start, pos);
|
|
772
|
+
pos++;
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
if (ch === 92) {
|
|
776
|
+
result += text.substring(start, pos);
|
|
777
|
+
pos++;
|
|
778
|
+
if (pos >= len) {
|
|
779
|
+
scanError = 2;
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
const ch2 = text.charCodeAt(pos++);
|
|
783
|
+
switch (ch2) {
|
|
784
|
+
case 34:
|
|
785
|
+
result += '"';
|
|
786
|
+
break;
|
|
787
|
+
case 92:
|
|
788
|
+
result += "\\";
|
|
789
|
+
break;
|
|
790
|
+
case 47:
|
|
791
|
+
result += "/";
|
|
792
|
+
break;
|
|
793
|
+
case 98:
|
|
794
|
+
result += "\b";
|
|
795
|
+
break;
|
|
796
|
+
case 102:
|
|
797
|
+
result += "\f";
|
|
798
|
+
break;
|
|
799
|
+
case 110:
|
|
800
|
+
result += "\n";
|
|
801
|
+
break;
|
|
802
|
+
case 114:
|
|
803
|
+
result += "\r";
|
|
804
|
+
break;
|
|
805
|
+
case 116:
|
|
806
|
+
result += " ";
|
|
807
|
+
break;
|
|
808
|
+
case 117:
|
|
809
|
+
const ch3 = scanHexDigits(4, true);
|
|
810
|
+
if (ch3 >= 0) {
|
|
811
|
+
result += String.fromCharCode(ch3);
|
|
812
|
+
} else {
|
|
813
|
+
scanError = 4;
|
|
814
|
+
}
|
|
815
|
+
break;
|
|
816
|
+
default:
|
|
817
|
+
scanError = 5;
|
|
818
|
+
}
|
|
819
|
+
start = pos;
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
if (ch >= 0 && ch <= 31) {
|
|
823
|
+
if (isLineBreak(ch)) {
|
|
824
|
+
result += text.substring(start, pos);
|
|
825
|
+
scanError = 2;
|
|
826
|
+
break;
|
|
827
|
+
} else {
|
|
828
|
+
scanError = 6;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
pos++;
|
|
832
|
+
}
|
|
833
|
+
return result;
|
|
834
|
+
}
|
|
835
|
+
function scanNext() {
|
|
836
|
+
value = "";
|
|
837
|
+
scanError = 0;
|
|
838
|
+
tokenOffset = pos;
|
|
839
|
+
lineStartOffset = lineNumber;
|
|
840
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
841
|
+
if (pos >= len) {
|
|
842
|
+
tokenOffset = len;
|
|
843
|
+
return token = 17;
|
|
844
|
+
}
|
|
845
|
+
let code = text.charCodeAt(pos);
|
|
846
|
+
if (isWhiteSpace(code)) {
|
|
847
|
+
do {
|
|
848
|
+
pos++;
|
|
849
|
+
value += String.fromCharCode(code);
|
|
850
|
+
code = text.charCodeAt(pos);
|
|
851
|
+
} while (isWhiteSpace(code));
|
|
852
|
+
return token = 15;
|
|
853
|
+
}
|
|
854
|
+
if (isLineBreak(code)) {
|
|
855
|
+
pos++;
|
|
856
|
+
value += String.fromCharCode(code);
|
|
857
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
858
|
+
pos++;
|
|
859
|
+
value += "\n";
|
|
860
|
+
}
|
|
861
|
+
lineNumber++;
|
|
862
|
+
tokenLineStartOffset = pos;
|
|
863
|
+
return token = 14;
|
|
864
|
+
}
|
|
865
|
+
switch (code) {
|
|
866
|
+
// tokens: []{}:,
|
|
867
|
+
case 123:
|
|
868
|
+
pos++;
|
|
869
|
+
return token = 1;
|
|
870
|
+
case 125:
|
|
871
|
+
pos++;
|
|
872
|
+
return token = 2;
|
|
873
|
+
case 91:
|
|
874
|
+
pos++;
|
|
875
|
+
return token = 3;
|
|
876
|
+
case 93:
|
|
877
|
+
pos++;
|
|
878
|
+
return token = 4;
|
|
879
|
+
case 58:
|
|
880
|
+
pos++;
|
|
881
|
+
return token = 6;
|
|
882
|
+
case 44:
|
|
883
|
+
pos++;
|
|
884
|
+
return token = 5;
|
|
885
|
+
// strings
|
|
886
|
+
case 34:
|
|
887
|
+
pos++;
|
|
888
|
+
value = scanString();
|
|
889
|
+
return token = 10;
|
|
890
|
+
// comments
|
|
891
|
+
case 47:
|
|
892
|
+
const start = pos - 1;
|
|
893
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
894
|
+
pos += 2;
|
|
895
|
+
while (pos < len) {
|
|
896
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
pos++;
|
|
900
|
+
}
|
|
901
|
+
value = text.substring(start, pos);
|
|
902
|
+
return token = 12;
|
|
903
|
+
}
|
|
904
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
905
|
+
pos += 2;
|
|
906
|
+
const safeLength = len - 1;
|
|
907
|
+
let commentClosed = false;
|
|
908
|
+
while (pos < safeLength) {
|
|
909
|
+
const ch = text.charCodeAt(pos);
|
|
910
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
911
|
+
pos += 2;
|
|
912
|
+
commentClosed = true;
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
915
|
+
pos++;
|
|
916
|
+
if (isLineBreak(ch)) {
|
|
917
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
918
|
+
pos++;
|
|
919
|
+
}
|
|
920
|
+
lineNumber++;
|
|
921
|
+
tokenLineStartOffset = pos;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (!commentClosed) {
|
|
925
|
+
pos++;
|
|
926
|
+
scanError = 1;
|
|
927
|
+
}
|
|
928
|
+
value = text.substring(start, pos);
|
|
929
|
+
return token = 13;
|
|
930
|
+
}
|
|
931
|
+
value += String.fromCharCode(code);
|
|
932
|
+
pos++;
|
|
933
|
+
return token = 16;
|
|
934
|
+
// numbers
|
|
935
|
+
case 45:
|
|
936
|
+
value += String.fromCharCode(code);
|
|
937
|
+
pos++;
|
|
938
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
939
|
+
return token = 16;
|
|
940
|
+
}
|
|
941
|
+
// found a minus, followed by a number so
|
|
942
|
+
// we fall through to proceed with scanning
|
|
943
|
+
// numbers
|
|
944
|
+
case 48:
|
|
945
|
+
case 49:
|
|
946
|
+
case 50:
|
|
947
|
+
case 51:
|
|
948
|
+
case 52:
|
|
949
|
+
case 53:
|
|
950
|
+
case 54:
|
|
951
|
+
case 55:
|
|
952
|
+
case 56:
|
|
953
|
+
case 57:
|
|
954
|
+
value += scanNumber();
|
|
955
|
+
return token = 11;
|
|
956
|
+
// literals and unknown symbols
|
|
957
|
+
default:
|
|
958
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
959
|
+
pos++;
|
|
960
|
+
code = text.charCodeAt(pos);
|
|
961
|
+
}
|
|
962
|
+
if (tokenOffset !== pos) {
|
|
963
|
+
value = text.substring(tokenOffset, pos);
|
|
964
|
+
switch (value) {
|
|
965
|
+
case "true":
|
|
966
|
+
return token = 8;
|
|
967
|
+
case "false":
|
|
968
|
+
return token = 9;
|
|
969
|
+
case "null":
|
|
970
|
+
return token = 7;
|
|
971
|
+
}
|
|
972
|
+
return token = 16;
|
|
973
|
+
}
|
|
974
|
+
value += String.fromCharCode(code);
|
|
975
|
+
pos++;
|
|
976
|
+
return token = 16;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
function isUnknownContentCharacter(code) {
|
|
980
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
switch (code) {
|
|
984
|
+
case 125:
|
|
985
|
+
case 93:
|
|
986
|
+
case 123:
|
|
987
|
+
case 91:
|
|
988
|
+
case 34:
|
|
989
|
+
case 58:
|
|
990
|
+
case 44:
|
|
991
|
+
case 47:
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
return true;
|
|
995
|
+
}
|
|
996
|
+
function scanNextNonTrivia() {
|
|
997
|
+
let result;
|
|
998
|
+
do {
|
|
999
|
+
result = scanNext();
|
|
1000
|
+
} while (result >= 12 && result <= 15);
|
|
1001
|
+
return result;
|
|
1002
|
+
}
|
|
1003
|
+
return {
|
|
1004
|
+
setPosition,
|
|
1005
|
+
getPosition: () => pos,
|
|
1006
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
1007
|
+
getToken: () => token,
|
|
1008
|
+
getTokenValue: () => value,
|
|
1009
|
+
getTokenOffset: () => tokenOffset,
|
|
1010
|
+
getTokenLength: () => pos - tokenOffset,
|
|
1011
|
+
getTokenStartLine: () => lineStartOffset,
|
|
1012
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
1013
|
+
getTokenError: () => scanError
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function isWhiteSpace(ch) {
|
|
1017
|
+
return ch === 32 || ch === 9;
|
|
1018
|
+
}
|
|
1019
|
+
function isLineBreak(ch) {
|
|
1020
|
+
return ch === 10 || ch === 13;
|
|
1021
|
+
}
|
|
1022
|
+
function isDigit(ch) {
|
|
1023
|
+
return ch >= 48 && ch <= 57;
|
|
1024
|
+
}
|
|
1025
|
+
var CharacterCodes;
|
|
1026
|
+
(function(CharacterCodes2) {
|
|
1027
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
1028
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
1029
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
1030
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
1031
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
1032
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
1033
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
1034
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
1035
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
1036
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
1037
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
1038
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
1039
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
1040
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
1041
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
1042
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
1043
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
1044
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
1045
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
1046
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
1047
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
1048
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
1049
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
1050
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
1051
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
1052
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
1053
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
1054
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
1055
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
1056
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
1057
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
1058
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
1059
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
1060
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
1061
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
1062
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
1063
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
1064
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
1065
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
1066
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
1067
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
1068
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
1069
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
1070
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
1071
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
1072
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
1073
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
1074
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
1075
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
1076
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
1077
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
1078
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
1079
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
1080
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
1081
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
1082
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
1083
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
1084
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
1085
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
1086
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
1087
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
1088
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
1089
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
1090
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
1091
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
1092
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
1093
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
1094
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
1095
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
1096
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
1097
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
1098
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
1099
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
1100
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
1101
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
1102
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
1103
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
1104
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
1105
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
1106
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
1107
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
1108
|
+
|
|
1109
|
+
// ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
1110
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
1111
|
+
return " ".repeat(index);
|
|
1112
|
+
});
|
|
1113
|
+
var maxCachedValues = 200;
|
|
1114
|
+
var cachedBreakLinesWithSpaces = {
|
|
1115
|
+
" ": {
|
|
1116
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1117
|
+
return "\n" + " ".repeat(index);
|
|
1118
|
+
}),
|
|
1119
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1120
|
+
return "\r" + " ".repeat(index);
|
|
1121
|
+
}),
|
|
1122
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1123
|
+
return "\r\n" + " ".repeat(index);
|
|
1124
|
+
})
|
|
1125
|
+
},
|
|
1126
|
+
" ": {
|
|
1127
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1128
|
+
return "\n" + " ".repeat(index);
|
|
1129
|
+
}),
|
|
1130
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1131
|
+
return "\r" + " ".repeat(index);
|
|
1132
|
+
}),
|
|
1133
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1134
|
+
return "\r\n" + " ".repeat(index);
|
|
1135
|
+
})
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
// ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
1140
|
+
var ParseOptions;
|
|
1141
|
+
(function(ParseOptions2) {
|
|
1142
|
+
ParseOptions2.DEFAULT = {
|
|
1143
|
+
allowTrailingComma: false
|
|
1144
|
+
};
|
|
1145
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
1146
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1147
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
|
|
1148
|
+
function ensurePropertyComplete(endOffset) {
|
|
1149
|
+
if (currentParent.type === "property") {
|
|
1150
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
1151
|
+
currentParent = currentParent.parent;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
function onValue(valueNode) {
|
|
1155
|
+
currentParent.children.push(valueNode);
|
|
1156
|
+
return valueNode;
|
|
1157
|
+
}
|
|
1158
|
+
const visitor = {
|
|
1159
|
+
onObjectBegin: (offset) => {
|
|
1160
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
1161
|
+
},
|
|
1162
|
+
onObjectProperty: (name, offset, length) => {
|
|
1163
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
1164
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
1165
|
+
},
|
|
1166
|
+
onObjectEnd: (offset, length) => {
|
|
1167
|
+
ensurePropertyComplete(offset + length);
|
|
1168
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1169
|
+
currentParent = currentParent.parent;
|
|
1170
|
+
ensurePropertyComplete(offset + length);
|
|
1171
|
+
},
|
|
1172
|
+
onArrayBegin: (offset, length) => {
|
|
1173
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
1174
|
+
},
|
|
1175
|
+
onArrayEnd: (offset, length) => {
|
|
1176
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1177
|
+
currentParent = currentParent.parent;
|
|
1178
|
+
ensurePropertyComplete(offset + length);
|
|
1179
|
+
},
|
|
1180
|
+
onLiteralValue: (value, offset, length) => {
|
|
1181
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
1182
|
+
ensurePropertyComplete(offset + length);
|
|
1183
|
+
},
|
|
1184
|
+
onSeparator: (sep, offset, length) => {
|
|
1185
|
+
if (currentParent.type === "property") {
|
|
1186
|
+
if (sep === ":") {
|
|
1187
|
+
currentParent.colonOffset = offset;
|
|
1188
|
+
} else if (sep === ",") {
|
|
1189
|
+
ensurePropertyComplete(offset);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
onError: (error, offset, length) => {
|
|
1194
|
+
errors.push({ error, offset, length });
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
visit(text, visitor, options);
|
|
1198
|
+
const result = currentParent.children[0];
|
|
1199
|
+
if (result) {
|
|
1200
|
+
delete result.parent;
|
|
1201
|
+
}
|
|
1202
|
+
return result;
|
|
1203
|
+
}
|
|
1204
|
+
function findNodeAtLocation(root, path) {
|
|
1205
|
+
if (!root) {
|
|
1206
|
+
return void 0;
|
|
1207
|
+
}
|
|
1208
|
+
let node = root;
|
|
1209
|
+
for (let segment of path) {
|
|
1210
|
+
if (typeof segment === "string") {
|
|
1211
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
1212
|
+
return void 0;
|
|
1213
|
+
}
|
|
1214
|
+
let found = false;
|
|
1215
|
+
for (const propertyNode of node.children) {
|
|
1216
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1217
|
+
node = propertyNode.children[1];
|
|
1218
|
+
found = true;
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
if (!found) {
|
|
1223
|
+
return void 0;
|
|
1224
|
+
}
|
|
1225
|
+
} else {
|
|
1226
|
+
const index = segment;
|
|
1227
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
1228
|
+
return void 0;
|
|
1229
|
+
}
|
|
1230
|
+
node = node.children[index];
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
return node;
|
|
1234
|
+
}
|
|
1235
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1236
|
+
const _scanner = createScanner(text, false);
|
|
1237
|
+
const _jsonPath = [];
|
|
1238
|
+
let suppressedCallbacks = 0;
|
|
1239
|
+
function toNoArgVisit(visitFunction) {
|
|
1240
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1241
|
+
}
|
|
1242
|
+
function toOneArgVisit(visitFunction) {
|
|
1243
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1244
|
+
}
|
|
1245
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
1246
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1247
|
+
}
|
|
1248
|
+
function toBeginVisit(visitFunction) {
|
|
1249
|
+
return visitFunction ? () => {
|
|
1250
|
+
if (suppressedCallbacks > 0) {
|
|
1251
|
+
suppressedCallbacks++;
|
|
1252
|
+
} else {
|
|
1253
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
1254
|
+
if (cbReturn === false) {
|
|
1255
|
+
suppressedCallbacks = 1;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
} : () => true;
|
|
1259
|
+
}
|
|
1260
|
+
function toEndVisit(visitFunction) {
|
|
1261
|
+
return visitFunction ? () => {
|
|
1262
|
+
if (suppressedCallbacks > 0) {
|
|
1263
|
+
suppressedCallbacks--;
|
|
1264
|
+
}
|
|
1265
|
+
if (suppressedCallbacks === 0) {
|
|
1266
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
1267
|
+
}
|
|
1268
|
+
} : () => true;
|
|
1269
|
+
}
|
|
1270
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1271
|
+
const disallowComments = options && options.disallowComments;
|
|
1272
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1273
|
+
function scanNext() {
|
|
1274
|
+
while (true) {
|
|
1275
|
+
const token = _scanner.scan();
|
|
1276
|
+
switch (_scanner.getTokenError()) {
|
|
1277
|
+
case 4:
|
|
1278
|
+
handleError(
|
|
1279
|
+
14
|
|
1280
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
1281
|
+
);
|
|
1282
|
+
break;
|
|
1283
|
+
case 5:
|
|
1284
|
+
handleError(
|
|
1285
|
+
15
|
|
1286
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
1287
|
+
);
|
|
1288
|
+
break;
|
|
1289
|
+
case 3:
|
|
1290
|
+
handleError(
|
|
1291
|
+
13
|
|
1292
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
1293
|
+
);
|
|
1294
|
+
break;
|
|
1295
|
+
case 1:
|
|
1296
|
+
if (!disallowComments) {
|
|
1297
|
+
handleError(
|
|
1298
|
+
11
|
|
1299
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
break;
|
|
1303
|
+
case 2:
|
|
1304
|
+
handleError(
|
|
1305
|
+
12
|
|
1306
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
1307
|
+
);
|
|
1308
|
+
break;
|
|
1309
|
+
case 6:
|
|
1310
|
+
handleError(
|
|
1311
|
+
16
|
|
1312
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
1313
|
+
);
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
switch (token) {
|
|
1317
|
+
case 12:
|
|
1318
|
+
case 13:
|
|
1319
|
+
if (disallowComments) {
|
|
1320
|
+
handleError(
|
|
1321
|
+
10
|
|
1322
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
1323
|
+
);
|
|
1324
|
+
} else {
|
|
1325
|
+
onComment();
|
|
1326
|
+
}
|
|
1327
|
+
break;
|
|
1328
|
+
case 16:
|
|
1329
|
+
handleError(
|
|
1330
|
+
1
|
|
1331
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
1332
|
+
);
|
|
1333
|
+
break;
|
|
1334
|
+
case 15:
|
|
1335
|
+
case 14:
|
|
1336
|
+
break;
|
|
1337
|
+
default:
|
|
1338
|
+
return token;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
1343
|
+
onError(error);
|
|
1344
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
1345
|
+
let token = _scanner.getToken();
|
|
1346
|
+
while (token !== 17) {
|
|
1347
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1348
|
+
scanNext();
|
|
1349
|
+
break;
|
|
1350
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
1351
|
+
break;
|
|
1352
|
+
}
|
|
1353
|
+
token = scanNext();
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
function parseString(isValue) {
|
|
1358
|
+
const value = _scanner.getTokenValue();
|
|
1359
|
+
if (isValue) {
|
|
1360
|
+
onLiteralValue(value);
|
|
1361
|
+
} else {
|
|
1362
|
+
onObjectProperty(value);
|
|
1363
|
+
_jsonPath.push(value);
|
|
1364
|
+
}
|
|
1365
|
+
scanNext();
|
|
1366
|
+
return true;
|
|
1367
|
+
}
|
|
1368
|
+
function parseLiteral() {
|
|
1369
|
+
switch (_scanner.getToken()) {
|
|
1370
|
+
case 11:
|
|
1371
|
+
const tokenValue = _scanner.getTokenValue();
|
|
1372
|
+
let value = Number(tokenValue);
|
|
1373
|
+
if (isNaN(value)) {
|
|
1374
|
+
handleError(
|
|
1375
|
+
2
|
|
1376
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
1377
|
+
);
|
|
1378
|
+
value = 0;
|
|
1379
|
+
}
|
|
1380
|
+
onLiteralValue(value);
|
|
1381
|
+
break;
|
|
1382
|
+
case 7:
|
|
1383
|
+
onLiteralValue(null);
|
|
1384
|
+
break;
|
|
1385
|
+
case 8:
|
|
1386
|
+
onLiteralValue(true);
|
|
1387
|
+
break;
|
|
1388
|
+
case 9:
|
|
1389
|
+
onLiteralValue(false);
|
|
1390
|
+
break;
|
|
1391
|
+
default:
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
scanNext();
|
|
1395
|
+
return true;
|
|
1396
|
+
}
|
|
1397
|
+
function parseProperty() {
|
|
1398
|
+
if (_scanner.getToken() !== 10) {
|
|
1399
|
+
handleError(3, [], [
|
|
1400
|
+
2,
|
|
1401
|
+
5
|
|
1402
|
+
/* SyntaxKind.CommaToken */
|
|
1403
|
+
]);
|
|
1404
|
+
return false;
|
|
1405
|
+
}
|
|
1406
|
+
parseString(false);
|
|
1407
|
+
if (_scanner.getToken() === 6) {
|
|
1408
|
+
onSeparator(":");
|
|
1409
|
+
scanNext();
|
|
1410
|
+
if (!parseValue()) {
|
|
1411
|
+
handleError(4, [], [
|
|
1412
|
+
2,
|
|
1413
|
+
5
|
|
1414
|
+
/* SyntaxKind.CommaToken */
|
|
1415
|
+
]);
|
|
1416
|
+
}
|
|
1417
|
+
} else {
|
|
1418
|
+
handleError(5, [], [
|
|
1419
|
+
2,
|
|
1420
|
+
5
|
|
1421
|
+
/* SyntaxKind.CommaToken */
|
|
1422
|
+
]);
|
|
1423
|
+
}
|
|
1424
|
+
_jsonPath.pop();
|
|
1425
|
+
return true;
|
|
1426
|
+
}
|
|
1427
|
+
function parseObject() {
|
|
1428
|
+
onObjectBegin();
|
|
1429
|
+
scanNext();
|
|
1430
|
+
let needsComma = false;
|
|
1431
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1432
|
+
if (_scanner.getToken() === 5) {
|
|
1433
|
+
if (!needsComma) {
|
|
1434
|
+
handleError(4, [], []);
|
|
1435
|
+
}
|
|
1436
|
+
onSeparator(",");
|
|
1437
|
+
scanNext();
|
|
1438
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1439
|
+
break;
|
|
1440
|
+
}
|
|
1441
|
+
} else if (needsComma) {
|
|
1442
|
+
handleError(6, [], []);
|
|
1443
|
+
}
|
|
1444
|
+
if (!parseProperty()) {
|
|
1445
|
+
handleError(4, [], [
|
|
1446
|
+
2,
|
|
1447
|
+
5
|
|
1448
|
+
/* SyntaxKind.CommaToken */
|
|
1449
|
+
]);
|
|
1450
|
+
}
|
|
1451
|
+
needsComma = true;
|
|
1452
|
+
}
|
|
1453
|
+
onObjectEnd();
|
|
1454
|
+
if (_scanner.getToken() !== 2) {
|
|
1455
|
+
handleError(7, [
|
|
1456
|
+
2
|
|
1457
|
+
/* SyntaxKind.CloseBraceToken */
|
|
1458
|
+
], []);
|
|
1459
|
+
} else {
|
|
1460
|
+
scanNext();
|
|
1461
|
+
}
|
|
1462
|
+
return true;
|
|
1463
|
+
}
|
|
1464
|
+
function parseArray() {
|
|
1465
|
+
onArrayBegin();
|
|
1466
|
+
scanNext();
|
|
1467
|
+
let isFirstElement = true;
|
|
1468
|
+
let needsComma = false;
|
|
1469
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1470
|
+
if (_scanner.getToken() === 5) {
|
|
1471
|
+
if (!needsComma) {
|
|
1472
|
+
handleError(4, [], []);
|
|
1473
|
+
}
|
|
1474
|
+
onSeparator(",");
|
|
1475
|
+
scanNext();
|
|
1476
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
} else if (needsComma) {
|
|
1480
|
+
handleError(6, [], []);
|
|
1481
|
+
}
|
|
1482
|
+
if (isFirstElement) {
|
|
1483
|
+
_jsonPath.push(0);
|
|
1484
|
+
isFirstElement = false;
|
|
1485
|
+
} else {
|
|
1486
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1487
|
+
}
|
|
1488
|
+
if (!parseValue()) {
|
|
1489
|
+
handleError(4, [], [
|
|
1490
|
+
4,
|
|
1491
|
+
5
|
|
1492
|
+
/* SyntaxKind.CommaToken */
|
|
1493
|
+
]);
|
|
1494
|
+
}
|
|
1495
|
+
needsComma = true;
|
|
1496
|
+
}
|
|
1497
|
+
onArrayEnd();
|
|
1498
|
+
if (!isFirstElement) {
|
|
1499
|
+
_jsonPath.pop();
|
|
1500
|
+
}
|
|
1501
|
+
if (_scanner.getToken() !== 4) {
|
|
1502
|
+
handleError(8, [
|
|
1503
|
+
4
|
|
1504
|
+
/* SyntaxKind.CloseBracketToken */
|
|
1505
|
+
], []);
|
|
1506
|
+
} else {
|
|
1507
|
+
scanNext();
|
|
1508
|
+
}
|
|
1509
|
+
return true;
|
|
1510
|
+
}
|
|
1511
|
+
function parseValue() {
|
|
1512
|
+
switch (_scanner.getToken()) {
|
|
1513
|
+
case 3:
|
|
1514
|
+
return parseArray();
|
|
1515
|
+
case 1:
|
|
1516
|
+
return parseObject();
|
|
1517
|
+
case 10:
|
|
1518
|
+
return parseString(true);
|
|
1519
|
+
default:
|
|
1520
|
+
return parseLiteral();
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
scanNext();
|
|
1524
|
+
if (_scanner.getToken() === 17) {
|
|
1525
|
+
if (options.allowEmptyContent) {
|
|
1526
|
+
return true;
|
|
1527
|
+
}
|
|
1528
|
+
handleError(4, [], []);
|
|
1529
|
+
return false;
|
|
1530
|
+
}
|
|
1531
|
+
if (!parseValue()) {
|
|
1532
|
+
handleError(4, [], []);
|
|
1533
|
+
return false;
|
|
1534
|
+
}
|
|
1535
|
+
if (_scanner.getToken() !== 17) {
|
|
1536
|
+
handleError(9, [], []);
|
|
1537
|
+
}
|
|
1538
|
+
return true;
|
|
1539
|
+
}
|
|
1540
|
+
function getNodeType(value) {
|
|
1541
|
+
switch (typeof value) {
|
|
1542
|
+
case "boolean":
|
|
1543
|
+
return "boolean";
|
|
1544
|
+
case "number":
|
|
1545
|
+
return "number";
|
|
1546
|
+
case "string":
|
|
1547
|
+
return "string";
|
|
1548
|
+
case "object": {
|
|
1549
|
+
if (!value) {
|
|
1550
|
+
return "null";
|
|
1551
|
+
} else if (Array.isArray(value)) {
|
|
1552
|
+
return "array";
|
|
1553
|
+
}
|
|
1554
|
+
return "object";
|
|
1555
|
+
}
|
|
1556
|
+
default:
|
|
1557
|
+
return "null";
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
// ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
1562
|
+
var ScanError;
|
|
1563
|
+
(function(ScanError2) {
|
|
1564
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1565
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1566
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1567
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1568
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1569
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1570
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1571
|
+
})(ScanError || (ScanError = {}));
|
|
1572
|
+
var SyntaxKind;
|
|
1573
|
+
(function(SyntaxKind2) {
|
|
1574
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1575
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1576
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1577
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1578
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1579
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1580
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1581
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1582
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1583
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1584
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1585
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1586
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1587
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1588
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1589
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1590
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1591
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1592
|
+
var parseTree2 = parseTree;
|
|
1593
|
+
var findNodeAtLocation2 = findNodeAtLocation;
|
|
1594
|
+
var ParseErrorCode;
|
|
1595
|
+
(function(ParseErrorCode2) {
|
|
1596
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1597
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1598
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1599
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1600
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1601
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1602
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1603
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1604
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1605
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1606
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1607
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1608
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1609
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1610
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1611
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1612
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1613
|
+
|
|
1614
|
+
// src/generators/shared/json-edit.ts
|
|
650
1615
|
function detectIndent(raw) {
|
|
651
1616
|
for (const line of raw.split("\n")) {
|
|
652
1617
|
const match = /^(\t+| +)/.exec(line);
|
|
@@ -654,6 +1619,80 @@ function detectIndent(raw) {
|
|
|
654
1619
|
}
|
|
655
1620
|
return " ";
|
|
656
1621
|
}
|
|
1622
|
+
function styleOf(raw) {
|
|
1623
|
+
return { eol: raw.includes("\r\n") ? "\r\n" : "\n", unit: detectIndent(raw) };
|
|
1624
|
+
}
|
|
1625
|
+
function lineIndentAt(raw, offset) {
|
|
1626
|
+
const lineStart = raw.lastIndexOf("\n", offset - 1) + 1;
|
|
1627
|
+
return /^[ \t]*/.exec(raw.slice(lineStart))?.[0] ?? "";
|
|
1628
|
+
}
|
|
1629
|
+
function isMultiline(raw, node) {
|
|
1630
|
+
return raw.slice(node.offset, node.offset + node.length).includes("\n");
|
|
1631
|
+
}
|
|
1632
|
+
function isPrimitive(value) {
|
|
1633
|
+
return value === null || ["string", "number", "boolean"].includes(typeof value);
|
|
1634
|
+
}
|
|
1635
|
+
function renderValue(value, indent, style) {
|
|
1636
|
+
if (isPrimitive(value)) return JSON.stringify(value);
|
|
1637
|
+
if (Array.isArray(value)) {
|
|
1638
|
+
if (value.every(isPrimitive)) return `[${value.map((item) => JSON.stringify(item)).join(", ")}]`;
|
|
1639
|
+
const inner2 = `${indent}${style.unit}`;
|
|
1640
|
+
return `[${style.eol}${value.map((item) => `${inner2}${renderValue(item, inner2, style)}`).join(`,${style.eol}`)}${style.eol}${indent}]`;
|
|
1641
|
+
}
|
|
1642
|
+
const entries = Object.entries(value);
|
|
1643
|
+
if (entries.length === 0) return "{}";
|
|
1644
|
+
const inner = `${indent}${style.unit}`;
|
|
1645
|
+
const body = entries.map(([key, item]) => `${inner}${JSON.stringify(key)}: ${renderValue(item, inner, style)}`).join(`,${style.eol}`);
|
|
1646
|
+
return `{${style.eol}${body}${style.eol}${indent}}`;
|
|
1647
|
+
}
|
|
1648
|
+
function splice(raw, start, end, text) {
|
|
1649
|
+
return raw.slice(0, start) + text + raw.slice(end);
|
|
1650
|
+
}
|
|
1651
|
+
function nest(keys, value) {
|
|
1652
|
+
return keys.reduceRight((inner, key) => ({ [key]: inner }), value);
|
|
1653
|
+
}
|
|
1654
|
+
function insertProperty(raw, object, key, value, style) {
|
|
1655
|
+
const properties = object.children ?? [];
|
|
1656
|
+
const objectIndent = lineIndentAt(raw, object.offset);
|
|
1657
|
+
if (properties.length === 0) {
|
|
1658
|
+
const inner = `${objectIndent}${style.unit}`;
|
|
1659
|
+
const text = `{${style.eol}${inner}${JSON.stringify(String(key))}: ${renderValue(value, inner, style)}${style.eol}${objectIndent}}`;
|
|
1660
|
+
return splice(raw, object.offset, object.offset + object.length, text);
|
|
1661
|
+
}
|
|
1662
|
+
const last = properties[properties.length - 1];
|
|
1663
|
+
const end = last.offset + last.length;
|
|
1664
|
+
if (!isMultiline(raw, object)) {
|
|
1665
|
+
return splice(raw, end, end, `, ${JSON.stringify(String(key))}: ${renderValue(value, "", style)}`);
|
|
1666
|
+
}
|
|
1667
|
+
const indent = lineIndentAt(raw, last.offset);
|
|
1668
|
+
return splice(raw, end, end, `,${style.eol}${indent}${JSON.stringify(String(key))}: ${renderValue(value, indent, style)}`);
|
|
1669
|
+
}
|
|
1670
|
+
function setJsonValue(raw, path, value) {
|
|
1671
|
+
const style = styleOf(raw);
|
|
1672
|
+
const root = parseTree2(raw);
|
|
1673
|
+
if (root === void 0) throw new Error("setJsonValue: not a JSON document");
|
|
1674
|
+
const existing = findNodeAtLocation2(root, path);
|
|
1675
|
+
if (existing !== void 0) {
|
|
1676
|
+
return splice(raw, existing.offset, existing.offset + existing.length, renderValue(value, lineIndentAt(raw, existing.offset), style));
|
|
1677
|
+
}
|
|
1678
|
+
for (let depth = path.length - 1; depth >= 0; depth--) {
|
|
1679
|
+
const parent = depth === 0 ? root : findNodeAtLocation2(root, path.slice(0, depth));
|
|
1680
|
+
if (parent === void 0) continue;
|
|
1681
|
+
if (parent.type !== "object") throw new Error(`setJsonValue: ${path.slice(0, depth).join(".") || "the root"} is not an object`);
|
|
1682
|
+
return insertProperty(raw, parent, path[depth], nest(path.slice(depth + 1), value), style);
|
|
1683
|
+
}
|
|
1684
|
+
throw new Error("setJsonValue: unreachable");
|
|
1685
|
+
}
|
|
1686
|
+
function applyJsonEdits(raw, edits) {
|
|
1687
|
+
if (raw === null) {
|
|
1688
|
+
let text = "{}\n";
|
|
1689
|
+
for (const [path, value] of edits) text = setJsonValue(text, path, value);
|
|
1690
|
+
return text;
|
|
1691
|
+
}
|
|
1692
|
+
return edits.reduce((text, [path, value]) => setJsonValue(text, path, value), raw);
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
// src/generators/shared/toolkit-config-file.ts
|
|
657
1696
|
function recordedChoice(config, key, allowed) {
|
|
658
1697
|
const value = config?.[key];
|
|
659
1698
|
return typeof value === "string" && allowed.includes(value) ? value : void 0;
|
|
@@ -667,6 +1706,7 @@ function treePackageManager(tree, config) {
|
|
|
667
1706
|
}
|
|
668
1707
|
|
|
669
1708
|
// src/generators/add-review/render.ts
|
|
1709
|
+
var DEPENDABOT_PATH = ".github/dependabot.yml";
|
|
670
1710
|
function renderLineDiff(existing, generated) {
|
|
671
1711
|
const a = existing.split("\n");
|
|
672
1712
|
const b = generated.split("\n");
|
|
@@ -747,6 +1787,16 @@ function renderAddReviewReport(report) {
|
|
|
747
1787
|
lines.push(" --onConflict=skip keep the existing file");
|
|
748
1788
|
lines.push(" --onConflict=alternate-filename write the generated version alongside it");
|
|
749
1789
|
}
|
|
1790
|
+
if (report.dependabot === "created") {
|
|
1791
|
+
lines.push(` ${DEPENDABOT_PATH}: created \u2014 Dependabot proposes newer pins for the workflow's actions`);
|
|
1792
|
+
} else if (report.dependabot === "present") {
|
|
1793
|
+
lines.push(` ${DEPENDABOT_PATH}: already updates github-actions`);
|
|
1794
|
+
} else if (report.dependabot === "proposed") {
|
|
1795
|
+
lines.push(` ${DEPENDABOT_PATH}: NOT changed \u2014 it has no github-actions entry. The workflow pins each action`);
|
|
1796
|
+
lines.push(" to a commit SHA; add this entry under `updates:` so those pins get update pull requests:");
|
|
1797
|
+
lines.push("");
|
|
1798
|
+
lines.push(report.dependabotProposal ?? "");
|
|
1799
|
+
}
|
|
750
1800
|
if (report.workflowAction === "alternate") {
|
|
751
1801
|
lines.push("");
|
|
752
1802
|
lines.push(" Review the generated file, then replace the main workflow file with it yourself;");
|
|
@@ -832,7 +1882,9 @@ function runAddReview(tree, options) {
|
|
|
832
1882
|
diff: null,
|
|
833
1883
|
workflowYaml: null,
|
|
834
1884
|
configSnippetJson: null,
|
|
835
|
-
configError: config.error
|
|
1885
|
+
configError: config.error,
|
|
1886
|
+
dependabot: "not-applied",
|
|
1887
|
+
dependabotProposal: null
|
|
836
1888
|
};
|
|
837
1889
|
}
|
|
838
1890
|
const existing = tree.read(plan.workflowFilePath, "utf-8");
|
|
@@ -884,17 +1936,17 @@ function runAddReview(tree, options) {
|
|
|
884
1936
|
configAction = "unchanged";
|
|
885
1937
|
} else {
|
|
886
1938
|
configAction = config.raw === null ? "created" : "updated";
|
|
887
|
-
|
|
888
|
-
const trailingNewline = config.raw === null || config.raw.endsWith("\n");
|
|
889
|
-
const body = JSON.stringify({ ...config.parsed ?? {}, review: plan.configSnippet }, null, indent);
|
|
890
|
-
newConfigContent = trailingNewline ? `${body}
|
|
891
|
-
` : body;
|
|
1939
|
+
newConfigContent = applyJsonEdits(config.raw, [[["review"], plan.configSnippet]]);
|
|
892
1940
|
}
|
|
893
1941
|
}
|
|
1942
|
+
const [dependabotFile] = renderTemplateFiles(generatorFilesDir("add-review", import.meta.url), ".github", {});
|
|
1943
|
+
const existingDependabot = tree.read(DEPENDABOT_PATH, "utf-8");
|
|
1944
|
+
const dependabot = existingDependabot === null ? "created" : /github-actions/.test(existingDependabot) ? "present" : "proposed";
|
|
894
1945
|
const dryRun = options.dryRun ?? false;
|
|
895
1946
|
if (!dryRun) {
|
|
896
1947
|
if (writeWorkflowTo !== null) tree.write(writeWorkflowTo, plan.workflowYaml);
|
|
897
1948
|
if (newConfigContent !== null) tree.write(CONFIG_PATH, newConfigContent);
|
|
1949
|
+
if (dependabot === "created") tree.write(DEPENDABOT_PATH, dependabotFile.content);
|
|
898
1950
|
}
|
|
899
1951
|
return {
|
|
900
1952
|
dryRun,
|
|
@@ -906,6 +1958,8 @@ function runAddReview(tree, options) {
|
|
|
906
1958
|
workflowYaml: dryRun ? plan.workflowYaml : null,
|
|
907
1959
|
configSnippetJson: dryRun ? JSON.stringify(plan.configSnippet, null, 2) : null,
|
|
908
1960
|
configError: null,
|
|
1961
|
+
dependabot,
|
|
1962
|
+
dependabotProposal: dependabot === "proposed" ? dependabotFile.content : null,
|
|
909
1963
|
...packageManagerNote !== void 0 ? { packageManagerNote } : {}
|
|
910
1964
|
};
|
|
911
1965
|
}
|