@nifrajs/cli 5.8.0 → 5.10.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 +191 -0
- package/dist/agent-files.d.ts +0 -22
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +3 -1
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +2 -10
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +3 -3
- package/dist/assure.js.map +1 -1
- package/dist/check-diagnostics.d.ts +1 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +3 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +62 -87
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +3 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +27 -25
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +53 -20
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +1 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -49
- package/dist/command-catalog.js.map +1 -1
- package/dist/config-target.js +1 -1
- package/dist/config-target.js.map +1 -1
- package/dist/db-child.js +3 -10
- package/dist/db-child.js.map +1 -1
- package/dist/db-config.d.ts +2 -0
- package/dist/db-config.d.ts.map +1 -1
- package/dist/db-config.js +2 -0
- package/dist/db-config.js.map +1 -1
- package/dist/doctor.d.ts +14 -3
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +91 -6
- package/dist/doctor.js.map +1 -1
- package/dist/frontend-guidance.d.ts +19 -0
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +267 -23
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/hand-built-manifest.d.ts.map +1 -1
- package/dist/hand-built-manifest.js +1 -1
- package/dist/hand-built-manifest.js.map +1 -1
- package/dist/internal/control-character.d.ts +3 -0
- package/dist/internal/control-character.d.ts.map +1 -0
- package/dist/internal/control-character.js +10 -0
- package/dist/internal/control-character.js.map +1 -0
- package/dist/internal/escape-regexp.d.ts +3 -0
- package/dist/internal/escape-regexp.d.ts.map +1 -0
- package/dist/internal/escape-regexp.js +5 -0
- package/dist/internal/escape-regexp.js.map +1 -0
- package/dist/internal/line-at.d.ts +3 -0
- package/dist/internal/line-at.d.ts.map +1 -0
- package/dist/internal/line-at.js +5 -0
- package/dist/internal/line-at.js.map +1 -0
- package/dist/internal/nifra-project.d.ts.map +1 -1
- package/dist/internal/nifra-project.js +35 -41
- package/dist/internal/nifra-project.js.map +1 -1
- package/dist/internal/posix-path.d.ts +3 -0
- package/dist/internal/posix-path.d.ts.map +1 -0
- package/dist/internal/posix-path.js +5 -0
- package/dist/internal/posix-path.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +3 -10
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/realpath-or-self.d.ts +3 -0
- package/dist/internal/realpath-or-self.d.ts.map +1 -0
- package/dist/internal/realpath-or-self.js +11 -0
- package/dist/internal/realpath-or-self.js.map +1 -0
- package/dist/internal/record.d.ts +3 -0
- package/dist/internal/record.d.ts.map +1 -0
- package/dist/internal/record.js +5 -0
- package/dist/internal/record.js.map +1 -0
- package/dist/internal/source-facts.d.ts +30 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +155 -25
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.d.ts +0 -22
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +11 -151
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts +2 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +54 -64
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +8 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +5 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +7 -0
- package/dist/local-cli.d.ts.map +1 -1
- package/dist/local-cli.js +13 -0
- package/dist/local-cli.js.map +1 -1
- package/dist/mcp-docs-tools.d.ts +1 -1
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +46 -3
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-http.d.ts +1 -1
- package/dist/mcp-http.js +2 -2
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-io.d.ts +16 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +63 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-project-child.d.ts.map +1 -1
- package/dist/mcp-project-child.js +5 -12
- package/dist/mcp-project-child.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +9 -51
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.js +1 -1
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +3 -46
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp-tool-meta.d.ts.map +1 -1
- package/dist/mcp-tool-meta.js +0 -1
- package/dist/mcp-tool-meta.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +2 -18
- package/dist/mcp-ws.js.map +1 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +36 -57
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +7 -7
- package/dist/output-schemas.js.map +1 -1
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +1 -2
- package/dist/port.js.map +1 -1
- package/dist/ppr-read-fix.js +2 -2
- package/dist/ppr-read-fix.js.map +1 -1
- package/dist/recipes/5.10.0.d.ts +12 -0
- package/dist/recipes/5.10.0.d.ts.map +1 -0
- package/dist/recipes/5.10.0.js +44 -0
- package/dist/recipes/5.10.0.js.map +1 -0
- package/dist/recipes/5.9.0.d.ts +10 -0
- package/dist/recipes/5.9.0.d.ts.map +1 -0
- package/dist/recipes/5.9.0.js +41 -0
- package/dist/recipes/5.9.0.js.map +1 -0
- package/dist/recipes/index.d.ts +5 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +12 -13
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +3 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +3 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +3 -9
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +3 -10
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +15 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/internal-links.d.ts +5 -0
- package/dist/rules/internal-links.d.ts.map +1 -0
- package/dist/rules/internal-links.js +418 -0
- package/dist/rules/internal-links.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +20 -0
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +41 -58
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +20 -27
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +206 -313
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/server-fn-namespace.d.ts +8 -0
- package/dist/rules/server-fn-namespace.d.ts.map +1 -0
- package/dist/rules/server-fn-namespace.js +43 -0
- package/dist/rules/server-fn-namespace.js.map +1 -0
- package/dist/rules/source-scan.d.ts +29 -0
- package/dist/rules/source-scan.d.ts.map +1 -0
- package/dist/rules/source-scan.js +38 -0
- package/dist/rules/source-scan.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -1
- package/dist/rules/text-slot-boolean.js +21 -43
- package/dist/rules/text-slot-boolean.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -10
- package/dist/rules/zones.js.map +1 -1
- package/dist/runtime-differences.d.ts +62 -0
- package/dist/runtime-differences.d.ts.map +1 -0
- package/dist/runtime-differences.js +222 -0
- package/dist/runtime-differences.js.map +1 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +43 -43
- package/dist/sdk.js.map +1 -1
- package/dist/smoke.d.ts.map +1 -1
- package/dist/smoke.js +4 -12
- package/dist/smoke.js.map +1 -1
- package/dist/source-rewrites.d.ts +27 -0
- package/dist/source-rewrites.d.ts.map +1 -0
- package/dist/source-rewrites.js +517 -0
- package/dist/source-rewrites.js.map +1 -0
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +1 -1
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/symptom-search.d.ts +5 -0
- package/dist/symptom-search.d.ts.map +1 -0
- package/dist/symptom-search.js +21 -0
- package/dist/symptom-search.js.map +1 -0
- package/dist/typecheck-coverage.d.ts +9 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +16 -0
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +28 -3
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +153 -64
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +5 -3
- package/dist/verification-plan.js.map +1 -1
- package/docs/examples.json +51 -9
- package/docs/llms-full.txt +1296 -287
- package/docs/types.json +854 -170
- package/package.json +11 -11
- package/src/agent-files.ts +4 -1
- package/src/assure-hydration.ts +2 -9
- package/src/assure.ts +3 -4
- package/src/check-diagnostics.ts +5 -0
- package/src/check-scan.ts +74 -83
- package/src/check.ts +40 -26
- package/src/cli.ts +76 -20
- package/src/command-catalog.ts +22 -56
- package/src/config-target.ts +1 -1
- package/src/db-child.ts +3 -10
- package/src/db-config.ts +4 -0
- package/src/doctor.ts +128 -12
- package/src/frontend-guidance.ts +344 -25
- package/src/hand-built-manifest.ts +1 -2
- package/src/internal/control-character.ts +8 -0
- package/src/internal/escape-regexp.ts +4 -0
- package/src/internal/line-at.ts +4 -0
- package/src/internal/nifra-project.ts +39 -35
- package/src/internal/posix-path.ts +4 -0
- package/src/internal/project-specifiers.ts +3 -10
- package/src/internal/realpath-or-self.ts +10 -0
- package/src/internal/record.ts +4 -0
- package/src/internal/source-facts.ts +194 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +15 -1
- package/src/local-cli.ts +12 -0
- package/src/mcp-docs-tools.ts +51 -3
- package/src/mcp-http.ts +2 -2
- package/src/mcp-io.ts +77 -0
- package/src/mcp-isolate.ts +2 -3
- package/src/mcp-project-child.ts +5 -14
- package/src/mcp-render.ts +11 -59
- package/src/mcp-root.ts +1 -1
- package/src/mcp-run.ts +5 -54
- package/src/mcp-tool-meta.ts +0 -1
- package/src/mcp-ws.ts +2 -19
- package/src/migrate-layout.ts +52 -72
- package/src/output-schemas.ts +7 -8
- package/src/port.ts +1 -4
- package/src/ppr-read-fix.ts +2 -2
- package/src/recipes/5.10.0.ts +45 -0
- package/src/recipes/5.9.0.ts +42 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +15 -15
- package/src/rules/codes.ts +3 -0
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/explanations.ts +15 -0
- package/src/rules/internal-links.ts +490 -0
- package/src/rules/legacy.ts +21 -0
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- package/src/rules/server-fn-namespace.ts +47 -0
- package/src/rules/source-scan.ts +66 -0
- package/src/rules/text-slot-boolean.ts +26 -42
- package/src/rules/zones.ts +3 -10
- package/src/runtime-differences.ts +302 -0
- package/src/sdk.ts +55 -58
- package/src/smoke.ts +4 -13
- package/src/source-rewrites.ts +592 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/typecheck-coverage.ts +23 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
- package/dist/sync-routes.d.ts +0 -29
- package/dist/sync-routes.d.ts.map +0 -1
- package/dist/sync-routes.js +0 -56
- package/dist/sync-routes.js.map +0 -1
- package/src/sync-routes.ts +0 -70
package/src/upgrade.ts
CHANGED
|
@@ -26,8 +26,10 @@
|
|
|
26
26
|
* Dry-run by default (prints the plan, writes nothing); `--write` applies. Fail-closed on an unknown
|
|
27
27
|
* target version or a missing package.json, and deterministic (same repo + target → same edits).
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Transforms are string/specifier-level, except a recipe's `sourceRewrites`: syntax-tree edits made
|
|
30
|
+
* with the project's own TypeScript (`source-rewrites.ts`), each rewriting only a shape it recognizes
|
|
31
|
+
* whole and listing every other site to edit by hand. Without TypeScript such an upgrade refuses to
|
|
32
|
+
* run rather than leave the rewrite undone: after its pins land, no later upgrade would run it.
|
|
31
33
|
*/
|
|
32
34
|
|
|
33
35
|
import {
|
|
@@ -54,7 +56,10 @@ import {
|
|
|
54
56
|
} from "./hooks-report.ts"
|
|
55
57
|
import { type AncestorPinSite, ancestorPins, declaresCli, PIN_SITES } from "./init-agents.ts"
|
|
56
58
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
59
|
+
import { escapeRegExp } from "./internal/escape-regexp.ts"
|
|
57
60
|
import { gitIgnoredSync } from "./internal/git-ignored.ts"
|
|
61
|
+
import type { TypeScriptApi } from "./internal/typescript-import.ts"
|
|
62
|
+
import { otherProjectCore } from "./local-cli.ts"
|
|
58
63
|
import {
|
|
59
64
|
BUN_LOCK,
|
|
60
65
|
describeChange,
|
|
@@ -69,6 +74,7 @@ import {
|
|
|
69
74
|
type UpgradeRecipe,
|
|
70
75
|
} from "./recipes/index.ts"
|
|
71
76
|
import { markerTarget } from "./rules/comment-markers.ts"
|
|
77
|
+
import { getSourceRewrite } from "./source-rewrites.ts"
|
|
72
78
|
|
|
73
79
|
export interface UpgradeOptions {
|
|
74
80
|
/** Target version, e.g. "1.8.0". Required unless `list` is set. */
|
|
@@ -88,6 +94,8 @@ export interface UpgradeOptions {
|
|
|
88
94
|
readonly exact?: boolean
|
|
89
95
|
/** The running CLI's version: the newest target it applies. Default: its newest recipe. */
|
|
90
96
|
readonly cliVersion?: string
|
|
97
|
+
/** The compiler a recipe's source rewrites parse with. Default: the project's, else the CLI's own. */
|
|
98
|
+
readonly loadTypeScript?: () => Promise<TypeScriptApi | undefined>
|
|
91
99
|
/**
|
|
92
100
|
* With `--write`, capture `nifra routes --hooks` before and after the edits and print the diff, so a
|
|
93
101
|
* change in which hooks run where is visible. Loads the backend. Default true; `--no-hooks` skips it.
|
|
@@ -153,6 +161,20 @@ export interface RetiredMarkerSite {
|
|
|
153
161
|
readonly instead: string
|
|
154
162
|
}
|
|
155
163
|
|
|
164
|
+
/** A source file a recipe's syntax-tree rewrite changed. */
|
|
165
|
+
export interface SourceRewriteChange {
|
|
166
|
+
readonly file: string
|
|
167
|
+
readonly rewrite: string
|
|
168
|
+
readonly count: number
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** A site a rewrite found and left alone, with what to write instead. */
|
|
172
|
+
export interface ManualRewriteSite {
|
|
173
|
+
readonly file: string
|
|
174
|
+
readonly line: number
|
|
175
|
+
readonly reason: string
|
|
176
|
+
}
|
|
177
|
+
|
|
156
178
|
export interface UpgradePlan {
|
|
157
179
|
readonly version: string
|
|
158
180
|
readonly pins: readonly PinChange[]
|
|
@@ -164,6 +186,10 @@ export interface UpgradePlan {
|
|
|
164
186
|
readonly downgrades: readonly PinChange[]
|
|
165
187
|
/** Comments a release in the chain stopped honoring. Listed only, never rewritten. */
|
|
166
188
|
readonly retiredMarkers: readonly RetiredMarkerSite[]
|
|
189
|
+
readonly sourceRewrites: readonly SourceRewriteChange[]
|
|
190
|
+
readonly manualRewrites: readonly ManualRewriteSite[]
|
|
191
|
+
/** Files a rewrite must read that no TypeScript was given to parse. The upgrade refuses while any is listed. */
|
|
192
|
+
readonly rewritesNeedTypeScript: readonly string[]
|
|
167
193
|
/** Installed group packages linked from outside the workspace root, at another version. Never edited. */
|
|
168
194
|
readonly linkedOutside: readonly LinkedGroupInstall[]
|
|
169
195
|
/** Repositories a `link:`/`file:` dependency points outside the root, each loading its own nifra at
|
|
@@ -326,8 +352,6 @@ export function specIncludes(spec: string, version: string): boolean {
|
|
|
326
352
|
}
|
|
327
353
|
}
|
|
328
354
|
|
|
329
|
-
const escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
330
|
-
|
|
331
355
|
/**
|
|
332
356
|
* Apply pin rules to one package.json's TEXT (format-preserving - targeted string replaces, never a
|
|
333
357
|
* JSON re-serialize that would reorder keys or drop comments-as-formatting). Returns the new text and
|
|
@@ -1307,6 +1331,7 @@ export function chainRecipes(target: string, installed: string | null): ChainedR
|
|
|
1307
1331
|
importMoves: recipes.flatMap((recipe) => recipe.importMoves),
|
|
1308
1332
|
dependencyAdds: recipes.flatMap((recipe) => recipe.dependencyAdds ?? []),
|
|
1309
1333
|
retiredMarkers: recipes.flatMap((recipe) => recipe.retiredMarkers ?? []),
|
|
1334
|
+
sourceRewrites: [...new Set(recipes.flatMap((recipe) => recipe.sourceRewrites ?? []))],
|
|
1310
1335
|
notes: recipes.flatMap((recipe) =>
|
|
1311
1336
|
(recipe.notes ?? []).map((note) => `${recipe.version}: ${note}`),
|
|
1312
1337
|
),
|
|
@@ -1321,6 +1346,7 @@ export function computeUpgrade(
|
|
|
1321
1346
|
allowDowngrade = false,
|
|
1322
1347
|
exact = false,
|
|
1323
1348
|
above: readonly AncestorPinSite[] = [],
|
|
1349
|
+
compiler?: TypeScriptApi,
|
|
1324
1350
|
): UpgradePlan {
|
|
1325
1351
|
const pins: PinChange[] = []
|
|
1326
1352
|
const agentPins: AgentPinChange[] = []
|
|
@@ -1371,6 +1397,33 @@ export function computeUpgrade(
|
|
|
1371
1397
|
}
|
|
1372
1398
|
}
|
|
1373
1399
|
|
|
1400
|
+
// Each rewrite reads a source as the import moves (and the rewrites before it) leave it.
|
|
1401
|
+
const sourceRewrites: SourceRewriteChange[] = []
|
|
1402
|
+
const manualRewrites: ManualRewriteSite[] = []
|
|
1403
|
+
const rewritesNeedTypeScript: string[] = []
|
|
1404
|
+
const rewrites = (recipe.sourceRewrites ?? []).flatMap((id) => getSourceRewrite(id) ?? [])
|
|
1405
|
+
if (rewrites.length > 0) {
|
|
1406
|
+
for (const rel of scan(cwd, SOURCE_GLOB)) {
|
|
1407
|
+
const original = movedSources.get(rel) ?? readFileSync(join(cwd, rel), "utf8")
|
|
1408
|
+
let text = original
|
|
1409
|
+
for (const rewrite of rewrites) {
|
|
1410
|
+
if (!rewrite.mentions(text)) continue
|
|
1411
|
+
if (compiler === undefined) {
|
|
1412
|
+
if (!rewritesNeedTypeScript.includes(rel)) rewritesNeedTypeScript.push(rel)
|
|
1413
|
+
continue
|
|
1414
|
+
}
|
|
1415
|
+
const result = rewrite.rewrite(compiler, rel, text)
|
|
1416
|
+
text = result.text
|
|
1417
|
+
if (result.count > 0)
|
|
1418
|
+
sourceRewrites.push({ file: rel, rewrite: rewrite.id, count: result.count })
|
|
1419
|
+
for (const site of result.manual) manualRewrites.push({ file: rel, ...site })
|
|
1420
|
+
}
|
|
1421
|
+
if (text === original) continue
|
|
1422
|
+
movedSources.set(rel, text)
|
|
1423
|
+
if (write) writeFileSync(join(cwd, rel), text)
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1374
1427
|
// Read the sources as the import moves leave them, and each manifest as the pins left it.
|
|
1375
1428
|
const adds = recipe.dependencyAdds ?? []
|
|
1376
1429
|
if (adds.length > 0) {
|
|
@@ -1423,6 +1476,9 @@ export function computeUpgrade(
|
|
|
1423
1476
|
dependencyAdds,
|
|
1424
1477
|
downgrades,
|
|
1425
1478
|
retiredMarkers,
|
|
1479
|
+
sourceRewrites,
|
|
1480
|
+
manualRewrites,
|
|
1481
|
+
rewritesNeedTypeScript,
|
|
1426
1482
|
linkedOutside,
|
|
1427
1483
|
linkedSkew: linkedSkew(cwd, recipe.version),
|
|
1428
1484
|
strayPins: strayPins(cwd, recipe.version, planned),
|
|
@@ -1460,6 +1516,9 @@ function renderPlan(
|
|
|
1460
1516
|
plan.importMoves.length === 0 &&
|
|
1461
1517
|
plan.dependencyAdds.length === 0 &&
|
|
1462
1518
|
plan.retiredMarkers.length === 0 &&
|
|
1519
|
+
plan.sourceRewrites.length === 0 &&
|
|
1520
|
+
plan.manualRewrites.length === 0 &&
|
|
1521
|
+
plan.rewritesNeedTypeScript.length === 0 &&
|
|
1463
1522
|
plan.linkedOutside.length === 0 &&
|
|
1464
1523
|
plan.linkedSkew.length === 0 &&
|
|
1465
1524
|
plan.strayPins.length === 0 &&
|
|
@@ -1497,6 +1556,22 @@ function renderPlan(
|
|
|
1497
1556
|
for (const m of plan.importMoves) lines.push(` ${m.file} ${m.from} → ${m.to} (${m.count})`)
|
|
1498
1557
|
lines.push("")
|
|
1499
1558
|
}
|
|
1559
|
+
if (plan.sourceRewrites.length > 0) {
|
|
1560
|
+
const total = plan.sourceRewrites.reduce((n, r) => n + r.count, 0)
|
|
1561
|
+
lines.push(`${verb} ${total} source rewrite(s) across ${plan.sourceRewrites.length} file(s):`)
|
|
1562
|
+
for (const r of plan.sourceRewrites) {
|
|
1563
|
+
lines.push(
|
|
1564
|
+
` ${r.file} ${getSourceRewrite(r.rewrite)?.description ?? r.rewrite} (${r.count})`,
|
|
1565
|
+
)
|
|
1566
|
+
}
|
|
1567
|
+
lines.push("")
|
|
1568
|
+
}
|
|
1569
|
+
if (plan.manualRewrites.length > 0) {
|
|
1570
|
+
lines.push(`${plan.manualRewrites.length} site(s) to edit by hand:`)
|
|
1571
|
+
for (const site of plan.manualRewrites)
|
|
1572
|
+
lines.push(` ${site.file}:${site.line} ${site.reason}`)
|
|
1573
|
+
lines.push("")
|
|
1574
|
+
}
|
|
1500
1575
|
if (plan.dependencyAdds.length > 0) {
|
|
1501
1576
|
lines.push(`${verb} ${plan.dependencyAdds.length} dependency addition(s):`)
|
|
1502
1577
|
for (const add of plan.dependencyAdds) {
|
|
@@ -1617,6 +1692,8 @@ export type UpgradeHookScope =
|
|
|
1617
1692
|
| { readonly saved: string; readonly changes: readonly HookReportChange[] }
|
|
1618
1693
|
| { readonly saved: string; readonly pending: "install" }
|
|
1619
1694
|
| { readonly error: string; readonly saved?: string }
|
|
1695
|
+
/** This CLI runs another `@nifrajs/core` than the project, whose app it cannot reflect. */
|
|
1696
|
+
| { readonly skipped: "other-core" }
|
|
1620
1697
|
|
|
1621
1698
|
/** The edits `--write` made that the installed packages do not reflect yet. */
|
|
1622
1699
|
export interface PendingInstall {
|
|
@@ -1718,6 +1795,9 @@ function renderHookScope(scope: UpgradeHookScope): string {
|
|
|
1718
1795
|
"The new release's hooks run once its packages are installed. After installing, compare against the report saved before the edits:",
|
|
1719
1796
|
` nifra routes --hooks --since ${saved}`,
|
|
1720
1797
|
]
|
|
1798
|
+
if ("skipped" in scope) {
|
|
1799
|
+
return "Hook scope: not compared, since this CLI runs another @nifrajs/core than the project. Once the release is installed, `nifra routes --hooks` shows it."
|
|
1800
|
+
}
|
|
1721
1801
|
if ("error" in scope) {
|
|
1722
1802
|
const head = `Hook scope: not captured (${scope.error}).`
|
|
1723
1803
|
return scope.saved === undefined ? head : [head, ...since(scope.saved)].join("\n")
|
|
@@ -1877,81 +1957,121 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1877
1957
|
|
|
1878
1958
|
// Fail-closed on rollback: a dry pass writes nothing, so we can refuse before any package.json is touched.
|
|
1879
1959
|
const above = (await ancestorPins(cwd)).owned
|
|
1880
|
-
const
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1960
|
+
const loaded =
|
|
1961
|
+
(recipe.sourceRewrites?.length ?? 0) > 0
|
|
1962
|
+
? await (await import("./internal/typescript-import.ts")).loadProjectTypeScript(
|
|
1963
|
+
cwd,
|
|
1964
|
+
options.loadTypeScript,
|
|
1965
|
+
)
|
|
1966
|
+
: undefined
|
|
1967
|
+
try {
|
|
1968
|
+
return await upgradeWith(loaded?.compiler)
|
|
1969
|
+
} finally {
|
|
1970
|
+
await loaded?.session?.close()
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
async function upgradeWith(compiler: TypeScriptApi | undefined): Promise<boolean> {
|
|
1974
|
+
const preview = computeUpgrade(cwd, recipe, false, allowDowngrade, exact, above, compiler)
|
|
1975
|
+
// Refused before anything is written: once the pins land, no later upgrade runs this rewrite.
|
|
1976
|
+
if (preview.rewritesNeedTypeScript.length > 0) {
|
|
1977
|
+
if (options.json) {
|
|
1978
|
+
console.log(
|
|
1979
|
+
JSON.stringify(
|
|
1980
|
+
{ ...preview, from, steps: recipe.steps, write: false, refused: "needs-typescript" },
|
|
1981
|
+
null,
|
|
1982
|
+
2,
|
|
1983
|
+
),
|
|
1984
|
+
)
|
|
1985
|
+
} else {
|
|
1986
|
+
console.error(
|
|
1987
|
+
`nifra upgrade → ${recipe.version} rewrites ${preview.rewritesNeedTypeScript.length} source file(s) on their syntax tree, which needs TypeScript, and neither this project nor the CLI resolves one:\n${preview.rewritesNeedTypeScript.map((file) => ` ${file}`).join("\n")}\nRun \`bun add -d typescript\`, then this upgrade again.`,
|
|
1988
|
+
)
|
|
1989
|
+
}
|
|
1990
|
+
return false
|
|
1892
1991
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1992
|
+
if (preview.downgrades.length > 0) {
|
|
1993
|
+
if (options.json) {
|
|
1994
|
+
console.log(
|
|
1995
|
+
JSON.stringify(
|
|
1996
|
+
{ ...preview, from, steps: recipe.steps, write: false, refused: "downgrade" },
|
|
1997
|
+
null,
|
|
1998
|
+
2,
|
|
1999
|
+
),
|
|
2000
|
+
)
|
|
2001
|
+
} else {
|
|
2002
|
+
console.error(renderDowngradeRefusal(recipe.version, preview.downgrades))
|
|
2003
|
+
}
|
|
2004
|
+
return false
|
|
2005
|
+
}
|
|
2006
|
+
// Refused before anything is written: the linked repository fails at the first merge(), not here.
|
|
2007
|
+
if (preview.linkedSkew.length > 0 && options.allowLinkedSkew !== true) {
|
|
2008
|
+
if (options.json) {
|
|
2009
|
+
console.log(
|
|
2010
|
+
JSON.stringify(
|
|
2011
|
+
{ ...preview, from, steps: recipe.steps, write: false, refused: "linked-skew" },
|
|
2012
|
+
null,
|
|
2013
|
+
2,
|
|
2014
|
+
),
|
|
2015
|
+
)
|
|
2016
|
+
} else {
|
|
2017
|
+
if (!write) console.log(renderPlan(preview, false, from, recipe.steps))
|
|
2018
|
+
console.error(renderLinkedSkew(recipe.version, preview.linkedSkew, cwd, false))
|
|
2019
|
+
}
|
|
2020
|
+
return false
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
const captureHooks = write && options.hooks !== false
|
|
2024
|
+
// A server() the project's copy builds is not one this CLI's copy can reflect, which is the normal
|
|
2025
|
+
// state of an upgrade run from the new release before it is installed.
|
|
2026
|
+
const otherCore = captureHooks && otherProjectCore(cwd) !== undefined
|
|
2027
|
+
const before = captureHooks && !otherCore ? await hookReportBefore(cwd) : undefined
|
|
2028
|
+
const plan = write
|
|
2029
|
+
? computeUpgrade(cwd, recipe, true, allowDowngrade, exact, above, compiler)
|
|
2030
|
+
: preview
|
|
2031
|
+
const pending = write ? pendingInstall(cwd, plan) : undefined
|
|
2032
|
+
const hooks: UpgradeHookScope | undefined = otherCore
|
|
2033
|
+
? { skipped: "other-core" }
|
|
2034
|
+
: before === undefined
|
|
2035
|
+
? undefined
|
|
2036
|
+
: await hookScopeAcross(cwd, before, pending === undefined)
|
|
2037
|
+
|
|
2038
|
+
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
2039
|
+
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
2040
|
+
const verify = write && options.verify !== false && pending === undefined
|
|
2041
|
+
const uncovered = await uncoveredContracts(cwd)
|
|
1897
2042
|
if (options.json) {
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
)
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2043
|
+
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
2044
|
+
const report: Record<string, unknown> = { ...plan, from, steps: recipe.steps, write }
|
|
2045
|
+
if (uncovered.length > 0) report.contractsUncovered = uncovered
|
|
2046
|
+
if (hooks !== undefined) report.hooks = hooks
|
|
2047
|
+
if (pending !== undefined) report.install = pending
|
|
2048
|
+
let ok = true
|
|
2049
|
+
if (verify) {
|
|
2050
|
+
const { collectProjectVerification } = await import("./verification.ts")
|
|
2051
|
+
const verification = await collectProjectVerification(cwd, { lintsOnly: false })
|
|
2052
|
+
const check = await verification.check()
|
|
2053
|
+
report.check = check
|
|
2054
|
+
ok = check.ok
|
|
2055
|
+
}
|
|
2056
|
+
console.log(JSON.stringify(report, null, 2))
|
|
2057
|
+
return ok
|
|
1908
2058
|
}
|
|
1909
|
-
|
|
1910
|
-
|
|
2059
|
+
console.log(renderPlan(plan, write, from, recipe.steps))
|
|
2060
|
+
if (uncovered.length > 0) console.log(uncoveredContractsNote(uncovered))
|
|
2061
|
+
if (plan.linkedSkew.length > 0)
|
|
2062
|
+
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`)
|
|
2063
|
+
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
|
2064
|
+
if (pending !== undefined && options.verify !== false)
|
|
2065
|
+
console.log(`\n${renderPendingInstall(pending, recipe.version)}`)
|
|
1911
2066
|
|
|
1912
|
-
const captureHooks = write && options.hooks !== false
|
|
1913
|
-
const before = captureHooks ? await hookReportBefore(cwd) : undefined
|
|
1914
|
-
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact, above) : preview
|
|
1915
|
-
const pending = write ? pendingInstall(cwd, plan) : undefined
|
|
1916
|
-
const hooks =
|
|
1917
|
-
before === undefined ? undefined : await hookScopeAcross(cwd, before, pending === undefined)
|
|
1918
|
-
|
|
1919
|
-
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
1920
|
-
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
1921
|
-
const verify = write && options.verify !== false && pending === undefined
|
|
1922
|
-
const uncovered = await uncoveredContracts(cwd)
|
|
1923
|
-
if (options.json) {
|
|
1924
|
-
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
1925
|
-
const report: Record<string, unknown> = { ...plan, from, steps: recipe.steps, write }
|
|
1926
|
-
if (uncovered.length > 0) report.contractsUncovered = uncovered
|
|
1927
|
-
if (hooks !== undefined) report.hooks = hooks
|
|
1928
|
-
if (pending !== undefined) report.install = pending
|
|
1929
|
-
let ok = true
|
|
1930
2067
|
if (verify) {
|
|
1931
|
-
const {
|
|
1932
|
-
const
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
console.log(JSON.stringify(report, null, 2))
|
|
1938
|
-
return ok
|
|
1939
|
-
}
|
|
1940
|
-
console.log(renderPlan(plan, write, from, recipe.steps))
|
|
1941
|
-
if (uncovered.length > 0) console.log(uncoveredContractsNote(uncovered))
|
|
1942
|
-
if (plan.linkedSkew.length > 0)
|
|
1943
|
-
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`)
|
|
1944
|
-
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
|
1945
|
-
if (pending !== undefined && options.verify !== false)
|
|
1946
|
-
console.log(`\n${renderPendingInstall(pending, recipe.version)}`)
|
|
1947
|
-
|
|
1948
|
-
if (verify) {
|
|
1949
|
-
const { runCheck } = await import("./check.ts")
|
|
1950
|
-
const ok = await runCheck(cwd, { json: false })
|
|
1951
|
-
if (!ok) {
|
|
1952
|
-
console.error("\n[nifra] upgrade applied but `nifra check` failed - review above.")
|
|
1953
|
-
return false
|
|
2068
|
+
const { runCheck } = await import("./check.ts")
|
|
2069
|
+
const ok = await runCheck(cwd, { json: false })
|
|
2070
|
+
if (!ok) {
|
|
2071
|
+
console.error("\n[nifra] upgrade applied but `nifra check` failed - review above.")
|
|
2072
|
+
return false
|
|
2073
|
+
}
|
|
1954
2074
|
}
|
|
2075
|
+
return true
|
|
1955
2076
|
}
|
|
1956
|
-
return true
|
|
1957
2077
|
}
|
package/src/verification-plan.ts
CHANGED
|
@@ -58,9 +58,14 @@ const GATES = Object.freeze([
|
|
|
58
58
|
"Run `bun run gen:cards` and review the generated package cards.",
|
|
59
59
|
),
|
|
60
60
|
gate(
|
|
61
|
-
"node-outcome-
|
|
61
|
+
"node-outcome-laws",
|
|
62
62
|
[["run", "check:node-outcome"]],
|
|
63
|
-
"Run `bun run
|
|
63
|
+
"Run `bun run check:node-outcome` and fix the Node adapter answer that breaks the printed outcome law.",
|
|
64
|
+
),
|
|
65
|
+
gate(
|
|
66
|
+
"vendored-copies",
|
|
67
|
+
[["run", "check:vendored"]],
|
|
68
|
+
"Edit the source each refused copy names, never the copy, then run `bun run gen:vendored`.",
|
|
64
69
|
),
|
|
65
70
|
gate(
|
|
66
71
|
"sitemap",
|
|
@@ -104,7 +109,7 @@ const GATES = Object.freeze([
|
|
|
104
109
|
gate(
|
|
105
110
|
"corpus",
|
|
106
111
|
[["run", "check:corpus"]],
|
|
107
|
-
"Run `bun run gen:llms`, `bun run gen:api`, and `bun run gen:
|
|
112
|
+
"Run `bun run gen:llms`, `bun run gen:api`, `bun run gen:cards`, and `bun run gen:vendored`, then rerun the corpus gate.",
|
|
108
113
|
),
|
|
109
114
|
gate(
|
|
110
115
|
"core-performance",
|
|
@@ -227,7 +232,8 @@ const DEFAULT_PLAN = Object.freeze([
|
|
|
227
232
|
"docs",
|
|
228
233
|
"api-corpus",
|
|
229
234
|
"cards-corpus",
|
|
230
|
-
"node-outcome-
|
|
235
|
+
"node-outcome-laws",
|
|
236
|
+
"vendored-copies",
|
|
231
237
|
"sitemap",
|
|
232
238
|
"public-boundary",
|
|
233
239
|
"public-manifest",
|
package/dist/sync-routes.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `nifra sync-routes` - regenerate the route-search types (`nifra-routes.d.ts`) from the current `routes/`
|
|
3
|
-
* tree, so `navigate({ to, search })` is typed against each static route's `searchSchema`. It runs
|
|
4
|
-
* `@nifrajs/web`'s `generateRouteSearchTypes` over the discovered routes and writes the `.d.ts` at the
|
|
5
|
-
* project root; include it in your tsconfig's `include`. Because it is regenerated from the route files, a
|
|
6
|
-
* stale navigate search shape becomes a `tsc` error - run it after adding/renaming a route or changing a
|
|
7
|
-
* `searchSchema` (a pure file write, no build). A dynamic route (`:param`/catch-all) is omitted, since its
|
|
8
|
-
* pattern is not a concrete `to`; those keep the loose object form.
|
|
9
|
-
*/
|
|
10
|
-
/** The committed route-types file `sync-routes` writes, so `nifra check` can recognise + drift-check it. */
|
|
11
|
-
export declare const ROUTE_TYPES_FILE = "nifra-routes.d.ts";
|
|
12
|
-
export interface SyncRoutesResult {
|
|
13
|
-
/** The written `.d.ts` (relative to the project root). */
|
|
14
|
-
readonly file: string;
|
|
15
|
-
/** True when the file's content changed and it was rewritten. */
|
|
16
|
-
readonly changed: boolean;
|
|
17
|
-
/** How many static routes got a typed entry. */
|
|
18
|
-
readonly typedRoutes: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Generate the route-search types `.d.ts` from `<cwd>/routes` (the nifra convention). Returns
|
|
22
|
-
* `null` when there is no `routes/` directory (an API-only project - nothing to type). Never loads
|
|
23
|
-
* `backend/framework.ts`: it needs only the route tree, so it works before a build and on a broken
|
|
24
|
-
* framework config.
|
|
25
|
-
*/
|
|
26
|
-
export declare function syncRouteTypes(cwd: string): Promise<SyncRoutesResult | null>;
|
|
27
|
-
/** CLI entry: write/refresh the route-types file and print a one-line summary + the tsconfig reminder. */
|
|
28
|
-
export declare function runSyncRoutes(cwd: string): Promise<boolean>;
|
|
29
|
-
//# sourceMappingURL=sync-routes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-routes.d.ts","sourceRoot":"","sources":["../src/sync-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,4GAA4G;AAC5G,eAAO,MAAM,gBAAgB,sBAAsB,CAAA;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAkBlF;AAED,0GAA0G;AAC1G,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAiBjE"}
|
package/dist/sync-routes.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `nifra sync-routes` - regenerate the route-search types (`nifra-routes.d.ts`) from the current `routes/`
|
|
3
|
-
* tree, so `navigate({ to, search })` is typed against each static route's `searchSchema`. It runs
|
|
4
|
-
* `@nifrajs/web`'s `generateRouteSearchTypes` over the discovered routes and writes the `.d.ts` at the
|
|
5
|
-
* project root; include it in your tsconfig's `include`. Because it is regenerated from the route files, a
|
|
6
|
-
* stale navigate search shape becomes a `tsc` error - run it after adding/renaming a route or changing a
|
|
7
|
-
* `searchSchema` (a pure file write, no build). A dynamic route (`:param`/catch-all) is omitted, since its
|
|
8
|
-
* pattern is not a concrete `to`; those keep the loose object form.
|
|
9
|
-
*/
|
|
10
|
-
import { existsSync } from "node:fs";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
/** The committed route-types file `sync-routes` writes, so `nifra check` can recognise + drift-check it. */
|
|
13
|
-
export const ROUTE_TYPES_FILE = "nifra-routes.d.ts";
|
|
14
|
-
/**
|
|
15
|
-
* Generate the route-search types `.d.ts` from `<cwd>/routes` (the nifra convention). Returns
|
|
16
|
-
* `null` when there is no `routes/` directory (an API-only project - nothing to type). Never loads
|
|
17
|
-
* `backend/framework.ts`: it needs only the route tree, so it works before a build and on a broken
|
|
18
|
-
* framework config.
|
|
19
|
-
*/
|
|
20
|
-
export async function syncRouteTypes(cwd) {
|
|
21
|
-
const routesDir = join(cwd, "routes");
|
|
22
|
-
if (!existsSync(routesDir))
|
|
23
|
-
return null;
|
|
24
|
-
const { discoverRoutes } = await import("@nifrajs/web/fs");
|
|
25
|
-
const { generateRouteSearchTypes } = await import("@nifrajs/web");
|
|
26
|
-
const manifest = discoverRoutes(routesDir);
|
|
27
|
-
const code = generateRouteSearchTypes(manifest, {
|
|
28
|
-
// A route file is relative to routesDir (`reports.tsx`, `users/index.tsx`); the `.d.ts` sits at the
|
|
29
|
-
// project root, so the `typeof import(...)` specifier is `./routes/<file без extension>`.
|
|
30
|
-
resolve: (file) => `./routes/${file.replace(/\.[^./]+$/, "")}`,
|
|
31
|
-
});
|
|
32
|
-
const outFile = join(cwd, ROUTE_TYPES_FILE);
|
|
33
|
-
const existing = await Bun.file(outFile)
|
|
34
|
-
.text()
|
|
35
|
-
.catch(() => "");
|
|
36
|
-
const changed = existing !== code;
|
|
37
|
-
if (changed)
|
|
38
|
-
await Bun.write(outFile, code);
|
|
39
|
-
return { file: ROUTE_TYPES_FILE, changed, typedRoutes: (code.match(/: SearchOf</g) ?? []).length };
|
|
40
|
-
}
|
|
41
|
-
/** CLI entry: write/refresh the route-types file and print a one-line summary + the tsconfig reminder. */
|
|
42
|
-
export async function runSyncRoutes(cwd) {
|
|
43
|
-
const result = await syncRouteTypes(cwd);
|
|
44
|
-
if (result === null) {
|
|
45
|
-
console.log("nifra sync-routes: no routes/ directory found. Run from your project root.");
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
const n = result.typedRoutes;
|
|
49
|
-
const routes = `${n} typed route${n === 1 ? "" : "s"}`;
|
|
50
|
-
console.log(result.changed
|
|
51
|
-
? `✓ wrote ${result.file} (${routes})`
|
|
52
|
-
: `• ${result.file} already in sync (${routes})`);
|
|
53
|
-
console.log(" Include it in your tsconfig's `include` so `navigate({ to, search })` is typed per route.");
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=sync-routes.js.map
|
package/dist/sync-routes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-routes.js","sourceRoot":"","sources":["../src/sync-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,4GAA4G;AAC5G,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAA;AAWnD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAW;IAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IACrC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IACvC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAA;IAC1D,MAAM,EAAE,wBAAwB,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;IAC1C,MAAM,IAAI,GAAG,wBAAwB,CAAC,QAAQ,EAAE;QAC9C,oGAAoG;QACpG,0FAA0F;QAC1F,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE;KAC/D,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;SACrC,IAAI,EAAE;SACN,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;IAClB,MAAM,OAAO,GAAG,QAAQ,KAAK,IAAI,CAAA;IACjC,IAAI,OAAO;QAAE,MAAM,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3C,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAA;AACpG,CAAC;AAED,0GAA0G;AAC1G,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAW;IAC7C,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAA;IACxC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,CAAC,GAAG,CAAC,4EAA4E,CAAC,CAAA;QACzF,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,CAAA;IAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;IACtD,OAAO,CAAC,GAAG,CACT,MAAM,CAAC,OAAO;QACZ,CAAC,CAAC,WAAW,MAAM,CAAC,IAAI,KAAK,MAAM,GAAG;QACtC,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,qBAAqB,MAAM,GAAG,CACnD,CAAA;IACD,OAAO,CAAC,GAAG,CACT,6FAA6F,CAC9F,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/src/sync-routes.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `nifra sync-routes` - regenerate the route-search types (`nifra-routes.d.ts`) from the current `routes/`
|
|
3
|
-
* tree, so `navigate({ to, search })` is typed against each static route's `searchSchema`. It runs
|
|
4
|
-
* `@nifrajs/web`'s `generateRouteSearchTypes` over the discovered routes and writes the `.d.ts` at the
|
|
5
|
-
* project root; include it in your tsconfig's `include`. Because it is regenerated from the route files, a
|
|
6
|
-
* stale navigate search shape becomes a `tsc` error - run it after adding/renaming a route or changing a
|
|
7
|
-
* `searchSchema` (a pure file write, no build). A dynamic route (`:param`/catch-all) is omitted, since its
|
|
8
|
-
* pattern is not a concrete `to`; those keep the loose object form.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { existsSync } from "node:fs"
|
|
12
|
-
import { join } from "node:path"
|
|
13
|
-
|
|
14
|
-
/** The committed route-types file `sync-routes` writes, so `nifra check` can recognise + drift-check it. */
|
|
15
|
-
export const ROUTE_TYPES_FILE = "nifra-routes.d.ts"
|
|
16
|
-
|
|
17
|
-
export interface SyncRoutesResult {
|
|
18
|
-
/** The written `.d.ts` (relative to the project root). */
|
|
19
|
-
readonly file: string
|
|
20
|
-
/** True when the file's content changed and it was rewritten. */
|
|
21
|
-
readonly changed: boolean
|
|
22
|
-
/** How many static routes got a typed entry. */
|
|
23
|
-
readonly typedRoutes: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Generate the route-search types `.d.ts` from `<cwd>/routes` (the nifra convention). Returns
|
|
28
|
-
* `null` when there is no `routes/` directory (an API-only project - nothing to type). Never loads
|
|
29
|
-
* `backend/framework.ts`: it needs only the route tree, so it works before a build and on a broken
|
|
30
|
-
* framework config.
|
|
31
|
-
*/
|
|
32
|
-
export async function syncRouteTypes(cwd: string): Promise<SyncRoutesResult | null> {
|
|
33
|
-
const routesDir = join(cwd, "routes")
|
|
34
|
-
if (!existsSync(routesDir)) return null
|
|
35
|
-
const { discoverRoutes } = await import("@nifrajs/web/fs")
|
|
36
|
-
const { generateRouteSearchTypes } = await import("@nifrajs/web")
|
|
37
|
-
const manifest = discoverRoutes(routesDir)
|
|
38
|
-
const code = generateRouteSearchTypes(manifest, {
|
|
39
|
-
// A route file is relative to routesDir (`reports.tsx`, `users/index.tsx`); the `.d.ts` sits at the
|
|
40
|
-
// project root, so the `typeof import(...)` specifier is `./routes/<file без extension>`.
|
|
41
|
-
resolve: (file) => `./routes/${file.replace(/\.[^./]+$/, "")}`,
|
|
42
|
-
})
|
|
43
|
-
const outFile = join(cwd, ROUTE_TYPES_FILE)
|
|
44
|
-
const existing = await Bun.file(outFile)
|
|
45
|
-
.text()
|
|
46
|
-
.catch(() => "")
|
|
47
|
-
const changed = existing !== code
|
|
48
|
-
if (changed) await Bun.write(outFile, code)
|
|
49
|
-
return { file: ROUTE_TYPES_FILE, changed, typedRoutes: (code.match(/: SearchOf</g) ?? []).length }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** CLI entry: write/refresh the route-types file and print a one-line summary + the tsconfig reminder. */
|
|
53
|
-
export async function runSyncRoutes(cwd: string): Promise<boolean> {
|
|
54
|
-
const result = await syncRouteTypes(cwd)
|
|
55
|
-
if (result === null) {
|
|
56
|
-
console.log("nifra sync-routes: no routes/ directory found. Run from your project root.")
|
|
57
|
-
return true
|
|
58
|
-
}
|
|
59
|
-
const n = result.typedRoutes
|
|
60
|
-
const routes = `${n} typed route${n === 1 ? "" : "s"}`
|
|
61
|
-
console.log(
|
|
62
|
-
result.changed
|
|
63
|
-
? `✓ wrote ${result.file} (${routes})`
|
|
64
|
-
: `• ${result.file} already in sync (${routes})`,
|
|
65
|
-
)
|
|
66
|
-
console.log(
|
|
67
|
-
" Include it in your tsconfig's `include` so `navigate({ to, search })` is typed per route.",
|
|
68
|
-
)
|
|
69
|
-
return true
|
|
70
|
-
}
|