@nifrajs/cli 5.2.0 → 5.3.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 +102 -0
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +6 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +2 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +9 -3
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +61 -24
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +3 -3
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +22 -14
- package/dist/cli.js.map +1 -1
- package/dist/db-tool.d.ts.map +1 -1
- package/dist/db-tool.js +2 -1
- package/dist/db-tool.js.map +1 -1
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +41 -8
- package/dist/env-file.js.map +1 -1
- package/dist/internal/source-facts.d.ts +20 -4
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +248 -32
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +11 -3
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +23 -3
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +59 -12
- 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/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +1 -0
- package/dist/migrate-layout.js.map +1 -1
- package/dist/recipes/5.3.0.d.ts +11 -0
- package/dist/recipes/5.3.0.d.ts.map +1 -0
- package/dist/recipes/5.3.0.js +35 -0
- package/dist/recipes/5.3.0.js.map +1 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +12 -2
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/pages.d.ts +25 -1
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +149 -33
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/route-statement.d.ts +10 -0
- package/dist/rules/route-statement.d.ts.map +1 -0
- package/dist/rules/route-statement.js +150 -0
- package/dist/rules/route-statement.js.map +1 -0
- package/dist/upgrade.d.ts +43 -10
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +161 -45
- package/dist/upgrade.js.map +1 -1
- package/docs/llms-full.txt +96 -13
- package/docs/types.json +124 -28
- package/package.json +11 -11
- package/src/assure-hydration.ts +7 -1
- package/src/check-diagnostics.ts +2 -0
- package/src/check-scan.ts +64 -25
- package/src/check.ts +8 -3
- package/src/cli.ts +22 -14
- package/src/db-tool.ts +2 -0
- package/src/env-file.ts +42 -7
- package/src/internal/source-facts.ts +312 -39
- package/src/mcp-exec.ts +13 -2
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +72 -12
- package/src/mcp-isolate.ts +2 -0
- package/src/migrate-layout.ts +1 -0
- package/src/recipes/5.3.0.ts +36 -0
- package/src/recipes/index.ts +2 -0
- package/src/review.ts +2 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/explanations.ts +12 -2
- package/src/rules/pages.ts +193 -33
- package/src/rules/route-statement.ts +170 -0
- package/src/upgrade.ts +202 -47
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. **verify** - reuse the existing `nifra check` gate; no new verification surface.
|
|
15
|
+
* 4. **verify** - reuse the existing `nifra check` gate; no new verification surface. It reads the
|
|
16
|
+
* installed packages, so while the edited pins are not installed yet it is skipped with the
|
|
17
|
+
* install command to run first: a check then would judge the release being left.
|
|
16
18
|
*
|
|
17
19
|
* Upgrading across several releases runs every recipe between the installed version (the lowest
|
|
18
20
|
* fixed-group version the workspace declares) and the target, oldest first, then pins the target. A
|
|
@@ -69,7 +71,8 @@ export interface UpgradeOptions {
|
|
|
69
71
|
readonly json?: boolean
|
|
70
72
|
/** Print the available target versions and return. */
|
|
71
73
|
readonly list?: boolean
|
|
72
|
-
/** After `--write`, run `nifra check` and fail the command if it fails
|
|
74
|
+
/** After `--write`, run `nifra check` and fail the command if it fails, once the install matches
|
|
75
|
+
* the target; until then, print the install command to run first. Default true. */
|
|
73
76
|
readonly verify?: boolean
|
|
74
77
|
/** Permit a target BELOW the installed version (a rollback). Default false → fail-closed. */
|
|
75
78
|
readonly allowDowngrade?: boolean
|
|
@@ -162,21 +165,29 @@ const DEP_FIELDS = [
|
|
|
162
165
|
"peerDependencies",
|
|
163
166
|
"optionalDependencies",
|
|
164
167
|
] as const
|
|
168
|
+
const PEER_FIELD = "peerDependencies"
|
|
165
169
|
|
|
166
170
|
// Only a bare semver spec is rewritten. Anything else - workspace:*, link:/file:, npm: aliases, git
|
|
167
171
|
// urls, "*", "latest", or a multi-part range - is intentionally left untouched (skipped, not guessed).
|
|
168
172
|
const SEMVER_SPEC =
|
|
169
173
|
/^([\^~]|>=|<=|>|<|=)?\s*(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/
|
|
170
174
|
|
|
175
|
+
const UPPER_BOUND = /^\s*<=?/
|
|
176
|
+
|
|
177
|
+
// A strict bound kept on the target would exclude it: `>5.2.0` → `>5.3.0` refuses 5.3.0.
|
|
178
|
+
const INCLUSIVE_OPERATOR: Readonly<Record<string, string>> = { ">": ">=", "<": "<=" }
|
|
179
|
+
|
|
171
180
|
/**
|
|
172
|
-
* Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`,
|
|
173
|
-
*
|
|
174
|
-
* already equals the
|
|
181
|
+
* Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`, …;
|
|
182
|
+
* a strict `>` or `<` becomes `>=` or `<=`, so the result admits the target), or dropping it when
|
|
183
|
+
* `exact`. Returns null when the spec is not a plain semver spec (→ skip it) or already equals the
|
|
184
|
+
* target.
|
|
175
185
|
*/
|
|
176
186
|
export function rewriteVersionSpec(spec: string, toVersion: string, exact = false): string | null {
|
|
177
187
|
const match = SEMVER_SPEC.exec(spec.trim())
|
|
178
188
|
if (!match) return null
|
|
179
|
-
const
|
|
189
|
+
const written = match[1] ?? ""
|
|
190
|
+
const operator = exact ? "" : (INCLUSIVE_OPERATOR[written] ?? written)
|
|
180
191
|
const next = `${operator}${toVersion}`
|
|
181
192
|
return next === spec ? null : next
|
|
182
193
|
}
|
|
@@ -252,6 +263,48 @@ export function compareSemverSpec(a: string, b: string): number {
|
|
|
252
263
|
return 0
|
|
253
264
|
}
|
|
254
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Whether a plain semver spec's range admits `version`, as npm reads it: `^` and `~` stop before the
|
|
268
|
+
* next breaking release, and a prerelease satisfies only a spec naming a prerelease of its own core.
|
|
269
|
+
* False for any other spec.
|
|
270
|
+
*/
|
|
271
|
+
export function specIncludes(spec: string, version: string): boolean {
|
|
272
|
+
const match = SEMVER_SPEC.exec(spec.trim())
|
|
273
|
+
const target = parseSpecVersion(version)
|
|
274
|
+
const floor = specVersion(spec)
|
|
275
|
+
if (match === null || target === null || floor === null) return false
|
|
276
|
+
const core: readonly [number, number, number] = [
|
|
277
|
+
Number(match[2]),
|
|
278
|
+
Number(match[3]),
|
|
279
|
+
Number(match[4]),
|
|
280
|
+
]
|
|
281
|
+
if (
|
|
282
|
+
target.prerelease.length > 0 &&
|
|
283
|
+
(match[5] === undefined || compareSemverCore(core, target.core) !== 0)
|
|
284
|
+
)
|
|
285
|
+
return false
|
|
286
|
+
const order = compareSemverSpec(version, floor)
|
|
287
|
+
switch (match[1]) {
|
|
288
|
+
case ">=":
|
|
289
|
+
return order >= 0
|
|
290
|
+
case ">":
|
|
291
|
+
return order > 0
|
|
292
|
+
case "<=":
|
|
293
|
+
return order <= 0
|
|
294
|
+
case "<":
|
|
295
|
+
return order < 0
|
|
296
|
+
case "^": {
|
|
297
|
+
const below: readonly [number, number, number] =
|
|
298
|
+
core[0] > 0 ? [core[0] + 1, 0, 0] : core[1] > 0 ? [0, core[1] + 1, 0] : [0, 0, core[2] + 1]
|
|
299
|
+
return order >= 0 && compareSemverCore(target.core, below) < 0
|
|
300
|
+
}
|
|
301
|
+
case "~":
|
|
302
|
+
return order >= 0 && compareSemverCore(target.core, [core[0], core[1] + 1, 0]) < 0
|
|
303
|
+
default:
|
|
304
|
+
return order === 0
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
255
308
|
const escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
256
309
|
|
|
257
310
|
/**
|
|
@@ -278,13 +331,21 @@ export function pinSweepText(
|
|
|
278
331
|
let out = text
|
|
279
332
|
const changes: Array<Omit<PinChange, "file">> = []
|
|
280
333
|
const downgrades: Array<Omit<PinChange, "file">> = []
|
|
281
|
-
for (const { path, key, target: name, spec: rawSpec } of pinEntries(parsed)) {
|
|
334
|
+
for (const { path, holder, key, target: name, spec: rawSpec } of pinEntries(parsed)) {
|
|
282
335
|
const field = path.join(".")
|
|
283
336
|
const rule = rules.find(
|
|
284
337
|
(r) => name === r.match || (r.match.endsWith("/") && name.startsWith(r.match)),
|
|
285
338
|
)
|
|
286
339
|
if (!rule) continue
|
|
287
|
-
|
|
340
|
+
// A peer range states what a library accepts, not what installs: widening a floor that already
|
|
341
|
+
// admits the target would drop every consumer still on an older release, and an exact peer pin
|
|
342
|
+
// would admit one release only.
|
|
343
|
+
const peer = field === PEER_FIELD
|
|
344
|
+
if (peer && specIncludes(rawSpec, rule.to)) continue
|
|
345
|
+
// An upper bound has no floor to raise: one that admits the target (`<6.0.0`) stays as written,
|
|
346
|
+
// in every field, and is never read as a rollback.
|
|
347
|
+
if (UPPER_BOUND.test(rawSpec) && specIncludes(rawSpec, rule.to)) continue
|
|
348
|
+
const next = rewriteVersionSpec(rawSpec, rule.to, exact && !peer)
|
|
288
349
|
if (next === null) continue
|
|
289
350
|
// Refuse a rollback: `upgrade <version>` pins an exact target, so an OLD target on a newer install
|
|
290
351
|
// walks dependencies backward (e.g. ^2.3.0 → ^2.0.0) and can break a shared-package peer range.
|
|
@@ -299,17 +360,14 @@ export function pinSweepText(
|
|
|
299
360
|
downgrades.push({ field, name: key, from: rawSpec, to: next })
|
|
300
361
|
continue
|
|
301
362
|
}
|
|
302
|
-
// Replace exactly `"key"<ws>:<ws>"spec"` inside this
|
|
303
|
-
// nested `
|
|
304
|
-
const range = objectRangeAt(out,
|
|
305
|
-
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
out = out.slice(0, range.start) + replaced + out.slice(range.end)
|
|
311
|
-
changes.push({ field, name: key, from: rawSpec, to: next })
|
|
312
|
-
}
|
|
363
|
+
// Replace exactly `"key"<ws>:<ws>"spec"` inside the object holding this pin, preserving the
|
|
364
|
+
// whitespace: npm's nested `{ ".": "5.2.0" }` under another package names that package.
|
|
365
|
+
const range = objectRangeAt(out, holder)
|
|
366
|
+
const at = range === undefined ? undefined : memberValueAt(out, range, key)
|
|
367
|
+
const written = JSON.stringify(rawSpec)
|
|
368
|
+
if (at === undefined || out.slice(at, at + written.length) !== written) continue
|
|
369
|
+
out = out.slice(0, at) + JSON.stringify(next) + out.slice(at + written.length)
|
|
370
|
+
changes.push({ field, name: key, from: rawSpec, to: next })
|
|
313
371
|
}
|
|
314
372
|
return { text: out, changes, downgrades }
|
|
315
373
|
}
|
|
@@ -332,31 +390,41 @@ function overrideTarget(key: string): string {
|
|
|
332
390
|
}
|
|
333
391
|
|
|
334
392
|
/** Every string version spec a package.json declares for a package, with the field path it sits in. */
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
393
|
+
interface PinEntry {
|
|
394
|
+
/** The field the pin is reported under: a dependency field, or the override field it sits in. */
|
|
395
|
+
readonly path: readonly string[]
|
|
396
|
+
/** The object holding the pin, nested override parents included. */
|
|
397
|
+
readonly holder: readonly string[]
|
|
398
|
+
readonly key: string
|
|
399
|
+
readonly target: string
|
|
400
|
+
readonly spec: string
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function pinEntries(parsed: Record<string, unknown>): PinEntry[] {
|
|
404
|
+
const entries: PinEntry[] = []
|
|
339
405
|
for (const field of DEP_FIELDS) {
|
|
340
406
|
const deps = parsed[field]
|
|
341
407
|
if (typeof deps !== "object" || deps === null) continue
|
|
342
408
|
for (const [name, spec] of Object.entries(deps))
|
|
343
|
-
if (typeof spec === "string")
|
|
409
|
+
if (typeof spec === "string")
|
|
410
|
+
entries.push({ path: [field], holder: [field], key: name, target: name, spec })
|
|
344
411
|
}
|
|
345
412
|
for (const path of OVERRIDE_FIELDS) {
|
|
346
413
|
let value: unknown = parsed
|
|
347
414
|
for (const key of path)
|
|
348
415
|
value = typeof value === "object" && value !== null ? Reflect.get(value, key) : undefined
|
|
349
416
|
// npm nests an override under the package whose dependency it pins; `.` pins that package itself.
|
|
350
|
-
const walk = (object: object, parent: string | undefined): void => {
|
|
417
|
+
const walk = (object: object, parent: string | undefined, holder: readonly string[]): void => {
|
|
351
418
|
for (const [key, spec] of Object.entries(object)) {
|
|
352
419
|
const target = key === "." ? parent : overrideTarget(key)
|
|
353
420
|
if (typeof spec === "string" && target !== undefined)
|
|
354
|
-
entries.push({ path, key, target, spec })
|
|
421
|
+
entries.push({ path, holder, key, target, spec })
|
|
355
422
|
else if (typeof spec === "object" && spec !== null && !Array.isArray(spec))
|
|
356
|
-
walk(spec, target)
|
|
423
|
+
walk(spec, target, [...holder, key])
|
|
357
424
|
}
|
|
358
425
|
}
|
|
359
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value))
|
|
426
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value))
|
|
427
|
+
walk(value, undefined, path)
|
|
360
428
|
}
|
|
361
429
|
return entries
|
|
362
430
|
}
|
|
@@ -407,6 +475,18 @@ function memberObjectRange(
|
|
|
407
475
|
within: { start: number; end: number },
|
|
408
476
|
key: string,
|
|
409
477
|
): { start: number; end: number } | undefined {
|
|
478
|
+
const at = memberValueAt(text, within, key)
|
|
479
|
+
return at !== undefined && text[at] === "{"
|
|
480
|
+
? { start: at + 1, end: closingBrace(text, at) }
|
|
481
|
+
: undefined
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Where `key`'s value starts among the direct members of the object body `within`. */
|
|
485
|
+
function memberValueAt(
|
|
486
|
+
text: string,
|
|
487
|
+
within: { start: number; end: number },
|
|
488
|
+
key: string,
|
|
489
|
+
): number | undefined {
|
|
410
490
|
let depth = 0
|
|
411
491
|
for (let index = within.start; index < within.end; index++) {
|
|
412
492
|
const char = text[index]
|
|
@@ -419,9 +499,7 @@ function memberObjectRange(
|
|
|
419
499
|
if (depth === 0 && text[after] === ":" && text.slice(index + 1, close) === key) {
|
|
420
500
|
after++
|
|
421
501
|
while (/\s/.test(text[after] ?? "")) after++
|
|
422
|
-
return
|
|
423
|
-
? { start: after + 1, end: closingBrace(text, after) }
|
|
424
|
-
: undefined
|
|
502
|
+
return after
|
|
425
503
|
}
|
|
426
504
|
index = close
|
|
427
505
|
}
|
|
@@ -598,10 +676,15 @@ export function groupDeclaredNames(cwd: string): ReadonlySet<string> {
|
|
|
598
676
|
|
|
599
677
|
/**
|
|
600
678
|
* Every fixed-group version the package.json files under `cwd` declare with a plain semver spec, each
|
|
601
|
-
* with the files that declare it. An override counts: it decides what installs.
|
|
602
|
-
*
|
|
679
|
+
* with the files that declare it. An override counts: it decides what installs. A peer range does
|
|
680
|
+
* not (`>=3.1.0` names a floor a library accepts, not a version anything loads), and `workspace:`,
|
|
681
|
+
* `link:` and other non-semver specs are not versions.
|
|
603
682
|
*/
|
|
604
683
|
export function groupPinVersions(cwd: string): ReadonlyMap<string, readonly string[]> {
|
|
684
|
+
return groupSpecVersions(cwd, false)
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function groupSpecVersions(cwd: string, peers: boolean): Map<string, string[]> {
|
|
605
688
|
const versions = new Map<string, string[]>()
|
|
606
689
|
for (const rel of scan(cwd, "**/package.json")) {
|
|
607
690
|
let parsed: Record<string, unknown>
|
|
@@ -610,8 +693,8 @@ export function groupPinVersions(cwd: string): ReadonlyMap<string, readonly stri
|
|
|
610
693
|
} catch {
|
|
611
694
|
continue
|
|
612
695
|
}
|
|
613
|
-
for (const { target, spec } of pinEntries(parsed)) {
|
|
614
|
-
if (!isFixedGroup(target)) continue
|
|
696
|
+
for (const { path, target, spec } of pinEntries(parsed)) {
|
|
697
|
+
if (!isFixedGroup(target) || (path[0] === PEER_FIELD) !== peers) continue
|
|
615
698
|
const version = specVersion(spec)
|
|
616
699
|
if (version === null) continue
|
|
617
700
|
const files = versions.get(version) ?? []
|
|
@@ -860,15 +943,27 @@ export function installedGroupPackages(
|
|
|
860
943
|
}
|
|
861
944
|
|
|
862
945
|
/**
|
|
863
|
-
* The lowest fixed-group version any package.json under
|
|
864
|
-
*
|
|
946
|
+
* The version the workspace upgrades from: the lowest fixed-group version any package.json under
|
|
947
|
+
* `cwd` pins ({@link groupPinVersions}), since recipes newer than it still have edits to make
|
|
948
|
+
* somewhere. Without a pin, the lowest one installed inside the root, then the lowest peer floor;
|
|
949
|
+
* null when none names one.
|
|
865
950
|
*/
|
|
866
951
|
export function installedGroupVersion(cwd: string): string | null {
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
952
|
+
const lowest = (versions: Iterable<string>): string | null => {
|
|
953
|
+
let found: string | null = null
|
|
954
|
+
for (const version of versions)
|
|
955
|
+
if (found === null || compareSemverSpec(version, found) < 0) found = version
|
|
956
|
+
return found
|
|
870
957
|
}
|
|
871
|
-
return
|
|
958
|
+
return (
|
|
959
|
+
lowest(groupPinVersions(cwd).keys()) ??
|
|
960
|
+
lowest(
|
|
961
|
+
installedGroupPackages(cwd)
|
|
962
|
+
.filter((entry) => entry.inside)
|
|
963
|
+
.map((entry) => entry.version),
|
|
964
|
+
) ??
|
|
965
|
+
lowest(groupSpecVersions(cwd, true).keys())
|
|
966
|
+
)
|
|
872
967
|
}
|
|
873
968
|
|
|
874
969
|
/** One recipe that applies every release recipe after `installed` up to `target`, oldest first. */
|
|
@@ -1133,7 +1228,7 @@ function renderPlan(
|
|
|
1133
1228
|
lines.push("")
|
|
1134
1229
|
}
|
|
1135
1230
|
for (const note of plan.notes) lines.push(`note: ${note}`)
|
|
1136
|
-
if (!write) lines.push("\nRe-run with --write to apply, then nifra check
|
|
1231
|
+
if (!write) lines.push("\nRe-run with --write to apply, then install and run nifra check.")
|
|
1137
1232
|
return lines.join("\n").trimEnd()
|
|
1138
1233
|
}
|
|
1139
1234
|
|
|
@@ -1174,11 +1269,61 @@ function renderDowngradeRefusal(version: string, downgrades: readonly PinChange[
|
|
|
1174
1269
|
].join("\n")
|
|
1175
1270
|
}
|
|
1176
1271
|
|
|
1177
|
-
/** The hook report around `--write`: the diff and where the pre-upgrade report was saved, or why not.
|
|
1272
|
+
/** The hook report around `--write`: the diff and where the pre-upgrade report was saved, or why not.
|
|
1273
|
+
* `install` means the edits are not installed yet, so only the pre-upgrade report was taken. */
|
|
1178
1274
|
export type UpgradeHookScope =
|
|
1179
1275
|
| { readonly saved: string; readonly changes: readonly HookReportChange[] }
|
|
1276
|
+
| { readonly saved: string; readonly pending: "install" }
|
|
1180
1277
|
| { readonly error: string; readonly saved?: string }
|
|
1181
1278
|
|
|
1279
|
+
/** The edits `--write` made that the installed packages do not reflect yet. */
|
|
1280
|
+
export interface PendingInstall {
|
|
1281
|
+
/** The command that installs them, by the lockfile the project keeps. */
|
|
1282
|
+
readonly command: string
|
|
1283
|
+
/** Fixed-group packages installed inside the root at a version other than the target. */
|
|
1284
|
+
readonly installed: readonly { readonly package: string; readonly version: string }[]
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
const INSTALL_COMMANDS: readonly (readonly [lockfile: string, command: string])[] = [
|
|
1288
|
+
["pnpm-lock.yaml", "pnpm install"],
|
|
1289
|
+
["yarn.lock", "yarn install"],
|
|
1290
|
+
["package-lock.json", "npm install"],
|
|
1291
|
+
]
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Whether the project needs an install before a check can judge the target: `--write` changed what
|
|
1295
|
+
* package.json declares or what bun.lock records, or node_modules holds a group package at another
|
|
1296
|
+
* version. A link from outside the root is left out; installing here does not move it.
|
|
1297
|
+
*/
|
|
1298
|
+
export function pendingInstall(cwd: string, plan: UpgradePlan): PendingInstall | undefined {
|
|
1299
|
+
const installed = installedGroupPackages(cwd)
|
|
1300
|
+
.filter((entry) => entry.inside && entry.version !== plan.version)
|
|
1301
|
+
.map(({ package: name, version }) => ({ package: name, version }))
|
|
1302
|
+
const edited = plan.pins.length > 0 || plan.dependencyMoves.length > 0 || plan.lockPruned
|
|
1303
|
+
if (!edited && installed.length === 0) return undefined
|
|
1304
|
+
const command =
|
|
1305
|
+
INSTALL_COMMANDS.find(([lockfile]) => existsSync(join(cwd, lockfile)))?.[1] ?? "bun install"
|
|
1306
|
+
return { command, installed }
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
const SHOWN_INSTALLS = 3
|
|
1310
|
+
|
|
1311
|
+
function renderPendingInstall(pending: PendingInstall, version: string): string {
|
|
1312
|
+
const shown = pending.installed
|
|
1313
|
+
.slice(0, SHOWN_INSTALLS)
|
|
1314
|
+
.map((entry) => `${entry.package} ${entry.version}`)
|
|
1315
|
+
const more = pending.installed.length - shown.length
|
|
1316
|
+
const holds =
|
|
1317
|
+
shown.length === 0
|
|
1318
|
+
? "the edited pins are not installed yet"
|
|
1319
|
+
: `node_modules still holds ${shown.join(", ")}${more > 0 ? ` and ${more} more` : ""}`
|
|
1320
|
+
return [
|
|
1321
|
+
`Not checked yet: \`nifra check\` reads the installed packages, and ${holds}, so it would judge the release this upgrade leaves rather than ${version}. Install, then check:`,
|
|
1322
|
+
` ${pending.command}`,
|
|
1323
|
+
" nifra check",
|
|
1324
|
+
].join("\n")
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1182
1327
|
async function hookReportBefore(cwd: string): Promise<ReflectedHookReport | { error: string }> {
|
|
1183
1328
|
try {
|
|
1184
1329
|
const { loadBackendApp } = await import("./load.ts")
|
|
@@ -1190,15 +1335,18 @@ async function hookReportBefore(cwd: string): Promise<ReflectedHookReport | { er
|
|
|
1190
1335
|
}
|
|
1191
1336
|
|
|
1192
1337
|
/** The report after the edits, from a fresh process: the edited sources must not come from this one's
|
|
1193
|
-
* module cache. Saves the pre-upgrade report for `nifra routes --hooks --since` after an install.
|
|
1338
|
+
* module cache. Saves the pre-upgrade report for `nifra routes --hooks --since` after an install.
|
|
1339
|
+
* While the edits are not installed, the old release would load in its place, so none is taken. */
|
|
1194
1340
|
async function hookScopeAcross(
|
|
1195
1341
|
cwd: string,
|
|
1196
1342
|
before: ReflectedHookReport | { error: string },
|
|
1343
|
+
installed: boolean,
|
|
1197
1344
|
): Promise<UpgradeHookScope> {
|
|
1198
1345
|
if ("error" in before) return { error: before.error }
|
|
1199
1346
|
const saved = join(cwd, HOOKS_BEFORE_UPGRADE_FILE)
|
|
1200
1347
|
mkdirSync(dirname(saved), { recursive: true })
|
|
1201
1348
|
writeFileSync(saved, `${JSON.stringify(before, null, 2)}\n`)
|
|
1349
|
+
if (!installed) return { saved: HOOKS_BEFORE_UPGRADE_FILE, pending: "install" }
|
|
1202
1350
|
const entry = fileURLToPath(
|
|
1203
1351
|
new URL(import.meta.url.endsWith(".ts") ? "./cli.ts" : "./cli.js", import.meta.url),
|
|
1204
1352
|
)
|
|
@@ -1232,6 +1380,7 @@ function renderHookScope(scope: UpgradeHookScope): string {
|
|
|
1232
1380
|
const head = `Hook scope: not captured (${scope.error}).`
|
|
1233
1381
|
return scope.saved === undefined ? head : [head, ...since(scope.saved)].join("\n")
|
|
1234
1382
|
}
|
|
1383
|
+
if ("pending" in scope) return since(scope.saved).join("\n")
|
|
1235
1384
|
return [
|
|
1236
1385
|
"Hook scope across the edits (nifra routes --hooks):",
|
|
1237
1386
|
renderHookDiff(scope.changes)
|
|
@@ -1392,14 +1541,18 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1392
1541
|
const captureHooks = write && options.hooks !== false
|
|
1393
1542
|
const before = captureHooks ? await hookReportBefore(cwd) : undefined
|
|
1394
1543
|
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact, above) : preview
|
|
1395
|
-
const
|
|
1544
|
+
const pending = write ? pendingInstall(cwd, plan) : undefined
|
|
1545
|
+
const hooks =
|
|
1546
|
+
before === undefined ? undefined : await hookScopeAcross(cwd, before, pending === undefined)
|
|
1396
1547
|
|
|
1397
|
-
// Verify only makes sense once edits are on disk. Default on after --write; opt out
|
|
1398
|
-
|
|
1548
|
+
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
1549
|
+
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
1550
|
+
const verify = write && options.verify !== false && pending === undefined
|
|
1399
1551
|
if (options.json) {
|
|
1400
1552
|
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
1401
1553
|
const report: Record<string, unknown> = { ...plan, from, steps: recipe.steps, write }
|
|
1402
1554
|
if (hooks !== undefined) report.hooks = hooks
|
|
1555
|
+
if (pending !== undefined) report.install = pending
|
|
1403
1556
|
let ok = true
|
|
1404
1557
|
if (verify) {
|
|
1405
1558
|
const { collectProjectVerification } = await import("./verification.ts")
|
|
@@ -1415,6 +1568,8 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1415
1568
|
if (plan.linkedSkew.length > 0)
|
|
1416
1569
|
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`)
|
|
1417
1570
|
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
|
1571
|
+
if (pending !== undefined && options.verify !== false)
|
|
1572
|
+
console.log(`\n${renderPendingInstall(pending, recipe.version)}`)
|
|
1418
1573
|
|
|
1419
1574
|
if (verify) {
|
|
1420
1575
|
const { runCheck } = await import("./check.ts")
|