rman 2.41.3 → 2.42.1

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.
@@ -123,7 +123,8 @@ export declare namespace PublishService {
123
123
  *
124
124
  * Otherwise the registry decides, via one `npmViewPackage` per remaining package (run
125
125
  * concurrently): **the local version being among the published `versions`** is `'up-to-date'`,
126
- * anything else - including never having been published at all - is `'publish'`. Deliberately not
126
+ * anything else - including never having been published at all - is `'publish'`, and a lookup
127
+ * the registry gave no answer to (no access, no network) is `'error'`. Deliberately not
127
128
  * a comparison against `latest`, which answers a different question and disagrees with this one
128
129
  * the moment a prerelease ships under its own dist-tag; see `npmViewPackage`.
129
130
  *
@@ -144,6 +145,10 @@ export declare namespace PublishService {
144
145
  * or `undefined` where it names none, or names npm's own registry. What `rman list` shows in
145
146
  * place of `npm`. */
146
147
  function registryLabel(pkg: Package): string | undefined;
148
+ /** The registry `pkg` publishes to when the run names none - its `publishConfig.registry` - or
149
+ * `undefined` to let npm resolve `.npmrc` itself. Pass it to `npmViewPackage` to ask the registry
150
+ * the publish will use. */
151
+ function registryOf(pkg: Package): string | undefined;
147
152
  function getPlan(repository: Repository, options?: Options, deps?: Deps): Promise<Entry[]>;
148
153
  interface WaitOptions {
149
154
  /** As in `Options` - the registry each package is asked on is resolved the same way. */
@@ -80,6 +80,8 @@ function preparePublishManifest(pkg, publishDir, packagesByName) {
80
80
  * decides from the manifest this produces, so the rule here *is* the publish rule - a preset
81
81
  * writing the build directory's manifest must apply the same one.
82
82
  * - `publishConfig.directory` - it pointed *here*; kept, it would point one level deeper again.
83
+ * - `publishConfig.linkDirectory` - pnpm's switch for linking `directory` inside the workspace, which
84
+ * means nothing once `directory` is gone and nothing to a consumer.
83
85
  */
84
86
  function derivePublishManifest(pkg, packagesByName) {
85
87
  const json = structuredClone(pkg.manifest.raw);
@@ -96,6 +98,7 @@ function derivePublishManifest(pkg, packagesByName) {
96
98
  }
97
99
  if (json.publishConfig) {
98
100
  delete json.publishConfig.directory;
101
+ delete json.publishConfig.linkDirectory;
99
102
  if (!Object.keys(json.publishConfig).length)
100
103
  delete json.publishConfig;
101
104
  }
@@ -143,7 +146,8 @@ export var PublishService;
143
146
  *
144
147
  * Otherwise the registry decides, via one `npmViewPackage` per remaining package (run
145
148
  * concurrently): **the local version being among the published `versions`** is `'up-to-date'`,
146
- * anything else - including never having been published at all - is `'publish'`. Deliberately not
149
+ * anything else - including never having been published at all - is `'publish'`, and a lookup
150
+ * the registry gave no answer to (no access, no network) is `'error'`. Deliberately not
147
151
  * a comparison against `latest`, which answers a different question and disagrees with this one
148
152
  * the moment a prerelease ships under its own dist-tag; see `npmViewPackage`.
149
153
  *
@@ -195,6 +199,13 @@ export var PublishService;
195
199
  }
196
200
  }
197
201
  PublishService.registryLabel = registryLabel;
202
+ /** The registry `pkg` publishes to when the run names none - its `publishConfig.registry` - or
203
+ * `undefined` to let npm resolve `.npmrc` itself. Pass it to `npmViewPackage` to ask the registry
204
+ * the publish will use. */
205
+ function registryOf(pkg) {
206
+ return resolveRegistry(pkg, undefined);
207
+ }
208
+ PublishService.registryOf = registryOf;
198
209
  async function getPlan(repository, options = {}, deps = {}) {
199
210
  const git = new GitHelper({ cwd: repository.dirname });
200
211
  const packages = filterPackages(repository.getPackages({ toposort: true }), options).filter(pkg => options.shipsHere?.(pkg) ?? true);
@@ -260,7 +271,16 @@ export var PublishService;
260
271
  }
261
272
  }
262
273
  await Promise.all(toCheck.map(async (pkg) => {
263
- const view = await viewPackage(pkg);
274
+ /** A registry that gave no answer is an `'error'`, never "never published" - see
275
+ * `npmViewPackage`. */
276
+ let view;
277
+ try {
278
+ view = await viewPackage(pkg);
279
+ }
280
+ catch (e) {
281
+ entries.set(pkg.name, { package: pkg, version: pkg.version, status: 'error', reason: e.message });
282
+ return;
283
+ }
264
284
  const registryVersion = view?.latest;
265
285
  /** **This version**, not `latest` - the two part company the moment a prerelease is
266
286
  * published under its own dist-tag, and `latest` then never moves however many betas go
@@ -315,7 +335,9 @@ export var PublishService;
315
335
  });
316
336
  while (pending.size) {
317
337
  await Promise.all([...pending].map(async (entry) => {
318
- if ((await view(entry.package))?.versions.includes(entry.version))
338
+ /** A failed round is "not yet": the next one asks again, and the deadline still holds. */
339
+ const answer = await view(entry.package).catch(() => undefined);
340
+ if (answer?.versions.includes(entry.version))
319
341
  pending.delete(entry);
320
342
  }));
321
343
  const left = deadline - Date.now();
@@ -538,16 +560,23 @@ const TRANSIENT_PUBLISH_ERRORS = [
538
560
  [/\bcode E429\b|\(status 429\b|\b429 Too Many Requests\b/i, 'registry rate limit'],
539
561
  [/\b(ETIMEDOUT|ECONNRESET|ECONNREFUSED|EAI_AGAIN|ESOCKETTIMEDOUT|EPIPE)\b|socket hang up/, 'network error'],
540
562
  ];
541
- /** Whether the registry already serves `version` of `pkg` - asked past npm's cache. */
563
+ /** Whether the registry already serves `version` of `pkg` - asked past npm's cache. A lookup that
564
+ * gets no answer is `false`: the retry it guards then tries the publish again, which the registry
565
+ * refuses if the version did land. */
542
566
  async function isPublished(pkg, version, options, deps) {
543
- const view = deps.npmViewPackage
544
- ? await deps.npmViewPackage(pkg.name, pkg.dirname)
545
- : await npmViewPackage(pkg.name, pkg.dirname, {
546
- userconfig: options.userconfig,
547
- registry: resolveRegistry(pkg, options.registry),
548
- preferOnline: true,
549
- });
550
- return !!view?.versions.includes(version);
567
+ try {
568
+ const view = deps.npmViewPackage
569
+ ? await deps.npmViewPackage(pkg.name, pkg.dirname)
570
+ : await npmViewPackage(pkg.name, pkg.dirname, {
571
+ userconfig: options.userconfig,
572
+ registry: resolveRegistry(pkg, options.registry),
573
+ preferOnline: true,
574
+ });
575
+ return !!view?.versions.includes(version);
576
+ }
577
+ catch {
578
+ return false;
579
+ }
551
580
  }
552
581
  /** npm's own registry, which `PublishService.registryLabel` leaves shown as `npm`. */
553
582
  const NPMJS_HOST = 'registry.npmjs.org';
@@ -1,6 +1,7 @@
1
1
  import type { Package } from '../../../../core/classes/package.js';
2
2
  import { VersionPlanService } from '../../../../services/version-plan.service.js';
3
3
  import type { GitHelper } from '../../../../utils/git.js';
4
+ import { type NpmPackageView } from '../../../publish-targets/npm/npm-view.js';
4
5
  /**
5
6
  * How a release is planned for an npm repository.
6
7
  *
@@ -39,4 +40,13 @@ export declare class NodeVersionPlanService extends VersionPlanService {
39
40
  * dependencies from source may not need a release for any of it.
40
41
  */
41
42
  protected cascade(bump: string): VersionPlanService.Cascade;
43
+ /**
44
+ * Every version of `pkg` on the registry it publishes to - `[]` for a package the npm target
45
+ * leaves alone (private, `publish.skip`, or shipping elsewhere), and for one never published.
46
+ *
47
+ * @throws {NpmViewError} When the registry gives no answer (no token, no network).
48
+ */
49
+ protected publishedVersions(pkg: Package): Promise<readonly string[]>;
50
+ /** `npm view` of `pkg`, asked of the registry its publish uses. */
51
+ protected registryView(pkg: Package): Promise<NpmPackageView | undefined>;
42
52
  }
@@ -1,5 +1,9 @@
1
+ import { skipReasonFor, targetsOf } from '../../../../core/interfaces/publish-target.js';
1
2
  import { ChangeHashService } from '../../../../services/change-hash.service.js';
2
3
  import { VersionPlanService } from '../../../../services/version-plan.service.js';
4
+ import { NPM_TARGET } from '../../../publish-targets/npm/npm-publish-target.js';
5
+ import { npmViewPackage } from '../../../publish-targets/npm/npm-view.js';
6
+ import { PublishService } from './publish.service.js';
3
7
  /**
4
8
  * How a release is planned for an npm repository.
5
9
  *
@@ -71,6 +75,22 @@ export class NodeVersionPlanService extends VersionPlanService {
71
75
  * floor is wrong, which is a broken install. */
72
76
  return CASCADE_BY_BUMP[bump] ?? 'group';
73
77
  }
78
+ /**
79
+ * Every version of `pkg` on the registry it publishes to - `[]` for a package the npm target
80
+ * leaves alone (private, `publish.skip`, or shipping elsewhere), and for one never published.
81
+ *
82
+ * @throws {NpmViewError} When the registry gives no answer (no token, no network).
83
+ */
84
+ async publishedVersions(pkg) {
85
+ const target = targetsOf(pkg.repository.app, pkg).find(t => t.name === NPM_TARGET);
86
+ if (!target || skipReasonFor(pkg, target))
87
+ return [];
88
+ return (await this.registryView(pkg))?.versions ?? [];
89
+ }
90
+ /** `npm view` of `pkg`, asked of the registry its publish uses. */
91
+ registryView(pkg) {
92
+ return npmViewPackage(pkg.name, pkg.dirname, { registry: PublishService.registryOf(pkg) });
93
+ }
74
94
  }
75
95
  /** semver's bump names against how far each has to reach - see `NodeVersionPlanService.cascade`. */
76
96
  const CASCADE_BY_BUMP = {
@@ -7,26 +7,22 @@ export interface NpmPackageView {
7
7
  /** Every version ever published, `latest` included. */
8
8
  versions: string[];
9
9
  }
10
+ /** A registry lookup that got no answer - no access, no network, a server error - as opposed to
11
+ * the registry answering that the package does not exist. */
12
+ export declare class NpmViewError extends Error {
13
+ /** npm's own error code: `E401`, `E403`, `ECONNREFUSED`, ... - `undefined` when npm gave none. */
14
+ readonly code?: string;
15
+ constructor(name: string, code: string | undefined, summary: string | undefined, options?: {
16
+ cause?: unknown;
17
+ });
18
+ }
10
19
  /**
11
- * `npm view <name> version versions --json` - `undefined` for anything that is not an answer (never
12
- * published, no network, private or restricted with no access). Catch-everything on purpose: every
13
- * caller treats "no answer" as a legitimate state rather than a failure.
14
- *
15
- * **Two fields in one call, because the two questions are genuinely different and `publish` needs
16
- * both.** Whether *this* version is already out there decides `up-to-date` vs `publish`, and only
17
- * `versions` can answer it; what `latest` points at is what the plan *reports*, so a reader can see
18
- * where the registry stands. Asking `latest` alone was the same approximation in both roles, and it
19
- * is wrong in both directions: a prerelease on its own dist-tag never moves `latest`, so `publish`
20
- * kept proposing an already-published version until npm answered 403; and a package whose local
21
- * version is *behind* `latest` was proposed just as wrongly.
20
+ * `npm view <name> version versions --json` - `undefined` when the registry answers that the package
21
+ * does not exist (E404, which is also how npmjs.org answers a restricted package to a reader without
22
+ * access), the view otherwise.
22
23
  *
23
- * **`versions` is normalized to an array defensively, and the reason is what happens if it is
24
- * not.** `includes` exists on a string too, so a bare `"1.0.0"` would answer `versions.includes()`
25
- * without any error at all - and answer it by substring, where `"1.0.10".includes("1.0.1")` is
26
- * `true` (measured). npm's own `--json` output *is* a real array here on this npm (measured: a
27
- * single-entry `maintainers` comes back as `[...]`, not unwrapped), so this guards a shape
28
- * difference across npm versions rather than one I reproduced - but a silent wrong answer about
29
- * whether a version is published is worth two lines.
24
+ * @throws {NpmViewError} When the registry gave no answer: no access (E401/E403), no network, a
25
+ * server error.
30
26
  */
31
27
  export declare function npmViewPackage(name: string, cwd: string, options?: {
32
28
  registry?: string;
@@ -72,7 +68,7 @@ export interface NpmReleases {
72
68
  * the package's `dist-tags` (and `time`, when `withTime`) - two calls, run at once. `undefined` when
73
69
  * the registry gave no answer at all.
74
70
  *
75
- * **Not catch-everything, unlike the two above.** A name the registry does not know is an answer
71
+ * **Not catch-everything, unlike `npmViewVersion`.** A name the registry does not know is an answer
76
72
  * `rman deps` has to report, not a state it can treat as "nothing newer".
77
73
  */
78
74
  export declare function npmViewReleases(name: string, range: string, cwd: string, options?: {
@@ -1,9 +1,33 @@
1
1
  import { execFile } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
+ /** A registry lookup that got no answer - no access, no network, a server error - as opposed to
4
+ * the registry answering that the package does not exist. */
5
+ export class NpmViewError extends Error {
6
+ /** npm's own error code: `E401`, `E403`, `ECONNREFUSED`, ... - `undefined` when npm gave none. */
7
+ code;
8
+ constructor(name, code, summary, options) {
9
+ const hint = code === 'E401' || code === 'E403' ? ' - is a token for this registry configured (.npmrc, NODE_AUTH_TOKEN)?' : '';
10
+ super(`cannot read ${name} from the registry: ${summary || code || 'npm view failed'}${hint}`, options);
11
+ this.name = 'NpmViewError';
12
+ this.code = code;
13
+ }
14
+ }
3
15
  /**
4
- * `npm view <name> version versions --json` - `undefined` for anything that is not an answer (never
5
- * published, no network, private or restricted with no access). Catch-everything on purpose: every
6
- * caller treats "no answer" as a legitimate state rather than a failure.
16
+ * `npm view <name> version versions --json` - `undefined` when the registry answers that the package
17
+ * does not exist (E404, which is also how npmjs.org answers a restricted package to a reader without
18
+ * access), the view otherwise.
19
+ *
20
+ * @throws {NpmViewError} When the registry gave no answer: no access (E401/E403), no network, a
21
+ * server error.
22
+ */
23
+ /* **Only E404 means "never published".** This was catch-everything, and `publish` reads `undefined`
24
+ * as "never published": reported from peacox-ui, a GitHub Packages repository read without a token
25
+ * (`NPM_CONFIG_USERCONFIG=/dev/null`) planned 0.9.24 of both packages as `never published`, though
26
+ * the registry held 90 and 110 versions. Measured, npm answers that with `code E401` and
27
+ * `401 Unauthorized ... authentication token not provided`; a missing package with `code E404`; a
28
+ * dead address with `code ECONNREFUSED` - each as a JSON `error` object on stdout under `--json`, and
29
+ * exit 1. A plan that cannot see the registry now says so instead of proposing a republish, or - the
30
+ * worse half - letting `version` pick a number the registry already has.
7
31
  *
8
32
  * **Two fields in one call, because the two questions are genuinely different and `publish` needs
9
33
  * both.** Whether *this* version is already out there decides `up-to-date` vs `publish`, and only
@@ -39,8 +63,11 @@ export async function npmViewPackage(name, cwd, options = {}) {
39
63
  const raw = JSON.parse(text);
40
64
  return { latest: raw.version, versions: toVersionList(raw.versions) };
41
65
  }
42
- catch {
43
- return undefined;
66
+ catch (e) {
67
+ const { code, summary } = npmErrorOf(e);
68
+ if (code === 'E404')
69
+ return undefined;
70
+ throw new NpmViewError(name, code, summary, { cause: e });
44
71
  }
45
72
  }
46
73
  /**
@@ -72,7 +99,7 @@ export async function npmViewVersion(name, cwd, options = {}) {
72
99
  * the package's `dist-tags` (and `time`, when `withTime`) - two calls, run at once. `undefined` when
73
100
  * the registry gave no answer at all.
74
101
  *
75
- * **Not catch-everything, unlike the two above.** A name the registry does not know is an answer
102
+ * **Not catch-everything, unlike `npmViewVersion`.** A name the registry does not know is an answer
76
103
  * `rman deps` has to report, not a state it can treat as "nothing newer".
77
104
  */
78
105
  /* **One call returns every version in the range.** npm answers a range with an array holding one
@@ -105,6 +132,23 @@ export async function npmViewReleases(name, range, cwd, options = {}) {
105
132
  time: meta.time,
106
133
  };
107
134
  }
135
+ /** npm's error code and summary from a failed call: the JSON `error` object `--json` prints on
136
+ * stdout, else the `npm error code X` line on stderr. */
137
+ function npmErrorOf(e) {
138
+ const stdout = String(e?.stdout ?? '').trim();
139
+ if (stdout) {
140
+ try {
141
+ const error = JSON.parse(stdout)?.error;
142
+ if (error?.code)
143
+ return { code: String(error.code), summary: error.summary ? String(error.summary) : undefined };
144
+ }
145
+ catch {
146
+ /* not JSON - fall through to stderr */
147
+ }
148
+ }
149
+ const code = /npm (?:error|ERR!) code (\S+)/.exec(String(e?.stderr ?? ''))?.[1];
150
+ return { code, summary: code ? undefined : e?.message };
151
+ }
108
152
  function toVersionList(versions) {
109
153
  if (Array.isArray(versions))
110
154
  return versions;
@@ -14,8 +14,8 @@ export const SPM_TARGET = 'spm';
14
14
  * --json` answers it, as `npm view` does for the npm target - `up-to-date` when the version is
15
15
  * listed, `publish` when it is not, `error` when the lookup itself failed.
16
16
  */
17
- /* **A failed lookup is an `'error'`, never "not published"** - the opposite of the npm and
18
- * cloudflare checks, on purpose. Their catch-everything shape is a measured cost on the npm side
17
+ /* **A failed lookup is an `'error'`, never "not published"** - as the npm check's is now too (the
18
+ * cloudflare one is still catch-everything). Catch-everything was a measured cost on the npm side
19
19
  * (`npmViewPackage` read a failed lookup as "never published" and proposed a republish every run),
20
20
  * and `spm view` was asked for with a distinct failure exit exactly so this one need not guess.
21
21
  *
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.41.3';
1
+ export const version = '2.42.1';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.41.3",
4
+ "version": "2.42.1",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -17,7 +17,7 @@
17
17
  "js-yaml": "^5.5.0",
18
18
  "micromatch": "^4.0.8",
19
19
  "power-tasks": "^1.14.2",
20
- "semver": "^7.8.5",
20
+ "semver": "^7.8.6",
21
21
  "signal-exit": "^4.1.0",
22
22
  "yargs": "^18.2.0"
23
23
  },
@@ -5,7 +5,7 @@ import { Package } from '../core/classes/package.js';
5
5
  import { Repository } from '../core/classes/repository.js';
6
6
  import { Service } from '../core/classes/service.js';
7
7
  import { dirtyReason, GitHelper } from '../utils/git.js';
8
- import { expandReleaseTag, isCalendarVersion, releaseTagPattern } from '../utils/release-version.js';
8
+ import { isCalendarVersion, releaseTagPattern, repositoryReleaseTag } from '../utils/release-version.js';
9
9
  import { ChangeHashService } from './change-hash.service.js';
10
10
  /**
11
11
  * A service class - see `ListService` for the shape and `Service` for the three measured
@@ -48,7 +48,7 @@ export class GithubReleaseService extends Service {
48
48
  },
49
49
  ];
50
50
  }
51
- const tag = releaseTagFor(root);
51
+ const tag = repositoryReleaseTag(root, root.version);
52
52
  const dirtyFiles = await git.listDirtyFiles();
53
53
  if (dirtyFiles.length) {
54
54
  return [
@@ -130,15 +130,7 @@ export class GithubReleaseService extends Service {
130
130
  }
131
131
  const GITHUB_API = 'https://api.github.com';
132
132
  const GITHUB_UPLOADS = 'https://uploads.github.com';
133
- /** The tag naming this repository's release. A calendar root version means several version lines,
134
- * so the release needs a name of its own (`release-*`); a plain one means every package shares it,
135
- * and that shared version's tag already *is* the release. */
136
- function releaseTagFor(root) {
137
- return isCalendarVersion(root.version)
138
- ? expandReleaseTag(root, root.version)
139
- : ChangeHashService.expandTag(root, root.version);
140
- }
141
- /** The glob matching the tags `releaseTagFor` produces - for stepping back to the previous one. */
133
+ /** The glob matching the tags `repositoryReleaseTag` produces - for stepping back to the previous one. */
142
134
  function releaseTagGlob(root) {
143
135
  const pattern = isCalendarVersion(root.version) ? releaseTagPattern(root) : ChangeHashService.tagPattern(root);
144
136
  return pattern.replace('{name}', root.name);
@@ -16,6 +16,9 @@ import { type PackageFilterOptions } from '../utils/package-filter.js';
16
16
  * entirely. Declared before the namespace, which TypeScript requires for the merge.
17
17
  */
18
18
  export declare class RunService extends Service {
19
+ /** The environment variable a run hands its children: every script already running above them,
20
+ * one `runKey` per line, so a nested rman can tell it was asked to run one of them again. */
21
+ protected readonly runStackVar: string;
19
22
  runScript(script: string, options?: RunService.Options & {
20
23
  commandName?: string;
21
24
  }): Promise<void>;
@@ -91,6 +94,9 @@ export declare class RunService extends Service {
91
94
  * as prose, or as a `message` event under `--json`, where stdout belongs to the events. Also in the
92
95
  * log file when there is one.
93
96
  */
97
+ /** What identifies one script of one package in `runStackVar`: where it sits in the config (or
98
+ * the command, for a `forEachPackage` sweep), the plan's name and its directory. */
99
+ protected runKey(plan: RunService.PackagePlan, commandName: string): string;
94
100
  protected say(level: 'info' | 'error', message: string): void;
95
101
  /**
96
102
  * Who renders a run: the panel when it draws, plain lines when it does not, neither under `--json`
@@ -23,6 +23,9 @@ import { runBin } from '../utils/run-bin.js';
23
23
  * entirely. Declared before the namespace, which TypeScript requires for the merge.
24
24
  */
25
25
  export class RunService extends Service {
26
+ /** The environment variable a run hands its children: every script already running above them,
27
+ * one `runKey` per line, so a nested rman can tell it was asked to run one of them again. */
28
+ runStackVar = 'RMAN_RUN_STACK';
26
29
  async runScript(script, options = {}) {
27
30
  const repository = this.repository;
28
31
  const commandName = options.commandName || 'run';
@@ -157,6 +160,26 @@ export class RunService extends Service {
157
160
  */
158
161
  async schedule(options) {
159
162
  const { panel, concurrency, commandName } = options;
163
+ /**
164
+ * **A script that runs itself is refused before anything starts.** Reported from peacox-ui: a
165
+ * local rman 2.34 that could not read `pnpm-workspace.yaml` took the monorepo for one package,
166
+ * ran the root's `build` script - `rman build` - and that rman did the same, a new nested rman
167
+ * every ~20s until stopped. The same loop is one line away for anyone: a package's own `build`
168
+ * that calls `rman build`, or a root `before` hook that calls the command it hooks. Each run
169
+ * passes the scripts it is running down to its children (`runStackVar`); a run asked for one of
170
+ * those again fails here instead of recursing.
171
+ */
172
+ const parentStack = (process.env[this.runStackVar] ?? '').split('\n').filter(Boolean);
173
+ for (const plan of [options.before, ...options.plans, options.after]) {
174
+ if (!plan || !parentStack.includes(this.runKey(plan, commandName)))
175
+ continue;
176
+ const err = new Error(`"${plan.at?.[plan.at.length - 1] ?? commandName}" of ${plan.label} is already running in a parent rman - ` +
177
+ `its script calls rman to run itself, which would never end. Check the script in ${plan.cwd}.`);
178
+ this.say('error', err.message);
179
+ err.logged = true;
180
+ throw err;
181
+ }
182
+ const stackFor = (plan) => [...parentStack, this.runKey(plan, commandName)].join('\n');
160
183
  /** Every event of the run is produced once, here, and rendered by each reporter - the screen
161
184
  * (panel or plain lines, or neither under `--json`) and the log. See `Reporter`. */
162
185
  const reporters = this.reportersFor(commandName, panel);
@@ -241,7 +264,7 @@ export class RunService extends Service {
241
264
  cwd,
242
265
  stdio: 'pipe',
243
266
  onLine,
244
- env: Object.keys(childEnv).length ? childEnv : undefined,
267
+ env: { ...childEnv, [this.runStackVar]: stackFor(plan) },
245
268
  app: pkg.repository.app,
246
269
  });
247
270
  }
@@ -536,6 +559,11 @@ export class RunService extends Service {
536
559
  * as prose, or as a `message` event under `--json`, where stdout belongs to the events. Also in the
537
560
  * log file when there is one.
538
561
  */
562
+ /** What identifies one script of one package in `runStackVar`: where it sits in the config (or
563
+ * the command, for a `forEachPackage` sweep), the plan's name and its directory. */
564
+ runKey(plan, commandName) {
565
+ return `${plan.at?.join('.') ?? commandName}:${plan.name}@${plan.cwd}`;
566
+ }
539
567
  say(level, message) {
540
568
  for (const reporter of this.reportersFor('run'))
541
569
  reporter.report({ event: 'message', level, message });
@@ -77,6 +77,11 @@ export declare abstract class VersionPlanService {
77
77
  * commits count toward the published packages that carry it (`bundledPackages`).
78
78
  */
79
79
  protected notVersionedReason(pkg: Package): string | undefined;
80
+ /**
81
+ * How many version lines the repository has - the distinct groups of every package it versions,
82
+ * whatever this run was filtered to. `buildRootEntry`'s `groupCount`.
83
+ */
84
+ protected versionLines(repository: Repository): number;
80
85
  /**
81
86
  * The commit a package's changes are measured **since** - its last release boundary, or
82
87
  * `undefined` for a package that has never been released (the caller then reads the whole
@@ -105,6 +110,17 @@ export declare abstract class VersionPlanService {
105
110
  * wrong one here is invisible - it produces a plan that simply releases too little.
106
111
  */
107
112
  protected abstract cascade(bump: string): VersionPlanService.Cascade;
113
+ /**
114
+ * Every version of `pkg` its registry already has - `[]` when it has none, or when the package is
115
+ * not published to a registry at all. A computed version never lands on or below the highest of
116
+ * these (see `computeGroupPlan`).
117
+ *
118
+ * The core knows no registry, so it answers `[]`; a technology overrides it.
119
+ *
120
+ * @throws When the registry gives no answer - a plan that cannot see the registry must not pick a
121
+ * number as though it had.
122
+ */
123
+ protected publishedVersions(pkg: Package): Promise<readonly string[]>;
108
124
  /**
109
125
  * **Which planner answers for one package: its own technology's.**
110
126
  *
@@ -208,7 +224,7 @@ export declare abstract class VersionPlanService {
208
224
  * narrow reading failed. A repository in lockstep therefore keeps it when the number is chosen
209
225
  * by hand, with no cascade involved.
210
226
  */
211
- protected computeGroupPlan(key: string, members: Package[], changeByPackage: Map<string, VersionPlanService.Change>, explicitVersion: string | undefined, preid: string | undefined, entries: Map<string, VersionPlanService.Entry>): void;
227
+ protected computeGroupPlan(key: string, members: Package[], changeByPackage: Map<string, VersionPlanService.Change>, explicitVersion: string | undefined, preid: string | undefined, entries: Map<string, VersionPlanService.Entry>, published?: ReadonlyMap<string, readonly string[]>): void;
212
228
  /**
213
229
  * A package depending on another group's bumped package always receives its scheme's **smallest**
214
230
  * bump, computed from its *own* group's current ceiling (the highest `to`/version among its group
@@ -222,7 +238,13 @@ export declare abstract class VersionPlanService {
222
238
  * a four-part scheme. A planner for which a changed dependency is not a release at all overrides
223
239
  * this to do nothing.
224
240
  */
225
- protected rippleCrossGroup(packages: Package[], entries: Map<string, VersionPlanService.Entry>, preid: string | undefined): void;
241
+ protected rippleCrossGroup(packages: Package[], entries: Map<string, VersionPlanService.Entry>, preid: string | undefined, published?: ReadonlyMap<string, readonly string[]>): void;
242
+ /**
243
+ * The highest version any of `members` already has on its registry, among those a bump on this
244
+ * line could land on - releases, and prereleases under `preid` when there is one - or `undefined`
245
+ * when there are none.
246
+ */
247
+ protected registryCeiling(members: readonly Package[], scheme: VersionScheme, preid: string | undefined, published: ReadonlyMap<string, readonly string[]>): string | undefined;
226
248
  /**
227
249
  * A monorepo root is never published on its own, but its version is still the repository's release
228
250
  * identity - what a GitHub Release is named after. How it's computed depends on how many version
@@ -192,16 +192,23 @@ export class VersionPlanService {
192
192
  else
193
193
  groups.set(key, [pkg]);
194
194
  }
195
+ /** Only when something is going to be bumped, and only for a computed number - an explicit
196
+ * `rman version <v>` is the reader's own choice. Asked of every eligible package, since the
197
+ * cross-group ripple can bump a group none of whose members changed. */
198
+ const published = new Map();
199
+ if (changeByPackage.size && !explicitVersion) {
200
+ await Promise.all(eligible.map(async (pkg) => published.set(pkg.name, await this.plannerFor(pkg).publishedVersions(pkg))));
201
+ }
195
202
  for (const [key, members] of groups) {
196
203
  const preid = options.preid ?? this.declaredPreid(members, this.groupLabel(key));
197
- this.computeGroupPlan(key, members, changeByPackage, explicitVersion, preid, entries);
204
+ this.computeGroupPlan(key, members, changeByPackage, explicitVersion, preid, entries, published);
198
205
  }
199
- this.rippleCrossGroup(packages, entries, options.preid);
206
+ this.rippleCrossGroup(packages, entries, options.preid, published);
200
207
  this.checkKeptRanges(packages, entries);
201
208
  const result = packages.map(pkg => entries.get(pkg.name));
202
209
  if (repository.monorepo) {
203
210
  result.push(this.buildRootEntry(repository, result, {
204
- groupCount: groups.size,
211
+ groupCount: this.versionLines(repository),
205
212
  lastReleaseVersion: await findLastReleaseVersion(git, repository.rootPackage),
206
213
  now: options.now ?? (() => new Date()),
207
214
  }));
@@ -236,6 +243,35 @@ export class VersionPlanService {
236
243
  notVersionedReason(pkg) {
237
244
  return unversionedReason(pkg);
238
245
  }
246
+ /**
247
+ * How many version lines the repository has - the distinct groups of every package it versions,
248
+ * whatever this run was filtered to. `buildRootEntry`'s `groupCount`.
249
+ */
250
+ /* **Structural, not the groups this run built.** It was `groups.size`, and `groups` holds only the
251
+ * packages this run looks at: `rman version patch --scope pkg-a` on a repository with two version
252
+ * lines built one group, so the root took the semver path and reported `1.0.1` - a shared number
253
+ * claiming a release `pkg-b` never had. That went unseen while `version` created no root tag on
254
+ * semver; once it creates the one `github-release` looks for (`repositoryReleaseTag`), it tagged
255
+ * `v1.0.1`. A package the planner never versions (`notVersionedReason` - a `publish.skip` demo
256
+ * app) is left out: it moves no number, so it is no version line of the release's. */
257
+ versionLines(repository) {
258
+ const versioned = repository.getPackages().filter(pkg => !this.notVersionedReason(pkg));
259
+ return new Set(versioned.map(pkg => this.resolveGroupKey(pkg))).size;
260
+ }
261
+ /**
262
+ * Every version of `pkg` its registry already has - `[]` when it has none, or when the package is
263
+ * not published to a registry at all. A computed version never lands on or below the highest of
264
+ * these (see `computeGroupPlan`).
265
+ *
266
+ * The core knows no registry, so it answers `[]`; a technology overrides it.
267
+ *
268
+ * @throws When the registry gives no answer - a plan that cannot see the registry must not pick a
269
+ * number as though it had.
270
+ */
271
+ async publishedVersions(pkg) {
272
+ void pkg;
273
+ return [];
274
+ }
239
275
  /**
240
276
  * **Which planner answers for one package: its own technology's.**
241
277
  *
@@ -504,7 +540,7 @@ export class VersionPlanService {
504
540
  * narrow reading failed. A repository in lockstep therefore keeps it when the number is chosen
505
541
  * by hand, with no cascade involved.
506
542
  */
507
- computeGroupPlan(key, members, changeByPackage, explicitVersion, preid, entries) {
543
+ computeGroupPlan(key, members, changeByPackage, explicitVersion, preid, entries, published = new Map()) {
508
544
  const label = this.groupLabel(key);
509
545
  /** One version line, so one scheme - the members are about to be compared against each other and
510
546
  * bumped together, which two schemes would make meaningless. */
@@ -520,6 +556,8 @@ export class VersionPlanService {
520
556
  const current = scheme.highestVersion(members.map(m => m.version)) ?? members[0].version;
521
557
  let to;
522
558
  let bump;
559
+ /** Why `to` is past what the commits alone asked for - named in every bumped member's reason. */
560
+ let jumped;
523
561
  if (explicitVersion) {
524
562
  to = explicitVersion;
525
563
  }
@@ -528,6 +566,12 @@ export class VersionPlanService {
528
566
  * resolves; the `!` is for the type. */
529
567
  bump = scheme.highestBump(changed.map(m => changeByPackage.get(m.name).bump));
530
568
  to = scheme.next(current, bump, { preid });
569
+ const taken = this.registryCeiling(members, scheme, preid, published);
570
+ if (taken && scheme.compare(taken, to) >= 0) {
571
+ const planned = to;
572
+ to = scheme.next(taken, bump, { preid });
573
+ jumped = `registry has ${taken}, so ${planned} -> ${to}`;
574
+ }
531
575
  }
532
576
  const bumping = new Set(changed);
533
577
  /** **`'changed'` with no bump is not a narrowing, because there is nothing left to narrow.** An
@@ -573,7 +617,7 @@ export class VersionPlanService {
573
617
  status: 'bump',
574
618
  from: m.version,
575
619
  to,
576
- reason: own?.reason ?? inherited,
620
+ reason: [own?.reason ?? inherited, jumped].filter(Boolean).join('; '),
577
621
  });
578
622
  }
579
623
  else {
@@ -594,7 +638,7 @@ export class VersionPlanService {
594
638
  * a four-part scheme. A planner for which a changed dependency is not a release at all overrides
595
639
  * this to do nothing.
596
640
  */
597
- rippleCrossGroup(packages, entries, preid) {
641
+ rippleCrossGroup(packages, entries, preid, published = new Map()) {
598
642
  const worklist = [...entries.values()].filter(e => e.status === 'bump');
599
643
  while (worklist.length) {
600
644
  const source = worklist.shift();
@@ -612,16 +656,17 @@ export class VersionPlanService {
612
656
  continue;
613
657
  /** The group always contains `pkg` itself, so there is always at least one version here -
614
658
  * the fallback is for the type, not for a case that can happen. */
615
- const groupCeiling = pkg.versionScheme.highestVersion(packages
616
- .filter(p => entries.get(p.name).groupKey === entry.groupKey)
617
- .map(p => entries.get(p.name).to ?? p.version)) ?? pkg.version;
659
+ const groupMembers = packages.filter(p => entries.get(p.name).groupKey === entry.groupKey);
660
+ const groupPreid = preid ?? this.declaredPreid(groupMembers, entry.group ?? entry.groupKey);
661
+ /** The registry's highest counts as part of the ceiling, as it does in `computeGroupPlan`. */
662
+ const groupCeiling = pkg.versionScheme.highestVersion([
663
+ ...groupMembers.map(p => entries.get(p.name).to ?? p.version),
664
+ this.registryCeiling(groupMembers, pkg.versionScheme, groupPreid, published),
665
+ ].filter((v) => !!v)) ?? pkg.version;
618
666
  const next = {
619
667
  ...entry,
620
668
  status: 'bump',
621
- to: pkg.versionScheme.next(groupCeiling, pkg.versionScheme.smallestBump(), {
622
- preid: preid ??
623
- this.declaredPreid(packages.filter(p => entries.get(p.name).groupKey === entry.groupKey), entry.group ?? entry.groupKey),
624
- }),
669
+ to: pkg.versionScheme.next(groupCeiling, pkg.versionScheme.smallestBump(), { preid: groupPreid }),
625
670
  reason: `depends on ${source.package.name}@${source.to}`,
626
671
  };
627
672
  entries.set(pkg.name, next);
@@ -629,6 +674,29 @@ export class VersionPlanService {
629
674
  }
630
675
  }
631
676
  }
677
+ /**
678
+ * The highest version any of `members` already has on its registry, among those a bump on this
679
+ * line could land on - releases, and prereleases under `preid` when there is one - or `undefined`
680
+ * when there are none.
681
+ */
682
+ /* **Why a computed version is checked against the registry at all.** Reported from peacox-ui: the
683
+ * last tag was `@panates-prv/peacox-ui@0.9.24` and breaking commits since planned 1.0.0 for both
684
+ * packages of the lockstep group - but GitHub Packages already had `peacox-icons@1.0.0`, an
685
+ * untagged publish from a month earlier. `publish` would have answered `up-to-date` for icons and
686
+ * shipped ui 1.0.0 peering `^1.0.0` onto the stale package. The user's rule: the base of the bump is
687
+ * the higher of the tag's version and the registry's highest, so the plan goes to 2.0.0 and its
688
+ * reason says why. This is not question B leaking into A - which packages changed is still the
689
+ * tags' answer; the registry only rules out numbers that are taken.
690
+ *
691
+ * **Releases always count, other prerelease lines never do.** Counting a `2.1.0-beta.3` against a
692
+ * stable patch would turn `2.0.1` into `2.1.0`; ignoring a stable `1.0.0` against a beta would plan
693
+ * `1.0.0-beta.0` below a release that already exists. */
694
+ registryCeiling(members, scheme, preid, published) {
695
+ const onLine = members
696
+ .flatMap(m => published.get(m.name) ?? [])
697
+ .filter(v => scheme.isValid(v) && (!scheme.isPrerelease(v) || (!!preid && scheme.prereleaseId(v) === preid)));
698
+ return scheme.highestVersion(onLine);
699
+ }
632
700
  /**
633
701
  * A monorepo root is never published on its own, but its version is still the repository's release
634
702
  * identity - what a GitHub Release is named after. How it's computed depends on how many version
@@ -5,7 +5,7 @@ import { ConfigInterpolator } from '../core/config/config-interpolator.js';
5
5
  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
- import { expandReleaseTag, isCalendarVersion } from '../utils/release-version.js';
8
+ import { isCalendarVersion, repositoryReleaseTag } from '../utils/release-version.js';
9
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';
@@ -267,19 +267,28 @@ export class VersionService extends Service {
267
267
  tagged.push({ name: tag, created: !exists });
268
268
  }
269
269
  }
270
- /** A repository release tag, on top of the per-group ones - but only once the root is on a
271
- * calendar version. With a single version line the group's own tag already *is* the release
272
- * (same version, same commit), and a second name for it would only add noise to every existing
273
- * repo's tag space. Created last, so it lands on HEAD rather than behind whichever group
274
- * happened to be committed last. */
275
- if (rootEntry?.status === 'bump' && isCalendarVersion(rootEntry.to)) {
276
- const releaseTag = expandReleaseTag(repository.rootPackage, rootEntry.to);
277
- if (await git.tagExists(releaseTag)) {
278
- throw new Error(`Release tag "${releaseTag}" already exists - a second release within the same minute. ` +
279
- 'Wait a moment and run again.');
270
+ /** The repository release tag `github-release` looks for (`repositoryReleaseTag`), on top of the
271
+ * per-group ones. On a calendar version it is always a name of its own. On a semver one it is
272
+ * usually the group's own tag already (same version, same commit), and then nothing is added -
273
+ * a second name would only be noise in every existing repo's tag space; it is created only when
274
+ * the members' tags are named otherwise (`{name}@*`). Created last, so it lands on HEAD rather
275
+ * than behind whichever group happened to be committed last. */
276
+ if (rootEntry?.status === 'bump') {
277
+ const releaseTag = repositoryReleaseTag(repository.rootPackage, rootEntry.to);
278
+ const exists = await git.tagExists(releaseTag);
279
+ if (isCalendarVersion(rootEntry.to)) {
280
+ if (exists) {
281
+ throw new Error(`Release tag "${releaseTag}" already exists - a second release within the same minute. ` +
282
+ 'Wait a moment and run again.');
283
+ }
284
+ await git.createTag(releaseTag);
285
+ tagged.push({ name: releaseTag, created: true, release: true });
286
+ }
287
+ else if (!tagged.some(t => t.name === releaseTag)) {
288
+ if (!exists)
289
+ await git.createTag(releaseTag);
290
+ tagged.push({ name: releaseTag, created: !exists, release: true });
280
291
  }
281
- await git.createTag(releaseTag);
282
- tagged.push({ name: releaseTag, created: true, release: true });
283
292
  }
284
293
  const pushed = !!options.push && bumped.length > 0;
285
294
  if (pushed) {
@@ -43,6 +43,12 @@ export declare function usesCalendarVersion(options: {
43
43
  /** The tag naming a given repository release - `releaseTagPattern` run forward, the way
44
44
  * `expandTag` runs `changelog.tagPattern` forward for a package. */
45
45
  export declare function expandReleaseTag(root: Package, version: string): string;
46
+ /**
47
+ * The tag naming the repository's release at `version` (the root's): its release tag on a calendar
48
+ * version, the root's own `changelog.tagPattern` tag (`v*` unless configured) otherwise. `version`
49
+ * creates it and `github-release` looks it up, so both name it through this one function.
50
+ */
51
+ export declare function repositoryReleaseTag(root: Package, version: string): string;
46
52
  /** The version of the repository's most recent release, from its release tags (highest by version
47
53
  * sort) - `undefined` for a repo that has never cut one, or whose tags aren't available (a shallow
48
54
  * clone). The authoritative half of `usesCalendarVersion`'s stickiness check: tags record what was
@@ -54,6 +54,20 @@ export function usesCalendarVersion(options) {
54
54
  export function expandReleaseTag(root, version) {
55
55
  return ChangeHashService.applyTagPattern(releaseTagPattern(root), root.name, version);
56
56
  }
57
+ /**
58
+ * The tag naming the repository's release at `version` (the root's): its release tag on a calendar
59
+ * version, the root's own `changelog.tagPattern` tag (`v*` unless configured) otherwise. `version`
60
+ * creates it and `github-release` looks it up, so both name it through this one function.
61
+ */
62
+ /* **One function, because two copies drifted.** `github-release` expected `v<version>` for a semver
63
+ * root while `version` created a root tag only on the calendar path, trusting the group's own tag to
64
+ * be the same name. It is not whenever the members' tags are `{name}@*` - declared, or derived by
65
+ * `versionLineCount` counting a package the planner leaves out (a `publish.skip` app). Reported from
66
+ * panates/peacox-ui: one named group plus a private demo app, `version` tagged
67
+ * `@panates-prv/peacox-ui@2.0.0-beta.0` and `github-release` refused for want of `v2.0.0-beta.0`. */
68
+ export function repositoryReleaseTag(root, version) {
69
+ return isCalendarVersion(version) ? expandReleaseTag(root, version) : ChangeHashService.expandTag(root, version);
70
+ }
57
71
  /** The version of the repository's most recent release, from its release tags (highest by version
58
72
  * sort) - `undefined` for a repo that has never cut one, or whose tags aren't available (a shallow
59
73
  * clone). The authoritative half of `usesCalendarVersion`'s stickiness check: tags record what was