rman 2.40.1 → 2.40.3

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
  /**
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.40.1';
1
+ export const version = '2.40.3';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.40.1",
4
+ "version": "2.40.3",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {