@nifrajs/cli 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/check.d.ts +9 -1
  3. package/dist/check.d.ts.map +1 -1
  4. package/dist/check.js +38 -6
  5. package/dist/check.js.map +1 -1
  6. package/dist/cli.d.ts +2 -18
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +95 -64
  9. package/dist/cli.js.map +1 -1
  10. package/dist/dev-bun-config.d.ts +17 -6
  11. package/dist/dev-bun-config.d.ts.map +1 -1
  12. package/dist/dev-bun-config.js +51 -14
  13. package/dist/dev-bun-config.js.map +1 -1
  14. package/dist/doctor.d.ts +10 -0
  15. package/dist/doctor.d.ts.map +1 -1
  16. package/dist/doctor.js +17 -1
  17. package/dist/doctor.js.map +1 -1
  18. package/dist/introspect.d.ts.map +1 -1
  19. package/dist/introspect.js +7 -1
  20. package/dist/introspect.js.map +1 -1
  21. package/dist/load.d.ts +4 -0
  22. package/dist/load.d.ts.map +1 -1
  23. package/dist/load.js +1 -0
  24. package/dist/load.js.map +1 -1
  25. package/dist/mcp-http.js +1 -1
  26. package/dist/mcp.js +2 -2
  27. package/dist/mcp.js.map +1 -1
  28. package/dist/pipeline-guard.d.ts +25 -10
  29. package/dist/pipeline-guard.d.ts.map +1 -1
  30. package/dist/pipeline-guard.js +35 -15
  31. package/dist/pipeline-guard.js.map +1 -1
  32. package/dist/pipeline-report.d.ts +34 -0
  33. package/dist/pipeline-report.d.ts.map +1 -0
  34. package/dist/pipeline-report.js +282 -0
  35. package/dist/pipeline-report.js.map +1 -0
  36. package/docs/llms-full.txt +200 -13
  37. package/docs/types.json +88 -5
  38. package/package.json +9 -9
  39. package/src/check.ts +54 -5
  40. package/src/cli.ts +99 -65
  41. package/src/dev-bun-config.ts +57 -14
  42. package/src/doctor.ts +28 -1
  43. package/src/introspect.ts +6 -0
  44. package/src/load.ts +5 -0
  45. package/src/mcp-http.ts +1 -1
  46. package/src/mcp.ts +2 -2
  47. package/src/pipeline-guard.ts +44 -14
  48. package/src/pipeline-report.ts +341 -0
package/src/mcp.ts CHANGED
@@ -1124,7 +1124,7 @@ export function projectTools(
1124
1124
  {
1125
1125
  name: "nifra_check",
1126
1126
  description:
1127
- 'Run the project\'s drift gate and return a structured result { ok, typecheck, diagnostics[] }: typecheck (the frontend↔backend contract), plus lints for hand-rolled fetch() to your own API, untyped client("…") calls missing <typeof app>, and server-only imports in routes/. Pass lintsOnly:true for a near-instant lint pass while iterating; run the full gate (default) to confirm the work is done - fix every diagnostic before finishing.',
1127
+ 'Run the project\'s drift gate and return a structured result { ok, typecheck, diagnostics[], pipeline? }: typecheck (the frontend↔backend contract), plus lints for hand-rolled fetch() to your own API, untyped client("…") calls missing <typeof app>, and server-only imports in routes/. `pipeline` answers "which bundler does this app run on" (bun|vite, for dev AND build alike) without starting a server, and its `pipeline` diagnostics catch the hazards of having two: a plugin in the slot the other bundler reads (accepted, then never called), a dev toolchain imported by the file `nifra build` bundles into the production server, and `conditions` that cannot reach Bun\'s dev client bundle. Read it before adding a plugin or a compiler. Pass lintsOnly:true for a near-instant lint pass while iterating; run the full gate (default) to confirm the work is done - fix every diagnostic before finishing.',
1128
1128
  inputSchema: {
1129
1129
  type: "object",
1130
1130
  properties: {
@@ -1323,7 +1323,7 @@ export function projectTools(
1323
1323
  {
1324
1324
  name: "nifra_doctor",
1325
1325
  description:
1326
- "Check this project for packages imported in source but NOT declared in package.json - the Bun-workspace trap where an import resolves at runtime (hoisting/workspace) so tests pass and `bun install` says no changes, yet tsc fails and a fresh/standalone install can't resolve it. Returns { ok, ran, findings[], fixed?, skippedFixes? }. Pass autoFix:true to update package.json only when the dependency version can be inferred locally from an ancestor package.json or installed package metadata; otherwise the tool returns the exact bun add command to run.",
1326
+ "Check this project for packages imported in source but NOT declared in package.json - the Bun-workspace trap where an import resolves at runtime (hoisting/workspace) so tests pass and `bun install` says no changes, yet tsc fails and a fresh/standalone install can't resolve it. Also reports `pipeline`: which bundler (bun|vite) this app's dev AND build phases run on and why, plus config hazards that only exist because there are two - a plugin sitting in the slot the other bundler reads (accepted, then never called), a dev toolchain imported by the file `nifra build` bundles into the production server (builds clean, dies at startup), and `conditions` that cannot reach the client bundle Bun's dev server serves. Returns { ok, ran, findings[], pipeline?, fixed?, skippedFixes? }. Pass autoFix:true to update package.json only when the dependency version can be inferred locally from an ancestor package.json or installed package metadata; otherwise the tool returns the exact bun add command to run.",
1327
1327
  inputSchema: {
1328
1328
  type: "object",
1329
1329
  properties: {
@@ -116,6 +116,13 @@ export type BuildPipeline = "bun" | "vite"
116
116
 
117
117
  export interface PipelineDecision {
118
118
  readonly pipeline: BuildPipeline
119
+ /**
120
+ * How the pipeline was arrived at. Always set, because "which bundler am I on" is a question every
121
+ * `dev`/`build` run should answer without the user reading this source: `default` is the plain Bun
122
+ * default, `auto` means the config forced nifra's hand (see {@link reason}), `forced` is `--vite` /
123
+ * `--bun`.
124
+ */
125
+ readonly why: "default" | "auto" | "forced"
119
126
  /**
120
127
  * Why this pipeline, for the `nifra build` log line - so an auto-selected Vite build never looks
121
128
  * like the user got the default. `undefined` when the choice was the plain default or was forced.
@@ -139,16 +146,14 @@ const pluginNames = (plugins: readonly unknown[]): string =>
139
146
  .join(", ")
140
147
 
141
148
  /**
142
- * Pick the bundler for `nifra build`, per app rather than per global default.
149
+ * Pick the bundler for `nifra build` and `nifra dev`, per app rather than per global default.
143
150
  *
144
- * The phase defaults are deliberately asymmetric - `nifra dev` is Vite (for the plugin ecosystem, and
145
- * because Bun's DEV-server bundler cannot compile CSS Modules), `nifra build` is Bun (faster and
146
- * Bun-native). For an app with no transforms that asymmetry is free: there is nothing to disagree about.
147
- * For an app whose ONLY transforms are Vite plugins it is not. Those plugins run in dev and are then
148
- * dropped by the Bun build - `buildForTarget` reads `clientPlugins`/`serverPlugins`, never `vitePlugins`
149
- * - so the build succeeds, the output looks plausible, and the transform simply did not happen. That is
150
- * the same failure {@link checkPipelineSeparation} exists to prevent, reached by crossing PHASES instead
151
- * of slots, and the slot check cannot see it because the plugins are correctly placed.
151
+ * The phase defaults are Bun (faster and Bun-native). For an app with no transforms that is direct and
152
+ * predictable. For an app whose ONLY transforms are Vite plugins it is not: those plugins are required in
153
+ * both dev and production, while the Bun build reads `clientPlugins`/`serverPlugins`, never `vitePlugins`.
154
+ * Selecting Bun would make the build succeed with the transform omitted. That is the same failure
155
+ * {@link checkPipelineSeparation} exists to prevent, reached by crossing PHASES instead of slots, and the
156
+ * slot check cannot see it because the plugins are correctly placed.
152
157
  *
153
158
  * So the default follows the app: Vite plugins with no Bun counterpart means the app has exactly one
154
159
  * pipeline that can build it, and that is the one used. An app declaring BOTH has supplied the Bun
@@ -161,26 +166,51 @@ const pluginNames = (plugins: readonly unknown[]): string =>
161
166
  export function chooseBuildPipeline(
162
167
  slots: PipelineSlots,
163
168
  forced?: BuildPipeline,
169
+ command: "build" | "dev" = "build",
164
170
  ): PipelineDecision {
165
171
  const vitePlugins = slots.vitePlugins ?? []
166
172
  const bunPlugins = [...(slots.clientPlugins ?? []), ...(slots.serverPlugins ?? [])]
167
173
  const viteOnly = vitePlugins.length > 0 && bunPlugins.length === 0
168
174
 
169
175
  if (forced === "bun" && viteOnly) {
176
+ // Named for the command the user actually typed - a `nifra dev --bun` failure that talks about
177
+ // `nifra build` sends them looking at the wrong command.
178
+ const phase = command === "dev" ? "dev server" : "build"
170
179
  throw new Error(
171
- "[nifra] `nifra build --bun` would silently drop this app's only transforms. `vitePlugins` are " +
172
- "read by the Vite build; the Bun build reads `clientPlugins`/`serverPlugins`, so these would " +
180
+ `[nifra] \`nifra ${command} --bun\` would silently drop this app's only transforms. \`vitePlugins\` are ` +
181
+ `read by the Vite ${phase}; the Bun ${phase} reads \`clientPlugins\`/\`serverPlugins\`, so these would ` +
173
182
  "never run and the output would look plausible without them.\n" +
174
183
  ` Would be dropped: ${pluginNames(vitePlugins)}\n` +
175
- " Drop the flag to build with Vite, or add the Bun equivalents to `clientPlugins`/`serverPlugins`.",
184
+ ` Drop the flag to use Vite, or add the Bun equivalents to \`clientPlugins\`/\`serverPlugins\`.`,
176
185
  )
177
186
  }
178
- if (forced !== undefined) return { pipeline: forced }
187
+ if (forced !== undefined) return { pipeline: forced, why: "forced" }
179
188
  if (viteOnly) {
180
189
  return {
181
190
  pipeline: "vite",
191
+ why: "auto",
182
192
  reason: `auto: this app's only transforms are \`vitePlugins\` (${pluginNames(vitePlugins)}), which the Bun build cannot run`,
183
193
  }
184
194
  }
185
- return { pipeline: "bun" }
195
+ return { pipeline: "bun", why: "default" }
196
+ }
197
+
198
+ /**
199
+ * The one-line "which bundler, and why" note `nifra dev` and `nifra build` print under their banner.
200
+ *
201
+ * Printed on EVERY run, not only the surprising ones. A pipeline that announces itself only when it
202
+ * deviates teaches nobody which pipeline they are normally on, and every gotcha in the dev docs -
203
+ * plugin slots, resolve conditions, which compiler owns a `.svelte` file - is answerable only once you
204
+ * know that. The line also names the flag that switches, so the answer to "can I try the other one"
205
+ * is on screen rather than in the docs.
206
+ */
207
+ export function describePipeline(decision: PipelineDecision): string {
208
+ const other = decision.pipeline === "bun" ? "--vite" : "--bun"
209
+ const detail =
210
+ decision.why === "forced"
211
+ ? `forced by --${decision.pipeline}`
212
+ : decision.why === "auto"
213
+ ? (decision.reason ?? "auto")
214
+ : `default; ${other} to switch`
215
+ return `bundler: ${decision.pipeline} (${detail})`
186
216
  }
@@ -0,0 +1,341 @@
1
+ /**
2
+ * The two-pipeline rule, reported STATICALLY - which bundler this app runs on, and the config hazards
3
+ * that only exist because nifra supports two.
4
+ *
5
+ * `loadApp` already refuses a plugin in the wrong slot ({@link ./load.ts}), and `nifra dev`/`nifra build`
6
+ * print the chosen bundler. Both of those need the app's config to be IMPORTED, which is code execution -
7
+ * something `nifra check` deliberately never does, and something an agent inspecting a repo it has not
8
+ * installed cannot do at all. So this reads the config as text instead.
9
+ *
10
+ * Text, not types, so the rules are chosen for the ones that survive being read rather than run:
11
+ *
12
+ * - Which pipeline the app is on. `chooseBuildPipeline` decides from whether the plugin slots are
13
+ * empty, and "does this file declare a non-empty `vitePlugins`" is a question the source answers.
14
+ * - The adapter-entry hazard. `nifra build` imports the adapter from `framework.ts`, or from
15
+ * `nifra.config.ts` when there is no `framework.ts`, and bundles everything that file imports into
16
+ * the production server. A Vite plugin or an SFC compiler reached that way builds cleanly and then
17
+ * dies at startup on a missing native binding. Nothing runtime-side catches it: by then the build
18
+ * has already succeeded.
19
+ * - A plugin in the wrong slot, for the subset whose import specifier names its pipeline. The load
20
+ * guard classifies by hook shape and is authoritative; this catches the same thing earlier, before
21
+ * anything is installed or started.
22
+ * - `conditions` on the Bun pipeline, which reach SSR and cannot reach the dev client bundle.
23
+ *
24
+ * Everything here degrades to silence rather than guessing. A config that computes its plugins, or
25
+ * re-exports them from elsewhere, yields `certain: false` and no findings - a static reader that
26
+ * invents a pipeline is worse than one that says it could not tell.
27
+ */
28
+ import { existsSync } from "node:fs"
29
+ import { join } from "node:path"
30
+ import { codePositionMask, stripComments } from "./check.ts"
31
+ import type { BuildPipeline } from "./pipeline-guard.ts"
32
+
33
+ /** A plugin slot, and the pipeline it feeds. */
34
+ const SLOT_PIPELINE = {
35
+ vitePlugins: "vite",
36
+ clientPlugins: "bun",
37
+ serverPlugins: "bun",
38
+ } as const satisfies Readonly<Record<string, BuildPipeline>>
39
+
40
+ type Slot = keyof typeof SLOT_PIPELINE
41
+
42
+ const SLOTS = Object.keys(SLOT_PIPELINE) as readonly Slot[]
43
+
44
+ export interface PipelineFinding {
45
+ readonly rule: "adapter-entry" | "plugin-slot" | "bun-client-conditions"
46
+ readonly severity: "error" | "warning"
47
+ /** Project-relative file the finding is in. */
48
+ readonly file: string
49
+ readonly line?: number
50
+ readonly message: string
51
+ readonly fix: string
52
+ }
53
+
54
+ export interface PipelineReport {
55
+ /** `false` when the directory holds no `nifra.config.ts` or `framework.ts` - nothing to report on. */
56
+ readonly ran: boolean
57
+ /** The bundler `nifra dev` and `nifra build` will use, or `unknown` when the source can't say. */
58
+ readonly pipeline: BuildPipeline | "unknown"
59
+ /** Plain-language "why this bundler", in the same words the CLI prints. */
60
+ readonly reason: string
61
+ /**
62
+ * Whether the config states its plugin slots outright. `false` when a slot is a thunk, an identifier,
63
+ * or a re-export - the pipeline shown is then nifra's best reading, and `nifra dev` prints the real one.
64
+ */
65
+ readonly certain: boolean
66
+ /** The config file read, project-relative. */
67
+ readonly configFile?: string
68
+ /** The file `nifra build` imports the adapter from - `framework.ts`, else the config. */
69
+ readonly adapterEntry?: string
70
+ readonly findings: readonly PipelineFinding[]
71
+ }
72
+
73
+ /**
74
+ * Specifiers that carry a dev toolchain: Vite itself, a Vite/Rollup plugin, or a framework's SFC
75
+ * compiler plugin (`@nifrajs/web-vue/plugin` and friends, which import the compiler). A relative
76
+ * `./plugin` is NOT matched - a local file of that name is as likely to be the app's own tiny plugin as
77
+ * a compiler, and this rule fails a gate.
78
+ */
79
+ const DEV_TOOLCHAIN =
80
+ /^vite$|^vite\/|^@vitejs\/|vite-plugin|^rollup$|^@rollup\/|^esbuild$|^(?:@[^/]+\/)?[^./][^/]*\/(?:.*\/)?plugin(?:\.ts)?$/
81
+
82
+ /** Specifiers that name the Vite pipeline outright. */
83
+ const VITE_SPECIFIER = /^vite$|^vite\/|^@vitejs\/|vite-plugin/
84
+ /** Specifiers whose package subpath is nifra's Bun-plugin convention (`@nifrajs/web-vue/plugin`). */
85
+ const BUN_SPECIFIER = /^(?:@[^/]+\/)?[^./][^/]*\/(?:.*\/)?plugin(?:\.ts)?$/
86
+
87
+ const lineAt = (src: string, index: number): number => {
88
+ let line = 1
89
+ for (let i = 0; i < index && i < src.length; i++) if (src[i] === "\n") line++
90
+ return line
91
+ }
92
+
93
+ /** Local binding names introduced by one import clause (`a`, `{ b as c }`, `* as ns`). */
94
+ function localNames(clause: string): string[] {
95
+ const names: string[] = []
96
+ const braced = /\{([^}]*)\}/.exec(clause)
97
+ if (braced !== null) {
98
+ for (const part of (braced[1] ?? "").split(",")) {
99
+ const named = /([A-Za-z_$][\w$]*)\s*$/.exec(part.trim())
100
+ if (named?.[1] !== undefined) names.push(named[1])
101
+ }
102
+ }
103
+ const head = clause.replace(/\{[^}]*\}/, " ").replace(/,/g, " ")
104
+ const star = /\*\s*as\s+([A-Za-z_$][\w$]*)/.exec(head)
105
+ if (star?.[1] !== undefined) names.push(star[1])
106
+ else {
107
+ const def = /^\s*([A-Za-z_$][\w$]*)\s*$/.exec(head)
108
+ if (def?.[1] !== undefined) names.push(def[1])
109
+ }
110
+ return names
111
+ }
112
+
113
+ interface ImportedBinding {
114
+ readonly specifier: string
115
+ readonly index: number
116
+ }
117
+
118
+ /**
119
+ * Every value-importing binding in a module, mapped to the specifier it came from. `import type` is
120
+ * skipped: a type has no runtime cost, so it is neither a bundled toolchain nor a plugin in a slot.
121
+ */
122
+ function importedBindings(stripped: string): Map<string, ImportedBinding> {
123
+ const out = new Map<string, ImportedBinding>()
124
+ const re = /(?<![.\w$])import\s+(?!type[\s{])([^'";]+?)\s+from\s*['"]([^'"]+)['"]/g
125
+ for (let m = re.exec(stripped); m !== null; m = re.exec(stripped)) {
126
+ const specifier = m[2]
127
+ if (specifier === undefined) continue
128
+ for (const name of localNames(m[1] ?? "")) out.set(name, { specifier, index: m.index })
129
+ }
130
+ return out
131
+ }
132
+
133
+ /** Every specifier a module imports for its side effects or bindings, with the position to report. */
134
+ function importedSpecifiers(stripped: string): Array<{ specifier: string; index: number }> {
135
+ const out: Array<{ specifier: string; index: number }> = []
136
+ const re = /(?<![.\w$])import\s+(?:(?!type[\s{])[^'";]*?\s+from\s*)?['"]([^'"]+)['"]/g
137
+ for (let m = re.exec(stripped); m !== null; m = re.exec(stripped)) {
138
+ if (m[1] !== undefined) out.push({ specifier: m[1], index: m.index })
139
+ }
140
+ return out
141
+ }
142
+
143
+ /** Index just past the `]` matching the `[` at `open`, or `undefined` when it never closes. */
144
+ function closeBracket(masked: string, open: number): number | undefined {
145
+ let depth = 0
146
+ for (let i = open; i < masked.length; i++) {
147
+ const c = masked[i]
148
+ if (c === "[") depth++
149
+ else if (c === "]") {
150
+ depth--
151
+ if (depth === 0) return i
152
+ }
153
+ }
154
+ return undefined
155
+ }
156
+
157
+ interface SlotState {
158
+ /** Whether the slot holds at least one plugin (an empty array literal reads as absent, as at runtime). */
159
+ readonly present: boolean
160
+ /** Whether the source states that outright, rather than deferring to a thunk or a re-export. */
161
+ readonly certain: boolean
162
+ readonly index?: number
163
+ /** Identifiers inside the array literal, when there is one. */
164
+ readonly items?: readonly string[]
165
+ }
166
+
167
+ const ABSENT: SlotState = { present: false, certain: true }
168
+
169
+ /**
170
+ * Read one exported binding as a plugin slot.
171
+ *
172
+ * Only an array LITERAL is read precisely; a thunk (`() => import(…)`), a bare identifier or a
173
+ * re-export is recorded as present-but-uncertain. That asymmetry is deliberate: `[]` and `[vue()]`
174
+ * decide the pipeline, and anything else is a promise the source cannot keep.
175
+ */
176
+ function readSlot(masked: string, stripped: string, name: string): SlotState {
177
+ const declaration = new RegExp(
178
+ `(?<![.\\w$])export\\s+(?:const|let|var)\\s+${name}\\b[^=\\n]*=\\s*`,
179
+ )
180
+ const m = declaration.exec(masked)
181
+ if (m !== null) {
182
+ const start = m.index + m[0].length
183
+ if (masked[start] === "[") {
184
+ const end = closeBracket(masked, start)
185
+ if (end !== undefined) {
186
+ // Both views are offset-preserving, and each answers a different question: the mask has string
187
+ // CONTENTS blanked, so identifiers found in it are real code; the stripped source keeps them, so
188
+ // it is the one that can tell `["solid"]` from `[]`.
189
+ const code = masked.slice(start + 1, end)
190
+ const text = stripped.slice(start + 1, end)
191
+ const items = [...code.matchAll(/(?<![.\w$])([A-Za-z_$][\w$]*)/g)].map((i) => i[1] ?? "")
192
+ return { present: text.trim() !== "", certain: true, index: m.index, items }
193
+ }
194
+ }
195
+ return { present: true, certain: false, index: m.index }
196
+ }
197
+ // `export { vitePlugins } from "./plugins.ts"` - present, but its contents live in another file.
198
+ const reexport = new RegExp(`(?<![.\\w$])export\\s*\\{[^}]*\\b${name}\\b[^}]*\\}`)
199
+ const r = reexport.exec(stripped)
200
+ if (r !== null) return { present: true, certain: false, index: r.index }
201
+ // `export * from …` could carry the slot; say so rather than reporting an absence that isn't one.
202
+ if (/(?<![.\w$])export\s*\*\s*from/.test(stripped)) return { present: false, certain: false }
203
+ return ABSENT
204
+ }
205
+
206
+ /** Which pipeline a plugin reference belongs to, or `undefined` when its name and origin say nothing. */
207
+ function classifyRef(name: string, specifier: string | undefined): BuildPipeline | undefined {
208
+ // nifra's own Bun plugins are named for what they are, and the name survives an alias-free import.
209
+ if (/BunPlugin$/.test(name)) return "bun"
210
+ if (specifier === undefined) return undefined
211
+ if (VITE_SPECIFIER.test(specifier)) return "vite"
212
+ if (BUN_SPECIFIER.test(specifier)) return "bun"
213
+ return undefined
214
+ }
215
+
216
+ /** Read one file as text, or `undefined` when it is missing or unreadable. */
217
+ async function readSource(path: string): Promise<string | undefined> {
218
+ try {
219
+ return await Bun.file(path).text()
220
+ } catch {
221
+ return undefined
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Report the pipeline and its config hazards for the app at `cwd`, without executing anything.
227
+ * Total: a missing or unreadable config yields `ran: false`, never a throw.
228
+ */
229
+ export async function collectPipelineReport(cwd: string): Promise<PipelineReport> {
230
+ const configFile = existsSync(join(cwd, "nifra.config.ts")) ? "nifra.config.ts" : "framework.ts"
231
+ const source = await readSource(join(cwd, configFile))
232
+ if (source === undefined) {
233
+ return {
234
+ ran: false,
235
+ pipeline: "unknown",
236
+ reason: "no nifra.config.ts or framework.ts here",
237
+ certain: false,
238
+ findings: [],
239
+ }
240
+ }
241
+ const masked = codePositionMask(source)
242
+ const stripped = stripComments(source)
243
+ const bindings = importedBindings(stripped)
244
+ const slots = Object.fromEntries(
245
+ SLOTS.map((slot) => [slot, readSlot(masked, stripped, slot)]),
246
+ ) as Record<Slot, SlotState>
247
+
248
+ const findings: PipelineFinding[] = []
249
+
250
+ // A plugin whose specifier names the other pipeline. The load-time guard classifies by hook shape and
251
+ // remains the authority; this is the half of it that can run on a repo nobody has installed yet.
252
+ for (const slot of SLOTS) {
253
+ const state = slots[slot]
254
+ const expected = SLOT_PIPELINE[slot]
255
+ for (const item of state.items ?? []) {
256
+ const binding = bindings.get(item)
257
+ const actual = classifyRef(item, binding?.specifier)
258
+ if (actual === undefined || actual === expected) continue
259
+ const from = binding !== undefined ? ` (imported from "${binding.specifier}")` : ""
260
+ findings.push({
261
+ rule: "plugin-slot",
262
+ severity: "error",
263
+ file: configFile,
264
+ line: lineAt(source, state.index ?? 0),
265
+ message:
266
+ `\`${item}\`${from} is a ${actual === "vite" ? "Vite" : "Bun"} plugin but sits in \`${slot}\`, which feeds ` +
267
+ `${expected === "vite" ? "Vite" : "Bun.build"}. The wrong bundler never calls its hooks, so the transform silently does not run and the build still succeeds.`,
268
+ fix:
269
+ actual === "vite"
270
+ ? `move \`${item}\` to \`vitePlugins\``
271
+ : `move \`${item}\` to \`clientPlugins\` (client bundle) or \`serverPlugins\` (SSR)`,
272
+ })
273
+ }
274
+ }
275
+
276
+ // Which bundler this app gets, by the same rule `chooseBuildPipeline` applies to the loaded config.
277
+ const viteOnly =
278
+ slots.vitePlugins.present && !slots.clientPlugins.present && !slots.serverPlugins.present
279
+ const certain = SLOTS.every((slot) => slots[slot].certain)
280
+ const pipeline: BuildPipeline = viteOnly ? "vite" : "bun"
281
+ const reason = viteOnly
282
+ ? "auto: this app's only transforms are `vitePlugins`, which the Bun build cannot run"
283
+ : slots.clientPlugins.present || slots.serverPlugins.present
284
+ ? "default: this app declares Bun plugins, so both phases stay on Bun"
285
+ : "default: no transforms to place, so both phases stay on Bun"
286
+
287
+ // The adapter entry is bundled into every `nifra build` server entry. Whatever it imports goes with it.
288
+ const adapterEntry = existsSync(join(cwd, "framework.ts")) ? "framework.ts" : configFile
289
+ const entrySource =
290
+ adapterEntry === configFile ? source : await readSource(join(cwd, adapterEntry))
291
+ if (entrySource !== undefined) {
292
+ const seen = new Set<string>()
293
+ for (const { specifier, index } of importedSpecifiers(stripComments(entrySource))) {
294
+ if (!DEV_TOOLCHAIN.test(specifier) || seen.has(specifier)) continue
295
+ seen.add(specifier)
296
+ findings.push({
297
+ rule: "adapter-entry",
298
+ severity: "error",
299
+ file: adapterEntry,
300
+ line: lineAt(entrySource, index),
301
+ message:
302
+ `${adapterEntry} imports "${specifier}", and \`nifra build\` imports the adapter from ${adapterEntry} - ` +
303
+ "so the dev toolchain is bundled into the production server entry. The build succeeds and the server then fails at startup on a dependency of the bundler (a missing native binding, typically), which reads like a broken install rather than a config split.",
304
+ fix:
305
+ adapterEntry === "framework.ts"
306
+ ? 'move "' +
307
+ specifier +
308
+ '" to `nifra.config.ts`, which only the CLI imports, and keep `framework.ts` to the adapter'
309
+ : 'add a `framework.ts` exporting just the adapter, re-export it from `nifra.config.ts` (`export { adapter } from "./framework"`), and leave the toolchain imports in the config',
310
+ })
311
+ }
312
+ }
313
+
314
+ // `conditions` reach SSR on the Bun pipeline and cannot reach the client bundle Bun's dev server
315
+ // serves - it takes no resolve conditions from bunfig or anywhere else. `nifra dev` says so at
316
+ // startup; a project whose CI only runs `nifra check` would otherwise never hear it.
317
+ const conditions = readSlot(masked, stripped, "conditions")
318
+ if (conditions.present && pipeline === "bun") {
319
+ findings.push({
320
+ rule: "bun-client-conditions",
321
+ severity: "warning",
322
+ file: configFile,
323
+ line: lineAt(source, conditions.index ?? 0),
324
+ message:
325
+ "`conditions` are honoured by SSR and by `nifra build`, but Bun's dev-server bundler accepts no resolve conditions - so under `nifra dev` a package with an `exports` map can resolve to one file in the browser and another everywhere else.",
326
+ fix: "run `nifra dev --vite` when the client bundle must resolve exactly as production does",
327
+ })
328
+ }
329
+
330
+ return {
331
+ ran: true,
332
+ pipeline: certain ? pipeline : "unknown",
333
+ reason: certain
334
+ ? reason
335
+ : "the config states its plugins indirectly (a thunk, an identifier or a re-export), so the bundler can only be read by loading it - `nifra dev` and `nifra build` print the real one",
336
+ certain,
337
+ configFile,
338
+ adapterEntry,
339
+ findings,
340
+ }
341
+ }