@nifrajs/cli 5.17.0 → 5.18.1
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 +67 -0
- package/dist/check-diagnostics.d.ts +7 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan-sql.d.ts +95 -0
- package/dist/check-scan-sql.d.ts.map +1 -0
- package/dist/check-scan-sql.js +1190 -0
- package/dist/check-scan-sql.js.map +1 -0
- package/dist/check-scan.d.ts +5 -93
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +20 -1207
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +9 -0
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +2 -6
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +249 -80
- 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 +18 -4
- package/dist/command-catalog.js.map +1 -1
- package/dist/frontend-guidance.js +1 -1
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/internal/a11y-element.d.ts +33 -0
- package/dist/internal/a11y-element.d.ts.map +1 -0
- package/dist/internal/a11y-element.js +124 -0
- package/dist/internal/a11y-element.js.map +1 -0
- package/dist/internal/a11y-jsx.d.ts +12 -0
- package/dist/internal/a11y-jsx.d.ts.map +1 -0
- package/dist/internal/a11y-jsx.js +42 -0
- package/dist/internal/a11y-jsx.js.map +1 -0
- package/dist/internal/a11y-template.d.ts +11 -0
- package/dist/internal/a11y-template.d.ts.map +1 -0
- package/dist/internal/a11y-template.js +56 -0
- package/dist/internal/a11y-template.js.map +1 -0
- package/dist/internal/aria-data.d.ts +23 -0
- package/dist/internal/aria-data.d.ts.map +1 -0
- package/dist/internal/aria-data.js +220 -0
- package/dist/internal/aria-data.js.map +1 -0
- package/dist/internal/edit-distance.d.ts +3 -0
- package/dist/internal/edit-distance.d.ts.map +1 -0
- package/dist/internal/edit-distance.js +12 -0
- package/dist/internal/edit-distance.js.map +1 -0
- package/dist/internal/imported-as.d.ts +10 -0
- package/dist/internal/imported-as.d.ts.map +1 -0
- package/dist/internal/imported-as.js +23 -0
- package/dist/internal/imported-as.js.map +1 -0
- package/dist/internal/source-facts.d.ts +3 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +2 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/template-markup.d.ts +58 -0
- package/dist/internal/template-markup.d.ts.map +1 -0
- package/dist/internal/template-markup.js +221 -0
- package/dist/internal/template-markup.js.map +1 -0
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +11 -0
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +37 -23
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +5 -3
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-root.js +1 -1
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +3 -2
- package/dist/mcp-ws.js.map +1 -1
- package/dist/migrate-layout-config.d.ts +63 -0
- package/dist/migrate-layout-config.d.ts.map +1 -0
- package/dist/migrate-layout-config.js +507 -0
- package/dist/migrate-layout-config.js.map +1 -0
- package/dist/migrate-layout-split.d.ts +46 -0
- package/dist/migrate-layout-split.d.ts.map +1 -0
- package/dist/migrate-layout-split.js +687 -0
- package/dist/migrate-layout-split.js.map +1 -0
- package/dist/migrate-layout.d.ts +4 -24
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +8 -1183
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +78 -10
- package/dist/output-schemas.js.map +1 -1
- package/dist/recipes/5.18.0.d.ts +9 -0
- package/dist/recipes/5.18.0.d.ts.map +1 -0
- package/dist/recipes/5.18.0.js +56 -0
- package/dist/recipes/5.18.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 +6 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/a11y.d.ts +5 -0
- package/dist/rules/a11y.d.ts.map +1 -0
- package/dist/rules/a11y.js +78 -0
- package/dist/rules/a11y.js.map +1 -0
- package/dist/rules/codes.d.ts +6 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +6 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/comment-markers.js +1 -1
- package/dist/rules/comment-markers.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +30 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/host-exposure.d.ts +23 -0
- package/dist/rules/host-exposure.d.ts.map +1 -0
- package/dist/rules/host-exposure.js +380 -0
- package/dist/rules/host-exposure.js.map +1 -0
- package/dist/rules/internal-links.d.ts.map +1 -1
- package/dist/rules/internal-links.js +16 -141
- package/dist/rules/internal-links.js.map +1 -1
- package/dist/rules/islands.d.ts +54 -0
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +577 -80
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/security.d.ts +1 -0
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +34 -7
- package/dist/rules/security.js.map +1 -1
- package/dist/runtime-differences.js +3 -3
- package/dist/runtime-differences.js.map +1 -1
- package/dist/scaffold.d.ts +1 -1
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +2 -2
- package/dist/scaffold.js.map +1 -1
- package/dist/source-rewrites.d.ts.map +1 -1
- package/dist/source-rewrites.js +2 -19
- package/dist/source-rewrites.js.map +1 -1
- package/docs/examples.json +4 -4
- package/docs/llms-full.txt +422 -42
- package/docs/types.json +466 -56
- package/package.json +12 -12
- package/src/check-diagnostics.ts +11 -0
- package/src/check-scan-sql.ts +1746 -0
- package/src/check-scan.ts +34 -1754
- package/src/check.ts +10 -1
- package/src/cli.ts +258 -98
- package/src/command-catalog.ts +21 -4
- package/src/frontend-guidance.ts +1 -1
- package/src/internal/a11y-element.ts +227 -0
- package/src/internal/a11y-jsx.ts +54 -0
- package/src/internal/a11y-template.ts +74 -0
- package/src/internal/aria-data.ts +242 -0
- package/src/internal/edit-distance.ts +16 -0
- package/src/internal/imported-as.ts +30 -0
- package/src/internal/source-facts.ts +4 -0
- package/src/internal/template-markup.ts +270 -0
- package/src/internal/typescript-import.ts +15 -0
- package/src/mcp-exec.ts +43 -22
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +5 -3
- package/src/mcp-root.ts +1 -1
- package/src/mcp-ws.ts +3 -2
- package/src/migrate-layout-config.ts +615 -0
- package/src/migrate-layout-split.ts +870 -0
- package/src/migrate-layout.ts +37 -1468
- package/src/output-schemas.ts +85 -17
- package/src/recipes/5.18.0.ts +63 -0
- package/src/recipes/index.ts +2 -0
- package/src/review.ts +6 -0
- package/src/rules/a11y.ts +119 -0
- package/src/rules/codes.ts +6 -0
- package/src/rules/comment-markers.ts +2 -2
- package/src/rules/explanations.ts +30 -0
- package/src/rules/host-exposure.ts +531 -0
- package/src/rules/internal-links.ts +21 -154
- package/src/rules/islands.ts +698 -86
- package/src/rules/security.ts +48 -7
- package/src/runtime-differences.ts +3 -3
- package/src/scaffold.ts +3 -3
- 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 {
|
|
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 {
|
|
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
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
356
|
-
? (
|
|
357
|
-
:
|
|
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
|
-
|
|
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
|
|
412
|
-
for
|
|
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
|