@nifrajs/cli 5.15.1 → 5.16.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 +47 -0
- package/README.md +11 -0
- package/dist/build-provenance.d.ts +14 -0
- package/dist/build-provenance.d.ts.map +1 -0
- package/dist/build-provenance.js +82 -0
- package/dist/build-provenance.js.map +1 -0
- package/dist/check-diagnostics.d.ts +1 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +1 -1
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +6 -5
- package/dist/check-scan.js.map +1 -1
- package/dist/check-timings.d.ts +11 -0
- package/dist/check-timings.d.ts.map +1 -0
- package/dist/check-timings.js +23 -0
- package/dist/check-timings.js.map +1 -0
- package/dist/check.d.ts +3 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +68 -28
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +26 -11
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +3 -0
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +25 -4
- package/dist/command-catalog.js.map +1 -1
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +4 -2
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +5 -2
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +27 -9
- package/dist/doctor.js.map +1 -1
- package/dist/internal/named-imports.d.ts +4 -0
- package/dist/internal/named-imports.d.ts.map +1 -0
- package/dist/internal/named-imports.js +19 -0
- package/dist/internal/named-imports.js.map +1 -0
- package/dist/internal/rewrite-kit.d.ts +35 -0
- package/dist/internal/rewrite-kit.d.ts.map +1 -0
- package/dist/internal/rewrite-kit.js +14 -0
- package/dist/internal/rewrite-kit.js.map +1 -0
- package/dist/internal/source-facts.d.ts +37 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +115 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/levels-tool.d.ts +3 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +28 -18
- package/dist/levels-tool.js.map +1 -1
- package/dist/mcp-exec.js +1 -1
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +3 -1
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +9 -2
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +3 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-project-child.d.ts +10 -0
- package/dist/mcp-project-child.d.ts.map +1 -1
- package/dist/mcp-project-child.js +12 -1
- package/dist/mcp-project-child.js.map +1 -1
- package/dist/mcp-tool-meta.d.ts.map +1 -1
- package/dist/mcp-tool-meta.js +4 -1
- package/dist/mcp-tool-meta.js.map +1 -1
- package/dist/recipes/5.16.0.d.ts +12 -0
- package/dist/recipes/5.16.0.d.ts.map +1 -0
- package/dist/recipes/5.16.0.js +31 -0
- package/dist/recipes/5.16.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/review.d.ts.map +1 -1
- package/dist/review.js +3 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +3 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +3 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +15 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/route-hooks.d.ts +10 -0
- package/dist/rules/route-hooks.d.ts.map +1 -0
- package/dist/rules/route-hooks.js +88 -0
- package/dist/rules/route-hooks.js.map +1 -0
- package/dist/rules/silent-sse.d.ts +9 -0
- package/dist/rules/silent-sse.d.ts.map +1 -0
- package/dist/rules/silent-sse.js +89 -0
- package/dist/rules/silent-sse.js.map +1 -0
- package/dist/rules/source-scan.d.ts +4 -2
- package/dist/rules/source-scan.d.ts.map +1 -1
- package/dist/rules/source-scan.js +3 -1
- package/dist/rules/source-scan.js.map +1 -1
- package/dist/source-rewrites.d.ts +2 -20
- package/dist/source-rewrites.d.ts.map +1 -1
- package/dist/source-rewrites.js +3 -13
- package/dist/source-rewrites.js.map +1 -1
- package/dist/typecheck-cache.d.ts +6 -0
- package/dist/typecheck-cache.d.ts.map +1 -0
- package/dist/typecheck-cache.js +37 -0
- package/dist/typecheck-cache.js.map +1 -0
- package/dist/typecheck-coverage.js +1 -1
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/typed-api-rewrites.d.ts +3 -0
- package/dist/typed-api-rewrites.d.ts.map +1 -0
- package/dist/typed-api-rewrites.js +253 -0
- package/dist/typed-api-rewrites.js.map +1 -0
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +3 -1
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-gates.d.ts +23 -0
- package/dist/verification-gates.d.ts.map +1 -0
- package/dist/verification-gates.js +8 -0
- package/dist/verification-gates.js.map +1 -0
- package/dist/verification.d.ts +2 -0
- package/dist/verification.d.ts.map +1 -1
- package/dist/verification.js +6 -0
- package/dist/verification.js.map +1 -1
- package/dist/work-graph.d.ts +17 -8
- package/dist/work-graph.d.ts.map +1 -1
- package/dist/work-graph.js +157 -104
- package/dist/work-graph.js.map +1 -1
- package/docs/examples.json +2 -2
- package/docs/llms-full.txt +563 -46
- package/docs/types.json +269 -84
- package/package.json +12 -12
- package/src/build-provenance.ts +107 -0
- package/src/check-diagnostics.ts +5 -0
- package/src/check-scan.ts +7 -4
- package/src/check-timings.ts +27 -0
- package/src/check.ts +77 -32
- package/src/cli.ts +33 -12
- package/src/command-catalog.ts +28 -4
- package/src/dev-feed-tool.ts +8 -3
- package/src/doctor.ts +37 -18
- package/src/internal/named-imports.ts +26 -0
- package/src/internal/rewrite-kit.ts +49 -0
- package/src/internal/source-facts.ts +158 -0
- package/src/levels-tool.ts +27 -18
- package/src/mcp-exec.ts +1 -1
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +13 -1
- package/src/mcp-isolate.ts +4 -0
- package/src/mcp-project-child.ts +19 -1
- package/src/mcp-tool-meta.ts +5 -1
- package/src/recipes/5.16.0.ts +41 -0
- package/src/recipes/index.ts +2 -0
- package/src/review.ts +3 -0
- package/src/rules/codes.ts +3 -0
- package/src/rules/explanations.ts +15 -0
- package/src/rules/route-hooks.ts +112 -0
- package/src/rules/silent-sse.ts +95 -0
- package/src/rules/source-scan.ts +8 -3
- package/src/source-rewrites.ts +18 -52
- package/src/typecheck-cache.ts +33 -0
- package/src/typecheck-coverage.ts +1 -1
- package/src/typed-api-rewrites.ts +308 -0
- package/src/upgrade.ts +2 -1
- package/src/verification-gates.ts +9 -0
- package/src/verification.ts +8 -0
- package/src/work-graph.ts +200 -121
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 5.16 source rewrites. Three APIs became typed from the generated route table and the backend, and
|
|
3
|
+
* each old call shape stopped compiling; these rewrite the shapes whose new form is decided by the call
|
|
4
|
+
* alone, and list every other site by line:
|
|
5
|
+
*
|
|
6
|
+
* - `route-hooks`: `useSearch<T>()` / `useParams<T>()` / the bare calls become `useSearch("/pattern")`,
|
|
7
|
+
* the pattern being the page file's own route. A call outside a page file (a shared component, a
|
|
8
|
+
* layout) is listed: only its author knows which route it renders in.
|
|
9
|
+
* - `query-keys`: `getQueryData(key)` / `setQueryData(key, value)` take a typed key, so a plain key is
|
|
10
|
+
* wrapped in `queryKey(...)` (its type argument moves onto it).
|
|
11
|
+
* - `form-for`: `formFor<App, "/path", "method">()` becomes `formFor<App>()("/path", "method")`.
|
|
12
|
+
*/
|
|
13
|
+
import { buildManifest } from "@nifrajs/web"
|
|
14
|
+
import type * as TS from "typescript"
|
|
15
|
+
import { importedNames } from "./internal/named-imports.ts"
|
|
16
|
+
import {
|
|
17
|
+
applyEdits,
|
|
18
|
+
type Edit,
|
|
19
|
+
type ManualSite,
|
|
20
|
+
parseSource,
|
|
21
|
+
type RewriteResult,
|
|
22
|
+
type SourceRewrite,
|
|
23
|
+
} from "./internal/rewrite-kit.ts"
|
|
24
|
+
|
|
25
|
+
const ADAPTER = /^@nifrajs\/web-(?:react|preact|solid|svelte|vue)(?:\/router)?$/
|
|
26
|
+
const WEB_QUERY =
|
|
27
|
+
/^@nifrajs\/web(?:-(?:react|preact|solid|svelte|vue))?(?:\/(?:router|client|query))?$/
|
|
28
|
+
const FORMS = /^@nifrajs\/web(?:\/forms)?$/
|
|
29
|
+
const SFC = /\.(?:svelte|vue)$/
|
|
30
|
+
const PAGE_FILE = /\.(?:tsx|jsx|svelte|vue|mdx)$/
|
|
31
|
+
|
|
32
|
+
/** The quote the file's own imports use. */
|
|
33
|
+
const quoteOf = (text: string): '"' | "'" => (/from\s*'/.test(text) ? "'" : '"')
|
|
34
|
+
|
|
35
|
+
/** The URL patterns the page file `file` serves, or none when it is not a page of a routes directory. */
|
|
36
|
+
function pagePatterns(file: string): readonly string[] {
|
|
37
|
+
const path = file.replaceAll("\\", "/")
|
|
38
|
+
const nested = path.indexOf("/routes/")
|
|
39
|
+
const inside = path.startsWith("routes/")
|
|
40
|
+
? path.slice("routes/".length)
|
|
41
|
+
: nested === -1
|
|
42
|
+
? undefined
|
|
43
|
+
: path.slice(nested + "/routes/".length)
|
|
44
|
+
if (inside === undefined || !PAGE_FILE.test(inside)) return []
|
|
45
|
+
try {
|
|
46
|
+
// Only the patterns are read; no route module is ever loaded.
|
|
47
|
+
const never = () => () => Promise.reject(new Error("not loaded"))
|
|
48
|
+
return buildManifest([inside], never).routes.map((route) => route.pattern)
|
|
49
|
+
} catch {
|
|
50
|
+
return []
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const lineAt = (text: string, index: number): number => text.slice(0, index).split("\n").length
|
|
55
|
+
|
|
56
|
+
const HOOK_CALL = /\b(use(?:Search|Params))(?:<[^<>()]*>)?\(\s*\)/g
|
|
57
|
+
|
|
58
|
+
function rewriteRouteHooks(ts: typeof TS, file: string, text: string): RewriteResult {
|
|
59
|
+
const patterns = pagePatterns(file)
|
|
60
|
+
const only = patterns.length === 1 ? patterns[0] : undefined
|
|
61
|
+
const where =
|
|
62
|
+
patterns.length === 0
|
|
63
|
+
? 'this file is not a page: name the route it renders in, as in useSearch("/reports") (a component shared by several pages takes the pattern as a prop typed as the union of their routes)'
|
|
64
|
+
: `this page serves ${patterns.map((pattern) => `"${pattern}"`).join(" and ")}: name the one it reads`
|
|
65
|
+
if (SFC.test(file)) {
|
|
66
|
+
const manual: ManualSite[] = []
|
|
67
|
+
for (const match of text.matchAll(HOOK_CALL))
|
|
68
|
+
manual.push({
|
|
69
|
+
line: lineAt(text, match.index),
|
|
70
|
+
reason: `${match[0]} takes the route: ${only === undefined ? where : `write ${match[1]}("${only}")`}`,
|
|
71
|
+
})
|
|
72
|
+
return { text, count: 0, manual }
|
|
73
|
+
}
|
|
74
|
+
const { tree, lineOf } = parseSource(ts, file, text)
|
|
75
|
+
const names = importedNames(ts, tree, ADAPTER, ["useSearch", "useParams"])
|
|
76
|
+
if (names.size === 0) return { text, count: 0, manual: [] }
|
|
77
|
+
const quote = quoteOf(text)
|
|
78
|
+
const edits: Edit[] = []
|
|
79
|
+
const manual: ManualSite[] = []
|
|
80
|
+
const visit = (node: TS.Node): void => {
|
|
81
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
82
|
+
const hook = names.get(node.expression.text)
|
|
83
|
+
if (hook !== undefined && node.arguments.length === 0) {
|
|
84
|
+
if (only === undefined)
|
|
85
|
+
manual.push({ line: lineOf(node), reason: `${hook}() takes the route: ${where}` })
|
|
86
|
+
else
|
|
87
|
+
edits.push({
|
|
88
|
+
start: node.expression.end,
|
|
89
|
+
end: node.end,
|
|
90
|
+
text: `(${quote}${only}${quote})`,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
ts.forEachChild(node, visit)
|
|
95
|
+
}
|
|
96
|
+
visit(tree)
|
|
97
|
+
return { text: applyEdits(text, edits), count: edits.length, manual }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const QUERY_KEY = "queryKey"
|
|
101
|
+
const KEYED = new Set(["getQueryData", "setQueryData"])
|
|
102
|
+
const QUERY_CALL = /\.(?:get|set)QueryData(?:<[^<>()]*>)?\(/g
|
|
103
|
+
|
|
104
|
+
/** The local name for the helper a rewrite writes: the file's own import, else one no identifier in the file uses. */
|
|
105
|
+
function helperName(ts: typeof TS, tree: TS.SourceFile, imported: string | undefined): string {
|
|
106
|
+
if (imported !== undefined) return imported
|
|
107
|
+
const used = new Set<string>()
|
|
108
|
+
const collect = (node: TS.Node): void => {
|
|
109
|
+
if (ts.isIdentifier(node)) used.add(node.text)
|
|
110
|
+
ts.forEachChild(node, collect)
|
|
111
|
+
}
|
|
112
|
+
collect(tree)
|
|
113
|
+
for (let n = 0; ; n++) {
|
|
114
|
+
const candidate = n === 0 ? QUERY_KEY : `nifraQueryKey${n === 1 ? "" : n}`
|
|
115
|
+
if (!used.has(candidate)) return candidate
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const MAX_QUERY_KEY_PASSES = 8
|
|
120
|
+
|
|
121
|
+
/** One walk of `tree`: wraps the key of every `getQueryData`/`setQueryData` call that is not wrapped yet. */
|
|
122
|
+
function queryKeyPass(
|
|
123
|
+
ts: typeof TS,
|
|
124
|
+
tree: TS.SourceFile,
|
|
125
|
+
local: string,
|
|
126
|
+
): { readonly edits: Edit[]; readonly sites: number } {
|
|
127
|
+
const edits: Edit[] = []
|
|
128
|
+
let sites = 0
|
|
129
|
+
const visit = (node: TS.Node, skip?: TS.Node): void => {
|
|
130
|
+
let skipped: TS.Node | undefined
|
|
131
|
+
if (
|
|
132
|
+
ts.isCallExpression(node) &&
|
|
133
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
134
|
+
KEYED.has(node.expression.name.text)
|
|
135
|
+
) {
|
|
136
|
+
const [key] = node.arguments
|
|
137
|
+
const alreadyKeyed =
|
|
138
|
+
key !== undefined &&
|
|
139
|
+
ts.isCallExpression(key) &&
|
|
140
|
+
ts.isIdentifier(key.expression) &&
|
|
141
|
+
key.expression.text === local
|
|
142
|
+
if (key !== undefined && !alreadyKeyed) {
|
|
143
|
+
sites++
|
|
144
|
+
const typeArgs = node.typeArguments
|
|
145
|
+
const generic =
|
|
146
|
+
typeArgs === undefined ? "" : `<${typeArgs.map((arg) => arg.getText(tree)).join(", ")}>`
|
|
147
|
+
if (typeArgs !== undefined)
|
|
148
|
+
edits.push({ start: node.expression.name.end, end: key.getStart(tree), text: "(" })
|
|
149
|
+
edits.push({
|
|
150
|
+
start: key.getStart(tree),
|
|
151
|
+
end: key.end,
|
|
152
|
+
text: `${local}${generic}(${key.getText(tree)})`,
|
|
153
|
+
})
|
|
154
|
+
// A call inside the key is rewritten by the next pass, once this key is wrapped: two edits
|
|
155
|
+
// over one range would corrupt the source.
|
|
156
|
+
skipped = key
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
ts.forEachChild(node, (child) => {
|
|
160
|
+
if (child !== skipped && child !== skip) visit(child)
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
visit(tree)
|
|
164
|
+
return { edits, sites }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function rewriteQueryKeys(ts: typeof TS, file: string, text: string): RewriteResult {
|
|
168
|
+
if (SFC.test(file)) {
|
|
169
|
+
if (!/@nifrajs\/web/.test(text) || /@tanstack\//.test(text))
|
|
170
|
+
return { text, count: 0, manual: [] }
|
|
171
|
+
const manual: ManualSite[] = []
|
|
172
|
+
for (const match of text.matchAll(QUERY_CALL)) {
|
|
173
|
+
if (
|
|
174
|
+
text
|
|
175
|
+
.slice(match.index + match[0].length)
|
|
176
|
+
.trimStart()
|
|
177
|
+
.startsWith(QUERY_KEY)
|
|
178
|
+
)
|
|
179
|
+
continue
|
|
180
|
+
manual.push({
|
|
181
|
+
line: lineAt(text, match.index),
|
|
182
|
+
reason: `${match[0].slice(1, -1)} takes a typed key: wrap the key in queryKey(...), from "@nifrajs/web/client"`,
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
return { text, count: 0, manual }
|
|
186
|
+
}
|
|
187
|
+
const first = parseSource(ts, file, text).tree
|
|
188
|
+
const fromWeb = first.statements.some(
|
|
189
|
+
(statement) =>
|
|
190
|
+
ts.isImportDeclaration(statement) &&
|
|
191
|
+
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
192
|
+
WEB_QUERY.test(statement.moduleSpecifier.text),
|
|
193
|
+
)
|
|
194
|
+
// The calls are unqualified in name (`qc.setQueryData`), so only a file that holds a Nifra query
|
|
195
|
+
// client is read: TanStack's client has the same method names and a different key type.
|
|
196
|
+
const tanstack = first.statements.some(
|
|
197
|
+
(statement) =>
|
|
198
|
+
ts.isImportDeclaration(statement) &&
|
|
199
|
+
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
200
|
+
statement.moduleSpecifier.text.startsWith("@tanstack/"),
|
|
201
|
+
)
|
|
202
|
+
if (!fromWeb || tanstack) return { text, count: 0, manual: [] }
|
|
203
|
+
const imported = importedNames(ts, first, WEB_QUERY, [QUERY_KEY]).keys().next().value
|
|
204
|
+
const local = helperName(ts, first, imported)
|
|
205
|
+
let current = text
|
|
206
|
+
let sites = 0
|
|
207
|
+
for (let pass = 0; pass < MAX_QUERY_KEY_PASSES; pass++) {
|
|
208
|
+
const { tree } = parseSource(ts, file, current)
|
|
209
|
+
const found = queryKeyPass(ts, tree, local)
|
|
210
|
+
if (found.edits.length === 0) break
|
|
211
|
+
sites += found.sites
|
|
212
|
+
current = applyEdits(current, found.edits)
|
|
213
|
+
}
|
|
214
|
+
if (sites === 0) return { text, count: 0, manual: [] }
|
|
215
|
+
if (imported === undefined) {
|
|
216
|
+
const tree = parseSource(ts, file, current).tree
|
|
217
|
+
const quote = quoteOf(current)
|
|
218
|
+
const last = tree.statements.filter(ts.isImportDeclaration).at(-1)
|
|
219
|
+
const names = local === QUERY_KEY ? QUERY_KEY : `${QUERY_KEY} as ${local}`
|
|
220
|
+
const line = `import { ${names} } from ${quote}@nifrajs/web/client${quote}`
|
|
221
|
+
current = applyEdits(current, [
|
|
222
|
+
last === undefined
|
|
223
|
+
? { start: 0, end: 0, text: `${line}\n` }
|
|
224
|
+
: { start: last.end, end: last.end, text: `\n${line}` },
|
|
225
|
+
])
|
|
226
|
+
}
|
|
227
|
+
return { text: current, count: sites, manual: [] }
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const FORM_FOR_TYPES = /\bformFor<[^<>(),]*,[^<>()]*>\(\s*\)/g
|
|
231
|
+
|
|
232
|
+
function rewriteFormFor(ts: typeof TS, file: string, text: string): RewriteResult {
|
|
233
|
+
if (SFC.test(file)) {
|
|
234
|
+
if (!/@nifrajs\/web/.test(text)) return { text, count: 0, manual: [] }
|
|
235
|
+
const manual: ManualSite[] = []
|
|
236
|
+
for (const match of text.matchAll(FORM_FOR_TYPES))
|
|
237
|
+
manual.push({
|
|
238
|
+
line: lineAt(text, match.index),
|
|
239
|
+
reason: `${match[0]} is now formFor<App>()("/path", "method"): the path and method are values`,
|
|
240
|
+
})
|
|
241
|
+
return { text, count: 0, manual }
|
|
242
|
+
}
|
|
243
|
+
const { tree, lineOf } = parseSource(ts, file, text)
|
|
244
|
+
const names = importedNames(ts, tree, FORMS, ["formFor"])
|
|
245
|
+
if (names.size === 0) return { text, count: 0, manual: [] }
|
|
246
|
+
const edits: Edit[] = []
|
|
247
|
+
const manual: ManualSite[] = []
|
|
248
|
+
const literal = (node: TS.TypeNode | undefined): string | undefined =>
|
|
249
|
+
node !== undefined && ts.isLiteralTypeNode(node) && ts.isStringLiteral(node.literal)
|
|
250
|
+
? node.literal.getText(tree)
|
|
251
|
+
: undefined
|
|
252
|
+
const visit = (node: TS.Node): void => {
|
|
253
|
+
if (
|
|
254
|
+
ts.isCallExpression(node) &&
|
|
255
|
+
ts.isIdentifier(node.expression) &&
|
|
256
|
+
names.has(node.expression.text) &&
|
|
257
|
+
(node.typeArguments?.length ?? 0) >= 2
|
|
258
|
+
) {
|
|
259
|
+
const [app, path, method] = node.typeArguments ?? []
|
|
260
|
+
const pathText = literal(path)
|
|
261
|
+
const methodText = literal(method)
|
|
262
|
+
if (
|
|
263
|
+
app === undefined ||
|
|
264
|
+
pathText === undefined ||
|
|
265
|
+
(method !== undefined && methodText === undefined)
|
|
266
|
+
)
|
|
267
|
+
manual.push({
|
|
268
|
+
line: lineOf(node),
|
|
269
|
+
reason:
|
|
270
|
+
'formFor<App, Path>() is now formFor<App>()("/path", "method"): the path and method are values, so write them as literals',
|
|
271
|
+
})
|
|
272
|
+
else
|
|
273
|
+
edits.push({
|
|
274
|
+
start: node.getStart(tree),
|
|
275
|
+
end: node.end,
|
|
276
|
+
text: `${node.expression.text}<${app.getText(tree)}>()(${pathText}${methodText === undefined ? "" : `, ${methodText}`})`,
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
ts.forEachChild(node, visit)
|
|
280
|
+
}
|
|
281
|
+
visit(tree)
|
|
282
|
+
return { text: applyEdits(text, edits), count: edits.length, manual }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export const TYPED_API_REWRITES: readonly SourceRewrite[] = [
|
|
286
|
+
{
|
|
287
|
+
id: "route-hooks",
|
|
288
|
+
description:
|
|
289
|
+
'useSearch<T>() / useParams<T>() and the bare calls → useSearch("/pattern") / useParams("/pattern") in a page file',
|
|
290
|
+
mentions: (text) => /\buse(?:Search|Params)\b/.test(text) && /@nifrajs\/web-/.test(text),
|
|
291
|
+
components: true,
|
|
292
|
+
rewrite: rewriteRouteHooks,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: "query-keys",
|
|
296
|
+
description: "getQueryData(key) / setQueryData(key, v) → the same with queryKey(key)",
|
|
297
|
+
mentions: (text) => /\b(?:get|set)QueryData\b/.test(text) && /@nifrajs\/web/.test(text),
|
|
298
|
+
components: true,
|
|
299
|
+
rewrite: rewriteQueryKeys,
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
id: "form-for",
|
|
303
|
+
description: 'formFor<App, "/path">() → formFor<App>()("/path")',
|
|
304
|
+
mentions: (text) => /\bformFor\b/.test(text) && /@nifrajs\/web/.test(text),
|
|
305
|
+
components: true,
|
|
306
|
+
rewrite: rewriteFormFor,
|
|
307
|
+
},
|
|
308
|
+
]
|
package/src/upgrade.ts
CHANGED
|
@@ -1406,10 +1406,11 @@ export function computeUpgrade(
|
|
|
1406
1406
|
const rewritesNeedTypeScript: string[] = []
|
|
1407
1407
|
const rewrites = (recipe.sourceRewrites ?? []).flatMap((id) => getSourceRewrite(id) ?? [])
|
|
1408
1408
|
if (rewrites.length > 0) {
|
|
1409
|
-
for (const rel of scan(cwd,
|
|
1409
|
+
for (const rel of scan(cwd, ADD_SOURCE_GLOB)) {
|
|
1410
1410
|
const original = movedSources.get(rel) ?? readFileSync(join(cwd, rel), "utf8")
|
|
1411
1411
|
let text = original
|
|
1412
1412
|
for (const rewrite of rewrites) {
|
|
1413
|
+
if (rewrite.components !== true && /\.(?:svelte|vue)$/.test(rel)) continue
|
|
1413
1414
|
if (!rewrite.mentions(text)) continue
|
|
1414
1415
|
if (compiler === undefined) {
|
|
1415
1416
|
if (!rewritesNeedTypeScript.includes(rel)) rewritesNeedTypeScript.push(rel)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const VERIFICATION_GATES = [
|
|
2
|
+
{ level: 0, kind: "typecheck", name: "typed contract" },
|
|
3
|
+
{ level: 1, kind: "assurance", name: "route assurance" },
|
|
4
|
+
{ level: 2, kind: "capability", name: "capability lockfile" },
|
|
5
|
+
{ level: 3, kind: "manifest", name: "route manifest" },
|
|
6
|
+
{ level: 4, kind: "invariants", name: "invariant-tested" },
|
|
7
|
+
] as const
|
|
8
|
+
|
|
9
|
+
export type VerificationGate = (typeof VERIFICATION_GATES)[number]
|
package/src/verification.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
collectCapabilityProjectReport,
|
|
31
31
|
} from "./capabilities-tool.ts"
|
|
32
32
|
import { type CheckAssuranceContext, type CheckResult, collectCheckResult } from "./check.ts"
|
|
33
|
+
import { createCheckTimer } from "./check-timings.ts"
|
|
33
34
|
|
|
34
35
|
export interface CollectProjectVerificationOptions {
|
|
35
36
|
/** Assurance config path, default `nifra.assurance.ts`. Honored by the assurance + levels views. */
|
|
@@ -38,6 +39,8 @@ export interface CollectProjectVerificationOptions {
|
|
|
38
39
|
readonly preloaded?: { readonly config: AssuranceConfig } | { readonly error: unknown }
|
|
39
40
|
/** Skip the `tsc` pass in the check view (the agent inner-loop mode). */
|
|
40
41
|
readonly lintsOnly?: boolean
|
|
42
|
+
readonly incremental?: boolean
|
|
43
|
+
readonly timings?: boolean
|
|
41
44
|
/** Cancels the check view's typecheck. */
|
|
42
45
|
readonly signal?: AbortSignal
|
|
43
46
|
/** Cap the check view's diagnostics (the `levels` L0 and MCP paths set this). */
|
|
@@ -81,6 +84,8 @@ export async function collectProjectVerification(
|
|
|
81
84
|
cwd: string,
|
|
82
85
|
options: CollectProjectVerificationOptions = {},
|
|
83
86
|
): Promise<ProjectVerification> {
|
|
87
|
+
const timer = options.timings === true ? createCheckTimer() : undefined
|
|
88
|
+
const started = performance.now()
|
|
84
89
|
const { loadAssuranceConfig, DEFAULT_ASSURANCE_CONFIG } = await import("./assure.ts")
|
|
85
90
|
const configPath = resolve(cwd, options.config ?? DEFAULT_ASSURANCE_CONFIG)
|
|
86
91
|
const assuranceConfigPresent = existsSync(configPath)
|
|
@@ -143,6 +148,7 @@ export async function collectProjectVerification(
|
|
|
143
148
|
routeAssurance = undefined
|
|
144
149
|
capability = undefined
|
|
145
150
|
}
|
|
151
|
+
timer?.record("assurance", started)
|
|
146
152
|
|
|
147
153
|
// The check view's assurance inputs. Fed to `check()` only when no custom config path was requested,
|
|
148
154
|
// so `nifra check` (which always reads the default `nifra.assurance.ts`) and `levels` L0 keep reading
|
|
@@ -168,6 +174,8 @@ export async function collectProjectVerification(
|
|
|
168
174
|
check(): Promise<CheckResult> {
|
|
169
175
|
checkResult ??= collectCheckResult(cwd, {
|
|
170
176
|
lintsOnly: options.lintsOnly ?? false,
|
|
177
|
+
incremental: options.incremental ?? false,
|
|
178
|
+
...(timer === undefined ? {} : { timer }),
|
|
171
179
|
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
172
180
|
...(options.maxDiagnostics !== undefined ? { maxDiagnostics: options.maxDiagnostics } : {}),
|
|
173
181
|
...(options.config === undefined ? { assurance: checkContext } : {}),
|