rolldown-pnpm-config 2.4.7 → 2.5.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/catalogs.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { Result } from "effect";
2
+ import { VersionSpecifier } from "@effected/semver";
3
+
1
4
  // src/catalogs.ts
2
5
  /**
3
6
  * The install range of a catalog spec (bare string or `{ range }` object).
@@ -6,11 +9,55 @@
6
9
  */
7
10
  const rangeOf = (spec) => typeof spec === "string" ? spec : spec.range;
8
11
  /**
12
+ * Matches a range the `upgrade` CLI discovers and rewrites: a simple operator
13
+ * (`^`, `~` or none) on a version, partials like `^1.2` and `1.x` included.
14
+ * Shared so the build and `upgrade` agree on which ranges move under an
15
+ * upgrade.
16
+ *
17
+ * @internal
18
+ */
19
+ const REWRITABLE_RANGE_RE = /^(\^|~|)(\d[\w.+-]*)$/;
20
+ /** The operators whose single version an exact pin can be read from. */
21
+ const EXACT_OPERATORS = /* @__PURE__ */ new Set([
22
+ "^",
23
+ "~",
24
+ ">=",
25
+ "=",
26
+ ""
27
+ ]);
28
+ /** The single version a range names, or `null` when it names none (compound, wildcard, tag, `<`, `>`). */
29
+ function singleVersionOf(range) {
30
+ const parsed = Result.getOrNull(VersionSpecifier.parseResult(range));
31
+ if (parsed === null || !EXACT_OPERATORS.has(parsed.operator)) return null;
32
+ return parsed.version.toString();
33
+ }
34
+ /** The `<name>:exact` value of one entry, `undefined` to leave it out; throws on an entry with no single version. */
35
+ function exactEntry(catalog, pkg, spec) {
36
+ const range = rangeOf(spec);
37
+ const derived = singleVersionOf(range);
38
+ const explicit = typeof spec === "object" ? spec.exact : void 0;
39
+ if (explicit === false) return void 0;
40
+ const rewritable = REWRITABLE_RANGE_RE.test(range);
41
+ if (explicit !== void 0) {
42
+ if (derived !== null) throw new Error(`catalogs: "${pkg}" in catalog "${catalog}" derives its exact version ${derived} from "${range}"; remove its exact value, which upgrade would leave stale`);
43
+ if (rewritable) throw new Error(`catalogs: "${pkg}" in catalog "${catalog}" has range "${range}", which upgrade rewrites; an exact value would go stale, so write the range as a full version, or set exact: false`);
44
+ const parsed = Result.getOrNull(VersionSpecifier.parseResult(explicit));
45
+ if (parsed === null || parsed.operator !== "") throw new Error(`catalogs: exact value "${explicit}" for "${pkg}" in catalog "${catalog}" is not a plain version`);
46
+ return explicit;
47
+ }
48
+ if (derived === null && rewritable) throw new Error(`catalogs: catalog "${catalog}" sets exact: true, but "${pkg}" has range "${range}", which names no single version; write the range as a full version, or set exact: false to leave it out`);
49
+ if (derived === null) throw new Error(`catalogs: catalog "${catalog}" sets exact: true, but "${pkg}" has range "${range}", which names no single version; set exact to a version, or exact: false to leave it out`);
50
+ return derived;
51
+ }
52
+ /**
9
53
  * Normalize declarative catalog input into the resolved `{ catalog → pkg → range }`
10
54
  * map consumed by the runtime. Pure: the base catalog uses each package's
11
55
  * `range` (or bare string); a peers catalog is emitted only for packages
12
56
  * carrying a materialized `peer`, using that value verbatim, under the
13
- * `<name>:peers` colon-delimited name. `strategy` is CLI-only and ignored here.
57
+ * `<name>:peers` colon-delimited name. A declaration with `exact: true` also
58
+ * emits `<name>:exact`, each range with its operator stripped. `strategy` is
59
+ * CLI-only and ignored here. Throws when an exact-opted entry names no single
60
+ * version, or when an entry sets `exact` in a catalog that has not opted in.
14
61
  *
15
62
  * @internal
16
63
  */
@@ -20,14 +67,20 @@ function normalizeCatalogs(input) {
20
67
  if (typeof decl !== "object" || decl === null || typeof decl.packages !== "object" || decl.packages === null) continue;
21
68
  const base = {};
22
69
  const peers = {};
70
+ const exact = {};
23
71
  for (const [pkg, spec] of Object.entries(decl.packages)) {
24
72
  base[pkg] = typeof spec === "string" ? spec : spec.range;
25
73
  if (typeof spec === "object" && spec.peer !== void 0) peers[pkg] = spec.peer;
74
+ if (decl.exact === true) {
75
+ const value = exactEntry(name, pkg, spec);
76
+ if (value !== void 0) exact[pkg] = value;
77
+ } else if (typeof spec === "object" && spec.exact !== void 0) throw new Error(`catalogs: "${pkg}" sets exact, but catalog "${name}" does not set exact: true, so it would be ignored`);
26
78
  }
27
79
  out[name] = base;
28
80
  if (Object.keys(peers).length > 0) out[`${name}:peers`] = peers;
81
+ if (Object.keys(exact).length > 0) out[`${name}:exact`] = exact;
29
82
  }
30
83
  return out;
31
84
  }
32
85
 
33
- export { normalizeCatalogs, rangeOf };
86
+ export { REWRITABLE_RANGE_RE, normalizeCatalogs, rangeOf };
package/cli/discover.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { REWRITABLE_RANGE_RE } from "../catalogs.js";
1
2
  import { findPluginArg, keyName, prop } from "./ast.js";
2
3
  import { Data } from "effect";
3
4
  import { parseSync } from "oxc-parser";
@@ -9,8 +10,6 @@ import { parseSync } from "oxc-parser";
9
10
  * @internal
10
11
  */
11
12
  var DiscoverError = class extends Data.TaggedError("DiscoverError") {};
12
- /** Matches a simple-operator range we can safely rewrite (`^x`, `~x`, or bare `x`). */
13
- const SIMPLE_RANGE_RE = /^(\^|~|)(\d[\w.+-]*)$/;
14
13
  function operatorOf(range) {
15
14
  if (range.startsWith("^")) return "^";
16
15
  if (range.startsWith("~")) return "~";
@@ -76,7 +75,7 @@ function discoverCatalogEntries(source, filename) {
76
75
  const src = prop(value, "source");
77
76
  if (src?.type === "Literal" && (src.value === "registry" || src.value === "workspace")) source = src.value;
78
77
  }
79
- if (!rangeNode || !SIMPLE_RANGE_RE.test(rangeNode.value)) {
78
+ if (!rangeNode || !REWRITABLE_RANGE_RE.test(rangeNode.value)) {
80
79
  skippedRefs.push({
81
80
  catalog,
82
81
  pkg
package/cli/version.js CHANGED
@@ -6,6 +6,6 @@
6
6
  *
7
7
  * @internal
8
8
  */
9
- const CLI_VERSION = "2.4.7";
9
+ const CLI_VERSION = "2.5.0";
10
10
 
11
11
  export { CLI_VERSION };
@@ -3,7 +3,7 @@ import { ResolveError } from "./resolve.js";
3
3
  import { Effect, Result } from "effect";
4
4
  import { resolve } from "node:path";
5
5
  import { Fmt } from "@effected/cli-kit";
6
- import { findWorkspaceRootSync, getWorkspacePackagesSync } from "@effected/workspaces";
6
+ import { WorkspaceDiscoveryError, WorkspacePatternError, findWorkspaceRootSync, getWorkspacePackagesSync } from "@effected/workspaces";
7
7
  import { nodeSyncOps } from "@effected/workspaces/node-sync";
8
8
  import { PendingChangesets } from "@effected/changesets";
9
9
 
@@ -25,10 +25,12 @@ const BUMP_ORDER = {
25
25
  * publishes is the author's decision, made elsewhere — and catalog membership
26
26
  * is already an explicit choice in the consuming config.
27
27
  *
28
- * The sync discovery facade is total by contract — an unreadable or malformed
29
- * manifest is skipped, never raised — which is exactly this resolver's
30
- * degrade-don't-fail contract; the Effect surface (`WorkspaceDiscovery`)
31
- * instead fails typed on any unusable member.
28
+ * This resolver degrades, never fails. The sync discovery facade skips an
29
+ * unreadable or malformed member manifest, but since `@effected/workspaces`
30
+ * 0.46 it throws a `WorkspaceDiscoveryError` or `WorkspacePatternError` when
31
+ * the pattern source itself (`pnpm-workspace.yaml` or the root `package.json`)
32
+ * cannot be read, parsed or compiled. Those two are caught here and read as a
33
+ * workspace with no packages, as before; any other throw propagates.
32
34
  *
33
35
  * Since `@effected/workspaces` 0.19, that enumeration yields the **root
34
36
  * package first** and carries a member whose manifest declares no `version`
@@ -41,7 +43,14 @@ const BUMP_ORDER = {
41
43
  */
42
44
  function readManifests(rootDir) {
43
45
  const out = /* @__PURE__ */ new Map();
44
- for (const pkg of getWorkspacePackagesSync(rootDir, nodeSyncOps)) {
46
+ let packages;
47
+ try {
48
+ packages = getWorkspacePackagesSync(rootDir, nodeSyncOps);
49
+ } catch (error) {
50
+ if (error instanceof WorkspaceDiscoveryError || error instanceof WorkspacePatternError) return out;
51
+ throw error;
52
+ }
53
+ for (const pkg of packages) {
45
54
  const version = pkg.version;
46
55
  if (version === void 0) continue;
47
56
  out.set(pkg.name, {
package/index.d.ts CHANGED
@@ -21,8 +21,9 @@ type PeerStrategy = "lock" | "lock-minor" | "interop";
21
21
  type VersionSource = "registry" | "workspace";
22
22
  /**
23
23
  * A package's version: a bare range, or an object carrying a materialized peer
24
- * range (`peer`), optional CLI recompute `strategy`, and optional CLI version
25
- * `source`.
24
+ * range (`peer`), optional CLI recompute `strategy`, optional CLI version
25
+ * `source`, and an optional `exact` escape for a catalog that opts into the
26
+ * exact variant.
26
27
  *
27
28
  * @public
28
29
  */
@@ -31,6 +32,15 @@ type CatalogPackageSpec = string | {
31
32
  readonly peer?: string;
32
33
  readonly strategy?: PeerStrategy;
33
34
  readonly source?: VersionSource;
35
+ /**
36
+ * The entry's value in the `<name>:exact` catalog, for a range that names
37
+ * no single version (`">=1.2.0 <2.0.0"`), or `false` to leave the entry
38
+ * out of that catalog. Only valid when the declaration sets
39
+ * `exact: true`, and a plain version is rejected on a range the exact
40
+ * value already derives from, since `upgrade` rewrites `range` and
41
+ * would leave a hand-written value stale.
42
+ */
43
+ readonly exact?: string | false;
34
44
  };
35
45
  /**
36
46
  * One catalog's declaration: a map of package name to version spec.
@@ -40,6 +50,16 @@ type CatalogPackageSpec = string | {
40
50
  interface CatalogDeclaration {
41
51
  /** Map of package name to version spec or range object. */
42
52
  readonly packages: Record<string, CatalogPackageSpec>;
53
+ /**
54
+ * Also emit `<name>:exact`, holding each entry's range with its operator
55
+ * stripped (`^0.34.0` becomes `0.34.0`), so a dependent writing
56
+ * `catalog:<name>:exact` publishes an exact version that still follows the
57
+ * catalog. Only a single comparator (`^`, `~`, `>=`, `=` or none) on one
58
+ * version derives; any other range fails the build unless its entry sets
59
+ * `exact` (a value only where `upgrade` never rewrites the range). Where `overridesFromCatalogs` pins a member, the exact catalog
60
+ * names the pinned version.
61
+ */
62
+ readonly exact?: boolean;
43
63
  }
44
64
  /**
45
65
  * A directive that derives `peerDependencyRules.allowedVersions` rules from a
@@ -89,8 +109,9 @@ interface AllowedVersionsFromCatalogs {
89
109
  * would let a dependent writing `catalog:` resolve a newer patch than the
90
110
  * override pins everywhere else, and the graph would carry two copies. Only
91
111
  * 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
112
+ * authored range stays what `upgrade` reads and rewrites, the `:peers`
113
+ * catalog keeps its peer range, and an opted-in `:exact` catalog names the
114
+ * pinned version. When a hand-authored override wins on the
94
115
  * selector, the catalog takes its value if that is an exact version and keeps
95
116
  * the authored range otherwise.
96
117
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-pnpm-config",
3
- "version": "2.4.7",
3
+ "version": "2.5.0",
4
4
  "private": false,
5
5
  "description": "A dogfooding example of our plugin",
6
6
  "repository": {
@@ -36,15 +36,15 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@effect/platform-node": "4.1.3",
39
- "@effected/changesets": "^0.4.0",
40
- "@effected/cli-kit": "^0.28.0",
39
+ "@effected/changesets": "^0.4.1",
40
+ "@effected/cli-kit": "^0.28.1",
41
41
  "@effected/env": "^0.12.0",
42
42
  "@effected/files": "^0.3.0",
43
43
  "@effected/glob": "^0.21.0",
44
- "@effected/npm": "^0.33.0",
44
+ "@effected/npm": "^0.34.0",
45
45
  "@effected/semver": "^0.24.0",
46
- "@effected/walker": "^0.27.0",
47
- "@effected/workspaces": "^0.45.0",
46
+ "@effected/walker": "^0.28.0",
47
+ "@effected/workspaces": "^0.46.0",
48
48
  "@effected/yaml": "^0.30.0",
49
49
  "effect": "4.1.3",
50
50
  "ink": "^8.0.0",
package/plugin/freeze.js CHANGED
@@ -58,7 +58,11 @@ function freeze(config) {
58
58
  return Effect.gen(function* () {
59
59
  const base = {};
60
60
  const manifest = {};
61
- base.catalogs = yield* Schema.decodeUnknownEffect(CatalogsSchema)(normalizeCatalogs(config.catalogs)).pipe(Effect.mapError((error) => new ConfigError({ message: `Invalid catalogs: ${Fmt.describe(error)}` })));
61
+ const normalized = yield* Effect.try({
62
+ try: () => normalizeCatalogs(config.catalogs),
63
+ catch: (error) => new ConfigError({ message: Fmt.describe(error) })
64
+ });
65
+ base.catalogs = yield* Schema.decodeUnknownEffect(CatalogsSchema)(normalized).pipe(Effect.mapError((error) => new ConfigError({ message: `Invalid catalogs: ${Fmt.describe(error)}` })));
62
66
  manifest.catalogs = {
63
67
  strategy: "catalogs",
64
68
  enforcement: "warn"
@@ -86,7 +90,10 @@ function freeze(config) {
86
90
  ...decl.options ? { options: decl.options } : {}
87
91
  };
88
92
  }
89
- base.catalogs = pinCatalogs(base.catalogs, base.overrides, config.overridesFromCatalogs, config.catalogs);
93
+ base.catalogs = yield* Effect.try({
94
+ try: () => pinCatalogs(base.catalogs, base.overrides, config.overridesFromCatalogs, config.catalogs),
95
+ catch: directiveError
96
+ });
90
97
  return {
91
98
  base,
92
99
  manifest,
@@ -84,7 +84,9 @@ function exactVersion(value) {
84
84
  * Freeze each pinned member's catalog value to the exact version its final
85
85
  * override names, so a `catalog:` specifier (which pnpm never matches against
86
86
  * an override) resolves the same version the override pins. Returns a new
87
- * catalogs map; `:peers` catalogs and unpinned members pass through verbatim,
87
+ * catalogs map, and the `:exact` variant names the same version (a winner that
88
+ * is not an exact version throws for a member that variant holds); `:peers`
89
+ * catalogs and unpinned members pass through verbatim,
88
90
  * and a member whose winning override is not an exact version keeps its range.
89
91
  *
90
92
  * @internal
@@ -96,11 +98,17 @@ function pinCatalogs(resolved, overrides, directives, catalogs) {
96
98
  for (const { catalog, name, selector } of derivePins(catalogs, directives)) {
97
99
  const pinned = exactVersion(table[selector]);
98
100
  const current = out[catalog];
101
+ const exact = out[`${catalog}:exact`];
102
+ if (pinned === null && exact !== void 0 && name in exact) throw new Error(`overridesFromCatalogs: override "${selector}" wins with ${JSON.stringify(table[selector])}, which is not an exact version, so catalog "${catalog}:exact" cannot name the version it pins; override with an exact version, or set exact: false on "${name}"`);
99
103
  if (pinned === null || current === void 0 || !(name in current)) continue;
100
104
  out[catalog] = {
101
105
  ...current,
102
106
  [name]: pinned
103
107
  };
108
+ if (exact !== void 0 && name in exact) out[`${catalog}:exact`] = {
109
+ ...exact,
110
+ [name]: pinned
111
+ };
104
112
  }
105
113
  return out;
106
114
  }