@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/check-scan.ts
CHANGED
|
@@ -352,15 +352,59 @@ export function parseSimpleFetchCall(snippet: string): SimpleFetchCall | undefin
|
|
|
352
352
|
return { path, method, start: match.index, end: close + 1 }
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
const SERVER_CONSTRUCTION = /(?<![.\w])server\s*\(|new\s+Hono(?:<[^>]+>)?\s*\(/
|
|
356
|
+
|
|
357
|
+
function isPotentialBackendSource(
|
|
358
|
+
code: string,
|
|
359
|
+
file?: string,
|
|
360
|
+
project?: ReadonlyMap<string, string>,
|
|
361
|
+
): boolean {
|
|
356
362
|
return (
|
|
357
363
|
code.includes("@nifrajs/core") ||
|
|
358
|
-
|
|
364
|
+
SERVER_CONSTRUCTION.test(code) ||
|
|
359
365
|
/(?:from\s*|import\s*)["']hono["']/.test(code) ||
|
|
360
|
-
|
|
366
|
+
(file !== undefined && project !== undefined && callsLocalServerFactory(code, file, project))
|
|
361
367
|
)
|
|
362
368
|
}
|
|
363
369
|
|
|
370
|
+
/**
|
|
371
|
+
* A module that builds its server through a local helper - `newServer().get(...)` with `newServer`
|
|
372
|
+
* imported from a project file that calls `server()` - names neither `@nifrajs/core` nor `server(`
|
|
373
|
+
* itself. One import hop is followed: the imported module must construct a server, so a helper module
|
|
374
|
+
* that merely mentions `@nifrajs/core` (a schema re-export) does not turn every importer into a
|
|
375
|
+
* backend and its `client.get("/x")` calls into routes.
|
|
376
|
+
*/
|
|
377
|
+
function callsLocalServerFactory(
|
|
378
|
+
code: string,
|
|
379
|
+
file: string,
|
|
380
|
+
project: ReadonlyMap<string, string>,
|
|
381
|
+
): boolean {
|
|
382
|
+
for (const [local, binding] of namedImports(code)) {
|
|
383
|
+
if (!new RegExp(`(?<![.\\w$])${local.replaceAll("$", "\\$")}\\s*\\(`).test(code)) continue
|
|
384
|
+
const target = projectModule(project, file, binding.specifier)
|
|
385
|
+
if (target !== undefined && SERVER_CONSTRUCTION.test(stripComments(project.get(target) ?? "")))
|
|
386
|
+
return true
|
|
387
|
+
}
|
|
388
|
+
return false
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Literal route registrations in a file the backend-source gate turned away, so a route the scan
|
|
393
|
+
* could not cover can say where it probably lives. Nothing here is treated as a route.
|
|
394
|
+
*/
|
|
395
|
+
export function scanSkippedRouteText(
|
|
396
|
+
file: string,
|
|
397
|
+
content: string,
|
|
398
|
+
project?: ReadonlyMap<string, string>,
|
|
399
|
+
): StaticRouteFinding[] {
|
|
400
|
+
const code = stripComments(content)
|
|
401
|
+
if (isPotentialBackendSource(code, file, project)) return []
|
|
402
|
+
return [
|
|
403
|
+
...scanRoutePattern(file, content, code, ROUTE_REGISTRATION_DQ),
|
|
404
|
+
...scanRoutePattern(file, content, code, ROUTE_REGISTRATION_SQ),
|
|
405
|
+
]
|
|
406
|
+
}
|
|
407
|
+
|
|
364
408
|
function scanRoutePattern(
|
|
365
409
|
file: string,
|
|
366
410
|
content: string,
|
|
@@ -727,7 +771,7 @@ export function scanStaticRouteText(
|
|
|
727
771
|
project?: ReadonlyMap<string, string>,
|
|
728
772
|
): StaticRouteFinding[] {
|
|
729
773
|
const code = stripComments(content)
|
|
730
|
-
if (!isPotentialBackendSource(code)) return []
|
|
774
|
+
if (!isPotentialBackendSource(code, file, project)) return []
|
|
731
775
|
return [
|
|
732
776
|
...scanRoutePattern(file, content, code, ROUTE_REGISTRATION_DQ, facts),
|
|
733
777
|
...scanRoutePattern(file, content, code, ROUTE_REGISTRATION_SQ, facts),
|
|
@@ -849,7 +893,7 @@ function scanRouteArguments(
|
|
|
849
893
|
const routes: StaticRouteFinding[] = []
|
|
850
894
|
const unresolved: UnresolvedRoutePathFinding[] = []
|
|
851
895
|
const code = stripComments(content)
|
|
852
|
-
if (!isPotentialBackendSource(code)) return { routes, unresolved }
|
|
896
|
+
if (!isPotentialBackendSource(code, file, project)) return { routes, unresolved }
|
|
853
897
|
const lines = content.split("\n")
|
|
854
898
|
const constants = moduleConstants(code, content)
|
|
855
899
|
const imports = namedImports(code)
|
|
@@ -922,7 +966,7 @@ export function scanStaticSocketText(
|
|
|
922
966
|
project?: ReadonlyMap<string, string>,
|
|
923
967
|
): StaticRouteFinding[] {
|
|
924
968
|
const code = stripComments(content)
|
|
925
|
-
if (!isPotentialBackendSource(code)) return []
|
|
969
|
+
if (!isPotentialBackendSource(code, file, project)) return []
|
|
926
970
|
return [
|
|
927
971
|
...scanRoutePattern(file, content, code, ROUTE_REGISTRATION_DQ, facts, SOCKET_VERB),
|
|
928
972
|
...scanRoutePattern(file, content, code, ROUTE_REGISTRATION_SQ, facts, SOCKET_VERB),
|
|
@@ -2939,7 +2983,8 @@ function staticImportEdges(
|
|
|
2939
2983
|
for (let m = re.exec(code); m !== null; m = re.exec(code)) {
|
|
2940
2984
|
if (positions[m.index] === " ") continue
|
|
2941
2985
|
if (m[1] === undefined) continue
|
|
2942
|
-
|
|
2986
|
+
// Only a `type` modifier can erase a clause the pattern matched, so other clauses skip the parse.
|
|
2987
|
+
if (facts !== undefined && file !== undefined && /\btype\b/.test(m[0])) {
|
|
2943
2988
|
const source = facts.parse(file, content)
|
|
2944
2989
|
if (source !== undefined && facts.isValueImportAt(source, m.index, m[1]) === false) continue
|
|
2945
2990
|
}
|
|
@@ -3020,12 +3065,14 @@ function importEdges(
|
|
|
3020
3065
|
return edges.sort((a, b) => a.index - b.index)
|
|
3021
3066
|
}
|
|
3022
3067
|
|
|
3023
|
-
/** The runtime imports of a module with the line each sits on, in source order.
|
|
3068
|
+
/** The runtime imports of a module with the line each sits on, in source order. With `facts`, an
|
|
3069
|
+
* import the compiler erases (`import { type X }`) is none. Pure. */
|
|
3024
3070
|
export function importSites(
|
|
3025
3071
|
content: string,
|
|
3026
3072
|
file?: string,
|
|
3073
|
+
facts?: SourceFacts,
|
|
3027
3074
|
): Array<{ readonly specifier: string; readonly line: number }> {
|
|
3028
|
-
return importEdges(content,
|
|
3075
|
+
return importEdges(content, facts, file).map(({ specifier, index }) => ({
|
|
3029
3076
|
specifier,
|
|
3030
3077
|
line: lineAt(content, index),
|
|
3031
3078
|
}))
|
|
@@ -3334,9 +3381,15 @@ export function scanResponseRoutes(
|
|
|
3334
3381
|
for (let m = RESPONSE_RETURN.exec(code); m !== null; m = RESPONSE_RETURN.exec(code)) {
|
|
3335
3382
|
if (facts !== undefined) {
|
|
3336
3383
|
const source = facts.parse(file, content)
|
|
3337
|
-
// A parseable AST rejects `return new Response(` text that only lives in a normal string
|
|
3338
|
-
//
|
|
3339
|
-
|
|
3384
|
+
// A parseable AST rejects `return new Response(` text that only lives in a normal string, and
|
|
3385
|
+
// one outside a route handler (an auth stage's `rejected` helper, say). On malformed source we
|
|
3386
|
+
// keep the lexical candidate; the typecheck gate will report the syntax error.
|
|
3387
|
+
if (
|
|
3388
|
+
source !== undefined &&
|
|
3389
|
+
(facts.isResponseSyntaxAt(source, m.index) !== true ||
|
|
3390
|
+
!facts.isRouteHandlerAt(source, m.index))
|
|
3391
|
+
)
|
|
3392
|
+
continue
|
|
3340
3393
|
}
|
|
3341
3394
|
const line = lineAt(content, m.index)
|
|
3342
3395
|
// A `// nifra-expect NF-C007` comment (or the `raw-response` slug) marks an intentional raw Response
|
package/src/check.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { existsSync, mkdtempSync, readFileSync, realpathSync, rmdirSync, rmSync } from "node:fs"
|
|
20
20
|
import { tmpdir } from "node:os"
|
|
21
21
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path"
|
|
22
|
-
import { specifierPackage } from "@nifrajs/web/zones"
|
|
22
|
+
import { declaredSide, specifierPackage } from "@nifrajs/web/zones"
|
|
23
23
|
import { BACKEND_APP_FILE } from "./app-files.ts"
|
|
24
24
|
import {
|
|
25
25
|
type CheckAssuranceContext,
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
import { appDirs, clientModuleRoot } from "./client-module.ts"
|
|
34
34
|
import { checkContractsLock, DEFAULT_CONTRACTS_LOCK } from "./contracts.ts"
|
|
35
35
|
import { type Diagnostic, normalizeSeverity, toSarifLog } from "./diagnostics.ts"
|
|
36
|
+
import { installedManifest } from "./internal/installed-package.ts"
|
|
36
37
|
import { createApiOnlyProbe, createNifraProjectProbe } from "./internal/nifra-project.ts"
|
|
37
38
|
import { createSpecifierResolver } from "./internal/project-specifiers.ts"
|
|
38
39
|
import { createSourceFacts } from "./internal/source-facts.ts"
|
|
@@ -43,7 +44,7 @@ import { forwardTerminalSignals, OWN_PROCESS_GROUP, signalProcessGroup } from ".
|
|
|
43
44
|
import type { ContractCheckFacts, ProjectFactsSeed } from "./project-facts.ts"
|
|
44
45
|
import { RULE_CODES } from "./rules/codes.ts"
|
|
45
46
|
import { sourceIndex } from "./rules/index.ts"
|
|
46
|
-
import { filesOutsideProgram, splitListedFiles } from "./typecheck-coverage.ts"
|
|
47
|
+
import { filesOutsideProgram, splitListedFiles, typecheckProjects } from "./typecheck-coverage.ts"
|
|
47
48
|
|
|
48
49
|
export type {
|
|
49
50
|
CheckAnalysisInput,
|
|
@@ -95,6 +96,10 @@ interface TypecheckResult {
|
|
|
95
96
|
/** tsconfig.json exists but no `typescript` install was found walking up from cwd. The contract
|
|
96
97
|
* gate could not run - the caller surfaces this as a FAILING diagnostic, never a silent skip. */
|
|
97
98
|
readonly missingTypeScript?: boolean
|
|
99
|
+
/** No tsconfig.json at the project root. Fails the check only when TypeScript sources exist. */
|
|
100
|
+
readonly missingTsconfig?: boolean
|
|
101
|
+
/** TypeScript sources the scan found with no tsconfig.json to typecheck them. */
|
|
102
|
+
readonly sourcesWithoutTsconfig?: number
|
|
98
103
|
/** Every file in the compiler's program, absolute. Absent when the compiler listed none. */
|
|
99
104
|
readonly programFiles?: readonly string[]
|
|
100
105
|
/** Zoned TypeScript files outside the program, project-relative: the typecheck never read them. */
|
|
@@ -119,11 +124,25 @@ function resolveTscBin(cwd: string): string | undefined {
|
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Run the project's own `tsc --noEmit` over each tsconfig `typecheckProjects` names, one program at a
|
|
129
|
+
* time, if TypeScript and a tsconfig are present. Never auto-installs.
|
|
130
|
+
*/
|
|
131
|
+
async function typecheck(
|
|
132
|
+
cwd: string,
|
|
133
|
+
signal?: AbortSignal,
|
|
134
|
+
configured?: readonly string[],
|
|
135
|
+
): Promise<TypecheckResult> {
|
|
136
|
+
const projects = typecheckProjects(cwd, configured)
|
|
137
|
+
if (projects.missing.length > 0) {
|
|
138
|
+
return {
|
|
139
|
+
ran: true,
|
|
140
|
+
ok: false,
|
|
141
|
+
output: `nifra.check.json "tsconfigs" names ${projects.missing.map((path) => `"${path}"`).join(", ")}, which does not exist`,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (projects.paths.length === 0)
|
|
145
|
+
return { ran: false, ok: true, missingTsconfig: true, note: "no tsconfig.json" }
|
|
127
146
|
// Routes import their generated `./+types` modules; bring them up to date before tsc reads them.
|
|
128
147
|
const { refreshRouteTypes } = await import("./route-types.ts")
|
|
129
148
|
refreshRouteTypes(cwd, () => {})
|
|
@@ -136,11 +155,28 @@ async function typecheck(cwd: string, signal?: AbortSignal): Promise<TypecheckRe
|
|
|
136
155
|
note: "typescript not installed (run: bun add -d typescript)",
|
|
137
156
|
}
|
|
138
157
|
}
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
const runs: TypecheckResult[] = []
|
|
159
|
+
for (const tsconfig of projects.paths) {
|
|
160
|
+
let run = await runTsc(cwd, tscBin, tsconfig, true, signal)
|
|
161
|
+
// A compiler that rejects `--listFiles` still gets its typecheck; only the coverage check is lost.
|
|
162
|
+
if (!run.ok && !run.cancelled && /TS50(?:23|25)\b[^\n]*listFiles/.test(run.output ?? ""))
|
|
163
|
+
run = await runTsc(cwd, tscBin, tsconfig, false, signal)
|
|
164
|
+
if (run.cancelled === true) return run
|
|
165
|
+
runs.push(run)
|
|
166
|
+
}
|
|
167
|
+
const [only] = runs
|
|
168
|
+
if (runs.length === 1 && only !== undefined) return only
|
|
169
|
+
// A file two programs both hold reports each error twice; keep one copy of each diagnostic block.
|
|
170
|
+
const blocks = new Set(
|
|
171
|
+
runs.flatMap((run) => (run.output ?? "").split(/\n(?=\S)/).filter((block) => block !== "")),
|
|
172
|
+
)
|
|
173
|
+
const programFiles = [...new Set(runs.flatMap((run) => run.programFiles ?? []))]
|
|
174
|
+
const merged: TypecheckResult = {
|
|
175
|
+
ran: true,
|
|
176
|
+
ok: runs.every((run) => run.ok),
|
|
177
|
+
output: [...blocks].join("\n"),
|
|
178
|
+
}
|
|
179
|
+
return programFiles.length > 0 ? { ...merged, programFiles } : merged
|
|
144
180
|
}
|
|
145
181
|
|
|
146
182
|
async function runTsc(
|
|
@@ -216,6 +252,7 @@ async function loadCheckConfig(
|
|
|
216
252
|
const parsed = JSON.parse(await Bun.file(path).text()) as {
|
|
217
253
|
externalMounts?: unknown
|
|
218
254
|
rules?: unknown
|
|
255
|
+
tsconfigs?: unknown
|
|
219
256
|
}
|
|
220
257
|
const raw = Array.isArray(parsed.externalMounts) ? parsed.externalMounts : []
|
|
221
258
|
const externalMounts = raw
|
|
@@ -268,7 +305,25 @@ async function loadCheckConfig(
|
|
|
268
305
|
}
|
|
269
306
|
}
|
|
270
307
|
}
|
|
271
|
-
|
|
308
|
+
let tsconfigs: readonly string[] | undefined
|
|
309
|
+
if (parsed.tsconfigs !== undefined) {
|
|
310
|
+
if (
|
|
311
|
+
Array.isArray(parsed.tsconfigs) &&
|
|
312
|
+
parsed.tsconfigs.length > 0 &&
|
|
313
|
+
parsed.tsconfigs.every(
|
|
314
|
+
(entry): entry is string =>
|
|
315
|
+
typeof entry === "string" && entry.endsWith(".json") && !isAbsolute(entry),
|
|
316
|
+
)
|
|
317
|
+
)
|
|
318
|
+
tsconfigs = parsed.tsconfigs
|
|
319
|
+
else
|
|
320
|
+
warnings.push(
|
|
321
|
+
'`tsconfigs` must be a non-empty array of tsconfig paths relative to the project, such as ["tsconfig.json"] - ignored',
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
const config: CheckConfig =
|
|
325
|
+
tsconfigs === undefined ? { externalMounts, rules } : { externalMounts, rules, tsconfigs }
|
|
326
|
+
return { config, warnings }
|
|
272
327
|
} catch (error) {
|
|
273
328
|
return {
|
|
274
329
|
config: empty,
|
|
@@ -309,6 +364,16 @@ async function collectContractFacts(cwd: string): Promise<ContractCheckFacts> {
|
|
|
309
364
|
}
|
|
310
365
|
}
|
|
311
366
|
|
|
367
|
+
/** A project whose TypeScript no tsconfig.json covers has no typecheck to pass: the gate fails. */
|
|
368
|
+
function withoutTsconfig(
|
|
369
|
+
result: TypecheckResult,
|
|
370
|
+
sourceFiles: ReadonlyArray<{ readonly file: string }>,
|
|
371
|
+
): TypecheckResult {
|
|
372
|
+
if (result.missingTsconfig !== true) return result
|
|
373
|
+
const sources = sourceFiles.filter(({ file }) => !/\.d\.[cm]?ts$/.test(file)).length
|
|
374
|
+
return sources === 0 ? result : { ...result, ok: false, sourcesWithoutTsconfig: sources }
|
|
375
|
+
}
|
|
376
|
+
|
|
312
377
|
/** Record the zoned files the compiler's program left out, minus the typecheck rule's `ignore` globs. */
|
|
313
378
|
function withProgramCoverage(
|
|
314
379
|
cwd: string,
|
|
@@ -354,7 +419,7 @@ async function buildProjectScan(
|
|
|
354
419
|
const [typecheckRun, _, doctor, manifestDrift, contracts] = await Promise.all([
|
|
355
420
|
opts.lintsOnly
|
|
356
421
|
? Promise.resolve<TypecheckResult>({ ran: false, ok: true, note: "lints-only mode" })
|
|
357
|
-
: typecheck(cwd, opts.signal),
|
|
422
|
+
: typecheck(cwd, opts.signal, checkConfig.tsconfigs),
|
|
358
423
|
walkSource(
|
|
359
424
|
cwd,
|
|
360
425
|
(rel, content) => {
|
|
@@ -376,11 +441,10 @@ async function buildProjectScan(
|
|
|
376
441
|
|
|
377
442
|
// tsc compiles TypeScript sources only; the JavaScript and component files the scan reads are no
|
|
378
443
|
// program's to cover.
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
typecheckRun,
|
|
382
|
-
|
|
383
|
-
checkConfig,
|
|
444
|
+
const typeScriptSources = sourceFiles.filter(({ file }) => /\.[cm]?tsx?$/.test(file))
|
|
445
|
+
const typecheckResult = withoutTsconfig(
|
|
446
|
+
withProgramCoverage(cwd, typecheckRun, typeScriptSources, checkConfig),
|
|
447
|
+
typeScriptSources,
|
|
384
448
|
)
|
|
385
449
|
|
|
386
450
|
// TypeScript 7's unstable API materializes source files through one project session. Build the
|
|
@@ -390,7 +454,24 @@ async function buildProjectScan(
|
|
|
390
454
|
const loadedTypeScript = await loadProjectTypeScript(cwd, opts.loadTypeScript, source)
|
|
391
455
|
try {
|
|
392
456
|
const sqlCompiler = loadedTypeScript.compiler
|
|
393
|
-
|
|
457
|
+
// Resolved modules stay project-relative, as the scanned files are: the zone of a path is read
|
|
458
|
+
// from its folders, and a checkout under a folder named `backend/` must not make it all backend.
|
|
459
|
+
// The resolver answers with real paths, so the project root is read as one too.
|
|
460
|
+
const realCwd = (() => {
|
|
461
|
+
try {
|
|
462
|
+
return realpathSync(cwd)
|
|
463
|
+
} catch {
|
|
464
|
+
return cwd
|
|
465
|
+
}
|
|
466
|
+
})()
|
|
467
|
+
const resolveSpecifier = createSpecifierResolver()
|
|
468
|
+
const sourceFacts =
|
|
469
|
+
sqlCompiler === undefined
|
|
470
|
+
? undefined
|
|
471
|
+
: createSourceFacts(sqlCompiler, {
|
|
472
|
+
keepsTypeOnlyImports: (file) =>
|
|
473
|
+
resolveSpecifier.keepsTypeOnlyImports(isAbsolute(file) ? file : join(realCwd, file)),
|
|
474
|
+
})
|
|
394
475
|
const sqlImports = sqlCompiler === undefined ? undefined : createProjectSqlImports(cwd)
|
|
395
476
|
const project = new Map(
|
|
396
477
|
sourceFiles.map(({ file, content }) => [file.replaceAll("\\", "/"), content]),
|
|
@@ -403,17 +484,6 @@ async function buildProjectScan(
|
|
|
403
484
|
interpolatedSql.push(...scanSqlSites(file, content, sqlCompiler, sqlImports))
|
|
404
485
|
}
|
|
405
486
|
|
|
406
|
-
// Resolved modules stay project-relative, as the scanned files are: the zone of a path is read
|
|
407
|
-
// from its folders, and a checkout under a folder named `backend/` must not make it all backend.
|
|
408
|
-
// The resolver answers with real paths, so the project root is read as one too.
|
|
409
|
-
const realCwd = (() => {
|
|
410
|
-
try {
|
|
411
|
-
return realpathSync(cwd)
|
|
412
|
-
} catch {
|
|
413
|
-
return cwd
|
|
414
|
-
}
|
|
415
|
-
})()
|
|
416
|
-
const resolveSpecifier = createSpecifierResolver()
|
|
417
487
|
const projectPath = (path: string): string => {
|
|
418
488
|
const rel = relative(realCwd, path).replaceAll("\\", "/")
|
|
419
489
|
return rel.startsWith("../") || isAbsolute(rel) ? path : rel
|
|
@@ -439,7 +509,7 @@ async function buildProjectScan(
|
|
|
439
509
|
// An app's `clientModule` is browser code wherever it lives: the generated client entry imports it.
|
|
440
510
|
const browserRoots = new Set<string>()
|
|
441
511
|
for (const app of appDirs(source.files)) {
|
|
442
|
-
const entry = clientModuleRoot(cwd, app, resolveSpecifier)
|
|
512
|
+
const entry = clientModuleRoot(cwd, app, resolveSpecifier, sqlCompiler)
|
|
443
513
|
if (entry === undefined) continue
|
|
444
514
|
const rel = projectPath(entry.file)
|
|
445
515
|
if (isBrowserSource(rel) || browserRoots.has(rel)) continue
|
|
@@ -448,28 +518,24 @@ async function buildProjectScan(
|
|
|
448
518
|
browserRoots.add(rel)
|
|
449
519
|
browserModules.push({ rel, content })
|
|
450
520
|
}
|
|
451
|
-
//
|
|
521
|
+
// The side the package gives the entry the import names: package-wide, or per entry.
|
|
452
522
|
const backendPackage = (fromFile: string, specifier: string): boolean => {
|
|
453
523
|
const name = specifierPackage(specifier)
|
|
454
524
|
if (name === undefined) return false
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
const parent = dirname(dir)
|
|
471
|
-
if (parent === dir) return false
|
|
472
|
-
dir = parent
|
|
525
|
+
const manifest = installedManifest(
|
|
526
|
+
isAbsolute(fromFile) ? fromFile : join(realCwd, fromFile),
|
|
527
|
+
name,
|
|
528
|
+
)
|
|
529
|
+
if (manifest === undefined) return false
|
|
530
|
+
try {
|
|
531
|
+
const nifra: unknown = JSON.parse(readFileSync(manifest, "utf8"))?.nifra
|
|
532
|
+
return (
|
|
533
|
+
typeof nifra === "object" &&
|
|
534
|
+
nifra !== null &&
|
|
535
|
+
declaredSide(Reflect.get(nifra, "environment"), specifier) === "backend"
|
|
536
|
+
)
|
|
537
|
+
} catch {
|
|
538
|
+
return false
|
|
473
539
|
}
|
|
474
540
|
}
|
|
475
541
|
const serverOnlyChains = createServerOnlyChains({
|
|
@@ -591,6 +657,11 @@ export function renderCheckReport(result: CheckResult): string[] {
|
|
|
591
657
|
`• intentional external mounts (not typed-client checked): ${result.externalMounts.join(", ")}`,
|
|
592
658
|
)
|
|
593
659
|
}
|
|
660
|
+
if (result.tsconfigs !== undefined) {
|
|
661
|
+
lines.push(
|
|
662
|
+
`• typecheck programs (nifra.check.json "tsconfigs"): ${result.tsconfigs.join(", ")}`,
|
|
663
|
+
)
|
|
664
|
+
}
|
|
594
665
|
for (const gap of result.knownGaps ?? []) {
|
|
595
666
|
lines.push(`• known gap, not capability-analyzed: ${gap.path} - ${gap.reason}`)
|
|
596
667
|
}
|