@nifrajs/cli 3.3.0 → 4.0.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/README.md +42 -3
- package/dist/app-files.d.ts +11 -0
- package/dist/app-files.d.ts.map +1 -0
- package/dist/app-files.js +34 -0
- package/dist/app-files.js.map +1 -0
- package/dist/assure-hydration.d.ts +7 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +128 -43
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +16 -2
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts +5 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +32 -10
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/cdn-check.d.ts +41 -0
- package/dist/cdn-check.d.ts.map +1 -0
- package/dist/cdn-check.js +207 -0
- package/dist/cdn-check.js.map +1 -0
- package/dist/check-diagnostics.d.ts +7 -15
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +162 -713
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +58 -7
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +323 -62
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +1 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +145 -54
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +42 -16
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +306 -87
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +60 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +298 -33
- package/dist/command-catalog.js.map +1 -1
- package/dist/config-target.d.ts +8 -0
- package/dist/config-target.d.ts.map +1 -0
- package/dist/config-target.js +45 -0
- package/dist/config-target.js.map +1 -0
- package/dist/contracts.d.ts +3 -2
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +56 -16
- package/dist/contracts.js.map +1 -1
- package/dist/db-audit.d.ts +37 -0
- package/dist/db-audit.d.ts.map +1 -0
- package/dist/db-audit.js +99 -0
- package/dist/db-audit.js.map +1 -0
- package/dist/db-child.d.ts +64 -0
- package/dist/db-child.d.ts.map +1 -0
- package/dist/db-child.js +213 -0
- package/dist/db-child.js.map +1 -0
- package/dist/db-config.d.ts +60 -0
- package/dist/db-config.d.ts.map +1 -0
- package/dist/db-config.js +176 -0
- package/dist/db-config.js.map +1 -0
- package/dist/db-tool.d.ts +84 -0
- package/dist/db-tool.d.ts.map +1 -0
- package/dist/db-tool.js +537 -0
- package/dist/db-tool.js.map +1 -0
- package/dist/dev-bun-config.d.ts +20 -13
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +98 -41
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +106 -0
- package/dist/dev-feed-tool.d.ts.map +1 -0
- package/dist/dev-feed-tool.js +713 -0
- package/dist/dev-feed-tool.js.map +1 -0
- package/dist/dev-server-client.d.ts +67 -0
- package/dist/dev-server-client.d.ts.map +1 -0
- package/dist/dev-server-client.js +195 -0
- package/dist/dev-server-client.js.map +1 -0
- package/dist/diagnostics.d.ts +86 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +85 -0
- package/dist/diagnostics.js.map +1 -1
- package/dist/diff-tool.d.ts +3 -3
- package/dist/diff-tool.d.ts.map +1 -1
- package/dist/diff-tool.js +6 -5
- package/dist/diff-tool.js.map +1 -1
- package/dist/docs-search.d.ts.map +1 -1
- package/dist/docs-search.js +12 -4
- package/dist/docs-search.js.map +1 -1
- package/dist/doctor.d.ts +17 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +76 -15
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts +15 -0
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +73 -1
- package/dist/env-file.js.map +1 -1
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +41 -21
- package/dist/fix-recipes.js.map +1 -1
- package/dist/frontend-guidance.js +5 -5
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/i18n-check.d.ts +16 -0
- package/dist/i18n-check.d.ts.map +1 -0
- package/dist/i18n-check.js +154 -0
- package/dist/i18n-check.js.map +1 -0
- package/dist/init-agents.d.ts +49 -13
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +239 -34
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/code-unit-order.d.ts +4 -0
- package/dist/internal/code-unit-order.d.ts.map +1 -0
- package/dist/internal/code-unit-order.js +6 -0
- package/dist/internal/code-unit-order.js.map +1 -0
- package/dist/internal/script-kind.d.ts +7 -0
- package/dist/internal/script-kind.d.ts.map +1 -0
- package/dist/internal/script-kind.js +12 -0
- package/dist/internal/script-kind.js.map +1 -0
- package/dist/internal/source-facts.d.ts +5 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +61 -5
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts +49 -24
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +507 -67
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/introspect.d.ts +6 -4
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +93 -74
- package/dist/introspect.js.map +1 -1
- package/dist/learn.js +3 -3
- package/dist/learn.js.map +1 -1
- package/dist/levels-tool.d.ts +10 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +33 -3
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +71 -16
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +78 -18
- package/dist/load.js.map +1 -1
- package/dist/manifest-tool.d.ts.map +1 -1
- package/dist/manifest-tool.js +3 -2
- package/dist/manifest-tool.js.map +1 -1
- package/dist/mcp-app-tool.d.ts.map +1 -1
- package/dist/mcp-app-tool.js +2 -0
- package/dist/mcp-app-tool.js.map +1 -1
- package/dist/mcp-context.d.ts.map +1 -1
- package/dist/mcp-context.js +5 -6
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-delegate.d.ts +57 -0
- package/dist/mcp-delegate.d.ts.map +1 -0
- package/dist/mcp-delegate.js +130 -0
- package/dist/mcp-delegate.js.map +1 -0
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +23 -5
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-exec.d.ts +3 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +263 -131
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.d.ts.map +1 -1
- package/dist/mcp-http.js +20 -5
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-io.d.ts +26 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +113 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts +48 -0
- package/dist/mcp-isolate.d.ts.map +1 -0
- package/dist/mcp-isolate.js +222 -0
- package/dist/mcp-isolate.js.map +1 -0
- package/dist/mcp-path.d.ts +10 -0
- package/dist/mcp-path.d.ts.map +1 -0
- package/dist/mcp-path.js +51 -0
- package/dist/mcp-path.js.map +1 -0
- package/dist/mcp-project-child.d.ts +74 -0
- package/dist/mcp-project-child.d.ts.map +1 -0
- package/dist/mcp-project-child.js +130 -0
- package/dist/mcp-project-child.js.map +1 -0
- package/dist/mcp-reflect.d.ts.map +1 -1
- package/dist/mcp-reflect.js +2 -2
- package/dist/mcp-reflect.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +64 -45
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.d.ts +37 -9
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +124 -25
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts +18 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +159 -55
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp-ws.js +4 -1
- package/dist/mcp-ws.js.map +1 -1
- package/dist/mcp.d.ts +18 -5
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +165 -82
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +44 -0
- package/dist/migrate-layout.d.ts.map +1 -0
- package/dist/migrate-layout.js +982 -0
- package/dist/migrate-layout.js.map +1 -0
- package/dist/openapi-tool.d.ts +2 -2
- package/dist/openapi-tool.d.ts.map +1 -1
- package/dist/openapi-tool.js.map +1 -1
- package/dist/openapi-types.d.ts +2 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +240 -12
- package/dist/openapi-types.js.map +1 -1
- package/dist/pipeline-report.d.ts +3 -2
- package/dist/pipeline-report.d.ts.map +1 -1
- package/dist/pipeline-report.js +19 -16
- package/dist/pipeline-report.js.map +1 -1
- package/dist/port.d.ts +5 -4
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +46 -29
- package/dist/port.js.map +1 -1
- package/dist/project-facts.d.ts +28 -4
- package/dist/project-facts.d.ts.map +1 -1
- package/dist/project-facts.js +12 -2
- package/dist/project-facts.js.map +1 -1
- package/dist/recipes/4.0.0.d.ts +9 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -0
- package/dist/recipes/4.0.0.js +34 -0
- package/dist/recipes/4.0.0.js.map +1 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/release-verification.d.ts +11 -1
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +47 -4
- package/dist/release-verification.js.map +1 -1
- package/dist/review.d.ts +21 -0
- package/dist/review.d.ts.map +1 -0
- package/dist/review.js +823 -0
- package/dist/review.js.map +1 -0
- package/dist/route-types.d.ts +28 -0
- package/dist/route-types.d.ts.map +1 -0
- package/dist/route-types.js +106 -0
- package/dist/route-types.js.map +1 -0
- package/dist/rules/codes.d.ts +9 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +9 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/data-guard.d.ts +12 -0
- package/dist/rules/data-guard.d.ts.map +1 -0
- package/dist/rules/data-guard.js +213 -0
- package/dist/rules/data-guard.js.map +1 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +17 -5
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +7 -4
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/legacy.d.ts +3 -1
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +829 -34
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/nano.d.ts.map +1 -1
- package/dist/rules/nano.js +15 -6
- package/dist/rules/nano.js.map +1 -1
- package/dist/rules/pages.d.ts +15 -0
- package/dist/rules/pages.d.ts.map +1 -0
- package/dist/rules/pages.js +88 -0
- package/dist/rules/pages.js.map +1 -0
- package/dist/rules/routes.d.ts +11 -0
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +180 -2
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/secrets.d.ts +10 -0
- package/dist/rules/secrets.d.ts.map +1 -0
- package/dist/rules/secrets.js +169 -0
- package/dist/rules/secrets.js.map +1 -0
- package/dist/rules/security.d.ts +7 -0
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +171 -65
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/typescript.d.ts +16 -0
- package/dist/rules/typescript.d.ts.map +1 -0
- package/dist/rules/typescript.js +59 -0
- package/dist/rules/typescript.js.map +1 -0
- package/dist/rules/zones.d.ts +17 -0
- package/dist/rules/zones.d.ts.map +1 -0
- package/dist/rules/zones.js +174 -0
- package/dist/rules/zones.js.map +1 -0
- package/dist/scaffold.d.ts +25 -12
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +154 -90
- package/dist/scaffold.js.map +1 -1
- package/dist/sdk.d.ts +17 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +941 -153
- package/dist/sdk.js.map +1 -1
- package/dist/search-terms.d.ts +2 -0
- package/dist/search-terms.d.ts.map +1 -1
- package/dist/search-terms.js +23 -8
- package/dist/search-terms.js.map +1 -1
- package/dist/smoke.d.ts +79 -0
- package/dist/smoke.d.ts.map +1 -0
- package/dist/smoke.js +494 -0
- package/dist/smoke.js.map +1 -0
- package/dist/sync-manifest.d.ts.map +1 -1
- package/dist/sync-manifest.js +2 -1
- package/dist/sync-manifest.js.map +1 -1
- package/dist/sync-routes.d.ts +4 -3
- package/dist/sync-routes.d.ts.map +1 -1
- package/dist/sync-routes.js +4 -3
- package/dist/sync-routes.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +30 -11
- package/dist/test-tool.js.map +1 -1
- package/dist/types-search.d.ts.map +1 -1
- package/dist/types-search.js +11 -5
- package/dist/types-search.js.map +1 -1
- package/dist/upgrade.d.ts +36 -6
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +167 -29
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +8 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/verification.d.ts.map +1 -1
- package/dist/verification.js +45 -12
- package/dist/verification.js.map +1 -1
- package/dist/web-app-options.d.ts +19 -0
- package/dist/web-app-options.d.ts.map +1 -0
- package/dist/web-app-options.js +49 -0
- package/dist/web-app-options.js.map +1 -0
- package/dist/work-graph.d.ts +3 -0
- package/dist/work-graph.d.ts.map +1 -1
- package/dist/work-graph.js +33 -16
- package/dist/work-graph.js.map +1 -1
- package/docs/examples.json +185 -29
- package/docs/llms-full.txt +4123 -548
- package/docs/types.json +14391 -10060
- package/package.json +19 -11
- package/src/app-files.ts +40 -0
- package/src/assure-hydration.ts +139 -46
- package/src/assure.ts +17 -2
- package/src/capabilities-tool.ts +35 -9
- package/src/cdn-check.ts +268 -0
- package/src/check-diagnostics.ts +199 -797
- package/src/check-scan.ts +394 -63
- package/src/check.ts +146 -58
- package/src/cli.ts +347 -92
- package/src/command-catalog.ts +407 -45
- package/src/config-target.ts +47 -0
- package/src/contracts.ts +66 -15
- package/src/db-audit.ts +128 -0
- package/src/db-child.ts +285 -0
- package/src/db-config.ts +224 -0
- package/src/db-tool.ts +690 -0
- package/src/dev-bun-config.ts +116 -40
- package/src/dev-feed-tool.ts +912 -0
- package/src/dev-server-client.ts +267 -0
- package/src/diagnostics.ts +179 -0
- package/src/diff-tool.ts +6 -5
- package/src/docs-search.ts +10 -3
- package/src/doctor.ts +98 -15
- package/src/env-file.ts +78 -1
- package/src/fix-recipes.ts +44 -31
- package/src/frontend-guidance.ts +5 -5
- package/src/i18n-check.ts +179 -0
- package/src/init-agents.ts +301 -38
- package/src/internal/code-unit-order.ts +5 -0
- package/src/internal/script-kind.ts +11 -0
- package/src/internal/source-facts.ts +96 -22
- package/src/internal/typescript-import.ts +663 -68
- package/src/introspect.ts +93 -82
- package/src/learn.ts +3 -3
- package/src/levels-tool.ts +47 -2
- package/src/load.ts +144 -32
- package/src/manifest-tool.ts +3 -2
- package/src/mcp-app-tool.ts +2 -0
- package/src/mcp-context.ts +5 -7
- package/src/mcp-delegate.ts +162 -0
- package/src/mcp-docs-tools.ts +23 -5
- package/src/mcp-exec.ts +301 -161
- package/src/mcp-http.ts +22 -5
- package/src/mcp-io.ts +130 -0
- package/src/mcp-isolate.ts +287 -0
- package/src/mcp-path.ts +50 -0
- package/src/mcp-project-child.ts +182 -0
- package/src/mcp-reflect.ts +3 -2
- package/src/mcp-render.ts +72 -42
- package/src/mcp-root.ts +130 -24
- package/src/mcp-run.ts +190 -56
- package/src/mcp-ws.ts +4 -1
- package/src/mcp.ts +193 -91
- package/src/migrate-layout.ts +1121 -0
- package/src/openapi-tool.ts +7 -3
- package/src/openapi-types.ts +315 -13
- package/src/pipeline-report.ts +22 -18
- package/src/port.ts +53 -30
- package/src/project-facts.ts +42 -8
- package/src/recipes/4.0.0.ts +35 -0
- package/src/recipes/index.ts +2 -0
- package/src/release-verification.ts +74 -5
- package/src/review.ts +988 -0
- package/src/route-types.ts +133 -0
- package/src/rules/codes.ts +9 -0
- package/src/rules/data-guard.ts +230 -0
- package/src/rules/index.ts +18 -5
- package/src/rules/islands.ts +12 -4
- package/src/rules/legacy.ts +947 -35
- package/src/rules/nano.ts +18 -6
- package/src/rules/pages.ts +99 -0
- package/src/rules/routes.ts +181 -2
- package/src/rules/secrets.ts +174 -0
- package/src/rules/security.ts +198 -70
- package/src/rules/typescript.ts +77 -0
- package/src/rules/zones.ts +195 -0
- package/src/scaffold.ts +175 -98
- package/src/sdk.ts +1215 -158
- package/src/search-terms.ts +24 -7
- package/src/smoke.ts +607 -0
- package/src/sync-manifest.ts +2 -1
- package/src/sync-routes.ts +4 -3
- package/src/test-tool.ts +32 -11
- package/src/types-search.ts +11 -4
- package/src/upgrade.ts +205 -25
- package/src/verification-plan.ts +27 -0
- package/src/verification.ts +50 -12
- package/src/web-app-options.ts +57 -0
- package/src/work-graph.ts +40 -16
package/src/scaffold.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `nifra_scaffold` - turn a URL path into the correct `routes/`
|
|
3
|
-
* gets wrong) + a minimal, contract-correct
|
|
4
|
-
*
|
|
5
|
-
* `/` → `
|
|
2
|
+
* `nifra_scaffold` - turn a URL path into the correct `routes/` files (the convention an agent most often
|
|
3
|
+
* gets wrong) + a minimal, contract-correct route pair: the page, and its `.backend.ts` half holding the
|
|
4
|
+
* loader and its output schema. The mapping is the inverse of @nifrajs/web's `filePathToPatterns`:
|
|
5
|
+
* `:id`/`[id]` → `[id]`, `*rest`/`[...rest]` → `[...rest]`, `[[lang]]` optional, `/` → `index`. The
|
|
6
|
+
* framework (→ file extension) comes from the project's `clientModule`.
|
|
6
7
|
*
|
|
7
8
|
* Page stubs are emitted for the JSX family (react/preact/solid - one shared, verified shape) and
|
|
8
9
|
* for vanilla (a zero-runtime `html` page carrying the golden island pattern); for vue/svelte we
|
|
9
|
-
* return the correct
|
|
10
|
-
* rather than hand-writing an SFC we can't typecheck here.
|
|
10
|
+
* return the correct PATHS, the backend half and the route contract, and point at `nifra_example` for
|
|
11
|
+
* the page body, rather than hand-writing an SFC we can't typecheck here.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { lstat, mkdir, realpath, writeFile } from "node:fs/promises"
|
|
14
|
-
import { dirname, resolve, sep } from "node:path"
|
|
15
|
+
import { basename, dirname, resolve, sep } from "node:path"
|
|
16
|
+
import { paramConstraint } from "@nifrajs/core/pattern"
|
|
15
17
|
|
|
16
18
|
export type Framework = "react" | "preact" | "solid" | "vue" | "svelte" | "vanilla"
|
|
17
19
|
|
|
@@ -45,11 +47,41 @@ function segmentToFile(seg: string): string {
|
|
|
45
47
|
return seg
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
/** Reject syntax that could be interpreted by the host filesystem rather than the route mapper. */
|
|
51
|
+
function assertSafeRouteSegment(segment: string, urlPath: string): void {
|
|
52
|
+
if (segment === "." || segment === ".." || segment.includes("\0") || segment.includes("\\")) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`invalid route segment in ${JSON.stringify(urlPath)}: ${JSON.stringify(segment)}`,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
const brace = segment.indexOf("{")
|
|
58
|
+
if (segment.startsWith(":") && brace > 0 && paramConstraint(segment.slice(brace)) !== undefined) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`a param constraint cannot be written in a route file name: ${JSON.stringify(segment)} in ${JSON.stringify(urlPath)}. Scaffold the page without it and check the value in the route's loader.`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
const fileSegment = segmentToFile(segment)
|
|
64
|
+
if (
|
|
65
|
+
fileSegment === "." ||
|
|
66
|
+
fileSegment === ".." ||
|
|
67
|
+
fileSegment.includes("\0") ||
|
|
68
|
+
fileSegment.includes("/") ||
|
|
69
|
+
fileSegment.includes("\\") ||
|
|
70
|
+
fileSegment.includes(":") ||
|
|
71
|
+
/^[A-Za-z]:/.test(fileSegment)
|
|
72
|
+
) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`invalid route segment in ${JSON.stringify(urlPath)}: ${JSON.stringify(segment)}`,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
48
79
|
/** Map a URL path to its `routes/` file path (relative to `routes/`, without extension prefix dir).
|
|
49
80
|
* `/` → `index`; `/users/:id` → `users/[id]`; `/blog/*slug` → `blog/[...slug]`. */
|
|
50
81
|
export function routePathToFile(urlPath: string, ext: string): string {
|
|
51
82
|
const segments = urlPath.split("/").filter((s) => s.length > 0)
|
|
52
83
|
if (segments.length === 0) return `routes/index.${ext}`
|
|
84
|
+
for (const segment of segments) assertSafeRouteSegment(segment, urlPath)
|
|
53
85
|
const last = segments.length - 1
|
|
54
86
|
// Catch-all must be the final segment (mirrors @nifrajs/web); flag it rather than emit an invalid file.
|
|
55
87
|
for (let i = 0; i < last; i++) {
|
|
@@ -59,25 +91,69 @@ export function routePathToFile(urlPath: string, ext: string): string {
|
|
|
59
91
|
return `routes/${segments.map(segmentToFile).join("/")}.${ext}`
|
|
60
92
|
}
|
|
61
93
|
|
|
62
|
-
const ROUTE_CONTRACT = `A route
|
|
63
|
-
- \`export default function Page(
|
|
64
|
-
- \`export async function loader({ params,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
const ROUTE_CONTRACT = `A route is two files:
|
|
95
|
+
- The page, \`routes/x.<ext>\` - ships to the browser: \`export default function Page({ data }: Route.ComponentProps)\` and \`export const meta = { title, meta: […] }\`. It never imports backend code.
|
|
96
|
+
- Its backend half, \`routes/x.backend.ts\` - never reaches the browser: \`export const loaderOutput = t.object({…})\` with \`export async function loader({ params, api }: Route.LoaderArgs)\` (data for SSR - only what the schema declares is sent), \`actionOutput\` with \`action\` (the form POST), and \`hydrate\`, \`islandScripts\`, \`revalidate\`, \`middleware\`. Reach the backend through the typed \`api\`.
|
|
97
|
+
Both import \`type { Route } from "./+types/<name>"\`, which \`nifra dev\`, \`nifra build\`, \`nifra check\` and \`nifra types\` generate. Path params are typed on \`params\`.`
|
|
98
|
+
|
|
99
|
+
interface RouteParam {
|
|
100
|
+
readonly name: string
|
|
101
|
+
readonly optional: boolean
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Param names a route file declares, for the stubs. */
|
|
105
|
+
function paramsOf(file: string): RouteParam[] {
|
|
106
|
+
const out: RouteParam[] = []
|
|
107
|
+
for (const m of file.matchAll(/(\[)?\[(?:\.\.\.)?([A-Za-z_][A-Za-z0-9_]*)\]/g))
|
|
108
|
+
out.push({ name: m[2] as string, optional: m[1] !== undefined })
|
|
109
|
+
return out
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** `./+types/<name>` for a route file: the generated module both halves import `Route` from. */
|
|
113
|
+
const typesOf = (file: string): string => `./+types/${basename(file).replace(/\.[^.]+$/, "")}`
|
|
114
|
+
|
|
115
|
+
/** `routes/users/[id].tsx` → `routes/users/[id].backend.ts`. */
|
|
116
|
+
export const backendFileOf = (file: string): string => file.replace(/\.[^./]+$/, ".backend.ts")
|
|
117
|
+
|
|
118
|
+
/** The page's backend half: its loader, and the schema that bounds what the loader sends. */
|
|
119
|
+
function backendStub(file: string, params: readonly RouteParam[], vanilla: boolean): string {
|
|
120
|
+
const last = params.at(-1)
|
|
121
|
+
const loader =
|
|
122
|
+
last === undefined
|
|
123
|
+
? `export async function loader(_args: Route.LoaderArgs) {
|
|
124
|
+
// Load through the typed backend client, \`api\` in these args; see nifra_example("loader").
|
|
125
|
+
return { title: "TODO" }
|
|
126
|
+
}`
|
|
127
|
+
: `export async function loader({ params }: Route.LoaderArgs) {
|
|
128
|
+
// Load by params.${last.name} through the typed backend client, \`api\` in these args; see nifra_example("loader").
|
|
129
|
+
return { title: \`TODO: \${params.${last.name}${last.optional ? ' ?? ""' : ""}}\` }
|
|
130
|
+
}`
|
|
131
|
+
const vanillaExports = vanilla
|
|
132
|
+
? `
|
|
133
|
+
|
|
134
|
+
// No client framework to hydrate with - vanilla routes are documents, not hydrated apps.
|
|
135
|
+
export const hydrate = false
|
|
136
|
+
|
|
137
|
+
// The built URL of each island enhancer this page renders a marker for (./<name>.client.ts).
|
|
138
|
+
// export const islandScripts = []`
|
|
139
|
+
: ""
|
|
140
|
+
return `// ${backendFileOf(file)} - the server half of ${file}; it never reaches the browser.
|
|
141
|
+
import { t } from "@nifrajs/schema"
|
|
142
|
+
import type { Route } from "${typesOf(file)}"
|
|
143
|
+
|
|
144
|
+
// Only what this schema declares is sent to the page.
|
|
145
|
+
export const loaderOutput = t.object({ title: t.string() })
|
|
146
|
+
|
|
147
|
+
${loader}${vanillaExports}
|
|
148
|
+
`
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function jsxStub(file: string): string {
|
|
152
|
+
return `// ${file} - the page; it ships to the browser. Its data comes from ${basename(backendFileOf(file))}.
|
|
153
|
+
import type { Route } from "${typesOf(file)}"
|
|
154
|
+
|
|
155
|
+
export default function Page({ data }: Route.ComponentProps) {
|
|
156
|
+
return <main>{data.title}</main>
|
|
81
157
|
}
|
|
82
158
|
`
|
|
83
159
|
}
|
|
@@ -89,29 +165,20 @@ export default function Page() {
|
|
|
89
165
|
* returns its cleanup (the one thing NF-C020 checks), wired through `mountIslands`. Interactivity is
|
|
90
166
|
* added by uncommenting and writing the companion `<name>.client.ts`, never by turning on hydration.
|
|
91
167
|
*/
|
|
92
|
-
function vanillaStub(file: string
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const loaderLine =
|
|
96
|
-
params.length > 0
|
|
97
|
-
? `// export async function loader({ params, api }: LoaderArgs<typeof backend>) { return { /* fetch by ${params[0]} */ } }`
|
|
98
|
-
: `// export async function loader({ api }: LoaderArgs<typeof backend>) { return {} }`
|
|
99
|
-
return `// ${file} - @nifrajs/web-vanilla route. Server-rendered HTML, ZERO framework runtime.
|
|
100
|
-
// Available here: ${paramsNote}. Fetch data in a loader via the typed \`api\`; see nifra_example("loader").
|
|
168
|
+
function vanillaStub(file: string): string {
|
|
169
|
+
return `// ${file} - @nifrajs/web-vanilla page. Server-rendered HTML, ZERO framework runtime; its data,
|
|
170
|
+
// and \`hydrate = false\`, live in ${basename(backendFileOf(file))}.
|
|
101
171
|
import { html } from "@nifrajs/web-vanilla"
|
|
172
|
+
import type { Route } from "${typesOf(file)}"
|
|
102
173
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
${loaderLine}
|
|
107
|
-
|
|
108
|
-
export default function Page() {
|
|
109
|
-
return html\`<main><h1>TODO: ${file}</h1></main>\`
|
|
174
|
+
export default function Page({ data }: Route.ComponentProps) {
|
|
175
|
+
return html\`<main><h1>\${data.title}</h1></main>\`
|
|
110
176
|
}
|
|
111
177
|
|
|
112
178
|
// --- Add interactivity the AI-safe way (islands), NOT hydration ---------------------------------
|
|
113
179
|
// 1. Render a marker in the page above: html\`<nifra-island data-id="counter" data-props=\${JSON.stringify({ start: 0 })}></nifra-island>\`
|
|
114
|
-
// 2. Wire the route to its enhancer bundle
|
|
180
|
+
// 2. Wire the route to its enhancer bundle, in ${basename(backendFileOf(file))}:
|
|
181
|
+
// export const islandScripts = [/* built URL of ./counter.client.ts */]
|
|
115
182
|
// 3. Write ./counter.client.ts as an imperative enhancer that ALWAYS returns its cleanup:
|
|
116
183
|
//
|
|
117
184
|
// import { defineIsland, mountIslands } from "@nifrajs/web/islands"
|
|
@@ -140,33 +207,21 @@ export default function Page() {
|
|
|
140
207
|
* The page body is a valid, typecheckable static document; interactivity is added by writing the
|
|
141
208
|
* companion client shown, never by turning on hydration.
|
|
142
209
|
*/
|
|
143
|
-
function nanoStub(file: string
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
params.length > 0
|
|
148
|
-
? `// export async function loader({ params, api }: LoaderArgs<typeof backend>) { return { /* seed by ${params[0]} */ } }`
|
|
149
|
-
: `// export async function loader({ api }: LoaderArgs<typeof backend>) { return {} }`
|
|
150
|
-
return `// ${file} - @nifrajs/web-vanilla route + a nano island (explicit reactivity, zero VDOM).
|
|
151
|
-
// Available here: ${paramsNote}. Seed data in a loader via the typed \`api\`; see nifra_example("loader").
|
|
210
|
+
function nanoStub(file: string): string {
|
|
211
|
+
return `// ${file} - @nifrajs/web-vanilla page + a nano island (explicit reactivity, zero VDOM). The
|
|
212
|
+
// document is static and the nano client below owns all interactivity; \`hydrate = false\` and the
|
|
213
|
+
// island's \`islandScripts\` URL live in ${basename(backendFileOf(file))}.
|
|
152
214
|
import { html } from "@nifrajs/web-vanilla"
|
|
215
|
+
import type { Route } from "${typesOf(file)}"
|
|
153
216
|
|
|
154
|
-
|
|
155
|
-
export const hydrate = false
|
|
156
|
-
|
|
157
|
-
${loaderLine}
|
|
158
|
-
|
|
159
|
-
export default function Page() {
|
|
217
|
+
export default function Page({ data }: Route.ComponentProps) {
|
|
160
218
|
// The island marker: data-props is the initial state the client reads on mount.
|
|
161
219
|
return html\`<main>
|
|
162
|
-
<h1
|
|
220
|
+
<h1>\${data.title}</h1>
|
|
163
221
|
<nifra-island data-id="todos" data-props=\${JSON.stringify({ items: [] })}></nifra-island>
|
|
164
222
|
</main>\`
|
|
165
223
|
}
|
|
166
224
|
|
|
167
|
-
// Wire the route to the built URL of ./todos.client.ts (the nano enhancer below).
|
|
168
|
-
// export const islandScripts = [/* built URL of ./todos.client.ts */]
|
|
169
|
-
|
|
170
225
|
// --- ./todos.client.ts - the golden nano pattern (write this as a companion file) -----------------
|
|
171
226
|
//
|
|
172
227
|
// import { defineIsland, mountIslands } from "@nifrajs/web/islands"
|
|
@@ -210,17 +265,13 @@ export default function Page() {
|
|
|
210
265
|
`
|
|
211
266
|
}
|
|
212
267
|
|
|
213
|
-
/** Param names a route file declares, for the stub's notes. */
|
|
214
|
-
function paramsOf(file: string): string[] {
|
|
215
|
-
const out: string[] = []
|
|
216
|
-
for (const m of file.matchAll(/\[(?:\.\.\.)?([A-Za-z_][A-Za-z0-9_]*)\]/g))
|
|
217
|
-
out.push(m[1] as string)
|
|
218
|
-
return out
|
|
219
|
-
}
|
|
220
|
-
|
|
221
268
|
export interface ScaffoldResult {
|
|
269
|
+
/** The page file. */
|
|
222
270
|
readonly file: string
|
|
271
|
+
/** The page stub, when there is a verified one for the framework. */
|
|
223
272
|
readonly content?: string
|
|
273
|
+
/** The page's backend half - framework-independent, so always present. */
|
|
274
|
+
readonly backend: { readonly file: string; readonly content: string }
|
|
224
275
|
readonly note: string
|
|
225
276
|
}
|
|
226
277
|
|
|
@@ -229,8 +280,9 @@ export interface ScaffoldWriteResult extends ScaffoldResult {
|
|
|
229
280
|
readonly reason?: string
|
|
230
281
|
}
|
|
231
282
|
|
|
232
|
-
/** Scaffold a page route for `urlPath` under the project's `framework`. Returns the correct file
|
|
233
|
-
* always; a ready-to-write stub for the JSX family, contract
|
|
283
|
+
/** Scaffold a page route for `urlPath` under the project's `framework`. Returns the correct file paths
|
|
284
|
+
* and the backend half always; a ready-to-write page stub for the JSX family and vanilla, contract
|
|
285
|
+
* guidance otherwise. */
|
|
234
286
|
export function scaffoldRoute(
|
|
235
287
|
urlPath: string,
|
|
236
288
|
framework: Framework,
|
|
@@ -239,40 +291,49 @@ export function scaffoldRoute(
|
|
|
239
291
|
const ext = EXT[framework]
|
|
240
292
|
const file = routePathToFile(urlPath, ext)
|
|
241
293
|
const params = paramsOf(file)
|
|
294
|
+
const backend = {
|
|
295
|
+
file: backendFileOf(file),
|
|
296
|
+
content: backendStub(file, params, framework === "vanilla"),
|
|
297
|
+
}
|
|
242
298
|
// `stateful` is vanilla-only: it swaps the static island stub for the nano golden pattern. Asking
|
|
243
299
|
// for it on a JSX/SFC framework is a no-op on the flavour (those lanes have their own reactivity).
|
|
244
300
|
if (framework === "vanilla" && variant === "stateful") {
|
|
245
301
|
return {
|
|
246
302
|
file,
|
|
247
|
-
content: nanoStub(file
|
|
248
|
-
|
|
303
|
+
content: nanoStub(file),
|
|
304
|
+
backend,
|
|
305
|
+
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route with a nano island. ${ROUTE_CONTRACT}\nThe stub embeds the golden nano client (signal + computed(fn,[deps]) + keyed bindList + collected cleanups); write it as the companion .client.ts. \`nifra check\` runs NF-C021/C022/C023 over it; nifra_docs("nano") is the full cookbook.`,
|
|
249
306
|
}
|
|
250
307
|
}
|
|
251
308
|
if (framework === "react" || framework === "preact" || framework === "solid") {
|
|
252
309
|
return {
|
|
253
310
|
file,
|
|
254
|
-
content: jsxStub(file
|
|
255
|
-
|
|
311
|
+
content: jsxStub(file),
|
|
312
|
+
backend,
|
|
313
|
+
note: `Create ${file} and ${backend.file}. ${ROUTE_CONTRACT}\nIf the rendered page misbehaves (hydration warning, a value that stops updating), call nifra_frontend { adapter: "${framework}" } for the cause + fix.`,
|
|
256
314
|
}
|
|
257
315
|
}
|
|
258
316
|
if (framework === "vanilla") {
|
|
259
317
|
return {
|
|
260
318
|
file,
|
|
261
|
-
content: vanillaStub(file
|
|
262
|
-
|
|
319
|
+
content: vanillaStub(file),
|
|
320
|
+
backend,
|
|
321
|
+
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route. ${ROUTE_CONTRACT}\nInteractivity comes from islands (imperative enhancers), never hydration - the stub embeds the golden pattern; nifra_example("islands") has the full cookbook. For explicit local state (a list a human edits), scaffold with variant "stateful" to get the nano pattern instead.`,
|
|
263
322
|
}
|
|
264
323
|
}
|
|
265
324
|
return {
|
|
266
325
|
file,
|
|
267
|
-
|
|
326
|
+
backend,
|
|
327
|
+
note: `Create ${file} as a ${framework} route module, and ${backend.file} from the stub below. ${ROUTE_CONTRACT}\nFor the ${framework} page body, call nifra_example (it ships verified ${framework} snippets) rather than guessing the SFC shape. If a value stops updating the template, call nifra_frontend { adapter: "${framework}" } for the ${framework} reactivity-loss fix.`,
|
|
268
328
|
}
|
|
269
329
|
}
|
|
270
330
|
|
|
271
|
-
function
|
|
331
|
+
function resolveInsideRoutes(cwd: string, relativeFile: string): string {
|
|
272
332
|
const root = resolve(cwd)
|
|
333
|
+
const routesRoot = resolve(root, "routes")
|
|
273
334
|
const target = resolve(root, relativeFile)
|
|
274
|
-
if (target
|
|
275
|
-
throw new Error(`refusing to write outside
|
|
335
|
+
if (target === routesRoot || !target.startsWith(`${routesRoot}${sep}`)) {
|
|
336
|
+
throw new Error(`refusing to write outside routes directory: ${relativeFile}`)
|
|
276
337
|
}
|
|
277
338
|
return target
|
|
278
339
|
}
|
|
@@ -308,9 +369,11 @@ async function assertNoSymlinkedAncestors(root: string, target: string): Promise
|
|
|
308
369
|
}
|
|
309
370
|
}
|
|
310
371
|
|
|
311
|
-
/** Write a scaffolded route
|
|
312
|
-
* intentionally conservative: it refuses
|
|
313
|
-
* uses `wx`, so an agent
|
|
372
|
+
/** Write a scaffolded route pair when the framework has a verified ready-to-write page body. The write
|
|
373
|
+
* is intentionally conservative: it refuses frameworks where we only return contract guidance (a
|
|
374
|
+
* backend half alone is a build error), refuses when either file exists, and uses `wx`, so an agent
|
|
375
|
+
* cannot overwrite user work by accident. It then generates the route's `./+types` module, so both
|
|
376
|
+
* halves typecheck at once. */
|
|
314
377
|
export async function writeScaffoldRoute(
|
|
315
378
|
cwd: string,
|
|
316
379
|
urlPath: string,
|
|
@@ -325,22 +388,35 @@ export async function writeScaffoldRoute(
|
|
|
325
388
|
reason: "no verified ready-to-write stub for this framework; use nifra_example for the body",
|
|
326
389
|
}
|
|
327
390
|
}
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (
|
|
336
|
-
return { ...result, written: false, reason: `file already exists: ${
|
|
391
|
+
const files = [
|
|
392
|
+
{ file: result.file, content: result.content },
|
|
393
|
+
{ file: result.backend.file, content: result.backend.content },
|
|
394
|
+
]
|
|
395
|
+
const targets = files.map(({ file }) => resolveInsideRoutes(cwd, file))
|
|
396
|
+
for (const target of targets) await assertNoSymlinkedAncestors(cwd, target)
|
|
397
|
+
for (const [i, target] of targets.entries()) {
|
|
398
|
+
if ((await lstat(target).catch(() => undefined)) !== undefined) {
|
|
399
|
+
return { ...result, written: false, reason: `file already exists: ${files[i]?.file}` }
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
await mkdir(dirname(targets[0] as string), { recursive: true })
|
|
403
|
+
for (const target of targets) await assertNoSymlinkedAncestors(cwd, target)
|
|
404
|
+
for (const [i, target] of targets.entries()) {
|
|
405
|
+
try {
|
|
406
|
+
await writeFile(target, files[i]?.content ?? "", { flag: "wx" })
|
|
407
|
+
} catch (err) {
|
|
408
|
+
if (err && typeof err === "object" && (err as { code?: string }).code === "EEXIST") {
|
|
409
|
+
return { ...result, written: false, reason: `file already exists: ${files[i]?.file}` }
|
|
410
|
+
}
|
|
411
|
+
throw err
|
|
337
412
|
}
|
|
338
|
-
throw err
|
|
339
413
|
}
|
|
414
|
+
const { refreshRouteTypes } = await import("./route-types.ts")
|
|
415
|
+
refreshRouteTypes(cwd, () => {})
|
|
340
416
|
return { ...result, written: true }
|
|
341
417
|
}
|
|
342
418
|
|
|
343
|
-
/** Render the tool result as markdown - the file
|
|
419
|
+
/** Render the tool result as markdown - the file paths, the stubs (if any), and the contract note. */
|
|
344
420
|
export function renderScaffold(
|
|
345
421
|
urlPath: string,
|
|
346
422
|
framework: Framework,
|
|
@@ -352,6 +428,7 @@ export function renderScaffold(
|
|
|
352
428
|
} catch (err) {
|
|
353
429
|
return `Cannot scaffold ${JSON.stringify(urlPath)}: ${err instanceof Error ? err.message : String(err)}`
|
|
354
430
|
}
|
|
355
|
-
const
|
|
356
|
-
|
|
431
|
+
const page = r.content ? `\n\n\`${r.file}\`:\n\n\`\`\`${EXT[framework]}\n${r.content}\`\`\`` : ""
|
|
432
|
+
const backend = `\n\n\`${r.backend.file}\`:\n\n\`\`\`ts\n${r.backend.content}\`\`\``
|
|
433
|
+
return `# Scaffold route \`${urlPath}\` (${framework})\n\n**Files:** \`${r.file}\` + \`${r.backend.file}\`\n\n${r.note}${page}${backend}`
|
|
357
434
|
}
|