@nifrajs/cli 5.2.0 → 5.4.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 +125 -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/5.4.0.d.ts +10 -0
- package/dist/recipes/5.4.0.d.ts.map +1 -0
- package/dist/recipes/5.4.0.js +25 -0
- package/dist/recipes/5.4.0.js.map +1 -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 +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 +508 -190
- package/docs/types.json +217 -31
- 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/5.4.0.ts +26 -0
- package/src/recipes/index.ts +4 -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/dist/upgrade.d.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
|
|
@@ -38,7 +40,8 @@ export interface UpgradeOptions {
|
|
|
38
40
|
readonly json?: boolean;
|
|
39
41
|
/** Print the available target versions and return. */
|
|
40
42
|
readonly list?: boolean;
|
|
41
|
-
/** After `--write`, run `nifra check` and fail the command if it fails
|
|
43
|
+
/** After `--write`, run `nifra check` and fail the command if it fails, once the install matches
|
|
44
|
+
* the target; until then, print the install command to run first. Default true. */
|
|
42
45
|
readonly verify?: boolean;
|
|
43
46
|
/** Permit a target BELOW the installed version (a rollback). Default false → fail-closed. */
|
|
44
47
|
readonly allowDowngrade?: boolean;
|
|
@@ -122,9 +125,10 @@ export interface UpgradePlan {
|
|
|
122
125
|
readonly notes: readonly string[];
|
|
123
126
|
}
|
|
124
127
|
/**
|
|
125
|
-
* Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`,
|
|
126
|
-
*
|
|
127
|
-
* already equals the
|
|
128
|
+
* Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`, …;
|
|
129
|
+
* a strict `>` or `<` becomes `>=` or `<=`, so the result admits the target), or dropping it when
|
|
130
|
+
* `exact`. Returns null when the spec is not a plain semver spec (→ skip it) or already equals the
|
|
131
|
+
* target.
|
|
128
132
|
*/
|
|
129
133
|
export declare function rewriteVersionSpec(spec: string, toVersion: string, exact?: boolean): string | null;
|
|
130
134
|
/** The version a plain semver spec names (`^2.4.1` → `2.4.1`), or null for any other spec. */
|
|
@@ -135,6 +139,12 @@ export declare function specVersionTuple(spec: string): readonly [number, number
|
|
|
135
139
|
export declare function compareSemverCore(a: readonly [number, number, number], b: readonly [number, number, number]): number;
|
|
136
140
|
/** Compare full semver precedence, including prereleases (`2.3.0-beta` < `2.3.0`). */
|
|
137
141
|
export declare function compareSemverSpec(a: string, b: string): number;
|
|
142
|
+
/**
|
|
143
|
+
* Whether a plain semver spec's range admits `version`, as npm reads it: `^` and `~` stop before the
|
|
144
|
+
* next breaking release, and a prerelease satisfies only a spec naming a prerelease of its own core.
|
|
145
|
+
* False for any other spec.
|
|
146
|
+
*/
|
|
147
|
+
export declare function specIncludes(spec: string, version: string): boolean;
|
|
138
148
|
/**
|
|
139
149
|
* Apply pin rules to one package.json's TEXT (format-preserving - targeted string replaces, never a
|
|
140
150
|
* JSON re-serialize that would reorder keys or drop comments-as-formatting). Returns the new text and
|
|
@@ -174,8 +184,9 @@ export declare const isFixedGroup: (name: string) => boolean;
|
|
|
174
184
|
export declare function groupDeclaredNames(cwd: string): ReadonlySet<string>;
|
|
175
185
|
/**
|
|
176
186
|
* Every fixed-group version the package.json files under `cwd` declare with a plain semver spec, each
|
|
177
|
-
* with the files that declare it. An override counts: it decides what installs.
|
|
178
|
-
*
|
|
187
|
+
* with the files that declare it. An override counts: it decides what installs. A peer range does
|
|
188
|
+
* not (`>=3.1.0` names a floor a library accepts, not a version anything loads), and `workspace:`,
|
|
189
|
+
* `link:` and other non-semver specs are not versions.
|
|
179
190
|
*/
|
|
180
191
|
export declare function groupPinVersions(cwd: string): ReadonlyMap<string, readonly string[]>;
|
|
181
192
|
/** A fixed-group version spelled outside package.json, which the upgrade lists and never edits. */
|
|
@@ -232,8 +243,10 @@ export declare function installedGroupPackages(cwd: string): readonly (LinkedGro
|
|
|
232
243
|
readonly inside: boolean;
|
|
233
244
|
})[];
|
|
234
245
|
/**
|
|
235
|
-
* The lowest fixed-group version any package.json under
|
|
236
|
-
*
|
|
246
|
+
* The version the workspace upgrades from: the lowest fixed-group version any package.json under
|
|
247
|
+
* `cwd` pins ({@link groupPinVersions}), since recipes newer than it still have edits to make
|
|
248
|
+
* somewhere. Without a pin, the lowest one installed inside the root, then the lowest peer floor;
|
|
249
|
+
* null when none names one.
|
|
237
250
|
*/
|
|
238
251
|
export declare function installedGroupVersion(cwd: string): string | null;
|
|
239
252
|
/** One recipe that applies every release recipe after `installed` up to `target`, oldest first. */
|
|
@@ -249,14 +262,34 @@ export interface ChainedRecipe extends UpgradeRecipe {
|
|
|
249
262
|
export declare function chainRecipes(target: string, installed: string | null): ChainedRecipe;
|
|
250
263
|
/** Compute the plan (and, when `write`, apply it) for a target recipe against `cwd`. */
|
|
251
264
|
export declare function computeUpgrade(cwd: string, recipe: UpgradeRecipe, write: boolean, allowDowngrade?: boolean, exact?: boolean, above?: readonly AncestorPinSite[]): UpgradePlan;
|
|
252
|
-
/** The hook report around `--write`: the diff and where the pre-upgrade report was saved, or why not.
|
|
265
|
+
/** The hook report around `--write`: the diff and where the pre-upgrade report was saved, or why not.
|
|
266
|
+
* `install` means the edits are not installed yet, so only the pre-upgrade report was taken. */
|
|
253
267
|
export type UpgradeHookScope = {
|
|
254
268
|
readonly saved: string;
|
|
255
269
|
readonly changes: readonly HookReportChange[];
|
|
270
|
+
} | {
|
|
271
|
+
readonly saved: string;
|
|
272
|
+
readonly pending: "install";
|
|
256
273
|
} | {
|
|
257
274
|
readonly error: string;
|
|
258
275
|
readonly saved?: string;
|
|
259
276
|
};
|
|
277
|
+
/** The edits `--write` made that the installed packages do not reflect yet. */
|
|
278
|
+
export interface PendingInstall {
|
|
279
|
+
/** The command that installs them, by the lockfile the project keeps. */
|
|
280
|
+
readonly command: string;
|
|
281
|
+
/** Fixed-group packages installed inside the root at a version other than the target. */
|
|
282
|
+
readonly installed: readonly {
|
|
283
|
+
readonly package: string;
|
|
284
|
+
readonly version: string;
|
|
285
|
+
}[];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Whether the project needs an install before a check can judge the target: `--write` changed what
|
|
289
|
+
* package.json declares or what bun.lock records, or node_modules holds a group package at another
|
|
290
|
+
* version. A link from outside the root is left out; installing here does not move it.
|
|
291
|
+
*/
|
|
292
|
+
export declare function pendingInstall(cwd: string, plan: UpgradePlan): PendingInstall | undefined;
|
|
260
293
|
/** The targets this CLI applies: each release recipe up to its own version, and that version. */
|
|
261
294
|
export declare function upgradeTargets(cliVersion: string): string[];
|
|
262
295
|
/** CLI entry. Returns false (→ non-zero exit) on an unknown version, no project, or a failed verify. */
|
package/dist/upgrade.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAgBH,OAAO,EAIL,KAAK,gBAAgB,EAGtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,KAAK,eAAe,EAAwC,MAAM,kBAAkB,CAAA;AAC7F,OAAO,EAKL,KAAK,aAAa,EAEnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGtF,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,mFAAmF;IACnF,QAAQ,CAA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,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,cAAc,GAAG,SAAS,CASzF;AAuFD,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAM3D;AA0CD,wGAAwG;AACxG,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CA2IvF"}
|
package/dist/upgrade.js
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
|
|
@@ -40,19 +42,25 @@ const DEP_FIELDS = [
|
|
|
40
42
|
"peerDependencies",
|
|
41
43
|
"optionalDependencies",
|
|
42
44
|
];
|
|
45
|
+
const PEER_FIELD = "peerDependencies";
|
|
43
46
|
// Only a bare semver spec is rewritten. Anything else - workspace:*, link:/file:, npm: aliases, git
|
|
44
47
|
// urls, "*", "latest", or a multi-part range - is intentionally left untouched (skipped, not guessed).
|
|
45
48
|
const SEMVER_SPEC = /^([\^~]|>=|<=|>|<|=)?\s*(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
49
|
+
const UPPER_BOUND = /^\s*<=?/;
|
|
50
|
+
// A strict bound kept on the target would exclude it: `>5.2.0` → `>5.3.0` refuses 5.3.0.
|
|
51
|
+
const INCLUSIVE_OPERATOR = { ">": ">=", "<": "<=" };
|
|
46
52
|
/**
|
|
47
|
-
* Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`,
|
|
48
|
-
*
|
|
49
|
-
* already equals the
|
|
53
|
+
* Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`, …;
|
|
54
|
+
* a strict `>` or `<` becomes `>=` or `<=`, so the result admits the target), or dropping it when
|
|
55
|
+
* `exact`. Returns null when the spec is not a plain semver spec (→ skip it) or already equals the
|
|
56
|
+
* target.
|
|
50
57
|
*/
|
|
51
58
|
export function rewriteVersionSpec(spec, toVersion, exact = false) {
|
|
52
59
|
const match = SEMVER_SPEC.exec(spec.trim());
|
|
53
60
|
if (!match)
|
|
54
61
|
return null;
|
|
55
|
-
const
|
|
62
|
+
const written = match[1] ?? "";
|
|
63
|
+
const operator = exact ? "" : (INCLUSIVE_OPERATOR[written] ?? written);
|
|
56
64
|
const next = `${operator}${toVersion}`;
|
|
57
65
|
return next === spec ? null : next;
|
|
58
66
|
}
|
|
@@ -123,6 +131,45 @@ export function compareSemverSpec(a, b) {
|
|
|
123
131
|
}
|
|
124
132
|
return 0;
|
|
125
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Whether a plain semver spec's range admits `version`, as npm reads it: `^` and `~` stop before the
|
|
136
|
+
* next breaking release, and a prerelease satisfies only a spec naming a prerelease of its own core.
|
|
137
|
+
* False for any other spec.
|
|
138
|
+
*/
|
|
139
|
+
export function specIncludes(spec, version) {
|
|
140
|
+
const match = SEMVER_SPEC.exec(spec.trim());
|
|
141
|
+
const target = parseSpecVersion(version);
|
|
142
|
+
const floor = specVersion(spec);
|
|
143
|
+
if (match === null || target === null || floor === null)
|
|
144
|
+
return false;
|
|
145
|
+
const core = [
|
|
146
|
+
Number(match[2]),
|
|
147
|
+
Number(match[3]),
|
|
148
|
+
Number(match[4]),
|
|
149
|
+
];
|
|
150
|
+
if (target.prerelease.length > 0 &&
|
|
151
|
+
(match[5] === undefined || compareSemverCore(core, target.core) !== 0))
|
|
152
|
+
return false;
|
|
153
|
+
const order = compareSemverSpec(version, floor);
|
|
154
|
+
switch (match[1]) {
|
|
155
|
+
case ">=":
|
|
156
|
+
return order >= 0;
|
|
157
|
+
case ">":
|
|
158
|
+
return order > 0;
|
|
159
|
+
case "<=":
|
|
160
|
+
return order <= 0;
|
|
161
|
+
case "<":
|
|
162
|
+
return order < 0;
|
|
163
|
+
case "^": {
|
|
164
|
+
const below = core[0] > 0 ? [core[0] + 1, 0, 0] : core[1] > 0 ? [0, core[1] + 1, 0] : [0, 0, core[2] + 1];
|
|
165
|
+
return order >= 0 && compareSemverCore(target.core, below) < 0;
|
|
166
|
+
}
|
|
167
|
+
case "~":
|
|
168
|
+
return order >= 0 && compareSemverCore(target.core, [core[0], core[1] + 1, 0]) < 0;
|
|
169
|
+
default:
|
|
170
|
+
return order === 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
126
173
|
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
127
174
|
/**
|
|
128
175
|
* Apply pin rules to one package.json's TEXT (format-preserving - targeted string replaces, never a
|
|
@@ -140,12 +187,22 @@ export function pinSweepText(text, rules, allowDowngrade = false, exact = false)
|
|
|
140
187
|
let out = text;
|
|
141
188
|
const changes = [];
|
|
142
189
|
const downgrades = [];
|
|
143
|
-
for (const { path, key, target: name, spec: rawSpec } of pinEntries(parsed)) {
|
|
190
|
+
for (const { path, holder, key, target: name, spec: rawSpec } of pinEntries(parsed)) {
|
|
144
191
|
const field = path.join(".");
|
|
145
192
|
const rule = rules.find((r) => name === r.match || (r.match.endsWith("/") && name.startsWith(r.match)));
|
|
146
193
|
if (!rule)
|
|
147
194
|
continue;
|
|
148
|
-
|
|
195
|
+
// A peer range states what a library accepts, not what installs: widening a floor that already
|
|
196
|
+
// admits the target would drop every consumer still on an older release, and an exact peer pin
|
|
197
|
+
// would admit one release only.
|
|
198
|
+
const peer = field === PEER_FIELD;
|
|
199
|
+
if (peer && specIncludes(rawSpec, rule.to))
|
|
200
|
+
continue;
|
|
201
|
+
// An upper bound has no floor to raise: one that admits the target (`<6.0.0`) stays as written,
|
|
202
|
+
// in every field, and is never read as a rollback.
|
|
203
|
+
if (UPPER_BOUND.test(rawSpec) && specIncludes(rawSpec, rule.to))
|
|
204
|
+
continue;
|
|
205
|
+
const next = rewriteVersionSpec(rawSpec, rule.to, exact && !peer);
|
|
149
206
|
if (next === null)
|
|
150
207
|
continue;
|
|
151
208
|
// Refuse a rollback: `upgrade <version>` pins an exact target, so an OLD target on a newer install
|
|
@@ -159,18 +216,15 @@ export function pinSweepText(text, rules, allowDowngrade = false, exact = false)
|
|
|
159
216
|
downgrades.push({ field, name: key, from: rawSpec, to: next });
|
|
160
217
|
continue;
|
|
161
218
|
}
|
|
162
|
-
// Replace exactly `"key"<ws>:<ws>"spec"` inside this
|
|
163
|
-
// nested `
|
|
164
|
-
const range = objectRangeAt(out,
|
|
165
|
-
|
|
219
|
+
// Replace exactly `"key"<ws>:<ws>"spec"` inside the object holding this pin, preserving the
|
|
220
|
+
// whitespace: npm's nested `{ ".": "5.2.0" }` under another package names that package.
|
|
221
|
+
const range = objectRangeAt(out, holder);
|
|
222
|
+
const at = range === undefined ? undefined : memberValueAt(out, range, key);
|
|
223
|
+
const written = JSON.stringify(rawSpec);
|
|
224
|
+
if (at === undefined || out.slice(at, at + written.length) !== written)
|
|
166
225
|
continue;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const replaced = body.replace(pattern, `$1${next}$2`);
|
|
170
|
-
if (replaced !== body) {
|
|
171
|
-
out = out.slice(0, range.start) + replaced + out.slice(range.end);
|
|
172
|
-
changes.push({ field, name: key, from: rawSpec, to: next });
|
|
173
|
-
}
|
|
226
|
+
out = out.slice(0, at) + JSON.stringify(next) + out.slice(at + written.length);
|
|
227
|
+
changes.push({ field, name: key, from: rawSpec, to: next });
|
|
174
228
|
}
|
|
175
229
|
return { text: out, changes, downgrades };
|
|
176
230
|
}
|
|
@@ -189,7 +243,6 @@ function overrideTarget(key) {
|
|
|
189
243
|
const last = key.slice(key.lastIndexOf(">") + 1);
|
|
190
244
|
return /(?:^|\/)((?:@[^/@]+\/)?[^/@]+)(?:@[^/]*)?$/.exec(last)?.[1] ?? last;
|
|
191
245
|
}
|
|
192
|
-
/** Every string version spec a package.json declares for a package, with the field path it sits in. */
|
|
193
246
|
function pinEntries(parsed) {
|
|
194
247
|
const entries = [];
|
|
195
248
|
for (const field of DEP_FIELDS) {
|
|
@@ -198,24 +251,24 @@ function pinEntries(parsed) {
|
|
|
198
251
|
continue;
|
|
199
252
|
for (const [name, spec] of Object.entries(deps))
|
|
200
253
|
if (typeof spec === "string")
|
|
201
|
-
entries.push({ path: [field], key: name, target: name, spec });
|
|
254
|
+
entries.push({ path: [field], holder: [field], key: name, target: name, spec });
|
|
202
255
|
}
|
|
203
256
|
for (const path of OVERRIDE_FIELDS) {
|
|
204
257
|
let value = parsed;
|
|
205
258
|
for (const key of path)
|
|
206
259
|
value = typeof value === "object" && value !== null ? Reflect.get(value, key) : undefined;
|
|
207
260
|
// npm nests an override under the package whose dependency it pins; `.` pins that package itself.
|
|
208
|
-
const walk = (object, parent) => {
|
|
261
|
+
const walk = (object, parent, holder) => {
|
|
209
262
|
for (const [key, spec] of Object.entries(object)) {
|
|
210
263
|
const target = key === "." ? parent : overrideTarget(key);
|
|
211
264
|
if (typeof spec === "string" && target !== undefined)
|
|
212
|
-
entries.push({ path, key, target, spec });
|
|
265
|
+
entries.push({ path, holder, key, target, spec });
|
|
213
266
|
else if (typeof spec === "object" && spec !== null && !Array.isArray(spec))
|
|
214
|
-
walk(spec, target);
|
|
267
|
+
walk(spec, target, [...holder, key]);
|
|
215
268
|
}
|
|
216
269
|
};
|
|
217
270
|
if (typeof value === "object" && value !== null && !Array.isArray(value))
|
|
218
|
-
walk(value, undefined);
|
|
271
|
+
walk(value, undefined, path);
|
|
219
272
|
}
|
|
220
273
|
return entries;
|
|
221
274
|
}
|
|
@@ -262,6 +315,13 @@ function closingBrace(text, open) {
|
|
|
262
315
|
}
|
|
263
316
|
/** The body of `key`'s object value among the direct members of the object body `within`. */
|
|
264
317
|
function memberObjectRange(text, within, key) {
|
|
318
|
+
const at = memberValueAt(text, within, key);
|
|
319
|
+
return at !== undefined && text[at] === "{"
|
|
320
|
+
? { start: at + 1, end: closingBrace(text, at) }
|
|
321
|
+
: undefined;
|
|
322
|
+
}
|
|
323
|
+
/** Where `key`'s value starts among the direct members of the object body `within`. */
|
|
324
|
+
function memberValueAt(text, within, key) {
|
|
265
325
|
let depth = 0;
|
|
266
326
|
for (let index = within.start; index < within.end; index++) {
|
|
267
327
|
const char = text[index];
|
|
@@ -278,9 +338,7 @@ function memberObjectRange(text, within, key) {
|
|
|
278
338
|
after++;
|
|
279
339
|
while (/\s/.test(text[after] ?? ""))
|
|
280
340
|
after++;
|
|
281
|
-
return
|
|
282
|
-
? { start: after + 1, end: closingBrace(text, after) }
|
|
283
|
-
: undefined;
|
|
341
|
+
return after;
|
|
284
342
|
}
|
|
285
343
|
index = close;
|
|
286
344
|
}
|
|
@@ -437,10 +495,14 @@ export function groupDeclaredNames(cwd) {
|
|
|
437
495
|
}
|
|
438
496
|
/**
|
|
439
497
|
* Every fixed-group version the package.json files under `cwd` declare with a plain semver spec, each
|
|
440
|
-
* with the files that declare it. An override counts: it decides what installs.
|
|
441
|
-
*
|
|
498
|
+
* with the files that declare it. An override counts: it decides what installs. A peer range does
|
|
499
|
+
* not (`>=3.1.0` names a floor a library accepts, not a version anything loads), and `workspace:`,
|
|
500
|
+
* `link:` and other non-semver specs are not versions.
|
|
442
501
|
*/
|
|
443
502
|
export function groupPinVersions(cwd) {
|
|
503
|
+
return groupSpecVersions(cwd, false);
|
|
504
|
+
}
|
|
505
|
+
function groupSpecVersions(cwd, peers) {
|
|
444
506
|
const versions = new Map();
|
|
445
507
|
for (const rel of scan(cwd, "**/package.json")) {
|
|
446
508
|
let parsed;
|
|
@@ -450,8 +512,8 @@ export function groupPinVersions(cwd) {
|
|
|
450
512
|
catch {
|
|
451
513
|
continue;
|
|
452
514
|
}
|
|
453
|
-
for (const { target, spec } of pinEntries(parsed)) {
|
|
454
|
-
if (!isFixedGroup(target))
|
|
515
|
+
for (const { path, target, spec } of pinEntries(parsed)) {
|
|
516
|
+
if (!isFixedGroup(target) || (path[0] === PEER_FIELD) !== peers)
|
|
455
517
|
continue;
|
|
456
518
|
const version = specVersion(spec);
|
|
457
519
|
if (version === null)
|
|
@@ -676,16 +738,24 @@ export function installedGroupPackages(cwd) {
|
|
|
676
738
|
return found;
|
|
677
739
|
}
|
|
678
740
|
/**
|
|
679
|
-
* The lowest fixed-group version any package.json under
|
|
680
|
-
*
|
|
741
|
+
* The version the workspace upgrades from: the lowest fixed-group version any package.json under
|
|
742
|
+
* `cwd` pins ({@link groupPinVersions}), since recipes newer than it still have edits to make
|
|
743
|
+
* somewhere. Without a pin, the lowest one installed inside the root, then the lowest peer floor;
|
|
744
|
+
* null when none names one.
|
|
681
745
|
*/
|
|
682
746
|
export function installedGroupVersion(cwd) {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
747
|
+
const lowest = (versions) => {
|
|
748
|
+
let found = null;
|
|
749
|
+
for (const version of versions)
|
|
750
|
+
if (found === null || compareSemverSpec(version, found) < 0)
|
|
751
|
+
found = version;
|
|
752
|
+
return found;
|
|
753
|
+
};
|
|
754
|
+
return (lowest(groupPinVersions(cwd).keys()) ??
|
|
755
|
+
lowest(installedGroupPackages(cwd)
|
|
756
|
+
.filter((entry) => entry.inside)
|
|
757
|
+
.map((entry) => entry.version)) ??
|
|
758
|
+
lowest(groupSpecVersions(cwd, true).keys()));
|
|
689
759
|
}
|
|
690
760
|
/**
|
|
691
761
|
* Chain the recipes after `installed` (exclusive) up to `target` (inclusive): their dependency and
|
|
@@ -915,7 +985,7 @@ function renderPlan(plan, write, from, steps) {
|
|
|
915
985
|
for (const note of plan.notes)
|
|
916
986
|
lines.push(`note: ${note}`);
|
|
917
987
|
if (!write)
|
|
918
|
-
lines.push("\nRe-run with --write to apply, then nifra check
|
|
988
|
+
lines.push("\nRe-run with --write to apply, then install and run nifra check.");
|
|
919
989
|
return lines.join("\n").trimEnd();
|
|
920
990
|
}
|
|
921
991
|
/** Explain a refused rollback: which pins would roll back, why it's blocked, and the escape hatch. */
|
|
@@ -943,6 +1013,41 @@ function renderDowngradeRefusal(version, downgrades) {
|
|
|
943
1013
|
"installed one, or pass --allow-downgrade if the rollback is intended.",
|
|
944
1014
|
].join("\n");
|
|
945
1015
|
}
|
|
1016
|
+
const INSTALL_COMMANDS = [
|
|
1017
|
+
["pnpm-lock.yaml", "pnpm install"],
|
|
1018
|
+
["yarn.lock", "yarn install"],
|
|
1019
|
+
["package-lock.json", "npm install"],
|
|
1020
|
+
];
|
|
1021
|
+
/**
|
|
1022
|
+
* Whether the project needs an install before a check can judge the target: `--write` changed what
|
|
1023
|
+
* package.json declares or what bun.lock records, or node_modules holds a group package at another
|
|
1024
|
+
* version. A link from outside the root is left out; installing here does not move it.
|
|
1025
|
+
*/
|
|
1026
|
+
export function pendingInstall(cwd, plan) {
|
|
1027
|
+
const installed = installedGroupPackages(cwd)
|
|
1028
|
+
.filter((entry) => entry.inside && entry.version !== plan.version)
|
|
1029
|
+
.map(({ package: name, version }) => ({ package: name, version }));
|
|
1030
|
+
const edited = plan.pins.length > 0 || plan.dependencyMoves.length > 0 || plan.lockPruned;
|
|
1031
|
+
if (!edited && installed.length === 0)
|
|
1032
|
+
return undefined;
|
|
1033
|
+
const command = INSTALL_COMMANDS.find(([lockfile]) => existsSync(join(cwd, lockfile)))?.[1] ?? "bun install";
|
|
1034
|
+
return { command, installed };
|
|
1035
|
+
}
|
|
1036
|
+
const SHOWN_INSTALLS = 3;
|
|
1037
|
+
function renderPendingInstall(pending, version) {
|
|
1038
|
+
const shown = pending.installed
|
|
1039
|
+
.slice(0, SHOWN_INSTALLS)
|
|
1040
|
+
.map((entry) => `${entry.package} ${entry.version}`);
|
|
1041
|
+
const more = pending.installed.length - shown.length;
|
|
1042
|
+
const holds = shown.length === 0
|
|
1043
|
+
? "the edited pins are not installed yet"
|
|
1044
|
+
: `node_modules still holds ${shown.join(", ")}${more > 0 ? ` and ${more} more` : ""}`;
|
|
1045
|
+
return [
|
|
1046
|
+
`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:`,
|
|
1047
|
+
` ${pending.command}`,
|
|
1048
|
+
" nifra check",
|
|
1049
|
+
].join("\n");
|
|
1050
|
+
}
|
|
946
1051
|
async function hookReportBefore(cwd) {
|
|
947
1052
|
try {
|
|
948
1053
|
const { loadBackendApp } = await import("./load.js");
|
|
@@ -954,13 +1059,16 @@ async function hookReportBefore(cwd) {
|
|
|
954
1059
|
}
|
|
955
1060
|
}
|
|
956
1061
|
/** The report after the edits, from a fresh process: the edited sources must not come from this one's
|
|
957
|
-
* module cache. Saves the pre-upgrade report for `nifra routes --hooks --since` after an install.
|
|
958
|
-
|
|
1062
|
+
* module cache. Saves the pre-upgrade report for `nifra routes --hooks --since` after an install.
|
|
1063
|
+
* While the edits are not installed, the old release would load in its place, so none is taken. */
|
|
1064
|
+
async function hookScopeAcross(cwd, before, installed) {
|
|
959
1065
|
if ("error" in before)
|
|
960
1066
|
return { error: before.error };
|
|
961
1067
|
const saved = join(cwd, HOOKS_BEFORE_UPGRADE_FILE);
|
|
962
1068
|
mkdirSync(dirname(saved), { recursive: true });
|
|
963
1069
|
writeFileSync(saved, `${JSON.stringify(before, null, 2)}\n`);
|
|
1070
|
+
if (!installed)
|
|
1071
|
+
return { saved: HOOKS_BEFORE_UPGRADE_FILE, pending: "install" };
|
|
964
1072
|
const entry = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./cli.ts" : "./cli.js", import.meta.url));
|
|
965
1073
|
const child = Bun.spawn([process.execPath, entry, "routes", "--hooks", "--json"], {
|
|
966
1074
|
cwd,
|
|
@@ -991,6 +1099,8 @@ function renderHookScope(scope) {
|
|
|
991
1099
|
const head = `Hook scope: not captured (${scope.error}).`;
|
|
992
1100
|
return scope.saved === undefined ? head : [head, ...since(scope.saved)].join("\n");
|
|
993
1101
|
}
|
|
1102
|
+
if ("pending" in scope)
|
|
1103
|
+
return since(scope.saved).join("\n");
|
|
994
1104
|
return [
|
|
995
1105
|
"Hook scope across the edits (nifra routes --hooks):",
|
|
996
1106
|
renderHookDiff(scope.changes)
|
|
@@ -1121,14 +1231,18 @@ export async function runUpgrade(cwd, options) {
|
|
|
1121
1231
|
const captureHooks = write && options.hooks !== false;
|
|
1122
1232
|
const before = captureHooks ? await hookReportBefore(cwd) : undefined;
|
|
1123
1233
|
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact, above) : preview;
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1234
|
+
const pending = write ? pendingInstall(cwd, plan) : undefined;
|
|
1235
|
+
const hooks = before === undefined ? undefined : await hookScopeAcross(cwd, before, pending === undefined);
|
|
1236
|
+
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
1237
|
+
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
1238
|
+
const verify = write && options.verify !== false && pending === undefined;
|
|
1127
1239
|
if (options.json) {
|
|
1128
1240
|
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
1129
1241
|
const report = { ...plan, from, steps: recipe.steps, write };
|
|
1130
1242
|
if (hooks !== undefined)
|
|
1131
1243
|
report.hooks = hooks;
|
|
1244
|
+
if (pending !== undefined)
|
|
1245
|
+
report.install = pending;
|
|
1132
1246
|
let ok = true;
|
|
1133
1247
|
if (verify) {
|
|
1134
1248
|
const { collectProjectVerification } = await import("./verification.js");
|
|
@@ -1145,6 +1259,8 @@ export async function runUpgrade(cwd, options) {
|
|
|
1145
1259
|
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`);
|
|
1146
1260
|
if (hooks !== undefined)
|
|
1147
1261
|
console.log(`\n${renderHookScope(hooks)}`);
|
|
1262
|
+
if (pending !== undefined && options.verify !== false)
|
|
1263
|
+
console.log(`\n${renderPendingInstall(pending, recipe.version)}`);
|
|
1148
1264
|
if (verify) {
|
|
1149
1265
|
const { runCheck } = await import("./check.js");
|
|
1150
1266
|
const ok = await runCheck(cwd, { json: false });
|