@nifrajs/cli 5.5.0 → 5.6.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.
Files changed (143) hide show
  1. package/CHANGELOG.md +172 -0
  2. package/dist/cdn-check.d.ts +7 -6
  3. package/dist/cdn-check.d.ts.map +1 -1
  4. package/dist/cdn-check.js +13 -1
  5. package/dist/cdn-check.js.map +1 -1
  6. package/dist/check-diagnostics.d.ts.map +1 -1
  7. package/dist/check-diagnostics.js +5 -3
  8. package/dist/check-diagnostics.js.map +1 -1
  9. package/dist/check-scan.d.ts.map +1 -1
  10. package/dist/check-scan.js +29 -2
  11. package/dist/check-scan.js.map +1 -1
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +14 -5
  14. package/dist/cli.js.map +1 -1
  15. package/dist/command-catalog.d.ts +14 -1
  16. package/dist/command-catalog.d.ts.map +1 -1
  17. package/dist/command-catalog.js +93 -0
  18. package/dist/command-catalog.js.map +1 -1
  19. package/dist/doctor.d.ts +9 -1
  20. package/dist/doctor.d.ts.map +1 -1
  21. package/dist/doctor.js +52 -0
  22. package/dist/doctor.js.map +1 -1
  23. package/dist/fix-recipes.d.ts.map +1 -1
  24. package/dist/fix-recipes.js +27 -0
  25. package/dist/fix-recipes.js.map +1 -1
  26. package/dist/frontend-guidance.d.ts +1 -1
  27. package/dist/frontend-guidance.d.ts.map +1 -1
  28. package/dist/frontend-guidance.js +17 -8
  29. package/dist/frontend-guidance.js.map +1 -1
  30. package/dist/internal/source-facts.d.ts +2 -1
  31. package/dist/internal/source-facts.d.ts.map +1 -1
  32. package/dist/internal/source-facts.js +17 -11
  33. package/dist/internal/source-facts.js.map +1 -1
  34. package/dist/introspect.js +1 -1
  35. package/dist/introspect.js.map +1 -1
  36. package/dist/load.d.ts +4 -1
  37. package/dist/load.d.ts.map +1 -1
  38. package/dist/load.js +8 -0
  39. package/dist/load.js.map +1 -1
  40. package/dist/mcp-exec.d.ts.map +1 -1
  41. package/dist/mcp-exec.js +57 -3
  42. package/dist/mcp-exec.js.map +1 -1
  43. package/dist/mcp-http.d.ts +2 -1
  44. package/dist/mcp-http.d.ts.map +1 -1
  45. package/dist/mcp-http.js +3 -2
  46. package/dist/mcp-http.js.map +1 -1
  47. package/dist/mcp-tool-meta.d.ts +21 -0
  48. package/dist/mcp-tool-meta.d.ts.map +1 -0
  49. package/dist/mcp-tool-meta.js +246 -0
  50. package/dist/mcp-tool-meta.js.map +1 -0
  51. package/dist/mcp.d.ts +3 -2
  52. package/dist/mcp.d.ts.map +1 -1
  53. package/dist/mcp.js +36 -98
  54. package/dist/mcp.js.map +1 -1
  55. package/dist/output-schemas.d.ts +8 -0
  56. package/dist/output-schemas.d.ts.map +1 -1
  57. package/dist/output-schemas.js +14 -0
  58. package/dist/output-schemas.js.map +1 -1
  59. package/dist/ppr-read-fix.d.ts +8 -0
  60. package/dist/ppr-read-fix.d.ts.map +1 -0
  61. package/dist/ppr-read-fix.js +356 -0
  62. package/dist/ppr-read-fix.js.map +1 -0
  63. package/dist/recipes/5.6.0.d.ts +10 -0
  64. package/dist/recipes/5.6.0.d.ts.map +1 -0
  65. package/dist/recipes/5.6.0.js +68 -0
  66. package/dist/recipes/5.6.0.js.map +1 -0
  67. package/dist/recipes/index.d.ts.map +1 -1
  68. package/dist/recipes/index.js +2 -0
  69. package/dist/recipes/index.js.map +1 -1
  70. package/dist/review.d.ts.map +1 -1
  71. package/dist/review.js +7 -2
  72. package/dist/review.js.map +1 -1
  73. package/dist/rules/codes.d.ts +8 -3
  74. package/dist/rules/codes.d.ts.map +1 -1
  75. package/dist/rules/codes.js +9 -4
  76. package/dist/rules/codes.js.map +1 -1
  77. package/dist/rules/explanations.d.ts.map +1 -1
  78. package/dist/rules/explanations.js +39 -13
  79. package/dist/rules/explanations.js.map +1 -1
  80. package/dist/rules/islands.d.ts +91 -0
  81. package/dist/rules/islands.d.ts.map +1 -1
  82. package/dist/rules/islands.js +757 -3
  83. package/dist/rules/islands.js.map +1 -1
  84. package/dist/rules/ppr.d.ts +16 -0
  85. package/dist/rules/ppr.d.ts.map +1 -0
  86. package/dist/rules/ppr.js +114 -0
  87. package/dist/rules/ppr.js.map +1 -0
  88. package/dist/rules/swap.d.ts +7 -0
  89. package/dist/rules/swap.d.ts.map +1 -0
  90. package/dist/rules/swap.js +338 -0
  91. package/dist/rules/swap.js.map +1 -0
  92. package/dist/scaffold-hole.d.ts +105 -0
  93. package/dist/scaffold-hole.d.ts.map +1 -0
  94. package/dist/scaffold-hole.js +688 -0
  95. package/dist/scaffold-hole.js.map +1 -0
  96. package/dist/scaffold.d.ts +5 -3
  97. package/dist/scaffold.d.ts.map +1 -1
  98. package/dist/scaffold.js +56 -46
  99. package/dist/scaffold.js.map +1 -1
  100. package/dist/verification-plan.d.ts.map +1 -1
  101. package/dist/verification-plan.js +12 -1
  102. package/dist/verification-plan.js.map +1 -1
  103. package/dist/web-app-options.d.ts +1 -1
  104. package/dist/web-app-options.d.ts.map +1 -1
  105. package/dist/web-app-options.js.map +1 -1
  106. package/docs/examples.json +63 -9
  107. package/docs/llms-full.txt +2070 -437
  108. package/docs/types.json +1300 -270
  109. package/package.json +11 -11
  110. package/src/cdn-check.ts +21 -7
  111. package/src/check-diagnostics.ts +5 -3
  112. package/src/check-scan.ts +34 -3
  113. package/src/cli.ts +14 -5
  114. package/src/command-catalog.ts +126 -0
  115. package/src/doctor.ts +44 -1
  116. package/src/fix-recipes.ts +28 -0
  117. package/src/frontend-guidance.ts +20 -8
  118. package/src/internal/source-facts.ts +27 -13
  119. package/src/introspect.ts +1 -1
  120. package/src/load.ts +13 -0
  121. package/src/mcp-exec.ts +74 -3
  122. package/src/mcp-http.ts +3 -2
  123. package/src/mcp-tool-meta.ts +268 -0
  124. package/src/mcp.ts +35 -99
  125. package/src/output-schemas.ts +28 -0
  126. package/src/ppr-read-fix.ts +426 -0
  127. package/src/recipes/5.6.0.ts +69 -0
  128. package/src/recipes/index.ts +2 -0
  129. package/src/review.ts +7 -2
  130. package/src/rules/codes.ts +9 -4
  131. package/src/rules/explanations.ts +39 -13
  132. package/src/rules/islands.ts +875 -3
  133. package/src/rules/ppr.ts +143 -0
  134. package/src/rules/swap.ts +402 -0
  135. package/src/scaffold-hole.ts +880 -0
  136. package/src/scaffold.ts +60 -49
  137. package/src/verification-plan.ts +20 -1
  138. package/src/web-app-options.ts +1 -0
  139. package/dist/rules/nano.d.ts +0 -6
  140. package/dist/rules/nano.d.ts.map +0 -1
  141. package/dist/rules/nano.js +0 -273
  142. package/dist/rules/nano.js.map +0 -1
  143. package/src/rules/nano.ts +0 -307
package/src/rules/nano.ts DELETED
@@ -1,307 +0,0 @@
1
- import type * as TSApi from "typescript"
2
- import { type Diagnostic, diagnostic } from "../diagnostics.ts"
3
- import { scriptKindOf } from "../internal/script-kind.ts"
4
- import type { CheckRule, SourceIndex } from "./index.ts"
5
- import { loadRuleTypeScript } from "./typescript.ts"
6
-
7
- /**
8
- * The nano lane lints (`@nifrajs/web/nano`). nano is deliberately explicit - every reactive edge is a
9
- * `bind`/`bindList` call or a `computed(fn, [deps])` - and that is exactly what makes its three
10
- * mistakes STATICALLY catchable, the property a framework's auto-tracked reactivity cannot offer:
11
- *
12
- * NF-C021 a `bind`/`bindList`/`bindResource` whose disposer is discarded (leaks on teardown)
13
- * NF-C022 a `bindList` keyed by the array index (breaks add/remove/reorder)
14
- * NF-C023 a `computed`/`resource` `(fn, [deps])` reading a signal its `deps` omit (won't recompute/refetch)
15
- *
16
- * All three warn (never block): a false positive must never fail a build, and each maps to a fix
17
- * recipe (`nano.*`). Deliberately conservative - only the unambiguous authoring shapes are inspected.
18
- */
19
-
20
- const parseCache = new WeakMap<
21
- SourceIndex,
22
- Map<string, { readonly tree: TSApi.SourceFile } | null>
23
- >()
24
-
25
- function parsedTree(
26
- ts: typeof TSApi,
27
- sources: SourceIndex,
28
- file: string,
29
- ): TSApi.SourceFile | undefined {
30
- let files = parseCache.get(sources)
31
- if (files === undefined) {
32
- files = new Map()
33
- parseCache.set(sources, files)
34
- }
35
- const cached = files.get(file)
36
- if (cached !== undefined) return cached?.tree
37
- const source = sources.read(file)
38
- if (source === undefined) {
39
- files.set(file, null)
40
- return undefined
41
- }
42
- const tree = ts.createSourceFile(
43
- file,
44
- source,
45
- ts.ScriptTarget.Latest,
46
- true,
47
- scriptKindOf(ts, file),
48
- )
49
- files.set(file, { tree })
50
- return tree
51
- }
52
-
53
- type Fn = TSApi.ArrowFunction | TSApi.FunctionExpression
54
- const isFn = (ts: typeof TSApi, n: TSApi.Node): n is Fn =>
55
- ts.isArrowFunction(n) || ts.isFunctionExpression(n)
56
-
57
- /** Names bound to a `signal(...)` or `computed(...)` result anywhere in the file - the reactive cells
58
- * a `computed` body may read and must therefore declare. */
59
- function reactiveBindings(ts: typeof TSApi, tree: TSApi.SourceFile): Set<string> {
60
- const names = new Set<string>()
61
- const visit = (n: TSApi.Node): void => {
62
- if (
63
- ts.isVariableDeclaration(n) &&
64
- ts.isIdentifier(n.name) &&
65
- n.initializer !== undefined &&
66
- ts.isCallExpression(n.initializer) &&
67
- ts.isIdentifier(n.initializer.expression) &&
68
- (n.initializer.expression.text === "signal" ||
69
- n.initializer.expression.text === "computed" ||
70
- n.initializer.expression.text === "resource")
71
- ) {
72
- names.add(n.name.text)
73
- }
74
- ts.forEachChild(n, visit)
75
- }
76
- visit(tree)
77
- return names
78
- }
79
-
80
- /** Reactive identifiers read as `x.get()` inside `fn`. */
81
- function getsInside(ts: typeof TSApi, fn: TSApi.Node, reactive: ReadonlySet<string>): Set<string> {
82
- const reads = new Set<string>()
83
- const visit = (n: TSApi.Node): void => {
84
- if (
85
- ts.isCallExpression(n) &&
86
- ts.isPropertyAccessExpression(n.expression) &&
87
- n.expression.name.text === "get" &&
88
- ts.isIdentifier(n.expression.expression) &&
89
- reactive.has(n.expression.expression.text)
90
- ) {
91
- reads.add(n.expression.expression.text)
92
- }
93
- ts.forEachChild(n, visit)
94
- }
95
- visit(fn)
96
- return reads
97
- }
98
-
99
- /** The identifiers listed in a `computed`'s deps array literal (non-identifier entries are ignored -
100
- * an unusual deps shape simply isn't linted rather than mis-flagged). */
101
- function declaredDeps(ts: typeof TSApi, depsArg: TSApi.Expression): Set<string> {
102
- const deps = new Set<string>()
103
- if (ts.isArrayLiteralExpression(depsArg)) {
104
- for (const el of depsArg.elements) if (ts.isIdentifier(el)) deps.add(el.text)
105
- }
106
- return deps
107
- }
108
-
109
- /** A `bind`/`bindList` call whose return value is discarded: its immediate parent is the expression
110
- * statement itself (not an assignment, array element, `return`, `await`, or argument). */
111
- function isDiscarded(ts: typeof TSApi, call: TSApi.CallExpression): boolean {
112
- const parent = call.parent
113
- return parent !== undefined && ts.isExpressionStatement(parent)
114
- }
115
-
116
- /** For a `bindList(src, container, { key, ... })`, the `key` property's function if it is an inline
117
- * arrow/function literal. */
118
- function keyFn(ts: typeof TSApi, call: TSApi.CallExpression): Fn | undefined {
119
- const opts = call.arguments[2]
120
- if (opts === undefined || !ts.isObjectLiteralExpression(opts)) return undefined
121
- for (const prop of opts.properties) {
122
- if (
123
- ts.isPropertyAssignment(prop) &&
124
- ts.isIdentifier(prop.name) &&
125
- prop.name.text === "key" &&
126
- isFn(ts, prop.initializer)
127
- ) {
128
- return prop.initializer
129
- }
130
- }
131
- return undefined
132
- }
133
-
134
- /** Does `fn`'s body return its own second parameter (the index) directly? `key: (_, i) => i`, the
135
- * classic reorder-breaking key. Conservative: only a bare `return <secondParam>` / concise `=> i`. */
136
- function returnsSecondParam(ts: typeof TSApi, fn: Fn): boolean {
137
- if (fn.parameters.length < 2) return false
138
- const second = fn.parameters[1]
139
- if (second === undefined || !ts.isIdentifier(second.name)) return false
140
- const idx = second.name.text
141
- const isIdxRef = (e: TSApi.Expression): boolean => ts.isIdentifier(e) && e.text === idx
142
- if (ts.isArrowFunction(fn) && !ts.isBlock(fn.body)) return isIdxRef(fn.body)
143
- let found = false
144
- const visit = (n: TSApi.Node): void => {
145
- if (found) return
146
- if (isFn(ts, n) || ts.isFunctionDeclaration(n)) return // not a nested fn's return
147
- if (ts.isReturnStatement(n) && n.expression !== undefined && isIdxRef(n.expression)) {
148
- found = true
149
- return
150
- }
151
- ts.forEachChild(n, visit)
152
- }
153
- ts.forEachChild(fn, visit)
154
- return found
155
- }
156
-
157
- const lineOf = (tree: TSApi.SourceFile, n: TSApi.Node): number =>
158
- tree.getLineAndCharacterOfPosition(n.getStart(tree)).line + 1
159
-
160
- function toolchainMissing(code: string): Diagnostic {
161
- return diagnostic({
162
- code,
163
- severity: "warn",
164
- message: `nano lint (${code}) did NOT run - TypeScript is not installed, so this report says nothing about it`,
165
- fix: { recipe: "toolchain.install-typescript", command: "bun add -d typescript" },
166
- verify: "nifra check --lints-only",
167
- })
168
- }
169
-
170
- export const nanoBindCleanupRule: CheckRule = {
171
- code: "NF-C021",
172
- title: "nano binding cleanup check",
173
- async scan(ctx) {
174
- const loaded = await loadRuleTypeScript(ctx)
175
- if (loaded.diagnostics !== undefined) return loaded.diagnostics
176
- const ts = loaded.compiler
177
- if (ts === undefined) return [toolchainMissing("NF-C021")]
178
- const findings: Diagnostic[] = []
179
- for (const file of ctx.project.source.files) {
180
- const tree = parsedTree(ts, ctx.project.source, file)
181
- if (tree === undefined) continue
182
- const visit = (n: TSApi.Node): void => {
183
- if (
184
- ts.isCallExpression(n) &&
185
- ts.isIdentifier(n.expression) &&
186
- (n.expression.text === "bind" ||
187
- n.expression.text === "bindList" ||
188
- n.expression.text === "bindResource") &&
189
- isDiscarded(ts, n)
190
- ) {
191
- findings.push(
192
- diagnostic({
193
- code: "NF-C021",
194
- severity: "warn",
195
- file,
196
- line: lineOf(tree, n),
197
- message: `${n.expression.text}(...) discards its cleanup - collect the returned disposer and call it on teardown, or it leaks on soft-nav`,
198
- evidence: [`${n.expression.text}(...) as a bare statement`],
199
- fix: { recipe: "nano.collect-cleanup", command: "nifra_docs nano" },
200
- verify: "nifra check --lints-only",
201
- }),
202
- )
203
- }
204
- ts.forEachChild(n, visit)
205
- }
206
- visit(tree)
207
- }
208
- return findings
209
- },
210
- }
211
-
212
- export const nanoListKeyRule: CheckRule = {
213
- code: "NF-C022",
214
- title: "nano bindList key check",
215
- async scan(ctx) {
216
- const loaded = await loadRuleTypeScript(ctx)
217
- if (loaded.diagnostics !== undefined) return loaded.diagnostics
218
- const ts = loaded.compiler
219
- if (ts === undefined) return [toolchainMissing("NF-C022")]
220
- const findings: Diagnostic[] = []
221
- for (const file of ctx.project.source.files) {
222
- const tree = parsedTree(ts, ctx.project.source, file)
223
- if (tree === undefined) continue
224
- const visit = (n: TSApi.Node): void => {
225
- if (
226
- ts.isCallExpression(n) &&
227
- ts.isIdentifier(n.expression) &&
228
- n.expression.text === "bindList"
229
- ) {
230
- const key = keyFn(ts, n)
231
- if (key !== undefined && returnsSecondParam(ts, key)) {
232
- findings.push(
233
- diagnostic({
234
- code: "NF-C022",
235
- severity: "warn",
236
- file,
237
- line: lineOf(tree, key),
238
- message:
239
- "bindList key is the array index - add/remove/reorder will reuse the wrong node. Key by a stable id on the item instead",
240
- evidence: ["key: (_, i) => i"],
241
- fix: { recipe: "nano.stable-key", command: "nifra_docs nano" },
242
- verify: "nifra check --lints-only",
243
- }),
244
- )
245
- }
246
- }
247
- ts.forEachChild(n, visit)
248
- }
249
- visit(tree)
250
- }
251
- return findings
252
- },
253
- }
254
-
255
- export const nanoComputedDepsRule: CheckRule = {
256
- code: "NF-C023",
257
- title: "nano computed deps check",
258
- async scan(ctx) {
259
- const loaded = await loadRuleTypeScript(ctx)
260
- if (loaded.diagnostics !== undefined) return loaded.diagnostics
261
- const ts = loaded.compiler
262
- if (ts === undefined) return [toolchainMissing("NF-C023")]
263
- const findings: Diagnostic[] = []
264
- for (const file of ctx.project.source.files) {
265
- const tree = parsedTree(ts, ctx.project.source, file)
266
- if (tree === undefined) continue
267
- const reactive = reactiveBindings(ts, tree)
268
- if (reactive.size === 0) continue
269
- const visit = (n: TSApi.Node): void => {
270
- const fnArg = ts.isCallExpression(n) ? n.arguments[0] : undefined
271
- const depsArg = ts.isCallExpression(n) ? n.arguments[1] : undefined
272
- const callName =
273
- ts.isCallExpression(n) && ts.isIdentifier(n.expression) ? n.expression.text : undefined
274
- if (
275
- (callName === "computed" || callName === "resource") &&
276
- fnArg !== undefined &&
277
- depsArg !== undefined &&
278
- isFn(ts, fnArg)
279
- ) {
280
- const reads = getsInside(ts, fnArg, reactive)
281
- const deps = declaredDeps(ts, depsArg)
282
- const missing = [...reads].filter((r) => !deps.has(r))
283
- if (missing.length > 0) {
284
- const verb = callName === "resource" ? "refetch" : "recompute"
285
- findings.push(
286
- diagnostic({
287
- code: "NF-C023",
288
- severity: "warn",
289
- file,
290
- line: lineOf(tree, n),
291
- message: `${callName} reads ${JSON.stringify([...reads])} but its deps declare ${JSON.stringify([...deps])} - it will not ${verb} when ${missing.join(", ")} changes. Add ${missing.join(", ")} to the deps array`,
292
- evidence: [`missing dep: ${missing.join(", ")}`],
293
- fix: { recipe: "nano.declare-deps", command: "nifra_docs nano" },
294
- verify: "nifra check --lints-only",
295
- }),
296
- )
297
- }
298
- }
299
- ts.forEachChild(n, visit)
300
- }
301
- visit(tree)
302
- }
303
- return findings
304
- },
305
- }
306
-
307
- export const nanoRules = Object.freeze([nanoBindCleanupRule, nanoListKeyRule, nanoComputedDepsRule])