@ultimat3/cli 31.50.0 → 31.52.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/README.md +9 -9
- package/package.json +29 -29
- 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 +22 -5
- package/src/catalog-layout.ts +194 -0
- package/src/cmd-i18n-spec.ts +4 -4
- package/src/cmd-i18n-split.ts +133 -0
- package/src/cmd-i18n.ts +46 -66
- package/src/config-redact.ts +20 -4
- package/src/db-rollback-pass.ts +4 -1
- package/src/dev-child-watch.ts +16 -0
- package/src/dev-db-migrate.ts +27 -46
- package/src/dev-db-migrator-hold.ts +131 -0
- package/src/dev-db-rollback.ts +11 -2
- package/src/dev-only-imports.ts +59 -0
- package/src/dev-rebuild-schema.ts +7 -24
- package/src/error-codes-boundary.ts +2 -0
- package/src/evaluated-walk.ts +103 -0
- package/src/generate-catalog-locales.ts +25 -2
- package/src/generate-follow-ups.ts +8 -3
- package/src/i18n-audit.ts +17 -33
- package/src/i18n-index.ts +108 -31
- package/src/i18n-locale-parity.ts +14 -6
- package/src/i18n-new-locale.ts +75 -0
- package/src/i18n-registration.ts +52 -27
- package/src/index.ts +2 -0
- package/src/island-capture.ts +36 -7
- package/src/mcp-errors.ts +3 -1
- package/src/merge-state.ts +3 -2
- package/src/messages-floor.ts +2 -0
- package/src/messages.ts +2 -0
- package/src/module-imports.ts +26 -15
- package/src/page-route.ts +75 -0
- package/src/scan-ways.ts +145 -0
- package/src/serve-boot-telemetry.ts +106 -0
- package/src/serve-boot.ts +23 -4
- package/src/shot-blank.ts +70 -0
- package/src/templates/catalog-barrel.ts +84 -0
- package/src/templates/guard-released-forms.ts +2 -1
- package/src/templates/guard-untranslated-string.ts +27 -6
- package/src/templates/locales.ts +6 -0
- package/src/templates/scaffold-gitattributes.ts +9 -2
- package/src/templates/scaffold-i18n.ts +10 -6
- package/src/templates/shapes/offline.ts +5 -2
- package/src/test-ignores.ts +3 -2
- package/src/verify-checks.ts +7 -3
- package/src/verify-floor.ts +9 -1
- package/src/verify-local-only.ts +66 -0
- package/src/verify-run.ts +17 -2
- package/wiki/Actions.md +1 -1
- package/wiki/Auth.md +4 -4
- package/wiki/Batching-And-Preloading.md +1 -0
- package/wiki/CLI-Reference-Data.md +241 -0
- package/wiki/CLI-Reference-Gate.md +572 -0
- package/wiki/CLI-Reference-Project.md +414 -0
- package/wiki/CLI-Reference-Ship.md +348 -0
- package/wiki/CLI-Reference-Tools.md +666 -0
- package/wiki/CLI-Reference.md +14 -2225
- package/wiki/Compared.md +8 -8
- package/wiki/Configuration.md +26 -2
- package/wiki/Deployment.md +1 -1
- package/wiki/Entities-And-Migrations.md +3 -2
- package/wiki/I18n.md +39 -5
- package/wiki/Installation.md +1 -1
- package/wiki/Jobs-And-Workflows.md +29 -1
- package/wiki/Known-Gaps.md +3 -0
- package/wiki/Observability.md +15 -1
- package/wiki/Outbound-HTTP.md +62 -2
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Policies-And-Authz.md +10 -0
- package/wiki/Realtime.md +29 -2
- package/wiki/Static-Assets.md +1 -1
- package/wiki/Testing.md +58 -0
- package/wiki/Theming.md +31 -8
- package/wiki/Troubleshooting.md +2 -2
- package/wiki/Upgrading.md +6 -1
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/README.md
CHANGED
|
@@ -27,8 +27,8 @@ Commands and the `x verify` step count, `As of 2026-08`:
|
|
|
27
27
|
| `x g <primitive> <name>` | scaffolds a primitive **with a passing test** | never a TODO stub |
|
|
28
28
|
| `x db gen\|migrate\|rollback\|reset\|branch\|backfill` | everything DB | `rollback [--steps n]` (default 1) runs the `-- down` half of the most recently applied migration(s) and leaves the files on disk; `gen` refuses an applied migration edited since (`X_MIGRATION_CONFLICT`) before it writes — checked against the embedded ledger only (asked of a live `x dev` when one holds it): an external `DATABASE_URL` is never dialled, so there `x db migrate`'s own audit is the refusal, and an embedded ledger it cannot read is a warning line naming why, never a refusal; `branch` = copy-on-write clone + preview URL; `backfill` dry-runs unless `--write`. The schema browser is `/_x`'s db panel (`x dev`); `studio` left the registry ([Known gaps](../../wiki/Known-Gaps.md#open-by-decision)) |
|
|
29
29
|
| `x mcp serve` | `@ultimat3/mcp`'s 19 dev tools, over stdio or HTTP | one catalog, one scope set, both transports |
|
|
30
|
-
| `x upgrade` | one major per run: exact pins, the Bun floor, `bun install`, the gate; an `AGENTS.md` byte-identical to `CLAUDE.md` becomes a symlink to it, a different one is reported in `data.agentsMd` and left | the `--json` report names the wiki section, the guards that differ and what the gate still says ([fields](../../wiki/CLI-Reference.md#x-upgrade)); `bunx @ultimat3/cli@latest upgrade` in an app that predates it; pins with no `app.config.ts` still hop, and `data.proof` says what checked them |
|
|
31
|
-
| `x doctor` | environment, ports, drift, PWA prerequisites, `APP_URL` | every finding carries a fix command; probes the port `x dev` binds ([which one](../../wiki/CLI-Reference.md#x-doctor)); the framework's deploy secrets only where the machine names `staging`/`production` |
|
|
30
|
+
| `x upgrade` | one major per run: exact pins, the Bun floor, `bun install`, the gate; an `AGENTS.md` byte-identical to `CLAUDE.md` becomes a symlink to it, a different one is reported in `data.agentsMd` and left | the `--json` report names the wiki section, the guards that differ and what the gate still says ([fields](../../wiki/CLI-Reference-Tools.md#x-upgrade)); `bunx @ultimat3/cli@latest upgrade` in an app that predates it; pins with no `app.config.ts` still hop, and `data.proof` says what checked them |
|
|
31
|
+
| `x doctor` | environment, ports, drift, PWA prerequisites, `APP_URL` | every finding carries a fix command; probes the port `x dev` binds ([which one](../../wiki/CLI-Reference-Tools.md#x-doctor)); the framework's deploy secrets only where the machine names `staging`/`production` |
|
|
32
32
|
| `x deploy` | container deploy plan | compose or helm; zero platform primitives. Compose reads `.env.production` first (`X_DEPLOY_ENV_MISSING`). Helm carries `drain.*`, `drain.workerRetireMs` as `roles.worker.retireSeconds`, and `jobs.maxInFlight` as the worker's `targetAverageValue` |
|
|
33
33
|
| `x deploy verify` | production serves this build, holds it, and a worker of it claims every queue | samples `/readyz` through the load balancer, grades `x_job_workers` when `DATABASE_URL` is set; no platform API |
|
|
34
34
|
| `x manifest` / `x routes` | generated facts | `x.manifest.json`, `openapi.json`, route table |
|
|
@@ -46,16 +46,16 @@ Commands and the `x verify` step count, `As of 2026-08`:
|
|
|
46
46
|
| `x repro <id> [--write] [--verify]` / `--list` / `--from` | a dead job or a captured 5xx as a red test in `repro/` | `--verify` answers `{ reproduced, code, fingerprint }`; a mismatch is `X_REPRO_NOT_REPRODUCED`, never a crash |
|
|
47
47
|
| `x repro <id> --bundle` | the failure as one redacted `repro/bundle-<id>.json` for an issue | secrets masked, env values / hostnames / paths replaced; `bunx create-ultimate repro <file>` opens it |
|
|
48
48
|
| `x docs "<question>"` | the framework docs and the wiki, offline | answered from the installed packages and the `wiki/` this tarball ships (`prepack`: `scripts/pack-cli-wiki.ts`), never the network; `x docs Upgrading#<anchor>` prints one whole section |
|
|
49
|
-
| `x graph [--from a --to b]` / `x impact <file\|primitive\|entity>` | the app as one typed graph (`@ultimat3/manifest`'s `buildGraph` over the loaded app, its module graph and `.x/exercise.json`) · what an edit reaches | every edge `declared`, `import` or `observed`; a miss is `X_GRAPH_NODE_UNKNOWN` with the nearest three; `x affected` in an app root adds `data.tests` by import closure ([details](../../wiki/CLI-Reference.md#x-graph--x-impact)) |
|
|
50
|
-
| `x client vendor <name>` / `x client customer --out <dir>` | one OpenAPI compiler (`openapi-compile.ts`), two emitters: a vendor's document into `apps/web/clients/<name>/` (`outbound()` + `t`), or the app's published document into a client with no framework import | every generated file is stamped with its source and body hash; `drift` raises `X_CLIENT_STALE` / `X_CLIENT_EDITED` ([flags](../../wiki/CLI-Reference.md#x-client)) |
|
|
49
|
+
| `x graph [--from a --to b]` / `x impact <file\|primitive\|entity>` | the app as one typed graph (`@ultimat3/manifest`'s `buildGraph` over the loaded app, its module graph and `.x/exercise.json`) · what an edit reaches | every edge `declared`, `import` or `observed`; a miss is `X_GRAPH_NODE_UNKNOWN` with the nearest three; `x affected` in an app root adds `data.tests` by import closure ([details](../../wiki/CLI-Reference-Tools.md#x-graph--x-impact)) |
|
|
50
|
+
| `x client vendor <name>` / `x client customer --out <dir>` | one OpenAPI compiler (`openapi-compile.ts`), two emitters: a vendor's document into `apps/web/clients/<name>/` (`outbound()` + `t`), or the app's published document into a client with no framework import | every generated file is stamped with its source and body hash; `drift` raises `X_CLIENT_STALE` / `X_CLIENT_EDITED` ([flags](../../wiki/CLI-Reference-Tools.md#x-client)) |
|
|
51
51
|
| `x fix boundary <file>` | the minimal cut for a crossed surface boundary | prints the plan and the `git mv`; never rewrites a file |
|
|
52
|
-
| `x ci [runs]` / `x ci tested` | CI triage through `gh`; `tested`: may this push reuse a green PR run of the same tree | `tested` exits 0 on every answer, `data.tested`; any doubt is `false`, a full run ([conditions](../../wiki/CLI-Reference.md#x-pr--x-ci)) |
|
|
53
|
-
| `x token create\|list\|revoke` | MCP / API tokens in `x_api_keys` | `create --scopes a,b` prints the plaintext once and stores its hash; `list --owner <id>` carries no secret; no `grant`: a wider set is a new key ([details](../../wiki/CLI-Reference.md#x-token)) |
|
|
52
|
+
| `x ci [runs]` / `x ci tested` | CI triage through `gh`; `tested`: may this push reuse a green PR run of the same tree | `tested` exits 0 on every answer, `data.tested`; any doubt is `false`, a full run ([conditions](../../wiki/CLI-Reference-Tools.md#x-pr--x-ci)) |
|
|
53
|
+
| `x token create\|list\|revoke` | MCP / API tokens in `x_api_keys` | `create --scopes a,b` prints the plaintext once and stores its hash; `list --owner <id>` carries no secret; no `grant`: a wider set is a new key ([details](../../wiki/CLI-Reference-Tools.md#x-token)) |
|
|
54
54
|
| `x config show [--section <key>]` | the resolved `app.config.ts` | defaults merged by `defineConfig`; credential keys, `secret()` values and URL passwords redacted |
|
|
55
55
|
| `x logs tail [--lines n] [--role <role>]` | the end of `.x/dev.log` or a role log | the `logs.tail` MCP tool's file and reader |
|
|
56
56
|
| `x cache graph\|bust <tag>\|clear` | the tag graph off the manifest; a bust through the app's own tiers and bus | an in-process bus is said in the summary; a failed tier is `X_CACHE_DRIVER_UNAVAILABLE` |
|
|
57
57
|
| `x explain <query> [--input <json>] [--org <id>]` | one query's statements, planned on the dev database | the `exercise` step's oracle (`sweepPlans`): an unindexed read is `X_QUERY_UNINDEXED` with the `indexes:` entry as its fix |
|
|
58
|
-
| `x status [--url <origin>] [--samples n]` | the build each live worker runs, and what each origin's `/readyz` answers | a read, exit 0; `data.unrecorded` names the roles no fleet-wide record covers ([details](../../wiki/CLI-Reference.md#x-status)) |
|
|
58
|
+
| `x status [--url <origin>] [--samples n]` | the build each live worker runs, and what each origin's `/readyz` answers | a read, exit 0; `data.unrecorded` names the roles no fleet-wide record covers ([details](../../wiki/CLI-Reference-Ship.md#x-status)) |
|
|
59
59
|
|
|
60
60
|
Everything in [CLI reference](../../wiki/CLI-Reference.md)'s planned table is also in the registry
|
|
61
61
|
and exits `X_NOT_IMPLEMENTED` with a `fix:` naming the closest shipped command — "not built yet"
|
|
@@ -349,8 +349,8 @@ one, silently. `As of 2026-11`:
|
|
|
349
349
|
| Command | Beside a live `x dev` holding `.x/pgdata` |
|
|
350
350
|
|---|---|
|
|
351
351
|
| `x db migrate` | applied BY the dev server (`POST /_x/db/migrate`: loopback Host and peer, same-origin — the command sends `Sec-Fetch-Site: same-origin`, so an app's CSRF check lets it through); the report, drift and schema dump are the same. `x dev`'s own `x db gen "…" && x db migrate` fix works as printed. A holder that is still booting (its lock claimed inside the last 120 s, or a new child) is waited for, up to 120 s, on a refused connection only |
|
|
352
|
-
| `x db migrate`, app with `database.rowSecurity` |
|
|
353
|
-
| `x db rollback [--steps n]` | run BY the dev server (`POST /_x/db/rollback`, the same doors); with `database.rowSecurity`
|
|
352
|
+
| `x db migrate`, app with `database.rowSecurity` | applied by the dev server too: it holds its one session exclusively, runs the pass as `x_migrator`, and serves as `x_app` again before any other statement runs (`dev-db-migrator-hold.ts`). A session that cannot become `x_app` again stops serving: `X_DB_ROW_SECURITY_BYPASSED`, fix `x stop --json && x dev` |
|
|
353
|
+
| `x db rollback [--steps n]` | run BY the dev server (`POST /_x/db/rollback`, the same doors); with `database.rowSecurity` under the same hold as `x_migrator` |
|
|
354
354
|
| `x db gen` | reads the ledger's checksums from the dev server (`POST /_x/db/ledger`) for its edited-migration check; one that does not answer is a printed line, never a refusal |
|
|
355
355
|
| `x db seed`, `x db backfill --write`, `x jobs retry\|cancel\|delete\|promote\|resolve-step\|pause\|resume`, `x auth seal-mfa` | `X_DEV_ALREADY_RUNNING`; the fix stops the holder, runs the command and starts `x dev` again |
|
|
356
356
|
| `x db reset\|status\|diagnostics\|recount` | `X_DEV_ALREADY_RUNNING`, as before |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.52.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.1.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.
|
|
56
|
+
"@ultimat3/action": "31.52.0",
|
|
57
|
+
"@ultimat3/admin": "31.52.0",
|
|
58
|
+
"@ultimat3/ai": "31.52.0",
|
|
59
|
+
"@ultimat3/auth": "31.52.0",
|
|
60
|
+
"@ultimat3/cache": "31.52.0",
|
|
61
|
+
"@ultimat3/core": "31.52.0",
|
|
62
|
+
"@ultimat3/db": "31.52.0",
|
|
63
|
+
"@ultimat3/entity": "31.52.0",
|
|
64
|
+
"@ultimat3/flags": "31.52.0",
|
|
65
|
+
"@ultimat3/http": "31.52.0",
|
|
66
|
+
"@ultimat3/i18n": "31.52.0",
|
|
67
|
+
"@ultimat3/jobs": "31.52.0",
|
|
68
|
+
"@ultimat3/mail": "31.52.0",
|
|
69
|
+
"@ultimat3/manifest": "31.52.0",
|
|
70
|
+
"@ultimat3/mcp": "31.52.0",
|
|
71
|
+
"@ultimat3/money": "31.52.0",
|
|
72
|
+
"@ultimat3/notify": "31.52.0",
|
|
73
|
+
"@ultimat3/policy": "31.52.0",
|
|
74
|
+
"@ultimat3/pwa": "31.52.0",
|
|
75
|
+
"@ultimat3/query": "31.52.0",
|
|
76
|
+
"@ultimat3/realtime": "31.52.0",
|
|
77
|
+
"@ultimat3/render": "31.52.0",
|
|
78
|
+
"@ultimat3/schema": "31.52.0",
|
|
79
|
+
"@ultimat3/scraping": "31.52.0",
|
|
80
|
+
"@ultimat3/seo": "31.52.0",
|
|
81
|
+
"@ultimat3/storage": "31.52.0",
|
|
82
|
+
"@ultimat3/testing": "31.52.0",
|
|
83
|
+
"@ultimat3/time": "31.52.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
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
|
@@ -25,7 +25,7 @@ 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';
|
|
@@ -239,8 +239,23 @@ export async function scannedModulePaths(root: string): Promise<readonly string[
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
/** A module that would not import, keyed by its file. */
|
|
242
|
-
|
|
243
|
-
|
|
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
|
+
}
|
|
244
259
|
|
|
245
260
|
/** Reads at most this many sources at once: a 12k-module app opened 12k descriptors otherwise. */
|
|
246
261
|
const READ_BATCH = 64;
|
|
@@ -277,12 +292,13 @@ async function scanBatched(
|
|
|
277
292
|
const alone = await asyncModules(root, candidates);
|
|
278
293
|
const imported = await importInOrder(candidates, alone, register);
|
|
279
294
|
const result: ScanResult = { files: [], findings: [] };
|
|
295
|
+
const importFinding = importFindings(root);
|
|
280
296
|
for (const [index, absolute] of candidates.entries()) {
|
|
281
297
|
const file = posixRelative(root, absolute);
|
|
282
298
|
const one = imported[index];
|
|
283
299
|
if (one === undefined) continue;
|
|
284
300
|
if (!one.ok) {
|
|
285
|
-
result.findings.push(importFinding(one.error,
|
|
301
|
+
result.findings.push(await importFinding(one.error, file));
|
|
286
302
|
continue;
|
|
287
303
|
}
|
|
288
304
|
result.files.push(file);
|
|
@@ -299,6 +315,7 @@ async function scanSerial(
|
|
|
299
315
|
options: ScanOptions,
|
|
300
316
|
): Promise<ScanResult> {
|
|
301
317
|
const result: ScanResult = { files: [], findings: [] };
|
|
318
|
+
const importFinding = importFindings(root);
|
|
302
319
|
for (const absolute of candidates) {
|
|
303
320
|
const file = posixRelative(root, absolute);
|
|
304
321
|
if (options.include !== undefined && !(await options.include(absolute))) continue;
|
|
@@ -315,7 +332,7 @@ async function scanSerial(
|
|
|
315
332
|
try {
|
|
316
333
|
module = (await import(absolute)) as Record<string, unknown>;
|
|
317
334
|
} catch (error) {
|
|
318
|
-
result.findings.push(importFinding(error,
|
|
335
|
+
result.findings.push(await importFinding(error, file));
|
|
319
336
|
continue;
|
|
320
337
|
}
|
|
321
338
|
result.files.push(file);
|