@ultimat3/cli 31.2.0 → 31.4.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 +2 -2
- package/package.json +29 -29
- package/src/app-load.ts +3 -2
- package/src/cmd-doctor.ts +12 -316
- package/src/dev-boot.ts +4 -5
- package/src/dev-rebuild.ts +38 -5
- package/src/doctor-database.ts +121 -0
- package/src/doctor-port.ts +88 -0
- package/src/doctor-probe.ts +148 -0
- package/src/framework-schema.ts +4 -2
- package/src/island-build-pool.ts +35 -0
- package/src/island-bundle.ts +137 -176
- package/src/island-cache-inputs.ts +141 -0
- package/src/island-duplicates.ts +36 -0
- package/src/island-group-cache.ts +289 -0
- package/src/island-groups.ts +117 -0
- package/src/island-outputs.ts +153 -0
- package/src/island-runtime.ts +5 -0
- package/src/island-styles.ts +68 -19
- package/src/templates/scaffold-auth.ts +7 -10
- package/src/verify-e2e.ts +17 -5
- package/wiki/Client-Data.md +14 -8
- package/wiki/Configuration.md +1 -1
- package/wiki/Deployment.md +1 -1
- package/wiki/Entities-And-Migrations.md +15 -10
- package/wiki/Stability.md +6 -5
- package/wiki/Storage-And-Uploads.md +1 -1
- package/wiki/Testing.md +1 -0
- package/wiki/Upgrading.md +10 -10
package/CLAUDE.md
CHANGED
|
@@ -116,7 +116,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
116
116
|
| `generate-refresh.ts` | `x g` refreshes the manifest only when a written file needs it |
|
|
117
117
|
| `role-load.ts` / `document-graph.ts` / `serve-web.ts` | a role imports what it runs: `ROLE_LOADS` (`X_ROLE_LOAD_INCOMPLETE`) † |
|
|
118
118
|
| `module-imports.ts` | a module's imports, resolved once for both graphs: `referenced` (reload), `evaluated` (document) |
|
|
119
|
-
| `cmd-dev.ts` / `dev-boot.ts` / `dev-rebuild.ts` / `dev-route-table.ts` | `x dev`: every role in one process, `/_x`, the watcher; one save = one generation † |
|
|
119
|
+
| `cmd-dev.ts` / `dev-boot.ts` / `dev-rebuild.ts` / `dev-route-table.ts` | `x dev`: every role in one process, `/_x`, the watcher; one save = one generation, and the boot is the first: `buildGeneration` builds the manifest and the islands at once † |
|
|
120
120
|
| `runtime-bindings.ts` | which service each binding points at (embedded or external); events follow `NATS_URL` |
|
|
121
121
|
| `runtime-queue.ts` / `runtime-services.ts` / `runtime-bus.ts` | db + queue; every other accessor; the bus |
|
|
122
122
|
| `framework-schema-apply.ts` / `framework-schema-stamp.ts` | the framework tables, applied in one locked transaction † |
|
|
@@ -141,7 +141,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
141
141
|
| `page-navigation.ts` | the client router for `navigation.client` surfaces — built, routed and named ONCE for `x dev`, the container and the static export; none opted in builds nothing |
|
|
142
142
|
| `page-speculation.ts` | Speculation Rules for documents WITHOUT the router (`navigation.speculation`): an allow-list of pure-read pages ‡ |
|
|
143
143
|
| `static-document.ts` | a served `static` page: `304` on `If-None-Match`; container keeps the document (never `x dev`) † |
|
|
144
|
-
| `island-{bundle,store,sources,runtime}.ts` / `island-realtime*.ts` / `solid-loader.ts` | islands: one `Bun.build`
|
|
144
|
+
| `island-{bundle,groups,outputs,build-pool,group-cache,cache-inputs,store,sources,runtime}.ts` / `island-realtime*.ts` / `solid-loader.ts` | islands, source-addressed: one `Bun.build` per route group — islands on exactly the same routes split together, every other alone; groups read from `page.tsx` sources, the one input every caller has before rendering (`islands.sharedChunks` = one group). A group's output is reused from `.x/cache/islands/` while every file it read (Sass partials included), every directory listing it resolved in and the lockfile/tsconfig/`package.json` environment hash the same (`reuse: false` for a determinism test) † |
|
|
145
145
|
| `local-cli.ts` / `local-cli-handoff.ts` | a global `x` hands over to the app's own CLI (`local-cli.ts` decides whether; `x upgrade` alone stays when the app's is strictly older — `upgrade-handover.test.ts`) |
|
|
146
146
|
| `serve-prebuilt.ts` / `serve-prebuilt-paths.ts` | the image's prebuilt store; a boot that built anything logs `X_IMAGE_NOT_PREBUILT` † |
|
|
147
147
|
| `dev-*.ts` | `x dev` only: dashboard sources, traces, the N+1 ledger, watcher, reload, lock, port |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.4.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.0.9",
|
|
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.4.0",
|
|
57
|
+
"@ultimat3/admin": "31.4.0",
|
|
58
|
+
"@ultimat3/ai": "31.4.0",
|
|
59
|
+
"@ultimat3/auth": "31.4.0",
|
|
60
|
+
"@ultimat3/cache": "31.4.0",
|
|
61
|
+
"@ultimat3/core": "31.4.0",
|
|
62
|
+
"@ultimat3/db": "31.4.0",
|
|
63
|
+
"@ultimat3/entity": "31.4.0",
|
|
64
|
+
"@ultimat3/flags": "31.4.0",
|
|
65
|
+
"@ultimat3/http": "31.4.0",
|
|
66
|
+
"@ultimat3/i18n": "31.4.0",
|
|
67
|
+
"@ultimat3/jobs": "31.4.0",
|
|
68
|
+
"@ultimat3/mail": "31.4.0",
|
|
69
|
+
"@ultimat3/manifest": "31.4.0",
|
|
70
|
+
"@ultimat3/mcp": "31.4.0",
|
|
71
|
+
"@ultimat3/money": "31.4.0",
|
|
72
|
+
"@ultimat3/notify": "31.4.0",
|
|
73
|
+
"@ultimat3/policy": "31.4.0",
|
|
74
|
+
"@ultimat3/pwa": "31.4.0",
|
|
75
|
+
"@ultimat3/query": "31.4.0",
|
|
76
|
+
"@ultimat3/realtime": "31.4.0",
|
|
77
|
+
"@ultimat3/render": "31.4.0",
|
|
78
|
+
"@ultimat3/schema": "31.4.0",
|
|
79
|
+
"@ultimat3/scraping": "31.4.0",
|
|
80
|
+
"@ultimat3/seo": "31.4.0",
|
|
81
|
+
"@ultimat3/storage": "31.4.0",
|
|
82
|
+
"@ultimat3/testing": "31.4.0",
|
|
83
|
+
"@ultimat3/time": "31.4.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/app-load.ts
CHANGED
|
@@ -209,9 +209,10 @@ export function isScannedModule(root: string, absolute: string): boolean {
|
|
|
209
209
|
// `~/dev/node_modules-experiments/myapp` answered `includes('node_modules')` for every
|
|
210
210
|
// file it holds, so this loop imported none of them and the app registered nothing.
|
|
211
211
|
// The ROOT-RELATIVE path is tested, never the absolute one: an app checked out under
|
|
212
|
-
// `~/work/my.test.app` matched `.test.` on every file and loaded none of them
|
|
212
|
+
// `~/work/my.test.app` matched `.test.` on every file and loaded none of them, and one under
|
|
213
|
+
// `<anything>/node_modules/<app>` matched the segment on every file the same way.
|
|
213
214
|
const file = posixRelative(root, absolute);
|
|
214
|
-
if (hasPathSegment(
|
|
215
|
+
if (hasPathSegment(file, 'node_modules') || isTest(file)) return false;
|
|
215
216
|
return !(
|
|
216
217
|
ENTRY_POINT.test(file) ||
|
|
217
218
|
EXERCISE_FILE.test(file) ||
|
package/src/cmd-doctor.ts
CHANGED
|
@@ -2,203 +2,40 @@
|
|
|
2
2
|
// carries the command that fixes it; a diagnostic that only describes a problem has handed the
|
|
3
3
|
// work back to the reader.
|
|
4
4
|
|
|
5
|
-
import { existsSync } from 'node:fs';
|
|
6
|
-
import { dirname, join, resolve, sep } from 'node:path';
|
|
7
5
|
import { ENV_EXAMPLE_PATH, ERROR_DOCS_URL } from '@ultimat3/core';
|
|
8
|
-
import {
|
|
9
|
-
import { loadApp } from './app-load';
|
|
10
|
-
import { IMPORT_UNRESOLVED } from './app-load-unresolved';
|
|
11
|
-
import { findAppRoot, REQUIRED_BUN, versionAtLeast } from './app-root';
|
|
6
|
+
import { REQUIRED_BUN, versionAtLeast } from './app-root';
|
|
12
7
|
import { doctorSpec } from './cmd-doctor-spec';
|
|
13
8
|
import type { CliCommand, CommandContext } from './command';
|
|
14
|
-
import { checkMigrationSnapshots } from './db-snapshot';
|
|
15
9
|
import { appUrlFindings } from './doctor-app-url';
|
|
16
|
-
import {
|
|
10
|
+
import { authStorageFindings } from './doctor-auth';
|
|
17
11
|
import { chartAlertsProbe, withChartAlertsListing } from './doctor-chart-alerts';
|
|
18
12
|
import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
|
|
13
|
+
import { embeddedDatabaseFinding } from './doctor-database';
|
|
19
14
|
import { shippedGuardsProbe, withGuardListing } from './doctor-guards';
|
|
20
|
-
import
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
23
|
-
import {
|
|
15
|
+
import { offlineFallbackFinding } from './doctor-offline';
|
|
16
|
+
import { NO_POOLER_FACT, poolerFindings, withPoolerReport } from './doctor-pooler';
|
|
17
|
+
import { doctorPort, portFindings } from './doctor-port';
|
|
18
|
+
import type { DoctorProbe } from './doctor-probe';
|
|
19
|
+
import { probeFor } from './doctor-probe';
|
|
24
20
|
import { rollingSinceProbe, withRollingReminder } from './doctor-rolling';
|
|
25
|
-
import {
|
|
26
|
-
import
|
|
27
|
-
import { sealedKeyFindings, sealedKeysProbe } from './doctor-sealed';
|
|
28
|
-
import { typescriptFindings, typescriptProbe } from './doctor-typescript';
|
|
29
|
-
import { PORT_RANGE, portPairAfter, readIntFlag } from './flag-number';
|
|
30
|
-
import { machineSecretFindings } from './framework-env';
|
|
21
|
+
import { sealedKeyFindings } from './doctor-sealed';
|
|
22
|
+
import { typescriptFindings } from './doctor-typescript';
|
|
31
23
|
import { ICON_SOURCE } from './icon-assets';
|
|
32
24
|
import { msg } from './messages';
|
|
33
25
|
import type { CommandResult, Finding } from './output';
|
|
34
|
-
import { findingFrom } from './output';
|
|
35
|
-
import type { ParsedArgs } from './parse';
|
|
36
|
-
import { portFree } from './port-probe';
|
|
37
|
-
import { syncPortFor } from './role-sync';
|
|
38
|
-
import { checkMigrationDrift } from './schema-drift';
|
|
39
|
-
import { portFromEnv } from './serve-env';
|
|
40
26
|
import { quoteArg } from './shell-quote';
|
|
41
|
-
import type { TypescriptLag } from './typescript-floor';
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* `wiki/Upgrading.md` covers `X_*` codes, the eight primitive shapes, the `x` CLI surface, the
|
|
46
|
-
* tier table and `app.config.ts` fields, and not this — so a new fact the probe must report is a
|
|
47
|
-
* REQUIRED field: an optional one lets an implementation skip the check and still typecheck.
|
|
48
|
-
*/
|
|
49
|
-
export interface DoctorProbe {
|
|
50
|
-
readonly bunVersion: string;
|
|
51
|
-
/** App root, or undefined when the command runs outside an app. */
|
|
52
|
-
readonly root: string | undefined;
|
|
53
|
-
readonly port: number;
|
|
54
|
-
/** `APP_URL` as this environment declares it; `undefined` when unset. */
|
|
55
|
-
readonly appUrl: string | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* The framework's own secrets this machine lacks — `framework-env.ts`'s
|
|
58
|
-
* `machineSecretFindings`, gated by `namedDeployed`: only an environment NAMED staging or
|
|
59
|
-
* production (an unnamed developer shell owes nothing; `x env check` is the fail-closed answer).
|
|
60
|
-
* The list's own `needed`/`unsafe` decide; doctor reports.
|
|
61
|
-
*/
|
|
62
|
-
readonly frameworkFindings: readonly Finding[];
|
|
63
|
-
exists(relativePath: string): boolean;
|
|
64
|
-
portFree(port: number): Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* Is the configured database reachable, and what refused? `null` is "reachable, or there is
|
|
67
|
-
* nothing external to reach" — an unset `DATABASE_URL` is embedded PGlite, which `x dev` owns
|
|
68
|
-
* and which a probe would take the single-writer lock on.
|
|
69
|
-
*
|
|
70
|
-
* Until this existed `x doctor` answered "no findings — environment is shippable" against
|
|
71
|
-
* `DATABASE_URL=postgres://nope:nope@localhost:5432/nope`, while `x db migrate` on the same env
|
|
72
|
-
* correctly answered `X_DB_UNAVAILABLE` (#F5).
|
|
73
|
-
*/
|
|
74
|
-
database(): Promise<Finding | null>;
|
|
75
|
-
/**
|
|
76
|
-
* Is the EMBEDDED database usable, and is it the one this environment would open? A FACT and not
|
|
77
|
-
* a finding, the split `offlineFallback` makes below: reaching a module resolver is IO, and what
|
|
78
|
-
* an unresolvable optional peer MEANS is a pure rule with a pure test.
|
|
79
|
-
*
|
|
80
|
-
* `database()` answers `null` the moment `DATABASE_URL` is unset — which is exactly a bare VM,
|
|
81
|
-
* the configuration `x dev` invents a database FOR — so until this existed `x doctor` was silent
|
|
82
|
-
* about the only database a fresh box has. `bin/setup` found out instead, at `x db migrate`.
|
|
83
|
-
*/
|
|
84
|
-
embeddedDatabase(): Promise<EmbeddedDatabase>;
|
|
85
|
-
drift(): Promise<readonly Finding[]>;
|
|
86
|
-
/**
|
|
87
|
-
* The other half of the migrations directory: a newest migration with no `.snapshot.json`, which
|
|
88
|
-
* is what `x db gen` refuses on. Separate from `drift()` because they are separate questions with
|
|
89
|
-
* separate remedies — one is "generate a migration", the other is "this migration is incomplete".
|
|
90
|
-
*/
|
|
91
|
-
snapshots(): Promise<readonly Finding[]>;
|
|
92
|
-
/**
|
|
93
|
-
* What the app declared as its offline fallback, and which routes it really serves. A FACT and
|
|
94
|
-
* not a finding, because deciding is `offlineFallbackFinding`'s and this seam's whole job is
|
|
95
|
-
* reaching the disk — the same split `drift()` makes one question over.
|
|
96
|
-
*/
|
|
97
|
-
offlineFallback(): Promise<OfflineFallbackFact>;
|
|
98
|
-
/**
|
|
99
|
-
* The app's `.sealed()` columns and the master keys this environment declares. A FACT, for the
|
|
100
|
-
* reason `offlineFallback` is one: loading the app and opening the secrets file is IO, and what
|
|
101
|
-
* a retired key beside a sealed column means is `sealedKeyFindings`' pure rule.
|
|
102
|
-
*/
|
|
103
|
-
sealedKeys(): Promise<SealedKeysFact>;
|
|
104
|
-
/**
|
|
105
|
-
* What an upgrade left in the auth tables for an operator to finish: unsealed second-factor
|
|
106
|
-
* secrets, and tables no release reads. Asked of an external database only.
|
|
107
|
-
*/
|
|
108
|
-
authStorage(): Promise<AuthStorageFact>;
|
|
109
|
-
/** The statement bound the session really reads, and what a pooler refused (`doctor-pooler.ts`). */
|
|
110
|
-
pooler(): Promise<PoolerFact>;
|
|
111
|
-
/** Each manifest whose `typescript` range lags the scaffold's (`doctor-typescript.ts`). */
|
|
112
|
-
typescript(): Promise<readonly TypescriptLag[]>;
|
|
113
|
-
/** With `database.rowSecurity` on, whether the serving role is exempt (`doctor-row-security.ts`). */
|
|
114
|
-
rowSecurity?(): Promise<readonly Finding[]>;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** What `x doctor` reads about the embedded database, without opening it. */
|
|
118
|
-
export interface EmbeddedDatabase {
|
|
119
|
-
/**
|
|
120
|
-
* True while `DATABASE_URL` is unset or blank — the condition that makes PGlite the app's
|
|
121
|
-
* database (`resolveServices`), and the same reading `probeDatabase` returns `null` on.
|
|
122
|
-
*/
|
|
123
|
-
readonly selected: boolean;
|
|
124
|
-
/** Does `@electric-sql/pglite` resolve from the app root? */
|
|
125
|
-
readonly resolved: boolean;
|
|
126
|
-
}
|
|
28
|
+
// `src/index.ts` publishes the seam from here; its declaration lives in `doctor-probe.ts`.
|
|
29
|
+
export type { DoctorProbe } from './doctor-probe';
|
|
127
30
|
|
|
128
31
|
const finding = (code: string, cause: string, fix: string, at?: string): Finding =>
|
|
129
32
|
at === undefined
|
|
130
33
|
? { code, cause, fix, docs: ERROR_DOCS_URL }
|
|
131
34
|
: { code, cause, fix, docs: ERROR_DOCS_URL, at };
|
|
132
35
|
|
|
133
|
-
/**
|
|
134
|
-
* The rule, pure. Red only where the embedded database is the one that would be opened: an app
|
|
135
|
-
* pointed at a real Postgres never loads PGlite, and a finding about an absent optional peer there
|
|
136
|
-
* is noise the reader learns to skim.
|
|
137
|
-
*
|
|
138
|
-
* `@ultimat3/db`'s own refusal, not a CLI twin of it — same `X_DB_UNAVAILABLE`, same sentence,
|
|
139
|
-
* same runnable fix. The package already says this the moment a query arrives; `x doctor` is what
|
|
140
|
-
* says it before `bin/setup` gets that far.
|
|
141
|
-
*/
|
|
142
|
-
export const embeddedDatabaseFinding = (fact: EmbeddedDatabase): Finding | undefined =>
|
|
143
|
-
fact.selected && !fact.resolved
|
|
144
|
-
? finding(
|
|
145
|
-
'X_DB_UNAVAILABLE',
|
|
146
|
-
`${PGLITE_MISSING} — and DATABASE_URL is unset or blank, so the embedded one is the database this app would open`,
|
|
147
|
-
PGLITE_FIX,
|
|
148
|
-
)
|
|
149
|
-
: undefined;
|
|
150
|
-
|
|
151
36
|
/** The file `x doctor` reports missing, and the one the reader creates. */
|
|
152
37
|
export const ENV_DEVELOPMENT = '.env.development';
|
|
153
38
|
|
|
154
|
-
/**
|
|
155
|
-
* Both ports `x dev` binds, each labelled with the role that wants it. `x dev --port 3999` printed
|
|
156
|
-
* `web listening on 3999`, then died on 4000 as `X_CLI_UNEXPECTED` with a caught `Error` rendered
|
|
157
|
-
* into its cause — and `x doctor --port 3999` answered "no findings", because it probed the web
|
|
158
|
-
* port and only the web port (#F5). The neighbouring port is not an implementation detail an
|
|
159
|
-
* operator can ignore: `docker-compose.prod.yml` publishes `3001:3001` from it and `docker/helm`
|
|
160
|
-
* derives `PORT = .port - 1` from it, so it is part of the contract `x dev` runs by.
|
|
161
|
-
*
|
|
162
|
-
* The suggested port moves BOTH: `x dev --port N` occupies N and N+1, so a free N beside a taken
|
|
163
|
-
* N+1 is still not a runnable command. It did not move both until 2026-09 — the line was
|
|
164
|
-
* `neighbouringPort(probe.port)`, which for the sync finding IS the port the finding is about, and
|
|
165
|
-
* a docblock claiming otherwise is how it survived. `portPairAfter` is the one reader of that rule
|
|
166
|
-
* and `role-sync.ts`'s own refusal shares it.
|
|
167
|
-
*
|
|
168
|
-
* The sync port is `syncPortFor`, never `neighbouringPort` again: that helper answers 65534 for a
|
|
169
|
-
* web port of 65535 — BELOW the web port, and a port `x dev` never binds — where the boot refuses
|
|
170
|
-
* the run outright with `X_PORT_INVALID`. A probe that reports on a socket the command would never
|
|
171
|
-
* open is answering a question nobody asked, so the boot's own rule decides, and its refusal is
|
|
172
|
-
* reported instead of a probe. Alone, and ahead of the web port: there is no runnable `x dev` at
|
|
173
|
-
* this port whatever the other one answers, and a second finding about it is noise over the cause.
|
|
174
|
-
*/
|
|
175
|
-
async function portFindings(probe: DoctorProbe): Promise<readonly Finding[]> {
|
|
176
|
-
let syncPort: number;
|
|
177
|
-
try {
|
|
178
|
-
syncPort = syncPortFor(probe.port);
|
|
179
|
-
} catch (error) {
|
|
180
|
-
// The boot's own error, carried whole — `findingFrom` reads its code, cause and fix off the
|
|
181
|
-
// value rather than rendering it, which is what `scripts/catch-render.ts` requires.
|
|
182
|
-
return [findingFrom(error)];
|
|
183
|
-
}
|
|
184
|
-
const wanted = [
|
|
185
|
-
{ port: probe.port, role: 'web' },
|
|
186
|
-
{ port: syncPort, role: 'sync' },
|
|
187
|
-
] as const;
|
|
188
|
-
const findings: Finding[] = [];
|
|
189
|
-
for (const entry of wanted) {
|
|
190
|
-
if (await probe.portFree(entry.port)) continue;
|
|
191
|
-
findings.push(
|
|
192
|
-
finding(
|
|
193
|
-
'X_PORT_IN_USE',
|
|
194
|
-
`port ${entry.port} is already listening, and \`x dev --port ${probe.port}\` binds it for the ${entry.role} role`,
|
|
195
|
-
`x dev --port ${quoteArg(String(portPairAfter(probe.port)))}`,
|
|
196
|
-
),
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
return findings;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
39
|
/**
|
|
203
40
|
* Ordered cheapest-first so the first failure is usually the root cause: a wrong Bun explains
|
|
204
41
|
* every other symptom, and running outside an app explains the rest.
|
|
@@ -297,147 +134,6 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
|
|
|
297
134
|
return findings;
|
|
298
135
|
}
|
|
299
136
|
|
|
300
|
-
/**
|
|
301
|
-
* The port to TEST, and the one place `x doctor` reads it: `devPortFor`'s order — `--port`, then
|
|
302
|
-
* `PORT` (`portFromEnv`, the one reader of it), then 3000 — so the probe answers about the port
|
|
303
|
-
* `x dev` will bind. It probed 3000 under `PORT=4000` while dev bound 4000 and 4001. `PORT_RANGE.min`
|
|
304
|
-
* is 0 because `x dev --port 0` means "let the kernel pick"; here 0 means nothing, and
|
|
305
|
-
* `Bun.serve({ port: 0 })` always succeeds — so the port check could not fail.
|
|
306
|
-
*/
|
|
307
|
-
export const doctorPort = (
|
|
308
|
-
args: ParsedArgs,
|
|
309
|
-
env: Readonly<Record<string, string | undefined>>,
|
|
310
|
-
): number =>
|
|
311
|
-
readIntFlag(args, {
|
|
312
|
-
name: 'port',
|
|
313
|
-
command: 'doctor',
|
|
314
|
-
...PORT_RANGE,
|
|
315
|
-
min: 1,
|
|
316
|
-
example: 'x doctor --port 3000',
|
|
317
|
-
}) ?? portFromEnv(env);
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* `DATABASE_URL` as BOTH halves of the database question read it: unset and blank are one case.
|
|
321
|
-
* One seam, because the two halves are complementary — a second reading of the same variable is
|
|
322
|
-
* how a configuration ends up reported by neither probe, or by both.
|
|
323
|
-
*/
|
|
324
|
-
const externalUrl = (raw: string | undefined): string | undefined =>
|
|
325
|
-
raw === undefined || raw.trim() === '' ? undefined : raw;
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Is the optional peer INSTALLED for this app — a `node_modules` walk up from the app root.
|
|
329
|
-
*
|
|
330
|
-
* Never an IMPORT: loading PGlite boots 26 MB of WASM and takes the single-writer lock the next
|
|
331
|
-
* command needs, and a diagnostic must not be the reason `x dev` cannot open the database it just
|
|
332
|
-
* reported on.
|
|
333
|
-
*
|
|
334
|
-
* Never `Bun.resolveSync` either, which was this check's first draft. It falls back to Bun's
|
|
335
|
-
* machine-global install cache: measured 2026-09-11 against a freshly scaffolded app with no
|
|
336
|
-
* `node_modules` anywhere above it, `Bun.resolveSync('@electric-sql/pglite', <app>)` answered
|
|
337
|
-
* `~/.bun/install/cache/@electric-sql/pglite@0.5.8@@@1/dist/index.js` — a version the app does not
|
|
338
|
-
* depend on, in a directory `bun install` never wrote for it. A box that had downloaded the package
|
|
339
|
-
* ONCE, for anything, would have read as ready on every app after it, which is the exact opposite
|
|
340
|
-
* of the question. The walk asks what `bun add` answers, and nothing else.
|
|
341
|
-
*
|
|
342
|
-
* Up from the root and not at it, because an app checked out inside a larger workspace is installed
|
|
343
|
-
* by the hoisting one: `examples/dummy` in this repository has no `node_modules` of its own.
|
|
344
|
-
*/
|
|
345
|
-
const installedAbove = (dir: string, specifier: string): boolean => {
|
|
346
|
-
let current = resolve(dir);
|
|
347
|
-
// Bounded by the path itself — one segment per step — rather than by `for (;;)` and the promise
|
|
348
|
-
// that `dirname('/')` is `/`. The loop still stops on that, one step earlier.
|
|
349
|
-
for (let remaining = current.split(sep).length; remaining > 0; remaining -= 1) {
|
|
350
|
-
if (existsSync(join(current, 'node_modules', specifier, 'package.json'))) return true;
|
|
351
|
-
const parent = dirname(current);
|
|
352
|
-
if (parent === current) return false;
|
|
353
|
-
current = parent;
|
|
354
|
-
}
|
|
355
|
-
return false;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* A real `select 1` through the app's own driver, not a TCP connect: a running Postgres with the
|
|
360
|
-
* wrong credentials or a database that does not exist accepts the socket and refuses the session,
|
|
361
|
-
* which is the case an operator most needs told about before a deploy.
|
|
362
|
-
*
|
|
363
|
-
* The pool is CLOSED on every path — this command exits, and a held pool is a connection slot the
|
|
364
|
-
* next `x db migrate` cannot have.
|
|
365
|
-
*/
|
|
366
|
-
async function probeDatabase(
|
|
367
|
-
url: string | undefined,
|
|
368
|
-
env: Readonly<Record<string, string | undefined>>,
|
|
369
|
-
): Promise<Finding | null> {
|
|
370
|
-
if (externalUrl(url) === undefined) return null;
|
|
371
|
-
let client: ReturnType<typeof postgresClient>;
|
|
372
|
-
try {
|
|
373
|
-
client = postgresClient({ url, env, applicationName: 'x-doctor' });
|
|
374
|
-
} catch (error) {
|
|
375
|
-
return findingFrom(error);
|
|
376
|
-
}
|
|
377
|
-
try {
|
|
378
|
-
const report = await checkDb(client);
|
|
379
|
-
if (report.ok) return null;
|
|
380
|
-
// `DbHealthReport.error` is `checkDb`'s own rendering of what refused, never this file's — the
|
|
381
|
-
// caught value is `checkDb`'s to read, and it is the one function that already reads it safely.
|
|
382
|
-
return finding(
|
|
383
|
-
'X_DB_UNAVAILABLE',
|
|
384
|
-
`DATABASE_URL does not answer \`select 1\`: ${report.error ?? 'no reason reported'}`,
|
|
385
|
-
// `dbUnavailable`'s own two branches, verbatim: a second wording for one condition is two
|
|
386
|
-
// answers to "what do I do", and this one is reached first, before any command opens a pool.
|
|
387
|
-
'set DATABASE_URL to a reachable Postgres url, or run `x dev` to use the embedded PGlite',
|
|
388
|
-
);
|
|
389
|
-
} finally {
|
|
390
|
-
await client.close();
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export function probeFor(
|
|
395
|
-
cwd: string,
|
|
396
|
-
bunVersion: string,
|
|
397
|
-
port: number,
|
|
398
|
-
// The environment `doctorPort` read `PORT` from, so `APP_URL` is judged against the same one.
|
|
399
|
-
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
400
|
-
): DoctorProbe {
|
|
401
|
-
const root = findAppRoot(cwd)?.dir;
|
|
402
|
-
return {
|
|
403
|
-
bunVersion,
|
|
404
|
-
root,
|
|
405
|
-
port,
|
|
406
|
-
appUrl: env['APP_URL'],
|
|
407
|
-
frameworkFindings: machineSecretFindings(env),
|
|
408
|
-
exists: (relativePath) => (root === undefined ? false : existsSync(join(root, relativePath))),
|
|
409
|
-
portFree,
|
|
410
|
-
database: () => probeDatabase(process.env['DATABASE_URL'], env),
|
|
411
|
-
// `root ?? cwd` because the walk needs a directory that exists; outside an app `runDoctor`
|
|
412
|
-
// returns on `X_NOT_IN_APP` before this is ever asked, so the value only has to be honest.
|
|
413
|
-
embeddedDatabase: async () => ({
|
|
414
|
-
selected: externalUrl(process.env['DATABASE_URL']) === undefined,
|
|
415
|
-
resolved: installedAbove(root ?? cwd, PGLITE_PACKAGE),
|
|
416
|
-
}),
|
|
417
|
-
drift: async () => (root === undefined ? [] : checkMigrationDrift(root)),
|
|
418
|
-
// The import half too: `X_CLI_UNEXPECTED` used to send a reader here and find this silent.
|
|
419
|
-
snapshots: async () =>
|
|
420
|
-
root === undefined
|
|
421
|
-
? []
|
|
422
|
-
: [...(await unresolvedImportFindings(root)), ...(await checkMigrationSnapshots(root))],
|
|
423
|
-
// `routes: undefined` outside an app is "not judged", which is what the caller already is:
|
|
424
|
-
// `runDoctor` returns on `X_NOT_IN_APP` before this can be asked.
|
|
425
|
-
offlineFallback: async () =>
|
|
426
|
-
root === undefined ? { fallback: null, routes: undefined } : offlineFallbackProbe(root),
|
|
427
|
-
sealedKeys: async () =>
|
|
428
|
-
root === undefined ? { columns: undefined, keys: undefined } : sealedKeysProbe(root),
|
|
429
|
-
authStorage: () => authStorageProbe(process.env['DATABASE_URL'], env),
|
|
430
|
-
pooler: () => poolerProbe(process.env['DATABASE_URL'], env),
|
|
431
|
-
typescript: async () => (root === undefined ? [] : typescriptProbe(root)),
|
|
432
|
-
rowSecurity: async () =>
|
|
433
|
-
root === undefined ? [] : rowSecurityProbe(root, process.env['DATABASE_URL'], env),
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/** What a load reports, narrowed to the one failure a doctor can name a repair for. */
|
|
438
|
-
const unresolvedImportFindings = async (root: string): Promise<readonly Finding[]> =>
|
|
439
|
-
(await loadApp(root)).findings.filter((finding) => finding.code === IMPORT_UNRESOLVED);
|
|
440
|
-
|
|
441
137
|
export const doctorCommand: CliCommand = {
|
|
442
138
|
spec: doctorSpec,
|
|
443
139
|
async run(ctx: CommandContext): Promise<CommandResult> {
|
package/src/dev-boot.ts
CHANGED
|
@@ -10,7 +10,6 @@ import type { OverlayNotice, RequestContext } from '@ultimat3/http';
|
|
|
10
10
|
import { asCtx } from '@ultimat3/http';
|
|
11
11
|
import { loadSignInPath } from './app-auth';
|
|
12
12
|
import { loadAppConfig } from './app-config-load';
|
|
13
|
-
import { appManifest } from './app-manifest';
|
|
14
13
|
import type { StalePin } from './app-reload-graph';
|
|
15
14
|
import { enableReloadTracking } from './app-reload-graph';
|
|
16
15
|
import { loadAppRuntime } from './app-runtime';
|
|
@@ -20,12 +19,11 @@ import { createInvalidationLog } from './dev-dashboard-invalidations';
|
|
|
20
19
|
import { declareDevEnvironment, needsDevEnvironmentDeclaration } from './dev-environment';
|
|
21
20
|
import { createStatementLedger } from './dev-n-plus-one';
|
|
22
21
|
import type { DevState } from './dev-rebuild';
|
|
23
|
-
import { devRebuilder } from './dev-rebuild';
|
|
22
|
+
import { buildGeneration, devRebuilder } from './dev-rebuild';
|
|
24
23
|
import { devRouteTable } from './dev-route-table';
|
|
25
24
|
import { createTraceRecorder } from './dev-traces';
|
|
26
25
|
import { watchTree } from './dev-watch-tree';
|
|
27
26
|
import { armFailureCapture } from './failure-capture-boot';
|
|
28
|
-
import { buildIslands } from './island-bundle';
|
|
29
27
|
import { FRAME_STYLE } from './island-harness';
|
|
30
28
|
import type { Finding } from './output';
|
|
31
29
|
import { plainRoutes } from './plain-routes';
|
|
@@ -184,13 +182,14 @@ async function bootDev(
|
|
|
184
182
|
// two projections of one scan. Until 2026-09-07 this was `loadApp` for the findings and then
|
|
185
183
|
// `appManifest` — which loads again — for the manifest, so a save landing between the two put
|
|
186
184
|
// `/_x`'s findings and its manifest on different registration states.
|
|
187
|
-
|
|
185
|
+
// The islands are built beside that load, never after it: `buildGeneration`, as every save does.
|
|
186
|
+
const app = await buildGeneration(options.root);
|
|
188
187
|
const state: DevState = {
|
|
189
188
|
manifest: app.manifest,
|
|
190
189
|
reloads: 0,
|
|
191
190
|
reloadFinding: undefined,
|
|
192
191
|
appFindings: app.findings,
|
|
193
|
-
islands:
|
|
192
|
+
islands: app.islands,
|
|
194
193
|
};
|
|
195
194
|
// `serve-boot.ts`'s guard, at its point: after the app's modules, before any role serves. On
|
|
196
195
|
// PGlite the boot serves as `x_app`; on an external database a role that bypasses is refused.
|
package/src/dev-rebuild.ts
CHANGED
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
import type { Manifest } from '@ultimat3/manifest';
|
|
6
6
|
import { beginDeviceSocketGeneration } from '@ultimat3/realtime/server';
|
|
7
7
|
import type { IsrController } from '@ultimat3/render/server';
|
|
8
|
+
import type { AppManifest } from './app-manifest';
|
|
8
9
|
import { appManifest } from './app-manifest';
|
|
9
10
|
import type { StalePin } from './app-reload-graph';
|
|
10
11
|
import { takeStalePins } from './app-reload-graph';
|
|
11
12
|
import type { ReloadTrigger } from './dev-reload';
|
|
12
13
|
import { coalesceReloads } from './dev-reload';
|
|
13
14
|
import { restartFinding } from './dev-supervisor';
|
|
14
|
-
import type { IslandBundle } from './island-bundle';
|
|
15
|
+
import type { BuildIslandsOptions, IslandBundle } from './island-bundle';
|
|
15
16
|
import { buildIslands } from './island-bundle';
|
|
17
|
+
import { appPersistsRecords } from './island-realtime-state';
|
|
16
18
|
import type { Finding } from './output';
|
|
17
19
|
import { findingFrom } from './output';
|
|
18
20
|
|
|
@@ -36,6 +38,40 @@ export interface DevState {
|
|
|
36
38
|
islands: IslandBundle;
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
/** The two builders of one generation — the seam a test times them through. */
|
|
42
|
+
export interface GenerationBuilders {
|
|
43
|
+
readonly manifest: (root: string) => Promise<AppManifest>;
|
|
44
|
+
readonly islands: (root: string, options: BuildIslandsOptions) => Promise<IslandBundle>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const BUILDERS: GenerationBuilders = { manifest: appManifest, islands: buildIslands };
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* One generation — the app's manifest and its island bundle — both builders started at once, at
|
|
51
|
+
* the boot as on every save. The island build is Bun's bundler, off the JS thread, and the app
|
|
52
|
+
* load is imports on it: one after the other, a 5,000-file app's boot paid ~4 s and ~12 s in sum
|
|
53
|
+
* before its first 200 (`scripts/bench/results/boot-large-app.json`).
|
|
54
|
+
*/
|
|
55
|
+
export async function buildGeneration(
|
|
56
|
+
root: string,
|
|
57
|
+
build: GenerationBuilders = BUILDERS,
|
|
58
|
+
): Promise<AppManifest & { readonly islands: IslandBundle }> {
|
|
59
|
+
const loaded = build.manifest(root);
|
|
60
|
+
// The one answer the island build takes from the app — whether it persists records — read only
|
|
61
|
+
// once the load has settled: before it the registry is empty, and every reader island would be
|
|
62
|
+
// built as one that restores (`island-realtime.ts`). Only realtime groups wait for it.
|
|
63
|
+
const persists = (): Promise<boolean | undefined> =>
|
|
64
|
+
loaded.then(
|
|
65
|
+
() => appPersistsRecords(),
|
|
66
|
+
() => undefined,
|
|
67
|
+
);
|
|
68
|
+
const [{ manifest, findings }, islands] = await Promise.all([
|
|
69
|
+
loaded,
|
|
70
|
+
build.islands(root, { persists }),
|
|
71
|
+
]);
|
|
72
|
+
return { manifest, findings, islands };
|
|
73
|
+
}
|
|
74
|
+
|
|
39
75
|
/** What a rebuild reports to, read off `StartDevOptions`. */
|
|
40
76
|
export interface DevRebuildOptions {
|
|
41
77
|
readonly root: string;
|
|
@@ -73,10 +109,7 @@ export function devRebuilder(
|
|
|
73
109
|
async (file) => {
|
|
74
110
|
const started = performance.now();
|
|
75
111
|
beginDeviceSocketGeneration();
|
|
76
|
-
const
|
|
77
|
-
appManifest(options.root),
|
|
78
|
-
buildIslands(options.root),
|
|
79
|
-
]);
|
|
112
|
+
const { manifest, findings, islands } = await buildGeneration(options.root);
|
|
80
113
|
state.manifest = manifest;
|
|
81
114
|
state.appFindings = findings;
|
|
82
115
|
state.islands = islands;
|