rman 2.39.0 → 2.40.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.
@@ -2,6 +2,7 @@ import type { Package } from '../../../core/classes/package.js';
2
2
  import { DependencyUpdater } from '../../../core/interfaces/dependency-updater.js';
3
3
  import { type ExecResult } from '../../../utils/exec.js';
4
4
  import { type NpmRelease, type NpmReleases } from '../../publish-targets/npm/npm-view.js';
5
+ import { CiService } from './services/ci.service.js';
5
6
  /**
6
7
  * npm's answer to `rman deps`: which of a `package.json`'s dependencies have a newer version on the
7
8
  * registry, and which of those can be taken without breaking a rule another dependency states.
@@ -24,6 +25,10 @@ export declare class NodeDependencyUpdater implements DependencyUpdater {
24
25
  /** `name@version` for each move the last `applyPlan` wrote - what a pnpm peer issue is matched
25
26
  * against, to tell the upgrade's issues from the repository's own. */
26
27
  protected written: Set<string>;
28
+ /** pnpm's `minimumReleaseAge` when nothing sets it, in minutes - see `pnpmReleaseAge`. */
29
+ protected readonly pnpmDefaultReleaseAge: number;
30
+ /** The first pnpm with a non-zero default `minimumReleaseAge`; an older one has none. */
31
+ protected readonly pnpmReleaseAgeSince: string;
27
32
  getPlan(ctx: DependencyUpdater.Context, packages: readonly Package[]): Promise<DependencyUpdater.Entry[]>;
28
33
  applyPlan(ctx: DependencyUpdater.Context, plan: readonly DependencyUpdater.Entry[]): Promise<DependencyUpdater.Applied>;
29
34
  /**
@@ -37,6 +42,25 @@ export declare class NodeDependencyUpdater implements DependencyUpdater {
37
42
  * which read the two package managers' own words.
38
43
  */
39
44
  blame(refusal: string, plan: readonly DependencyUpdater.Entry[]): DependencyUpdater.Blame[];
45
+ /**
46
+ * The package manager that installs the repository: the one its lockfile belongs to, else the
47
+ * one `CiService.resolvePackageManager` answers.
48
+ */
49
+ protected installer(ctx: DependencyUpdater.Context): CiService.PackageManager;
50
+ /**
51
+ * In a pnpm repository, holds every dependency of a package that sets no `deps.minAge` to pnpm's
52
+ * own `minimumReleaseAge` and `minimumReleaseAgeExclude` - see `pnpmReleaseAge`.
53
+ */
54
+ protected applyReleaseAge(ctx: DependencyUpdater.Context, decisions: readonly NodeDependencyUpdater.Decision[]): Promise<void>;
55
+ /**
56
+ * pnpm's effective `minimumReleaseAge` (minutes) and `minimumReleaseAgeExclude` at the repository
57
+ * root, as `pnpm config get` reads them - `pnpm-workspace.yaml`, the user's config and the
58
+ * environment - and `pnpmDefaultReleaseAge` when none sets the age.
59
+ */
60
+ protected pnpmReleaseAge(ctx: DependencyUpdater.Context): Promise<NodeDependencyUpdater.ReleaseAge>;
61
+ /** Whether `minimumReleaseAgeExclude` lets `name@version` in: an entry naming the package - a glob
62
+ * such as `@scope/*` - with no version, or with that version among its `||` alternatives. */
63
+ protected releaseAgeExempt(exclude: readonly string[], name: string, version: string): boolean;
40
64
  /**
41
65
  * `npm install --dry-run` at the repository root: npm's own resolver, which refuses a peer
42
66
  * conflict anywhere in the tree with `ERESOLVE`, and writes nothing.
@@ -90,6 +114,8 @@ export declare class NodeDependencyUpdater implements DependencyUpdater {
90
114
  /** Step 1: why the package's own settings leave `release` out - `deps.target` or `deps.minAge` -
91
115
  * or `undefined` when they do not. */
92
116
  protected settingRefusal(d: NodeDependencyUpdater.Decision, release: NpmRelease, time?: Record<string, string>): string | undefined;
117
+ /** A release's age, in the largest unit that reads well - `3 day(s)`, `21 hour(s)`. */
118
+ protected ageText(minutes: number): string;
93
119
  /**
94
120
  * How big a move from `from` to `to` is, **as npm's caret reads it**: anything a `^from` range
95
121
  * would not accept is a `major`, so `0.1.0 -> 0.2.0` is one.
@@ -203,10 +229,18 @@ export declare namespace NodeDependencyUpdater {
203
229
  /** Into `candidates`; `-1` keeps what is declared. */
204
230
  index: number;
205
231
  releases?: Map<string, NpmRelease>;
232
+ /** pnpm's release-age policy, when the package sets no `deps.minAge` of its own - see
233
+ * `applyReleaseAge`. */
234
+ releaseAge?: ReleaseAge;
206
235
  latestTag?: string;
207
236
  reason?: string;
208
237
  error?: string;
209
238
  }
239
+ /** pnpm's `minimumReleaseAge`, in minutes, and its `minimumReleaseAgeExclude`. */
240
+ interface ReleaseAge {
241
+ minutes: number;
242
+ exclude: string[];
243
+ }
210
244
  /** One unmet or missing peer in pnpm's report - see `pnpmPeerIssues`. */
211
245
  interface PnpmPeerIssue {
212
246
  peer: string;
@@ -72,10 +72,18 @@ export class NodeDependencyUpdater {
72
72
  /** `name@version` for each move the last `applyPlan` wrote - what a pnpm peer issue is matched
73
73
  * against, to tell the upgrade's issues from the repository's own. */
74
74
  written = new Set();
75
+ /** pnpm's `minimumReleaseAge` when nothing sets it, in minutes - see `pnpmReleaseAge`. */
76
+ /* Measured on pnpm 12.10.1 rather than read: a release 22 hours old was added to
77
+ * `minimumReleaseAgeExclude` by a plain install, one 25.7 hours old was not. `pnpm config get`
78
+ * answers `null` for it, so the default is the one value that cannot be asked. */
79
+ pnpmDefaultReleaseAge = 1440;
80
+ /** The first pnpm with a non-zero default `minimumReleaseAge`; an older one has none. */
81
+ pnpmReleaseAgeSince = '11.0.0';
75
82
  async getPlan(ctx, packages) {
76
83
  const inRepo = new Set([ctx.repository.rootPackage, ...ctx.repository.packages].map(p => p.name));
77
84
  const decisions = packages.flatMap(pkg => this.collect(pkg, DependencyUpdater.settingsFor(pkg, ctx.options), ctx.options, inRepo));
78
- const withTime = decisions.some(d => d.settings.minAge > 0);
85
+ await this.applyReleaseAge(ctx, decisions);
86
+ const withTime = decisions.some(d => d.settings.minAge > 0 || !!d.releaseAge?.minutes);
79
87
  const registry = await this.fetchAll(ctx, decisions, withTime);
80
88
  for (const d of decisions)
81
89
  this.prepare(d, registry.get(this.sourceOf(d)));
@@ -127,7 +135,7 @@ export class NodeDependencyUpdater {
127
135
  * (`verifyWithPnpm`). yarn and bun are not asked, and a note says so.
128
136
  */
129
137
  async verify(ctx) {
130
- const manager = CiService.resolvePackageManager(ctx.repository);
138
+ const manager = this.installer(ctx);
131
139
  if (manager === 'npm')
132
140
  return this.verifyWithNpm(ctx);
133
141
  if (manager === 'pnpm')
@@ -142,6 +150,101 @@ export class NodeDependencyUpdater {
142
150
  blame(refusal, plan) {
143
151
  return this.pnpmPeerIssues(refusal).length ? this.blamePnpm(refusal, plan) : this.blameNpm(refusal, plan);
144
152
  }
153
+ /**
154
+ * The package manager that installs the repository: the one its lockfile belongs to, else the
155
+ * one `CiService.resolvePackageManager` answers.
156
+ */
157
+ /* **The lockfile first, here and nowhere else in rman.** `deps` asks two questions of the tool
158
+ * that installs - would it take these manifests (`verify`), and what does it let in (`pnpm`'s
159
+ * release age) - and the lockfile is what that tool last wrote. `packageManager.node` answers who
160
+ * *publishes* as well, and the two can differ on purpose: `panates/opra` installs with pnpm and
161
+ * sets `node: npm` so `rman publish` keeps npm's provenance statement, and `verify` then ran
162
+ * `npm install --dry-run` on a pnpm workspace and failed `EUNSUPPORTEDPROTOCOL` on every
163
+ * `workspace:^`, putting the whole upgrade back. Two lockfiles in one directory fall through to
164
+ * the setting, which is the documented way to settle that. */
165
+ installer(ctx) {
166
+ try {
167
+ const found = CiService.detectPackageManager(ctx.repository);
168
+ if (found)
169
+ return found;
170
+ }
171
+ catch {
172
+ /** Two managers' lockfiles: the setting decides, or throws saying how. */
173
+ }
174
+ return CiService.resolvePackageManager(ctx.repository);
175
+ }
176
+ /**
177
+ * In a pnpm repository, holds every dependency of a package that sets no `deps.minAge` to pnpm's
178
+ * own `minimumReleaseAge` and `minimumReleaseAgeExclude` - see `pnpmReleaseAge`.
179
+ */
180
+ /* **The two have to agree, or pnpm settles it behind the user's back.** `deps.minAge` defaults to
181
+ * 0 and pnpm 11+ to a day, so `deps -u` wrote versions pnpm refuses - and pnpm does not refuse
182
+ * them: a plain `pnpm install` adds each one to `minimumReleaseAgeExclude` in
183
+ * `pnpm-workspace.yaml` and says so in one line. Measured on `panates/opra`: six `@nestjs/*@12.3.2`
184
+ * (21 hours old) and `postgrejs@3.14.1` (one hour) were exempted from the supply-chain check that
185
+ * exists for exactly such releases, and it showed up in a commit diff.
186
+ *
187
+ * **pnpm's policy is read, never restated.** Mirroring it in `.rmanrc` was the workaround, and it
188
+ * is two places to keep in step, in days on one side and minutes on the other. An explicit
189
+ * `deps.minAge` or `--min-age` still wins - whoever wrote it decided. */
190
+ async applyReleaseAge(ctx, decisions) {
191
+ const inherits = (d) => d.wanted && ctx.options.minAge === undefined && d.pkg.config.deps?.minAge === undefined;
192
+ if (!decisions.some(inherits) || this.installer(ctx) !== 'pnpm')
193
+ return;
194
+ const policy = await this.pnpmReleaseAge(ctx);
195
+ if (!policy.minutes)
196
+ return;
197
+ for (const d of decisions)
198
+ if (inherits(d))
199
+ d.releaseAge = policy;
200
+ }
201
+ /**
202
+ * pnpm's effective `minimumReleaseAge` (minutes) and `minimumReleaseAgeExclude` at the repository
203
+ * root, as `pnpm config get` reads them - `pnpm-workspace.yaml`, the user's config and the
204
+ * environment - and `pnpmDefaultReleaseAge` when none sets the age.
205
+ */
206
+ async pnpmReleaseAge(ctx) {
207
+ const read = async (key) => {
208
+ const result = await this.pnpm(ctx, `config get ${key} --json`);
209
+ if (result.code)
210
+ return undefined;
211
+ try {
212
+ return JSON.parse(result.stdout?.trim() || 'null');
213
+ }
214
+ catch {
215
+ return undefined;
216
+ }
217
+ };
218
+ const [age, exclude] = await Promise.all([read('minimumReleaseAge'), read('minimumReleaseAgeExclude')]);
219
+ let minutes = Number(age);
220
+ if (age === null || age === undefined || !Number.isFinite(minutes)) {
221
+ const version = (await this.pnpm(ctx, '--version')).stdout?.trim();
222
+ minutes =
223
+ version && semver.valid(version) && semver.gte(version, this.pnpmReleaseAgeSince)
224
+ ? this.pnpmDefaultReleaseAge
225
+ : 0;
226
+ }
227
+ return {
228
+ minutes,
229
+ exclude: Array.isArray(exclude) ? exclude.filter((e) => typeof e === 'string') : [],
230
+ };
231
+ }
232
+ /** Whether `minimumReleaseAgeExclude` lets `name@version` in: an entry naming the package - a glob
233
+ * such as `@scope/*` - with no version, or with that version among its `||` alternatives. */
234
+ releaseAgeExempt(exclude, name, version) {
235
+ return exclude.some(entry => {
236
+ const at = entry.indexOf('@', 1);
237
+ const pattern = at < 0 ? entry : entry.slice(0, at);
238
+ if (!micromatch.isMatch(name, pattern))
239
+ return false;
240
+ if (at < 0)
241
+ return true;
242
+ return entry
243
+ .slice(at + 1)
244
+ .split('||')
245
+ .some(v => v.trim() === version);
246
+ });
247
+ }
145
248
  /**
146
249
  * `npm install --dry-run` at the repository root: npm's own resolver, which refuses a peer
147
250
  * conflict anywhere in the tree with `ERESOLVE`, and writes nothing.
@@ -303,7 +406,10 @@ export class NodeDependencyUpdater {
303
406
  * @typescript-eslint/parser@8.40.0
304
407
  * @typescript-eslint/typescript-estree@8.40.0
305
408
  *
306
- * `missing peer` is read the same way, with no `Installed`. */
409
+ * `missing peer` is read the same way, with no `Installed`. **A range is quoted only when it has
410
+ * a space** - `panates/opra`'s `schema-utils` wanting webpack came back as a bare `^5.112.0:` -
411
+ * and read as anything else it ended the issue before its requirers, so the issue named no
412
+ * package wanting the peer and nothing could be held for it. */
307
413
  pnpmPeerIssues(output) {
308
414
  const issues = [];
309
415
  let issue;
@@ -318,7 +424,7 @@ export class NodeDependencyUpdater {
318
424
  if (!issue)
319
425
  continue;
320
426
  const installed = /^Installed: (\S+)$/.exec(line);
321
- const range = /^(".*"):$/.exec(line);
427
+ const range = line === 'Wanted:' ? null : /^(".*"|\S+):$/.exec(line);
322
428
  const by = /^((?:@[^/@\s]+\/)?[^@\s]+@\S+)$/.exec(line);
323
429
  if (installed)
324
430
  issue.installed = installed[1];
@@ -495,16 +601,30 @@ export class NodeDependencyUpdater {
495
601
  const target = DependencyUpdater.targetFor(d.settings, d.name);
496
602
  if (sizes.indexOf(size) > sizes.indexOf(target.size))
497
603
  return `${size} - ${target.from} is "${target.size}"`;
498
- if (d.settings.minAge > 0) {
604
+ const age = d.releaseAge;
605
+ const rule = d.settings.minAge > 0
606
+ ? { minutes: d.settings.minAge * 1440, from: `deps.minAge is ${d.settings.minAge}` }
607
+ : age?.minutes && !this.releaseAgeExempt(age.exclude, this.sourceOf(d), release.version)
608
+ ? { minutes: age.minutes, from: `pnpm's minimumReleaseAge is ${age.minutes} minutes` }
609
+ : undefined;
610
+ if (rule) {
499
611
  const published = time?.[release.version];
500
612
  if (!published)
501
- return `no publish date to check deps.minAge against`;
502
- const days = Math.floor((Date.now() - Date.parse(published)) / 86_400_000);
503
- if (days < d.settings.minAge)
504
- return `published ${days} day(s) ago - deps.minAge is ${d.settings.minAge}`;
613
+ return `no publish date to check the release age against - ${rule.from}`;
614
+ const minutes = (Date.now() - Date.parse(published)) / 60_000;
615
+ if (minutes < rule.minutes)
616
+ return `published ${this.ageText(minutes)} ago - ${rule.from}`;
505
617
  }
506
618
  return undefined;
507
619
  }
620
+ /** A release's age, in the largest unit that reads well - `3 day(s)`, `21 hour(s)`. */
621
+ ageText(minutes) {
622
+ if (minutes >= 1440)
623
+ return `${Math.floor(minutes / 1440)} day(s)`;
624
+ if (minutes >= 60)
625
+ return `${Math.floor(minutes / 60)} hour(s)`;
626
+ return `${Math.max(0, Math.floor(minutes))} minute(s)`;
627
+ }
508
628
  /**
509
629
  * How big a move from `from` to `to` is, **as npm's caret reads it**: anything a `^from` range
510
630
  * would not accept is a `major`, so `0.1.0 -> 0.2.0` is one.
@@ -35,7 +35,7 @@ const config = {
35
35
  minAge: {
36
36
  target: 'both',
37
37
  cliName: 'min-age',
38
- describe: 'Only move to a version published at least this many days ago',
38
+ describe: "Only move to a version published at least this many days ago - default: pnpm's minimumReleaseAge in a pnpm repository, else 0",
39
39
  type: 'number',
40
40
  },
41
41
  types: {
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.39.0';
1
+ export const version = '2.40.0';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.39.0",
4
+ "version": "2.40.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {