@nifrajs/cli 5.5.1 → 5.7.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 +314 -0
- package/dist/cdn-check.d.ts +7 -6
- package/dist/cdn-check.d.ts.map +1 -1
- package/dist/cdn-check.js +13 -1
- package/dist/cdn-check.js.map +1 -1
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +9 -3
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +6 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +30 -32
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +35 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +66 -9
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +19 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +111 -6
- package/dist/command-catalog.js.map +1 -1
- package/dist/contracts.d.ts +42 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +288 -9
- package/dist/contracts.js.map +1 -1
- package/dist/doctor.d.ts +12 -2
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +67 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +27 -0
- package/dist/fix-recipes.js.map +1 -1
- package/dist/frontend-guidance.d.ts +1 -1
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +17 -8
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/internal/git-ignored.d.ts +12 -0
- package/dist/internal/git-ignored.d.ts.map +1 -0
- package/dist/internal/git-ignored.js +49 -0
- package/dist/internal/git-ignored.js.map +1 -0
- package/dist/internal/source-facts.d.ts +29 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +160 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.js +1 -1
- package/dist/introspect.js.map +1 -1
- package/dist/load.d.ts +7 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +18 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +15 -0
- package/dist/local-cli.d.ts.map +1 -0
- package/dist/local-cli.js +74 -0
- package/dist/local-cli.js.map +1 -0
- package/dist/lock-links.d.ts +0 -7
- package/dist/lock-links.d.ts.map +1 -1
- package/dist/lock-links.js +5 -44
- package/dist/lock-links.js.map +1 -1
- package/dist/mcp-delegate.d.ts +13 -5
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +24 -8
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +57 -3
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.d.ts +2 -1
- package/dist/mcp-http.d.ts.map +1 -1
- package/dist/mcp-http.js +3 -2
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-tool-meta.d.ts +21 -0
- package/dist/mcp-tool-meta.d.ts.map +1 -0
- package/dist/mcp-tool-meta.js +246 -0
- package/dist/mcp-tool-meta.js.map +1 -0
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +36 -98
- package/dist/mcp.js.map +1 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +45 -2
- package/dist/openapi-types.js.map +1 -1
- package/dist/output-schemas.d.ts +8 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +14 -0
- package/dist/output-schemas.js.map +1 -1
- package/dist/ppr-read-fix.d.ts +8 -0
- package/dist/ppr-read-fix.d.ts.map +1 -0
- package/dist/ppr-read-fix.js +356 -0
- package/dist/ppr-read-fix.js.map +1 -0
- package/dist/recipes/5.6.0.d.ts +10 -0
- package/dist/recipes/5.6.0.d.ts.map +1 -0
- package/dist/recipes/5.6.0.js +68 -0
- package/dist/recipes/5.6.0.js.map +1 -0
- package/dist/recipes/5.7.0.d.ts +12 -0
- package/dist/recipes/5.7.0.d.ts.map +1 -0
- package/dist/recipes/5.7.0.js +70 -0
- package/dist/recipes/5.7.0.js.map +1 -0
- package/dist/recipes/index.d.ts +13 -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 -2
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +10 -3
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +11 -4
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +52 -16
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/islands.d.ts +91 -0
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +757 -3
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/legacy.js +1 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/ppr.d.ts +16 -0
- package/dist/rules/ppr.d.ts.map +1 -0
- package/dist/rules/ppr.js +114 -0
- package/dist/rules/ppr.js.map +1 -0
- package/dist/rules/swap.d.ts +7 -0
- package/dist/rules/swap.d.ts.map +1 -0
- package/dist/rules/swap.js +338 -0
- package/dist/rules/swap.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts +8 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -0
- package/dist/rules/text-slot-boolean.js +57 -0
- package/dist/rules/text-slot-boolean.js.map +1 -0
- package/dist/rules/undeclared-response.d.ts +9 -0
- package/dist/rules/undeclared-response.d.ts.map +1 -0
- package/dist/rules/undeclared-response.js +93 -0
- package/dist/rules/undeclared-response.js.map +1 -0
- package/dist/scaffold-hole.d.ts +105 -0
- package/dist/scaffold-hole.d.ts.map +1 -0
- package/dist/scaffold-hole.js +688 -0
- package/dist/scaffold-hole.js.map +1 -0
- package/dist/scaffold.d.ts +5 -3
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +56 -46
- package/dist/scaffold.js.map +1 -1
- package/dist/upgrade.d.ts +34 -8
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +197 -25
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +12 -1
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.js +1 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +70 -10
- package/docs/llms-full.txt +3162 -1196
- package/docs/types.json +1473 -322
- package/package.json +11 -11
- package/src/cdn-check.ts +21 -7
- package/src/check-diagnostics.ts +9 -3
- package/src/check-scan.ts +35 -32
- package/src/check.ts +32 -10
- package/src/cli.ts +71 -9
- package/src/command-catalog.ts +149 -6
- package/src/contracts.ts +348 -14
- package/src/doctor.ts +62 -3
- package/src/fix-recipes.ts +28 -0
- package/src/frontend-guidance.ts +20 -8
- package/src/internal/git-ignored.ts +47 -0
- package/src/internal/source-facts.ts +198 -0
- package/src/introspect.ts +1 -1
- package/src/load.ts +29 -0
- package/src/local-cli.ts +83 -0
- package/src/lock-links.ts +5 -43
- package/src/mcp-delegate.ts +30 -9
- package/src/mcp-exec.ts +74 -3
- package/src/mcp-http.ts +3 -2
- package/src/mcp-tool-meta.ts +268 -0
- package/src/mcp.ts +35 -99
- package/src/openapi-types.ts +43 -2
- package/src/output-schemas.ts +28 -0
- package/src/ppr-read-fix.ts +426 -0
- package/src/recipes/5.6.0.ts +69 -0
- package/src/recipes/5.7.0.ts +72 -0
- package/src/recipes/index.ts +18 -0
- package/src/review.ts +9 -2
- package/src/rules/codes.ts +11 -4
- package/src/rules/explanations.ts +52 -16
- package/src/rules/islands.ts +875 -3
- package/src/rules/legacy.ts +1 -1
- package/src/rules/ppr.ts +143 -0
- package/src/rules/swap.ts +402 -0
- package/src/rules/text-slot-boolean.ts +56 -0
- package/src/rules/undeclared-response.ts +92 -0
- package/src/scaffold-hole.ts +880 -0
- package/src/scaffold.ts +60 -49
- package/src/upgrade.ts +229 -33
- package/src/verification-plan.ts +20 -1
- package/src/version-drift.ts +1 -1
- package/src/web-app-options.ts +2 -0
- package/dist/rules/nano.d.ts +0 -6
- package/dist/rules/nano.d.ts.map +0 -1
- package/dist/rules/nano.js +0 -273
- package/dist/rules/nano.js.map +0 -1
- package/src/rules/nano.ts +0 -307
package/src/scaffold.ts
CHANGED
|
@@ -18,9 +18,9 @@ import { paramConstraint } from "@nifrajs/core/pattern"
|
|
|
18
18
|
export type Framework = "react" | "preact" | "solid" | "vue" | "svelte" | "vanilla"
|
|
19
19
|
|
|
20
20
|
/** A scaffold flavour on top of the framework. `default` is the plain page stub; `stateful` only
|
|
21
|
-
* applies to vanilla and emits
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
21
|
+
* applies to vanilla and emits a reactive island (`bindIsland` state + `data-bind-*` markup + keyed
|
|
22
|
+
* `bindList`) instead of the static island stub - the small-app lane whose binding names, binding
|
|
23
|
+
* hosts and list keys NF-C047/C048/C022 check statically. */
|
|
24
24
|
export type ScaffoldVariant = "default" | "stateful"
|
|
25
25
|
|
|
26
26
|
const EXT: Record<Framework, string> = {
|
|
@@ -32,6 +32,9 @@ const EXT: Record<Framework, string> = {
|
|
|
32
32
|
vanilla: "tsx",
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** The page file extension a framework's routes use. */
|
|
36
|
+
export const pageExtension = (framework: Framework): string => EXT[framework]
|
|
37
|
+
|
|
35
38
|
/** Derive the framework from a `clientModule` like `@nifrajs/web-react/client`. Defaults to react. */
|
|
36
39
|
export function frameworkFromClientModule(clientModule: string | undefined): Framework {
|
|
37
40
|
const m = /@nifrajs\/web-(react|preact|solid|vue|svelte|vanilla)\b/.exec(clientModule ?? "")
|
|
@@ -178,7 +181,7 @@ export default function Page({ data }: Route.ComponentProps) {
|
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
// --- Add interactivity the AI-safe way (islands), NOT hydration ---------------------------------
|
|
181
|
-
// 1. Render a marker in the page above: html\`<nifra-island data-
|
|
184
|
+
// 1. Render a marker in the page above: html\`<nifra-island data-island="counter" data-island-props="\${JSON.stringify({ start: 0 })}"></nifra-island>\`
|
|
182
185
|
// 2. Wire the route to its enhancer bundle, in ${basename(backendFileOf(file))}:
|
|
183
186
|
// export const islandScripts = [/* built URL of ./counter.client.ts */]
|
|
184
187
|
// 3. Write ./counter.client.ts as an imperative enhancer that ALWAYS returns its cleanup:
|
|
@@ -198,72 +201,80 @@ export default function Page({ data }: Route.ComponentProps) {
|
|
|
198
201
|
}
|
|
199
202
|
|
|
200
203
|
/**
|
|
201
|
-
* The
|
|
202
|
-
* page
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* - a `bind
|
|
207
|
-
* - a `bindList` keyed by
|
|
208
|
-
* - a `computed` reading a signal its `[deps]` omits -> NF-C023 (the block declares `[todos]`)
|
|
204
|
+
* The reactive island stub (`nifra scaffold --variant stateful`, vanilla only): a zero-runtime `html`
|
|
205
|
+
* page whose island markup carries its own `data-bind-*` attributes, plus the companion
|
|
206
|
+
* `<name>.client.ts` shown as the copy-paste block. Bindings are names, never code, and the client
|
|
207
|
+
* names its state and handlers literally, so `nifra check` can match the two:
|
|
208
|
+
* - a `data-bind-*` name with no `state("...")` key or returned handler -> NF-C047
|
|
209
|
+
* - a `data-bind-*` attribute outside a host mounted with `bindIsland` -> NF-C048
|
|
210
|
+
* - a `bindList` keyed by the item's position -> NF-C022
|
|
209
211
|
* The page body is a valid, typecheckable static document; interactivity is added by writing the
|
|
210
212
|
* companion client shown, never by turning on hydration.
|
|
211
213
|
*/
|
|
212
|
-
function
|
|
213
|
-
return `// ${file} - @nifrajs/web-vanilla page + a
|
|
214
|
-
// document is static and
|
|
215
|
-
// island's \`islandScripts\` URL live in ${basename(backendFileOf(file))}.
|
|
214
|
+
function statefulStub(file: string): string {
|
|
215
|
+
return `// ${file} - @nifrajs/web-vanilla page + a reactive island (signals bound to server-rendered
|
|
216
|
+
// markup, zero VDOM). The document is static and works with JS off; the client below binds it.
|
|
217
|
+
// \`hydrate = false\` and the island's \`islandScripts\` URL live in ${basename(backendFileOf(file))}.
|
|
216
218
|
import { html } from "@nifrajs/web-vanilla"
|
|
217
219
|
import type { Route } from "${typesOf(file)}"
|
|
218
220
|
|
|
219
221
|
export default function Page({ data }: Route.ComponentProps) {
|
|
220
|
-
//
|
|
222
|
+
// data-island names the enhancer; data-island-props seeds its state; data-bind-* names its state
|
|
223
|
+
// and handlers.
|
|
221
224
|
return html\`<main>
|
|
222
225
|
<h1>\${data.title}</h1>
|
|
223
|
-
<
|
|
226
|
+
<section data-island="todos" data-island-props="\${JSON.stringify({ items: [] })}">
|
|
227
|
+
<form data-bind-on="submit:add">
|
|
228
|
+
<input name="text" data-bind-value="draft" />
|
|
229
|
+
<button>Add</button>
|
|
230
|
+
</form>
|
|
231
|
+
<p><span data-bind-text="left">0</span> left</p>
|
|
232
|
+
<ul></ul>
|
|
233
|
+
</section>
|
|
224
234
|
</main>\`
|
|
225
235
|
}
|
|
226
236
|
|
|
227
|
-
// --- ./todos.client.ts - the
|
|
237
|
+
// --- ./todos.client.ts - the reactive island (write this as a companion file) -------------------
|
|
228
238
|
//
|
|
229
|
-
// import {
|
|
230
|
-
// import { signal, computed, bind, bindList } from "@nifrajs/web/nano"
|
|
239
|
+
// import { bindIsland, bindList, effect, mountIslands } from "@nifrajs/web/islands"
|
|
231
240
|
//
|
|
232
241
|
// interface Todo { id: string; text: string; done: boolean }
|
|
233
242
|
//
|
|
234
|
-
// const todos =
|
|
235
|
-
// // 1. State is
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
// const
|
|
243
|
+
// const todos = bindIsland(({ root, state }) => {
|
|
244
|
+
// // 1. State is named. Every data-bind-* name in the markup is a state(...) key here (NF-C047),
|
|
245
|
+
// // seeded from data-island-props when the props carry it.
|
|
246
|
+
// const items = state<Todo[]>("items", [])
|
|
247
|
+
// const draft = state("draft", "")
|
|
248
|
+
// const left = state("left", 0)
|
|
240
249
|
//
|
|
241
|
-
// //
|
|
242
|
-
//
|
|
243
|
-
// const count = el.querySelector("[data-count]")!
|
|
244
|
-
// cleanups.push(bind(count, remaining, (node, n) => { node.textContent = String(n) + " left" }))
|
|
250
|
+
// // 2. Derived values come from an effect: it re-runs when a signal it read changes.
|
|
251
|
+
// effect(() => left.set(items().filter((t) => !t.done).length))
|
|
245
252
|
//
|
|
246
|
-
// //
|
|
247
|
-
// //
|
|
248
|
-
// const list =
|
|
249
|
-
//
|
|
253
|
+
// // 3. A keyed list. Key by a STABLE id on the item, never its position (NF-C022), or an
|
|
254
|
+
// // insert, removal or reorder hands a node to the wrong item.
|
|
255
|
+
// const list = root.querySelector("ul")
|
|
256
|
+
// if (list) bindList(items, list, {
|
|
250
257
|
// key: (t) => t.id,
|
|
251
|
-
// create: (
|
|
258
|
+
// create: () => document.createElement("li"),
|
|
252
259
|
// update: (li, t) => { li.textContent = t.text; li.classList.toggle("done", t.done) },
|
|
253
|
-
// })
|
|
254
|
-
//
|
|
255
|
-
// // Mutations replace the value (Object.is-deduped); subscribers run synchronously.
|
|
256
|
-
// const add = (text: string) => items.set([...items.get(), { id: crypto.randomUUID(), text, done: false }])
|
|
257
|
-
// void add
|
|
260
|
+
// })
|
|
258
261
|
//
|
|
259
|
-
// //
|
|
260
|
-
//
|
|
262
|
+
// // 4. Handlers are returned by name for data-bind-on. Everything the setup created stops when
|
|
263
|
+
// // the island unmounts; onDispose(fn) covers timers and requests it starts itself.
|
|
264
|
+
// return {
|
|
265
|
+
// add: (event) => {
|
|
266
|
+
// event.preventDefault()
|
|
267
|
+
// const text = draft().trim()
|
|
268
|
+
// if (text) items.set((list) => [...list, { id: crypto.randomUUID(), text, done: false }])
|
|
269
|
+
// draft.set("")
|
|
270
|
+
// },
|
|
271
|
+
// }
|
|
261
272
|
// })
|
|
262
273
|
//
|
|
263
274
|
// mountIslands({ todos })
|
|
264
275
|
//
|
|
265
|
-
// Cross-island coordination: one createIslandBus() closed over in each enhancer. nifra_docs("
|
|
266
|
-
// has the full cookbook; \`nifra check\` runs NF-
|
|
276
|
+
// Cross-island coordination: one createIslandBus() closed over in each enhancer. nifra_docs("islands")
|
|
277
|
+
// has the full cookbook; \`nifra check\` runs NF-C047/C048/C022 over the page and client you write.
|
|
267
278
|
`
|
|
268
279
|
}
|
|
269
280
|
|
|
@@ -297,14 +308,14 @@ export function scaffoldRoute(
|
|
|
297
308
|
file: backendFileOf(file),
|
|
298
309
|
content: backendStub(file, params, framework === "vanilla"),
|
|
299
310
|
}
|
|
300
|
-
// `stateful` is vanilla-only: it swaps the static island stub for the
|
|
311
|
+
// `stateful` is vanilla-only: it swaps the static island stub for the reactive island. Asking
|
|
301
312
|
// for it on a JSX/SFC framework is a no-op on the flavour (those lanes have their own reactivity).
|
|
302
313
|
if (framework === "vanilla" && variant === "stateful") {
|
|
303
314
|
return {
|
|
304
315
|
file,
|
|
305
|
-
content:
|
|
316
|
+
content: statefulStub(file),
|
|
306
317
|
backend,
|
|
307
|
-
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route with a
|
|
318
|
+
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route with a reactive island. ${ROUTE_CONTRACT}\nThe stub embeds the island client (bindIsland state + data-bind-* markup + keyed bindList); write it as the companion .client.ts. \`nifra check\` runs NF-C047/C048/C022 over the page and client; nifra_docs("islands") is the full cookbook.`,
|
|
308
319
|
}
|
|
309
320
|
}
|
|
310
321
|
if (framework === "react" || framework === "preact" || framework === "solid") {
|
|
@@ -320,7 +331,7 @@ export function scaffoldRoute(
|
|
|
320
331
|
file,
|
|
321
332
|
content: vanillaStub(file),
|
|
322
333
|
backend,
|
|
323
|
-
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route. ${ROUTE_CONTRACT}\nInteractivity comes from islands (imperative enhancers), never hydration - the stub embeds the golden pattern; nifra_example("islands") has the full cookbook. For
|
|
334
|
+
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route. ${ROUTE_CONTRACT}\nInteractivity comes from islands (imperative enhancers), never hydration - the stub embeds the golden pattern; nifra_example("islands") has the full cookbook. For local state (a list a human edits), scaffold with variant "stateful" to get a reactive island instead.`,
|
|
324
335
|
}
|
|
325
336
|
}
|
|
326
337
|
return {
|
package/src/upgrade.ts
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* 2. **dependency moves** - replace removed packages with their supported successor without
|
|
13
13
|
* reserializing package.json or leaving duplicate dependency keys.
|
|
14
14
|
* 3. **import moves** - rewrite exact import specifiers to their updated module paths.
|
|
15
|
-
* 4. **
|
|
15
|
+
* 4. **dependency adds** - add a package an imported entry needs to the manifest that imports it,
|
|
16
|
+
* beside the package the entry belongs to, when that manifest lists it nowhere.
|
|
17
|
+
* 5. **verify** - reuse the existing `nifra check` gate; no new verification surface. It reads the
|
|
16
18
|
* installed packages, so while the edited pins are not installed yet it is skipped with the
|
|
17
19
|
* install command to run first: a check then would judge the release being left.
|
|
18
20
|
*
|
|
@@ -52,15 +54,20 @@ import {
|
|
|
52
54
|
} from "./hooks-report.ts"
|
|
53
55
|
import { type AncestorPinSite, ancestorPins, declaresCli, PIN_SITES } from "./init-agents.ts"
|
|
54
56
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
57
|
+
import { gitIgnoredSync } from "./internal/git-ignored.ts"
|
|
55
58
|
import {
|
|
56
59
|
BUN_LOCK,
|
|
57
60
|
describeChange,
|
|
58
61
|
linkLockUpdate,
|
|
59
|
-
pruneLinkLocks,
|
|
60
62
|
type StaleLinkLock,
|
|
61
63
|
staleLinkLocks,
|
|
62
64
|
} from "./lock-links.ts"
|
|
63
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
type DependencyAdd,
|
|
67
|
+
getRecipe,
|
|
68
|
+
listRecipeVersions,
|
|
69
|
+
type UpgradeRecipe,
|
|
70
|
+
} from "./recipes/index.ts"
|
|
64
71
|
import { markerTarget } from "./rules/comment-markers.ts"
|
|
65
72
|
|
|
66
73
|
export interface UpgradeOptions {
|
|
@@ -115,6 +122,17 @@ export interface DependencyMoveChange {
|
|
|
115
122
|
readonly action: "renamed" | "removed"
|
|
116
123
|
}
|
|
117
124
|
|
|
125
|
+
/** A package added to a manifest because a source file beneath it imports an entry that needs it. */
|
|
126
|
+
export interface DependencyAddChange {
|
|
127
|
+
readonly file: string
|
|
128
|
+
readonly field: string
|
|
129
|
+
readonly name: string
|
|
130
|
+
readonly version: string
|
|
131
|
+
/** The first source file found importing that entry, and the specifier it uses. */
|
|
132
|
+
readonly importer: string
|
|
133
|
+
readonly specifier: string
|
|
134
|
+
}
|
|
135
|
+
|
|
118
136
|
/** An agent file whose MCP launch pins another `@nifrajs/cli`, re-pinned to the target. */
|
|
119
137
|
export interface AgentPinChange {
|
|
120
138
|
readonly file: string
|
|
@@ -141,6 +159,7 @@ export interface UpgradePlan {
|
|
|
141
159
|
readonly agentPins: readonly AgentPinChange[]
|
|
142
160
|
readonly dependencyMoves: readonly DependencyMoveChange[]
|
|
143
161
|
readonly importMoves: readonly ImportChange[]
|
|
162
|
+
readonly dependencyAdds: readonly DependencyAddChange[]
|
|
144
163
|
/** Pins refused because the target is BELOW the installed version (a rollback). Empty when allowed. */
|
|
145
164
|
readonly downgrades: readonly PinChange[]
|
|
146
165
|
/** Comments a release in the chain stopped honoring. Listed only, never rewritten. */
|
|
@@ -153,10 +172,9 @@ export interface UpgradePlan {
|
|
|
153
172
|
/** Other versions pinned outside package.json. Never edited. */
|
|
154
173
|
readonly strayPins: readonly StrayPin[]
|
|
155
174
|
/** `file:` entries of the project's bun.lock whose recorded dependencies the linked package.json
|
|
156
|
-
* (as this upgrade leaves it) no longer declares. Bun never refreshes them on its own.
|
|
175
|
+
* (as this upgrade leaves it) no longer declares. Bun 1.4.2 never refreshes them on its own. Never
|
|
176
|
+
* edited: an install that finds one missing re-resolves every package in the lock. */
|
|
157
177
|
readonly linkLocks: readonly StaleLinkLock[]
|
|
158
|
-
/** Whether `--write` dropped {@link linkLocks} from bun.lock, so `bun install` re-reads them. */
|
|
159
|
-
readonly lockPruned: boolean
|
|
160
178
|
readonly notes: readonly string[]
|
|
161
179
|
/** Releases on the way up that announce no behaviour change for the packages this project loads. */
|
|
162
180
|
readonly unaffected: readonly UnaffectedRelease[]
|
|
@@ -632,6 +650,138 @@ export function applyImportMoves(
|
|
|
632
650
|
}
|
|
633
651
|
|
|
634
652
|
const SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"
|
|
653
|
+
// Svelte and Vue components import adapter entries too.
|
|
654
|
+
const ADD_SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}"
|
|
655
|
+
|
|
656
|
+
const IMPORTED_SPEC = (prefix: string): RegExp =>
|
|
657
|
+
new RegExp(
|
|
658
|
+
`(?:\\bfrom\\s*|\\bimport\\s*\\(\\s*|\\brequire\\s*\\(\\s*|\\bimport\\s+)(['"])(${escapeRegExp(prefix)}(?:/[^'"]*)?)\\1`,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
/** The first specifier in `text` that names one of `imports` or a subpath of one. */
|
|
662
|
+
export function importedSpecifier(text: string, imports: readonly string[]): string | undefined {
|
|
663
|
+
for (const prefix of imports) {
|
|
664
|
+
const match = IMPORTED_SPEC(prefix).exec(text)
|
|
665
|
+
if (match !== null) return match[2]
|
|
666
|
+
}
|
|
667
|
+
return undefined
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const packageOf = (specifier: string): string =>
|
|
671
|
+
specifier
|
|
672
|
+
.split("/")
|
|
673
|
+
.slice(0, specifier.startsWith("@") ? 2 : 1)
|
|
674
|
+
.join("/")
|
|
675
|
+
|
|
676
|
+
const MEMBER = /("(?:[^"\\]|\\.)*")\s*:\s*"(?:[^"\\]|\\.)*"/g
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Add `"name": "version"` to the `field` object of a package.json text without reserializing it,
|
|
680
|
+
* creating the field at the end of the root when absent. The entry goes before the first larger name
|
|
681
|
+
* when the members are sorted, last otherwise.
|
|
682
|
+
*/
|
|
683
|
+
function insertDependencyEntry(text: string, field: string, name: string, version: string): string {
|
|
684
|
+
const entry = `${JSON.stringify(name)}: ${JSON.stringify(version)}`
|
|
685
|
+
const unit = /\n([ \t]+)"/.exec(text)?.[1] ?? " "
|
|
686
|
+
const range = objectRangeAt(text, [field])
|
|
687
|
+
if (range === undefined) {
|
|
688
|
+
const root = objectRangeAt(text, [])
|
|
689
|
+
if (root === undefined) return text
|
|
690
|
+
const body = text.slice(root.start, root.end)
|
|
691
|
+
const at = root.start + body.trimEnd().length
|
|
692
|
+
const comma = body.trim() === "" ? "" : ","
|
|
693
|
+
const close = /^[ \t]*\n/.test(text.slice(at)) ? "" : "\n"
|
|
694
|
+
const object = `${JSON.stringify(field)}: {\n${unit}${unit}${entry}\n${unit}}`
|
|
695
|
+
return `${text.slice(0, at)}${comma}\n${unit}${object}${close}${text.slice(at)}`
|
|
696
|
+
}
|
|
697
|
+
const body = text.slice(range.start, range.end)
|
|
698
|
+
const members = [...body.matchAll(MEMBER)]
|
|
699
|
+
const first = members[0]
|
|
700
|
+
const last = members.at(-1)
|
|
701
|
+
if (first === undefined || last === undefined) {
|
|
702
|
+
const lineStart = text.lastIndexOf("\n", range.start) + 1
|
|
703
|
+
const indent = /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? ""
|
|
704
|
+
return `${text.slice(0, range.start)}\n${indent}${unit}${entry}\n${indent}${text.slice(range.end)}`
|
|
705
|
+
}
|
|
706
|
+
const names = members.map((member): unknown => JSON.parse(member[1] ?? '""'))
|
|
707
|
+
const newline = body.lastIndexOf("\n", first.index)
|
|
708
|
+
const separator = newline === -1 ? " " : `\n${body.slice(newline + 1, first.index)}`
|
|
709
|
+
const sorted = names.every(
|
|
710
|
+
(current, index) =>
|
|
711
|
+
typeof current === "string" && (index === 0 || String(names[index - 1]) <= current),
|
|
712
|
+
)
|
|
713
|
+
const before = sorted ? members.find((_, index) => String(names[index]) > name) : undefined
|
|
714
|
+
const at = range.start + (before === undefined ? last.index + last[0].length : before.index)
|
|
715
|
+
const insert = before === undefined ? `,${separator}${entry}` : `${entry},${separator}`
|
|
716
|
+
return text.slice(0, at) + insert + text.slice(at)
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Add `rule.add` to a package.json text beside the first anchor it lists - the imported entry's own
|
|
721
|
+
* package, then each of `rule.beside` - in every field that anchor is in, with the anchor's range
|
|
722
|
+
* style; in `dependencies` when no anchor is listed. Undefined when the manifest already lists the
|
|
723
|
+
* package in any field, is that package, or the edit would not parse.
|
|
724
|
+
*/
|
|
725
|
+
export function addDependencyText(
|
|
726
|
+
text: string,
|
|
727
|
+
rule: DependencyAdd,
|
|
728
|
+
specifier: string,
|
|
729
|
+
version: string,
|
|
730
|
+
exact = false,
|
|
731
|
+
): { text: string; changes: Array<{ field: string; name: string; version: string }> } | undefined {
|
|
732
|
+
let parsed: unknown
|
|
733
|
+
try {
|
|
734
|
+
parsed = JSON.parse(text)
|
|
735
|
+
} catch {
|
|
736
|
+
return undefined
|
|
737
|
+
}
|
|
738
|
+
if (typeof parsed !== "object" || parsed === null) return undefined
|
|
739
|
+
const manifest: object = parsed
|
|
740
|
+
if (Reflect.get(manifest, "name") === rule.add) return undefined
|
|
741
|
+
const specIn = (from: object, field: string, name: string): string | undefined => {
|
|
742
|
+
const deps: unknown = Reflect.get(from, field)
|
|
743
|
+
if (typeof deps !== "object" || deps === null || !Object.hasOwn(deps, name)) return undefined
|
|
744
|
+
const spec: unknown = Reflect.get(deps, name)
|
|
745
|
+
return typeof spec === "string" ? spec : undefined
|
|
746
|
+
}
|
|
747
|
+
if (DEP_FIELDS.some((field) => specIn(manifest, field, rule.add) !== undefined)) return undefined
|
|
748
|
+
const fallback = exact ? version : `^${version}`
|
|
749
|
+
const rangeFor = (spec: string): string =>
|
|
750
|
+
rewriteVersionSpec(spec, version, exact) ?? (specVersion(spec) === version ? spec : fallback)
|
|
751
|
+
let placed: Array<{ field: string; name: string; version: string }> = []
|
|
752
|
+
for (const anchor of [packageOf(specifier), ...(rule.beside ?? [])]) {
|
|
753
|
+
placed = DEP_FIELDS.flatMap((field) => {
|
|
754
|
+
const spec = specIn(manifest, field, anchor)
|
|
755
|
+
return spec === undefined ? [] : [{ field, name: rule.add, version: rangeFor(spec) }]
|
|
756
|
+
})
|
|
757
|
+
if (placed.length > 0) break
|
|
758
|
+
}
|
|
759
|
+
if (placed.length === 0) placed = [{ field: "dependencies", name: rule.add, version: fallback }]
|
|
760
|
+
let out = text
|
|
761
|
+
for (const change of placed)
|
|
762
|
+
out = insertDependencyEntry(out, change.field, rule.add, change.version)
|
|
763
|
+
// The edit is textual; a result that does not parse, or lacks an entry, is never written.
|
|
764
|
+
let written: unknown
|
|
765
|
+
try {
|
|
766
|
+
written = JSON.parse(out)
|
|
767
|
+
} catch {
|
|
768
|
+
return undefined
|
|
769
|
+
}
|
|
770
|
+
if (typeof written !== "object" || written === null) return undefined
|
|
771
|
+
const result: object = written
|
|
772
|
+
if (placed.some((change) => specIn(result, change.field, rule.add) !== change.version))
|
|
773
|
+
return undefined
|
|
774
|
+
return { text: out, changes: placed }
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** The package.json nearest above `file`, both relative to `cwd`; undefined when none is under it. */
|
|
778
|
+
function nearestManifest(cwd: string, file: string): string | undefined {
|
|
779
|
+
for (let dir = dirname(file); ; dir = dirname(dir)) {
|
|
780
|
+
const manifest = dir === "." ? "package.json" : `${dir}/package.json`
|
|
781
|
+
if (plainFileAt(cwd, manifest)) return manifest
|
|
782
|
+
if (dir === ".") return undefined
|
|
783
|
+
}
|
|
784
|
+
}
|
|
635
785
|
const IGNORED_DIRECTORIES = new Set(["node_modules", "dist", "build", ".git", "coverage", ".next"])
|
|
636
786
|
|
|
637
787
|
// Any directory on the path counts, the top-level one included (`dist/index.js`). Bun's glob yields
|
|
@@ -650,7 +800,9 @@ function scan(cwd: string, pattern: string, dot = false): string[] {
|
|
|
650
800
|
for (const path of glob.scanSync({ cwd, dot, followSymlinks: false })) {
|
|
651
801
|
if (!isIgnored(path)) out.push(path.replaceAll("\\", "/"))
|
|
652
802
|
}
|
|
653
|
-
|
|
803
|
+
// A gitignored copy (a backup, a generated app) is not the project: never edited, never reported.
|
|
804
|
+
const ignored = gitIgnoredSync(cwd, out)
|
|
805
|
+
return (ignored.size === 0 ? out : out.filter((path) => !ignored.has(path))).sort()
|
|
654
806
|
}
|
|
655
807
|
|
|
656
808
|
// The fixed version group: every package released together at one version.
|
|
@@ -1153,6 +1305,7 @@ export function chainRecipes(target: string, installed: string | null): ChainedR
|
|
|
1153
1305
|
pins: [...pins].map(([match, to]) => ({ match, to })),
|
|
1154
1306
|
dependencyMoves: recipes.flatMap((recipe) => recipe.dependencyMoves ?? []),
|
|
1155
1307
|
importMoves: recipes.flatMap((recipe) => recipe.importMoves),
|
|
1308
|
+
dependencyAdds: recipes.flatMap((recipe) => recipe.dependencyAdds ?? []),
|
|
1156
1309
|
retiredMarkers: recipes.flatMap((recipe) => recipe.retiredMarkers ?? []),
|
|
1157
1310
|
notes: recipes.flatMap((recipe) =>
|
|
1158
1311
|
(recipe.notes ?? []).map((note) => `${recipe.version}: ${note}`),
|
|
@@ -1174,6 +1327,7 @@ export function computeUpgrade(
|
|
|
1174
1327
|
const planned = new Map<string, string>()
|
|
1175
1328
|
const dependencyMoves: DependencyMoveChange[] = []
|
|
1176
1329
|
const importMoves: ImportChange[] = []
|
|
1330
|
+
const dependencyAdds: DependencyAddChange[] = []
|
|
1177
1331
|
const downgrades: PinChange[] = []
|
|
1178
1332
|
const retiredMarkers: RetiredMarkerSite[] = []
|
|
1179
1333
|
const linkedOutside = installedGroupPackages(cwd)
|
|
@@ -1195,20 +1349,8 @@ export function computeUpgrade(
|
|
|
1195
1349
|
}
|
|
1196
1350
|
}
|
|
1197
1351
|
|
|
1198
|
-
// Read against the manifests as this upgrade leaves them
|
|
1352
|
+
// Read against the manifests as this upgrade leaves them.
|
|
1199
1353
|
const linkLocks = plainFileAt(cwd, BUN_LOCK) ? staleLinkLocks(resolve(cwd), manifests) : []
|
|
1200
|
-
let lockPruned = false
|
|
1201
|
-
if (write && linkLocks.length > 0) {
|
|
1202
|
-
const lockPath = join(cwd, BUN_LOCK)
|
|
1203
|
-
const pruned = pruneLinkLocks(
|
|
1204
|
-
readFileSync(lockPath, "utf8"),
|
|
1205
|
-
linkLocks.map((entry) => entry.package),
|
|
1206
|
-
)
|
|
1207
|
-
if (pruned !== undefined) {
|
|
1208
|
-
writeFileSync(lockPath, pruned)
|
|
1209
|
-
lockPruned = true
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
1354
|
|
|
1213
1355
|
for (const { change, text, abs } of agentPinEdits(cwd, recipe.version, above)) {
|
|
1214
1356
|
agentPins.push(change)
|
|
@@ -1216,17 +1358,41 @@ export function computeUpgrade(
|
|
|
1216
1358
|
if (write) writeFileSync(abs, Buffer.from(text, "latin1"))
|
|
1217
1359
|
}
|
|
1218
1360
|
|
|
1361
|
+
const movedSources = new Map<string, string>()
|
|
1219
1362
|
if (recipe.importMoves.length > 0) {
|
|
1220
1363
|
for (const rel of scan(cwd, SOURCE_GLOB)) {
|
|
1221
1364
|
const abs = join(cwd, rel)
|
|
1222
1365
|
const text = readFileSync(abs, "utf8")
|
|
1223
1366
|
const result = applyImportMoves(text, recipe.importMoves)
|
|
1224
1367
|
if (result.changes.length === 0) continue
|
|
1368
|
+
movedSources.set(rel, result.text)
|
|
1225
1369
|
for (const change of result.changes) importMoves.push({ file: rel, ...change })
|
|
1226
1370
|
if (write) writeFileSync(abs, result.text)
|
|
1227
1371
|
}
|
|
1228
1372
|
}
|
|
1229
1373
|
|
|
1374
|
+
// Read the sources as the import moves leave them, and each manifest as the pins left it.
|
|
1375
|
+
const adds = recipe.dependencyAdds ?? []
|
|
1376
|
+
if (adds.length > 0) {
|
|
1377
|
+
for (const rel of scan(cwd, ADD_SOURCE_GLOB)) {
|
|
1378
|
+
const source = movedSources.get(rel) ?? readFileSync(join(cwd, rel), "utf8")
|
|
1379
|
+
for (const rule of adds) {
|
|
1380
|
+
const specifier = importedSpecifier(source, rule.imports)
|
|
1381
|
+
if (specifier === undefined) continue
|
|
1382
|
+
const file = nearestManifest(cwd, rel)
|
|
1383
|
+
if (file === undefined) continue
|
|
1384
|
+
const abs = resolve(cwd, file)
|
|
1385
|
+
const current = manifests.get(abs) ?? readFileSync(abs, "utf8")
|
|
1386
|
+
const added = addDependencyText(current, rule, specifier, recipe.version, exact)
|
|
1387
|
+
if (added === undefined) continue
|
|
1388
|
+
manifests.set(abs, added.text)
|
|
1389
|
+
for (const change of added.changes)
|
|
1390
|
+
dependencyAdds.push({ file, ...change, importer: rel, specifier })
|
|
1391
|
+
if (write) writeFileSync(abs, added.text)
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1230
1396
|
// Read after the import moves, so a listed line number is the one the file has after `--write`.
|
|
1231
1397
|
const retired = recipe.retiredMarkers ?? []
|
|
1232
1398
|
if (retired.length > 0) {
|
|
@@ -1254,13 +1420,13 @@ export function computeUpgrade(
|
|
|
1254
1420
|
agentPins,
|
|
1255
1421
|
dependencyMoves,
|
|
1256
1422
|
importMoves,
|
|
1423
|
+
dependencyAdds,
|
|
1257
1424
|
downgrades,
|
|
1258
1425
|
retiredMarkers,
|
|
1259
1426
|
linkedOutside,
|
|
1260
1427
|
linkedSkew: linkedSkew(cwd, recipe.version),
|
|
1261
1428
|
strayPins: strayPins(cwd, recipe.version, planned),
|
|
1262
1429
|
linkLocks,
|
|
1263
|
-
lockPruned,
|
|
1264
1430
|
notes: recipe.notes ?? [],
|
|
1265
1431
|
unaffected: unaffectedReleases(
|
|
1266
1432
|
"steps" in recipe && Array.isArray(recipe.steps) ? recipe.steps : [recipe.version],
|
|
@@ -1292,6 +1458,7 @@ function renderPlan(
|
|
|
1292
1458
|
plan.agentPins.length === 0 &&
|
|
1293
1459
|
plan.dependencyMoves.length === 0 &&
|
|
1294
1460
|
plan.importMoves.length === 0 &&
|
|
1461
|
+
plan.dependencyAdds.length === 0 &&
|
|
1295
1462
|
plan.retiredMarkers.length === 0 &&
|
|
1296
1463
|
plan.linkedOutside.length === 0 &&
|
|
1297
1464
|
plan.linkedSkew.length === 0 &&
|
|
@@ -1330,6 +1497,15 @@ function renderPlan(
|
|
|
1330
1497
|
for (const m of plan.importMoves) lines.push(` ${m.file} ${m.from} → ${m.to} (${m.count})`)
|
|
1331
1498
|
lines.push("")
|
|
1332
1499
|
}
|
|
1500
|
+
if (plan.dependencyAdds.length > 0) {
|
|
1501
|
+
lines.push(`${verb} ${plan.dependencyAdds.length} dependency addition(s):`)
|
|
1502
|
+
for (const add of plan.dependencyAdds) {
|
|
1503
|
+
lines.push(
|
|
1504
|
+
` ${add.file} ${add.field}: ${add.name}@${add.version} (${add.importer} imports ${add.specifier})`,
|
|
1505
|
+
)
|
|
1506
|
+
}
|
|
1507
|
+
lines.push("")
|
|
1508
|
+
}
|
|
1333
1509
|
if (plan.retiredMarkers.length > 0) {
|
|
1334
1510
|
lines.push(
|
|
1335
1511
|
`${plan.retiredMarkers.length} retired comment(s) that silence nothing now; nifra check reports what each covered:`,
|
|
@@ -1371,20 +1547,15 @@ function renderPlan(
|
|
|
1371
1547
|
}
|
|
1372
1548
|
if (plan.linkLocks.length > 0) {
|
|
1373
1549
|
lines.push(
|
|
1374
|
-
plan.
|
|
1375
|
-
? `Dropped ${plan.linkLocks.length} file: package(s) from bun.lock, whose recorded dependencies Bun never refreshes; \`bun install\` reads each linked package.json again:`
|
|
1376
|
-
: write
|
|
1377
|
-
? `bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s), which Bun never refreshes; run \`${linkLockUpdate(plan.linkLocks)}\`:`
|
|
1378
|
-
: `bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s), which Bun never refreshes; --write drops them so \`bun install\` reads each linked package.json again:`,
|
|
1550
|
+
`bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s). ${write ? "Left as it is" : "--write leaves it as it is"}; run \`${linkLockUpdate(plan.linkLocks)}\`, which refreshes those entries and keeps every other pin:`,
|
|
1379
1551
|
)
|
|
1380
1552
|
for (const entry of plan.linkLocks)
|
|
1381
1553
|
lines.push(
|
|
1382
1554
|
` ${entry.package} (file:${entry.path}) ${entry.changes.map(describeChange).join(", ")}`,
|
|
1383
1555
|
)
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
)
|
|
1556
|
+
lines.push(
|
|
1557
|
+
" Bun records each linked package.json as it is on disk, uncommitted edits included: review the bun.lock diff before committing it.",
|
|
1558
|
+
)
|
|
1388
1559
|
lines.push("")
|
|
1389
1560
|
}
|
|
1390
1561
|
for (const note of plan.notes) lines.push(`note: ${note}`)
|
|
@@ -1463,14 +1634,14 @@ const INSTALL_COMMANDS: readonly (readonly [lockfile: string, command: string])[
|
|
|
1463
1634
|
|
|
1464
1635
|
/**
|
|
1465
1636
|
* Whether the project needs an install before a check can judge the target: `--write` changed what
|
|
1466
|
-
* package.json declares
|
|
1467
|
-
* version. A link from outside the root is left out; installing here does not move it.
|
|
1637
|
+
* package.json declares, or node_modules holds a group package at another version. A link from outside the root is left out; installing here does not move it.
|
|
1468
1638
|
*/
|
|
1469
1639
|
export function pendingInstall(cwd: string, plan: UpgradePlan): PendingInstall | undefined {
|
|
1470
1640
|
const installed = installedGroupPackages(cwd)
|
|
1471
1641
|
.filter((entry) => entry.inside && entry.version !== plan.version)
|
|
1472
1642
|
.map(({ package: name, version }) => ({ package: name, version }))
|
|
1473
|
-
const edited =
|
|
1643
|
+
const edited =
|
|
1644
|
+
plan.pins.length > 0 || plan.dependencyMoves.length > 0 || plan.dependencyAdds.length > 0
|
|
1474
1645
|
if (!edited && installed.length === 0) return undefined
|
|
1475
1646
|
const command =
|
|
1476
1647
|
INSTALL_COMMANDS.find(([lockfile]) => existsSync(join(cwd, lockfile)))?.[1] ?? "bun install"
|
|
@@ -1615,6 +1786,28 @@ function newerCliCommand(version: string, options: UpgradeOptions): string {
|
|
|
1615
1786
|
}
|
|
1616
1787
|
|
|
1617
1788
|
/** CLI entry. Returns false (→ non-zero exit) on an unknown version, no project, or a failed verify. */
|
|
1789
|
+
/** The contracts.lock.json routes that send a body but whose request side guards nothing. A release
|
|
1790
|
+
* that reads a body schema the installed one could not has `nifra check` report each as newly
|
|
1791
|
+
* covered. Read routes and response sides are left out: most declare no schema there. */
|
|
1792
|
+
async function uncoveredContracts(cwd: string): Promise<string[]> {
|
|
1793
|
+
const { blindLockEntries, DEFAULT_CONTRACTS_LOCK, parseContractsLock } = await import(
|
|
1794
|
+
"./contracts.ts"
|
|
1795
|
+
)
|
|
1796
|
+
try {
|
|
1797
|
+
const text = readFileSync(join(cwd, DEFAULT_CONTRACTS_LOCK), "utf8")
|
|
1798
|
+
return (await blindLockEntries(parseContractsLock(JSON.parse(text))))
|
|
1799
|
+
.filter(
|
|
1800
|
+
(entry) => entry.sides.includes("request") && !/^(?:GET|HEAD|OPTIONS) /.test(entry.route),
|
|
1801
|
+
)
|
|
1802
|
+
.map((entry) => entry.route)
|
|
1803
|
+
} catch {
|
|
1804
|
+
return []
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
const uncoveredContractsNote = (routes: readonly string[]): string =>
|
|
1809
|
+
`note: contracts.lock.json records no request schema for ${routes.slice(0, 3).join(", ")}${routes.length > 3 ? ` and ${routes.length - 3} more` : ""}. Where this release reads a schema the installed one could not, \`nifra check\` reports it as newly covered: review it, then run \`nifra contracts snapshot\`.`
|
|
1810
|
+
|
|
1618
1811
|
export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<boolean> {
|
|
1619
1812
|
const cliVersion = options.cliVersion ?? listRecipeVersions().at(-1) ?? "0.0.0"
|
|
1620
1813
|
const targets = upgradeTargets(cliVersion)
|
|
@@ -1726,9 +1919,11 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1726
1919
|
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
1727
1920
|
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
1728
1921
|
const verify = write && options.verify !== false && pending === undefined
|
|
1922
|
+
const uncovered = await uncoveredContracts(cwd)
|
|
1729
1923
|
if (options.json) {
|
|
1730
1924
|
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
1731
1925
|
const report: Record<string, unknown> = { ...plan, from, steps: recipe.steps, write }
|
|
1926
|
+
if (uncovered.length > 0) report.contractsUncovered = uncovered
|
|
1732
1927
|
if (hooks !== undefined) report.hooks = hooks
|
|
1733
1928
|
if (pending !== undefined) report.install = pending
|
|
1734
1929
|
let ok = true
|
|
@@ -1743,6 +1938,7 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1743
1938
|
return ok
|
|
1744
1939
|
}
|
|
1745
1940
|
console.log(renderPlan(plan, write, from, recipe.steps))
|
|
1941
|
+
if (uncovered.length > 0) console.log(uncoveredContractsNote(uncovered))
|
|
1746
1942
|
if (plan.linkedSkew.length > 0)
|
|
1747
1943
|
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`)
|
|
1748
1944
|
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
package/src/verification-plan.ts
CHANGED
|
@@ -163,6 +163,16 @@ const GATES = Object.freeze([
|
|
|
163
163
|
[["run", "check:workerd"]],
|
|
164
164
|
"Run `bun run check:workerd` and fix the real Workers runtime contract failure.",
|
|
165
165
|
),
|
|
166
|
+
gate(
|
|
167
|
+
"runtime-differential",
|
|
168
|
+
[["run", "check:runtime-differential"]],
|
|
169
|
+
"Run `bun run check:runtime-differential` and replay the printed shrunk case; fix the runtime or adapter that answered differently, or document the difference in scripts/runtime-differential/oracle.ts.",
|
|
170
|
+
),
|
|
171
|
+
gate(
|
|
172
|
+
"postgres-live",
|
|
173
|
+
[["run", "test:postgres"]],
|
|
174
|
+
"Set NIFRA_TEST_POSTGRES_URL to the superuser URL of a throwaway Postgres, run `bun run test:postgres` and fix the first failing live query; without the variable the suites skip.",
|
|
175
|
+
),
|
|
166
176
|
gate(
|
|
167
177
|
"pipeline-parity",
|
|
168
178
|
[["run", "check:pipeline-parity"]],
|
|
@@ -253,6 +263,8 @@ const RELEASE_PLAN = Object.freeze([
|
|
|
253
263
|
"cross-runtime-deno",
|
|
254
264
|
"cross-runtime-node",
|
|
255
265
|
"workerd",
|
|
266
|
+
"runtime-differential",
|
|
267
|
+
"postgres-live",
|
|
256
268
|
"pipeline-parity",
|
|
257
269
|
"leak-matrix",
|
|
258
270
|
"verification-parity",
|
|
@@ -293,7 +305,14 @@ const RELEASE_GROUPS: Readonly<Record<string, readonly string[]>> = Object.freez
|
|
|
293
305
|
"edge-startup",
|
|
294
306
|
],
|
|
295
307
|
packages: ["build", "publish", "consumer", "cold-start"],
|
|
296
|
-
runtimes: [
|
|
308
|
+
runtimes: [
|
|
309
|
+
"build",
|
|
310
|
+
"cross-runtime-deno",
|
|
311
|
+
"cross-runtime-node",
|
|
312
|
+
"workerd",
|
|
313
|
+
"runtime-differential",
|
|
314
|
+
"postgres-live",
|
|
315
|
+
],
|
|
297
316
|
pipelines: ["build", "pipeline-parity", "leak-matrix"],
|
|
298
317
|
"server-components": [
|
|
299
318
|
"build",
|