rolldown-pnpm-config 2.4.4 → 2.4.6
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/README.md +1 -1
- package/cli/commands/upgrade.js +41 -12
- package/cli/discover.js +21 -14
- package/cli/version.js +1 -1
- package/index.d.ts +11 -0
- package/package.json +1 -1
- package/plugin/freeze.js +2 -1
- package/plugin/overrides-from-catalogs.js +46 -7
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ npx rolldown-pnpm-config upgrade
|
|
|
81
81
|
# Applied <n> changes.
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
The command shows an interactive table by default — every catalog package at once, one row per package, `●`/`○` bubbles, modeled on `pnpm up -i`. `--yes` takes the latest in-range version for every package without prompting and fails hard on any warning or unresolvable package name; `--dry-run` runs the identical table and skips only the write; `--catalog <name>`
|
|
84
|
+
The command shows an interactive table by default — every catalog package at once, one row per package, `●`/`○` bubbles, modeled on `pnpm up -i`. `--yes` takes the latest in-range version for every package without prompting and fails hard on any warning or unresolvable package name; `--dry-run` runs the identical table and skips only the write; `--catalog <name>` scopes every mode — the table, `--preview`, `--check`, `--yes` and `--dry-run` — to one catalog, and fails on a name the config does not declare. Pass `--preview` for a non-interactive projection of what an upgrade would do, with `--full` to show up-to-date entries too. The output is colorized in a supporting terminal. For packages that declare a `strategy`, the command also resyncs their materialized peer range, preserving any prerelease identifier rather than rebuilding it from parsed version parts. See [upgrading catalogs](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/05-upgrading-catalogs.md) for the full surface.
|
|
85
85
|
|
|
86
86
|
## Exporting to pnpm-workspace.yaml
|
|
87
87
|
|
package/cli/commands/upgrade.js
CHANGED
|
@@ -75,21 +75,46 @@ var CheckFailedError = class extends Data.TaggedError("CheckFailedError") {
|
|
|
75
75
|
function writeSource(file, next) {
|
|
76
76
|
return AtomicFile.write(file, next).pipe(Effect.mapError(() => new UpgradeError({ message: `Cannot write ${file}` })));
|
|
77
77
|
}
|
|
78
|
-
/**
|
|
79
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Read a config file and statically discover its catalog entries. With
|
|
80
|
+
* `catalog`, the entries and skipped names are scoped to that one catalog,
|
|
81
|
+
* and a name the config does not declare fails (`kind: "catalog"`) rather
|
|
82
|
+
* than silently matching nothing. Every `upgrade` mode reads through here, so
|
|
83
|
+
* `--catalog` scopes them all alike.
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
function readCatalogSource(file, catalog) {
|
|
80
88
|
return Effect.gen(function* () {
|
|
81
89
|
const source = yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.mapError(() => new UpgradeError({ message: `Cannot read ${file}` })));
|
|
82
|
-
const { entries, skipped } = yield* Effect.try({
|
|
90
|
+
const { entries, skipped, skippedRefs, catalogs } = yield* Effect.try({
|
|
83
91
|
try: () => discoverCatalogEntries(source, file),
|
|
84
92
|
catch: (e) => new UpgradeError({ message: Fmt.describe(e) })
|
|
85
93
|
});
|
|
86
|
-
return {
|
|
94
|
+
if (catalog === void 0) return {
|
|
87
95
|
source,
|
|
88
96
|
entries,
|
|
89
97
|
skipped
|
|
90
98
|
};
|
|
99
|
+
if (!catalogs.includes(catalog)) return yield* Effect.fail(new UpgradeError({
|
|
100
|
+
message: unknownCatalogMessage(catalog, catalogs),
|
|
101
|
+
kind: "catalog"
|
|
102
|
+
}));
|
|
103
|
+
return {
|
|
104
|
+
source,
|
|
105
|
+
entries: filterEntriesByCatalog(entries, catalog),
|
|
106
|
+
skipped: skippedRefs.filter((r) => r.catalog === catalog).map((r) => `${r.catalog}.${r.pkg}`)
|
|
107
|
+
};
|
|
91
108
|
});
|
|
92
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The message for a `--catalog` that names no catalog the config declares.
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
function unknownCatalogMessage(catalog, declared) {
|
|
116
|
+
return `No catalog named "${catalog}" in the config (${declared.length === 0 ? "it declares no catalogs" : `declared: ${declared.join(", ")}`})`;
|
|
117
|
+
}
|
|
93
118
|
/** Combine the config-declared and pnpm-resolved release-age gates (strictest of both). @internal */
|
|
94
119
|
function computeGate(source, file, resolver) {
|
|
95
120
|
return Effect.gen(function* () {
|
|
@@ -204,7 +229,7 @@ function resolveProgress(report) {
|
|
|
204
229
|
*/
|
|
205
230
|
function runUpgrade(opts) {
|
|
206
231
|
return Effect.gen(function* () {
|
|
207
|
-
const { source, entries, skipped } = yield* readCatalogSource(opts.file);
|
|
232
|
+
const { source, entries, skipped } = yield* readCatalogSource(opts.file, opts.catalog);
|
|
208
233
|
const gate = yield* computeGate(source, opts.file, opts.resolver);
|
|
209
234
|
const versionsByPkg = yield* resolveGatedVersions(entries, opts.resolver, gate, yield* Clock.currentTimeMillis, opts.onProgress, opts.workspaceResolver);
|
|
210
235
|
if (versionsByPkg.unresolved.length > 0) return yield* Effect.fail(new UpgradeError({ message: unresolvedMessage(versionsByPkg.unresolved) }));
|
|
@@ -382,7 +407,7 @@ function projectDecisions(items, full) {
|
|
|
382
407
|
*/
|
|
383
408
|
function runUpgradePreview(opts) {
|
|
384
409
|
return Effect.gen(function* () {
|
|
385
|
-
const { source, entries } = yield* readCatalogSource(opts.file);
|
|
410
|
+
const { source, entries } = yield* readCatalogSource(opts.file, opts.catalog);
|
|
386
411
|
const gate = yield* computeGate(source, opts.file, opts.resolver);
|
|
387
412
|
const versions = yield* resolveGatedVersions(entries, opts.resolver, gate, yield* Clock.currentTimeMillis, void 0, opts.workspaceResolver);
|
|
388
413
|
const items = yield* buildWalkItems(entries, versions.gated).pipe(Effect.mapError((e) => new UpgradeError({ message: e.message })));
|
|
@@ -669,6 +694,8 @@ const upgradeCommand = Command.make("upgrade", {
|
|
|
669
694
|
format: formatFlag
|
|
670
695
|
}, ({ file: fileOpt, yes, dryRun, catalog, preview, full, check, format }) => {
|
|
671
696
|
const skippedChangesets = skippedChangesetsTracker();
|
|
697
|
+
const catalogName = Option.getOrUndefined(catalog);
|
|
698
|
+
const scope = catalogName === void 0 ? {} : { catalog: catalogName };
|
|
672
699
|
return Effect.gen(function* () {
|
|
673
700
|
const jsonRejection = validateFormatMode({
|
|
674
701
|
format,
|
|
@@ -684,7 +711,8 @@ const upgradeCommand = Command.make("upgrade", {
|
|
|
684
711
|
file,
|
|
685
712
|
resolver,
|
|
686
713
|
workspaceResolver: workspaceOf(file),
|
|
687
|
-
dryRun: forceDryRun || dryRun
|
|
714
|
+
dryRun: forceDryRun || dryRun,
|
|
715
|
+
...scope
|
|
688
716
|
})), Effect.result);
|
|
689
717
|
if (check) {
|
|
690
718
|
const result = yield* nonInteractive(true);
|
|
@@ -720,7 +748,8 @@ const upgradeCommand = Command.make("upgrade", {
|
|
|
720
748
|
file,
|
|
721
749
|
resolver,
|
|
722
750
|
full,
|
|
723
|
-
workspaceResolver
|
|
751
|
+
workspaceResolver,
|
|
752
|
+
...scope
|
|
724
753
|
});
|
|
725
754
|
yield* Doc.print(doc);
|
|
726
755
|
return yield* warnUnresolved(unresolved);
|
|
@@ -731,7 +760,8 @@ const upgradeCommand = Command.make("upgrade", {
|
|
|
731
760
|
resolver,
|
|
732
761
|
dryRun,
|
|
733
762
|
workspaceResolver,
|
|
734
|
-
onProgress: resolveProgress(report)
|
|
763
|
+
onProgress: resolveProgress(report),
|
|
764
|
+
...scope
|
|
735
765
|
}));
|
|
736
766
|
yield* dryRun ? CliMessage.info(`Dry run — no changes written. ${Fmt.plural(result.updated, "package")} would be updated; skipped ${result.skipped.length}.`) : CliMessage.success(`Updated ${Fmt.plural(result.updated, "package")}; skipped ${result.skipped.length}.`);
|
|
737
767
|
if (result.conflicts.length > 0) {
|
|
@@ -740,8 +770,7 @@ const upgradeCommand = Command.make("upgrade", {
|
|
|
740
770
|
}
|
|
741
771
|
return;
|
|
742
772
|
}
|
|
743
|
-
const { source, entries
|
|
744
|
-
const entries = filterEntriesByCatalog(discovered, Option.getOrUndefined(catalog));
|
|
773
|
+
const { source, entries } = yield* readCatalogSource(file, catalogName);
|
|
745
774
|
const gate = yield* computeGate(source, file, resolver);
|
|
746
775
|
if (!(yield* CliInteractive)) {
|
|
747
776
|
const versions = yield* resolveGatedVersions(entries, resolver, gate, yield* Clock.currentTimeMillis, void 0, workspaceResolver);
|
|
@@ -810,4 +839,4 @@ const upgradeCommand = Command.make("upgrade", {
|
|
|
810
839
|
}).pipe(Effect.tapError((error) => isChangesetFailure(error) ? Effect.sync(skippedChangesets.silence) : Effect.void), Effect.ensuring(skippedChangesets.report));
|
|
811
840
|
}).pipe(Command.withDescription("Upgrade catalog versions in a config file"));
|
|
812
841
|
|
|
813
|
-
export { CHECK_FAILED_LABEL, CheckFailedError, UpgradeError, UpgradeUsageError, applyInteropAndDecisions, checkJsonOutcome, checkOutcome, computeGate, countChangedDecisions, nothingToUpgradeMessage, projectDecisions, readCatalogSource, resolveGatedVersions, resolveProgress, resolveTargetFile, runUpgrade, runUpgradePreview, skippedChangesetsMessage, unresolvedMessage, upgradeCommand, upgradeJsonOutcome, validateFormatMode };
|
|
842
|
+
export { CHECK_FAILED_LABEL, CheckFailedError, UpgradeError, UpgradeUsageError, applyInteropAndDecisions, checkJsonOutcome, checkOutcome, computeGate, countChangedDecisions, nothingToUpgradeMessage, projectDecisions, readCatalogSource, resolveGatedVersions, resolveProgress, resolveTargetFile, runUpgrade, runUpgradePreview, skippedChangesetsMessage, unknownCatalogMessage, unresolvedMessage, upgradeCommand, upgradeJsonOutcome, validateFormatMode };
|
package/cli/discover.js
CHANGED
|
@@ -22,6 +22,11 @@ function operatorOf(range) {
|
|
|
22
22
|
* Each package whose range is a simple-operator string literal yields a
|
|
23
23
|
* CatalogEntry with byte-offset spans; anything else (computed value, complex
|
|
24
24
|
* range) is reported in `skipped` as `<catalog>.<pkg>` and never throws.
|
|
25
|
+
* `catalogs` names every declared catalog in source order, including one
|
|
26
|
+
* that yields no entries, so `--catalog` can tell an empty catalog from a
|
|
27
|
+
* typo. `skippedRefs` carries the same skips as `{ catalog, pkg }` pairs, so
|
|
28
|
+
* a caller can scope them by catalog identity: the flattened string cannot
|
|
29
|
+
* tell catalog `a` from a catalog named `a.b`.
|
|
25
30
|
*
|
|
26
31
|
* @internal
|
|
27
32
|
*/
|
|
@@ -30,21 +35,23 @@ function discoverCatalogEntries(source, filename) {
|
|
|
30
35
|
if (result.errors.length > 0) throw new DiscoverError({ message: result.errors.map((e) => e.message).join("; ") });
|
|
31
36
|
const program = result.program;
|
|
32
37
|
const entries = [];
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
38
|
+
const skippedRefs = [];
|
|
39
|
+
const declared = [];
|
|
40
|
+
const finish = () => ({
|
|
36
41
|
entries,
|
|
37
|
-
skipped
|
|
38
|
-
|
|
42
|
+
skipped: skippedRefs.map((r) => `${r.catalog}.${r.pkg}`),
|
|
43
|
+
skippedRefs,
|
|
44
|
+
catalogs: declared
|
|
45
|
+
});
|
|
46
|
+
const arg = findPluginArg(program);
|
|
47
|
+
if (!arg) return finish();
|
|
39
48
|
const catalogs = prop(arg, "catalogs");
|
|
40
|
-
if (catalogs?.type !== "ObjectExpression") return
|
|
41
|
-
entries,
|
|
42
|
-
skipped
|
|
43
|
-
};
|
|
49
|
+
if (catalogs?.type !== "ObjectExpression") return finish();
|
|
44
50
|
for (const catProp of catalogs.properties ?? []) {
|
|
45
51
|
if (catProp.type !== "Property") continue;
|
|
46
52
|
const catalog = keyName(catProp.key);
|
|
47
53
|
if (catalog === void 0) continue;
|
|
54
|
+
declared.push(catalog);
|
|
48
55
|
const decl = catProp.value;
|
|
49
56
|
if (decl.type !== "ObjectExpression") continue;
|
|
50
57
|
const packages = prop(decl, "packages");
|
|
@@ -70,7 +77,10 @@ function discoverCatalogEntries(source, filename) {
|
|
|
70
77
|
if (src?.type === "Literal" && (src.value === "registry" || src.value === "workspace")) source = src.value;
|
|
71
78
|
}
|
|
72
79
|
if (!rangeNode || !SIMPLE_RANGE_RE.test(rangeNode.value)) {
|
|
73
|
-
|
|
80
|
+
skippedRefs.push({
|
|
81
|
+
catalog,
|
|
82
|
+
pkg
|
|
83
|
+
});
|
|
74
84
|
continue;
|
|
75
85
|
}
|
|
76
86
|
const currentRange = rangeNode.value;
|
|
@@ -89,10 +99,7 @@ function discoverCatalogEntries(source, filename) {
|
|
|
89
99
|
});
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
|
-
return
|
|
93
|
-
entries,
|
|
94
|
-
skipped
|
|
95
|
-
};
|
|
102
|
+
return finish();
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
export { DiscoverError, discoverCatalogEntries };
|
package/cli/version.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -83,6 +83,17 @@ interface AllowedVersionsFromCatalogs {
|
|
|
83
83
|
* authored by hand wins over a derived one on the same selector, and the
|
|
84
84
|
* consumer's own `overrides` still win over the plugin's at install time.
|
|
85
85
|
*
|
|
86
|
+
* Every pinned member's catalog value is frozen to the version its override
|
|
87
|
+
* names, so the catalog and the override always agree. pnpm never matches an
|
|
88
|
+
* override against a `catalog:` specifier, so a catalog left at `~X.Y.Z`
|
|
89
|
+
* would let a dependent writing `catalog:` resolve a newer patch than the
|
|
90
|
+
* override pins everywhere else, and the graph would carry two copies. Only
|
|
91
|
+
* the frozen output changes (the pnpmfile's `base`, `export`, `preview`): the
|
|
92
|
+
* authored range stays what `upgrade` reads and rewrites, and the `:peers`
|
|
93
|
+
* catalog keeps its peer range. When a hand-authored override wins on the
|
|
94
|
+
* selector, the catalog takes its value if that is an exact version and keeps
|
|
95
|
+
* the authored range otherwise.
|
|
96
|
+
*
|
|
86
97
|
* `include` and `exclude` select which members are pinned, so one catalog can
|
|
87
98
|
* hold both a release family that is pinned graph-wide and packages that are
|
|
88
99
|
* not. Each entry is an exact package name or a glob pattern (`@effect/*`),
|
package/package.json
CHANGED
package/plugin/freeze.js
CHANGED
|
@@ -2,7 +2,7 @@ import { normalizeCatalogs } from "../catalogs.js";
|
|
|
2
2
|
import { DESCRIPTORS, deriveSchemas } from "../descriptors/index.js";
|
|
3
3
|
import { FIELD_REGISTRY } from "../registry.js";
|
|
4
4
|
import { resolvePeerDependencyRules } from "./allowed-versions.js";
|
|
5
|
-
import { resolveOverrides } from "./overrides-from-catalogs.js";
|
|
5
|
+
import { pinCatalogs, resolveOverrides } from "./overrides-from-catalogs.js";
|
|
6
6
|
import { Data, Effect, Predicate, Schema } from "effect";
|
|
7
7
|
import { Fmt } from "@effected/cli-kit";
|
|
8
8
|
|
|
@@ -86,6 +86,7 @@ function freeze(config) {
|
|
|
86
86
|
...decl.options ? { options: decl.options } : {}
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
+
base.catalogs = pinCatalogs(base.catalogs, base.overrides, config.overridesFromCatalogs, config.catalogs);
|
|
89
90
|
return {
|
|
90
91
|
base,
|
|
91
92
|
manifest,
|
|
@@ -33,7 +33,7 @@ function compileFilter(entries, members, label, catalog) {
|
|
|
33
33
|
});
|
|
34
34
|
return (name) => globs.some((glob) => Glob.match(glob, name));
|
|
35
35
|
}
|
|
36
|
-
/** Derive the
|
|
36
|
+
/** Derive the pins for one directive. Pure; throws when the catalog is absent or a filter entry matches nothing. */
|
|
37
37
|
function deriveOne(catalogs, { catalog, include, exclude = [], scope = "line" }) {
|
|
38
38
|
const decl = catalogs[catalog];
|
|
39
39
|
if (decl === void 0) throw new Error(`overridesFromCatalogs: catalog "${catalog}" is not declared`);
|
|
@@ -41,7 +41,7 @@ function deriveOne(catalogs, { catalog, include, exclude = [], scope = "line" })
|
|
|
41
41
|
const members = Object.keys(decl.packages);
|
|
42
42
|
const isIncluded = include === void 0 ? () => true : compileFilter(include, members, "included", catalog);
|
|
43
43
|
const isExcluded = compileFilter(exclude, members, "excluded", catalog);
|
|
44
|
-
const
|
|
44
|
+
const pins = [];
|
|
45
45
|
for (const [name, spec] of Object.entries(decl.packages)) {
|
|
46
46
|
if (!isIncluded(name) || isExcluded(name)) continue;
|
|
47
47
|
const parsed = Result.getOrNull(VersionSpecifier.parseResult(rangeOf(spec)));
|
|
@@ -49,9 +49,18 @@ function deriveOne(catalogs, { catalog, include, exclude = [], scope = "line" })
|
|
|
49
49
|
const { version } = parsed;
|
|
50
50
|
if (version.prerelease.length > 0 || version.build.length > 0) continue;
|
|
51
51
|
const selector = scope === "any" ? name : `${name}@${releaseLine(version.major, version.minor)}`;
|
|
52
|
-
|
|
52
|
+
pins.push({
|
|
53
|
+
catalog,
|
|
54
|
+
name,
|
|
55
|
+
selector,
|
|
56
|
+
version: version.toString()
|
|
57
|
+
});
|
|
53
58
|
}
|
|
54
|
-
return
|
|
59
|
+
return pins;
|
|
60
|
+
}
|
|
61
|
+
/** Every directive's pins, in directive order. */
|
|
62
|
+
function derivePins(catalogs, directives) {
|
|
63
|
+
return (Array.isArray(directives) ? directives : [directives]).flatMap((d) => deriveOne(catalogs, d));
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
66
|
* Merge the derived overrides for one or more directives (later directives win
|
|
@@ -60,9 +69,39 @@ function deriveOne(catalogs, { catalog, include, exclude = [], scope = "line" })
|
|
|
60
69
|
* @internal
|
|
61
70
|
*/
|
|
62
71
|
function deriveOverrides(catalogs, directives) {
|
|
63
|
-
const list = Array.isArray(directives) ? directives : [directives];
|
|
64
72
|
const out = {};
|
|
65
|
-
for (const
|
|
73
|
+
for (const pin of derivePins(catalogs, directives)) out[pin.selector] = pin.version;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/** The exact version an override value names, or `null` for a range, alias or removal. */
|
|
77
|
+
function exactVersion(value) {
|
|
78
|
+
if (typeof value !== "string") return null;
|
|
79
|
+
const parsed = Result.getOrNull(VersionSpecifier.parseResult(value));
|
|
80
|
+
if (parsed === null || parsed.operator !== "" && parsed.operator !== "=") return null;
|
|
81
|
+
return parsed.version.toString();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Freeze each pinned member's catalog value to the exact version its final
|
|
85
|
+
* override names, so a `catalog:` specifier (which pnpm never matches against
|
|
86
|
+
* an override) resolves the same version the override pins. Returns a new
|
|
87
|
+
* catalogs map; `:peers` catalogs and unpinned members pass through verbatim,
|
|
88
|
+
* and a member whose winning override is not an exact version keeps its range.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
function pinCatalogs(resolved, overrides, directives, catalogs) {
|
|
93
|
+
if (directives === void 0 || !Predicate.isObject(overrides)) return resolved;
|
|
94
|
+
const table = overrides;
|
|
95
|
+
const out = { ...resolved };
|
|
96
|
+
for (const { catalog, name, selector } of derivePins(catalogs, directives)) {
|
|
97
|
+
const pinned = exactVersion(table[selector]);
|
|
98
|
+
const current = out[catalog];
|
|
99
|
+
if (pinned === null || current === void 0 || !(name in current)) continue;
|
|
100
|
+
out[catalog] = {
|
|
101
|
+
...current,
|
|
102
|
+
[name]: pinned
|
|
103
|
+
};
|
|
104
|
+
}
|
|
66
105
|
return out;
|
|
67
106
|
}
|
|
68
107
|
/**
|
|
@@ -83,4 +122,4 @@ function resolveOverrides(authored, directives, catalogs) {
|
|
|
83
122
|
};
|
|
84
123
|
}
|
|
85
124
|
|
|
86
|
-
export { deriveOverrides, resolveOverrides };
|
|
125
|
+
export { deriveOverrides, pinCatalogs, resolveOverrides };
|