@ultimat3/cli 31.5.0 → 31.6.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/CLAUDE.md +15 -8
- package/package.json +29 -29
- package/src/admin-catalog-keys.ts +17 -1
- package/src/app-transport.ts +7 -3
- package/src/browser-barrel-cut.ts +109 -0
- package/src/browser-import-chain.ts +119 -0
- package/src/browser-transport.ts +85 -13
- package/src/cmd-dev.ts +15 -2
- package/src/cmd-fix.ts +14 -4
- package/src/cmd-i18n.ts +52 -10
- package/src/dev-boot.ts +6 -4
- package/src/dev-log.ts +95 -0
- package/src/dev-rebuild-remount.ts +152 -0
- package/src/dev-rebuild-schema.ts +30 -0
- package/src/dev-rebuild.ts +51 -14
- package/src/dev-supervisor.ts +5 -4
- package/src/error-codes.ts +2 -0
- package/src/error-contract.ts +29 -2
- package/src/fix-sequence.ts +97 -0
- package/src/generate-grant-findings.ts +2 -2
- package/src/generate-grants.ts +50 -1
- package/src/generate-write.ts +16 -0
- package/src/i18n-registration.ts +8 -5
- package/src/island-bundle.ts +9 -9
- package/src/island-group-cache.ts +2 -1
- package/src/island-identity.ts +22 -51
- package/src/island-link.ts +32 -65
- package/src/island-outputs.ts +2 -6
- package/src/island-realtime.ts +1 -3
- package/src/island-runtime.ts +11 -8
- package/src/load-findings.ts +29 -22
- package/src/mcp-errors.ts +11 -3
- package/src/mcp-host-shell.ts +128 -0
- package/src/mcp-host.ts +19 -54
- package/src/mcp-test-output.ts +5 -2
- package/src/messages-gate.ts +12 -0
- package/src/messages.ts +16 -0
- package/src/page-sync.ts +1 -1
- package/src/policy-append.ts +88 -0
- package/src/sw-artifacts.ts +1 -1
- package/src/templates/entity.ts +18 -3
- package/src/templates/policy.ts +5 -1
- package/src/templates/query.ts +4 -2
- package/src/templates/resource-service.ts +5 -2
- package/src/templates/scaffold-repo.ts +8 -2
- package/src/ts-scan.ts +86 -1
- package/src/verify-checks.ts +23 -51
- package/src/verify-contract-diff.ts +143 -0
- package/src/verify-seeds.ts +132 -0
- package/src/verify-tests.ts +12 -6
- package/src/worker-bundle.ts +8 -9
- package/wiki/CLI-Reference.md +2 -2
- package/wiki/Upgrading.md +4 -0
package/src/dev-supervisor.ts
CHANGED
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
import { devPortFor } from './dev-port';
|
|
18
18
|
import { type RetiringWorker, retireThenDrain } from './dev-restart-retire';
|
|
19
19
|
import { PORT_RANGE } from './flag-number';
|
|
20
|
-
import { msg } from './messages';
|
|
21
20
|
import type { Finding } from './output';
|
|
22
21
|
import { parseArgs } from './parse';
|
|
23
22
|
import { posixRelative } from './posix-path';
|
|
@@ -237,7 +236,7 @@ export function restartFinding(root: string, pins: readonly StalePin[]): Finding
|
|
|
237
236
|
|
|
238
237
|
/** The child's half: what `startDev` is handed, and what the hold calls once released. */
|
|
239
238
|
export interface ChildRestart {
|
|
240
|
-
readonly options: { readonly onRestart?: (pins: readonly StalePin[]) => void };
|
|
239
|
+
readonly options: { readonly onRestart?: (pins: readonly StalePin[], line: string) => void };
|
|
241
240
|
readonly exit: (code: number) => void;
|
|
242
241
|
/**
|
|
243
242
|
* The worker this child booted, handed over once `startDev` returns: a restart retires it before
|
|
@@ -278,11 +277,13 @@ export function childRestart(
|
|
|
278
277
|
});
|
|
279
278
|
return {
|
|
280
279
|
options: {
|
|
281
|
-
|
|
280
|
+
// `line` is the rebuild's, rendered for the restart's own cause (`dev-rebuild.ts`): a pinned
|
|
281
|
+
// module, a changed route table or a load finding that appeared or cleared.
|
|
282
|
+
onRestart: (_pins, line) => {
|
|
282
283
|
// Already stopping for a signal (`x stop`, Ctrl-C) or a gone supervisor or root: a save
|
|
283
284
|
// landing during that drain must not respawn a child its operator asked to end.
|
|
284
285
|
if (leaving !== undefined && leaving !== 'restart') return;
|
|
285
|
-
writeErrorLine(
|
|
286
|
+
writeErrorLine(line);
|
|
286
287
|
leaving ??= 'restart';
|
|
287
288
|
watched?.stopping(DEV_RESTART_EXIT_CODE);
|
|
288
289
|
if (restarting) return;
|
package/src/error-codes.ts
CHANGED
|
@@ -237,6 +237,7 @@ export const CLI_OWNED_ERROR_CODES = [
|
|
|
237
237
|
'X_WORKSPACE_NAME_TAKEN',
|
|
238
238
|
'X_PARTITIONS_UNMAINTAINED',
|
|
239
239
|
'X_TYPESCRIPT_VERSION',
|
|
240
|
+
'X_SEED_FAILED',
|
|
240
241
|
] as const;
|
|
241
242
|
|
|
242
243
|
/**
|
|
@@ -460,6 +461,7 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
|
|
|
460
461
|
'x g app or x g package was given a name the other workspace kind already holds',
|
|
461
462
|
X_PARTITIONS_UNMAINTAINED: 'a partitioned entity with no partitions() job',
|
|
462
463
|
X_TYPESCRIPT_VERSION: 'The app declares a TypeScript older than the one x new scaffolds',
|
|
464
|
+
X_SEED_FAILED: 'a seed threw an uncoded error',
|
|
463
465
|
};
|
|
464
466
|
|
|
465
467
|
// One unconditional call, so a second package claiming one of the CLI's codes throws
|
package/src/error-contract.ts
CHANGED
|
@@ -112,25 +112,52 @@ export interface ErrorFixReport {
|
|
|
112
112
|
* relative specifiers only, and that gap is 3 call sites across this repo, measured 2026-08.
|
|
113
113
|
*/
|
|
114
114
|
readonly unreadable: number;
|
|
115
|
+
/** File → fix lines `fix-sequence.ts` refused there, allowed or not: what the baseline must equal. */
|
|
116
|
+
readonly sequenceRefused: ReadonlyMap<string, number>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* `fix-sequence.ts`'s rule, ratcheted per file: a file at or under its recorded count passes, and
|
|
121
|
+
* past it every refused line is reported — a text scan cannot tell which of them is the new one.
|
|
122
|
+
*/
|
|
123
|
+
function sequenceRefusals(
|
|
124
|
+
sites: readonly FixSite[],
|
|
125
|
+
fixSequenceProblem: (fix: string) => string | undefined,
|
|
126
|
+
): readonly Finding[] {
|
|
127
|
+
return sites.flatMap((site) => {
|
|
128
|
+
const problem = fixSequenceProblem(staticFix(site.fix));
|
|
129
|
+
return problem === undefined ? [] : [fixFinding(site, problem)];
|
|
130
|
+
});
|
|
115
131
|
}
|
|
116
132
|
|
|
117
133
|
export async function checkErrorFixReport(root: string): Promise<ErrorFixReport> {
|
|
118
134
|
const findings: Finding[] = [];
|
|
119
135
|
const catalog = await loadCommandCatalog();
|
|
136
|
+
// At its point of use, like the catalog: `app-load.ts` imports this module for
|
|
137
|
+
// `collectDeclaredCodes`, and a gate-only rule must not ride into every serving role's graph
|
|
138
|
+
// (`serve-graph.test.ts`'s `SERVING_ROLE_CEILING`).
|
|
139
|
+
const { FIX_SEQUENCE_BASELINE, fixSequenceProblem, generatorForceProblem } = await import(
|
|
140
|
+
'./fix-sequence'
|
|
141
|
+
);
|
|
120
142
|
const imports = createHelperResolver(root);
|
|
121
143
|
let checked = 0;
|
|
122
144
|
let unreadable = 0;
|
|
145
|
+
const sequenceRefused = new Map<string, number>();
|
|
123
146
|
for await (const path of eachSourceFile(root)) {
|
|
124
147
|
if (isTest(path) || isGenerated(path)) continue;
|
|
125
148
|
const source = await Bun.file(join(root, path)).text();
|
|
126
149
|
const scan = scanFixSites(source, path, await imports(path, source));
|
|
127
150
|
checked += scan.sites.length;
|
|
128
151
|
unreadable += scan.unreadable;
|
|
152
|
+
const refused = sequenceRefusals(scan.sites, fixSequenceProblem);
|
|
153
|
+
if (refused.length > 0) sequenceRefused.set(path, refused.length);
|
|
154
|
+
if (refused.length > (FIX_SEQUENCE_BASELINE.get(path) ?? 0)) findings.push(...refused);
|
|
129
155
|
for (const site of scan.sites) {
|
|
130
156
|
// The interpolation-blanked form for both rules: `x ${name}` names no command this can
|
|
131
157
|
// resolve, and reading `<value>` as one would be a finding nobody can act on.
|
|
132
158
|
const fix = staticFix(site.fix);
|
|
133
|
-
const problem =
|
|
159
|
+
const problem =
|
|
160
|
+
fixProblem(site.fix) ?? generatorForceProblem(fix) ?? citedCommandProblem(fix, catalog);
|
|
134
161
|
if (problem !== undefined) {
|
|
135
162
|
findings.push(fixFinding(site, problem));
|
|
136
163
|
continue;
|
|
@@ -141,7 +168,7 @@ export async function checkErrorFixReport(root: string): Promise<ErrorFixReport>
|
|
|
141
168
|
if (missing !== undefined) findings.push(pathFinding(site, missing));
|
|
142
169
|
}
|
|
143
170
|
}
|
|
144
|
-
return { findings, checked, unreadable };
|
|
171
|
+
return { findings, checked, unreadable, sequenceRefused };
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
/** The findings alone, for every caller that reports no coverage line. */
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The order rule on a `fix:` line, for the `errors` step: the edit leads, the re-run follows —
|
|
2
|
+
// `x verify # after deleting .sensitive()` is pasted before it is read, and re-runs unchanged.
|
|
3
|
+
// Shipped lines are ratcheted per file in `FIX_SEQUENCE_BASELINE`; a new one is
|
|
4
|
+
// `X_ERROR_FIX_INVALID`. A generator offered with `--force` is never a fix (none shipped 2026-11).
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A comment opening with the precondition, in its deferred-edit form only: `<command> # after
|
|
8
|
+
* editing …` (a gerund, a call, or an interpolated edit) or `# once … is repaired` (a past
|
|
9
|
+
* participle). A `#` glued to a word is a URL fragment (`…/Upgrading#after-31`), and `# once per
|
|
10
|
+
* environment` / `# once, at boot` is a frequency — neither is refused.
|
|
11
|
+
*/
|
|
12
|
+
const DEFERRED_EDIT =
|
|
13
|
+
/(?:^|\s)#\s+(?:(after)\s+(?:\w+ing\b|[\w.$]+\(|<value>)|(once)\s+(?!(?:per|only|a|an|each|every|more)\b)[^#,]*?\b\w+ed\b)/i;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A line whose whole instruction is to run the failing command again: an optional "fix the
|
|
17
|
+
* failure / cause / error, then", the re-run, and nothing it names to change.
|
|
18
|
+
*/
|
|
19
|
+
const RERUN_ONLY =
|
|
20
|
+
/^\s*(?:(?:fix|resolve|address|correct|repair)\b[^,.;#]*\b(?:cause|failure|error|problem)\b[^,.;#]*[,;]?\s*(?:then|and)\s+)?(?:re-?run|retry|run (?:it |this )?again)(?:\s+(?:it|this|the command|this command))?\s*\.?\s*$/i;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The rule, on one fix line — already `staticFix`ed by the caller, as every rule of the step reads
|
|
24
|
+
* it. `undefined` means the line leads with what to change.
|
|
25
|
+
*/
|
|
26
|
+
export function fixSequenceProblem(fix: string): string | undefined {
|
|
27
|
+
const deferred = DEFERRED_EDIT.exec(fix);
|
|
28
|
+
if (deferred !== null) {
|
|
29
|
+
return `fix "${fix}" opens with the command and defers the edit to "# ${deferred[1] ?? deferred[2]} …", so the line pasted first re-runs the failure unchanged — lead with the edit, then the command`;
|
|
30
|
+
}
|
|
31
|
+
if (RERUN_ONLY.test(fix)) {
|
|
32
|
+
return `fix "${fix}" only says to re-run, and names no edit, call or file that would make the re-run pass`;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `x g …` / `x generate …` carrying `--force`, before any `#` comment: the part that is pasted. */
|
|
38
|
+
const FORCED_GENERATOR = /(?:^|[\s;|&(])x\s+(?:g|generate)\b[^#]*?\s--force(?![\w-])/;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A printed fix is pasted with no diff in front of it, and a generator's file can be shared — a
|
|
42
|
+
* slice's `policy.ts` holds every permission its generators wrote, and `x g policy … --force`
|
|
43
|
+
* replaced the first with the second (FX2). Prose behind the `#` is not pasted, so it is not read.
|
|
44
|
+
*/
|
|
45
|
+
export function generatorForceProblem(fix: string): string | undefined {
|
|
46
|
+
const runnable = fix.split(/\s#\s/)[0] ?? '';
|
|
47
|
+
if (!FORCED_GENERATOR.test(runnable)) return undefined;
|
|
48
|
+
return `fix "${fix}" runs a generator with --force, which overwrites a file other slices or generators may share, and a pasted fix shows no diff first — name the edit to the existing file instead`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Root-relative file → how many fix lines in it the rule above refuses: 53 lines in 38 files across
|
|
53
|
+
* this repo and its three tracked apps, measured 2026-11-11 (the docs site's
|
|
54
|
+
* `packages/docs-source/src/errors.ts` is the one app entry). A file at or under its count passes;
|
|
55
|
+
* one past it, or any file not listed — every app's — is a finding at each of its refused lines.
|
|
56
|
+
* Held EQUAL to the step's counts by `fix-sequence.test.ts`: rewrite a line, lower its entry.
|
|
57
|
+
*/
|
|
58
|
+
export const FIX_SEQUENCE_BASELINE: ReadonlyMap<string, number> = new Map([
|
|
59
|
+
['packages/cli/src/cmd-client-customer.ts', 1],
|
|
60
|
+
['packages/cli/src/cmd-deploy-preflight.ts', 1],
|
|
61
|
+
['packages/cli/src/cmd-env-init.ts', 1],
|
|
62
|
+
['packages/cli/src/handle-registration.ts', 1],
|
|
63
|
+
['packages/cli/src/job-registration.ts', 1],
|
|
64
|
+
['packages/cli/src/package-boundaries.ts', 1],
|
|
65
|
+
['packages/cli/src/upgrade-plan.ts', 1],
|
|
66
|
+
['packages/cli/src/verify-drift-owner.ts', 1],
|
|
67
|
+
['packages/core/src/define-error.ts', 1],
|
|
68
|
+
['packages/core/src/errors.ts', 1],
|
|
69
|
+
['packages/db/src/drift-triggers.ts', 1],
|
|
70
|
+
['packages/db/src/generate-partition.ts', 2],
|
|
71
|
+
['packages/db/src/lifecycle-errors.ts', 1],
|
|
72
|
+
['packages/db/src/primary-key.ts', 1],
|
|
73
|
+
['packages/docs-source/src/errors.ts', 4],
|
|
74
|
+
['packages/entity/src/counter.ts', 1],
|
|
75
|
+
['packages/entity/src/partition.ts', 1],
|
|
76
|
+
['packages/entity/src/retain.ts', 1],
|
|
77
|
+
['packages/jobs/src/subject-errors.ts', 1],
|
|
78
|
+
['packages/mail/src/preview-check.ts', 1],
|
|
79
|
+
['packages/mcp/src/meta-errors.ts', 1],
|
|
80
|
+
['packages/mcp/src/remote-errors.ts', 1],
|
|
81
|
+
['packages/schema/src/sensitive.ts', 1],
|
|
82
|
+
['packages/seo/src/errors.ts', 1],
|
|
83
|
+
['packages/testing/src/exercise-override-input.ts', 1],
|
|
84
|
+
['packages/testing/src/plan-sweep-report.ts', 4],
|
|
85
|
+
['scripts/adapter-ports.ts', 4],
|
|
86
|
+
['scripts/bench-claims.ts', 1],
|
|
87
|
+
['scripts/budget-raises.ts', 1],
|
|
88
|
+
['scripts/declaration-readers-callers.ts', 2],
|
|
89
|
+
['scripts/factory-names.ts', 2],
|
|
90
|
+
['scripts/instrument-slots.ts', 1],
|
|
91
|
+
['scripts/lib/export-all.ts', 1],
|
|
92
|
+
['scripts/new-error-code.ts', 1],
|
|
93
|
+
['scripts/plan-status.ts', 3],
|
|
94
|
+
['scripts/posix-relative.ts', 1],
|
|
95
|
+
['scripts/set-cookie-literals.ts', 2],
|
|
96
|
+
['scripts/sql-export-readers.ts', 1],
|
|
97
|
+
]);
|
|
@@ -8,9 +8,9 @@ import { appDisk } from './generate-disk';
|
|
|
8
8
|
import type { RoleGrant } from './generate-grants';
|
|
9
9
|
import {
|
|
10
10
|
adminGrantsFor,
|
|
11
|
-
grantsForWritten,
|
|
12
11
|
insertGrants,
|
|
13
12
|
insertPermissions,
|
|
13
|
+
policyGrantsFor,
|
|
14
14
|
writtenTables,
|
|
15
15
|
} from './generate-grants';
|
|
16
16
|
import type { Finding } from './output';
|
|
@@ -49,7 +49,7 @@ export async function ungrantedByGenerator(
|
|
|
49
49
|
disk: GenerateDisk = appDisk(root),
|
|
50
50
|
): Promise<readonly Finding[]> {
|
|
51
51
|
const admin = (await writtenTables(root, written, disk)).flatMap(adminGrantsFor);
|
|
52
|
-
const grants = [...
|
|
52
|
+
const grants = [...(await policyGrantsFor(root, written, disk)), ...admin];
|
|
53
53
|
if (grants.length === 0) return [];
|
|
54
54
|
const source = await disk.read(ROLES_FILE);
|
|
55
55
|
// The file whose declarations nobody granted: where a reader starts when the map is not ours.
|
package/src/generate-grants.ts
CHANGED
|
@@ -39,6 +39,55 @@ export function grantsForWritten(written: readonly string[]): readonly RoleGrant
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** `member` reads, `admin` does everything else — `grantsForWritten`'s rule, per permission. */
|
|
43
|
+
const grantFor = (permission: string): RoleGrant => ({
|
|
44
|
+
role: permission.endsWith(':read') ? 'member' : 'admin',
|
|
45
|
+
permission,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** The string literals of the `definePermissions([...])` list opening at `open`. */
|
|
49
|
+
const literalsAt = (source: string, masked: string, open: number): readonly string[] =>
|
|
50
|
+
(readList(source, masked, open)?.entries ?? []).flatMap((entry) => {
|
|
51
|
+
const literal = /^'([^']+)'$/.exec(entry.text.trim())?.[1];
|
|
52
|
+
return literal === undefined ? [] : [literal];
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** Every permission a policy's `definePermissions([...])` calls declare, comments masked. */
|
|
56
|
+
export function declaredPermissions(source: string): readonly string[] {
|
|
57
|
+
const masked = maskOf(source);
|
|
58
|
+
return declarationLists(masked).flatMap((open) => literalsAt(source, masked, open));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The set a generator run WROTE into a policy: its LAST `definePermissions([...])` call. A fresh
|
|
63
|
+
* file holds one call, the template's; an append (`policy-append.ts`) puts its set after
|
|
64
|
+
* everything the author had. Never every declared permission: a hand-placed admin-only
|
|
65
|
+
* `payroll:read` earlier in the file would be granted to `member` by the next `x g policy`.
|
|
66
|
+
*/
|
|
67
|
+
export function introducedPermissions(source: string): readonly string[] {
|
|
68
|
+
const masked = maskOf(source);
|
|
69
|
+
const last = declarationLists(masked).at(-1);
|
|
70
|
+
return last === undefined ? [] : literalsAt(source, masked, last);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The grants the written policies imply: the set each run introduced, read off the file as it now
|
|
75
|
+
* stands — or, a file this cannot read a declaration from, the slice-path rule of
|
|
76
|
+
* `grantsForWritten`.
|
|
77
|
+
*/
|
|
78
|
+
export async function policyGrantsFor(
|
|
79
|
+
root: string,
|
|
80
|
+
written: readonly string[],
|
|
81
|
+
disk: GenerateDisk = appDisk(root),
|
|
82
|
+
): Promise<readonly RoleGrant[]> {
|
|
83
|
+
const grants: RoleGrant[] = [];
|
|
84
|
+
for (const path of written.filter((each) => POLICY_PATH.test(each))) {
|
|
85
|
+
const introduced = introducedPermissions((await disk.read(path)) ?? '');
|
|
86
|
+
grants.push(...(introduced.length > 0 ? introduced.map(grantFor) : grantsForWritten([path])));
|
|
87
|
+
}
|
|
88
|
+
return grants;
|
|
89
|
+
}
|
|
90
|
+
|
|
42
91
|
/** `entity('widgets', {` — the name the admin's permissions are spelled with. */
|
|
43
92
|
const ENTITY_NAME = /\bentity\(\s*'([^']+)'/;
|
|
44
93
|
|
|
@@ -166,7 +215,7 @@ export async function grantGeneratedPermissions(
|
|
|
166
215
|
disk: GenerateDisk = appDisk(root),
|
|
167
216
|
): Promise<readonly string[]> {
|
|
168
217
|
const admin = (await writtenTables(root, written, disk)).flatMap(adminGrantsFor);
|
|
169
|
-
const grants = [...
|
|
218
|
+
const grants = [...(await policyGrantsFor(root, written, disk)), ...admin];
|
|
170
219
|
const before = grants.length === 0 ? undefined : await disk.read(ROLES_FILE);
|
|
171
220
|
if (before === undefined) return [];
|
|
172
221
|
const unplaced = insertGrants(before, grants).skipped;
|
package/src/generate-write.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { commentSafe } from './comment-safe';
|
|
|
13
13
|
import { GenerateJsonInvalidError, ScaffoldPathEscapeError } from './errors';
|
|
14
14
|
import { mergeJsonDeep, mergeJsonInPlace, sortJsonDeep } from './json-merge';
|
|
15
15
|
import type { Finding } from './output';
|
|
16
|
+
import { appendPolicy } from './policy-append';
|
|
16
17
|
import { quoteArg } from './shell-quote';
|
|
17
18
|
import type { GeneratedFile } from './templates';
|
|
18
19
|
|
|
@@ -188,6 +189,12 @@ const conflictFix = (
|
|
|
188
189
|
return `${invocation} --force # overwrites ${path}, or pass a different name`;
|
|
189
190
|
const into = `--feature ${quoteArg(slice)}`;
|
|
190
191
|
const named = quoteArg(name);
|
|
192
|
+
// `x g policy` on a slice that already declares this very set: an action is the wrong kind and
|
|
193
|
+
// `--force` deletes every other rule in the file. A second set under its own name APPENDS.
|
|
194
|
+
const head = /^(?<head>.*? g) policy /.exec(invocation)?.groups?.['head'];
|
|
195
|
+
if (module === 'policy.ts' && head !== undefined) {
|
|
196
|
+
return `${head} policy ${quoteArg(`${name}-admin`)} ${into} # appends a second permission set: ${commentSafe(path)} already exports ${commentSafe(name)}'s`;
|
|
197
|
+
}
|
|
191
198
|
// A read needs the slice's table (X_FEATURE_REQUIRED), so it is offered only beside one.
|
|
192
199
|
const read = existsSync(join(dirname(absolute), 'entity.ts'))
|
|
193
200
|
? `or x g query ${named} ${into}`
|
|
@@ -212,6 +219,15 @@ function planFile(
|
|
|
212
219
|
? { kind: 'skip' }
|
|
213
220
|
: { kind: 'write', file, absolute, contents: file.contents };
|
|
214
221
|
}
|
|
222
|
+
// A slice's `policy.ts` holds every primitive's rules: a second permission set is appended to it,
|
|
223
|
+
// `--force` included — overwriting it would delete the rules already there. The same set again
|
|
224
|
+
// does not merge (`appendPolicy` answers undefined) and is the conflict below.
|
|
225
|
+
if (file.merge === undefined && typeof file.contents === 'string' && existsSync(absolute)) {
|
|
226
|
+
const merged = file.path.endsWith('/policy.ts')
|
|
227
|
+
? appendPolicy(readFileSync(absolute, 'utf8'), file.contents)
|
|
228
|
+
: undefined;
|
|
229
|
+
if (merged !== undefined) return { kind: 'write', file, absolute, contents: merged };
|
|
230
|
+
}
|
|
215
231
|
// The scaffold's own copy, untouched, is replaced without asking; an edited one is the author's.
|
|
216
232
|
if (file.merge === 'replaces-pristine' && existsSync(absolute)) {
|
|
217
233
|
if (readFileSync(absolute, 'utf8') === file.pristine) {
|
package/src/i18n-registration.ts
CHANGED
|
@@ -156,14 +156,18 @@ export async function checkRegistration(input: RegistrationInput): Promise<Regis
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
/**
|
|
160
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Keys the catalog does not define, or defines with a placeholder. Labels are never plurals.
|
|
161
|
+
* Exported because `x i18n sync` writes exactly this set and `x i18n check` counts it: one rule.
|
|
162
|
+
*/
|
|
163
|
+
export const unanswered = (catalog: Catalog, keys: readonly string[]): readonly string[] =>
|
|
161
164
|
keys.filter((key) => !Object.hasOwn(catalog, key) || isLoudMiss(catalog[key]));
|
|
162
165
|
|
|
163
166
|
/**
|
|
164
167
|
* `X_CATALOG_MISSING_KEYS` — the same fact, a catalog without keys it is asked for — with the
|
|
165
|
-
* cause naming who asks
|
|
166
|
-
*
|
|
168
|
+
* cause naming who asks. The fix stays the code's own, `x i18n sync <locale>`: it writes these keys
|
|
169
|
+
* too (`cmd-i18n.ts`), nested. The hand edit this used to name was a dotted key, which
|
|
170
|
+
* `loadCatalog` refuses as `X_CATALOG_INVALID`.
|
|
167
171
|
*/
|
|
168
172
|
function adminKeysFinding(locale: Locale, missing: readonly string[]): Finding {
|
|
169
173
|
const path = catalogPath(locale);
|
|
@@ -172,7 +176,6 @@ function adminKeysFinding(locale: Locale, missing: readonly string[]): Finding {
|
|
|
172
176
|
return {
|
|
173
177
|
...findingFrom(catalogMissingKeys(locale, missing)),
|
|
174
178
|
cause: `${path} is missing ${missing.length} key(s) the mounted admin renders (defineAdmin derives them, so no source file names one): ${shown.join(', ')}${more}`,
|
|
175
|
-
fix: `add to ${path}, each with its real label: ${shown.join(', ')}${more} — then x i18n check --json`,
|
|
176
179
|
at: path,
|
|
177
180
|
};
|
|
178
181
|
}
|
package/src/island-bundle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The island chunk table: every `*.island.tsx` in the app compiled as a bundle entry point,
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// named by a hash of its final BYTES (`island-link.ts`; why not its sources: `island-identity.ts`),
|
|
3
|
+
// plus the resolver that turns a page's `src` specifier into the URL its
|
|
4
4
|
// `data-x-entry` carries. The page's graph never reaches an island, so a `site/` document stays at
|
|
5
5
|
// 0kb whatever the island imports — axiom 6 made mechanical.
|
|
6
6
|
//
|
|
@@ -74,8 +74,8 @@ export interface IslandChunk {
|
|
|
74
74
|
/** `islandModuleId` of the filename — the id the document, the budget and a finding all name. */
|
|
75
75
|
readonly moduleId: string;
|
|
76
76
|
/**
|
|
77
|
-
* Immutable
|
|
78
|
-
*
|
|
77
|
+
* Immutable URL named by `contentHash(code)`. What `data-x-entry` carries and what a route
|
|
78
|
+
* serves — one name, one byte string, across every build that emits it (#1075).
|
|
79
79
|
*/
|
|
80
80
|
readonly url: string;
|
|
81
81
|
/** The built JavaScript. Held in memory so `x dev` and the container serve without a disk hop. */
|
|
@@ -98,7 +98,7 @@ export interface IslandChunk {
|
|
|
98
98
|
|
|
99
99
|
/** A module two or more islands import, served once beside them. */
|
|
100
100
|
export interface SharedChunk {
|
|
101
|
-
/** `/islands/chunk-<
|
|
101
|
+
/** `/islands/chunk-<contentHash(code)>.js` — named by its bytes, so `immutable` holds. */
|
|
102
102
|
readonly url: string;
|
|
103
103
|
readonly code: string;
|
|
104
104
|
readonly bytes: number;
|
|
@@ -181,7 +181,7 @@ async function buildAll(
|
|
|
181
181
|
format: 'esm',
|
|
182
182
|
splitting,
|
|
183
183
|
// `[dir]` keeps two islands sharing a filename apart and maps an output back to its island;
|
|
184
|
-
// a chunk's Bun hash is only a placeholder — `island-link.ts` renames every one.
|
|
184
|
+
// a chunk's Bun hash is only a placeholder — `island-link.ts` renames every one by its bytes.
|
|
185
185
|
naming: { entry: '[dir]/[name].[ext]', chunk: 'chunk-[hash].[ext]' },
|
|
186
186
|
minify: true,
|
|
187
187
|
// A build with no `plugins` is a build with no JSX transform: `Bun.plugin` installs into the
|
|
@@ -222,9 +222,9 @@ async function buildAll(
|
|
|
222
222
|
// `x dev` serves the same chunk the container does, and bytes that depend on the ambient
|
|
223
223
|
// NODE_ENV are a content hash and a byte budget measured on a build nobody ships.
|
|
224
224
|
define: { 'process.env.NODE_ENV': '"production"' },
|
|
225
|
-
// The fourth, and it is asked for its INPUT list rather than its output: `
|
|
226
|
-
//
|
|
227
|
-
//
|
|
225
|
+
// The fourth, and it is asked for its INPUT list rather than its output: `sources` are the
|
|
226
|
+
// files each output was built from, which the island store re-checks a prebuilt chunk
|
|
227
|
+
// against (`island-sources.ts`). Measured on 1.4.0 against a 131 kB island: 277ms with it and
|
|
228
228
|
// 276ms without, so the map costs nothing worth naming.
|
|
229
229
|
sourcemap: 'external',
|
|
230
230
|
// The fifth: which inputs each output carries, so one module bundled twice is refused below
|
|
@@ -27,7 +27,8 @@ import { hasPathSegment } from './path-segments';
|
|
|
27
27
|
export const ISLAND_CACHE_DIR = '.x/cache/islands';
|
|
28
28
|
|
|
29
29
|
/** Bumped when an entry's shape or meaning changes: an older entry is a miss, never a misread. */
|
|
30
|
-
|
|
30
|
+
// 3: URLs name the bytes (#1075); a 2 entry holds source-addressed URLs a 3 build never mints.
|
|
31
|
+
const FORMAT = 3;
|
|
31
32
|
|
|
32
33
|
/** An entry or a partial nobody read or wrote for this long is swept. */
|
|
33
34
|
const SWEEP_AFTER_MS = 14 * 86_400_000;
|
package/src/island-identity.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// `island-bundle.ts`, which builds; `worker-bundle.ts` names its chunks by the same rules.
|
|
1
|
+
// What an island output is, beyond its bytes: the source map's inputs (`sourcesContentOf`), the
|
|
2
|
+
// per-process pin that keeps one URL one byte string (`stableChunk`), and the bundler-diagnostic
|
|
3
|
+
// flattening every island refusal carries. Split from `island-bundle.ts`, which builds.
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
import { contentHash } from '@ultimat3/render/server';
|
|
8
|
-
import { IslandBuildFailedError } from './errors';
|
|
5
|
+
import { renderThrowable } from '@ultimat3/core';
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* `sourcemap: 'external'` appends `//# debugId=<hex>` to the chunk. It is a pointer to a map this
|
|
@@ -21,48 +18,20 @@ export function stripDebugId(code: string): string {
|
|
|
21
18
|
return at === -1 ? code : code.slice(0, at);
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* `sourcesContent`, hashed per file and SORTED, so the identity is independent of the order the
|
|
39
|
-
* bundler happened to visit the graph in. The PATHS are deliberately not in it: they are absolute
|
|
40
|
-
* on the build machine and would make a chunk built in a container disagree with the same chunk
|
|
41
|
-
* built on a laptop for no difference a browser could observe. `file` is, so two islands with
|
|
42
|
-
* byte-identical sources under different names stay two chunks; the framework version and the Bun
|
|
43
|
-
* version are, because both decide the emitted bytes while no source file moves — an upgrade must
|
|
44
|
-
* mint a new URL rather than leave a stale chunk pinned in a browser for a year.
|
|
45
|
-
*
|
|
46
|
-
* What this gives up, stated plainly: the URL is source-addressed, not byte-addressed. On a Bun
|
|
47
|
-
* with the renamer race (< 1.4.1) two processes building the same sources served two byte-strings
|
|
48
|
-
* at one URL — the same program under different local identifier names — and the alternative,
|
|
49
|
-
* `minify: { identifiers: false }`, was +47% raw and +20% gzipped. The `engines` floor is now past
|
|
50
|
-
* the fix, so the reason this function exists is gone; it is kept for now because moving every
|
|
51
|
-
* island URL to a content hash re-keys every browser cache and every precache manifest, which is a
|
|
52
|
-
* change of its own to make deliberately (issue #354's follow-up), not a comment edit.
|
|
53
|
-
*/
|
|
54
|
-
export function graphHash(file: string, map: string): string {
|
|
55
|
-
const parsed: unknown = JSON.parse(map);
|
|
56
|
-
const contents = sourcesContentOf(parsed);
|
|
57
|
-
if (contents === undefined) {
|
|
58
|
-
throw new IslandBuildFailedError({
|
|
59
|
-
file,
|
|
60
|
-
logs: 'the bundler emitted a source map with no sourcesContent, so the chunk has no stable identity',
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const graph = contents.map((source) => contentHash(source)).sort();
|
|
64
|
-
return contentHash([file, frameworkVersion(), Bun.version, ...graph].join('\u0000'));
|
|
65
|
-
}
|
|
21
|
+
// An island output's URL is `contentHash` of the bytes served under it (`island-link.ts`), never of
|
|
22
|
+
// its sources. Both were tried:
|
|
23
|
+
//
|
|
24
|
+
// - Output-addressed, then flapped: `Bun.build` under `minify` was not byte-deterministic before
|
|
25
|
+
// 1.4.1 (oven-sh/bun#40657) — ten `session-console-*.js` names in ten minutes on 1.4.0 — so a
|
|
26
|
+
// precache manifest named a chunk that already 404ed (19.2.0). Fixed upstream; on 1.4.2, 192
|
|
27
|
+
// contended build pairs of `examples/dummy`'s islands emitted one byte string per island (#354),
|
|
28
|
+
// and `island-determinism.test.ts` holds it.
|
|
29
|
+
// - Source-addressed, then served the wrong program (#1075): the minifier names a shared chunk's
|
|
30
|
+
// exports by how often the WHOLE build uses them, so editing one entry swapped two export
|
|
31
|
+
// names in a chunk whose sources had not moved. One URL, two byte strings, `immutable` — and a CDN handed
|
|
32
|
+
// the next build's islands the action client where they imported the query client.
|
|
33
|
+
//
|
|
34
|
+
// A flapping name costs a cache miss; a stuck one ships a broken page. So the name is the bytes.
|
|
66
35
|
|
|
67
36
|
/**
|
|
68
37
|
* `sourcesContent`, read the way `aggregatedErrors` below reads `errors`: narrowed first,
|
|
@@ -89,7 +58,9 @@ export function sourcesContentOf(
|
|
|
89
58
|
}
|
|
90
59
|
|
|
91
60
|
/**
|
|
92
|
-
* The code this process already emitted
|
|
61
|
+
* The code this process already emitted under this identity, or the code it just built. Every
|
|
62
|
+
* caller's identity is now `contentHash(code)`, so a hit is these bytes again: the table pins
|
|
63
|
+
* nothing the name does not, and `bytes` is measured here, once, on what is served.
|
|
93
64
|
*
|
|
94
65
|
* Keyed by PATH and validated by the input hash, `transformIslandTsx`'s cache's shape and for its
|
|
95
66
|
* reason: one entry per island bounds the map by the island count, which is the only quantity that
|
|
@@ -104,7 +75,7 @@ export function clearIslandChunkCache(): void {
|
|
|
104
75
|
|
|
105
76
|
/**
|
|
106
77
|
* `graph`, never `hash`: `bun run secret-compare` reads the NAME of a comparison's operands, and a
|
|
107
|
-
* value called `hash` is a digest an attacker may be probing. This one is a build
|
|
78
|
+
* value called `hash` is a digest an attacker may be probing. This one is a build output's
|
|
108
79
|
* identity — the same reason `pr-threads.ts` calls a review state `wanted`.
|
|
109
80
|
*/
|
|
110
81
|
export function stableChunk(
|