@nifrajs/cli 5.8.0 → 5.9.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 +134 -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-scan.d.ts +2 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +54 -86
- 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 +20 -23
- 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 +42 -13
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -30
- 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.map +1 -1
- package/dist/internal/source-facts.js +28 -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 +6 -1
- package/dist/load.d.ts.map +1 -1
- 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-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-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.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 +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +9 -13
- package/dist/review.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/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/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 +402 -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/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 +32 -2
- package/docs/llms-full.txt +749 -95
- package/docs/types.json +300 -61
- 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-scan.ts +65 -82
- package/src/check.ts +25 -23
- package/src/cli.ts +61 -13
- package/src/command-catalog.ts +22 -32
- 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 +39 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +6 -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-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.9.0.ts +42 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +12 -15
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- 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 +463 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
package/src/migrate-layout.ts
CHANGED
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
mkdirSync,
|
|
31
31
|
readdirSync,
|
|
32
32
|
readFileSync,
|
|
33
|
-
realpathSync,
|
|
34
33
|
renameSync,
|
|
35
34
|
rmdirSync,
|
|
36
35
|
rmSync,
|
|
@@ -45,8 +44,11 @@ import type * as TS from "typescript"
|
|
|
45
44
|
import { BACKEND_APP_FILE, CONFIG_FILE, FRAMEWORK_FILE, retiredRootFiles } from "./app-files.ts"
|
|
46
45
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
47
46
|
import { configPathReader, type StaticConfigPath } from "./internal/config-paths.ts"
|
|
47
|
+
import { escapeRegExp } from "./internal/escape-regexp.ts"
|
|
48
48
|
import { createKindProbe, hasWebConfig } from "./internal/nifra-project.ts"
|
|
49
|
+
import { toPosix } from "./internal/posix-path.ts"
|
|
49
50
|
import { createSpecifierResolver, isFile } from "./internal/project-specifiers.ts"
|
|
51
|
+
import { realpathOrSelf } from "./internal/realpath-or-self.ts"
|
|
50
52
|
import { importTypeScript } from "./internal/typescript-import.ts"
|
|
51
53
|
import { type OutputSchemaEntry, planOutputSchemas } from "./output-schemas.ts"
|
|
52
54
|
import { missingOutputSchemas } from "./rules/data-guard.ts"
|
|
@@ -171,8 +173,6 @@ export interface LayoutMigrationOptions {
|
|
|
171
173
|
/** A file's text, as the migration sees it before writing. */
|
|
172
174
|
type Files = Map<string, string>
|
|
173
175
|
|
|
174
|
-
const toPosix = (path: string): string => path.replaceAll("\\", "/")
|
|
175
|
-
|
|
176
176
|
/** A specifier without its `?query` or `#hash`; a leading `#` names a package.json import. Cut by
|
|
177
177
|
* index, since `/[?#].*$/` retries from every `#` and is quadratic on a long run of them. */
|
|
178
178
|
const withoutQuery = (specifier: string): string => {
|
|
@@ -466,8 +466,6 @@ function filterExportList(
|
|
|
466
466
|
return `${leading}export ${node.isTypeOnly ? "type " : ""}{ ${kept.join(", ")} }${from}${terminatorOf(sf, node)}`
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
-
const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
470
|
-
|
|
471
469
|
const joinStatements = (texts: readonly string[]): string => {
|
|
472
470
|
const body = texts.join("").replace(/^\s*\n/, "")
|
|
473
471
|
return body.endsWith("\n") ? body : `${body}\n`
|
|
@@ -1044,6 +1042,21 @@ function scriptBlocks(
|
|
|
1044
1042
|
return blocks
|
|
1045
1043
|
}
|
|
1046
1044
|
|
|
1045
|
+
/** A replacement of the source between `start` and `end`. */
|
|
1046
|
+
interface TextEdit {
|
|
1047
|
+
start: number
|
|
1048
|
+
end: number
|
|
1049
|
+
text: string
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/** `text` with every edit made, last offset first so the ones before it still point where they did. */
|
|
1053
|
+
function applyEdits(text: string, edits: TextEdit[]): string {
|
|
1054
|
+
let out = text
|
|
1055
|
+
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
1056
|
+
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
|
|
1057
|
+
return out
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1047
1060
|
// ---------------------------------------------------------------------------------------------------
|
|
1048
1061
|
// Import graph + zoning
|
|
1049
1062
|
// ---------------------------------------------------------------------------------------------------
|
|
@@ -1374,7 +1387,7 @@ function rebaseShellPaths(
|
|
|
1374
1387
|
locate: (target: string) => string,
|
|
1375
1388
|
): { readonly text: string; readonly unfollowed: string | undefined } {
|
|
1376
1389
|
let unfollowed: string | undefined
|
|
1377
|
-
const edits:
|
|
1390
|
+
const edits: TextEdit[] = []
|
|
1378
1391
|
for (const match of text.matchAll(SHELL_OWN_DIR)) {
|
|
1379
1392
|
const start = match.index + match[0].length
|
|
1380
1393
|
const trailing = /^\/([\w.@-]+(?:\/[\w.@-]+)*\/?)/.exec(text.slice(start))?.[1]
|
|
@@ -1457,7 +1470,7 @@ function rebaseOwnPaths(
|
|
|
1457
1470
|
true,
|
|
1458
1471
|
to.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
1459
1472
|
)
|
|
1460
|
-
const edits:
|
|
1473
|
+
const edits: TextEdit[] = []
|
|
1461
1474
|
const followed: Array<readonly [number, number]> = []
|
|
1462
1475
|
const aliases = ownDirAliases(ts, sf)
|
|
1463
1476
|
const isOwnDir = (node: TS.Node | undefined): node is TS.Expression =>
|
|
@@ -1571,10 +1584,7 @@ function rebaseOwnPaths(
|
|
|
1571
1584
|
const unfollowed = [...text.matchAll(new RegExp(SELF_LOCATION.source, "g"))].find(
|
|
1572
1585
|
(match) => !followed.some(([start, end]) => start <= match.index && match.index < end),
|
|
1573
1586
|
)?.[0]
|
|
1574
|
-
|
|
1575
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
1576
|
-
next = next.slice(0, edit.start) + edit.text + next.slice(edit.end)
|
|
1577
|
-
return { text: next, unfollowed }
|
|
1587
|
+
return { text: applyEdits(text, edits), unfollowed }
|
|
1578
1588
|
}
|
|
1579
1589
|
|
|
1580
1590
|
/** Rewrite one relative specifier from `from`'s new location to `target`'s new location, keeping the
|
|
@@ -1660,7 +1670,7 @@ function redirectMovedImports(
|
|
|
1660
1670
|
true,
|
|
1661
1671
|
file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
1662
1672
|
)
|
|
1663
|
-
const edits:
|
|
1673
|
+
const edits: TextEdit[] = []
|
|
1664
1674
|
const issues: string[] = []
|
|
1665
1675
|
const mentioned = (split: SplitTarget, pattern: (name: string) => RegExp): string[] =>
|
|
1666
1676
|
[...split.moved].filter((name) => pattern(escapeRegExp(name)).test(text)).sort()
|
|
@@ -1756,10 +1766,7 @@ function redirectMovedImports(
|
|
|
1756
1766
|
ts.forEachChild(node, visit)
|
|
1757
1767
|
}
|
|
1758
1768
|
visit(sf)
|
|
1759
|
-
|
|
1760
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
1761
|
-
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
|
|
1762
|
-
return { text: out, issues, redirects }
|
|
1769
|
+
return { text: applyEdits(text, edits), issues, redirects }
|
|
1763
1770
|
}
|
|
1764
1771
|
|
|
1765
1772
|
/**
|
|
@@ -1822,7 +1829,7 @@ function dynamicReads(
|
|
|
1822
1829
|
function workspacePattern(glob: string): RegExp {
|
|
1823
1830
|
const source = glob
|
|
1824
1831
|
.replace(/^\.\//, "")
|
|
1825
|
-
.replace(
|
|
1832
|
+
.replace(/(?<!\/)\/+$/, "")
|
|
1826
1833
|
.split("/")
|
|
1827
1834
|
.map((segment) =>
|
|
1828
1835
|
segment === "**"
|
|
@@ -1989,12 +1996,7 @@ function rewriteImports(
|
|
|
1989
1996
|
text: string,
|
|
1990
1997
|
rewrite: (specifier: string) => string | undefined,
|
|
1991
1998
|
): string {
|
|
1992
|
-
const replace = (
|
|
1993
|
-
code: string,
|
|
1994
|
-
offset: number,
|
|
1995
|
-
out: Array<{ start: number; end: number; text: string }>,
|
|
1996
|
-
kind: TS.ScriptKind,
|
|
1997
|
-
): void => {
|
|
1999
|
+
const replace = (code: string, offset: number, out: TextEdit[], kind: TS.ScriptKind): void => {
|
|
1998
2000
|
const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true, kind)
|
|
1999
2001
|
const visit = (node: TS.Node): void => {
|
|
2000
2002
|
let literal: TS.StringLiteralLike | undefined
|
|
@@ -2032,39 +2034,34 @@ function rewriteImports(
|
|
|
2032
2034
|
}
|
|
2033
2035
|
visit(sf)
|
|
2034
2036
|
}
|
|
2035
|
-
const edits:
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
} else if (file.endsWith(".css")) {
|
|
2040
|
-
for (const match of text.matchAll(/(@import\s+(?:url\()?["'])([^"']+)["']/g)) {
|
|
2037
|
+
const edits: TextEdit[] = []
|
|
2038
|
+
// A match's group 2 is the specifier; group 1 is everything before it.
|
|
2039
|
+
const rewriteMatches = (pattern: RegExp): void => {
|
|
2040
|
+
for (const match of text.matchAll(pattern)) {
|
|
2041
2041
|
const next = rewrite(match[2] ?? "")
|
|
2042
2042
|
if (next !== undefined) {
|
|
2043
2043
|
const start = (match.index ?? 0) + (match[1] ?? "").length
|
|
2044
2044
|
edits.push({ start, end: start + (match[2] ?? "").length, text: next })
|
|
2045
2045
|
}
|
|
2046
2046
|
}
|
|
2047
|
+
}
|
|
2048
|
+
if (/\.(?:svelte|vue)$/.test(file)) {
|
|
2049
|
+
for (const block of scriptBlocks(text))
|
|
2050
|
+
replace(text.slice(block.start, block.end), block.start, edits, ts.ScriptKind.TS)
|
|
2051
|
+
} else if (file.endsWith(".css")) {
|
|
2052
|
+
rewriteMatches(/(@import\s+(?:url\()?["'])([^"']+)["']/g)
|
|
2047
2053
|
} else if (file.endsWith(".mdx")) {
|
|
2048
|
-
|
|
2049
|
-
const next = rewrite(match[2] ?? "")
|
|
2050
|
-
if (next !== undefined) {
|
|
2051
|
-
const start = (match.index ?? 0) + (match[1] ?? "").length
|
|
2052
|
-
edits.push({ start, end: start + (match[2] ?? "").length, text: next })
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2054
|
+
rewriteMatches(/^((?:import|export)\s[^\n]*?from\s+["'])([^"']+)["']/gm)
|
|
2055
2055
|
} else if (/\.[cm]?[jt]sx?$/.test(file)) {
|
|
2056
2056
|
replace(text, 0, edits, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS)
|
|
2057
2057
|
}
|
|
2058
|
-
|
|
2059
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
2060
|
-
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
|
|
2061
|
-
return out
|
|
2058
|
+
return applyEdits(text, edits)
|
|
2062
2059
|
}
|
|
2063
2060
|
|
|
2064
2061
|
/** `ServerOnly` imported from `@nifrajs/web` becomes `BackendOnly`, along with every use of it. */
|
|
2065
2062
|
function renameRetiredTypes(ts: typeof TS, file: string, text: string): string {
|
|
2066
2063
|
if (!text.includes("ServerOnly")) return text
|
|
2067
|
-
const edits:
|
|
2064
|
+
const edits: TextEdit[] = []
|
|
2068
2065
|
const scan = (code: string, offset: number, kind: TS.ScriptKind): void => {
|
|
2069
2066
|
const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true, kind)
|
|
2070
2067
|
const rename = (node: TS.Node): void => {
|
|
@@ -2103,10 +2100,7 @@ function renameRetiredTypes(ts: typeof TS, file: string, text: string): string {
|
|
|
2103
2100
|
} else if (/\.[cm]?[jt]sx?$/.test(file)) {
|
|
2104
2101
|
scan(text, 0, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS)
|
|
2105
2102
|
}
|
|
2106
|
-
|
|
2107
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
2108
|
-
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
|
|
2109
|
-
return out
|
|
2103
|
+
return applyEdits(text, edits)
|
|
2110
2104
|
}
|
|
2111
2105
|
|
|
2112
2106
|
// ---------------------------------------------------------------------------------------------------
|
|
@@ -2363,13 +2357,7 @@ export async function migrateLayout(
|
|
|
2363
2357
|
const resolver = createSpecifierResolver({
|
|
2364
2358
|
moduleExists: (path) => knownPaths.has(path) || isFile(path),
|
|
2365
2359
|
})
|
|
2366
|
-
const realRoot = (
|
|
2367
|
-
try {
|
|
2368
|
-
return realpathSync(root)
|
|
2369
|
-
} catch {
|
|
2370
|
-
return root
|
|
2371
|
-
}
|
|
2372
|
-
})()
|
|
2360
|
+
const realRoot = realpathOrSelf(root)
|
|
2373
2361
|
/** An app file as the migration names it, from a path the resolver found (real, or as planned). */
|
|
2374
2362
|
const appFile = (path: string | undefined): string | undefined => {
|
|
2375
2363
|
if (path === undefined) return undefined
|
|
@@ -2821,7 +2809,7 @@ export async function migrateLayout(
|
|
|
2821
2809
|
const at = newPath(file)
|
|
2822
2810
|
const text = final.get(at)
|
|
2823
2811
|
if (text === undefined) continue
|
|
2824
|
-
const edits:
|
|
2812
|
+
const edits: TextEdit[] = []
|
|
2825
2813
|
for (const call of globCalls(ts, at, text)) {
|
|
2826
2814
|
if (!call.literal) continue
|
|
2827
2815
|
const written = call.patterns.map((pattern) => pattern.text)
|
|
@@ -2848,10 +2836,7 @@ export async function migrateLayout(
|
|
|
2848
2836
|
})
|
|
2849
2837
|
}
|
|
2850
2838
|
if (edits.length === 0) continue
|
|
2851
|
-
|
|
2852
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
2853
|
-
updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
|
|
2854
|
-
final.set(at, updated)
|
|
2839
|
+
final.set(at, applyEdits(text, edits))
|
|
2855
2840
|
if (!moveMap.has(file) && !rewritten.includes(file)) rewritten.push(file)
|
|
2856
2841
|
}
|
|
2857
2842
|
|
|
@@ -2861,7 +2846,7 @@ export async function migrateLayout(
|
|
|
2861
2846
|
const at = newPath(configFile)
|
|
2862
2847
|
const text = final.get(at)
|
|
2863
2848
|
if (text === undefined || !next.has(configFile)) continue
|
|
2864
|
-
const edits:
|
|
2849
|
+
const edits: TextEdit[] = []
|
|
2865
2850
|
for (const entry of configEntries(ts, at, text)) {
|
|
2866
2851
|
if (entry.span === undefined) continue
|
|
2867
2852
|
const target = resolveAny("nifra.config.ts", entry.path)
|
|
@@ -2872,10 +2857,7 @@ export async function migrateLayout(
|
|
|
2872
2857
|
if (value !== undefined) edits.push({ start: entry.span[0], end: entry.span[1], text: value })
|
|
2873
2858
|
}
|
|
2874
2859
|
if (edits.length === 0) continue
|
|
2875
|
-
|
|
2876
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
2877
|
-
updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
|
|
2878
|
-
final.set(at, updated)
|
|
2860
|
+
final.set(at, applyEdits(text, edits))
|
|
2879
2861
|
if (!moveMap.has(configFile) && !rewritten.includes(configFile)) rewritten.push(configFile)
|
|
2880
2862
|
}
|
|
2881
2863
|
|
|
@@ -3304,7 +3286,10 @@ const matchers = new Map<string, (file: string) => boolean>()
|
|
|
3304
3286
|
function matches(pattern: string, file: string): boolean {
|
|
3305
3287
|
let match = matchers.get(pattern)
|
|
3306
3288
|
if (match === undefined) {
|
|
3307
|
-
let spec = pattern
|
|
3289
|
+
let spec = pattern
|
|
3290
|
+
.replaceAll("\\", "/")
|
|
3291
|
+
.replace(/^\.\//, "")
|
|
3292
|
+
.replace(/(?<!\/)\/+$/, "")
|
|
3308
3293
|
if (spec === "" || spec === ".") match = () => true
|
|
3309
3294
|
else if (!/[*?]/.test(spec)) {
|
|
3310
3295
|
const folder = `${spec}/`
|
|
@@ -3398,7 +3383,7 @@ function followTsconfigs(
|
|
|
3398
3383
|
const inherited = parent === undefined ? undefined : settled.get(parent)
|
|
3399
3384
|
const extendsOther = base !== undefined && inherited === undefined
|
|
3400
3385
|
|
|
3401
|
-
const edits:
|
|
3386
|
+
const edits: TextEdit[] = []
|
|
3402
3387
|
const own = new Map<string, { before: string[]; after: string[] }>()
|
|
3403
3388
|
let malformed: string | undefined
|
|
3404
3389
|
for (const key of ["include", "exclude", "files"]) {
|
|
@@ -3427,9 +3412,7 @@ function followTsconfigs(
|
|
|
3427
3412
|
}
|
|
3428
3413
|
own.set(key, lists)
|
|
3429
3414
|
}
|
|
3430
|
-
let updated = text
|
|
3431
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
3432
|
-
updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
|
|
3415
|
+
let updated = applyEdits(text, edits)
|
|
3433
3416
|
const changes: string[] = []
|
|
3434
3417
|
if (edits.length > 0) changes.push(`${edits.length} file path(s) follow their moved files`)
|
|
3435
3418
|
|
|
@@ -3780,7 +3763,7 @@ function rewritePackagePaths(
|
|
|
3780
3763
|
`(?<![\\w.@/-])(\\./)?(${ordered.map(([from]) => escapeRegExp(from)).join("|")})(?![\\w/-]|\\.\\w)`,
|
|
3781
3764
|
"g",
|
|
3782
3765
|
)
|
|
3783
|
-
const edits:
|
|
3766
|
+
const edits: TextEdit[] = []
|
|
3784
3767
|
let count = 0
|
|
3785
3768
|
const visit = (node: TS.Node, field: string): void => {
|
|
3786
3769
|
if (ts.isStringLiteral(node)) {
|
|
@@ -3813,10 +3796,7 @@ function rewritePackagePaths(
|
|
|
3813
3796
|
if (!ts.isPropertyAssignment(property) || !ts.isStringLiteral(property.name)) continue
|
|
3814
3797
|
if (PACKAGE_PATH_FIELDS.has(property.name.text)) visit(property.initializer, property.name.text)
|
|
3815
3798
|
}
|
|
3816
|
-
|
|
3817
|
-
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
3818
|
-
next = next.slice(0, edit.start) + edit.text + next.slice(edit.end)
|
|
3819
|
-
return { text: next, count }
|
|
3799
|
+
return { text: applyEdits(text, edits), count }
|
|
3820
3800
|
}
|
|
3821
3801
|
|
|
3822
3802
|
/** Tailwind `content` globs that matched a moved file at its old path and match nothing at its new one. */
|
package/src/output-schemas.ts
CHANGED
|
@@ -15,6 +15,8 @@ import { isSensitiveFieldName } from "@nifrajs/web/zones"
|
|
|
15
15
|
import type * as TSApi from "typescript"
|
|
16
16
|
import { codePositionMask } from "./check-scan.ts"
|
|
17
17
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
18
|
+
import { lineAt } from "./internal/line-at.ts"
|
|
19
|
+
import { toPosix } from "./internal/posix-path.ts"
|
|
18
20
|
import {
|
|
19
21
|
loadProjectTypeScript,
|
|
20
22
|
type TypeScriptApi,
|
|
@@ -480,7 +482,7 @@ function schemaTokens(text: string): string {
|
|
|
480
482
|
i++
|
|
481
483
|
}
|
|
482
484
|
}
|
|
483
|
-
return out.replace(/,(?=[}\])])/g, "").replace(
|
|
485
|
+
return out.replace(/,(?=[}\])])/g, "").replace(/(?<!;);+$/, "")
|
|
484
486
|
}
|
|
485
487
|
|
|
486
488
|
function declarationText(schema: OutputExport, fn: RouteFn, body: string): string {
|
|
@@ -506,8 +508,6 @@ interface ProbeResult {
|
|
|
506
508
|
readonly warnings: readonly string[]
|
|
507
509
|
}
|
|
508
510
|
|
|
509
|
-
const posix = (path: string): string => path.replaceAll("\\", "/")
|
|
510
|
-
|
|
511
511
|
const PROBE_HELPERS = [
|
|
512
512
|
"type __NifraReturned<M, F extends string> = M extends { readonly [K in F]: (...args: any) => infer R } ? Awaited<R> : never",
|
|
513
513
|
'type __NifraDeclared<M, N extends string> = M extends { readonly [K in N]: infer S } ? S extends { readonly "~standard": { readonly types?: infer T } } ? NonNullable<T> extends { readonly output: infer O } ? O : never : never : never',
|
|
@@ -520,7 +520,7 @@ function probeSource(routes: readonly ProbeRoute[]): {
|
|
|
520
520
|
const lines = [...PROBE_HELPERS]
|
|
521
521
|
const names = new Map<string, string>()
|
|
522
522
|
routes.forEach((route, i) => {
|
|
523
|
-
const rel =
|
|
523
|
+
const rel = toPosix(route.file)
|
|
524
524
|
lines.push(
|
|
525
525
|
`import type * as __nifra_m${i} from ${JSON.stringify(rel.startsWith(".") ? rel : `./${rel}`)}`,
|
|
526
526
|
)
|
|
@@ -701,7 +701,7 @@ async function readShapes(
|
|
|
701
701
|
let close: (() => Promise<void>) | undefined
|
|
702
702
|
try {
|
|
703
703
|
await writeFile(probePath, probe, "utf8")
|
|
704
|
-
const include = [...routes.map((route) =>
|
|
704
|
+
const include = [...routes.map((route) => toPosix(route.file)), basename(probePath)]
|
|
705
705
|
await writeFile(
|
|
706
706
|
probeConfigPath,
|
|
707
707
|
JSON.stringify(
|
|
@@ -810,7 +810,7 @@ function overlaidHost(
|
|
|
810
810
|
contents: ReadonlyMap<string, string>,
|
|
811
811
|
): TSApi.CompilerHost {
|
|
812
812
|
const host = ts.createCompilerHost(options, true)
|
|
813
|
-
const key = (file: string): string =>
|
|
813
|
+
const key = (file: string): string => toPosix(ts.sys.resolvePath(file))
|
|
814
814
|
const overlay = new Map([...contents].map(([file, text]) => [key(file), text]))
|
|
815
815
|
const folders = new Set<string>()
|
|
816
816
|
for (const file of overlay.keys())
|
|
@@ -893,7 +893,6 @@ interface Target {
|
|
|
893
893
|
readonly declaration: SchemaDeclaration | null | undefined
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
-
const lineAt = (text: string, index: number): number => text.slice(0, index).split("\n").length
|
|
897
896
|
const lineStart = (text: string, index: number): number => text.lastIndexOf("\n", index - 1) + 1
|
|
898
897
|
|
|
899
898
|
/** The start of the comment block directly above the line at `start`, or `start`. */
|
|
@@ -1183,7 +1182,7 @@ function routeBackends(dir: string): string[] {
|
|
|
1183
1182
|
const routes = join(dir, "routes")
|
|
1184
1183
|
if (!existsSync(routes)) return []
|
|
1185
1184
|
return readdirSync(routes, { recursive: true, encoding: "utf8" })
|
|
1186
|
-
.map((file) =>
|
|
1185
|
+
.map((file) => toPosix(join("routes", file)))
|
|
1187
1186
|
.filter((file) => ROUTE_BACKEND_TS.test(file) && !file.split("/").includes("node_modules"))
|
|
1188
1187
|
.sort(codeUnitOrder)
|
|
1189
1188
|
}
|
package/src/port.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { Glob } from "bun"
|
|
|
19
19
|
import { stripComments } from "./check.ts"
|
|
20
20
|
import { readConfigTarget } from "./config-target.ts"
|
|
21
21
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
22
|
+
import { lineAt } from "./internal/line-at.ts"
|
|
22
23
|
|
|
23
24
|
/** The five deploy targets a nifra `site` app can build for (mirrors create-nifra's DEPLOY presets). */
|
|
24
25
|
export const TARGETS = ["bun", "node", "deno", "cloudflare", "vercel"] as const
|
|
@@ -211,10 +212,6 @@ export interface DetectedFeature {
|
|
|
211
212
|
readonly verdicts: Readonly<Record<Target, Verdict>>
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
/** Line number (1-based) of a string index. */
|
|
215
|
-
const lineAt = (content: string, index: number): number =>
|
|
216
|
-
content.slice(0, index).split("\n").length
|
|
217
|
-
|
|
218
215
|
// --- Detection signals (all matched against comment-stripped source so doc examples don't false-positive) ---
|
|
219
216
|
|
|
220
217
|
// A non-type import (static, side-effect, dynamic, or re-export) from one of these `@nifrajs/*` packages.
|
package/src/ppr-read-fix.ts
CHANGED
|
@@ -143,9 +143,9 @@ function holeNameOf(local: string): string | undefined {
|
|
|
143
143
|
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
144
144
|
.toLowerCase()
|
|
145
145
|
.replace(/[^a-z0-9]+/g, "-")
|
|
146
|
-
.replace(/^[^a-z]
|
|
146
|
+
.replace(/^[^a-z]+|(?<!-)-+$/g, "")
|
|
147
147
|
.slice(0, 28)
|
|
148
|
-
.replace(
|
|
148
|
+
.replace(/(?<!-)-+$/, "")
|
|
149
149
|
return HOLE_NAME.test(name) ? name : undefined
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { UpgradeRecipe } from "./index.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upgrade recipe for Nifra 5.9.
|
|
5
|
+
*
|
|
6
|
+
* One `serveStatic` with one set of options on every runtime: `@nifrajs/web`'s `servePublicDir` is
|
|
7
|
+
* removed, and `@nifrajs/node`'s `static` takes a function. The `serve-static` source rewrite moves
|
|
8
|
+
* each call, and `gracefulSignals` replaces `signals` on the Node and Deno adapters.
|
|
9
|
+
*/
|
|
10
|
+
export const recipe: UpgradeRecipe = {
|
|
11
|
+
version: "5.9.0",
|
|
12
|
+
pins: [
|
|
13
|
+
{ match: "@nifrajs/", to: "5.9.0" },
|
|
14
|
+
{ match: "create-nifra", to: "5.9.0" },
|
|
15
|
+
{ match: "nifra", to: "5.9.0" },
|
|
16
|
+
],
|
|
17
|
+
importMoves: [],
|
|
18
|
+
sourceRewrites: ["serve-static"],
|
|
19
|
+
// A servePublicDir call on Bun becomes @nifrajs/core/serve-static's, which an app may have had only
|
|
20
|
+
// through @nifrajs/web.
|
|
21
|
+
dependencyAdds: [
|
|
22
|
+
{ imports: ["@nifrajs/core/serve-static"], add: "@nifrajs/core", beside: ["@nifrajs/web"] },
|
|
23
|
+
],
|
|
24
|
+
affects: [
|
|
25
|
+
"@nifrajs/core",
|
|
26
|
+
"@nifrajs/schema",
|
|
27
|
+
"@nifrajs/mcp-db",
|
|
28
|
+
"@nifrajs/web",
|
|
29
|
+
"@nifrajs/node",
|
|
30
|
+
"@nifrajs/deno",
|
|
31
|
+
],
|
|
32
|
+
notes: [
|
|
33
|
+
'`servePublicDir` is removed from @nifrajs/web. Each call becomes `serveStatic({ dir, prefix: "/", fallthrough: true, hashedFiles, cacheControl: ONE_DAY })`, from @nifrajs/core/serve-static on Bun, and from @nifrajs/node or @nifrajs/deno in a file that serves on one of them: the same files, headers and misses as before. A `cache.hashed` other than the one-year immutable policy, or options built elsewhere, is listed to edit by hand. `serveStatic` answers `undefined` synchronously for a path no mount takes, so `handler(request).then(...)` needs `await` or `?.then`.',
|
|
34
|
+
"@nifrajs/node's `static` takes a function, as on Bun and Deno: mount objects passed to it are wrapped in `serveStatic(...)`, which keeps them on Node's own request. A mount object `static` names through a variable is listed; passing one throws a TypeError that names `serveStatic`.",
|
|
35
|
+
"`serve()` on @nifrajs/node and @nifrajs/deno takes `gracefulSignals` in place of `signals`, the name Bun's `server()` uses; `signals` throws a TypeError.",
|
|
36
|
+
"@nifrajs/deno exports `serveStatic`, which reads files with Deno's file API. The servers `nifra build` emits for bun, node and deno pass their runtime's `serveStatic` the same mounts, so a missing file under /assets/ or a listed public file answers `404 Not Found` on each.",
|
|
37
|
+
"Host validation is opt-in on Deno, as it is on Bun. Deno used to answer `400 invalid_host` for a malformed Host by default; it now routes the Host it received unless `server({ validateHost: true })` is set. Deno builds `Request.url` from the Host, so set it when Deno receives requests with an untrusted Host header.",
|
|
38
|
+
"Request targets are no longer normalized by default on Deno and Node. `/public/../admin` used to be routed as `/admin` on every runtime; Deno and Node now route the target as sent, as most frameworks do, and Bun still delivers a parsed URL. Set `server({ normalizeTarget: true })` on Deno or `serve(app, { normalizeTarget: true })` from @nifrajs/node when path guards, or a proxy that normalizes paths, sit in front of or inside the app.",
|
|
39
|
+
"The `date-time`, `date` and `time` string formats in @nifrajs/schema follow RFC 3339 in full: a day the calendar lacks (`2026-02-30`), an hour of `24` and an offset past `23:59` now fail validation. `t.date()` is a `Date` in code and an RFC 3339 string on the wire, in a request and a response alike.",
|
|
40
|
+
"@nifrajs/mcp-db/postgres checks the connected role's own privileges before every query and explain, and refuses a role that can read a masked column, an excluded table, a view over hidden data or a SECURITY DEFINER function with `NIFRA_DB_ROLE_GRANTS`. Run `nifra db role` for the grants a declaration needs, or name a function in `devDatabase.allowFunctions`.",
|
|
41
|
+
],
|
|
42
|
+
}
|
package/src/recipes/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { recipe as v5_5_0 } from "./5.5.0.ts"
|
|
|
20
20
|
import { recipe as v5_6_0 } from "./5.6.0.ts"
|
|
21
21
|
import { recipe as v5_7_0 } from "./5.7.0.ts"
|
|
22
22
|
import { recipe as v5_8_0 } from "./5.8.0.ts"
|
|
23
|
+
import { recipe as v5_9_0 } from "./5.9.0.ts"
|
|
23
24
|
|
|
24
25
|
/** A pin rule: every dependency whose name starts with `match` is set to version `to`. */
|
|
25
26
|
export interface PinRule {
|
|
@@ -69,6 +70,11 @@ export interface UpgradeRecipe {
|
|
|
69
70
|
readonly importMoves: readonly ImportMove[]
|
|
70
71
|
readonly dependencyAdds?: readonly DependencyAdd[]
|
|
71
72
|
readonly retiredMarkers?: readonly RetiredMarker[]
|
|
73
|
+
/**
|
|
74
|
+
* Syntax-tree rewrites (`../source-rewrites.ts`) by id, run on every source file after the import
|
|
75
|
+
* moves with the project's own TypeScript. An upgrade that needs one refuses to run without it.
|
|
76
|
+
*/
|
|
77
|
+
readonly sourceRewrites?: readonly string[]
|
|
72
78
|
/** Human notes printed after the plan - e.g. structural changes the runner deliberately can't do. */
|
|
73
79
|
readonly notes?: readonly string[]
|
|
74
80
|
/**
|
|
@@ -94,6 +100,7 @@ const RECIPES: Record<string, UpgradeRecipe> = {
|
|
|
94
100
|
[v5_6_0.version]: v5_6_0,
|
|
95
101
|
[v5_7_0.version]: v5_7_0,
|
|
96
102
|
[v5_8_0.version]: v5_8_0,
|
|
103
|
+
[v5_9_0.version]: v5_9_0,
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
export function getRecipe(version: string): UpgradeRecipe | undefined {
|
package/src/review.ts
CHANGED
|
@@ -17,6 +17,8 @@ import type { CheckResult } from "./check.ts"
|
|
|
17
17
|
import type { CommandCtx, CommandSpec } from "./command-catalog.ts"
|
|
18
18
|
import type { Diagnostic } from "./diagnostics.ts"
|
|
19
19
|
import { diagnosticCompatibilityOf, toSarifLog } from "./diagnostics.ts"
|
|
20
|
+
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
21
|
+
import { isRecord } from "./internal/record.ts"
|
|
20
22
|
import { RULE_CODES } from "./rules/codes.ts"
|
|
21
23
|
import { LEGACY_RULE_CODES } from "./rules/legacy.ts"
|
|
22
24
|
|
|
@@ -43,10 +45,6 @@ const REVIEW_INPUT_KEYS = new Set(["strict", "diff", "sarif", "fix", "dryRun", "
|
|
|
43
45
|
const CODE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
|
|
44
46
|
const SAFE_GIT_REF = /^[A-Za-z0-9][A-Za-z0-9._/@+-]{0,255}$/
|
|
45
47
|
|
|
46
|
-
function compareText(left: string, right: string): number {
|
|
47
|
-
return left < right ? -1 : left > right ? 1 : 0
|
|
48
|
-
}
|
|
49
|
-
|
|
50
48
|
const CHECK_IDS: readonly ReviewCheckId[] = [
|
|
51
49
|
"typecheck",
|
|
52
50
|
"typed-client",
|
|
@@ -199,10 +197,6 @@ const REVIEW_INPUT_SCHEMA = {
|
|
|
199
197
|
additionalProperties: false,
|
|
200
198
|
} as const
|
|
201
199
|
|
|
202
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
203
|
-
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
200
|
function optionalBoolean(raw: Record<string, unknown>, key: string): boolean | undefined {
|
|
207
201
|
const value = raw[key]
|
|
208
202
|
if (value === undefined) return undefined
|
|
@@ -485,7 +479,7 @@ async function diffScope(cwd: string, ref: string): Promise<ReviewScope> {
|
|
|
485
479
|
const untracked = await runGit(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])
|
|
486
480
|
if (!changed.ok || !untracked.ok) throw new ReviewInputError("invalid git scope")
|
|
487
481
|
const paths = [...new Set([...nulPaths(changed.stdout), ...nulPaths(untracked.stdout)])].sort(
|
|
488
|
-
|
|
482
|
+
codeUnitOrder,
|
|
489
483
|
)
|
|
490
484
|
if (
|
|
491
485
|
paths.some(
|
|
@@ -630,14 +624,17 @@ async function composeCollectedReport(
|
|
|
630
624
|
const leftLocation = normalizedLocation(cwd, left.diagnostic.file, left.diagnostic.line)
|
|
631
625
|
const rightLocation = normalizedLocation(cwd, right.diagnostic.file, right.diagnostic.line)
|
|
632
626
|
return (
|
|
633
|
-
|
|
634
|
-
|
|
627
|
+
codeUnitOrder(
|
|
628
|
+
normalizedCode(left.diagnostic.code),
|
|
629
|
+
normalizedCode(right.diagnostic.code),
|
|
630
|
+
) ||
|
|
631
|
+
codeUnitOrder(
|
|
635
632
|
normalizedSeverity(left.diagnostic.severity),
|
|
636
633
|
normalizedSeverity(right.diagnostic.severity),
|
|
637
634
|
) ||
|
|
638
|
-
|
|
635
|
+
codeUnitOrder(leftLocation?.path ?? "", rightLocation?.path ?? "") ||
|
|
639
636
|
(leftLocation?.line ?? 0) - (rightLocation?.line ?? 0) ||
|
|
640
|
-
|
|
637
|
+
codeUnitOrder(left.diagnostic.fix?.recipe ?? "", right.diagnostic.fix?.recipe ?? "") ||
|
|
641
638
|
left.index - right.index
|
|
642
639
|
)
|
|
643
640
|
})
|
|
@@ -773,7 +770,7 @@ async function composeCollectedReport(
|
|
|
773
770
|
findings.flatMap((finding) => (finding.fix === undefined ? [] : [finding.fix.recipe])),
|
|
774
771
|
),
|
|
775
772
|
]
|
|
776
|
-
.sort(
|
|
773
|
+
.sort(codeUnitOrder)
|
|
777
774
|
.map((recipe): ReviewFixResult => ({ recipe, status: "planned" }))
|
|
778
775
|
: undefined
|
|
779
776
|
const draft: ReviewReportDraft = {
|
|
@@ -825,7 +822,7 @@ async function safeChangedPaths(cwd: string, paths: readonly string[]): Promise<
|
|
|
825
822
|
if (relativePath.length > 0 && relativePath !== ".." && !relativePath.startsWith("../"))
|
|
826
823
|
result.push(relativePath)
|
|
827
824
|
}
|
|
828
|
-
return [...new Set(result)].sort(
|
|
825
|
+
return [...new Set(result)].sort(codeUnitOrder)
|
|
829
826
|
}
|
|
830
827
|
|
|
831
828
|
async function applyRequestedFixes(
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
* A contract imported from a workspace package is read through that package's `exports`.
|
|
9
9
|
* Re-exports on the way to a contract, and `...operations` spreads inside one, are followed.
|
|
10
10
|
*/
|
|
11
|
-
import { existsSync, readFileSync
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
12
12
|
import { join, relative } from "node:path"
|
|
13
13
|
import type * as TSApi from "typescript"
|
|
14
14
|
import { BACKEND_APP_FILE } from "../app-files.ts"
|
|
15
15
|
import { type Diagnostic, diagnostic } from "../diagnostics.ts"
|
|
16
16
|
import { createSpecifierResolver, type SpecifierResolver } from "../internal/project-specifiers.ts"
|
|
17
|
+
import { realpathOrSelf } from "../internal/realpath-or-self.ts"
|
|
17
18
|
import { scriptKindOf } from "../internal/script-kind.ts"
|
|
18
19
|
import { createExportedFileResolver } from "../internal/workspace-packages.ts"
|
|
19
20
|
import type { CheckRule } from "./index.ts"
|
|
@@ -233,13 +234,7 @@ export const contractVisibilityRule: CheckRule = {
|
|
|
233
234
|
return undefined
|
|
234
235
|
}
|
|
235
236
|
// The resolver answers with real paths, so the root is read as one to name files project-relative.
|
|
236
|
-
const realRoot = (
|
|
237
|
-
try {
|
|
238
|
-
return realpathSync(ctx.root)
|
|
239
|
-
} catch {
|
|
240
|
-
return ctx.root
|
|
241
|
-
}
|
|
242
|
-
})()
|
|
237
|
+
const realRoot = realpathOrSelf(ctx.root)
|
|
243
238
|
const parsedCache = new Map<string, Parsed | undefined>()
|
|
244
239
|
/** A project file, by its project-relative name, parsed with its contract bindings. */
|
|
245
240
|
const parse = (file: string, text: string | undefined): Parsed | undefined => {
|
package/src/rules/data-guard.ts
CHANGED
|
@@ -8,18 +8,17 @@
|
|
|
8
8
|
* refuses (an object, array, string, number or boolean) and a warning otherwise, since only running
|
|
9
9
|
* the loader proves what an expression evaluates to.
|
|
10
10
|
*/
|
|
11
|
-
import { realpathSync } from "node:fs"
|
|
12
11
|
import { isAbsolute, join, relative } from "node:path"
|
|
13
12
|
import { isSensitiveFieldName } from "@nifrajs/web/zones"
|
|
14
13
|
import { codePositionMask } from "../check-scan.ts"
|
|
15
14
|
import { type Diagnostic, diagnostic } from "../diagnostics.ts"
|
|
16
15
|
import { codeUnitOrder } from "../internal/code-unit-order.ts"
|
|
16
|
+
import { lineAt } from "../internal/line-at.ts"
|
|
17
17
|
import { createSpecifierResolver } from "../internal/project-specifiers.ts"
|
|
18
|
+
import { realpathOrSelf } from "../internal/realpath-or-self.ts"
|
|
18
19
|
import type { CheckRule } from "./index.ts"
|
|
19
20
|
import { zonedFiles } from "./zones.ts"
|
|
20
21
|
|
|
21
|
-
const lineAt = (text: string, index: number): number => text.slice(0, index).split("\n").length
|
|
22
|
-
|
|
23
22
|
const byPlace = (a: Diagnostic, b: Diagnostic): number =>
|
|
24
23
|
codeUnitOrder(a.file ?? "", b.file ?? "") || (a.line ?? 0) - (b.line ?? 0)
|
|
25
24
|
|
|
@@ -453,13 +452,7 @@ export const sensitiveOutputRule: CheckRule = {
|
|
|
453
452
|
async scan(ctx) {
|
|
454
453
|
const findings: Diagnostic[] = []
|
|
455
454
|
const resolve = createSpecifierResolver()
|
|
456
|
-
const realRoot = (
|
|
457
|
-
try {
|
|
458
|
-
return realpathSync(ctx.root)
|
|
459
|
-
} catch {
|
|
460
|
-
return ctx.root
|
|
461
|
-
}
|
|
462
|
-
})()
|
|
455
|
+
const realRoot = realpathOrSelf(ctx.root)
|
|
463
456
|
const sources = new Map<string, SchemaSource | undefined>()
|
|
464
457
|
const sourceOf = (file: string): SchemaSource | undefined => {
|
|
465
458
|
if (!sources.has(file)) {
|