@nifrajs/cli 5.0.0 → 5.2.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/CHANGELOG.md +3211 -0
- package/README.md +10 -2
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +5 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts +12 -2
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +73 -9
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +152 -49
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +7 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +8 -2
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +49 -13
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +91 -45
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +128 -59
- package/dist/cli.js.map +1 -1
- package/dist/client-module.d.ts +5 -3
- package/dist/client-module.d.ts.map +1 -1
- package/dist/client-module.js +34 -10
- package/dist/client-module.js.map +1 -1
- package/dist/command-catalog.d.ts +9 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +75 -26
- package/dist/command-catalog.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +19 -1
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +114 -0
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/fix-recipes.d.ts +2 -0
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +93 -12
- package/dist/fix-recipes.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +60 -4
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +196 -33
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/config-paths.d.ts +16 -0
- package/dist/internal/config-paths.d.ts.map +1 -0
- package/dist/internal/config-paths.js +124 -0
- package/dist/internal/config-paths.js.map +1 -0
- package/dist/internal/installed-package.d.ts +4 -0
- package/dist/internal/installed-package.d.ts.map +1 -0
- package/dist/internal/installed-package.js +17 -0
- package/dist/internal/installed-package.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts +14 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +63 -16
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +12 -1
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +117 -5
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +5 -3
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/introspect.d.ts +9 -0
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +32 -1
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +5 -8
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +9 -4
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +32 -3
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-context.d.ts.map +1 -1
- package/dist/mcp-context.js +6 -21
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-delegate.d.ts +2 -2
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +19 -7
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +13 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +13 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +23 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-path.d.ts +2 -1
- package/dist/mcp-path.d.ts.map +1 -1
- package/dist/mcp-path.js +9 -24
- package/dist/mcp-path.js.map +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +40 -17
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +41 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +1729 -236
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts +34 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +132 -21
- package/dist/output-schemas.js.map +1 -1
- package/dist/project-path.d.ts +6 -0
- package/dist/project-path.d.ts.map +1 -1
- package/dist/project-path.js +48 -14
- package/dist/project-path.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +7 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/release-verification.d.ts +5 -0
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +14 -0
- package/dist/release-verification.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +7 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +5 -1
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +5 -1
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/data-guard.d.ts +6 -0
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +37 -0
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +316 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +44 -2
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +56 -3
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +412 -23
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts +3 -2
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +42 -11
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +34 -11
- package/dist/rules/zones.js.map +1 -1
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +127 -17
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +3 -9
- package/dist/test-tool.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +57 -6
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +247 -19
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +7 -2
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +66 -3
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +21 -3
- package/docs/llms-full.txt +1083 -168
- package/docs/types.json +535 -112
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +5 -1
- package/src/assure.ts +99 -11
- package/src/capabilities-tool.ts +188 -53
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +65 -12
- package/src/check.ts +122 -51
- package/src/cli.ts +127 -45
- package/src/client-module.ts +45 -9
- package/src/command-catalog.ts +92 -28
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +146 -1
- package/src/doctor.ts +102 -66
- package/src/fix-recipes.ts +101 -10
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +225 -44
- package/src/internal/config-paths.ts +154 -0
- package/src/internal/installed-package.ts +15 -0
- package/src/internal/project-specifiers.ts +78 -17
- package/src/internal/source-facts.ts +147 -5
- package/src/internal/typescript-import.ts +5 -3
- package/src/internal/workspace-packages.ts +218 -0
- package/src/introspect.ts +39 -1
- package/src/levels-tool.ts +7 -9
- package/src/load.ts +46 -4
- package/src/lock-links.ts +173 -0
- package/src/mcp-context.ts +5 -18
- package/src/mcp-delegate.ts +22 -10
- package/src/mcp-exec.ts +14 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +33 -0
- package/src/mcp-path.ts +8 -22
- package/src/mcp-root.ts +14 -8
- package/src/mcp.ts +48 -19
- package/src/migrate-layout.ts +1968 -245
- package/src/output-schemas.ts +179 -23
- package/src/project-path.ts +44 -13
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/index.ts +7 -0
- package/src/release-verification.ts +20 -0
- package/src/review.ts +7 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +5 -1
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/data-guard.ts +40 -0
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +46 -2
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +486 -25
- package/src/rules/routes.ts +4 -3
- package/src/rules/security.ts +49 -11
- package/src/rules/zones.ts +33 -9
- package/src/stylex-migrate.ts +117 -17
- package/src/test-tool.ts +3 -9
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +312 -19
- package/src/verification-plan.ts +15 -2
- package/src/version-drift.ts +68 -2
- package/src/web-app-options.ts +9 -1
package/src/cli.ts
CHANGED
|
@@ -126,6 +126,11 @@ Usage:
|
|
|
126
126
|
one left. Exits 1 while current-code errors are open.
|
|
127
127
|
nifra logs [--since <n>] [--level <l>] [--grep <s>] The dev server's console, server and
|
|
128
128
|
browser, each line tagged with its request.
|
|
129
|
+
nifra explain [<message>] [--stack <s>] [--name <n>] A structured diagnostic for an error: its
|
|
130
|
+
code, the frame in your source, and the cause and fix when
|
|
131
|
+
nifra knows them. No message: the dev server's latest error.
|
|
132
|
+
A rule code (NF-C007): what that check rule reports and how
|
|
133
|
+
to fix it.
|
|
129
134
|
nifra cdn-check <url> Check a deployed page behind a CDN: served from cache, no
|
|
130
135
|
internal or CDN-only headers reaching the visitor, and soft
|
|
131
136
|
navigations get page data, not the cached document. Exits 1
|
|
@@ -177,12 +182,16 @@ Usage:
|
|
|
177
182
|
structure" sections. No-clobber by default (skips a file you've
|
|
178
183
|
customized); --force overwrites the owned files. AGENTS.md is
|
|
179
184
|
only appended to, never overwritten.
|
|
180
|
-
nifra init-agents --sync-mcp [--json]
|
|
185
|
+
nifra init-agents --sync-mcp [--json] Move an existing app's MCP launch to the nifra the project
|
|
181
186
|
installs: rewrites only the @nifrajs/cli@x.y.z version in
|
|
182
187
|
.mcp.json, .cursor/mcp.json, CLAUDE.md and AGENTS.md's MCP
|
|
183
|
-
section - every other byte stays as it is
|
|
188
|
+
section - every other byte stays as it is - and drops it
|
|
189
|
+
when the project declares @nifrajs/cli, so the launch runs
|
|
190
|
+
that install from then on. Creates nothing.
|
|
184
191
|
At a workspace root with one nifra member, the two registries'
|
|
185
|
-
launch also names that member (\`mcp app\`).
|
|
192
|
+
launch also names that member (\`mcp app\`). Run in a member,
|
|
193
|
+
it also re-pins the files above it, up to the repository
|
|
194
|
+
root, whose every nifra launch serves that member.
|
|
186
195
|
nifra mcp [dir] Start an MCP server (stdio) exposing this project to a coding
|
|
187
196
|
agent. The project root is [dir] when given, else resolved from
|
|
188
197
|
cwd (marker walk-up + the client's MCP roots); tools refuse
|
|
@@ -268,25 +277,30 @@ Usage:
|
|
|
268
277
|
[--list] [--json] apply exact imports, pin every matching dependency (keeping
|
|
269
278
|
[--exact] ^/~, or exact with --exact), then verify with nifra check.
|
|
270
279
|
[--allow-downgrade] Dry-run by default; --write applies then verifies (--no-verify
|
|
271
|
-
[--
|
|
272
|
-
|
|
273
|
-
this CLI prints the command for
|
|
274
|
-
on an unknown version
|
|
275
|
-
overrides)
|
|
276
|
-
|
|
280
|
+
[--allow-linked-skew] to skip), then prints how hook scope changed (--no-hooks to
|
|
281
|
+
[--no-hooks] skip). --list shows the targets with each newer release's
|
|
282
|
+
notes. A version newer than this CLI prints the command for
|
|
283
|
+
that release's CLI. Fail-closed on an unknown version, a
|
|
284
|
+
rollback (--allow-downgrade overrides), or a linked repository
|
|
285
|
+
that loads its own nifra at another version
|
|
286
|
+
(--allow-linked-skew overrides). Deterministic + idempotent.
|
|
287
|
+
nifra migrate layout [--write] [--zones] [--json]
|
|
277
288
|
Move an app onto the frontend/backend split: split each route
|
|
278
289
|
into x.tsx + x.backend.ts, fold _middleware.ts into
|
|
279
290
|
_layout.backend.ts, move backend.ts/framework.ts under backend/,
|
|
280
|
-
and zone the other modules into frontend/, backend/ or shared
|
|
281
|
-
|
|
291
|
+
and zone the other modules into frontend/, backend/ or shared/
|
|
292
|
+
(--zones keeps them in place and lists them in package.json
|
|
293
|
+
"nifra.zones"). Dry-run by default; --write applies.
|
|
282
294
|
nifra types [--check] [--json] Generate each route's ./+types module under .nifra/types: its
|
|
283
295
|
params, the data its output schemas let through, and api typed
|
|
284
296
|
by backend/app.ts. dev, build and check refresh them too;
|
|
285
297
|
--check fails when one is stale.
|
|
286
|
-
nifra schemas [--write] [--json]
|
|
298
|
+
nifra schemas [--write] [--check] [--json]
|
|
299
|
+
Draft loaderOutput/actionOutput from each loader's and
|
|
287
300
|
action's return type for review; --write adds the missing
|
|
288
301
|
ones (marked nifra:generated) and refreshes generated ones.
|
|
289
|
-
Lists the returned fields a hand-written schema drops
|
|
302
|
+
Lists the returned fields a hand-written schema drops;
|
|
303
|
+
--check fails on a missing, stale or any-typed one.
|
|
290
304
|
nifra port [--target <t>] [--json] Portability linter: print a feature × deploy-target capability
|
|
291
305
|
[--ci] [--strict] matrix (in-memory stores, in-process cron/WebSocket, Bun/Deno
|
|
292
306
|
globals, node: builtins) with file:line evidence. --target auto-
|
|
@@ -297,8 +311,9 @@ Usage:
|
|
|
297
311
|
[--json] [--strict] placeholder + tag parity, plural cases, script purity,
|
|
298
312
|
untranslated messages. IMPORTS the entry (default: the first
|
|
299
313
|
i18n.ts in ., lib/, src/, src/lib/, app/), which exports
|
|
300
|
-
\`locales\` + \`catalogs\` (+ optional \`ignore\`)
|
|
301
|
-
|
|
314
|
+
\`locales\` + \`catalogs\` (+ optional \`ignore\`), or a
|
|
315
|
+
\`copy\` from defineCopy(), whose tables it finds in the
|
|
316
|
+
source. Exits 1 on errors; --strict also on warnings.
|
|
302
317
|
|
|
303
318
|
Reads nifra.config.ts (adapter + clientModule + plugins; or backend/framework.ts), backend/app.ts
|
|
304
319
|
(optional), and routes/ from the current directory. Run from your project root.
|
|
@@ -315,7 +330,7 @@ set in the process environment is never overwritten by a file.
|
|
|
315
330
|
${renderCommandCatalogHelp()}`
|
|
316
331
|
|
|
317
332
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
318
|
-
const CLI_VERSION = "5.
|
|
333
|
+
const CLI_VERSION = "5.2.0"
|
|
319
334
|
|
|
320
335
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
321
336
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
@@ -366,6 +381,14 @@ export function formatCliError(err: unknown): string {
|
|
|
366
381
|
return String(err)
|
|
367
382
|
}
|
|
368
383
|
|
|
384
|
+
/** A failed command's message on stderr and, for a `--json` caller parsing stdout, as JSON there. */
|
|
385
|
+
function reportFailure(err: unknown, argv: readonly string[]): void {
|
|
386
|
+
const message = formatCliError(err)
|
|
387
|
+
console.error(message)
|
|
388
|
+
if (argv.includes("--json") || argv.includes("--json=true"))
|
|
389
|
+
console.log(JSON.stringify({ ok: false, error: message }, null, 2))
|
|
390
|
+
}
|
|
391
|
+
|
|
369
392
|
async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
370
393
|
if (app.framework.componentPipeline !== undefined) {
|
|
371
394
|
if (flags.bun)
|
|
@@ -430,6 +453,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
430
453
|
app.cwd,
|
|
431
454
|
app.configPath,
|
|
432
455
|
app.framework.define,
|
|
456
|
+
app.framework.publicEnvPrefix,
|
|
433
457
|
)
|
|
434
458
|
// Bun 1.4 on Windows may discard the script-relative portion of argv when `--config` is
|
|
435
459
|
// present. Keep a second, authenticated copy of the user vector in the child's environment so
|
|
@@ -922,6 +946,7 @@ async function buildPrerenderApp(
|
|
|
922
946
|
...(client.routes ? { routePreload: client.routes } : {}),
|
|
923
947
|
...(client.css ? { styles: client.css } : {}),
|
|
924
948
|
...(client.routeStyles ? { routeStyles: client.routeStyles } : {}),
|
|
949
|
+
...(client.copyChunks ? { copyChunks: client.copyChunks } : {}),
|
|
925
950
|
...(client.cssLoading !== undefined ? { cssLoading: client.cssLoading } : {}),
|
|
926
951
|
})
|
|
927
952
|
}
|
|
@@ -931,6 +956,7 @@ interface BuiltManifest {
|
|
|
931
956
|
readonly routes?: Readonly<Record<string, readonly string[]>>
|
|
932
957
|
readonly css?: readonly string[]
|
|
933
958
|
readonly routeStyles?: Readonly<Record<string, readonly string[]>>
|
|
959
|
+
readonly copyChunks?: Readonly<Record<string, string>>
|
|
934
960
|
readonly cssLoading?: CssLoadingMode
|
|
935
961
|
}
|
|
936
962
|
|
|
@@ -954,35 +980,73 @@ async function start(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
954
980
|
await import(serverFile)
|
|
955
981
|
}
|
|
956
982
|
|
|
983
|
+
const VALUE_FLAGS: Readonly<Record<string, "port" | "out" | "target">> = {
|
|
984
|
+
"--port": "port",
|
|
985
|
+
"-p": "port",
|
|
986
|
+
"--out": "out",
|
|
987
|
+
"--target": "target",
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
type SwitchField = "poll" | "report" | "vite" | "bun" | "allowDuplicateIdentity" | "noIndicator"
|
|
991
|
+
|
|
992
|
+
const SWITCH_FLAGS: Readonly<Record<string, SwitchField>> = {
|
|
993
|
+
"--poll": "poll",
|
|
994
|
+
"--report": "report",
|
|
995
|
+
"--vite": "vite",
|
|
996
|
+
"--bun": "bun",
|
|
997
|
+
"--allow-duplicate-identity": "allowDuplicateIdentity",
|
|
998
|
+
"--no-indicator": "noIndicator",
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/** The flags of `nifra dev`, `build` and `start`, as `--flag value` or `--flag=value`. Anything else is
|
|
1002
|
+
* refused: an ignored `--target=vercel` would build the default target and exit 0. */
|
|
957
1003
|
export function parseFlags(args: readonly string[]): Flags {
|
|
958
1004
|
// Port precedence: `--port`/`-p` (most specific) > `PORT` env > the framework default. The default is
|
|
959
1005
|
// the SAME uncommon port for `nifra dev` and `nifra start` (DEFAULT_DEV_PORT) so a project's URL is
|
|
960
1006
|
// stable across commands and doesn't collide with the usual 3000/5173/8080 crowd.
|
|
961
1007
|
let port = Number(Bun.env.PORT ?? DEFAULT_DEV_PORT)
|
|
962
1008
|
let out: string | undefined
|
|
963
|
-
let poll = Bun.env.CHOKIDAR_USEPOLLING === "1"
|
|
964
1009
|
let target: string | undefined
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1010
|
+
const switches: Record<SwitchField, boolean> = {
|
|
1011
|
+
poll: Bun.env.CHOKIDAR_USEPOLLING === "1",
|
|
1012
|
+
report: false,
|
|
1013
|
+
vite: false,
|
|
1014
|
+
bun: false,
|
|
1015
|
+
allowDuplicateIdentity: false,
|
|
1016
|
+
noIndicator: false,
|
|
1017
|
+
}
|
|
970
1018
|
for (let i = 0; i < args.length; i++) {
|
|
971
|
-
const
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1019
|
+
const arg = args[i] as string
|
|
1020
|
+
const equals = arg.startsWith("--") ? arg.indexOf("=") : -1
|
|
1021
|
+
const name = equals === -1 ? arg : arg.slice(0, equals)
|
|
1022
|
+
const valueField = Object.hasOwn(VALUE_FLAGS, name) ? VALUE_FLAGS[name] : undefined
|
|
1023
|
+
if (valueField !== undefined) {
|
|
1024
|
+
const value = equals === -1 ? args[++i] : arg.slice(equals + 1)
|
|
1025
|
+
if (value === undefined || value === "" || (equals === -1 && value.startsWith("-")))
|
|
1026
|
+
throw new Error(`[nifra] ${name} needs a value`)
|
|
1027
|
+
if (valueField === "port") port = Number(value)
|
|
1028
|
+
else if (valueField === "out") out = value
|
|
1029
|
+
else target = value
|
|
1030
|
+
continue
|
|
1031
|
+
}
|
|
1032
|
+
const switchField = Object.hasOwn(SWITCH_FLAGS, name) ? SWITCH_FLAGS[name] : undefined
|
|
1033
|
+
if (switchField !== undefined) {
|
|
1034
|
+
const value = equals === -1 ? "true" : arg.slice(equals + 1)
|
|
1035
|
+
if (value !== "true" && value !== "false")
|
|
1036
|
+
throw new Error(`[nifra] ${name} takes no value (or =true / =false)`)
|
|
1037
|
+
switches[switchField] = value === "true"
|
|
1038
|
+
continue
|
|
1039
|
+
}
|
|
1040
|
+
throw new Error(
|
|
1041
|
+
arg.startsWith("-")
|
|
1042
|
+
? `[nifra] unknown option: ${arg} - see \`nifra help\``
|
|
1043
|
+
: `[nifra] unexpected argument: ${arg} - see \`nifra help\``,
|
|
1044
|
+
)
|
|
981
1045
|
}
|
|
982
1046
|
if (!Number.isFinite(port) || port < 0 || port > 65535) {
|
|
983
1047
|
throw new Error(`[nifra] invalid --port: ${port}`)
|
|
984
1048
|
}
|
|
985
|
-
return { port, out,
|
|
1049
|
+
return { port, out, target, ...switches }
|
|
986
1050
|
}
|
|
987
1051
|
|
|
988
1052
|
/**
|
|
@@ -1190,7 +1254,7 @@ async function main(): Promise<void> {
|
|
|
1190
1254
|
// A thrown error is nifra's own reporting path, not a silent abort: clear the sentinel so the
|
|
1191
1255
|
// hint stays reserved for the case where the process died inside the app import.
|
|
1192
1256
|
markReflecting(undefined)
|
|
1193
|
-
|
|
1257
|
+
reportFailure(err, argv)
|
|
1194
1258
|
const candidate =
|
|
1195
1259
|
typeof err === "object" && err !== null && "exitCode" in err
|
|
1196
1260
|
? (err as { readonly exitCode?: unknown }).exitCode
|
|
@@ -1253,6 +1317,7 @@ async function main(): Promise<void> {
|
|
|
1253
1317
|
console.error(formatCliError(err))
|
|
1254
1318
|
process.exitCode = 1
|
|
1255
1319
|
}
|
|
1320
|
+
exitIfHeldOpen(command)
|
|
1256
1321
|
return
|
|
1257
1322
|
}
|
|
1258
1323
|
// `upgrade` is a pure cwd file-transformer (package.json pins + import moves) driven by a per-release
|
|
@@ -1270,14 +1335,16 @@ async function main(): Promise<void> {
|
|
|
1270
1335
|
verify: !argv.includes("--no-verify"),
|
|
1271
1336
|
hooks: !argv.includes("--no-hooks"),
|
|
1272
1337
|
allowDowngrade: argv.includes("--allow-downgrade"),
|
|
1338
|
+
allowLinkedSkew: argv.includes("--allow-linked-skew"),
|
|
1273
1339
|
exact: argv.includes("--exact"),
|
|
1274
1340
|
cliVersion: CLI_VERSION,
|
|
1275
1341
|
})
|
|
1276
1342
|
if (!ok) process.exitCode = 1
|
|
1277
1343
|
} catch (err) {
|
|
1278
|
-
|
|
1344
|
+
reportFailure(err, argv)
|
|
1279
1345
|
process.exitCode = 1
|
|
1280
1346
|
}
|
|
1347
|
+
exitIfHeldOpen(command)
|
|
1281
1348
|
return
|
|
1282
1349
|
}
|
|
1283
1350
|
// `port` is a pure cwd-based portability linter (scans source, doesn't run the app) - like `check`/
|
|
@@ -1288,17 +1355,32 @@ async function main(): Promise<void> {
|
|
|
1288
1355
|
process.exitCode = 1
|
|
1289
1356
|
return
|
|
1290
1357
|
}
|
|
1358
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
1359
|
+
console.log(HELP)
|
|
1360
|
+
return
|
|
1361
|
+
}
|
|
1291
1362
|
const flags = parseFlags(argv.slice(1))
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1363
|
+
try {
|
|
1364
|
+
const app = await loadApp(process.cwd(), flags.out)
|
|
1365
|
+
if (command !== "start" && process.env.NIFRA_BUN_DEV_TOKEN === undefined) {
|
|
1366
|
+
const { unservedRoutesWarning } = await import("./introspect.ts")
|
|
1367
|
+
const unserved = unservedRoutesWarning(app)
|
|
1368
|
+
if (unserved !== undefined) console.warn(unserved)
|
|
1369
|
+
}
|
|
1370
|
+
if (command !== "start") {
|
|
1371
|
+
const { refreshRouteTypes, watchRouteTypes } = await import("./route-types.ts")
|
|
1372
|
+
refreshRouteTypes(app.cwd)
|
|
1373
|
+
// A relaunched `nifra dev --bun` child runs beside its parent, which already watches.
|
|
1374
|
+
if (command === "dev" && process.env.NIFRA_BUN_DEV_TOKEN === undefined)
|
|
1375
|
+
watchRouteTypes(app.cwd)
|
|
1376
|
+
}
|
|
1377
|
+
if (command === "dev") await dev(app, flags)
|
|
1378
|
+
else if (command === "build") await buildForTarget(app, flags.target, flags)
|
|
1379
|
+
else await start(app, flags)
|
|
1380
|
+
} finally {
|
|
1381
|
+
// `dev` and `start` keep serving after they return; a build is over.
|
|
1382
|
+
if (command === "build") exitIfHeldOpen(command)
|
|
1298
1383
|
}
|
|
1299
|
-
if (command === "dev") await dev(app, flags)
|
|
1300
|
-
else if (command === "build") await buildForTarget(app, flags.target, flags)
|
|
1301
|
-
else await start(app, flags)
|
|
1302
1384
|
}
|
|
1303
1385
|
|
|
1304
1386
|
/**
|
|
@@ -1485,7 +1567,7 @@ if (isMainModule() || isBunDevReexecChild() || hasCliCommandToken()) {
|
|
|
1485
1567
|
try {
|
|
1486
1568
|
await main()
|
|
1487
1569
|
} catch (err) {
|
|
1488
|
-
|
|
1570
|
+
reportFailure(err, cliArgv())
|
|
1489
1571
|
process.exitCode = 1
|
|
1490
1572
|
}
|
|
1491
1573
|
}
|
package/src/client-module.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { existsSync, readFileSync } from "node:fs"
|
|
6
6
|
import { join } from "node:path"
|
|
7
|
+
import type * as TS from "typescript"
|
|
7
8
|
import { CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
|
|
8
9
|
import { stripComments } from "./check-scan.ts"
|
|
10
|
+
import { configPathReader, exportedInitializer } from "./internal/config-paths.ts"
|
|
9
11
|
import type { SpecifierResolver } from "./internal/project-specifiers.ts"
|
|
10
12
|
|
|
11
13
|
const CLIENT_MODULE_EXPORT =
|
|
@@ -34,28 +36,62 @@ export function appDirs(files: readonly string[]): string[] {
|
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* The file `clientModule` names in `app`, read the way the loader reads it: from `nifra.config.ts`
|
|
37
|
-
* when it exists, else `backend/framework.ts
|
|
38
|
-
*
|
|
39
|
+
* when it exists, else `backend/framework.ts`; a string against the app root, and, with `ts`, a
|
|
40
|
+
* `resolve`/`join` of the config's own folder against that folder. `undefined` for a package
|
|
41
|
+
* specifier, a value built any other way, or a path to no file.
|
|
39
42
|
*/
|
|
40
43
|
export function clientModuleRoot(
|
|
41
44
|
root: string,
|
|
42
45
|
app: string,
|
|
43
46
|
resolve: SpecifierResolver,
|
|
47
|
+
ts?: typeof TS,
|
|
44
48
|
): ClientModuleRoot | undefined {
|
|
45
49
|
const config = existsSync(join(root, app, CONFIG_FILE)) ? CONFIG_FILE : FRAMEWORK_FILE
|
|
46
50
|
const path = join(root, app, config)
|
|
47
51
|
if (!existsSync(path)) return undefined
|
|
48
52
|
const text = readFileSync(path, "utf8")
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const found = ts === undefined ? literalClientModule(text) : staticClientModule(ts, path, text)
|
|
54
|
+
if (found === undefined) return undefined
|
|
55
|
+
const file =
|
|
56
|
+
found.base === "app"
|
|
57
|
+
? resolve(join(root, app, CONFIG_FILE), found.specifier)
|
|
58
|
+
: resolve(path, found.specifier.startsWith("../") ? found.specifier : `./${found.specifier}`)
|
|
54
59
|
if (file === undefined) return undefined
|
|
55
60
|
return {
|
|
56
61
|
config: app === "" ? config : `${app}/${config}`,
|
|
57
|
-
line: text.slice(0,
|
|
58
|
-
specifier,
|
|
62
|
+
line: text.slice(0, found.index).split("\n").length,
|
|
63
|
+
specifier: found.specifier,
|
|
59
64
|
file,
|
|
60
65
|
}
|
|
61
66
|
}
|
|
67
|
+
|
|
68
|
+
interface FoundClientModule {
|
|
69
|
+
readonly base: "app" | "config"
|
|
70
|
+
readonly specifier: string
|
|
71
|
+
readonly index: number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function literalClientModule(text: string): FoundClientModule | undefined {
|
|
75
|
+
// `stripComments` keeps offsets, so the match index is a position in `text`.
|
|
76
|
+
const match = CLIENT_MODULE_EXPORT.exec(stripComments(text))
|
|
77
|
+
if (match === null) return undefined
|
|
78
|
+
return { base: "app", specifier: match[1] ?? match[2] ?? "", index: match.index }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function staticClientModule(
|
|
82
|
+
ts: typeof TS,
|
|
83
|
+
path: string,
|
|
84
|
+
text: string,
|
|
85
|
+
): FoundClientModule | undefined {
|
|
86
|
+
let sf: TS.SourceFile
|
|
87
|
+
try {
|
|
88
|
+
sf = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
|
|
89
|
+
} catch {
|
|
90
|
+
// TypeScript 7 parses only what its session preloaded; the literal form still reads.
|
|
91
|
+
return literalClientModule(text)
|
|
92
|
+
}
|
|
93
|
+
const initializer = exportedInitializer(ts, sf, "clientModule")
|
|
94
|
+
const found = configPathReader(ts, sf)(initializer)
|
|
95
|
+
if (initializer === undefined || found === undefined) return undefined
|
|
96
|
+
return { base: found.base, specifier: found.path, index: initializer.getStart(sf) }
|
|
97
|
+
}
|