@nifrajs/cli 5.17.0 → 5.18.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 (178) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/check-diagnostics.d.ts +7 -0
  3. package/dist/check-diagnostics.d.ts.map +1 -1
  4. package/dist/check-diagnostics.js +3 -0
  5. package/dist/check-diagnostics.js.map +1 -1
  6. package/dist/check-scan-sql.d.ts +95 -0
  7. package/dist/check-scan-sql.d.ts.map +1 -0
  8. package/dist/check-scan-sql.js +1190 -0
  9. package/dist/check-scan-sql.js.map +1 -0
  10. package/dist/check-scan.d.ts +5 -93
  11. package/dist/check-scan.d.ts.map +1 -1
  12. package/dist/check-scan.js +20 -1207
  13. package/dist/check-scan.js.map +1 -1
  14. package/dist/check.d.ts.map +1 -1
  15. package/dist/check.js +9 -0
  16. package/dist/check.js.map +1 -1
  17. package/dist/cli.d.ts +2 -6
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +249 -80
  20. package/dist/cli.js.map +1 -1
  21. package/dist/command-catalog.d.ts +3 -0
  22. package/dist/command-catalog.d.ts.map +1 -1
  23. package/dist/command-catalog.js +18 -4
  24. package/dist/command-catalog.js.map +1 -1
  25. package/dist/frontend-guidance.js +1 -1
  26. package/dist/frontend-guidance.js.map +1 -1
  27. package/dist/internal/a11y-element.d.ts +33 -0
  28. package/dist/internal/a11y-element.d.ts.map +1 -0
  29. package/dist/internal/a11y-element.js +124 -0
  30. package/dist/internal/a11y-element.js.map +1 -0
  31. package/dist/internal/a11y-jsx.d.ts +12 -0
  32. package/dist/internal/a11y-jsx.d.ts.map +1 -0
  33. package/dist/internal/a11y-jsx.js +42 -0
  34. package/dist/internal/a11y-jsx.js.map +1 -0
  35. package/dist/internal/a11y-template.d.ts +11 -0
  36. package/dist/internal/a11y-template.d.ts.map +1 -0
  37. package/dist/internal/a11y-template.js +56 -0
  38. package/dist/internal/a11y-template.js.map +1 -0
  39. package/dist/internal/aria-data.d.ts +23 -0
  40. package/dist/internal/aria-data.d.ts.map +1 -0
  41. package/dist/internal/aria-data.js +220 -0
  42. package/dist/internal/aria-data.js.map +1 -0
  43. package/dist/internal/edit-distance.d.ts +3 -0
  44. package/dist/internal/edit-distance.d.ts.map +1 -0
  45. package/dist/internal/edit-distance.js +12 -0
  46. package/dist/internal/edit-distance.js.map +1 -0
  47. package/dist/internal/imported-as.d.ts +10 -0
  48. package/dist/internal/imported-as.d.ts.map +1 -0
  49. package/dist/internal/imported-as.js +23 -0
  50. package/dist/internal/imported-as.js.map +1 -0
  51. package/dist/internal/source-facts.d.ts +3 -0
  52. package/dist/internal/source-facts.d.ts.map +1 -1
  53. package/dist/internal/source-facts.js +2 -0
  54. package/dist/internal/source-facts.js.map +1 -1
  55. package/dist/internal/template-markup.d.ts +58 -0
  56. package/dist/internal/template-markup.d.ts.map +1 -0
  57. package/dist/internal/template-markup.js +221 -0
  58. package/dist/internal/template-markup.js.map +1 -0
  59. package/dist/internal/typescript-import.d.ts.map +1 -1
  60. package/dist/internal/typescript-import.js +11 -0
  61. package/dist/internal/typescript-import.js.map +1 -1
  62. package/dist/mcp-exec.d.ts.map +1 -1
  63. package/dist/mcp-exec.js +37 -23
  64. package/dist/mcp-exec.js.map +1 -1
  65. package/dist/mcp-http.js +1 -1
  66. package/dist/mcp-io.d.ts.map +1 -1
  67. package/dist/mcp-io.js +5 -3
  68. package/dist/mcp-io.js.map +1 -1
  69. package/dist/mcp-root.js +1 -1
  70. package/dist/mcp-root.js.map +1 -1
  71. package/dist/mcp-ws.d.ts.map +1 -1
  72. package/dist/mcp-ws.js +3 -2
  73. package/dist/mcp-ws.js.map +1 -1
  74. package/dist/migrate-layout-config.d.ts +63 -0
  75. package/dist/migrate-layout-config.d.ts.map +1 -0
  76. package/dist/migrate-layout-config.js +507 -0
  77. package/dist/migrate-layout-config.js.map +1 -0
  78. package/dist/migrate-layout-split.d.ts +46 -0
  79. package/dist/migrate-layout-split.d.ts.map +1 -0
  80. package/dist/migrate-layout-split.js +687 -0
  81. package/dist/migrate-layout-split.js.map +1 -0
  82. package/dist/migrate-layout.d.ts +4 -24
  83. package/dist/migrate-layout.d.ts.map +1 -1
  84. package/dist/migrate-layout.js +8 -1183
  85. package/dist/migrate-layout.js.map +1 -1
  86. package/dist/output-schemas.d.ts.map +1 -1
  87. package/dist/output-schemas.js +78 -10
  88. package/dist/output-schemas.js.map +1 -1
  89. package/dist/recipes/5.18.0.d.ts +9 -0
  90. package/dist/recipes/5.18.0.d.ts.map +1 -0
  91. package/dist/recipes/5.18.0.js +56 -0
  92. package/dist/recipes/5.18.0.js.map +1 -0
  93. package/dist/recipes/index.d.ts.map +1 -1
  94. package/dist/recipes/index.js +2 -0
  95. package/dist/recipes/index.js.map +1 -1
  96. package/dist/review.d.ts.map +1 -1
  97. package/dist/review.js +6 -0
  98. package/dist/review.js.map +1 -1
  99. package/dist/rules/a11y.d.ts +5 -0
  100. package/dist/rules/a11y.d.ts.map +1 -0
  101. package/dist/rules/a11y.js +78 -0
  102. package/dist/rules/a11y.js.map +1 -0
  103. package/dist/rules/codes.d.ts +6 -0
  104. package/dist/rules/codes.d.ts.map +1 -1
  105. package/dist/rules/codes.js +6 -0
  106. package/dist/rules/codes.js.map +1 -1
  107. package/dist/rules/comment-markers.js +1 -1
  108. package/dist/rules/comment-markers.js.map +1 -1
  109. package/dist/rules/explanations.d.ts.map +1 -1
  110. package/dist/rules/explanations.js +30 -0
  111. package/dist/rules/explanations.js.map +1 -1
  112. package/dist/rules/host-exposure.d.ts +23 -0
  113. package/dist/rules/host-exposure.d.ts.map +1 -0
  114. package/dist/rules/host-exposure.js +380 -0
  115. package/dist/rules/host-exposure.js.map +1 -0
  116. package/dist/rules/internal-links.d.ts.map +1 -1
  117. package/dist/rules/internal-links.js +16 -141
  118. package/dist/rules/internal-links.js.map +1 -1
  119. package/dist/rules/islands.d.ts +54 -0
  120. package/dist/rules/islands.d.ts.map +1 -1
  121. package/dist/rules/islands.js +577 -80
  122. package/dist/rules/islands.js.map +1 -1
  123. package/dist/rules/security.d.ts +1 -0
  124. package/dist/rules/security.d.ts.map +1 -1
  125. package/dist/rules/security.js +34 -7
  126. package/dist/rules/security.js.map +1 -1
  127. package/dist/runtime-differences.js +3 -3
  128. package/dist/runtime-differences.js.map +1 -1
  129. package/dist/scaffold.d.ts +1 -1
  130. package/dist/scaffold.d.ts.map +1 -1
  131. package/dist/scaffold.js +2 -2
  132. package/dist/scaffold.js.map +1 -1
  133. package/dist/source-rewrites.d.ts.map +1 -1
  134. package/dist/source-rewrites.js +2 -19
  135. package/dist/source-rewrites.js.map +1 -1
  136. package/docs/examples.json +4 -4
  137. package/docs/llms-full.txt +422 -42
  138. package/docs/types.json +466 -56
  139. package/package.json +12 -12
  140. package/src/check-diagnostics.ts +11 -0
  141. package/src/check-scan-sql.ts +1746 -0
  142. package/src/check-scan.ts +34 -1754
  143. package/src/check.ts +10 -1
  144. package/src/cli.ts +258 -98
  145. package/src/command-catalog.ts +21 -4
  146. package/src/frontend-guidance.ts +1 -1
  147. package/src/internal/a11y-element.ts +227 -0
  148. package/src/internal/a11y-jsx.ts +54 -0
  149. package/src/internal/a11y-template.ts +74 -0
  150. package/src/internal/aria-data.ts +242 -0
  151. package/src/internal/edit-distance.ts +16 -0
  152. package/src/internal/imported-as.ts +30 -0
  153. package/src/internal/source-facts.ts +4 -0
  154. package/src/internal/template-markup.ts +270 -0
  155. package/src/internal/typescript-import.ts +15 -0
  156. package/src/mcp-exec.ts +43 -22
  157. package/src/mcp-http.ts +1 -1
  158. package/src/mcp-io.ts +5 -3
  159. package/src/mcp-root.ts +1 -1
  160. package/src/mcp-ws.ts +3 -2
  161. package/src/migrate-layout-config.ts +615 -0
  162. package/src/migrate-layout-split.ts +870 -0
  163. package/src/migrate-layout.ts +37 -1468
  164. package/src/output-schemas.ts +85 -17
  165. package/src/recipes/5.18.0.ts +63 -0
  166. package/src/recipes/index.ts +2 -0
  167. package/src/review.ts +6 -0
  168. package/src/rules/a11y.ts +119 -0
  169. package/src/rules/codes.ts +6 -0
  170. package/src/rules/comment-markers.ts +2 -2
  171. package/src/rules/explanations.ts +30 -0
  172. package/src/rules/host-exposure.ts +531 -0
  173. package/src/rules/internal-links.ts +21 -154
  174. package/src/rules/islands.ts +698 -86
  175. package/src/rules/security.ts +48 -7
  176. package/src/runtime-differences.ts +3 -3
  177. package/src/scaffold.ts +3 -3
  178. package/src/source-rewrites.ts +2 -15
@@ -1,12 +1,17 @@
1
1
  import { existsSync, readFileSync } from "node:fs"
2
2
  import { join } from "node:path"
3
- import { Glob } from "bun"
4
3
  import { CONFIG_FILE, FRAMEWORK_FILE } from "../app-files.ts"
5
- import { IGNORED, stripComments } from "../check-scan.ts"
4
+ import { stripComments } from "../check-scan.ts"
6
5
  import { type Diagnostic, diagnostic } from "../diagnostics.ts"
7
6
  import { codeUnitOrder } from "../internal/code-unit-order.ts"
8
- import { toPosix } from "../internal/posix-path.ts"
7
+ import { distance } from "../internal/edit-distance.ts"
9
8
  import { ANCHOR_HOLE } from "../internal/source-facts.ts"
9
+ import {
10
+ lineLookup,
11
+ readAttributes,
12
+ scanTemplate,
13
+ templateFiles,
14
+ } from "../internal/template-markup.ts"
10
15
  import { buildRouteTable } from "../introspect.ts"
11
16
  import { commentBlockExpectation } from "./comment-markers.ts"
12
17
  import type { CheckRule, RuleContext } from "./index.ts"
@@ -27,11 +32,6 @@ import { scanSources } from "./source-scan.ts"
27
32
 
28
33
  const TEST_DIR = /(?:^|\/)(?:tests?|__tests__)\//
29
34
  const FILE_EXTENSION = /\.[A-Za-z0-9]{1,8}$/
30
- // One attribute of a tag, matched where the previous one ended (sticky), so a tag is read in one pass:
31
- // `href="/x"`, `href='/x'`, `href={"/x"}` or `` href={`/x`} `` (Svelte), and Vue's `:href="'/x'"`. Any
32
- // other `{...}` value is an expression and names no path.
33
- const ATTRIBUTE =
34
- /\s+([^\s=>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|\{\s*(?:"([^"]*)"|'([^']*)'|`([^`]*)`)\s*\}|\{[^}]*\}))?/y
35
35
  const BOUND_LITERAL = /^\s*(?:'([^']*)'|"([^"]*)"|`([^`$]*)`)\s*$/
36
36
 
37
37
  interface Judged {
@@ -52,22 +52,6 @@ interface PageRoutes {
52
52
 
53
53
  const cache = new WeakMap<RuleContext, Promise<PageRoutes | undefined>>()
54
54
 
55
- function distance(a: string, b: string): number {
56
- let row = Array.from({ length: b.length + 1 }, (_, i) => i)
57
- for (let i = 1; i <= a.length; i++) {
58
- const next = [i]
59
- for (let j = 1; j <= b.length; j++) {
60
- next[j] = Math.min(
61
- (row[j] ?? 0) + 1,
62
- (next[j - 1] ?? 0) + 1,
63
- (row[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1),
64
- )
65
- }
66
- row = next
67
- }
68
- return row[b.length] ?? 0
69
- }
70
-
71
55
  /** Read only literal mount exports, never import/evaluate the app's config. An unreadable field
72
56
  * leaves the dead-link verdict open, just like an unreadable backend registration. */
73
57
  function backendMount(
@@ -259,47 +243,6 @@ function report(
259
243
  })
260
244
  }
261
245
 
262
- interface HtmlComment {
263
- readonly start: number
264
- /** Where the text after `<!--` stops: before the closing delimiter. */
265
- readonly bodyEnd: number
266
- readonly end: number
267
- }
268
-
269
- // A comment ends at `-->` or `--!>`.
270
- const COMMENT_END = /--!?>/g
271
-
272
- /** The comment opened at `start`, which HTML ends at `-->` or `--!>`; `<!-->` and `<!--->` are empty. */
273
- function commentAt(text: string, start: number): HtmlComment {
274
- const body = start + 4
275
- if (text.startsWith(">", body)) return { start, bodyEnd: body, end: body + 1 }
276
- if (text.startsWith("->", body)) return { start, bodyEnd: body, end: body + 2 }
277
- COMMENT_END.lastIndex = body
278
- const close = COMMENT_END.exec(text)
279
- return close === null
280
- ? { start, bodyEnd: text.length, end: text.length }
281
- : { start, bodyEnd: close.index, end: close.index + close[0].length }
282
- }
283
-
284
- /** The end of a markup tag or `{expression}`, ignoring `>`/braces inside quoted values. */
285
- function markupEnd(text: string, start: number, expression = false): number {
286
- let quote: string | undefined
287
- let braces = expression ? 1 : 0
288
- for (let at = start; at < text.length; at++) {
289
- const char = text[at]
290
- if (quote !== undefined) {
291
- if (braces > 0 && char === "\\") at++
292
- else if (char === quote) quote = undefined
293
- } else if (char === '"' || char === "'" || (braces > 0 && char === "`")) quote = char
294
- else if (char === "{") braces++
295
- else if (char === "}") {
296
- braces--
297
- if (expression && braces === 0) return at + 1
298
- } else if (!expression && braces === 0 && char === ">") return at + 1
299
- }
300
- return text.length
301
- }
302
-
303
246
  /** Scan markup, not script strings, HTML comments or other tags' quoted attributes. The existing
304
247
  * componentScripts scanner only extracts scripts and cannot distinguish these template regions. */
305
248
  function templateHrefs(
@@ -309,95 +252,24 @@ function templateHrefs(
309
252
  readonly hrefs: Array<{ readonly at: number; readonly tagAt: number; readonly value: string }>
310
253
  readonly expectationLines: readonly string[]
311
254
  } {
255
+ const { tags, expectationLines } = scanTemplate(text, vue)
312
256
  const hrefs: Array<{ at: number; tagAt: number; value: string }> = []
313
- const comments: HtmlComment[] = []
314
- let templateDepth = 0
315
- for (let at = 0; at < text.length; ) {
316
- if (text.startsWith("<!--", at)) {
317
- const comment = commentAt(text, at)
318
- comments.push(comment)
319
- at = comment.end
320
- continue
321
- }
322
- if (text[at] === "{" && (!vue || text.startsWith("{{", at))) {
323
- at = markupEnd(text, at + 1, true)
324
- continue
325
- }
326
- if (text[at] !== "<") {
327
- at++
328
- continue
329
- }
330
- const tag = /^<(\/?)([\w-]+)(?=[\s/>])/.exec(text.slice(at))
331
- if (tag === null) {
332
- at++
333
- continue
334
- }
335
- const tagAt = at
336
- const end = markupEnd(text, at + tag[0].length)
337
- const name = tag[2]?.toLowerCase()
338
- const closing = tag[1] === "/"
339
- at = end
340
- if (!closing && (name === "script" || name === "style")) {
341
- const close = name === "script" ? /<\/script\s*>/gi : /<\/style\s*>/gi
342
- close.lastIndex = end
343
- const match = close.exec(text)
344
- at = match === null ? text.length : close.lastIndex
345
- continue
346
- }
347
- if (name === "template") templateDepth += closing ? -1 : 1
348
- if (closing || name !== "a" || (vue && templateDepth <= 0)) continue
349
- ATTRIBUTE.lastIndex = tagAt + tag[0].length
350
- for (let match = ATTRIBUTE.exec(text); match !== null; match = ATTRIBUTE.exec(text)) {
351
- const [whole, attribute, doubled, single, braceDouble, braceSingle, braceTemplate] = match
352
- if (attribute !== "href" && attribute !== ":href" && attribute !== "v-bind:href") continue
353
- const raw = doubled ?? single
257
+ for (const tag of tags) {
258
+ if (tag.name !== "a" || !tag.inTemplate) continue
259
+ for (const attribute of readAttributes(text, tag)) {
260
+ const { name, quoted } = attribute
261
+ if (name !== "href" && name !== ":href" && name !== "v-bind:href") continue
354
262
  const value =
355
- attribute === "href"
356
- ? (raw ?? braceDouble ?? braceSingle ?? braceTemplate)
357
- : raw
263
+ name === "href"
264
+ ? (quoted ?? attribute.braceString)
265
+ : quoted
358
266
  ?.match(BOUND_LITERAL)
359
267
  ?.slice(1)
360
268
  .find((part) => part !== undefined)
361
- if (value !== undefined)
362
- hrefs.push({
363
- at: ATTRIBUTE.lastIndex - whole.length + whole.indexOf(attribute),
364
- tagAt,
365
- value,
366
- })
269
+ if (value !== undefined) hrefs.push({ at: attribute.at, tagAt: tag.at, value })
367
270
  }
368
271
  }
369
- // Adapt only real HTML comments to the shared directive parser. Non-comment code stays a block
370
- // boundary; quoted marker text cannot suppress anything. Line counts are unchanged.
371
- const code = (part: string): string => part.replace(/[^\s]/g, "x")
372
- let expectations = ""
373
- let previous = 0
374
- for (const comment of comments) {
375
- expectations += code(text.slice(previous, comment.start))
376
- expectations += text
377
- .slice(comment.start + 4, comment.bodyEnd)
378
- .split("\n")
379
- .map((line) => `// ${line}`)
380
- .join("\n")
381
- previous = comment.end
382
- }
383
- expectations += code(text.slice(previous))
384
- return { hrefs, expectationLines: expectations.split("\n") }
385
- }
386
-
387
- /** The 1-based line of an offset in `text`: a search over the line starts, so a file with thousands of links is not re-split for each. */
388
- function lineLookup(text: string): (offset: number) => number {
389
- const starts = [0]
390
- for (let at = text.indexOf("\n"); at !== -1; at = text.indexOf("\n", at + 1)) starts.push(at + 1)
391
- return (offset) => {
392
- let low = 0
393
- let high = starts.length - 1
394
- while (low < high) {
395
- const mid = (low + high + 1) >> 1
396
- if ((starts[mid] ?? 0) <= offset) low = mid
397
- else high = mid - 1
398
- }
399
- return low + 1
400
- }
272
+ return { hrefs, expectationLines }
401
273
  }
402
274
 
403
275
  async function templateFindings(
@@ -408,13 +280,8 @@ async function templateFindings(
408
280
  severity: "warn" | "info",
409
281
  ): Promise<Diagnostic[]> {
410
282
  const findings: Diagnostic[] = []
411
- const files: string[] = []
412
- for await (const entry of new Glob("**/*.{vue,svelte}").scan({ cwd: ctx.root, dot: false })) {
413
- // Bun yields `\` paths on Windows, which IGNORED and TEST_DIR (and the reported location) expect as `/`.
414
- const file = toPosix(entry)
415
- if (!IGNORED.test(file) && !TEST_DIR.test(file)) files.push(file)
416
- }
417
- for (const file of files.sort()) {
283
+ const files = await templateFiles(ctx.root)
284
+ for (const file of files) {
418
285
  // The source index holds only a component's script blocks; the links are in its template.
419
286
  const text = readFileSync(join(ctx.root, file), "utf8")
420
287
  if (!text.includes("href")) continue