rman 2.40.2 → 2.41.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.
@@ -9,6 +9,11 @@ export declare namespace PublishService {
9
9
  interface Deps {
10
10
  npmViewPackage?: (name: string, cwd: string) => Promise<NpmPackageView | undefined>;
11
11
  }
12
+ /** `applyPlan`'s seams - the registry lookup, and how long to wait before each retry. */
13
+ interface ApplyDeps extends Deps {
14
+ /** One entry per retry, in milliseconds. Default `[10_000, 30_000]`; `[]` never retries. */
15
+ retryDelaysMs?: readonly number[];
16
+ }
12
17
  interface Options extends PackageFilterOptions {
13
18
  /** A package with uncommitted local changes is excluded (status `'skip'`) instead of aborting
14
19
  * the whole plan (status `'error'`) - same as `version`'s own option. Default false. */
@@ -171,6 +176,11 @@ export declare namespace PublishService {
171
176
  * consumers a broken install. A package's own failure doesn't stop unrelated packages elsewhere in
172
177
  * the plan, though, nor one that lists it only where an install does not need it (see
173
178
  * `consumerNeeds`).
179
+ *
180
+ * A publish that fails for a reason that is not the package's - a Sigstore transparency-log
181
+ * conflict, a registry 5xx or 429, a dropped connection - is tried again, up to
182
+ * `deps.retryDelaysMs.length` more times (default after 10 and 30 seconds). Before each retry the
183
+ * registry is asked whether the version landed anyway; if it did, the entry counts as published.
174
184
  */
175
- function applyPlan(repository: Repository, plan: Entry[], options?: ApplyOptions): Promise<Entry[]>;
185
+ function applyPlan(repository: Repository, plan: Entry[], options?: ApplyOptions, deps?: ApplyDeps): Promise<Entry[]>;
176
186
  }
@@ -338,8 +338,28 @@ export var PublishService;
338
338
  * consumers a broken install. A package's own failure doesn't stop unrelated packages elsewhere in
339
339
  * the plan, though, nor one that lists it only where an install does not need it (see
340
340
  * `consumerNeeds`).
341
+ *
342
+ * A publish that fails for a reason that is not the package's - a Sigstore transparency-log
343
+ * conflict, a registry 5xx or 429, a dropped connection - is tried again, up to
344
+ * `deps.retryDelaysMs.length` more times (default after 10 and 30 seconds). Before each retry the
345
+ * registry is asked whether the version landed anyway; if it did, the entry counts as published.
341
346
  */
342
- async function applyPlan(repository, plan, options = {}) {
347
+ /* **Asked for after opra's 1.34.0 release.** `@opra/socketio` failed on
348
+ * `TLOG_CREATE_ENTRY_ERROR (409) an equivalent entry already exists in the transparency log` -
349
+ * provenance signing, nothing about the package - and was not tried again: 18 of 20 packages
350
+ * published, `nestjs-socketio` was blocked behind it, the Publish step failed and the GitHub
351
+ * Release never ran.
352
+ *
353
+ * **The registry check comes before the retry because a 5xx can arrive after the upload.** Run
354
+ * blind, the second attempt is refused for republishing a version, and a release that succeeded
355
+ * would read as failed. A staged entry is not checked - npm does not show its queue - and is
356
+ * retried as it is, leaving a duplicate stage for npm to answer.
357
+ *
358
+ * **Recognized by npm's own output, so the child is piped.** `stdio: 'stderr'` sent npm's output
359
+ * straight to our stderr and the error carried only `Command failed (1)`. Each line still goes to
360
+ * stderr, unchanged, so a `--json` stdout stays one document. Only the listed errors are retried:
361
+ * an auth failure, a version conflict or a bad manifest is the same on the second attempt. */
362
+ async function applyPlan(repository, plan, options = {}, deps = {}) {
343
363
  const failed = new Set();
344
364
  const result = [];
345
365
  /** The tuple is explicit: `[p.name, p]` widens to `(string | Package)[]`, and whether `new Map`
@@ -365,15 +385,38 @@ export var PublishService;
365
385
  /** The plan's own tag and staging decision, not recomputed ones: `getPlan` decided where
366
386
  * this package goes, the reader confirmed that, and `applyPlan` is here to carry it out.
367
387
  * `options.*` is the fallback only for a plan built by something other than `getPlan`. */
368
- await exec(buildPublishCommand(CiService.resolvePackageManager(pkg, options.packageManager), {
388
+ const command = buildPublishCommand(CiService.resolvePackageManager(pkg, options.packageManager), {
369
389
  ...options,
370
390
  tag: entry.distTag ?? options.tag,
371
391
  staged: entry.staged ?? options.staged,
372
- }), {
373
- cwd: publishDir,
374
- app: pkg.repository.app,
375
- stdio: 'stderr',
376
392
  });
393
+ const delays = deps.retryDelaysMs ?? [10_000, 30_000];
394
+ for (let attempt = 0;; attempt++) {
395
+ const output = [];
396
+ try {
397
+ await exec(command, {
398
+ cwd: publishDir,
399
+ app: pkg.repository.app,
400
+ onLine: line => {
401
+ output.push(line);
402
+ process.stderr.write(line + '\n');
403
+ },
404
+ });
405
+ break;
406
+ }
407
+ catch (e) {
408
+ const transient = transientPublishError(output);
409
+ if (!transient || attempt >= delays.length) {
410
+ if (transient)
411
+ e.message += ` (${transient}, after ${attempt + 1} attempts)`;
412
+ throw e;
413
+ }
414
+ await new Promise(resolve => setTimeout(resolve, delays[attempt]));
415
+ if (!(entry.staged ?? options.staged) && (await isPublished(pkg, entry.version, options, deps)))
416
+ break;
417
+ process.stderr.write(`${pkg.name}: ${transient}, trying again (${attempt + 2}/${delays.length + 1})\n`);
418
+ }
419
+ }
377
420
  result.push(entry);
378
421
  }
379
422
  catch (e) {
@@ -485,6 +528,37 @@ function resolveRegistry(pkg, override) {
485
528
  const native = pkg.manifest.raw.publishConfig?.registry;
486
529
  return override || (typeof native === 'string' && native ? native : undefined);
487
530
  }
531
+ /** Why a failed publish is worth trying again, read off npm's output - `undefined` when it is not. */
532
+ /* The pattern names are npm's own error codes. `TLOG_CREATE_ENTRY_ERROR` is the Sigstore conflict
533
+ * opra's release hit; the rest are a registry or a network that did not answer this time. A 4xx
534
+ * other than 429 is left out on purpose: the registry has decided, and asking again changes nothing. */
535
+ function transientPublishError(output) {
536
+ const text = output.join('\n');
537
+ for (const [pattern, label] of TRANSIENT_PUBLISH_ERRORS)
538
+ if (pattern.test(text))
539
+ return label;
540
+ return undefined;
541
+ }
542
+ const TRANSIENT_PUBLISH_ERRORS = [
543
+ [/TLOG_CREATE_ENTRY_ERROR/, 'transparency-log conflict'],
544
+ [
545
+ /\bcode E(5\d\d)\b|\b5\d\d (Internal Server Error|Bad Gateway|Service Unavailable|Gateway Time-?out)\b/i,
546
+ 'registry server error',
547
+ ],
548
+ [/\bcode E429\b|\b429 Too Many Requests\b/i, 'registry rate limit'],
549
+ [/\b(ETIMEDOUT|ECONNRESET|ECONNREFUSED|EAI_AGAIN|ESOCKETTIMEDOUT|EPIPE)\b|socket hang up/, 'network error'],
550
+ ];
551
+ /** Whether the registry already serves `version` of `pkg` - asked past npm's cache. */
552
+ async function isPublished(pkg, version, options, deps) {
553
+ const view = deps.npmViewPackage
554
+ ? await deps.npmViewPackage(pkg.name, pkg.dirname)
555
+ : await npmViewPackage(pkg.name, pkg.dirname, {
556
+ userconfig: options.userconfig,
557
+ registry: resolveRegistry(pkg, options.registry),
558
+ preferOnline: true,
559
+ });
560
+ return !!view?.versions.includes(version);
561
+ }
488
562
  /** npm's own registry, which `PublishService.registryLabel` leaves shown as `npm`. */
489
563
  const NPMJS_HOST = 'registry.npmjs.org';
490
564
  /**
@@ -104,8 +104,10 @@ const config = {
104
104
  },
105
105
  commitMessage: {
106
106
  target: 'config',
107
- describe: 'The commit message for each group this run commits - "{version}" is substituted when a ' +
108
- 'commit\'s own group shares one version. Default "chore(release): v{version}".',
107
+ describe: 'The commit message for each group this run commits - "{version}" and "{name}" (the ' +
108
+ "packages' names, comma-separated) are substituted when a commit's own group shares one " +
109
+ 'version. Default "chore(release): v{version}" with one version line, and ' +
110
+ '"chore(release): <name>@<version>, ..." with several.',
109
111
  type: 'string',
110
112
  },
111
113
  cascade: {
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.40.2';
1
+ export const version = '2.41.0';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.40.2",
4
+ "version": "2.41.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -109,8 +109,12 @@ function escapeRegExp(value) {
109
109
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
110
110
  }
111
111
  /** Turns a `version.commitMessage` template into a matcher for the commits it produces: every
112
- * literal part escaped, each `{version}` placeholder standing in for any semver. */
112
+ * literal part escaped, each `{version}` placeholder standing in for any semver and each `{name}`
113
+ * for any non-empty text (package names, comma-separated). */
113
114
  function templatePattern(template) {
114
- const source = template.split('{version}').map(escapeRegExp).join(SEMVER_SOURCE);
115
+ const source = template
116
+ .split('{version}')
117
+ .map(part => part.split('{name}').map(escapeRegExp).join('.+?'))
118
+ .join(SEMVER_SOURCE);
115
119
  return new RegExp(`^${source}$`);
116
120
  }
@@ -85,10 +85,15 @@ export declare namespace VersionService {
85
85
  /** True for the repository's own release tag, which belongs to no single package. */
86
86
  release?: boolean;
87
87
  }
88
- /** `.rmanrc version.commitMessage` (root-level; `{version}` is replaced when every bumped package
89
- * in this commit shares one version) - defaults to `"chore(release): v{version}"`, or a plain
90
- * listing of `name@version` pairs when this particular commit spans different versions (a
91
- * cross-group ripple can land a lone forced patch in a group that otherwise didn't move). */
88
+ /**
89
+ * The message of one group's release commit.
90
+ *
91
+ * `.rmanrc version.commitMessage` (root-level) when it is set and every package in the commit
92
+ * shares one version - `{version}` is that version, `{name}` the packages' names, comma-separated.
93
+ * Unset, `chore(release): v{version}` while the repository releases along one version line, and
94
+ * `chore(release): <name>@<version>, ...` once it releases along several, so each commit says what
95
+ * it released. A commit spanning different versions always takes that listing form.
96
+ */
92
97
  function buildCommitMessage(repository: Repository, entries: VersionPlanService.Entry[], messageOverride?: string): string;
93
98
  /**
94
99
  * A `version.<slot>` value: one step, or several to run in sequence - the same shape, and now the
@@ -6,7 +6,7 @@ import { Manifest } from '../core/interfaces/manifest.js';
6
6
  import { GitHelper } from '../utils/git.js';
7
7
  import { ROOT_SELECTOR } from '../utils/package-filter.js';
8
8
  import { expandReleaseTag, isCalendarVersion } from '../utils/release-version.js';
9
- import { groupKeyOf } from '../utils/version-group.js';
9
+ import { groupKeyOf, versionLineCount } from '../utils/version-group.js';
10
10
  import { stampVersionLabel } from '../utils/version-stamp.js';
11
11
  import { ChangeHashService } from './change-hash.service.js';
12
12
  import { changelogGroupBy } from './changelog.service.js';
@@ -301,22 +301,39 @@ export class VersionService extends Service {
301
301
  }
302
302
  }
303
303
  (function (VersionService) {
304
- /** `.rmanrc version.commitMessage` (root-level; `{version}` is replaced when every bumped package
305
- * in this commit shares one version) - defaults to `"chore(release): v{version}"`, or a plain
306
- * listing of `name@version` pairs when this particular commit spans different versions (a
307
- * cross-group ripple can land a lone forced patch in a group that otherwise didn't move). */
304
+ /**
305
+ * The message of one group's release commit.
306
+ *
307
+ * `.rmanrc version.commitMessage` (root-level) when it is set and every package in the commit
308
+ * shares one version - `{version}` is that version, `{name}` the packages' names, comma-separated.
309
+ * Unset, `chore(release): v{version}` while the repository releases along one version line, and
310
+ * `chore(release): <name>@<version>, ...` once it releases along several, so each commit says what
311
+ * it released. A commit spanning different versions always takes that listing form.
312
+ */
313
+ /* **The listing once there is more than one line, because one message per commit cannot then name
314
+ * a release.** Reported from `syncbridge-io/syncbridge-extensions`: nine packages, each its own
315
+ * line, and every release left nine commits reading `chore(release): v2.1.0` - `git log` could not
316
+ * say which commit released which package. One line keeps the old message, so a repository whose
317
+ * packages move together sees no change; the test is `versionLineCount`, the same structural
318
+ * question that makes the tag pattern `{name}@*`, so the commit and its tag name the same thing.
319
+ *
320
+ * Both forms are ones `ConventionalCommitsService.isReleaseCommit` already recognizes - the listing
321
+ * is the cross-group-ripple shape - so no history needed a new matcher. */
308
322
  function buildCommitMessage(repository, entries, messageOverride) {
309
323
  const versions = new Set(entries.map(e => e.to));
324
+ const listing = `chore(release): ${entries.map(e => `${e.package.name}@${e.to}`).join(', ')}`;
310
325
  if (versions.size === 1) {
311
326
  const template = messageOverride ?? repository.rootPackage.config?.version?.commitMessage;
312
327
  const version = entries[0].to;
313
- if (typeof template === 'string' && template)
314
- return template.replace(/\{version\}/g, version);
315
- return `chore(release): v${version}`;
328
+ if (typeof template === 'string' && template) {
329
+ const names = entries.map(e => e.package.name).join(', ');
330
+ return template.replace(/\{version\}/g, version).replace(/\{name\}/g, names);
331
+ }
332
+ return versionLineCount(entries[0].package) > 1 ? listing : `chore(release): v${version}`;
316
333
  }
317
334
  if (messageOverride)
318
335
  return messageOverride;
319
- return `chore(release): ${entries.map(e => `${e.package.name}@${e.to}`).join(', ')}`;
336
+ return listing;
320
337
  }
321
338
  VersionService.buildCommitMessage = buildCommitMessage;
322
339
  /**