rman 2.41.3 → 2.42.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/builtins/platforms/node/services/publish.service.d.ts +6 -1
- package/builtins/platforms/node/services/publish.service.js +41 -12
- package/builtins/platforms/node/services/version-plan.service.d.ts +10 -0
- package/builtins/platforms/node/services/version-plan.service.js +20 -0
- package/builtins/publish-targets/npm/npm-view.d.ts +15 -19
- package/builtins/publish-targets/npm/npm-view.js +50 -6
- package/builtins/publish-targets/spm/spm-publish.service.js +2 -2
- package/constants.js +1 -1
- package/package.json +2 -2
- package/services/run.service.d.ts +6 -0
- package/services/run.service.js +29 -1
- package/services/version-plan.service.d.ts +19 -2
- package/services/version-plan.service.js +65 -12
|
@@ -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'
|
|
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'
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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`
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
-
*
|
|
24
|
-
*
|
|
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
|
|
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`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
|
18
|
-
* cloudflare
|
|
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.
|
|
1
|
+
export const version = '2.42.0';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rman",
|
|
3
3
|
"description": "Repository manager",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.42.0",
|
|
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.
|
|
20
|
+
"semver": "^7.8.6",
|
|
21
21
|
"signal-exit": "^4.1.0",
|
|
22
22
|
"yargs": "^18.2.0"
|
|
23
23
|
},
|
|
@@ -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`
|
package/services/run.service.js
CHANGED
|
@@ -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:
|
|
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 });
|
|
@@ -105,6 +105,17 @@ export declare abstract class VersionPlanService {
|
|
|
105
105
|
* wrong one here is invisible - it produces a plan that simply releases too little.
|
|
106
106
|
*/
|
|
107
107
|
protected abstract cascade(bump: string): VersionPlanService.Cascade;
|
|
108
|
+
/**
|
|
109
|
+
* Every version of `pkg` its registry already has - `[]` when it has none, or when the package is
|
|
110
|
+
* not published to a registry at all. A computed version never lands on or below the highest of
|
|
111
|
+
* these (see `computeGroupPlan`).
|
|
112
|
+
*
|
|
113
|
+
* The core knows no registry, so it answers `[]`; a technology overrides it.
|
|
114
|
+
*
|
|
115
|
+
* @throws When the registry gives no answer - a plan that cannot see the registry must not pick a
|
|
116
|
+
* number as though it had.
|
|
117
|
+
*/
|
|
118
|
+
protected publishedVersions(pkg: Package): Promise<readonly string[]>;
|
|
108
119
|
/**
|
|
109
120
|
* **Which planner answers for one package: its own technology's.**
|
|
110
121
|
*
|
|
@@ -208,7 +219,7 @@ export declare abstract class VersionPlanService {
|
|
|
208
219
|
* narrow reading failed. A repository in lockstep therefore keeps it when the number is chosen
|
|
209
220
|
* by hand, with no cascade involved.
|
|
210
221
|
*/
|
|
211
|
-
protected computeGroupPlan(key: string, members: Package[], changeByPackage: Map<string, VersionPlanService.Change>, explicitVersion: string | undefined, preid: string | undefined, entries: Map<string, VersionPlanService.Entry>): void;
|
|
222
|
+
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
223
|
/**
|
|
213
224
|
* A package depending on another group's bumped package always receives its scheme's **smallest**
|
|
214
225
|
* bump, computed from its *own* group's current ceiling (the highest `to`/version among its group
|
|
@@ -222,7 +233,13 @@ export declare abstract class VersionPlanService {
|
|
|
222
233
|
* a four-part scheme. A planner for which a changed dependency is not a release at all overrides
|
|
223
234
|
* this to do nothing.
|
|
224
235
|
*/
|
|
225
|
-
protected rippleCrossGroup(packages: Package[], entries: Map<string, VersionPlanService.Entry>, preid: string | undefined): void;
|
|
236
|
+
protected rippleCrossGroup(packages: Package[], entries: Map<string, VersionPlanService.Entry>, preid: string | undefined, published?: ReadonlyMap<string, readonly string[]>): void;
|
|
237
|
+
/**
|
|
238
|
+
* The highest version any of `members` already has on its registry, among those a bump on this
|
|
239
|
+
* line could land on - releases, and prereleases under `preid` when there is one - or `undefined`
|
|
240
|
+
* when there are none.
|
|
241
|
+
*/
|
|
242
|
+
protected registryCeiling(members: readonly Package[], scheme: VersionScheme, preid: string | undefined, published: ReadonlyMap<string, readonly string[]>): string | undefined;
|
|
226
243
|
/**
|
|
227
244
|
* A monorepo root is never published on its own, but its version is still the repository's release
|
|
228
245
|
* identity - what a GitHub Release is named after. How it's computed depends on how many version
|
|
@@ -192,11 +192,18 @@ 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) {
|
|
@@ -236,6 +243,20 @@ export class VersionPlanService {
|
|
|
236
243
|
notVersionedReason(pkg) {
|
|
237
244
|
return unversionedReason(pkg);
|
|
238
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Every version of `pkg` its registry already has - `[]` when it has none, or when the package is
|
|
248
|
+
* not published to a registry at all. A computed version never lands on or below the highest of
|
|
249
|
+
* these (see `computeGroupPlan`).
|
|
250
|
+
*
|
|
251
|
+
* The core knows no registry, so it answers `[]`; a technology overrides it.
|
|
252
|
+
*
|
|
253
|
+
* @throws When the registry gives no answer - a plan that cannot see the registry must not pick a
|
|
254
|
+
* number as though it had.
|
|
255
|
+
*/
|
|
256
|
+
async publishedVersions(pkg) {
|
|
257
|
+
void pkg;
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
239
260
|
/**
|
|
240
261
|
* **Which planner answers for one package: its own technology's.**
|
|
241
262
|
*
|
|
@@ -504,7 +525,7 @@ export class VersionPlanService {
|
|
|
504
525
|
* narrow reading failed. A repository in lockstep therefore keeps it when the number is chosen
|
|
505
526
|
* by hand, with no cascade involved.
|
|
506
527
|
*/
|
|
507
|
-
computeGroupPlan(key, members, changeByPackage, explicitVersion, preid, entries) {
|
|
528
|
+
computeGroupPlan(key, members, changeByPackage, explicitVersion, preid, entries, published = new Map()) {
|
|
508
529
|
const label = this.groupLabel(key);
|
|
509
530
|
/** One version line, so one scheme - the members are about to be compared against each other and
|
|
510
531
|
* bumped together, which two schemes would make meaningless. */
|
|
@@ -520,6 +541,8 @@ export class VersionPlanService {
|
|
|
520
541
|
const current = scheme.highestVersion(members.map(m => m.version)) ?? members[0].version;
|
|
521
542
|
let to;
|
|
522
543
|
let bump;
|
|
544
|
+
/** Why `to` is past what the commits alone asked for - named in every bumped member's reason. */
|
|
545
|
+
let jumped;
|
|
523
546
|
if (explicitVersion) {
|
|
524
547
|
to = explicitVersion;
|
|
525
548
|
}
|
|
@@ -528,6 +551,12 @@ export class VersionPlanService {
|
|
|
528
551
|
* resolves; the `!` is for the type. */
|
|
529
552
|
bump = scheme.highestBump(changed.map(m => changeByPackage.get(m.name).bump));
|
|
530
553
|
to = scheme.next(current, bump, { preid });
|
|
554
|
+
const taken = this.registryCeiling(members, scheme, preid, published);
|
|
555
|
+
if (taken && scheme.compare(taken, to) >= 0) {
|
|
556
|
+
const planned = to;
|
|
557
|
+
to = scheme.next(taken, bump, { preid });
|
|
558
|
+
jumped = `registry has ${taken}, so ${planned} -> ${to}`;
|
|
559
|
+
}
|
|
531
560
|
}
|
|
532
561
|
const bumping = new Set(changed);
|
|
533
562
|
/** **`'changed'` with no bump is not a narrowing, because there is nothing left to narrow.** An
|
|
@@ -573,7 +602,7 @@ export class VersionPlanService {
|
|
|
573
602
|
status: 'bump',
|
|
574
603
|
from: m.version,
|
|
575
604
|
to,
|
|
576
|
-
reason: own?.reason ?? inherited,
|
|
605
|
+
reason: [own?.reason ?? inherited, jumped].filter(Boolean).join('; '),
|
|
577
606
|
});
|
|
578
607
|
}
|
|
579
608
|
else {
|
|
@@ -594,7 +623,7 @@ export class VersionPlanService {
|
|
|
594
623
|
* a four-part scheme. A planner for which a changed dependency is not a release at all overrides
|
|
595
624
|
* this to do nothing.
|
|
596
625
|
*/
|
|
597
|
-
rippleCrossGroup(packages, entries, preid) {
|
|
626
|
+
rippleCrossGroup(packages, entries, preid, published = new Map()) {
|
|
598
627
|
const worklist = [...entries.values()].filter(e => e.status === 'bump');
|
|
599
628
|
while (worklist.length) {
|
|
600
629
|
const source = worklist.shift();
|
|
@@ -612,16 +641,17 @@ export class VersionPlanService {
|
|
|
612
641
|
continue;
|
|
613
642
|
/** The group always contains `pkg` itself, so there is always at least one version here -
|
|
614
643
|
* the fallback is for the type, not for a case that can happen. */
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
644
|
+
const groupMembers = packages.filter(p => entries.get(p.name).groupKey === entry.groupKey);
|
|
645
|
+
const groupPreid = preid ?? this.declaredPreid(groupMembers, entry.group ?? entry.groupKey);
|
|
646
|
+
/** The registry's highest counts as part of the ceiling, as it does in `computeGroupPlan`. */
|
|
647
|
+
const groupCeiling = pkg.versionScheme.highestVersion([
|
|
648
|
+
...groupMembers.map(p => entries.get(p.name).to ?? p.version),
|
|
649
|
+
this.registryCeiling(groupMembers, pkg.versionScheme, groupPreid, published),
|
|
650
|
+
].filter((v) => !!v)) ?? pkg.version;
|
|
618
651
|
const next = {
|
|
619
652
|
...entry,
|
|
620
653
|
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
|
-
}),
|
|
654
|
+
to: pkg.versionScheme.next(groupCeiling, pkg.versionScheme.smallestBump(), { preid: groupPreid }),
|
|
625
655
|
reason: `depends on ${source.package.name}@${source.to}`,
|
|
626
656
|
};
|
|
627
657
|
entries.set(pkg.name, next);
|
|
@@ -629,6 +659,29 @@ export class VersionPlanService {
|
|
|
629
659
|
}
|
|
630
660
|
}
|
|
631
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* The highest version any of `members` already has on its registry, among those a bump on this
|
|
664
|
+
* line could land on - releases, and prereleases under `preid` when there is one - or `undefined`
|
|
665
|
+
* when there are none.
|
|
666
|
+
*/
|
|
667
|
+
/* **Why a computed version is checked against the registry at all.** Reported from peacox-ui: the
|
|
668
|
+
* last tag was `@panates-prv/peacox-ui@0.9.24` and breaking commits since planned 1.0.0 for both
|
|
669
|
+
* packages of the lockstep group - but GitHub Packages already had `peacox-icons@1.0.0`, an
|
|
670
|
+
* untagged publish from a month earlier. `publish` would have answered `up-to-date` for icons and
|
|
671
|
+
* shipped ui 1.0.0 peering `^1.0.0` onto the stale package. The user's rule: the base of the bump is
|
|
672
|
+
* the higher of the tag's version and the registry's highest, so the plan goes to 2.0.0 and its
|
|
673
|
+
* reason says why. This is not question B leaking into A - which packages changed is still the
|
|
674
|
+
* tags' answer; the registry only rules out numbers that are taken.
|
|
675
|
+
*
|
|
676
|
+
* **Releases always count, other prerelease lines never do.** Counting a `2.1.0-beta.3` against a
|
|
677
|
+
* stable patch would turn `2.0.1` into `2.1.0`; ignoring a stable `1.0.0` against a beta would plan
|
|
678
|
+
* `1.0.0-beta.0` below a release that already exists. */
|
|
679
|
+
registryCeiling(members, scheme, preid, published) {
|
|
680
|
+
const onLine = members
|
|
681
|
+
.flatMap(m => published.get(m.name) ?? [])
|
|
682
|
+
.filter(v => scheme.isValid(v) && (!scheme.isPrerelease(v) || (!!preid && scheme.prereleaseId(v) === preid)));
|
|
683
|
+
return scheme.highestVersion(onLine);
|
|
684
|
+
}
|
|
632
685
|
/**
|
|
633
686
|
* A monorepo root is never published on its own, but its version is still the repository's release
|
|
634
687
|
* identity - what a GitHub Release is named after. How it's computed depends on how many version
|