@ultimat3/cli 31.26.0 → 31.28.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/CLAUDE.md +47 -37
- package/README.md +19 -8
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/app-mcp.ts +17 -3
- package/src/cmd-cache-spec.ts +5 -2
- package/src/cmd-db-spec.ts +2 -3
- package/src/cmd-db.ts +0 -2
- package/src/cmd-deploy-verify-sample.ts +93 -0
- package/src/cmd-deploy-verify.ts +2 -41
- package/src/cmd-dev-spec.ts +15 -1
- package/src/cmd-dev.ts +31 -4
- package/src/cmd-doctor.ts +15 -4
- package/src/cmd-exercise-spec.ts +7 -1
- package/src/cmd-exercise.ts +22 -10
- package/src/cmd-generate.ts +2 -0
- package/src/cmd-jobs-spec.ts +3 -6
- package/src/cmd-jobs.ts +1 -7
- package/src/cmd-logs-spec.ts +2 -1
- package/src/cmd-logs.ts +9 -28
- package/src/cmd-planned.ts +11 -45
- package/src/cmd-profile-frames.ts +99 -0
- package/src/cmd-profile-spec.ts +24 -0
- package/src/cmd-profile.ts +164 -0
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- package/src/cmd-status-sample.ts +57 -0
- package/src/cmd-status-spec.ts +30 -0
- package/src/cmd-status.ts +108 -0
- package/src/cmd-token-spec.ts +5 -2
- package/src/cmd-token.ts +7 -3
- package/src/cmd-upgrade-codemods.ts +71 -0
- package/src/cmd-upgrade-spec.ts +19 -5
- package/src/cmd-upgrade.ts +91 -34
- package/src/codemods/agents-dev-mcp.ts +50 -0
- package/src/codemods/authenticator-session-refusal.ts +214 -0
- package/src/codemods/biome-no-default-export.ts +58 -0
- package/src/codemods/bunfig-island-coverage.ts +33 -0
- package/src/codemods/chart-dashboard.ts +73 -0
- package/src/codemods/ci-e2e-browser-stock.ts +75 -0
- package/src/codemods/ci-e2e-browser.ts +63 -0
- package/src/codemods/codemod.ts +58 -0
- package/src/codemods/define-error-leaf.ts +73 -0
- package/src/codemods/docs-ci-parts.ts +65 -0
- package/src/codemods/docs-gate-prose.ts +53 -0
- package/src/codemods/docs-island-rows.ts +31 -0
- package/src/codemods/docs-shipped-guards.ts +100 -0
- package/src/codemods/docs-test-services.ts +62 -0
- package/src/codemods/engine-diff.ts +104 -0
- package/src/codemods/engine-edits.ts +111 -0
- package/src/codemods/engine-fs.ts +95 -0
- package/src/codemods/engine.ts +191 -0
- package/src/codemods/format-edited-hook-3122.ts +28 -0
- package/src/codemods/format-edited-hook.ts +152 -0
- package/src/codemods/helm-alerts-objective.ts +105 -0
- package/src/codemods/helm-alerts-stock.ts +108 -0
- package/src/codemods/index.ts +56 -0
- package/src/codemods/metrics-probe-healthz.ts +47 -0
- package/src/codemods/pending.ts +36 -0
- package/src/codemods/repro-gitignore.ts +40 -0
- package/src/codemods/runtime-pin-lines.ts +109 -0
- package/src/codemods/runtime-pin.ts +116 -0
- package/src/codemods/solid-floor.ts +63 -0
- package/src/codemods/test-ports.ts +86 -0
- package/src/codemods/test-suites.ts +37 -0
- package/src/codemods/theme-toggle-mount-over.ts +70 -0
- package/src/codemods/vendored-guards.ts +186 -0
- package/src/codemods/verify-floor-skips.ts +88 -0
- package/src/codemods/verify-floor-steps.ts +90 -0
- package/src/coverage-island.ts +121 -0
- package/src/coverage-lcov.ts +49 -5
- package/src/coverage-remap.ts +146 -0
- package/src/db-replay-engine-prepared.ts +66 -0
- package/src/db-replay-engine-template.ts +156 -0
- package/src/db-replay-engine.ts +4 -0
- package/src/db-replay-scratch-reap.ts +54 -0
- package/src/deploy-verify-flags.ts +9 -2
- package/src/deploy-verify-grade.ts +10 -3
- package/src/dev-boot.ts +14 -1
- package/src/dev-dashboard-guard.ts +57 -10
- package/src/dev-host.ts +46 -0
- package/src/dev-tls-cache.ts +103 -0
- package/src/dev-tls-der.ts +69 -0
- package/src/dev-tls.ts +120 -0
- package/src/doctor-advisory-floors.ts +113 -0
- package/src/doctor-browser.ts +60 -0
- package/src/doctor-guards.ts +39 -86
- package/src/doctor-superseded.ts +67 -0
- package/src/error-codes-doctor.ts +12 -4
- package/src/error-codes-verify.ts +47 -0
- package/src/error-codes.ts +20 -23
- package/src/exercise-database.ts +47 -9
- package/src/exercise-push-device.ts +51 -0
- package/src/exercise-route-api.ts +74 -0
- package/src/exercise-routes.ts +14 -5
- package/src/exercise-services.ts +3 -1
- package/src/exercise-shard-flag.ts +47 -0
- package/src/fix-command.ts +2 -2
- package/src/generate-factories.ts +5 -11
- package/src/generate-feature-required.ts +9 -4
- package/src/generate-files.ts +26 -7
- package/src/generate-kinds.ts +5 -1
- package/src/guards-built-in-codes.ts +36 -0
- package/src/guards-built-in-refusal.ts +25 -0
- package/src/guards-built-in.ts +134 -0
- package/src/guards-materialize.ts +42 -0
- package/src/guards-paths.ts +37 -0
- package/src/guards-shipped-names.ts +38 -0
- package/src/guards-vendored.ts +73 -0
- package/src/guards.ts +105 -34
- package/src/index.ts +10 -0
- package/src/island-bundle-options.ts +48 -0
- package/src/island-bundle.ts +18 -46
- package/src/island-link.ts +5 -0
- package/src/island-outputs.ts +5 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors-verify.ts +35 -0
- package/src/mcp-errors.ts +21 -20
- package/src/mcp-host-logs.ts +121 -0
- package/src/mcp-host.ts +12 -73
- package/src/measure-scope.ts +23 -3
- package/src/messages-floor.ts +19 -0
- package/src/messages-repro.ts +16 -2
- package/src/messages-status.ts +10 -0
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +22 -1
- package/src/registry.ts +4 -0
- package/src/repro-archive-collect.ts +161 -0
- package/src/repro-archive-write.ts +96 -0
- package/src/repro-archive.ts +161 -0
- package/src/repro-bundle.ts +8 -16
- package/src/repro-errors.ts +14 -2
- package/src/repro-framework.ts +53 -0
- package/src/repro-parse.ts +87 -0
- package/src/repro-redact.ts +218 -0
- package/src/repro-scrub.ts +257 -0
- package/src/role-start-types.ts +7 -0
- package/src/role-start.ts +4 -0
- package/src/serve-boot.ts +7 -1
- package/src/serve-env-tls.ts +57 -0
- package/src/solid-loader.ts +27 -10
- package/src/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/generate-export-rows.ts +136 -0
- package/src/templates/generate-import-rows.ts +186 -0
- package/src/templates/generate-rows-slice.ts +95 -0
- package/src/templates/github/ci.yml.ts +5 -1
- package/src/templates/guard-released-forms.ts +112 -0
- package/src/templates/guard-runtime-pin-test.ts +54 -0
- package/src/templates/guard-runtime-pin.ts +189 -0
- package/src/templates/scaffold-claude-agents.ts +6 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-claude-hook.ts +18 -8
- package/src/templates/scaffold-claude.ts +2 -2
- package/src/templates/scaffold-db-package.ts +3 -0
- package/src/templates/scaffold-docs.ts +34 -30
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +4 -8
- package/src/templates/scaffold-site.ts +4 -1
- package/src/templates/scaffold-suites.ts +72 -0
- package/src/templates/scaffold-test-services.ts +35 -10
- package/src/templates/scaffold-verify-floor.ts +53 -31
- package/src/templates/shapes/api.ts +4 -0
- package/src/templates/slice-foundation.ts +3 -3
- package/src/unthrown-codes.ts +3 -1
- package/src/upgrade-bun-floor.ts +4 -0
- package/src/upgrade-clean-tree.ts +54 -0
- package/src/upgrade-gate-codemods-install.ts +40 -0
- package/src/upgrade-gate-codemods.ts +151 -0
- package/src/upgrade-gate.ts +44 -7
- package/src/upgrade-guards-baseline.ts +43 -0
- package/src/upgrade-guards.ts +37 -2
- package/src/upgrade-lock.ts +118 -0
- package/src/upgrade-plan.ts +2 -1
- package/src/upgrade-report-codemods.ts +54 -0
- package/src/upgrade-report.ts +55 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/src/verify-coverage-run.ts +42 -11
- package/src/verify-e2e.ts +115 -4
- package/src/verify-floor.ts +27 -0
- package/src/verify-guard-baseline.ts +109 -0
- package/src/verify-live.ts +72 -0
- package/src/verify-merge-skips.ts +51 -0
- package/src/verify-merge.ts +36 -2
- package/src/verify-run.ts +48 -7
- package/src/verify-services.ts +287 -0
- package/src/verify-skip-reason.ts +53 -0
- package/src/verify-strict.ts +108 -0
- package/src/verify-test-command.ts +129 -0
- package/src/verify-tests.ts +39 -126
- package/types/babel-modules.d.ts +2 -0
- package/wiki/CLI-Reference.md +200 -27
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Jobs-And-Workflows.md +3 -3
- package/wiki/Known-Gaps.md +5 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Observability.md +1 -0
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +8 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// One line of a Dockerfile or a workflow, read as a Bun pin and judged against the pin `x new`
|
|
2
|
+
// writes now: already there, carried there (a shape an older scaffold wrote), or the app's own
|
|
3
|
+
// choice — which is never edited, only reported with the line the scaffold would have written.
|
|
4
|
+
|
|
5
|
+
import { REQUIRED_BUN } from '../app-root';
|
|
6
|
+
import { type BunImage, scaffoldDigestPatch } from '../templates/bun-image';
|
|
7
|
+
import { SETUP_BUN } from '../templates/github/ci.yml';
|
|
8
|
+
|
|
9
|
+
export type LineVerdict =
|
|
10
|
+
| { readonly kind: 'keep' }
|
|
11
|
+
| { readonly kind: 'carry'; readonly to: string }
|
|
12
|
+
/** `to` is the scaffold's line, for the diff; the file is not written. */
|
|
13
|
+
| { readonly kind: 'foreign'; readonly to: string; readonly why: string };
|
|
14
|
+
|
|
15
|
+
const KEEP: LineVerdict = { kind: 'keep' };
|
|
16
|
+
|
|
17
|
+
const FROM = /^(\s*FROM\s+(?:--\S+\s+)*)(oven\/bun:([^\s@]+)(?:@(sha256:[0-9a-f]{64}))?)/i;
|
|
18
|
+
const TAG = /^(\d+\.\d+(?:\.\d+)?)(-[\w.-]+)?$/;
|
|
19
|
+
const RECORDED = /(digest is \\?`?oven\/bun:)(\d+\.\d+\.\d+)(-alpine)/;
|
|
20
|
+
const SETUP = /^(\s*(?:-\s*)?uses:\s*)oven-sh\/setup-bun@([^\s#]+)(.*)$/;
|
|
21
|
+
const COMMIT = /^[0-9a-f]{40}$/;
|
|
22
|
+
const BUN_VERSION = /^(\s*(?:-\s*)?bun-version:\s*)(['"]?)([^'"\s#]+)\2(\s*(?:#.*)?)$/;
|
|
23
|
+
const EXACT = /^\d+\.\d+\.\d+$/;
|
|
24
|
+
const SERIES = /^(\d+\.\d+)(?:\.x)?$/;
|
|
25
|
+
|
|
26
|
+
/** `version` against `patch`, read at the version's own precision: `1.4` is not below `1.4.4`. */
|
|
27
|
+
export function compareAt(version: string, patch: string): number {
|
|
28
|
+
const held = version.split('.').map(Number);
|
|
29
|
+
const wanted = patch.split('.').map(Number);
|
|
30
|
+
for (let at = 0; at < held.length; at += 1) {
|
|
31
|
+
const difference = (held[at] ?? 0) - (wanted[at] ?? 0);
|
|
32
|
+
if (difference !== 0) return Math.sign(difference);
|
|
33
|
+
}
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isComment = (line: string): boolean => line.trimStart().startsWith('#');
|
|
38
|
+
|
|
39
|
+
/** A `FROM oven/bun:` line against the scaffold's image. */
|
|
40
|
+
export function dockerfileLine(line: string, image: BunImage): LineVerdict {
|
|
41
|
+
if (isComment(line)) return KEEP;
|
|
42
|
+
const from = FROM.exec(line);
|
|
43
|
+
if (from === null) return KEEP;
|
|
44
|
+
const [whole, head = '', , tag = '', digest] = from;
|
|
45
|
+
const to = `${head}${image.ref}${line.slice(whole.length)}`;
|
|
46
|
+
const foreign = (why: string): LineVerdict => ({ kind: 'foreign', to, why });
|
|
47
|
+
if (tag.includes('$'))
|
|
48
|
+
return foreign(`the tag is a build arg: set it to ${image.ref} where it is defined`);
|
|
49
|
+
const parts = TAG.exec(tag);
|
|
50
|
+
if (parts === null) return foreign(`oven/bun:${tag} names no version`);
|
|
51
|
+
const order = compareAt(parts[1] ?? '', image.patch);
|
|
52
|
+
if (parts[2] !== `-${image.variant}`) {
|
|
53
|
+
return digest === undefined
|
|
54
|
+
? foreign(`oven/bun:${tag} is a variant x new does not write, by no digest`)
|
|
55
|
+
: KEEP;
|
|
56
|
+
}
|
|
57
|
+
if (digest === image.digest) return KEEP;
|
|
58
|
+
// A digest no scaffold wrote was chosen or moved since — Dependabot's docker ecosystem does.
|
|
59
|
+
if (digest !== undefined && scaffoldDigestPatch(digest) === undefined) {
|
|
60
|
+
return order < 0
|
|
61
|
+
? foreign(`oven/bun:${tag} is pinned by a digest x new never wrote, below Bun ${image.patch}`)
|
|
62
|
+
: KEEP;
|
|
63
|
+
}
|
|
64
|
+
if (order > 0) {
|
|
65
|
+
const inspect = `docker buildx imagetools inspect oven/bun:${tag}`;
|
|
66
|
+
return {
|
|
67
|
+
kind: 'foreign',
|
|
68
|
+
to: line,
|
|
69
|
+
why: `oven/bun:${tag} is ahead of x new's pin and has no digest: ${inspect}`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { kind: 'carry', to };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The "digest is `oven/bun:<patch>`" note, moved with the FROM lines it describes. */
|
|
76
|
+
export const recordedLine = (line: string, image: BunImage): string =>
|
|
77
|
+
isComment(line)
|
|
78
|
+
? line.replace(
|
|
79
|
+
RECORDED,
|
|
80
|
+
(_whole, head: string, _patch: string, variant: string) =>
|
|
81
|
+
`${head}${image.patch}${variant}`,
|
|
82
|
+
)
|
|
83
|
+
: line;
|
|
84
|
+
|
|
85
|
+
/** A workflow's `uses: oven-sh/setup-bun@…` or `bun-version:` line against the scaffold's. */
|
|
86
|
+
export function workflowLine(line: string): LineVerdict {
|
|
87
|
+
if (isComment(line)) return KEEP;
|
|
88
|
+
const setup = SETUP.exec(line);
|
|
89
|
+
if (setup !== null) {
|
|
90
|
+
// A commit pin is a pin, whichever one Dependabot last moved it to.
|
|
91
|
+
return COMMIT.test(setup[2] ?? '')
|
|
92
|
+
? KEEP
|
|
93
|
+
: { kind: 'carry', to: `${setup[1] ?? ''}${SETUP_BUN}` };
|
|
94
|
+
}
|
|
95
|
+
const key = BUN_VERSION.exec(line);
|
|
96
|
+
if (key === null) return KEEP;
|
|
97
|
+
const [, head = '', quote = '', value = '', tail = ''] = key;
|
|
98
|
+
if (value.includes('$')) return KEEP;
|
|
99
|
+
const to = `${head}${quote}${REQUIRED_BUN}${quote}${tail}`;
|
|
100
|
+
if (EXACT.test(value)) return compareAt(value, REQUIRED_BUN) < 0 ? { kind: 'carry', to } : KEEP;
|
|
101
|
+
const series = SERIES.exec(value)?.[1];
|
|
102
|
+
const scaffold = `${head}'${REQUIRED_BUN}'${tail}`;
|
|
103
|
+
if (series !== undefined && compareAt(series, REQUIRED_BUN) >= 0) return KEEP;
|
|
104
|
+
return {
|
|
105
|
+
kind: 'foreign',
|
|
106
|
+
to: scaffold,
|
|
107
|
+
why: `bun-version ${value} is a pin x new does not write`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Carries an older app's Bun pins to the ones `x new` writes now: every Dockerfile's `FROM oven/bun:`
|
|
2
|
+
// onto the scaffold's digest, every workflow's `setup-bun` onto its commit pin and `bun-version:`
|
|
3
|
+
// onto the CLI's floor, and `engines.bun` / `.bun-version` / `packageManager` up to that floor.
|
|
4
|
+
// A file holding a pin the app chose itself is left whole, reported with the diff it would take.
|
|
5
|
+
|
|
6
|
+
import { REQUIRED_BUN } from '../app-root';
|
|
7
|
+
import { SCAFFOLD_BUN_IMAGE } from '../templates/bun-image';
|
|
8
|
+
import { editBunSites } from '../upgrade-bun-floor';
|
|
9
|
+
import type { Codemod, CodemodApp, CodemodResult } from './codemod';
|
|
10
|
+
import { unifiedDiff } from './engine-diff';
|
|
11
|
+
import { mergeResults, readText } from './engine-edits';
|
|
12
|
+
import { dockerfileLine, type LineVerdict, recordedLine, workflowLine } from './runtime-pin-lines';
|
|
13
|
+
|
|
14
|
+
const NOTHING: CodemodResult = { changed: [], skipped: [] };
|
|
15
|
+
|
|
16
|
+
const DOCKERFILES = [
|
|
17
|
+
'Dockerfile*',
|
|
18
|
+
'*.Dockerfile',
|
|
19
|
+
'docker/**/Dockerfile*',
|
|
20
|
+
'docker/**/*.Dockerfile',
|
|
21
|
+
];
|
|
22
|
+
const WORKFLOWS = [
|
|
23
|
+
'.github/workflows/*.yml',
|
|
24
|
+
'.github/workflows/*.yaml',
|
|
25
|
+
'.github/actions/**/action.yml',
|
|
26
|
+
'.github/actions/**/action.yaml',
|
|
27
|
+
];
|
|
28
|
+
const MANIFESTS = ['package.json', '.bun-version'];
|
|
29
|
+
|
|
30
|
+
/** Every path the patterns match, once, in order: two globs can name one file. */
|
|
31
|
+
async function pathsOf(app: CodemodApp, patterns: readonly string[]): Promise<readonly string[]> {
|
|
32
|
+
const found = await Promise.all(patterns.map((pattern) => app.glob(pattern)));
|
|
33
|
+
return [...new Set(found.flat())].filter((path) => !path.endsWith('.dockerignore')).sort();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One file, line by line: written when every pin in it is the scaffold's to move, else reported. */
|
|
37
|
+
async function migrateLines(
|
|
38
|
+
app: CodemodApp,
|
|
39
|
+
path: string,
|
|
40
|
+
judge: (line: string) => LineVerdict,
|
|
41
|
+
carried: (lines: readonly string[]) => readonly string[] = (lines) => lines,
|
|
42
|
+
): Promise<CodemodResult> {
|
|
43
|
+
// LF lines with no BOM: a CRLF line's `\r` would defeat each `$`-anchored pin pattern.
|
|
44
|
+
const file = await readText(app, path);
|
|
45
|
+
if (file === undefined) return NOTHING;
|
|
46
|
+
const source = file.text;
|
|
47
|
+
const lines = source.split('\n');
|
|
48
|
+
const verdicts = lines.map(judge);
|
|
49
|
+
const foreign: string[] = [];
|
|
50
|
+
const next = verdicts.map((verdict, index) => {
|
|
51
|
+
if (verdict.kind === 'keep') return lines[index] ?? '';
|
|
52
|
+
if (verdict.kind === 'foreign') foreign.push(`${path}:${String(index + 1)}: ${verdict.why}`);
|
|
53
|
+
return verdict.to;
|
|
54
|
+
});
|
|
55
|
+
const moved = verdicts.some((verdict) => verdict.kind !== 'keep');
|
|
56
|
+
const text = (moved ? carried(next) : next).join('\n');
|
|
57
|
+
if (foreign.length > 0) {
|
|
58
|
+
const diff = unifiedDiff(path, source, text);
|
|
59
|
+
const reason = `a Bun pin here is the app's own, so the file is left as it is — ${foreign.join('; ')}`;
|
|
60
|
+
return { changed: [], skipped: [{ path, reason, ...(diff === '' ? {} : { diff }) }] };
|
|
61
|
+
}
|
|
62
|
+
if (text === source) return NOTHING;
|
|
63
|
+
await app.write(path, file.restore(text));
|
|
64
|
+
return { changed: [path], skipped: [] };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `engines.bun`, `packageManager` and `.bun-version`, raised by the one floor editor `x upgrade` has. */
|
|
68
|
+
async function migrateManifest(app: CodemodApp, path: string): Promise<CodemodResult> {
|
|
69
|
+
const source = await app.read(path);
|
|
70
|
+
if (source === undefined) return NOTHING;
|
|
71
|
+
const { text, manual } = editBunSites(path, source, REQUIRED_BUN);
|
|
72
|
+
if (manual.length > 0) {
|
|
73
|
+
const why = manual.map((site) => `${site.path}:${String(site.line)}: ${site.why}`).join('; ');
|
|
74
|
+
const diff = unifiedDiff(path, source, text);
|
|
75
|
+
return {
|
|
76
|
+
changed: [],
|
|
77
|
+
skipped: [
|
|
78
|
+
{
|
|
79
|
+
path,
|
|
80
|
+
reason: `a Bun pin here is the app's own — ${why}`,
|
|
81
|
+
...(diff === '' ? {} : { diff }),
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (text === source) return NOTHING;
|
|
87
|
+
await app.write(path, text);
|
|
88
|
+
return { changed: [path], skipped: [] };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const codemod: Codemod = {
|
|
92
|
+
id: 'runtime-pin',
|
|
93
|
+
// The release that ships this codemod. Its rewrite targets the pin 29.0.0's scaffold first wrote,
|
|
94
|
+
// but a codemod runs only for a hop whose span holds `since` (or a rerun at the target), so a
|
|
95
|
+
// `since` of 29.0.0 would never reach an app already past it — every app this codemod is for.
|
|
96
|
+
since: '31.28.0',
|
|
97
|
+
summary: `every Bun pin onto the one x new writes: ${SCAFFOLD_BUN_IMAGE.ref}, bun-version ${REQUIRED_BUN}`,
|
|
98
|
+
async run(app) {
|
|
99
|
+
const results: CodemodResult[] = [];
|
|
100
|
+
for (const path of await pathsOf(app, DOCKERFILES)) {
|
|
101
|
+
results.push(
|
|
102
|
+
await migrateLines(
|
|
103
|
+
app,
|
|
104
|
+
path,
|
|
105
|
+
(line) => dockerfileLine(line, SCAFFOLD_BUN_IMAGE),
|
|
106
|
+
(lines) => lines.map((line) => recordedLine(line, SCAFFOLD_BUN_IMAGE)),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
for (const path of await pathsOf(app, WORKFLOWS))
|
|
111
|
+
results.push(await migrateLines(app, path, workflowLine));
|
|
112
|
+
for (const path of await pathsOf(app, MANIFESTS))
|
|
113
|
+
results.push(await migrateManifest(app, path));
|
|
114
|
+
return mergeResults(results);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Carries an older app's `solid-js` pins up to the advisory floor `@ultimat3/ui` now peers: every
|
|
2
|
+
// manifest's exact, caret or tilde pin below it is raised in its own shape, so the app resolves a
|
|
3
|
+
// seroval past every advisory with no `overrides`. A range the app wrote itself is reported whole.
|
|
4
|
+
|
|
5
|
+
import { SOLID_FLOOR } from '../doctor-advisory-floors';
|
|
6
|
+
import type { Codemod, CodemodApp, CodemodResult } from './codemod';
|
|
7
|
+
import { mergeResults } from './engine-edits';
|
|
8
|
+
|
|
9
|
+
const NOTHING: CodemodResult = { changed: [], skipped: [] };
|
|
10
|
+
const MANIFESTS = ['package.json', 'apps/*/package.json', 'packages/*/package.json'];
|
|
11
|
+
const DECLARED = /("solid-js"\s*:\s*")([^"]*)"/g;
|
|
12
|
+
const PIN = /^([~^]?)(\d+)\.\d+\.\d+$/;
|
|
13
|
+
|
|
14
|
+
type Verdict = { readonly kind: 'keep' } | { readonly kind: 'raise'; readonly to: string };
|
|
15
|
+
|
|
16
|
+
/** One declared range: kept, raised, or `undefined` when it is a shape only the app can judge. */
|
|
17
|
+
function judge(range: string): Verdict | undefined {
|
|
18
|
+
const pin = PIN.exec(range);
|
|
19
|
+
if (pin === null) return undefined;
|
|
20
|
+
const [, operator = '', major = ''] = pin;
|
|
21
|
+
// A later major is past the floor already; an earlier one is a migration, not a security floor.
|
|
22
|
+
if (major !== '1') return Number(major) > 1 ? { kind: 'keep' } : undefined;
|
|
23
|
+
const version = range.slice(operator.length);
|
|
24
|
+
return Bun.semver.order(version, SOLID_FLOOR) >= 0
|
|
25
|
+
? { kind: 'keep' }
|
|
26
|
+
: { kind: 'raise', to: `${operator}${SOLID_FLOOR}` };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function migrate(app: CodemodApp, path: string): Promise<CodemodResult> {
|
|
30
|
+
const source = await app.read(path);
|
|
31
|
+
if (source === undefined) return NOTHING;
|
|
32
|
+
const foreign: string[] = [];
|
|
33
|
+
const next = source.replace(DECLARED, (whole, head: string, range: string) => {
|
|
34
|
+
const verdict = judge(range);
|
|
35
|
+
if (verdict === undefined) {
|
|
36
|
+
foreign.push(range);
|
|
37
|
+
return whole;
|
|
38
|
+
}
|
|
39
|
+
return verdict.kind === 'raise' ? `${head}${verdict.to}"` : whole;
|
|
40
|
+
});
|
|
41
|
+
if (foreign.length > 0) {
|
|
42
|
+
const ranges = foreign.map((range) => `solid-js ${range}`).join(', ');
|
|
43
|
+
const reason = `${ranges} is the app's own range, so the file is left as it is; it must resolve solid-js ${SOLID_FLOOR} or later`;
|
|
44
|
+
return { changed: [], skipped: [{ path, reason }] };
|
|
45
|
+
}
|
|
46
|
+
if (next === source) return NOTHING;
|
|
47
|
+
await app.write(path, next);
|
|
48
|
+
return { changed: [path], skipped: [] };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const codemod: Codemod = {
|
|
52
|
+
id: 'solid-floor',
|
|
53
|
+
// The release whose `@ultimat3/ui` first peers `solid-js ^1.9.18`, and whose scaffold pins it.
|
|
54
|
+
since: '31.28.0',
|
|
55
|
+
summary: `every solid-js pin up to ${SOLID_FLOOR}, the first release past the seroval advisories`,
|
|
56
|
+
async run(app) {
|
|
57
|
+
const found = await Promise.all(MANIFESTS.map((pattern) => app.glob(pattern)));
|
|
58
|
+
const paths = [...new Set(found.flat())].sort();
|
|
59
|
+
const results: CodemodResult[] = [];
|
|
60
|
+
for (const path of paths) results.push(await migrate(app, path));
|
|
61
|
+
return mergeResults(results);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// 31.27.0: the test stack's host ports are the app's own (its name picks an offset into each band),
|
|
2
|
+
// so two apps on one machine stop dialling each other's Postgres. Only a compose file and env file
|
|
3
|
+
// still byte-for-byte the old scaffold's move; an edited one is reported with the diff.
|
|
4
|
+
|
|
5
|
+
import type { NameSet } from '../templates/naming';
|
|
6
|
+
import { names } from '../templates/naming';
|
|
7
|
+
import {
|
|
8
|
+
TEST_COMPOSE_PATH,
|
|
9
|
+
TEST_ENV_PATH,
|
|
10
|
+
TEST_PORTS,
|
|
11
|
+
testPorts,
|
|
12
|
+
testServicesFiles,
|
|
13
|
+
} from '../templates/scaffold-test-services';
|
|
14
|
+
import type { Codemod, CodemodApp, CodemodResult } from './codemod';
|
|
15
|
+
import { unifiedDiff } from './engine-diff';
|
|
16
|
+
import { mergeResults, readText } from './engine-edits';
|
|
17
|
+
|
|
18
|
+
const NOTHING: CodemodResult = { changed: [], skipped: [] };
|
|
19
|
+
|
|
20
|
+
/** The compose comment the old scaffold wrote, and today's. */
|
|
21
|
+
const OLD_NOTE =
|
|
22
|
+
"# and a suite that needs a real server skips. Ports are the dev stack's plus 50000, so both run.";
|
|
23
|
+
const NEW_NOTE = [
|
|
24
|
+
"# and a suite that needs a real server skips. Ports are this app's own (its name picks",
|
|
25
|
+
"# them), above the dev stack's, so both stacks — and two apps — run at once.",
|
|
26
|
+
].join('\n');
|
|
27
|
+
|
|
28
|
+
/** The app's name, as the old env file spells it in its database URL. */
|
|
29
|
+
const appName = (env: string): string | undefined =>
|
|
30
|
+
/^TEST_DATABASE_URL=postgres:\/\/([a-z0-9-]+):\1-test@/m.exec(env)?.[1];
|
|
31
|
+
|
|
32
|
+
/** Today's file with the old fixed ports and comment: what the old scaffold wrote for this app. */
|
|
33
|
+
function before(today: string, app: NameSet): string {
|
|
34
|
+
const ports = testPorts(app);
|
|
35
|
+
let text = today.replace(NEW_NOTE, () => OLD_NOTE);
|
|
36
|
+
for (const key of Object.keys(TEST_PORTS) as (keyof typeof TEST_PORTS)[]) {
|
|
37
|
+
text = text.replaceAll(
|
|
38
|
+
`127.0.0.1:${String(ports[key])}`,
|
|
39
|
+
`127.0.0.1:${String(TEST_PORTS[key])}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function move(
|
|
46
|
+
app: CodemodApp,
|
|
47
|
+
path: string,
|
|
48
|
+
today: string,
|
|
49
|
+
name: NameSet,
|
|
50
|
+
): Promise<CodemodResult> {
|
|
51
|
+
const file = await readText(app, path);
|
|
52
|
+
if (file === undefined || file.text === today) return NOTHING;
|
|
53
|
+
const old = before(today, name);
|
|
54
|
+
if (file.text === old) {
|
|
55
|
+
await app.write(path, file.restore(today));
|
|
56
|
+
return { changed: [path], skipped: [] };
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
changed: [],
|
|
60
|
+
skipped: [
|
|
61
|
+
{
|
|
62
|
+
path,
|
|
63
|
+
reason:
|
|
64
|
+
"it is no longer the old scaffold's file byte for byte, so its ports stay: the diff is the scaffold's change, to make by hand if two apps share this machine",
|
|
65
|
+
diff: unifiedDiff(path, old, today),
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const codemod: Codemod = {
|
|
72
|
+
id: 'test-ports',
|
|
73
|
+
since: '31.27.0',
|
|
74
|
+
summary: `${TEST_COMPOSE_PATH} and ${TEST_ENV_PATH} publish this app's own test ports, so two apps on one machine run at once`,
|
|
75
|
+
async run(app) {
|
|
76
|
+
const kebab = appName((await readText(app, TEST_ENV_PATH))?.text ?? '');
|
|
77
|
+
if (kebab === undefined) return NOTHING;
|
|
78
|
+
const name = names(kebab);
|
|
79
|
+
const results: CodemodResult[] = [];
|
|
80
|
+
for (const file of testServicesFiles(name)) {
|
|
81
|
+
if (typeof file.contents === 'string')
|
|
82
|
+
results.push(await move(app, file.path, file.contents, name));
|
|
83
|
+
}
|
|
84
|
+
return mergeResults(results);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// 31.27.0: every scaffold ships a `live` suite (the production driver against a real Postgres) and,
|
|
2
|
+
// where it serves a page, an `e2e` suite (the landing page in a real browser). An app that predates
|
|
3
|
+
// them gains each, as `x new` writes it today; one it already holds is its own.
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
E2E_SUITE_PATH,
|
|
7
|
+
e2eSuiteFiles,
|
|
8
|
+
LIVE_SUITE_PATH,
|
|
9
|
+
liveSuiteFiles,
|
|
10
|
+
} from '../templates/scaffold-suites';
|
|
11
|
+
import type { Codemod, CodemodApp, CodemodResult } from './codemod';
|
|
12
|
+
import { mergeResults, writeIfAbsent } from './engine-edits';
|
|
13
|
+
|
|
14
|
+
const NOTHING: CodemodResult = { changed: [], skipped: [] };
|
|
15
|
+
|
|
16
|
+
/** Each suite lands beside what it drives: no db package, no live suite; no landing page, no e2e. */
|
|
17
|
+
const HOSTS: readonly (readonly [string, string])[] = [
|
|
18
|
+
[LIVE_SUITE_PATH, 'packages/db/src/index.ts'],
|
|
19
|
+
[E2E_SUITE_PATH, 'apps/web/site/page.tsx'],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
async function suite(app: CodemodApp, path: string, host: string): Promise<CodemodResult> {
|
|
23
|
+
if (!(await app.exists(host))) return NOTHING;
|
|
24
|
+
const file = [...liveSuiteFiles(), ...e2eSuiteFiles()].find((one) => one.path === path);
|
|
25
|
+
return typeof file?.contents === 'string' ? writeIfAbsent(app, path, file.contents) : NOTHING;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const codemod: Codemod = {
|
|
29
|
+
id: 'test-suites',
|
|
30
|
+
since: '31.27.0',
|
|
31
|
+
summary: `the live and e2e suites every scaffold ships: ${LIVE_SUITE_PATH} and ${E2E_SUITE_PATH}`,
|
|
32
|
+
async run(app) {
|
|
33
|
+
const results: CodemodResult[] = [];
|
|
34
|
+
for (const [path, host] of HOSTS) results.push(await suite(app, path, host));
|
|
35
|
+
return mergeResults(results);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// 31.15.0: an island's mount replaces its server markup through `mountOver`, which puts it back if
|
|
2
|
+
// the render throws — the shipped `island-mount-clears` guard refuses `el.textContent = ''`. The
|
|
3
|
+
// scaffold's own theme toggle, where it stands as `x new` wrote it; the example slice is the app's.
|
|
4
|
+
|
|
5
|
+
import type { Codemod } from './codemod';
|
|
6
|
+
import type { SnippetEdit } from './engine-edits';
|
|
7
|
+
import { editSnippets } from './engine-edits';
|
|
8
|
+
|
|
9
|
+
const TOGGLE = 'apps/web/shared/theme-toggle.island.tsx';
|
|
10
|
+
|
|
11
|
+
const lines = (...text: readonly string[]): string => text.join('\n');
|
|
12
|
+
|
|
13
|
+
const UI = "import { setSolidRuntime, ThemeToggle, UiProvider } from '@ultimat3/ui';";
|
|
14
|
+
|
|
15
|
+
export const THEME_TOGGLE_EDITS: readonly SnippetEdit[] = [
|
|
16
|
+
{ from: UI, to: lines("import { mountOver } from '@ultimat3/render/client';", UI) },
|
|
17
|
+
{
|
|
18
|
+
from: lines(
|
|
19
|
+
' * namespace object keeps every export of solid-js alive in the chunk. The shell is cleared before',
|
|
20
|
+
" * `render`, which APPENDS — the server's copy would otherwise stay on screen beside the live one.",
|
|
21
|
+
),
|
|
22
|
+
to: lines(
|
|
23
|
+
' * namespace object keeps every export of solid-js alive in the chunk. `mountOver` clears the shell',
|
|
24
|
+
' * before `render`, which APPENDS, and puts it back if the render throws: a broken toggle shows the',
|
|
25
|
+
" * server's copy, not a blank box, and the throw still reaches the runtime's `data-x-failed`.",
|
|
26
|
+
),
|
|
27
|
+
optional: true,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
from: lines(
|
|
31
|
+
" el.textContent = '';",
|
|
32
|
+
" // Solid's disposer, returned: the client router calls it when it navigates away, and a mount",
|
|
33
|
+
' // that returns nothing is X_ISLAND_DISPOSER_MISSING.',
|
|
34
|
+
' return render(',
|
|
35
|
+
' () => (',
|
|
36
|
+
' <UiProvider locale={props.locale}>',
|
|
37
|
+
' <ThemeToggle mode="toggle" />',
|
|
38
|
+
' </UiProvider>',
|
|
39
|
+
' ),',
|
|
40
|
+
' el,',
|
|
41
|
+
' );',
|
|
42
|
+
),
|
|
43
|
+
to: lines(
|
|
44
|
+
" // Solid's disposer, returned: the client router calls it when it navigates away, and a mount",
|
|
45
|
+
' // that returns nothing is X_ISLAND_DISPOSER_MISSING.',
|
|
46
|
+
' return mountOver(el, (root) =>',
|
|
47
|
+
' render(',
|
|
48
|
+
' () => (',
|
|
49
|
+
' <UiProvider locale={props.locale}>',
|
|
50
|
+
' <ThemeToggle mode="toggle" />',
|
|
51
|
+
' </UiProvider>',
|
|
52
|
+
' ),',
|
|
53
|
+
' root,',
|
|
54
|
+
' ),',
|
|
55
|
+
' );',
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
export const codemod: Codemod = {
|
|
61
|
+
id: 'theme-toggle-mount-over',
|
|
62
|
+
since: '31.15.0',
|
|
63
|
+
summary: `${TOGGLE} mounts through mountOver: a toggle whose render throws keeps the server's copy`,
|
|
64
|
+
async run(app) {
|
|
65
|
+
// The import alone would be added to a toggle whose mount the app rewrote: both, or neither.
|
|
66
|
+
const held = (await app.read(TOGGLE)) ?? '';
|
|
67
|
+
if (!held.includes(" el.textContent = '';")) return { changed: [], skipped: [] };
|
|
68
|
+
return editSnippets(app, TOGGLE, THEME_TOGGLE_EDITS);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Carries an app off vendored copies of shipped guards, once: every shipped guard runs from the
|
|
2
|
+
// installed framework now. An unedited copy — any form a release shipped — is deleted; one that
|
|
3
|
+
// differs only in severity becomes a `guards/shipped.json` row; any other edit is kept as the app's
|
|
4
|
+
// own guard under a new name, the shipped one off, with the reason and the diff — never lost.
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
parseShippedConfig,
|
|
8
|
+
SHIPPED_GUARD_CONFIG,
|
|
9
|
+
SHIPPED_SEVERITY_FIELD,
|
|
10
|
+
type ShippedSeverity,
|
|
11
|
+
vendoredPath,
|
|
12
|
+
} from '../guards-built-in';
|
|
13
|
+
import { guardFormHash, sameText, shippedFormSeverity } from '../guards-vendored';
|
|
14
|
+
import { RELEASED_GUARD_TEST_FORMS } from '../templates/guard-released-forms';
|
|
15
|
+
import {
|
|
16
|
+
SHIPPED_GUARD_NAMES,
|
|
17
|
+
shippedGuardForms,
|
|
18
|
+
shippedGuardTest,
|
|
19
|
+
} from '../templates/scaffold-guards';
|
|
20
|
+
import { VERIFY_FLOOR_FILE } from '../verify-floor';
|
|
21
|
+
import { GUARD_BASELINE_FIELD } from '../verify-guard-baseline';
|
|
22
|
+
import type { Codemod, CodemodApp, CodemodResult } from './codemod';
|
|
23
|
+
import { unifiedDiff } from './engine-diff';
|
|
24
|
+
|
|
25
|
+
/** The severity line a report-only guard carries; stripped, two copies differing only there match. */
|
|
26
|
+
const SEVERITY_LINE = /^\s*severity:\s*'warning',\s*\n/gm;
|
|
27
|
+
const REPORT_ONLY = /^\s*severity:\s*'warning',\s*$/m;
|
|
28
|
+
const withoutSeverity = (text: string): string =>
|
|
29
|
+
text.replaceAll('\r\n', '\n').replaceAll(SEVERITY_LINE, '');
|
|
30
|
+
|
|
31
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
32
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
33
|
+
|
|
34
|
+
/** What one copy becomes: deleted at a severity, or kept as the app's own guard. */
|
|
35
|
+
type Verdict =
|
|
36
|
+
| { readonly kind: 'delete'; readonly severity: 'error' | 'warning' }
|
|
37
|
+
| { readonly kind: 'keep' };
|
|
38
|
+
|
|
39
|
+
/** The copy against every current form of its guard: exact, then exact but for severity. */
|
|
40
|
+
/** Every rule-file text a release shipped, by guard: `RELEASED_GUARD_FORMS`' shape. */
|
|
41
|
+
type ReleasedForms = Parameters<typeof shippedFormSeverity>[2];
|
|
42
|
+
|
|
43
|
+
/** The tables a run judges against: the committed ones unless a test passes its own. */
|
|
44
|
+
export interface ReleasedTables {
|
|
45
|
+
readonly forms?: ReleasedForms;
|
|
46
|
+
readonly tests?: Readonly<Record<string, readonly string[]>>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The copy against every form of its guard — current or released — then exact but for severity. */
|
|
50
|
+
const judge = (name: string, copy: string, released: ReleasedForms): Verdict => {
|
|
51
|
+
const shipped = shippedFormSeverity(name, copy, released);
|
|
52
|
+
if (shipped !== undefined) return { kind: 'delete', severity: shipped };
|
|
53
|
+
const bare = withoutSeverity(copy);
|
|
54
|
+
if (shippedGuardForms(name).some((form) => withoutSeverity(form.source) === bare)) {
|
|
55
|
+
return { kind: 'delete', severity: REPORT_ONLY.test(copy) ? 'warning' : 'error' };
|
|
56
|
+
}
|
|
57
|
+
return { kind: 'keep' };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** `guards/app-<name>.ts`, or the first `app-<name>-<n>` the app does not already hold. */
|
|
61
|
+
const freeName = async (app: CodemodApp, name: string): Promise<string> => {
|
|
62
|
+
for (let n = 1; ; n += 1) {
|
|
63
|
+
const candidate = n === 1 ? `app-${name}` : `app-${name}-${String(n)}`;
|
|
64
|
+
if (!(await app.exists(`guards/${candidate}.ts`))) return candidate;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** A baseline written for the shipped name follows its rule to the new one, or it goes stale. */
|
|
69
|
+
const moveBaselines = async (
|
|
70
|
+
app: CodemodApp,
|
|
71
|
+
renamed: ReadonlyMap<string, string>,
|
|
72
|
+
): Promise<boolean> => {
|
|
73
|
+
const text = await app.read(VERIFY_FLOOR_FILE);
|
|
74
|
+
if (text === undefined || renamed.size === 0) return false;
|
|
75
|
+
let floor: unknown;
|
|
76
|
+
try {
|
|
77
|
+
floor = JSON.parse(text);
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const baseline = isRecord(floor) ? floor[GUARD_BASELINE_FIELD] : undefined;
|
|
82
|
+
if (!isRecord(floor) || !isRecord(baseline)) return false;
|
|
83
|
+
const moved = Object.fromEntries(
|
|
84
|
+
Object.entries(baseline).map(([key, value]) => [renamed.get(key) ?? key, value]),
|
|
85
|
+
);
|
|
86
|
+
if (Object.keys(baseline).every((key) => !renamed.has(key))) return false;
|
|
87
|
+
await app.write(
|
|
88
|
+
VERIFY_FLOOR_FILE,
|
|
89
|
+
`${JSON.stringify({ ...floor, [GUARD_BASELINE_FIELD]: moved }, null, 2)}\n`,
|
|
90
|
+
);
|
|
91
|
+
return true;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
async function run(app: CodemodApp, tables: ReleasedTables): Promise<CodemodResult> {
|
|
95
|
+
const changed: string[] = [];
|
|
96
|
+
const skipped: CodemodResult['skipped'] = [];
|
|
97
|
+
const configText = await app.read(SHIPPED_GUARD_CONFIG);
|
|
98
|
+
const parsed = configText === undefined ? undefined : parseShippedConfig(configText);
|
|
99
|
+
if (parsed !== undefined && parsed.problems.length > 0) {
|
|
100
|
+
const reason = `${SHIPPED_GUARD_CONFIG} does not parse (${parsed.problems.join('; ')}): fix it, then x upgrade again`;
|
|
101
|
+
return { changed, skipped: [{ path: SHIPPED_GUARD_CONFIG, reason }] };
|
|
102
|
+
}
|
|
103
|
+
const rows: Record<string, ShippedSeverity> = { ...(parsed?.severity ?? {}) };
|
|
104
|
+
const held = (await app.glob('guards/*.{ts,tsx}')).filter(
|
|
105
|
+
(path) => !/\.(?:test|d)\.tsx?$/.test(path),
|
|
106
|
+
);
|
|
107
|
+
const renamed = new Map<string, string>();
|
|
108
|
+
for (const name of SHIPPED_GUARD_NAMES) {
|
|
109
|
+
const path = vendoredPath(held, name);
|
|
110
|
+
const own = shippedGuardForms(name)[0]?.severity ?? 'error';
|
|
111
|
+
if (path === undefined) {
|
|
112
|
+
// A legacy app never had this guard gate it: it keeps reporting only, until the author says.
|
|
113
|
+
if (configText === undefined && own === 'error' && !Object.hasOwn(rows, name)) {
|
|
114
|
+
rows[name] = 'warning';
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const copy = (await app.read(path)) ?? '';
|
|
119
|
+
const testPath = `guards/${name}.test.ts`;
|
|
120
|
+
const test = await app.read(testPath);
|
|
121
|
+
const verdict = judge(name, copy, tables.forms);
|
|
122
|
+
if (verdict.kind === 'delete') {
|
|
123
|
+
await app.remove(path);
|
|
124
|
+
changed.push(path);
|
|
125
|
+
if (verdict.severity !== own && !Object.hasOwn(rows, name)) rows[name] = verdict.severity;
|
|
126
|
+
if (test !== undefined) {
|
|
127
|
+
await app.remove(testPath);
|
|
128
|
+
changed.push(testPath);
|
|
129
|
+
const shipped = shippedGuardTest(name) ?? '';
|
|
130
|
+
const releasedTests = tables.tests ?? RELEASED_GUARD_TEST_FORMS;
|
|
131
|
+
const known = Object.hasOwn(releasedTests, name) ? releasedTests[name] : undefined;
|
|
132
|
+
// A test some release wrote is unedited; only one no release shipped can hold a case.
|
|
133
|
+
if (!sameText(test, shipped) && !(known ?? []).includes(guardFormHash(test))) {
|
|
134
|
+
skipped.push({
|
|
135
|
+
path: testPath,
|
|
136
|
+
reason: `deleted with its rule, which is the shipped one and tested by the framework now; a case you added is in the diff — carry it to a test of your own`,
|
|
137
|
+
diff: unifiedDiff(testPath, shipped, test),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const next = await freeName(app, name);
|
|
144
|
+
const nextPath = `guards/${next}${path.endsWith('.tsx') ? '.tsx' : '.ts'}`;
|
|
145
|
+
await app.write(nextPath, copy);
|
|
146
|
+
await app.remove(path);
|
|
147
|
+
changed.push(path, nextPath);
|
|
148
|
+
if (test !== undefined) {
|
|
149
|
+
const nextTest = `guards/${next}.test.ts`;
|
|
150
|
+
await app.write(nextTest, test.replaceAll(`from './${name}'`, `from './${next}'`));
|
|
151
|
+
await app.remove(testPath);
|
|
152
|
+
changed.push(testPath, nextTest);
|
|
153
|
+
}
|
|
154
|
+
rows[name] = 'off';
|
|
155
|
+
renamed.set(name, next);
|
|
156
|
+
skipped.push({
|
|
157
|
+
path: nextPath,
|
|
158
|
+
reason: `${path} is not a form of the shipped ${name} guard and not one a ${SHIPPED_GUARD_CONFIG} row can say, so it is kept as your own guard ${nextPath} and the shipped one is "off" — delete ${nextPath} and that row to take the shipped rule`,
|
|
159
|
+
diff: unifiedDiff(path, shippedGuardForms(name)[0]?.source ?? '', copy),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (await moveBaselines(app, renamed)) changed.push(VERIFY_FLOOR_FILE);
|
|
163
|
+
// Written when absent — its presence is the opt-in — or when a row moved; never reformatted.
|
|
164
|
+
const sorted = Object.entries(rows).sort(([a], [b]) => (a < b ? -1 : 1));
|
|
165
|
+
const before = Object.entries(parsed?.severity ?? {}).sort(([a], [b]) => (a < b ? -1 : 1));
|
|
166
|
+
if (configText === undefined || JSON.stringify(sorted) !== JSON.stringify(before)) {
|
|
167
|
+
const severity = Object.fromEntries(sorted);
|
|
168
|
+
await app.write(
|
|
169
|
+
SHIPPED_GUARD_CONFIG,
|
|
170
|
+
`${JSON.stringify({ [SHIPPED_SEVERITY_FIELD]: severity }, null, 2)}\n`,
|
|
171
|
+
);
|
|
172
|
+
changed.push(SHIPPED_GUARD_CONFIG);
|
|
173
|
+
}
|
|
174
|
+
return { changed, skipped };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The migration over a released-forms table: the committed one, or a test's own. */
|
|
178
|
+
export const vendoredGuardsCodemod = (tables: ReleasedTables = {}): Codemod => ({
|
|
179
|
+
id: 'vendored-guards',
|
|
180
|
+
since: '31.28.0',
|
|
181
|
+
summary:
|
|
182
|
+
'shipped guards run from the installed framework: unedited copies in guards/ deleted, an edit kept as a guards/shipped.json row or an app guard',
|
|
183
|
+
run: (app) => run(app, tables),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export const codemod: Codemod = vendoredGuardsCodemod();
|