@nifrajs/cli 5.8.0 → 5.10.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 +191 -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-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 +3 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +62 -87
- 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 +27 -25
- 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 +53 -20
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +1 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -49
- 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 +30 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +155 -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 +8 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +5 -0
- 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-http.js.map +1 -1
- 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-tool-meta.d.ts.map +1 -1
- package/dist/mcp-tool-meta.js +0 -1
- package/dist/mcp-tool-meta.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.10.0.d.ts +12 -0
- package/dist/recipes/5.10.0.d.ts.map +1 -0
- package/dist/recipes/5.10.0.js +44 -0
- package/dist/recipes/5.10.0.js.map +1 -0
- 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 +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +12 -13
- 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/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/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +15 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/internal-links.d.ts +5 -0
- package/dist/rules/internal-links.d.ts.map +1 -0
- package/dist/rules/internal-links.js +418 -0
- package/dist/rules/internal-links.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +20 -0
- package/dist/rules/legacy.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/server-fn-namespace.d.ts +8 -0
- package/dist/rules/server-fn-namespace.d.ts.map +1 -0
- package/dist/rules/server-fn-namespace.js +43 -0
- package/dist/rules/server-fn-namespace.js.map +1 -0
- package/dist/rules/source-scan.d.ts +29 -0
- package/dist/rules/source-scan.d.ts.map +1 -0
- package/dist/rules/source-scan.js +38 -0
- package/dist/rules/source-scan.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -1
- package/dist/rules/text-slot-boolean.js +21 -43
- package/dist/rules/text-slot-boolean.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 +517 -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/typecheck-coverage.d.ts +9 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +16 -0
- package/dist/typecheck-coverage.js.map +1 -1
- 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 +51 -9
- package/docs/llms-full.txt +1296 -287
- package/docs/types.json +854 -170
- 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-diagnostics.ts +5 -0
- package/src/check-scan.ts +74 -83
- package/src/check.ts +40 -26
- package/src/cli.ts +76 -20
- package/src/command-catalog.ts +22 -56
- 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 +194 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +15 -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-tool-meta.ts +0 -1
- 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.10.0.ts +45 -0
- package/src/recipes/5.9.0.ts +42 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +15 -15
- package/src/rules/codes.ts +3 -0
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/explanations.ts +15 -0
- package/src/rules/internal-links.ts +490 -0
- package/src/rules/legacy.ts +21 -0
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- package/src/rules/server-fn-namespace.ts +47 -0
- package/src/rules/source-scan.ts +66 -0
- package/src/rules/text-slot-boolean.ts +26 -42
- 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 +592 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/typecheck-coverage.ts +23 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
- package/dist/sync-routes.d.ts +0 -29
- package/dist/sync-routes.d.ts.map +0 -1
- package/dist/sync-routes.js +0 -56
- package/dist/sync-routes.js.map +0 -1
- package/src/sync-routes.ts +0 -70
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source rewrites an upgrade recipe names: the edits an import move cannot express, made on the
|
|
3
|
+
* syntax tree with the project's own TypeScript. A rewrite changes only a shape it recognizes whole
|
|
4
|
+
* and lists every other site for the user to edit by hand; it never guesses.
|
|
5
|
+
*/
|
|
6
|
+
import type * as TS from "typescript"
|
|
7
|
+
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
8
|
+
import { scriptKindOf } from "./internal/script-kind.ts"
|
|
9
|
+
|
|
10
|
+
/** A site a rewrite found and left alone, with what to write instead. */
|
|
11
|
+
export interface ManualSite {
|
|
12
|
+
readonly line: number
|
|
13
|
+
readonly reason: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RewriteResult {
|
|
17
|
+
readonly text: string
|
|
18
|
+
/** Sites rewritten. */
|
|
19
|
+
readonly count: number
|
|
20
|
+
readonly manual: readonly ManualSite[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SourceRewrite {
|
|
24
|
+
readonly id: string
|
|
25
|
+
/** What it rewrites, for the plan. */
|
|
26
|
+
readonly description: string
|
|
27
|
+
/** Whether `text` may hold a site: a file it refuses is never parsed. */
|
|
28
|
+
readonly mentions: (text: string) => boolean
|
|
29
|
+
readonly rewrite: (ts: typeof TS, file: string, text: string) => RewriteResult
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Edit {
|
|
33
|
+
readonly start: number
|
|
34
|
+
readonly end: number
|
|
35
|
+
readonly text: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Apply `edits` (disjoint ranges) to `text`, from the end so earlier offsets stay valid. */
|
|
39
|
+
function applyEdits(text: string, edits: readonly Edit[]): string {
|
|
40
|
+
let out = text
|
|
41
|
+
for (const edit of edits.toSorted((a, b) => b.start - a.start)) {
|
|
42
|
+
out = `${out.slice(0, edit.start)}${edit.text}${out.slice(edit.end)}`
|
|
43
|
+
}
|
|
44
|
+
return out
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const WEB = "@nifrajs/web"
|
|
48
|
+
const NODE = "@nifrajs/node"
|
|
49
|
+
const DENO = "@nifrajs/deno"
|
|
50
|
+
const CORE_STATIC = "@nifrajs/core/serve-static"
|
|
51
|
+
const DAY = '"public, max-age=86400"'
|
|
52
|
+
const YEAR = "public, max-age=31536000, immutable"
|
|
53
|
+
const PUBLIC_DIR_KEYS = new Set(["dir", "hashedPrefix", "hashedFiles", "cache", "files"])
|
|
54
|
+
const PUBLIC_DIR_FORM =
|
|
55
|
+
'serveStatic({ dir, prefix: "/", fallthrough: true, hashedFiles: (path) => path.startsWith("/assets/"), cacheControl: ONE_DAY })'
|
|
56
|
+
|
|
57
|
+
type Runtime = "core" | "node" | "deno"
|
|
58
|
+
|
|
59
|
+
/** The named imports of one module: the declaration, and each imported name's local binding. */
|
|
60
|
+
interface ModuleImport {
|
|
61
|
+
readonly declaration: TS.ImportDeclaration
|
|
62
|
+
readonly named: TS.NamedImports | undefined
|
|
63
|
+
readonly locals: Map<string, string>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function propertyName(ts: typeof TS, name: TS.PropertyName): string | undefined {
|
|
67
|
+
return ts.isIdentifier(name) || ts.isStringLiteral(name) ? name.text : undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 5.9: `servePublicDir` (removed from `@nifrajs/web`) becomes the runtime's `serveStatic` with the
|
|
72
|
+
* options that keep its answers; `@nifrajs/node`'s `static` mount objects are wrapped in
|
|
73
|
+
* `serveStatic()`; and `signals` on `@nifrajs/node`'s and `@nifrajs/deno`'s `serve()` becomes
|
|
74
|
+
* `gracefulSignals`.
|
|
75
|
+
*/
|
|
76
|
+
/** Parse `text` as `file`, with the line lookup a rewrite lists its manual sites by. */
|
|
77
|
+
function parseSource(ts: typeof TS, file: string, text: string) {
|
|
78
|
+
const tree = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, scriptKindOf(ts, file))
|
|
79
|
+
const lineOf = (node: TS.Node): number =>
|
|
80
|
+
tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1
|
|
81
|
+
return { tree, lineOf }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function rewriteServeStatic(ts: typeof TS, file: string, text: string): RewriteResult {
|
|
85
|
+
const { tree, lineOf } = parseSource(ts, file, text)
|
|
86
|
+
const edits: Edit[] = []
|
|
87
|
+
const manual: ManualSite[] = []
|
|
88
|
+
let count = 0
|
|
89
|
+
const source = (node: TS.Node): string => node.getText(tree)
|
|
90
|
+
const imports = new Map<string, ModuleImport>()
|
|
91
|
+
// Every import of @nifrajs/web, with the specifiers of names 5.9 moved out of it.
|
|
92
|
+
const webImports: {
|
|
93
|
+
readonly declaration: TS.ImportDeclaration
|
|
94
|
+
readonly named: TS.NamedImports
|
|
95
|
+
}[] = []
|
|
96
|
+
const publicDirSpecifiers = new Set<TS.ImportSpecifier>()
|
|
97
|
+
const hashedFilesSpecifiers = new Set<TS.ImportSpecifier>()
|
|
98
|
+
// A servePublicDir site left for the user keeps its import.
|
|
99
|
+
let publicDirLeft = false
|
|
100
|
+
let publicDir: string | undefined
|
|
101
|
+
let hashedFilesLocal: string | undefined
|
|
102
|
+
|
|
103
|
+
for (const statement of tree.statements) {
|
|
104
|
+
if (ts.isExportDeclaration(statement)) {
|
|
105
|
+
const from = statement.moduleSpecifier
|
|
106
|
+
if (from !== undefined && ts.isStringLiteral(from) && from.text === WEB) {
|
|
107
|
+
const names = source(statement)
|
|
108
|
+
if (/\b(?:servePublicDir|ServePublicDirOptions|PublicDirCache|HashedFiles)\b/.test(names)) {
|
|
109
|
+
manual.push({
|
|
110
|
+
line: lineOf(statement),
|
|
111
|
+
reason: `re-exports from ${WEB} a name 5.9 removed: re-export serveStatic, ServeStaticOptions or HashedFiles from ${CORE_STATIC}`,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
continue
|
|
116
|
+
}
|
|
117
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
118
|
+
continue
|
|
119
|
+
const from = statement.moduleSpecifier.text
|
|
120
|
+
const clause = statement.importClause
|
|
121
|
+
const bindings = clause?.namedBindings
|
|
122
|
+
const named = bindings !== undefined && ts.isNamedImports(bindings) ? bindings : undefined
|
|
123
|
+
const locals = new Map<string, string>()
|
|
124
|
+
for (const element of named?.elements ?? []) {
|
|
125
|
+
locals.set((element.propertyName ?? element.name).text, element.name.text)
|
|
126
|
+
}
|
|
127
|
+
if (!imports.has(from)) imports.set(from, { declaration: statement, named, locals })
|
|
128
|
+
if (from !== WEB) continue
|
|
129
|
+
if (named !== undefined) webImports.push({ declaration: statement, named })
|
|
130
|
+
if (
|
|
131
|
+
bindings !== undefined &&
|
|
132
|
+
ts.isNamespaceImport(bindings) &&
|
|
133
|
+
text.includes("servePublicDir")
|
|
134
|
+
) {
|
|
135
|
+
publicDirLeft = true
|
|
136
|
+
manual.push({
|
|
137
|
+
line: lineOf(statement),
|
|
138
|
+
reason: `servePublicDir through a namespace import of ${WEB}: call ${PUBLIC_DIR_FORM} from ${CORE_STATIC}`,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
for (const element of named?.elements ?? []) {
|
|
142
|
+
const imported = (element.propertyName ?? element.name).text
|
|
143
|
+
if (imported === "servePublicDir") {
|
|
144
|
+
publicDir = element.name.text
|
|
145
|
+
publicDirSpecifiers.add(element)
|
|
146
|
+
} else if (imported === "HashedFiles") {
|
|
147
|
+
hashedFilesLocal = element.name.text
|
|
148
|
+
hashedFilesSpecifiers.add(element)
|
|
149
|
+
} else if (imported === "ServePublicDirOptions" || imported === "PublicDirCache") {
|
|
150
|
+
manual.push({
|
|
151
|
+
line: lineOf(element),
|
|
152
|
+
reason: `${imported} is removed: type the options as ServeStaticOptions from ${CORE_STATIC}, whose fields differ (prefix, fallthrough, hashedFiles, cacheControl)`,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const nodeServe = new Set(
|
|
159
|
+
[...(imports.get(NODE)?.locals ?? [])].filter(([name]) => name === "serve").map(([, l]) => l),
|
|
160
|
+
)
|
|
161
|
+
const denoServe = new Set(
|
|
162
|
+
[...(imports.get(DENO)?.locals ?? [])].filter(([name]) => name === "serve").map(([, l]) => l),
|
|
163
|
+
)
|
|
164
|
+
// The file's runtime: a module that serves on Node or Deno gets that adapter's reader.
|
|
165
|
+
const runtime: Runtime = imports.has(NODE) ? "node" : imports.has(DENO) ? "deno" : "core"
|
|
166
|
+
const runtimeModule = runtime === "node" ? NODE : runtime === "deno" ? DENO : CORE_STATIC
|
|
167
|
+
const bound = new Set<string>()
|
|
168
|
+
const collect = (node: TS.Node): void => {
|
|
169
|
+
if (ts.isIdentifier(node)) bound.add(node.text)
|
|
170
|
+
ts.forEachChild(node, collect)
|
|
171
|
+
}
|
|
172
|
+
collect(tree)
|
|
173
|
+
// The local name of the runtime's serveStatic, or `undefined` when the name is taken by another binding.
|
|
174
|
+
const existingStatic = imports.get(runtimeModule)?.locals.get("serveStatic")
|
|
175
|
+
const staticName =
|
|
176
|
+
existingStatic ?? (bound.has("serveStatic") ? undefined : ("serveStatic" as const))
|
|
177
|
+
const coreDay = runtime === "core" && !bound.has("ONE_DAY")
|
|
178
|
+
let staticUsed = false
|
|
179
|
+
let dayUsed = false
|
|
180
|
+
|
|
181
|
+
const publicDirCall = (call: TS.CallExpression): void => {
|
|
182
|
+
const [options, ...rest] = call.arguments
|
|
183
|
+
const refuse = (why: string): void => {
|
|
184
|
+
publicDirLeft = true
|
|
185
|
+
manual.push({ line: lineOf(call), reason: `${why}: call ${PUBLIC_DIR_FORM}` })
|
|
186
|
+
}
|
|
187
|
+
if (staticName === undefined) {
|
|
188
|
+
refuse("`serveStatic` already names something else here")
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
if (options === undefined || rest.length > 0 || !ts.isObjectLiteralExpression(options)) {
|
|
192
|
+
refuse("servePublicDir with options built elsewhere")
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
const values = new Map<string, TS.Expression | undefined>()
|
|
196
|
+
for (const property of options.properties) {
|
|
197
|
+
const name =
|
|
198
|
+
ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)
|
|
199
|
+
? propertyName(ts, property.name)
|
|
200
|
+
: undefined
|
|
201
|
+
if (name === undefined || !PUBLIC_DIR_KEYS.has(name)) {
|
|
202
|
+
refuse(`servePublicDir option \`${source(property)}\` has no direct counterpart`)
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
values.set(name, ts.isPropertyAssignment(property) ? property.initializer : undefined)
|
|
206
|
+
}
|
|
207
|
+
if (!values.has("dir")) {
|
|
208
|
+
refuse("servePublicDir without a `dir`")
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
const field = (name: string, as = name): string => {
|
|
212
|
+
const value = values.get(name)
|
|
213
|
+
return value === undefined
|
|
214
|
+
? as === name
|
|
215
|
+
? name
|
|
216
|
+
: `${as}: ${name}`
|
|
217
|
+
: `${as}: ${source(value)}`
|
|
218
|
+
}
|
|
219
|
+
let cacheControl: string | undefined
|
|
220
|
+
if (values.has("cache")) {
|
|
221
|
+
const cache = values.get("cache")
|
|
222
|
+
if (cache === undefined || !ts.isObjectLiteralExpression(cache)) {
|
|
223
|
+
refuse("servePublicDir `cache` built elsewhere")
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
for (const property of cache.properties) {
|
|
227
|
+
const name = ts.isPropertyAssignment(property) ? propertyName(ts, property.name) : undefined
|
|
228
|
+
if (name === "assets" && ts.isPropertyAssignment(property)) {
|
|
229
|
+
cacheControl = source(property.initializer)
|
|
230
|
+
} else if (
|
|
231
|
+
name === "hashed" &&
|
|
232
|
+
ts.isPropertyAssignment(property) &&
|
|
233
|
+
ts.isStringLiteralLike(property.initializer) &&
|
|
234
|
+
property.initializer.text === YEAR
|
|
235
|
+
) {
|
|
236
|
+
// serveStatic's own cache-control for a content-hashed file.
|
|
237
|
+
} else {
|
|
238
|
+
refuse(
|
|
239
|
+
`servePublicDir \`cache.${name ?? "?"}\` has no counterpart: a content-hashed file is always sent \`${YEAR}\``,
|
|
240
|
+
)
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (cacheControl === undefined) {
|
|
246
|
+
if (coreDay) dayUsed = true
|
|
247
|
+
cacheControl = coreDay ? "ONE_DAY" : DAY
|
|
248
|
+
}
|
|
249
|
+
const prefixValue = values.get("hashedPrefix")
|
|
250
|
+
// A shorthand `hashedPrefix` is a binding of that name.
|
|
251
|
+
const hashedPrefix = !values.has("hashedPrefix")
|
|
252
|
+
? '"/assets/"'
|
|
253
|
+
: prefixValue === undefined
|
|
254
|
+
? "hashedPrefix"
|
|
255
|
+
: source(prefixValue)
|
|
256
|
+
const hashed = values.has("hashedFiles")
|
|
257
|
+
? field("hashedFiles")
|
|
258
|
+
: `hashedFiles: (path) => path.startsWith(${hashedPrefix})`
|
|
259
|
+
const fields = [
|
|
260
|
+
field("dir"),
|
|
261
|
+
'prefix: "/"',
|
|
262
|
+
// A miss is the app's: servePublicDir answered `undefined` for every path it could not serve.
|
|
263
|
+
"fallthrough: true",
|
|
264
|
+
hashed,
|
|
265
|
+
`cacheControl: ${cacheControl}`,
|
|
266
|
+
...(values.has("files") ? [field("files")] : []),
|
|
267
|
+
]
|
|
268
|
+
const literal = source(options)
|
|
269
|
+
let body: string
|
|
270
|
+
if (literal.includes("\n")) {
|
|
271
|
+
const first = options.properties[0]
|
|
272
|
+
const lineStart = (at: number): number => text.lastIndexOf("\n", at - 1) + 1
|
|
273
|
+
const indent =
|
|
274
|
+
first === undefined
|
|
275
|
+
? " "
|
|
276
|
+
: text.slice(lineStart(first.getStart(tree)), first.getStart(tree))
|
|
277
|
+
const close =
|
|
278
|
+
text.slice(lineStart(options.getStart(tree)), options.getStart(tree)).match(/^\s*/)?.[0] ??
|
|
279
|
+
""
|
|
280
|
+
body = `{\n${fields.map((f) => `${indent}${f},`).join("\n")}\n${close}}`
|
|
281
|
+
} else body = `{ ${fields.join(", ")} }`
|
|
282
|
+
edits.push({ start: call.getStart(tree), end: call.end, text: `${staticName}(${body})` })
|
|
283
|
+
staticUsed = true
|
|
284
|
+
count++
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const serveCall = (call: TS.CallExpression, node: boolean): void => {
|
|
288
|
+
const options = call.arguments[1]
|
|
289
|
+
if (options === undefined) return
|
|
290
|
+
if (!ts.isObjectLiteralExpression(options)) {
|
|
291
|
+
if (/\bsignals\b/.test(text) || (node && /\bstatic\s*:/.test(text))) {
|
|
292
|
+
manual.push({
|
|
293
|
+
line: lineOf(options),
|
|
294
|
+
reason: `serve() options built elsewhere: rename \`signals\` to \`gracefulSignals\`${node ? ", and pass `static` a function, serveStatic(mounts) for mount objects" : ""}`,
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
for (const property of options.properties) {
|
|
300
|
+
if (ts.isSpreadAssignment(property)) {
|
|
301
|
+
if (/\bsignals\b/.test(source(property.expression)) || /\bsignals\b/.test(text)) {
|
|
302
|
+
manual.push({
|
|
303
|
+
line: lineOf(property),
|
|
304
|
+
reason:
|
|
305
|
+
"serve() options spread in: rename `signals` to `gracefulSignals` where they are built",
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
continue
|
|
309
|
+
}
|
|
310
|
+
const name = propertyName(ts, property.name)
|
|
311
|
+
if (name === "signals") {
|
|
312
|
+
if (ts.isShorthandPropertyAssignment(property)) {
|
|
313
|
+
edits.push({
|
|
314
|
+
start: property.getStart(tree),
|
|
315
|
+
end: property.end,
|
|
316
|
+
text: "gracefulSignals: signals",
|
|
317
|
+
})
|
|
318
|
+
} else {
|
|
319
|
+
edits.push({
|
|
320
|
+
start: property.name.getStart(tree),
|
|
321
|
+
end: property.name.end,
|
|
322
|
+
text: "gracefulSignals",
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
count++
|
|
326
|
+
} else if (node && name === "static" && ts.isPropertyAssignment(property)) {
|
|
327
|
+
const value = property.initializer
|
|
328
|
+
if (ts.isObjectLiteralExpression(value) || ts.isArrayLiteralExpression(value)) {
|
|
329
|
+
if (staticName === undefined) {
|
|
330
|
+
manual.push({
|
|
331
|
+
line: lineOf(value),
|
|
332
|
+
reason:
|
|
333
|
+
"`static` takes a function now: wrap the mounts in serveStatic(), which another binding here is named",
|
|
334
|
+
})
|
|
335
|
+
continue
|
|
336
|
+
}
|
|
337
|
+
edits.push({
|
|
338
|
+
start: value.getStart(tree),
|
|
339
|
+
end: value.end,
|
|
340
|
+
text: `${staticName}(${source(value)})`,
|
|
341
|
+
})
|
|
342
|
+
staticUsed = true
|
|
343
|
+
count++
|
|
344
|
+
} else if (
|
|
345
|
+
!ts.isCallExpression(value) &&
|
|
346
|
+
!ts.isArrowFunction(value) &&
|
|
347
|
+
!ts.isFunctionExpression(value)
|
|
348
|
+
) {
|
|
349
|
+
manual.push({
|
|
350
|
+
line: lineOf(value),
|
|
351
|
+
reason:
|
|
352
|
+
"`static` takes a function now: pass serveStatic(mounts) if this holds mount objects",
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const visit = (node: TS.Node): void => {
|
|
360
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
361
|
+
const callee = node.expression.text
|
|
362
|
+
if (callee === publicDir) {
|
|
363
|
+
publicDirCall(node)
|
|
364
|
+
return
|
|
365
|
+
}
|
|
366
|
+
if (nodeServe.has(callee)) serveCall(node, true)
|
|
367
|
+
else if (denoServe.has(callee)) serveCall(node, false)
|
|
368
|
+
} else if (ts.isIdentifier(node) && node.text === "servePublicDir" && publicDir === undefined) {
|
|
369
|
+
// Reached some way other than a static import (a dynamic one, a require): never left unsaid.
|
|
370
|
+
if (!manual.some(({ line }) => line === lineOf(node))) {
|
|
371
|
+
manual.push({
|
|
372
|
+
line: lineOf(node),
|
|
373
|
+
reason: `servePublicDir is removed from ${WEB}: use ${PUBLIC_DIR_FORM} from ${CORE_STATIC}`,
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
} else if (
|
|
377
|
+
ts.isIdentifier(node) &&
|
|
378
|
+
node.text === publicDir &&
|
|
379
|
+
!ts.isImportSpecifier(node.parent) &&
|
|
380
|
+
!(ts.isCallExpression(node.parent) && node.parent.expression === node)
|
|
381
|
+
) {
|
|
382
|
+
publicDirLeft = true
|
|
383
|
+
manual.push({
|
|
384
|
+
line: lineOf(node),
|
|
385
|
+
reason: `servePublicDir used as a value: use ${PUBLIC_DIR_FORM}`,
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
ts.forEachChild(node, visit)
|
|
389
|
+
}
|
|
390
|
+
visit(tree)
|
|
391
|
+
const removed = new Set([...hashedFilesSpecifiers, ...(publicDirLeft ? [] : publicDirSpecifiers)])
|
|
392
|
+
if (count === 0 && removed.size === 0) return { text, count: 0, manual }
|
|
393
|
+
|
|
394
|
+
// The web import loses the removed names; the runtime's serveStatic (and ONE_DAY) are imported.
|
|
395
|
+
const names: string[] = []
|
|
396
|
+
if (staticUsed && existingStatic === undefined) names.push("serveStatic")
|
|
397
|
+
if (dayUsed) names.push("ONE_DAY")
|
|
398
|
+
if (hashedFilesLocal !== undefined) {
|
|
399
|
+
names.push(
|
|
400
|
+
hashedFilesLocal === "HashedFiles"
|
|
401
|
+
? "type HashedFiles"
|
|
402
|
+
: `type HashedFiles as ${hashedFilesLocal}`,
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
const quote = /from\s*'/.test(text) ? "'" : '"'
|
|
406
|
+
const specifierOrder = (a: string, b: string): number =>
|
|
407
|
+
codeUnitOrder(a.replace(/^type /, ""), b.replace(/^type /, ""))
|
|
408
|
+
const target = imports.get(runtimeModule)
|
|
409
|
+
let added: string | undefined
|
|
410
|
+
if (names.length > 0) {
|
|
411
|
+
if (target?.named !== undefined) {
|
|
412
|
+
const all = [...target.named.elements.map(source), ...names].toSorted(specifierOrder)
|
|
413
|
+
edits.push({
|
|
414
|
+
start: target.named.getStart(tree),
|
|
415
|
+
end: target.named.end,
|
|
416
|
+
text: `{ ${all.join(", ")} }`,
|
|
417
|
+
})
|
|
418
|
+
} else {
|
|
419
|
+
added = `import { ${names.toSorted(specifierOrder).join(", ")} } from ${quote}${runtimeModule}${quote}`
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
// The new import goes where the first web import that loses a name was, or after the imports.
|
|
423
|
+
let placed = added === undefined
|
|
424
|
+
for (const { declaration, named } of webImports) {
|
|
425
|
+
if (!named.elements.some((element) => removed.has(element))) continue
|
|
426
|
+
const kept = named.elements.filter((element) => !removed.has(element)).map(source)
|
|
427
|
+
const place = placed ? undefined : added
|
|
428
|
+
placed = true
|
|
429
|
+
if (kept.length === 0 && declaration.importClause?.name === undefined) {
|
|
430
|
+
// The declaration goes, with its line ending, unless the new import takes its place.
|
|
431
|
+
const eol = text.startsWith("\r\n", declaration.end)
|
|
432
|
+
? 2
|
|
433
|
+
: text[declaration.end] === "\n"
|
|
434
|
+
? 1
|
|
435
|
+
: 0
|
|
436
|
+
edits.push({
|
|
437
|
+
start: declaration.getStart(tree),
|
|
438
|
+
end: place === undefined ? declaration.end + eol : declaration.end,
|
|
439
|
+
text: place ?? "",
|
|
440
|
+
})
|
|
441
|
+
} else {
|
|
442
|
+
edits.push({ start: named.getStart(tree), end: named.end, text: `{ ${kept.join(", ")} }` })
|
|
443
|
+
if (place !== undefined)
|
|
444
|
+
edits.push({ start: declaration.end, end: declaration.end, text: `\n${place}` })
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (!placed && added !== undefined) {
|
|
448
|
+
const last = tree.statements.filter(ts.isImportDeclaration).at(-1)
|
|
449
|
+
const at = last?.end ?? 0
|
|
450
|
+
edits.push({ start: at, end: at, text: last === undefined ? `${added}\n` : `\n${added}` })
|
|
451
|
+
}
|
|
452
|
+
return { text: applyEdits(text, edits), count, manual }
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const WEB_APP = "createWebApp"
|
|
456
|
+
|
|
457
|
+
/** `createWebApp({ experimental: { ppr } })` becomes `createWebApp({ ppr })`: 5.10 moved the option. */
|
|
458
|
+
function rewritePprOption(ts: typeof TS, file: string, text: string): RewriteResult {
|
|
459
|
+
const { tree, lineOf } = parseSource(ts, file, text)
|
|
460
|
+
const edits: Edit[] = []
|
|
461
|
+
const manual: ManualSite[] = []
|
|
462
|
+
let count = 0
|
|
463
|
+
// The names createWebApp is imported under, and the names @nifrajs/web is imported as a namespace.
|
|
464
|
+
const locals = new Set<string>()
|
|
465
|
+
const namespaces = new Set<string>()
|
|
466
|
+
for (const statement of tree.statements) {
|
|
467
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
468
|
+
continue
|
|
469
|
+
if (statement.moduleSpecifier.text !== WEB) continue
|
|
470
|
+
const bindings = statement.importClause?.namedBindings
|
|
471
|
+
if (bindings === undefined) continue
|
|
472
|
+
if (ts.isNamespaceImport(bindings)) namespaces.add(bindings.name.text)
|
|
473
|
+
else {
|
|
474
|
+
for (const element of bindings.elements) {
|
|
475
|
+
if ((element.propertyName ?? element.name).text === WEB_APP) locals.add(element.name.text)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const isCreateWebApp = (callee: TS.Expression): boolean =>
|
|
480
|
+
(ts.isIdentifier(callee) && locals.has(callee.text)) ||
|
|
481
|
+
(ts.isPropertyAccessExpression(callee) &&
|
|
482
|
+
ts.isIdentifier(callee.expression) &&
|
|
483
|
+
namespaces.has(callee.expression.text) &&
|
|
484
|
+
callee.name.text === WEB_APP)
|
|
485
|
+
const nameOf = (property: TS.ObjectLiteralElementLike): string | undefined =>
|
|
486
|
+
ts.isShorthandPropertyAssignment(property)
|
|
487
|
+
? property.name.text
|
|
488
|
+
: ts.isPropertyAssignment(property)
|
|
489
|
+
? propertyName(ts, property.name)
|
|
490
|
+
: undefined
|
|
491
|
+
const property = (
|
|
492
|
+
object: TS.ObjectLiteralExpression,
|
|
493
|
+
name: string,
|
|
494
|
+
): TS.ObjectLiteralElementLike | undefined => object.properties.find((p) => nameOf(p) === name)
|
|
495
|
+
const handled = new Set<TS.ObjectLiteralExpression>()
|
|
496
|
+
|
|
497
|
+
const move = (options: TS.ObjectLiteralExpression): void => {
|
|
498
|
+
const experimental = property(options, "experimental")
|
|
499
|
+
if (experimental === undefined) return
|
|
500
|
+
const spread = options.properties.some((p) => ts.isSpreadAssignment(p))
|
|
501
|
+
const inner = ts.isPropertyAssignment(experimental) ? experimental.initializer : undefined
|
|
502
|
+
const moved = inner !== undefined && ts.isObjectLiteralExpression(inner) ? inner : undefined
|
|
503
|
+
const only = moved?.properties.length === 1 ? moved.properties[0] : undefined
|
|
504
|
+
if (
|
|
505
|
+
moved === undefined ||
|
|
506
|
+
only === undefined ||
|
|
507
|
+
nameOf(only) !== "ppr" ||
|
|
508
|
+
property(options, "ppr") !== undefined ||
|
|
509
|
+
spread
|
|
510
|
+
) {
|
|
511
|
+
manual.push({
|
|
512
|
+
line: lineOf(experimental),
|
|
513
|
+
reason:
|
|
514
|
+
"experimental.ppr is now ppr: pass it beside the other createWebApp options and remove `experimental`",
|
|
515
|
+
})
|
|
516
|
+
return
|
|
517
|
+
}
|
|
518
|
+
edits.push({
|
|
519
|
+
start: experimental.getStart(tree),
|
|
520
|
+
end: experimental.end,
|
|
521
|
+
text: ts.isPropertyAssignment(only) ? `ppr: ${only.initializer.getText(tree)}` : "ppr",
|
|
522
|
+
})
|
|
523
|
+
count++
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const visit = (node: TS.Node): void => {
|
|
527
|
+
if (ts.isCallExpression(node) && isCreateWebApp(node.expression)) {
|
|
528
|
+
const options = node.arguments[0]
|
|
529
|
+
if (options !== undefined && ts.isObjectLiteralExpression(options)) {
|
|
530
|
+
handled.add(options)
|
|
531
|
+
move(options)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
ts.forEachChild(node, visit)
|
|
535
|
+
}
|
|
536
|
+
visit(tree)
|
|
537
|
+
|
|
538
|
+
// Options built apart from the call, or passed through a name, are the user's to move.
|
|
539
|
+
const sweep = (node: TS.Node): void => {
|
|
540
|
+
if (ts.isObjectLiteralExpression(node) && !handled.has(node)) {
|
|
541
|
+
const experimental = property(node, "experimental")
|
|
542
|
+
const inner =
|
|
543
|
+
experimental !== undefined && ts.isPropertyAssignment(experimental)
|
|
544
|
+
? experimental.initializer
|
|
545
|
+
: undefined
|
|
546
|
+
if (
|
|
547
|
+
inner !== undefined &&
|
|
548
|
+
ts.isObjectLiteralExpression(inner) &&
|
|
549
|
+
property(inner, "ppr") !== undefined
|
|
550
|
+
) {
|
|
551
|
+
manual.push({
|
|
552
|
+
line: lineOf(node),
|
|
553
|
+
reason:
|
|
554
|
+
"experimental.ppr is now ppr: pass it beside the other createWebApp options and remove `experimental`",
|
|
555
|
+
})
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
ts.forEachChild(node, sweep)
|
|
559
|
+
}
|
|
560
|
+
sweep(tree)
|
|
561
|
+
return {
|
|
562
|
+
text: applyEdits(text, edits),
|
|
563
|
+
count,
|
|
564
|
+
manual: manual.toSorted((a, b) => a.line - b.line),
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
const PPR_OPTION: SourceRewrite = {
|
|
569
|
+
id: "ppr-option",
|
|
570
|
+
description: "createWebApp({ experimental: { ppr } }) → createWebApp({ ppr })",
|
|
571
|
+
mentions: (text) => /\bexperimental\b/.test(text) && /\bcreateWebApp\b/.test(text),
|
|
572
|
+
rewrite: rewritePprOption,
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const SERVE_STATIC: SourceRewrite = {
|
|
576
|
+
id: "serve-static",
|
|
577
|
+
description:
|
|
578
|
+
"servePublicDir → serveStatic, @nifrajs/node `static` mounts → serveStatic(), `signals` → `gracefulSignals`",
|
|
579
|
+
mentions: (text) =>
|
|
580
|
+
text.includes("servePublicDir") ||
|
|
581
|
+
(/@nifrajs\/(?:node|deno)["']/.test(text) && /\bsignals\b|\bstatic\s*:/.test(text)),
|
|
582
|
+
rewrite: rewriteServeStatic,
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
const REWRITES: Readonly<Record<string, SourceRewrite>> = {
|
|
586
|
+
[SERVE_STATIC.id]: SERVE_STATIC,
|
|
587
|
+
[PPR_OPTION.id]: PPR_OPTION,
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export function getSourceRewrite(id: string): SourceRewrite | undefined {
|
|
591
|
+
return REWRITES[id]
|
|
592
|
+
}
|
package/src/stylex-migrate.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { readdir, readFile, writeFile } from "node:fs/promises"
|
|
9
9
|
import { relative, resolve } from "node:path"
|
|
10
|
+
import { isRecord } from "./internal/record.ts"
|
|
10
11
|
|
|
11
12
|
export interface MigrationIssue {
|
|
12
13
|
readonly file: string
|
|
@@ -596,9 +597,6 @@ const PSEUDO_VARIANTS: Readonly<Record<string, string>> = {
|
|
|
596
597
|
const CLASS_ATTRIBUTE =
|
|
597
598
|
/\bclassName\s*=\s*(?:"([^"]*)"|'([^']*)'|\{\s*(?:"([^"]*)"|'([^']*)')\s*\}|\{([\s\S]*?)\})/g
|
|
598
599
|
|
|
599
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
600
|
-
typeof value === "object" && value !== null
|
|
601
|
-
|
|
602
600
|
const cloneStyle = (style: StyleObject): StyleObject => {
|
|
603
601
|
const result: Record<string, string | number | StyleObject> = {}
|
|
604
602
|
for (const [key, value] of Object.entries(style))
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Longest symptom text scored; the MCP schemas advertise the same cap, this enforces it. */
|
|
2
|
+
const MAX_SYMPTOM_LENGTH = 256
|
|
3
|
+
|
|
4
|
+
/** The trimmed, capped query, or undefined when there is nothing to rank by. */
|
|
5
|
+
export function symptomQuery(symptom: string | undefined): string | undefined {
|
|
6
|
+
const query = symptom?.trim().slice(0, MAX_SYMPTOM_LENGTH)
|
|
7
|
+
return query === undefined || query.length === 0 ? undefined : query
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The best-scoring entries for a query, highest first, at most `limit` (1 to 5, default 3). */
|
|
11
|
+
export function rankBySymptom<T>(
|
|
12
|
+
entries: readonly T[],
|
|
13
|
+
query: string,
|
|
14
|
+
limit: number | undefined,
|
|
15
|
+
score: (entry: T, words: readonly string[]) => number,
|
|
16
|
+
): T[] {
|
|
17
|
+
const words = query
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.split(/\s+/)
|
|
20
|
+
.filter((w) => w.length > 1)
|
|
21
|
+
return entries
|
|
22
|
+
.map((entry) => ({ entry, s: score(entry, words) }))
|
|
23
|
+
.filter((r) => r.s > 0)
|
|
24
|
+
.sort((a, b) => b.s - a.s)
|
|
25
|
+
.slice(0, Math.min(Math.max(limit ?? 3, 1), 5))
|
|
26
|
+
.map((r) => r.entry)
|
|
27
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync, readFileSync, realpathSync } from "node:fs"
|
|
8
8
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path"
|
|
9
|
+
import { ROUTE_TABLE_FILE } from "@nifrajs/web/route-types"
|
|
9
10
|
import { stripComments } from "./check-scan.ts"
|
|
10
11
|
|
|
11
12
|
const ZONE_FOLDER = new Set(["routes", "frontend", "backend", "shared"])
|
|
@@ -140,6 +141,28 @@ const excludedBy = (patterns: readonly string[], file: string): boolean =>
|
|
|
140
141
|
(pattern) => new Bun.Glob(pattern).match(file) || new Bun.Glob(`${pattern}/**`).match(file),
|
|
141
142
|
)
|
|
142
143
|
|
|
144
|
+
// A named import of a navigation API from `@nifrajs/web` or an adapter: what the route table types.
|
|
145
|
+
const NAVIGATION_IMPORT =
|
|
146
|
+
/\bimport\s+(?:type\s+)?\{[^}]*\b(?:useNavigate|Link|NavLink|Navigate|redirect|href|rawHref)\b[^}]*\}\s*from\s*["']@nifrajs\/web(?:-[a-z]+)?(?:\/(?:router|client))?["']/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* `.nifra/types/routes.d.ts` (project-relative) when a source file uses a navigation API, the table
|
|
150
|
+
* exists, and no program holds it. A program that imports any route's `./+types` module loads the table
|
|
151
|
+
* through that module's reference; one that does not, and does not name it, never sees it. Its `href`
|
|
152
|
+
* calls have no route keys to check against. An app that uses none of these APIs is left alone.
|
|
153
|
+
*/
|
|
154
|
+
export function routeTableOutsideProgram(
|
|
155
|
+
cwd: string,
|
|
156
|
+
programFiles: readonly string[],
|
|
157
|
+
sources: ReadonlyArray<{ readonly content: string }>,
|
|
158
|
+
): string | undefined {
|
|
159
|
+
const table = join(cwd, ROUTE_TABLE_FILE)
|
|
160
|
+
if (!existsSync(table) || !sources.some(({ content }) => NAVIGATION_IMPORT.test(content)))
|
|
161
|
+
return undefined
|
|
162
|
+
const wanted = new Set([canonical(table), canonical(real(table))])
|
|
163
|
+
return programFiles.some((file) => wanted.has(canonical(file))) ? undefined : ROUTE_TABLE_FILE
|
|
164
|
+
}
|
|
165
|
+
|
|
143
166
|
/**
|
|
144
167
|
* The TypeScript files under a zone folder that `programFiles` does not contain, project-relative and
|
|
145
168
|
* in input order. Declaration files and tests are left out: a project may typecheck tests with a
|