@ultimat3/cli 31.49.0 → 31.51.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 +1 -1
- package/package.json +30 -30
- package/src/api-registration.ts +18 -1
- package/src/api-routes.ts +1 -0
- package/src/app-boundaries.ts +2 -0
- package/src/app-dev-imports.ts +77 -0
- package/src/app-load-import-chain.ts +112 -0
- package/src/app-load-unresolved.ts +173 -16
- package/src/app-load.ts +23 -7
- package/src/app-openapi.ts +7 -1
- package/src/budgets.ts +2 -1
- package/src/cmd-i18n.ts +33 -1
- package/src/codemods/engine-fs.ts +9 -2
- package/src/codemods/merge-drivers.ts +85 -4
- package/src/dev-only-imports.ts +59 -0
- package/src/error-codes-boundary.ts +2 -0
- package/src/evaluated-walk.ts +103 -0
- package/src/exercise-services.ts +13 -3
- package/src/framework-schema.ts +15 -5
- package/src/guard-sources.ts +1 -2
- package/src/index.ts +2 -0
- package/src/mcp-errors.ts +3 -1
- package/src/messages-upgrade.ts +4 -0
- package/src/module-imports.ts +26 -15
- package/src/page-navigation.ts +5 -2
- package/src/page-route.ts +75 -0
- package/src/pwa-artifacts.ts +1 -1
- package/src/retained-assets-boot.ts +1 -1
- package/src/runtime-assets-site.ts +2 -2
- package/src/runtime-assets.ts +1 -1
- package/src/runtime-render-document.ts +1 -2
- package/src/scan-ways.ts +145 -0
- package/src/site-asset-routes.ts +2 -2
- package/src/site-assets.ts +5 -158
- package/src/sw-precache-plan.ts +1 -1
- package/src/templates/guard-raw-motion.ts +96 -0
- package/src/templates/guard-released-forms.ts +4 -1
- package/src/templates/scaffold-repo.ts +1 -1
- package/src/test-only-shipped.ts +29 -2
- package/src/test-shards.ts +20 -8
- package/src/upgrade-coverage-ratchet.ts +95 -0
- package/src/upgrade-gate.ts +31 -11
- package/src/upgrade-report.ts +14 -0
- package/src/verify-checks.ts +7 -3
- package/src/verify-e2e.ts +21 -3
- package/src/workspace-checks.ts +4 -1
- package/wiki/Actions.md +64 -2
- package/wiki/Auth.md +6 -2
- package/wiki/CLI-Reference.md +8 -2
- package/wiki/Client-Navigation.md +34 -4
- package/wiki/Configuration.md +2 -1
- package/wiki/Entities-And-Migrations.md +12 -2
- package/wiki/Home.md +2 -2
- package/wiki/I18n.md +1 -1
- package/wiki/Interface-Rules.md +3 -1
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +41 -9
- package/wiki/Notify.md +4 -2
- package/wiki/Outbound-HTTP.md +53 -2
- package/wiki/Policies-And-Authz.md +1 -1
- package/wiki/Realtime.md +14 -6
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Static-Assets.md +5 -3
- package/wiki/Testing.md +82 -3
- package/wiki/Theming.md +6 -3
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/UI-Components.md +1 -0
- package/wiki/Upgrading.md +2 -0
package/CLAUDE.md
CHANGED
|
@@ -87,7 +87,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
87
87
|
| `i18n-app-key-shapes.ts` | every shape whose literal is a catalog key; `i18n-app-key-shapes.test.ts` reads `blocks`, so a new block reds until listed |
|
|
88
88
|
| `job-budget.ts` | `X_JOB_OUTLASTS_DRAIN` (`manifest`): `timeout` vs `workerBudgetMs(drain)`, from the registry † |
|
|
89
89
|
| `output-findings.ts` | render layer only: `runnableFix` (`bunx x`, decided by `dispatch.ts`'s `readerFor`) and `collapseFindings`. Throw sites keep `x …` |
|
|
90
|
-
| `app-load-unresolved.ts`
|
|
90
|
+
| `app-load-{unresolved,import-chain}.ts` / `app-dev-imports.ts` | `X_APP_IMPORT_UNRESOLVED`; `X_BOUNDARY_DEV_IMPORT` † |
|
|
91
91
|
| `fix-truth*.ts` / `db-fix-truth.job.test.ts` | a printed fix, executed against a broken scaffold † |
|
|
92
92
|
|
|
93
93
|
### Generators (`x g`, `x new`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.51.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -52,35 +52,35 @@
|
|
|
52
52
|
"dev": "bun run src/bin.ts dev"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@babel/core": "^8.0
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
55
|
+
"@babel/core": "^8.1.0",
|
|
56
|
+
"@ultimat3/action": "31.51.0",
|
|
57
|
+
"@ultimat3/admin": "31.51.0",
|
|
58
|
+
"@ultimat3/ai": "31.51.0",
|
|
59
|
+
"@ultimat3/auth": "31.51.0",
|
|
60
|
+
"@ultimat3/cache": "31.51.0",
|
|
61
|
+
"@ultimat3/core": "31.51.0",
|
|
62
|
+
"@ultimat3/db": "31.51.0",
|
|
63
|
+
"@ultimat3/entity": "31.51.0",
|
|
64
|
+
"@ultimat3/flags": "31.51.0",
|
|
65
|
+
"@ultimat3/http": "31.51.0",
|
|
66
|
+
"@ultimat3/i18n": "31.51.0",
|
|
67
|
+
"@ultimat3/jobs": "31.51.0",
|
|
68
|
+
"@ultimat3/mail": "31.51.0",
|
|
69
|
+
"@ultimat3/manifest": "31.51.0",
|
|
70
|
+
"@ultimat3/mcp": "31.51.0",
|
|
71
|
+
"@ultimat3/money": "31.51.0",
|
|
72
|
+
"@ultimat3/notify": "31.51.0",
|
|
73
|
+
"@ultimat3/policy": "31.51.0",
|
|
74
|
+
"@ultimat3/pwa": "31.51.0",
|
|
75
|
+
"@ultimat3/query": "31.51.0",
|
|
76
|
+
"@ultimat3/realtime": "31.51.0",
|
|
77
|
+
"@ultimat3/render": "31.51.0",
|
|
78
|
+
"@ultimat3/schema": "31.51.0",
|
|
79
|
+
"@ultimat3/scraping": "31.51.0",
|
|
80
|
+
"@ultimat3/seo": "31.51.0",
|
|
81
|
+
"@ultimat3/storage": "31.51.0",
|
|
82
|
+
"@ultimat3/testing": "31.51.0",
|
|
83
|
+
"@ultimat3/time": "31.51.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/api-registration.ts
CHANGED
|
@@ -81,6 +81,23 @@ export const apiListsOf = (
|
|
|
81
81
|
};
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Whether the `defineApi({ ... })` call names `key` in ANY form — `key: [...]`, `key: value`, the
|
|
86
|
+
* shorthand `key,`. `readProperties` sees only `key:`; a shorthand `queries,` read as absent, and
|
|
87
|
+
* 31.49.0's merge-drivers codemod added `queries: []` beside it: a duplicate key, TS1117.
|
|
88
|
+
*/
|
|
89
|
+
function apiDeclares(source: string, key: string): boolean {
|
|
90
|
+
const masked = maskOf(source);
|
|
91
|
+
const call = /\bdefineApi\(\s*\{/.exec(masked);
|
|
92
|
+
if (call === null) return false;
|
|
93
|
+
const object = readList(source, masked, call.index + call[0].length - 1);
|
|
94
|
+
const named = new RegExp(`^(?:${key}|'${key}'|"${key}")\\s*(?::|$)`);
|
|
95
|
+
// The SOURCE text, not the masked: masking blanks a string's contents, so `'jobs':` read as absent.
|
|
96
|
+
return (object?.entries ?? []).some((entry) =>
|
|
97
|
+
named.test(source.slice(entry.start, entry.end).trim()),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
84
101
|
/**
|
|
85
102
|
* `source` with `key: value,` added as a property, on its own row: in the order `x new` writes —
|
|
86
103
|
* actions, queries, jobs, tasks — so after the nearest list before it the call already holds, which
|
|
@@ -94,7 +111,7 @@ export function insertApiList(
|
|
|
94
111
|
): string | undefined {
|
|
95
112
|
const listOf = apiListsOf(source);
|
|
96
113
|
const actions = listOf?.('actions');
|
|
97
|
-
if (listOf === undefined || actions === undefined) return undefined;
|
|
114
|
+
if (listOf === undefined || actions === undefined || apiDeclares(source, key)) return undefined;
|
|
98
115
|
const earlier = LIST_ORDER.slice(0, LIST_ORDER.indexOf(key))
|
|
99
116
|
.map((name) => listOf(name))
|
|
100
117
|
.findLast((found) => found !== undefined);
|
package/src/api-routes.ts
CHANGED
|
@@ -38,6 +38,7 @@ export function apiMountRoutes(store?: RateLimitStore): readonly Route[] {
|
|
|
38
38
|
scopes: mount.scopes,
|
|
39
39
|
resolveToken: mount.resolveToken,
|
|
40
40
|
...(mount.rateLimit === undefined ? {} : { rateLimit: mount.rateLimit }),
|
|
41
|
+
...(mount.tenant === undefined ? {} : { tenant: mount.tenant }),
|
|
41
42
|
...(store === undefined ? {} : { rateLimitStore: store }),
|
|
42
43
|
}),
|
|
43
44
|
);
|
package/src/app-boundaries.ts
CHANGED
|
@@ -40,6 +40,8 @@ export const BOUNDARY_CODES = [
|
|
|
40
40
|
'X_BOUNDARY_LOADER_IMPORT',
|
|
41
41
|
// `package-boundaries.ts`'s: it reads `packages/`, which this module's surface graph never holds.
|
|
42
42
|
'X_BOUNDARY_PACKAGE_TO_APP',
|
|
43
|
+
// `app-dev-imports.ts`'s: a warning on `main`, over what the boot scan imports.
|
|
44
|
+
'X_BOUNDARY_DEV_IMPORT',
|
|
43
45
|
] as const;
|
|
44
46
|
|
|
45
47
|
export type BoundaryCode = (typeof BOUNDARY_CODES)[number];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// `X_BOUNDARY_DEV_IMPORT`: what the boot scan imports reaches no development entry. A test helper
|
|
2
|
+
// under `app/` is an app module, and one brought `@ultimat3/cli`'s barrel into every role, the gate
|
|
3
|
+
// green. A WARNING on `main` (X_BREAKING_ON_MAIN); the refusal lands on `next`.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no path API; the marker of an app root is read at a joined path.
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { APP_CONFIG_FILE, ERROR_DOCS_URL } from '@ultimat3/core';
|
|
8
|
+
import { realPath } from './app-load-unresolved';
|
|
9
|
+
import { devOnlyCut, devOnlyFix, isDevOnlySpecifier, scannedModules } from './dev-only-imports';
|
|
10
|
+
import type { EvaluatedImport, WalkVerdict } from './evaluated-walk';
|
|
11
|
+
import { createEvaluatedGraph } from './evaluated-walk';
|
|
12
|
+
import type { Finding } from './output';
|
|
13
|
+
import { hasPathSegment, isPathUnder } from './path-segments';
|
|
14
|
+
import { posixRelative } from './posix-path';
|
|
15
|
+
import { scanWays } from './scan-ways';
|
|
16
|
+
|
|
17
|
+
/** One finding per cut the app owes a development import its boot evaluates, in path order. */
|
|
18
|
+
export async function devImportFindings(root: string): Promise<readonly Finding[]> {
|
|
19
|
+
// An app only: the framework monorepo has no boot scan, and its `packages/cli` IS the barrel.
|
|
20
|
+
if (!(await Bun.file(join(root, APP_CONFIG_FILE)).exists())) return [];
|
|
21
|
+
const base = realPath(resolve(root));
|
|
22
|
+
const scanned = await scannedModules(base);
|
|
23
|
+
const named = (path: string): string => posixRelative(base, path);
|
|
24
|
+
const found: EvaluatedImport[] = [];
|
|
25
|
+
const followed: EvaluatedImport[] = [];
|
|
26
|
+
const judge = (edge: EvaluatedImport): WalkVerdict => {
|
|
27
|
+
if (isDevOnlySpecifier(edge.specifier)) {
|
|
28
|
+
found.push(edge);
|
|
29
|
+
return 'skip';
|
|
30
|
+
}
|
|
31
|
+
// The app's own modules only: an installed package answers for its own graph.
|
|
32
|
+
const target = edge.target();
|
|
33
|
+
const own =
|
|
34
|
+
target !== undefined &&
|
|
35
|
+
isPathUnder(base, target) &&
|
|
36
|
+
!hasPathSegment(named(target), 'node_modules');
|
|
37
|
+
if (!own) return 'skip';
|
|
38
|
+
followed.push(edge);
|
|
39
|
+
return 'follow';
|
|
40
|
+
};
|
|
41
|
+
await createEvaluatedGraph().walk([...scanned], judge);
|
|
42
|
+
const ways = scanWays(
|
|
43
|
+
found.map((edge) => edge.from),
|
|
44
|
+
scanned,
|
|
45
|
+
followed,
|
|
46
|
+
);
|
|
47
|
+
const findings = new Map<string, Finding>();
|
|
48
|
+
for (const { from, specifier } of found) {
|
|
49
|
+
for (const steps of ways(from)) {
|
|
50
|
+
const cut = devOnlyCut(steps, scanned);
|
|
51
|
+
const chain = steps.map((step) => named(step.path));
|
|
52
|
+
const at = chain[cut.index] ?? named(from);
|
|
53
|
+
const via = chain.length === 1 ? '' : ` (${chain.join(' → ')})`;
|
|
54
|
+
const finding: Finding = {
|
|
55
|
+
code: 'X_BOUNDARY_DEV_IMPORT',
|
|
56
|
+
cause: `the boot scan imports ${named(from)}${via}, and it imports "${specifier}", a development entry: an image that leaves the test packages out boots no role`,
|
|
57
|
+
fix: devOnlyFix(at, cut, specifier),
|
|
58
|
+
docs: ERROR_DOCS_URL,
|
|
59
|
+
at,
|
|
60
|
+
meta: { specifier, chain },
|
|
61
|
+
};
|
|
62
|
+
// One import written twice in a module is one edit: the same line finds both.
|
|
63
|
+
findings.set(
|
|
64
|
+
[at, chain.join('\u0000'), specifier, finding.fix].join('\u0000\u0000'),
|
|
65
|
+
finding,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return [...findings].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([, one]) => one);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** What the `boundaries` step carries on `main`: one line per finding, advice and never red. */
|
|
73
|
+
export async function devImportWarnings(root: string): Promise<readonly string[]> {
|
|
74
|
+
return (await devImportFindings(root)).map(
|
|
75
|
+
(finding) => `${finding.code} ${finding.cause} — fix: ${finding.fix}`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// An import that failed inside an installed package, explained from the app's side: the app module
|
|
2
|
+
// that pulled the package in, the chain to the failing import, and the edit or install that clears
|
|
3
|
+
// it. The bare finding names a file under `node_modules`, which no reader can edit.
|
|
4
|
+
// Loaded only when a load has already failed (`app-load.ts`).
|
|
5
|
+
|
|
6
|
+
// why: Bun ships no path API; the failing module is named app-root-relative and walked absolute.
|
|
7
|
+
import { resolve } from 'node:path';
|
|
8
|
+
import type { UnresolvedImport } from './app-load-unresolved';
|
|
9
|
+
import { realPath, unresolvedImport } from './app-load-unresolved';
|
|
10
|
+
import type { DevOnlyCut } from './dev-only-imports';
|
|
11
|
+
import { devOnlyCut, devOnlyFix, isDevOnlySpecifier, scannedModules } from './dev-only-imports';
|
|
12
|
+
import type { ChainStep } from './evaluated-walk';
|
|
13
|
+
import { createEvaluatedGraph } from './evaluated-walk';
|
|
14
|
+
import type { Finding } from './output';
|
|
15
|
+
import { findingFrom } from './output';
|
|
16
|
+
import { hasPathSegment, isPathUnder } from './path-segments';
|
|
17
|
+
import { posixRelative } from './posix-path';
|
|
18
|
+
|
|
19
|
+
/** `…/node_modules/@ultimat3/cli/src/index.ts` → `@ultimat3/cli/src/index.ts`, under any linker. */
|
|
20
|
+
const shown = (path: string): string => path.replace(/^.*\bnode_modules\//, '');
|
|
21
|
+
|
|
22
|
+
/** What the app does to reach the package: the module to edit, its import, and the way down. */
|
|
23
|
+
interface Entry {
|
|
24
|
+
readonly at: string;
|
|
25
|
+
readonly specifier: string;
|
|
26
|
+
/** App-root-relative: the module to edit first, the failing module last. */
|
|
27
|
+
readonly chain: readonly string[];
|
|
28
|
+
/** The import by which the chain leaves the app: `specifier`, unless the edit is further up. */
|
|
29
|
+
readonly leavesBy: string;
|
|
30
|
+
/** The gate's own cut, when the import that leaves the app is one no role may load. */
|
|
31
|
+
readonly cut?: DevOnlyCut;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The last module of the app's own on the chain, and what it imports out of the app. When that is a
|
|
36
|
+
* development entry the edit is the gate's (`devOnlyCut`): a kit outside the scan is not what moves.
|
|
37
|
+
*/
|
|
38
|
+
async function entryOf(
|
|
39
|
+
steps: readonly ChainStep[],
|
|
40
|
+
root: string,
|
|
41
|
+
scanned: () => Promise<ReadonlySet<string>>,
|
|
42
|
+
): Promise<Entry | undefined> {
|
|
43
|
+
const paths = steps.map((step) => posixRelative(root, step.path));
|
|
44
|
+
const own = steps.findLastIndex(
|
|
45
|
+
(step, index) =>
|
|
46
|
+
isPathUnder(root, step.path) && !hasPathSegment(paths[index] ?? '', 'node_modules'),
|
|
47
|
+
);
|
|
48
|
+
const leavesBy = steps[own + 1]?.specifier;
|
|
49
|
+
if (own === -1 || leavesBy === undefined) return undefined;
|
|
50
|
+
const cut = isDevOnlySpecifier(leavesBy)
|
|
51
|
+
? devOnlyCut(steps.slice(0, own + 1), await scanned())
|
|
52
|
+
: undefined;
|
|
53
|
+
const from = cut?.index ?? own;
|
|
54
|
+
return {
|
|
55
|
+
at: paths[from] ?? '',
|
|
56
|
+
specifier: cut?.into ?? leavesBy,
|
|
57
|
+
chain: paths.slice(from),
|
|
58
|
+
leavesBy,
|
|
59
|
+
...(cut === undefined ? {} : { cut }),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The finding told from `entry`: the install's fix, unless the app's import is the defect. */
|
|
64
|
+
function retold(found: UnresolvedImport, entry: Entry): Finding {
|
|
65
|
+
const { at, specifier, leavesBy, cut } = entry;
|
|
66
|
+
const brings = specifier === leavesBy ? '' : `, which brings in "${leavesBy}"`;
|
|
67
|
+
const refused = cut === undefined ? '' : ', a development entry no role may load';
|
|
68
|
+
const chain = [...entry.chain.map(shown), found.specifier].join(' → ');
|
|
69
|
+
return {
|
|
70
|
+
code: 'X_APP_IMPORT_UNRESOLVED',
|
|
71
|
+
cause: `${at} imports "${specifier}"${brings}${refused}, and that reaches ${found.missing}: ${chain}`,
|
|
72
|
+
fix: cut === undefined ? found.fix : devOnlyFix(at, cut, leavesBy),
|
|
73
|
+
at,
|
|
74
|
+
meta: { specifier: found.specifier, chain: [...entry.chain] },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One scan's explanations. The graph is shared: a package that would not load fails every module
|
|
80
|
+
* that reaches it, and each is explained over the same parsed edges.
|
|
81
|
+
*/
|
|
82
|
+
export function dependencyImports(
|
|
83
|
+
root: string,
|
|
84
|
+
): (error: unknown, file: string) => Promise<Finding> {
|
|
85
|
+
const base = realPath(resolve(root));
|
|
86
|
+
const graph = createEvaluatedGraph();
|
|
87
|
+
let modules: Promise<ReadonlySet<string>> | undefined;
|
|
88
|
+
// Globbed at most once, however many modules fail.
|
|
89
|
+
const scanned = (): Promise<ReadonlySet<string>> => {
|
|
90
|
+
modules ??= scannedModules(base);
|
|
91
|
+
return modules;
|
|
92
|
+
};
|
|
93
|
+
return async (error, file) => {
|
|
94
|
+
const found = unresolvedImport(error, root);
|
|
95
|
+
if (found?.referrer === undefined) return { ...findingFrom(error), at: file };
|
|
96
|
+
const target = realPath(found.referrer);
|
|
97
|
+
const walk = await graph.walk([realPath(resolve(base, file))], (edge) =>
|
|
98
|
+
edge.target() === target ? 'stop' : 'follow',
|
|
99
|
+
);
|
|
100
|
+
const entry = await entryOf(walk.chainTo(target), base, scanned);
|
|
101
|
+
if (entry !== undefined) return retold(found, entry);
|
|
102
|
+
// Reached through an import no source spells (`import(variable)`): the module the load was
|
|
103
|
+
// importing is still the one its reader can open.
|
|
104
|
+
return {
|
|
105
|
+
code: 'X_APP_IMPORT_UNRESOLVED',
|
|
106
|
+
cause: `importing ${file}: ${posixRelative(base, target)} imports ${found.missing}`,
|
|
107
|
+
fix: found.fix,
|
|
108
|
+
at: file,
|
|
109
|
+
meta: { specifier: found.specifier },
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// it, with `x doctor --json` as the fix, and doctor answered "shippable": the cycle closed on itself.
|
|
3
3
|
// Leaf module: `output.ts` reads it for a throw outside the scan, and the scan for one inside it.
|
|
4
4
|
|
|
5
|
-
// why: a synchronous probe
|
|
6
|
-
import { existsSync } from 'node:fs';
|
|
7
|
-
import { dirname, join } from 'node:path';
|
|
8
|
-
import { stringField } from '@ultimat3/core';
|
|
5
|
+
// why: a synchronous probe and read of an installed package's manifest; Bun ships no path helpers.
|
|
6
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
7
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { isJsonObject, stringField } from '@ultimat3/core';
|
|
9
9
|
import type { Finding } from './output';
|
|
10
|
+
import { hasPathSegment, isPathUnder } from './path-segments';
|
|
10
11
|
import { posixRelative } from './posix-path';
|
|
11
12
|
import { quoteArg } from './shell-quote';
|
|
12
13
|
|
|
@@ -31,32 +32,188 @@ const isInstalled = (pkg: string, referrer: string): boolean => {
|
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Whose module it is. `installed`: under a `node_modules`, so an install is what writes it. `linked`:
|
|
37
|
+
* neither the app's nor installed — a checkout a link reaches, which its owner edits and installs.
|
|
38
|
+
*/
|
|
39
|
+
type Place = 'app' | 'installed' | 'linked';
|
|
40
|
+
|
|
41
|
+
function placeOf(root: string, path: string): Place {
|
|
42
|
+
const base = realPath(resolve(root));
|
|
43
|
+
const real = realPath(path);
|
|
44
|
+
// Relative to the app, so one that itself sits under some `node_modules` is still an app.
|
|
45
|
+
if (hasPathSegment(posixRelative(base, real), 'node_modules')) return 'installed';
|
|
46
|
+
return isPathUnder(base, real) ? 'app' : 'linked';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `path` with its links followed, as Bun reports a referrer — or itself when they cannot be: this
|
|
51
|
+
* runs while a failure is being reported, over a tree an install may be rewriting.
|
|
52
|
+
*/
|
|
53
|
+
export function realPath(path: string): string {
|
|
54
|
+
try {
|
|
55
|
+
return realpathSync(path);
|
|
56
|
+
} catch {
|
|
57
|
+
return path;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The package a module belongs to. `manifest` is absent when there is none that can be read. */
|
|
62
|
+
interface Owner {
|
|
63
|
+
readonly dir: string;
|
|
64
|
+
readonly manifest?: Readonly<Record<string, unknown>>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The nearest named manifest above `file`, and never one above the package's own directory. */
|
|
68
|
+
function ownerOf(file: string): Owner {
|
|
69
|
+
for (let dir = dirname(file); ; dir = dirname(dir)) {
|
|
70
|
+
const manifest = readManifest(join(dir, 'package.json'));
|
|
71
|
+
if (manifest === 'unreadable') return { dir };
|
|
72
|
+
if (manifest !== 'absent' && typeof manifest['name'] === 'string') return { dir, manifest };
|
|
73
|
+
const above = dirname(dir);
|
|
74
|
+
if (above === dir || basename(above) === 'node_modules') return { dir };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Best effort by design: the caller is reporting a failed import, and a manifest an install is
|
|
80
|
+
* replacing — gone, half-written, a directory — must not become the failure that is reported.
|
|
81
|
+
*/
|
|
82
|
+
function readManifest(path: string): Readonly<Record<string, unknown>> | 'absent' | 'unreadable' {
|
|
83
|
+
try {
|
|
84
|
+
const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'));
|
|
85
|
+
return isJsonObject(parsed) ? parsed : 'unreadable';
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return stringField(error, 'code') === 'ENOENT' ? 'absent' : 'unreadable';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** An import that resolved to nothing, as the runtime reported it. */
|
|
92
|
+
export interface UnresolvedImport {
|
|
93
|
+
readonly specifier: string;
|
|
94
|
+
/** Absolute, when the runtime named it. */
|
|
95
|
+
readonly referrer?: string;
|
|
96
|
+
/** `referrer` is a package's module, installed or linked: not a file of the app's. */
|
|
97
|
+
readonly outside: boolean;
|
|
98
|
+
/** The package nobody installed; absent for a path, and for a subpath of an installed one. */
|
|
99
|
+
readonly pkg?: string;
|
|
100
|
+
/** What is missing, as a clause: `left-pad, which is not installed`. */
|
|
101
|
+
readonly missing: string;
|
|
102
|
+
readonly fix: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The line that shows the import to edit, in the file that holds it. */
|
|
106
|
+
const editFix = (specifier: string, where: string): string =>
|
|
107
|
+
`grep -nF -- ${quoteArg(specifier)} ${quoteArg(where)} # the import no file resolves: edit it`;
|
|
108
|
+
|
|
109
|
+
const declares = (owner: Owner, pkg: string): boolean => {
|
|
110
|
+
const declared = owner.manifest?.['dependencies'];
|
|
111
|
+
return isJsonObject(declared) && Object.hasOwn(declared, pkg);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The directory whose install wrote `file`, when the app's own line does not reach it: the one above
|
|
116
|
+
* the outermost `node_modules` on the way there. `undefined` is the app's install, in the app or in
|
|
117
|
+
* the workspace root above it. A directory INSIDE the app is named whichever it is: a checkout
|
|
118
|
+
* standing alone there has its own lockfile, and from a workspace `bun` finds the root's.
|
|
119
|
+
*/
|
|
120
|
+
function foreignInstall(root: string, file: string): string | undefined {
|
|
121
|
+
const base = realPath(resolve(root));
|
|
122
|
+
const parts = posixRelative(base, realPath(file)).split('/');
|
|
123
|
+
const dir = resolve(base, parts.slice(0, parts.indexOf('node_modules')).join('/'));
|
|
124
|
+
return dir === base || isPathUnder(dir, base) ? undefined : dir;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Inside an installed package: nobody has a line to edit, and an install is what writes it. */
|
|
128
|
+
function installedFix(
|
|
129
|
+
root: string,
|
|
130
|
+
referrer: string,
|
|
131
|
+
named: string | undefined,
|
|
132
|
+
pkg: string | undefined,
|
|
133
|
+
): string {
|
|
134
|
+
const owner = ownerOf(referrer);
|
|
135
|
+
const foreign = foreignInstall(root, referrer);
|
|
136
|
+
const cwd = foreign === undefined ? '' : ` --cwd ${quoteArg(foreign)}`;
|
|
137
|
+
if (pkg === undefined || owner.manifest === undefined) {
|
|
138
|
+
const why = `bun why ${String(named)}${foreign === undefined ? '' : ' there'}`;
|
|
139
|
+
return `bun install --force${cwd} # the installed copy lacks what it imports: reinstall it${named === undefined ? '' : `; still so: ${why}, then align the two versions`}`;
|
|
140
|
+
}
|
|
141
|
+
if (!declares(owner, pkg)) return `bun add ${quoteArg(pkg)}${cwd}`;
|
|
142
|
+
// A dependency the importing package DECLARES is missing from the install, not from the app's
|
|
143
|
+
// manifest: `bun add` would copy it into the app and leave the pruned install as it was.
|
|
144
|
+
return foreign === undefined
|
|
145
|
+
? `bun install --frozen-lockfile # ${pkg} is a declared dependency of an installed package: restore it, and prune no declared dependency from an image`
|
|
146
|
+
: `bun install${cwd} # ${pkg} is a declared dependency of a package installed there: restore it`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Inside a linked checkout: no install of the app's writes it, and nothing installed in the app
|
|
151
|
+
* resolves from it — a module resolves from its real path.
|
|
152
|
+
*/
|
|
153
|
+
function linkedFix(
|
|
154
|
+
specifier: string,
|
|
155
|
+
where: string,
|
|
156
|
+
referrer: string,
|
|
157
|
+
pkg: string | undefined,
|
|
158
|
+
): string {
|
|
159
|
+
const owner = ownerOf(realPath(referrer));
|
|
160
|
+
// No manifest to install from: what is left is the import itself.
|
|
161
|
+
if (pkg === undefined || owner.manifest === undefined) return editFix(specifier, where);
|
|
162
|
+
return declares(owner, pkg)
|
|
163
|
+
? `bun install --cwd ${quoteArg(owner.dir)}`
|
|
164
|
+
: `bun add ${quoteArg(pkg)} --cwd ${quoteArg(owner.dir)}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
34
167
|
/**
|
|
35
168
|
* Bun's `ResolveMessage`, read through `stringField`: a caught value this process did not build. The
|
|
36
169
|
* `specifier` and `referrer` are the failing import's own, however many modules were importing the
|
|
37
|
-
* file that holds it
|
|
170
|
+
* file that holds it.
|
|
38
171
|
*/
|
|
39
|
-
export function
|
|
172
|
+
export function unresolvedImport(error: unknown, root: string): UnresolvedImport | undefined {
|
|
40
173
|
if (stringField(error, 'code') !== 'ERR_MODULE_NOT_FOUND') return undefined;
|
|
41
174
|
const specifier = stringField(error, 'specifier');
|
|
42
175
|
if (specifier === undefined) return undefined;
|
|
43
176
|
const referrer = stringField(error, 'referrer');
|
|
44
|
-
const
|
|
45
|
-
const where =
|
|
177
|
+
const place = referrer === undefined ? 'app' : placeOf(root, referrer);
|
|
178
|
+
const where = referrer === undefined ? 'an app module' : posixRelative(root, referrer);
|
|
46
179
|
const named = installablePackage(specifier);
|
|
47
180
|
// Installed, and missing only the subpath: `bun add` would exit 0 and change nothing.
|
|
48
181
|
const installed = named !== undefined && referrer !== undefined && isInstalled(named, referrer);
|
|
49
182
|
const pkg = installed ? undefined : named;
|
|
50
|
-
const
|
|
183
|
+
const ownFix = pkg === undefined ? editFix(specifier, where) : `bun add ${quoteArg(pkg)}`;
|
|
184
|
+
const fixAt = (from: string): string =>
|
|
185
|
+
place === 'linked'
|
|
186
|
+
? linkedFix(specifier, where, from, pkg)
|
|
187
|
+
: place === 'installed'
|
|
188
|
+
? installedFix(root, from, named, pkg)
|
|
189
|
+
: ownFix;
|
|
51
190
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
191
|
+
specifier,
|
|
192
|
+
...(referrer === undefined ? {} : { referrer }),
|
|
193
|
+
outside: place !== 'app',
|
|
194
|
+
...(pkg === undefined ? {} : { pkg }),
|
|
195
|
+
missing: installed
|
|
196
|
+
? `"${specifier}", and ${String(named)} is installed with no such subpath`
|
|
55
197
|
: pkg === undefined
|
|
56
|
-
?
|
|
57
|
-
:
|
|
58
|
-
fix:
|
|
198
|
+
? `"${specifier}", which resolves to no file`
|
|
199
|
+
: `${pkg}, which is not installed`,
|
|
200
|
+
fix: referrer === undefined ? ownFix : fixAt(referrer),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The finding as the failing import alone tells it: at the module that holds it. */
|
|
205
|
+
export function unresolvedImportFinding(error: unknown, root: string): Finding | undefined {
|
|
206
|
+
const found = unresolvedImport(error, root);
|
|
207
|
+
if (found === undefined) return undefined;
|
|
208
|
+
const at = found.referrer === undefined ? undefined : posixRelative(root, found.referrer);
|
|
209
|
+
// A package the app itself imports is one `bun add`, so its cause names no importer: the render
|
|
210
|
+
// layer collapses findings by cause, and every importer of it is one repair.
|
|
211
|
+
const appsOwnPackage = !found.outside && found.pkg !== undefined;
|
|
212
|
+
return {
|
|
213
|
+
code: IMPORT_UNRESOLVED,
|
|
214
|
+
cause: `${appsOwnPackage ? 'an app module' : (at ?? 'an app module')} imports ${found.missing}`,
|
|
215
|
+
fix: found.fix,
|
|
59
216
|
...(at === undefined ? {} : { at }),
|
|
60
|
-
meta: { specifier },
|
|
217
|
+
meta: { specifier: found.specifier },
|
|
61
218
|
};
|
|
62
219
|
}
|
package/src/app-load.ts
CHANGED
|
@@ -21,11 +21,11 @@ import { routeEntries, setAssetResolver } from '@ultimat3/render';
|
|
|
21
21
|
// here is six hops through `error-contract` → `fix-command` → the command registry, which is an
|
|
22
22
|
// accident one refactor away from compiling every app's `.tsx` to `React.createElement`. The named
|
|
23
23
|
// import is a value import, so the side effect holds without the bare line it replaced.
|
|
24
|
-
import { setStylesheetRoot } from '@ultimat3/render/server';
|
|
24
|
+
import { setStylesheetRoot, siteAssetTable } from '@ultimat3/render/server';
|
|
25
25
|
import { asyncModules } from './app-load-async';
|
|
26
26
|
import { importInOrder } from './app-load-batch';
|
|
27
27
|
import { isFirstPass, registeredAny, registerModule } from './app-load-register';
|
|
28
|
-
import { unresolvedImportFinding } from './app-load-unresolved';
|
|
28
|
+
import { unresolvedImport, unresolvedImportFinding } from './app-load-unresolved';
|
|
29
29
|
import { evictChanged, trackModule, trackStylesheets } from './app-reload-graph';
|
|
30
30
|
import { API_INDEX } from './app-root';
|
|
31
31
|
import { collectDeclaredCodes } from './error-contract';
|
|
@@ -33,7 +33,6 @@ import type { Finding } from './output';
|
|
|
33
33
|
import { findingFrom } from './output';
|
|
34
34
|
import { hasPathSegment } from './path-segments';
|
|
35
35
|
import { posixRelative, toPosix } from './posix-path';
|
|
36
|
-
import { siteAssetTable } from './site-assets';
|
|
37
36
|
import { isTest } from './source-files';
|
|
38
37
|
|
|
39
38
|
/** Every place an app keeps code the framework has to see. */
|
|
@@ -240,8 +239,23 @@ export async function scannedModulePaths(root: string): Promise<readonly string[
|
|
|
240
239
|
}
|
|
241
240
|
|
|
242
241
|
/** A module that would not import, keyed by its file. */
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
type ImportFinding = (error: unknown, file: string) => Promise<Finding>;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* One per scan. An import that failed inside an installed package is explained by the app module
|
|
246
|
+
* that reached it (`app-load-import-chain.ts`), loaded then: a boot that imports everything never
|
|
247
|
+
* evaluates the walk.
|
|
248
|
+
*/
|
|
249
|
+
function importFindings(root: string): ImportFinding {
|
|
250
|
+
let explain: Promise<ImportFinding> | undefined;
|
|
251
|
+
return async (error, file) => {
|
|
252
|
+
if (unresolvedImport(error, root)?.outside === true) {
|
|
253
|
+
explain ??= import('./app-load-import-chain').then((one) => one.dependencyImports(root));
|
|
254
|
+
return (await explain)(error, file);
|
|
255
|
+
}
|
|
256
|
+
return unresolvedImportFinding(error, root) ?? { ...findingFrom(error), at: file };
|
|
257
|
+
};
|
|
258
|
+
}
|
|
245
259
|
|
|
246
260
|
/** Reads at most this many sources at once: a 12k-module app opened 12k descriptors otherwise. */
|
|
247
261
|
const READ_BATCH = 64;
|
|
@@ -278,12 +292,13 @@ async function scanBatched(
|
|
|
278
292
|
const alone = await asyncModules(root, candidates);
|
|
279
293
|
const imported = await importInOrder(candidates, alone, register);
|
|
280
294
|
const result: ScanResult = { files: [], findings: [] };
|
|
295
|
+
const importFinding = importFindings(root);
|
|
281
296
|
for (const [index, absolute] of candidates.entries()) {
|
|
282
297
|
const file = posixRelative(root, absolute);
|
|
283
298
|
const one = imported[index];
|
|
284
299
|
if (one === undefined) continue;
|
|
285
300
|
if (!one.ok) {
|
|
286
|
-
result.findings.push(importFinding(one.error,
|
|
301
|
+
result.findings.push(await importFinding(one.error, file));
|
|
287
302
|
continue;
|
|
288
303
|
}
|
|
289
304
|
result.files.push(file);
|
|
@@ -300,6 +315,7 @@ async function scanSerial(
|
|
|
300
315
|
options: ScanOptions,
|
|
301
316
|
): Promise<ScanResult> {
|
|
302
317
|
const result: ScanResult = { files: [], findings: [] };
|
|
318
|
+
const importFinding = importFindings(root);
|
|
303
319
|
for (const absolute of candidates) {
|
|
304
320
|
const file = posixRelative(root, absolute);
|
|
305
321
|
if (options.include !== undefined && !(await options.include(absolute))) continue;
|
|
@@ -316,7 +332,7 @@ async function scanSerial(
|
|
|
316
332
|
try {
|
|
317
333
|
module = (await import(absolute)) as Record<string, unknown>;
|
|
318
334
|
} catch (error) {
|
|
319
|
-
result.findings.push(importFinding(error,
|
|
335
|
+
result.findings.push(await importFinding(error, file));
|
|
320
336
|
continue;
|
|
321
337
|
}
|
|
322
338
|
result.files.push(file);
|
package/src/app-openapi.ts
CHANGED
|
@@ -72,7 +72,13 @@ export const openApiArtifacts = (manifest: Manifest): readonly OpenApiArtifact[]
|
|
|
72
72
|
const merged = mergedDocument(manifest);
|
|
73
73
|
const routes = apiRoutes();
|
|
74
74
|
for (const mount of mounts) {
|
|
75
|
-
bearerMount({
|
|
75
|
+
bearerMount({
|
|
76
|
+
prefix: mount.prefix,
|
|
77
|
+
routes,
|
|
78
|
+
scopes: mount.scopes,
|
|
79
|
+
resolveToken: () => null,
|
|
80
|
+
...(mount.tenant === undefined ? {} : { tenant: mount.tenant }),
|
|
81
|
+
});
|
|
76
82
|
artifacts.push({
|
|
77
83
|
file: mount.openapi ?? OPENAPI_FILE,
|
|
78
84
|
text: serializeOpenApi(
|
package/src/budgets.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { join } from 'node:path';
|
|
|
11
11
|
import { ERROR_DOCS_URL, formatBytes } from '@ultimat3/core';
|
|
12
12
|
import type { Manifest, RouteFact } from '@ultimat3/manifest';
|
|
13
13
|
import { describePages, parseByteBudget, themeScriptBody } from '@ultimat3/render';
|
|
14
|
+
import { MANIFEST_FILE } from './app-root';
|
|
14
15
|
import type { ChargedFile } from './budgets-charged';
|
|
15
16
|
import { chargedClause, chargedMeta, heaviestFirst } from './budgets-charged';
|
|
16
17
|
import type { RouteRequests } from './budgets-requests';
|
|
@@ -115,7 +116,7 @@ const KB = 1024;
|
|
|
115
116
|
function exceededJsFix(url: string, file: string | undefined, bytes: number): string {
|
|
116
117
|
const where = file ?? `the file declaring ${url}`;
|
|
117
118
|
const kb = Math.ceil(bytes / KB);
|
|
118
|
-
return `edit ${where} — set budget: { js: '${String(kb)}kb' } with // measured: ${String(bytes)} B (x build --target static) — why: <the function it buys> directly above it; or x routes --json for the chain and move the heavy import behind hydrate: 'interaction'`;
|
|
119
|
+
return `edit ${where} — set budget: { js: '${String(kb)}kb' } with // measured: ${String(bytes)} B (x build --target static) — why: <the function it buys> directly above it, then x manifest (${MANIFEST_FILE} carries the budget); or x routes --json for the chain and move the heavy import behind hydrate: 'interaction'`;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
/**
|