@nifrajs/cli 5.7.0 → 5.9.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 +150 -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-scan.d.ts +2 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +54 -86
- 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 +20 -23
- 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 +42 -13
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -30
- 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.map +1 -1
- package/dist/internal/source-facts.js +28 -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 +6 -1
- package/dist/load.d.ts.map +1 -1
- 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-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-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.8.0.d.ts +9 -0
- package/dist/recipes/5.8.0.d.ts.map +1 -0
- package/dist/recipes/5.8.0.js +20 -0
- package/dist/recipes/5.8.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 +9 -13
- package/dist/review.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/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/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 +402 -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/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 +32 -2
- package/docs/llms-full.txt +749 -95
- package/docs/types.json +300 -61
- 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-scan.ts +65 -82
- package/src/check.ts +25 -23
- package/src/cli.ts +61 -13
- package/src/command-catalog.ts +22 -32
- 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 +39 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +6 -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-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.8.0.ts +21 -0
- package/src/recipes/5.9.0.ts +42 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +12 -15
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- 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 +463 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
package/src/frontend-guidance.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import type { Framework } from "./scaffold.ts"
|
|
22
|
+
import { rankBySymptom, symptomQuery } from "./symptom-search.ts"
|
|
22
23
|
|
|
23
24
|
/** An adapter an entry applies to, or `all` for a seam issue that is adapter-independent. */
|
|
24
25
|
export type GuidanceAdapter = Framework | "all"
|
|
@@ -38,6 +39,28 @@ export interface GuidanceEntry {
|
|
|
38
39
|
readonly verify: string
|
|
39
40
|
/** Where to go deeper - a `nifra_docs`/`nifra_example` query, or the ecosystem linter that owns it. */
|
|
40
41
|
readonly seeAlso?: string | undefined
|
|
42
|
+
/** Framework/runtime versions covered by the advice. Omitted only for Nifra-wide seam entries. */
|
|
43
|
+
readonly versions?: readonly string[] | undefined
|
|
44
|
+
/** The authoritative documentation or linter reference for this case. */
|
|
45
|
+
readonly source?: string | undefined
|
|
46
|
+
/** Coarse category used by JSON consumers to group related cases. */
|
|
47
|
+
readonly category?:
|
|
48
|
+
| "seam"
|
|
49
|
+
| "hydration"
|
|
50
|
+
| "reactivity"
|
|
51
|
+
| "effects"
|
|
52
|
+
| "lists"
|
|
53
|
+
| "runtime"
|
|
54
|
+
| "ssr"
|
|
55
|
+
| undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface FrontendGuidanceResult {
|
|
59
|
+
readonly schemaVersion: 1
|
|
60
|
+
readonly adapter?: GuidanceAdapter | undefined
|
|
61
|
+
readonly symptom?: string | undefined
|
|
62
|
+
readonly matched: boolean
|
|
63
|
+
readonly entries: readonly GuidanceEntry[]
|
|
41
64
|
}
|
|
42
65
|
|
|
43
66
|
/**
|
|
@@ -80,6 +103,7 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
80
103
|
fix: "Dedupe the framework to a single version across the workspace (one entry in the lockfile). The adapter must resolve the app's copy, not bundle its own.",
|
|
81
104
|
verify: "nifra_doctor - it detects a duplicated framework runtime (NF-H002).",
|
|
82
105
|
seeAlso: "duplicate framework runtime dedupe NF-H002",
|
|
106
|
+
category: "runtime",
|
|
83
107
|
},
|
|
84
108
|
{
|
|
85
109
|
id: "loader-typing",
|
|
@@ -111,11 +135,14 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
111
135
|
symptom:
|
|
112
136
|
"A value stops updating the template after you pull it out of a ref, reactive object, or props.",
|
|
113
137
|
cause:
|
|
114
|
-
"Destructuring a `reactive()` object or `props` copies the current value and drops the reactive link; a `ref` read in script forgets `.value`.",
|
|
115
|
-
fix: "Keep the reactive source intact: use `toRefs`/`storeToRefs` when you must destructure, access `props.x` directly, and remember `.value` on a ref in script (templates unwrap it for you).",
|
|
138
|
+
"Destructuring a `reactive()` object or the `props` argument of `setup(props)` copies the current value and drops the reactive link; a `ref` read in script forgets `.value`. In Vue 3.5 `<script setup>`, destructuring `defineProps()` is compiled to keep reads reactive, but passing the destructured name to `watch` still hands it a plain value.",
|
|
139
|
+
fix: "Keep the reactive source intact: use `toRefs`/`storeToRefs` when you must destructure, access `props.x` directly, watch a getter such as `() => foo` for a destructured prop, and remember `.value` on a ref in script (templates unwrap it for you).",
|
|
116
140
|
verify:
|
|
117
141
|
"eslint-plugin-vue - it is the authority on Vue reactivity; nifra does not re-implement it.",
|
|
118
142
|
seeAlso: "eslint-plugin-vue toRefs reactivity",
|
|
143
|
+
versions: ["Vue 3.4-3.5"],
|
|
144
|
+
source: "https://vuejs.org/guide/essentials/reactivity-fundamentals.html",
|
|
145
|
+
category: "reactivity",
|
|
119
146
|
},
|
|
120
147
|
{
|
|
121
148
|
id: "solid-lost-reactivity",
|
|
@@ -127,6 +154,9 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
127
154
|
verify:
|
|
128
155
|
"eslint-plugin-solid - the authority on Solid reactivity; nifra routes you to it, not around it.",
|
|
129
156
|
seeAlso: "eslint-plugin-solid splitProps props getters",
|
|
157
|
+
versions: ["Solid 1.8-1.9"],
|
|
158
|
+
source: "https://docs.solidjs.com/concepts/components/props",
|
|
159
|
+
category: "reactivity",
|
|
130
160
|
},
|
|
131
161
|
{
|
|
132
162
|
id: "svelte-runes",
|
|
@@ -139,6 +169,9 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
139
169
|
verify:
|
|
140
170
|
"eslint-plugin-svelte and the Svelte compiler warnings own this; nifra points you at them.",
|
|
141
171
|
seeAlso: "eslint-plugin-svelte runes $props $derived",
|
|
172
|
+
versions: ["Svelte 5"],
|
|
173
|
+
source: "https://svelte.dev/docs/svelte/$props",
|
|
174
|
+
category: "reactivity",
|
|
142
175
|
},
|
|
143
176
|
{
|
|
144
177
|
id: "react-stale-deps",
|
|
@@ -151,6 +184,233 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
151
184
|
verify:
|
|
152
185
|
"eslint-plugin-react-hooks (`exhaustive-deps`) is the authority on effect deps; nifra does not duplicate it.",
|
|
153
186
|
seeAlso: "eslint-plugin-react-hooks exhaustive-deps effect closure",
|
|
187
|
+
versions: ["React 18-19", "Preact 10-11"],
|
|
188
|
+
source: "https://react.dev/reference/react/useEffect",
|
|
189
|
+
category: "effects",
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
id: "react-hydration-browser-read",
|
|
193
|
+
adapters: ["react"],
|
|
194
|
+
symptom:
|
|
195
|
+
"React reports a hydration mismatch when a component reads window, localStorage, matchMedia, or the current time while rendering.",
|
|
196
|
+
cause:
|
|
197
|
+
"The server render and the first client render produce different output. React requires the tree passed to hydrateRoot to match the server HTML.",
|
|
198
|
+
fix: "Render the same deterministic value on both sides, then read browser-only state in an effect and render the updated value after hydration. Pass server-known locale, time, and flags through loader data.",
|
|
199
|
+
verify:
|
|
200
|
+
"React's hydration warning should disappear; run `nifra_render` and a browser smoke test for the route.",
|
|
201
|
+
seeAlso: "hydrateRoot browser-only APIs deterministic rendering",
|
|
202
|
+
versions: ["React 18-19"],
|
|
203
|
+
source: "https://react.dev/reference/react-dom/client/hydrateRoot",
|
|
204
|
+
category: "hydration",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "react-effect-cleanup",
|
|
208
|
+
adapters: ["react"],
|
|
209
|
+
symptom:
|
|
210
|
+
"A subscription, timer, or request keeps running after a React component changes or unmounts.",
|
|
211
|
+
cause:
|
|
212
|
+
"The effect does not return cleanup, or cleanup does not undo the setup created for the previous dependency values.",
|
|
213
|
+
fix: "Return cleanup from every effect that subscribes, starts a timer, or owns an abortable request. Make cleanup idempotent because development Strict Mode may run setup and cleanup more than once.",
|
|
214
|
+
verify:
|
|
215
|
+
"Use the React hooks linter and a mount-update-unmount test that asserts the subscription and timer are released.",
|
|
216
|
+
seeAlso: "useEffect cleanup Strict Mode abort controller",
|
|
217
|
+
versions: ["React 18-19"],
|
|
218
|
+
source: "https://react.dev/reference/react/useEffect#parameters",
|
|
219
|
+
category: "effects",
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: "react-state-position",
|
|
223
|
+
adapters: ["react"],
|
|
224
|
+
symptom:
|
|
225
|
+
"React preserves input or component state for the wrong item after a reorder, conditional change, or route transition.",
|
|
226
|
+
cause:
|
|
227
|
+
"State is associated with a component's position and key. An index key or changing component identity makes React reuse state for a different item.",
|
|
228
|
+
fix: "Use a stable data key for each list item and give intentionally reset content a deliberate, changing key. Do not use array indexes for reorderable lists.",
|
|
229
|
+
verify:
|
|
230
|
+
"Exercise insert, remove, and reorder cases with a stateful row test; keep `eslint-plugin-react` key diagnostics enabled.",
|
|
231
|
+
seeAlso: "preserving and resetting state stable keys",
|
|
232
|
+
versions: ["React 18-19"],
|
|
233
|
+
source: "https://react.dev/learn/preserving-and-resetting-state",
|
|
234
|
+
category: "lists",
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
id: "preact-compat-runtime",
|
|
238
|
+
adapters: ["preact"],
|
|
239
|
+
symptom:
|
|
240
|
+
"A Preact app has a null context, invalid hook behavior, or a component that works before an adapter or dependency is added.",
|
|
241
|
+
cause:
|
|
242
|
+
"React imports and Preact compat imports are mixed, or more than one Preact runtime is installed. Context and hooks depend on one shared runtime instance.",
|
|
243
|
+
fix: "Choose Preact or `preact/compat` consistently, alias React packages only at the bundler boundary, and dedupe Preact across the workspace.",
|
|
244
|
+
verify:
|
|
245
|
+
"Run `nifra_doctor`, inspect the resolved dependency tree, and exercise a context provider plus a hook in a production build.",
|
|
246
|
+
seeAlso: "preact compat switching from React single runtime",
|
|
247
|
+
versions: ["Preact 10-11"],
|
|
248
|
+
source: "https://preactjs.com/guide/v10/switching-to-preact/",
|
|
249
|
+
category: "runtime",
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
id: "preact-effect-cleanup",
|
|
253
|
+
adapters: ["preact"],
|
|
254
|
+
symptom:
|
|
255
|
+
"A Preact effect creates duplicate listeners or timers after rerenders, navigation, or development reloads.",
|
|
256
|
+
cause:
|
|
257
|
+
"The effect setup has no cleanup, or dependencies cause a new setup without removing the previous one.",
|
|
258
|
+
fix: "Return cleanup from `useEffect` and keep the dependency list aligned with every value read by the effect. Abort requests owned by the effect.",
|
|
259
|
+
verify:
|
|
260
|
+
"Use `eslint-plugin-react-hooks` with the Preact hooks configuration and assert listener counts across rerenders.",
|
|
261
|
+
seeAlso: "Preact hooks useEffect cleanup dependencies",
|
|
262
|
+
versions: ["Preact 10-11"],
|
|
263
|
+
source: "https://preactjs.com/guide/v10/hooks/",
|
|
264
|
+
category: "effects",
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
id: "preact-hydration-output",
|
|
268
|
+
adapters: ["preact"],
|
|
269
|
+
symptom:
|
|
270
|
+
"Preact replaces server markup or event handlers fail after hydration even though the page initially looks correct.",
|
|
271
|
+
cause:
|
|
272
|
+
"The first client render differs from the server HTML, often because a browser API, random value, or locale is read during render.",
|
|
273
|
+
fix: "Keep the initial render deterministic and move browser-only reads into an effect or an explicit client-only boundary. Ensure the server and client use the same Preact runtime.",
|
|
274
|
+
verify:
|
|
275
|
+
"Run the route through SSR plus `hydrate`, capture console errors, and compare the initial markup before effects run.",
|
|
276
|
+
seeAlso: "Preact hydrate SSR deterministic render",
|
|
277
|
+
versions: ["Preact 10-11"],
|
|
278
|
+
source: "https://preactjs.com/guide/v10/api-reference/#hydrate",
|
|
279
|
+
category: "hydration",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
id: "solid-for-index",
|
|
283
|
+
adapters: ["solid"],
|
|
284
|
+
symptom:
|
|
285
|
+
"A Solid list displays the wrong row state or does unnecessary work after an item is inserted or reordered.",
|
|
286
|
+
cause:
|
|
287
|
+
"`Index` tracks positions while `For` tracks item identity. Choosing the wrong primitive changes which values remain attached to a row.",
|
|
288
|
+
fix: "Use `<For>` for collections whose item identity can move and `<Index>` only when position is the identity. Supply a stable key at the data boundary when persistence matters.",
|
|
289
|
+
verify:
|
|
290
|
+
"Test insert, remove, and reorder operations while editing one row; assert both rendered identity and preserved local state.",
|
|
291
|
+
seeAlso: "Solid list rendering For Index",
|
|
292
|
+
versions: ["Solid 1.8-1.9"],
|
|
293
|
+
source: "https://docs.solidjs.com/concepts/control-flow/list-rendering",
|
|
294
|
+
category: "lists",
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
id: "solid-tracking-scope",
|
|
298
|
+
adapters: ["solid"],
|
|
299
|
+
symptom:
|
|
300
|
+
"A Solid computation reads a signal once and never updates, or a server-rendered value is captured before the component runs.",
|
|
301
|
+
cause:
|
|
302
|
+
"The signal is read outside a tracked computation or at module/component setup time instead of inside JSX, `createEffect`, or `createMemo`.",
|
|
303
|
+
fix: "Read signals where Solid can track them, keep derived work in `createMemo`, and keep side effects in `createEffect`. Do not cache a getter's current value as a plain variable.",
|
|
304
|
+
verify:
|
|
305
|
+
"Change the source signal after mount and assert the derived output changes without manually calling an update function.",
|
|
306
|
+
seeAlso: "Solid reactivity tracking createMemo createEffect",
|
|
307
|
+
versions: ["Solid 1.8-1.9"],
|
|
308
|
+
source: "https://docs.solidjs.com/concepts/reactivity",
|
|
309
|
+
category: "reactivity",
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
id: "solid-effect-cleanup",
|
|
313
|
+
adapters: ["solid"],
|
|
314
|
+
symptom: "A Solid event listener, interval, or resource outlives the owner that created it.",
|
|
315
|
+
cause:
|
|
316
|
+
"The effect allocates an external resource without registering cleanup with the current owner.",
|
|
317
|
+
fix: "Register teardown with `onCleanup` in the same owner that created the resource. Abort async work when its owner is disposed.",
|
|
318
|
+
verify:
|
|
319
|
+
"Mount and dispose the owner repeatedly, then assert that listener, timer, and request counts return to zero.",
|
|
320
|
+
seeAlso: "Solid onCleanup effects",
|
|
321
|
+
versions: ["Solid 1.8-1.9"],
|
|
322
|
+
source: "https://docs.solidjs.com/reference/lifecycle/on-cleanup",
|
|
323
|
+
category: "effects",
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
id: "vue-ref-script-access",
|
|
327
|
+
adapters: ["vue"],
|
|
328
|
+
symptom:
|
|
329
|
+
"A Vue ref appears to work in a template but is stale or compares incorrectly in script code.",
|
|
330
|
+
cause:
|
|
331
|
+
"Templates unwrap refs, while JavaScript and TypeScript code must read and write the ref's `.value`.",
|
|
332
|
+
fix: "Use `.value` in script, or use `toRefs`/`storeToRefs` when exposing reactive properties without losing their link.",
|
|
333
|
+
verify:
|
|
334
|
+
"Run a component test that changes the ref from script and asserts both the value and rendered output update.",
|
|
335
|
+
seeAlso: "Vue refs unwrapping in templates and script",
|
|
336
|
+
versions: ["Vue 3.4-3.5"],
|
|
337
|
+
source: "https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref-unwrapping",
|
|
338
|
+
category: "reactivity",
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
id: "vue-watch-source",
|
|
342
|
+
adapters: ["vue"],
|
|
343
|
+
symptom:
|
|
344
|
+
"A Vue watcher never runs, runs only once, or fires for a value that the code did not intend to observe.",
|
|
345
|
+
cause:
|
|
346
|
+
"The watcher received a plain value instead of a reactive source, or a deep object was watched without an explicit decision about traversal cost.",
|
|
347
|
+
fix: "Pass a ref, getter, or reactive object as the watch source. Choose `deep`, `immediate`, and flush timing deliberately, and use `watchEffect` only when its automatic dependencies are intended.",
|
|
348
|
+
verify:
|
|
349
|
+
"Change the source and an unrelated nested value separately; assert the exact watcher calls and cleanup behavior.",
|
|
350
|
+
seeAlso: "Vue watch sources deep watchers watchEffect",
|
|
351
|
+
versions: ["Vue 3.4-3.5"],
|
|
352
|
+
source: "https://vuejs.org/guide/essentials/watchers.html",
|
|
353
|
+
category: "effects",
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
id: "vue-hydration-browser-read",
|
|
357
|
+
adapters: ["vue"],
|
|
358
|
+
symptom:
|
|
359
|
+
"Vue warns about hydration mismatch when a component reads browser state or formats a value during SSR.",
|
|
360
|
+
cause:
|
|
361
|
+
"The server and client produce different initial VNodes because browser-only state, timezone, locale, or random data is read during render.",
|
|
362
|
+
fix: "Render a deterministic initial value, then update browser-only state in `onMounted` or a client-only boundary. Serialize server-known locale and time through loader data.",
|
|
363
|
+
verify:
|
|
364
|
+
"Run SSR plus hydration with console warnings treated as failures and test at least one non-default locale.",
|
|
365
|
+
seeAlso: "Vue SSR hydration mismatch onMounted",
|
|
366
|
+
versions: ["Vue 3.4-3.5"],
|
|
367
|
+
source: "https://vuejs.org/guide/scaling-up/ssr.html#hydration-mismatch",
|
|
368
|
+
category: "hydration",
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
id: "svelte-keyed-each",
|
|
372
|
+
adapters: ["svelte"],
|
|
373
|
+
symptom:
|
|
374
|
+
"A Svelte row keeps the wrong input value or local state after a list item is inserted, removed, or reordered.",
|
|
375
|
+
cause:
|
|
376
|
+
"An unkeyed `{#each}` block reuses DOM by position, so local state follows the slot instead of the item identity.",
|
|
377
|
+
fix: "Use a keyed each block, `{#each items as item (item.id)}`, when item identity must survive collection changes.",
|
|
378
|
+
verify:
|
|
379
|
+
"Test reorder and deletion with focused, edited inputs and assert the state stays with the same id.",
|
|
380
|
+
seeAlso: "Svelte keyed each blocks list identity",
|
|
381
|
+
versions: ["Svelte 4-5"],
|
|
382
|
+
source: "https://svelte.dev/docs/svelte/each",
|
|
383
|
+
category: "lists",
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
id: "svelte-effect-cleanup",
|
|
387
|
+
adapters: ["svelte"],
|
|
388
|
+
symptom:
|
|
389
|
+
"A Svelte 5 effect leaves a timer, subscription, or request alive after dependencies change or the component unmounts.",
|
|
390
|
+
cause:
|
|
391
|
+
"The effect does not return a teardown function, or legacy and runes lifecycle assumptions are mixed.",
|
|
392
|
+
fix: "Return cleanup from `$effect` for every resource it creates. Keep DOM-only work in `$effect` and derived values in `$derived`.",
|
|
393
|
+
verify:
|
|
394
|
+
"Mount, change dependencies, and destroy the component while asserting the cleanup function runs once for each setup.",
|
|
395
|
+
seeAlso: "Svelte 5 $effect teardown $derived",
|
|
396
|
+
versions: ["Svelte 5"],
|
|
397
|
+
source: "https://svelte.dev/docs/svelte/$effect",
|
|
398
|
+
category: "effects",
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
id: "svelte-ssr-browser-read",
|
|
402
|
+
adapters: ["svelte"],
|
|
403
|
+
symptom:
|
|
404
|
+
"A Svelte page flashes or reports a hydration mismatch when it reads browser globals, random values, or the current time.",
|
|
405
|
+
cause:
|
|
406
|
+
"SSR executes the component before a browser exists, and the server output differs from the browser's first render.",
|
|
407
|
+
fix: "Keep the initial markup deterministic, use `onMount` for browser-only reads, and pass server-known values through page or loader data.",
|
|
408
|
+
verify:
|
|
409
|
+
"SSR the page, hydrate it in a browser, and fail the test on hydration warnings or a changed first render.",
|
|
410
|
+
seeAlso: "Svelte onMount SSR browser-only code hydration",
|
|
411
|
+
versions: ["Svelte 4-5"],
|
|
412
|
+
source: "https://svelte.dev/docs/svelte/svelte#onmount",
|
|
413
|
+
category: "hydration",
|
|
154
414
|
},
|
|
155
415
|
{
|
|
156
416
|
id: "prefer-reactive-island",
|
|
@@ -163,6 +423,7 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
163
423
|
verify:
|
|
164
424
|
"nifra_check runs NF-C047 (a binding names no state or handler), NF-C048 (a binding outside a bindIsland host) and NF-C022 (a positional list key) over the island code.",
|
|
165
425
|
seeAlso: "bindIsland state data-bind bindList resource islands",
|
|
426
|
+
category: "seam",
|
|
166
427
|
},
|
|
167
428
|
{
|
|
168
429
|
id: "swap-a-region",
|
|
@@ -175,6 +436,50 @@ export const FRONTEND_GUIDANCE: readonly GuidanceEntry[] = [
|
|
|
175
436
|
verify:
|
|
176
437
|
"nifra_check runs NF-C049 to NF-C052 over the swap markup and NF-C048 over bindings inside a slot.",
|
|
177
438
|
seeAlso: "data-swap data-swap-slot slot enableSwap islands",
|
|
439
|
+
category: "seam",
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
id: "react-activity-markers",
|
|
443
|
+
adapters: ["react"],
|
|
444
|
+
symptom:
|
|
445
|
+
"The tab freezes on load: the main thread spins and hydration never finishes, with no error, on a page that renders `<Activity>`.",
|
|
446
|
+
cause:
|
|
447
|
+
"React hydrates an `<Activity>` against server HTML that lacks its `<!--&-->` and `<!--/&-->` boundary comments and never returns. The server HTML carries the markers only when the server tree rendered the Activity. React also writes a component's `<title>` ahead of the opening comment in `renderToString` output.",
|
|
448
|
+
fix: "Make server and client agree: wrap in `<Activity>` on the client only where the server did, and when you detect the boundary in server HTML, skip leading `<title>` elements before looking for the comment.",
|
|
449
|
+
verify:
|
|
450
|
+
"Hydrate the route in a real browser (a test runner just times out without an error) and confirm the page becomes interactive.",
|
|
451
|
+
versions: ["React 19.3.1"],
|
|
452
|
+
source: "https://react.dev/reference/react/Activity",
|
|
453
|
+
category: "hydration",
|
|
454
|
+
seeAlso: "react activity hydration boundary",
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
id: "csp-inline-style-attribute",
|
|
458
|
+
adapters: ["all"],
|
|
459
|
+
symptom:
|
|
460
|
+
'A wrapper element with an inline `style` attribute, such as `<div style="display:contents">`, is ignored under a Content-Security-Policy and the layout breaks.',
|
|
461
|
+
cause:
|
|
462
|
+
"`style-src 'self'` refuses inline `style` attributes, and a framework's hydration does not set the attribute again from script. A `<slot>` element is `display: contents` by the user-agent stylesheet in Chromium, Firefox and WebKit, needs no CSP exception, and does not close an open `<p>`. Svelte reserves the `<slot>` tag name.",
|
|
463
|
+
fix: 'Use a `<slot>` wrapper for a layout-neutral container, or a class in a stylesheet. In Svelte write `<svelte:element this={"slot"}>`; a string-literal `this` warns.',
|
|
464
|
+
verify:
|
|
465
|
+
"Load the page with the production `style-src` and check the console for a blocked inline style.",
|
|
466
|
+
versions: ["Chromium, Firefox, WebKit (2026-10)"],
|
|
467
|
+
category: "ssr",
|
|
468
|
+
seeAlso: "csp style-src display contents slot wrapper",
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
id: "webkit-streamed-modules",
|
|
472
|
+
adapters: ["all"],
|
|
473
|
+
symptom:
|
|
474
|
+
"On a streamed HTML document, Safari or a WebKit test runs the page's module scripts only after the whole response arrives, and anything gated on `requestAnimationFrame` lags.",
|
|
475
|
+
cause:
|
|
476
|
+
'WebKit evaluates a `<script type="module">`, `async` or not, only when the parser finishes. A dynamic `import()` of the same URL waits with it, while one from a classic inline script with no module tag for that URL runs at once. Headless WebKit also runs no `requestAnimationFrame` callback until a streamed document ends, and Playwright\'s `page.click` waits two animation frames.',
|
|
477
|
+
fix: "Do not assume a streamed page hydrates early in WebKit. In WebKit tests, trigger timing-sensitive navigation with `locator.evaluate((el) => el.click())` and wait on app state, not on animation frames.",
|
|
478
|
+
verify:
|
|
479
|
+
"Stream a document for several seconds and log when the module and the first animation frame run in Chromium and WebKit.",
|
|
480
|
+
versions: ["Playwright 1.63 WebKit"],
|
|
481
|
+
category: "ssr",
|
|
482
|
+
seeAlso: "webkit streaming hydration module script requestAnimationFrame",
|
|
178
483
|
},
|
|
179
484
|
]
|
|
180
485
|
|
|
@@ -194,18 +499,43 @@ export function parseAdapter(value: string | undefined): GuidanceAdapter | undef
|
|
|
194
499
|
return ADAPTER_ALIASES[value.trim().toLowerCase()]
|
|
195
500
|
}
|
|
196
501
|
|
|
502
|
+
/** Return whether a catalog entry applies to the requested adapter. */
|
|
197
503
|
const appliesTo = (entry: GuidanceEntry, adapter: GuidanceAdapter): boolean =>
|
|
198
504
|
adapter === "all" || entry.adapters.includes("all") || entry.adapters.includes(adapter)
|
|
199
505
|
|
|
506
|
+
/** Scope the catalog once so the CLI and MCP heads cannot drift in their adapter filtering. */
|
|
507
|
+
function scopedEntries(adapter: GuidanceAdapter | undefined): readonly GuidanceEntry[] {
|
|
508
|
+
return adapter === undefined
|
|
509
|
+
? FRONTEND_GUIDANCE
|
|
510
|
+
: FRONTEND_GUIDANCE.filter((entry) => appliesTo(entry, adapter))
|
|
511
|
+
}
|
|
512
|
+
|
|
200
513
|
/** Keyword score of an entry against a query - counts distinct query words found in its text. */
|
|
201
514
|
function score(entry: GuidanceEntry, words: readonly string[]): number {
|
|
202
515
|
const hay =
|
|
203
|
-
`${entry.id} ${entry.symptom} ${entry.cause} ${entry.fix} ${entry.seeAlso ?? ""}`.toLowerCase()
|
|
516
|
+
`${entry.id} ${entry.symptom} ${entry.cause} ${entry.fix} ${entry.seeAlso ?? ""} ${entry.category ?? ""} ${entry.versions?.join(" ") ?? ""}`.toLowerCase()
|
|
204
517
|
let hits = 0
|
|
205
518
|
for (const w of words) if (hay.includes(w)) hits++
|
|
206
519
|
return hits
|
|
207
520
|
}
|
|
208
521
|
|
|
522
|
+
/** Select the entries rendered by the CLI and MCP heads; also the stable JSON shape for agents (no rendered prose). */
|
|
523
|
+
export function selectFrontendGuidance(args: {
|
|
524
|
+
adapter?: string | undefined
|
|
525
|
+
symptom?: string | undefined
|
|
526
|
+
limit?: number | undefined
|
|
527
|
+
}): FrontendGuidanceResult {
|
|
528
|
+
const adapter = parseAdapter(args.adapter)
|
|
529
|
+
const scoped = scopedEntries(adapter)
|
|
530
|
+
const query = symptomQuery(args.symptom)
|
|
531
|
+
if (query === undefined) {
|
|
532
|
+
return { schemaVersion: 1, adapter, matched: true, entries: scoped }
|
|
533
|
+
}
|
|
534
|
+
const entries = rankBySymptom(scoped, query, args.limit, score)
|
|
535
|
+
return { schemaVersion: 1, adapter, symptom: query, matched: entries.length > 0, entries }
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** Render one matched entry with all optional metadata that is actually present. */
|
|
209
539
|
function renderEntry(entry: GuidanceEntry): string {
|
|
210
540
|
const scope = entry.adapters.includes("all") ? "all adapters" : entry.adapters.join(", ")
|
|
211
541
|
const parts = [
|
|
@@ -215,10 +545,14 @@ function renderEntry(entry: GuidanceEntry): string {
|
|
|
215
545
|
`Fix: ${entry.fix}`,
|
|
216
546
|
`Verify: ${entry.verify}`,
|
|
217
547
|
]
|
|
548
|
+
if (entry.versions !== undefined) parts.push(`Applies: ${entry.versions.join(", ")}`)
|
|
549
|
+
if (entry.category !== undefined) parts.push(`Category: ${entry.category}`)
|
|
550
|
+
if (entry.source !== undefined) parts.push(`Source: ${entry.source}`)
|
|
218
551
|
if (entry.seeAlso !== undefined) parts.push(`See: ${entry.seeAlso}`)
|
|
219
552
|
return parts.join("\n")
|
|
220
553
|
}
|
|
221
554
|
|
|
555
|
+
/** Render the compact index used when no symptom matched or was supplied. */
|
|
222
556
|
function renderIndex(
|
|
223
557
|
entries: readonly GuidanceEntry[],
|
|
224
558
|
adapter: GuidanceAdapter | undefined,
|
|
@@ -245,27 +579,12 @@ export function renderFrontendResult(args: {
|
|
|
245
579
|
symptom?: string | undefined
|
|
246
580
|
limit?: number | undefined
|
|
247
581
|
}): string {
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (query === undefined || query.length === 0) return renderIndex(scoped, adapter)
|
|
255
|
-
|
|
256
|
-
const words = query
|
|
257
|
-
.toLowerCase()
|
|
258
|
-
.split(/\s+/)
|
|
259
|
-
.filter((w) => w.length > 1)
|
|
260
|
-
const limit = Math.min(Math.max(args.limit ?? 3, 1), 5)
|
|
261
|
-
const ranked = scoped
|
|
262
|
-
.map((entry) => ({ entry, s: score(entry, words) }))
|
|
263
|
-
.filter((r) => r.s > 0)
|
|
264
|
-
.sort((a, b) => b.s - a.s)
|
|
265
|
-
.slice(0, limit)
|
|
266
|
-
|
|
267
|
-
if (ranked.length === 0) {
|
|
268
|
-
return `No frontend-guidance entry matched "${query}"${adapter ? ` for ${adapter}` : ""}.\n\n${renderIndex(scoped, adapter)}`
|
|
582
|
+
const selected = selectFrontendGuidance(args)
|
|
583
|
+
const selectedAdapter = selected.adapter
|
|
584
|
+
const scoped = scopedEntries(selectedAdapter)
|
|
585
|
+
if (selected.symptom === undefined) return renderIndex(scoped, selectedAdapter)
|
|
586
|
+
if (!selected.matched) {
|
|
587
|
+
return `No frontend-guidance entry matched "${selected.symptom}"${selectedAdapter ? ` for ${selectedAdapter}` : ""}.\n\n${renderIndex(scoped, selectedAdapter)}`
|
|
269
588
|
}
|
|
270
|
-
return
|
|
589
|
+
return selected.entries.map(renderEntry).join("\n\n")
|
|
271
590
|
}
|
|
@@ -8,6 +8,7 @@ import { existsSync, readdirSync, statSync } from "node:fs"
|
|
|
8
8
|
import { dirname, join } from "node:path"
|
|
9
9
|
import { Glob } from "bun"
|
|
10
10
|
import { codePositionMask } from "./check.ts"
|
|
11
|
+
import { lineAt } from "./internal/line-at.ts"
|
|
11
12
|
import { expressionEnd } from "./rules/data-guard.ts"
|
|
12
13
|
|
|
13
14
|
/** A `buildManifest(...)` call whose file list reaches pages under `routes/` but not their halves. */
|
|
@@ -32,8 +33,6 @@ export interface ManifestList {
|
|
|
32
33
|
const BACKEND_HALF = /\.backend\.(?:[cm]?[jt]s)$/
|
|
33
34
|
const LITERAL = /(["'`])((?:\\.|(?!\1)[^\\])*)\1/g
|
|
34
35
|
|
|
35
|
-
const lineAt = (text: string, index: number): number => text.slice(0, index).split("\n").length
|
|
36
|
-
|
|
37
36
|
/**
|
|
38
37
|
* The `buildManifest(` calls in `content` whose first argument is spelled out in source: an array of
|
|
39
38
|
* string literals, or an expression around `import.meta.glob(...)` with literal patterns. A list built
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Whether `value` holds a C0 control character or DEL. */
|
|
2
|
+
export function hasControlCharacter(value: string): boolean {
|
|
3
|
+
for (let index = 0; index < value.length; index++) {
|
|
4
|
+
const code = value.charCodeAt(index)
|
|
5
|
+
if (code <= 31 || code === 127) return true
|
|
6
|
+
}
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
@@ -39,25 +39,37 @@ function declaresNifra(manifest: string): boolean {
|
|
|
39
39
|
* another project, such as another framework's app kept beside this one.
|
|
40
40
|
*/
|
|
41
41
|
export function createNifraProjectProbe(root: string): (dir: string) => boolean {
|
|
42
|
+
return cachedWalkUp(root, (at, dir) => {
|
|
43
|
+
if (dir === "" || existsSync(join(at, CONFIG_FILE)) || existsSync(join(at, FRAMEWORK_FILE)))
|
|
44
|
+
return true
|
|
45
|
+
if (!existsSync(join(at, "package.json"))) return undefined
|
|
46
|
+
let manifest: string
|
|
47
|
+
try {
|
|
48
|
+
manifest = readFileSync(join(at, "package.json"), "utf8")
|
|
49
|
+
} catch {
|
|
50
|
+
manifest = ""
|
|
51
|
+
}
|
|
52
|
+
return declaresNifra(manifest)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A probe that answers a project-relative directory with `decide`'s answer for it, or, where that is
|
|
58
|
+
* `undefined`, its parent's; nothing decided up to the root means no. Each directory is decided once.
|
|
59
|
+
*/
|
|
60
|
+
function cachedWalkUp(
|
|
61
|
+
root: string,
|
|
62
|
+
decide: (at: string, dir: string) => boolean | undefined,
|
|
63
|
+
): (dir: string) => boolean {
|
|
42
64
|
const cache = new Map<string, boolean>()
|
|
43
65
|
const probe = (dir: string): boolean => {
|
|
44
66
|
const cached = cache.get(dir)
|
|
45
67
|
if (cached !== undefined) return cached
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let manifest: string
|
|
52
|
-
try {
|
|
53
|
-
manifest = readFileSync(join(at, "package.json"), "utf8")
|
|
54
|
-
} catch {
|
|
55
|
-
manifest = ""
|
|
56
|
-
}
|
|
57
|
-
nifra = declaresNifra(manifest)
|
|
58
|
-
} else nifra = probe(dir.slice(0, Math.max(dir.lastIndexOf("/"), 0)))
|
|
59
|
-
cache.set(dir, nifra)
|
|
60
|
-
return nifra
|
|
68
|
+
const answer =
|
|
69
|
+
decide(join(root, dir), dir) ??
|
|
70
|
+
(dir !== "" && probe(dir.slice(0, Math.max(dir.lastIndexOf("/"), 0))))
|
|
71
|
+
cache.set(dir, answer)
|
|
72
|
+
return answer
|
|
61
73
|
}
|
|
62
74
|
return probe
|
|
63
75
|
}
|
|
@@ -144,26 +156,18 @@ const WEB_PACKAGE = /^@nifrajs\/web(?:-[a-z0-9-]+)?$/
|
|
|
144
156
|
* says yes. Nothing up to the root means no.
|
|
145
157
|
*/
|
|
146
158
|
export function createWebAppProbe(root: string): (dir: string) => boolean {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const deps = recordOf(manifest?.[field])
|
|
160
|
-
return deps !== undefined && Object.keys(deps).some((name) => WEB_PACKAGE.test(name))
|
|
161
|
-
})
|
|
162
|
-
} else web = dir !== "" && probe(dir.slice(0, Math.max(dir.lastIndexOf("/"), 0)))
|
|
163
|
-
cache.set(dir, web)
|
|
164
|
-
return web
|
|
165
|
-
}
|
|
166
|
-
return probe
|
|
159
|
+
return cachedWalkUp(root, (at) => {
|
|
160
|
+
if (existsSync(join(at, CONFIG_FILE)) || existsSync(join(at, FRAMEWORK_FILE))) return true
|
|
161
|
+
if (!existsSync(join(at, "package.json"))) return undefined
|
|
162
|
+
const manifest = recordOf(readJson(join(at, "package.json")))
|
|
163
|
+
return (
|
|
164
|
+
recordOf(manifest?.nifra)?.kind !== "api" &&
|
|
165
|
+
DEPENDENCY_FIELDS.some((field) => {
|
|
166
|
+
const deps = recordOf(manifest?.[field])
|
|
167
|
+
return deps !== undefined && Object.keys(deps).some((name) => WEB_PACKAGE.test(name))
|
|
168
|
+
})
|
|
169
|
+
)
|
|
170
|
+
})
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
/** A zone or server-only finding outside any web app, with the API-only setting named. */
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* Never `Bun.resolveSync`: it can install a missing package and remembers answers for the life of the
|
|
8
8
|
* process, and the MCP server is long-lived. A resolver caches what it reads for one check run only.
|
|
9
9
|
*/
|
|
10
|
-
import { readFileSync,
|
|
10
|
+
import { readFileSync, statSync } from "node:fs"
|
|
11
11
|
import { basename, dirname, extname, isAbsolute, join } from "node:path"
|
|
12
|
+
import { realpathOrSelf } from "./realpath-or-self.ts"
|
|
12
13
|
|
|
13
14
|
/** `(absolute importing file, specifier)` to the real path of the file it loads, or `undefined`. */
|
|
14
15
|
export type SpecifierResolver = (fromFile: string, specifier: string) => string | undefined
|
|
@@ -135,14 +136,6 @@ export const isFile = (path: string): boolean => {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
const real = (path: string): string => {
|
|
139
|
-
try {
|
|
140
|
-
return realpathSync(path)
|
|
141
|
-
} catch {
|
|
142
|
-
return path
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
139
|
/** The file a path names: as written, its source for a `.js` name, with an extension, or an index. */
|
|
147
140
|
function probe(base: string, exists: (path: string) => boolean): string | undefined {
|
|
148
141
|
if (exists(base)) return base
|
|
@@ -479,7 +472,7 @@ export function createSpecifierResolver(options: SpecifierResolverOptions = {}):
|
|
|
479
472
|
found = viaImports(fromFile, specifier) ?? viaTsconfig(fromFile, specifier)
|
|
480
473
|
else found = viaTsconfig(fromFile, specifier)
|
|
481
474
|
if (found === undefined) return undefined
|
|
482
|
-
const path =
|
|
475
|
+
const path = realpathOrSelf(found)
|
|
483
476
|
return /[\\/]node_modules[\\/]/.test(path) ? undefined : path
|
|
484
477
|
}
|
|
485
478
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs"
|
|
2
|
+
|
|
3
|
+
/** The real path, or `path` as given when it cannot be resolved: it does not exist yet, or is unreadable. */
|
|
4
|
+
export function realpathOrSelf(path: string): string {
|
|
5
|
+
try {
|
|
6
|
+
return realpathSync(path)
|
|
7
|
+
} catch {
|
|
8
|
+
return path
|
|
9
|
+
}
|
|
10
|
+
}
|