@wtf/release-npm 1.1.1 → 2.0.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/README.md +65 -42
- package/dist/check.d.ts +5 -5
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +2 -2
- package/dist/ecosystem.d.ts +46 -7
- package/dist/ecosystem.d.ts.map +1 -1
- package/dist/ecosystem.js +33 -25
- package/dist/ecosystem.js.map +1 -1
- package/dist/errors.d.ts +15 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -6
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +19 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -14
- package/dist/index.js.map +1 -1
- package/dist/manifests.d.ts +13 -13
- package/dist/manifests.d.ts.map +1 -1
- package/dist/manifests.js +9 -37
- package/dist/manifests.js.map +1 -1
- package/dist/prepare.d.ts +1 -1
- package/dist/publishers.d.ts +10 -1
- package/dist/publishers.d.ts.map +1 -1
- package/dist/publishers.js +31 -19
- package/dist/publishers.js.map +1 -1
- package/dist/release.d.ts +224 -222
- package/dist/release.d.ts.map +1 -1
- package/dist/release.js +503 -378
- package/dist/release.js.map +1 -1
- package/dist/smoke.d.ts +16 -12
- package/dist/smoke.d.ts.map +1 -1
- package/dist/smoke.js +31 -25
- package/dist/smoke.js.map +1 -1
- package/dist/types.d.ts +50 -36
- package/dist/types.d.ts.map +1 -1
- package/dist/workspace.d.ts +29 -11
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +18 -43
- package/dist/workspace.js.map +1 -1
- package/package.json +5 -3
package/dist/release.js
CHANGED
|
@@ -1,81 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The npm packages of a release published, of the plan its caller gives it, as `Plan` of
|
|
3
|
+
* `@wtf/release/contract` has it: the packages that publish, in the order to publish them in, and
|
|
4
|
+
* the version of each package of the repo a range of theirs resolves to. It knows no train and no
|
|
5
|
+
* release tool, and writes no file of the repo: the version of the release is given, and each
|
|
6
|
+
* package.json in git keeps the version it has, a placeholder, as `0.0.0-development`. Each step of
|
|
7
|
+
* the contract is a function of this module, which the ecosystem of `./ecosystem` runs:
|
|
5
8
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
9
|
+
* - {@link verifyRelease}: the version of semver, the options ({@link npmOptionsSchema}), and the
|
|
10
|
+
* packages as they are in the repo ({@link checkPlan});
|
|
11
|
+
* - {@link prepareRelease}: each manifest as it publishes, of the version of the release, each
|
|
12
|
+
* `workspace:` range resolved to the version of the plan, each export of the source stripped, and
|
|
13
|
+
* checked ({@link resolvePlan}); each package packed from a copy in a temporary folder of the
|
|
14
|
+
* platform ({@link packRelease}); and the registry asked, so a release that would move a dist-tag
|
|
15
|
+
* back fails before anything is published ({@link publishedOf}). It writes no file of the repo,
|
|
16
|
+
* and gives none;
|
|
17
|
+
* - {@link smokeRelease}: each package packed tried as a consumer installs it, by `smokePacked` of
|
|
18
|
+
* `./smoke`;
|
|
19
|
+
* - {@link publishRelease}: each package published in order, under the first dist-tag of `moving`,
|
|
20
|
+
* each other pointed at it, with the provenance of the build where the CI gives an ID token, and
|
|
21
|
+
* each the registry has at the version already skipped, so a publish run again publishes what is
|
|
22
|
+
* missing ({@link publishPacked});
|
|
23
|
+
* - {@link moveRelease}: each dist-tag of `moving` pointed at a version published already.
|
|
19
24
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
25
|
+
* What `prepare` packed, `smoke` and `publish` take in the same process, of the same folder,
|
|
26
|
+
* version and packages; a step that finds nothing packed packs again, as the same tree packs the
|
|
27
|
+
* same tarballs, and {@link discardPacked} removes what is packed of a release that goes no
|
|
28
|
+
* further.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import type { Release } from '@wtf/release/contract'
|
|
32
|
+
* import npm from '@wtf/release-npm'
|
|
33
|
+
* import type { NpmPackage } from '@wtf/release-npm/manifests'
|
|
34
|
+
*
|
|
35
|
+
* declare const release: Release
|
|
36
|
+
* declare const own: readonly NpmPackage[]
|
|
37
|
+
*
|
|
38
|
+
* const plan = { own, versions: new Map(own.map(({ name }) => [name, release.version])) }
|
|
39
|
+
* const options = { moving: ['latest'] } as const
|
|
40
|
+
* await npm.verify(release, plan, options)
|
|
41
|
+
* await npm.prepare(release, plan, options)
|
|
42
|
+
* const released = await npm.publish(release, plan, options)
|
|
43
|
+
* ```
|
|
23
44
|
*
|
|
24
45
|
* @packageDocumentation
|
|
25
46
|
* @module @wtf/release-npm/release
|
|
26
47
|
*/
|
|
27
48
|
import semver from 'semver';
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
49
|
+
import { removeAt, tempFolder } from '@wtf/platform-fs/files';
|
|
50
|
+
import { isReleaseError, throwAll } from '@wtf/release/errors';
|
|
51
|
+
import { copy, readDir, writeFile } from '@wtf/release/files';
|
|
52
|
+
import { publishOrder } from '@wtf/release/order';
|
|
53
|
+
import { pathMatcher } from '@wtf/release/paths';
|
|
54
|
+
import { joinPath, relativePath, resolvePath } from '@wtf/release/posix';
|
|
55
|
+
import { anyObject, anyOf, arrayOf, booleanOf, errorsOf, issueOf, objectOf, oneOf, refined, stringOf } from '@wtf/release/validator';
|
|
34
56
|
import { checkPackages, formatIssue } from "./check.js";
|
|
35
|
-
import {
|
|
57
|
+
import { NpmError } from "./errors.js";
|
|
36
58
|
import { packagesOfManifests } from "./manifests.js";
|
|
37
59
|
import { prepareManifest } from "./prepare.js";
|
|
38
|
-
import { npmPublisher } from "./publishers.js";
|
|
60
|
+
import { isPublisher, npmPublisher, registryOf } from "./publishers.js";
|
|
61
|
+
import { smokePacked } from "./smoke.js";
|
|
39
62
|
import { readWorkspace } from "./workspace.js";
|
|
40
|
-
/**
|
|
41
|
-
* The dist-tag of a version: `latest` of a release, and the first identifier of a prerelease, `beta`
|
|
42
|
-
* of `2.1.0-beta.3`, the channel of the branch semantic-release named it after; `prerelease` of one
|
|
43
|
-
* whose first identifier is a number, as `2.1.0-0`, which npm takes for a range and not a dist-tag,
|
|
44
|
-
* and is the channel of no branch. A prerelease never takes `latest`, which every install with no
|
|
45
|
-
* version gets.
|
|
46
|
-
*
|
|
47
|
-
* @param version - The version of the release, as `2.1.0` or `2.1.0-beta.3`.
|
|
48
|
-
* @returns The dist-tag of the version.
|
|
49
|
-
*/
|
|
50
|
-
export const distTagOf = (version) => {
|
|
51
|
-
const prerelease = /^\d+\.\d+\.\d+-([0-9A-Za-z-]+)/.exec(version)?.[1];
|
|
52
|
-
if (prerelease === undefined)
|
|
53
|
-
return 'latest';
|
|
54
|
-
return /^\d+$/.test(prerelease) ? 'prerelease' : prerelease;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* The dist-tag of a release on `channel`, or of its version where it has none ({@link distTagOf}):
|
|
58
|
-
* `release-1.x` of a channel npm takes for a range, as `1.x` of a branch of maintenance, which npm
|
|
59
|
-
* refuses as a dist-tag, as `@semantic-release/npm` names it. An empty channel is none, as it is
|
|
60
|
-
* to `@semantic-release/npm`.
|
|
61
|
-
*/
|
|
62
|
-
const distTagOfChannel = (channel, version) => {
|
|
63
|
-
const tag = channel === null || channel === undefined || channel === '' ? distTagOf(version) : channel;
|
|
64
|
-
return semver.validRange(tag) === null ? tag : `release-${tag}`;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* The train `train` selects, the workspace of `cwd`, its packages of a name, the packages of the
|
|
68
|
-
* train, and those of them that publish, in the order to publish them in, with the faults of that
|
|
69
|
-
* order.
|
|
70
|
-
*/
|
|
71
|
-
async function publishingOf(trains, train, { cwd, system, first, last }) {
|
|
72
|
-
const [name] = selectTrain(trains, train);
|
|
73
|
-
const workspace = await readWorkspace(cwd, { system });
|
|
74
|
-
const all = packagesOfManifests(workspace);
|
|
75
|
-
const packages = packagesOf(trains, name, all);
|
|
76
|
-
const publishable = packages.filter(({ published }) => published);
|
|
77
|
-
return { name, workspace, all, packages, ...publishOrder(publishable, { first, last }) };
|
|
78
|
-
}
|
|
79
63
|
/**
|
|
80
64
|
* The variables of the environment of an ID token the CI gives, of which npm signs provenance:
|
|
81
65
|
* Sigstore's on GitLab, GitHub's OIDC on GitHub Actions. Not `NPM_ID_TOKEN`, of npm's trusted
|
|
@@ -91,163 +75,254 @@ export const RUNNER_ENVIRONMENTS = [
|
|
|
91
75
|
'CI_RUNNER_ENVIRONMENT',
|
|
92
76
|
'RUNNER_ENVIRONMENT'
|
|
93
77
|
];
|
|
78
|
+
/** What is wrong with the order of the plan: its own, or what `publishOrder` finds of `own`. */
|
|
79
|
+
const faultsOf = (plan) => plan.faults ?? publishOrder(plan.own).faults;
|
|
80
|
+
/** A list of dist-tags, non-empty, each one npm takes, of no range of semver, which npm refuses. */
|
|
81
|
+
const distTagsOf = () => refined(arrayOf(stringOf({ minLength: 1 }), { minItems: 1 }), (tags, path) => tags.flatMap((tag, index) => semver.validRange(tag) === null
|
|
82
|
+
? []
|
|
83
|
+
: [
|
|
84
|
+
issueOf([...path, index], tag, 'a dist-tag, which npm takes of no range of semver', {
|
|
85
|
+
details: `npm reads ${tag} as a range of versions, and refuses it as a dist-tag: name it as \`release-${tag}\`.`
|
|
86
|
+
})
|
|
87
|
+
]), 'Each a dist-tag npm takes, of no range of semver.');
|
|
88
|
+
/** The validator of the options of the release of npm packages, each step's. */
|
|
89
|
+
export const npmOptionsSchema = objectOf({
|
|
90
|
+
moving: { of: distTagsOf() },
|
|
91
|
+
publisher: {
|
|
92
|
+
of: refined(anyObject(), (publisher, path) => isPublisher(publisher)
|
|
93
|
+
? []
|
|
94
|
+
: [
|
|
95
|
+
issueOf(path, undefined, 'a publisher', {
|
|
96
|
+
code: 'EPUBLISHER',
|
|
97
|
+
message: () => 'The publisher is no publisher.',
|
|
98
|
+
details: 'A publisher has a `name`, and `lookup` and `publish` functions, and `pack`, `tag` and `page`, where it has them, functions too: see the Publisher type.'
|
|
99
|
+
})
|
|
100
|
+
], 'A Publisher of the types of the package.'),
|
|
101
|
+
optional: true
|
|
102
|
+
},
|
|
103
|
+
access: { of: oneOf(['public', 'restricted']), optional: true },
|
|
104
|
+
provenance: {
|
|
105
|
+
of: anyOf([booleanOf(), oneOf(['auto'])], "true, false or 'auto'"),
|
|
106
|
+
optional: true
|
|
107
|
+
},
|
|
108
|
+
registry: { of: stringOf({ minLength: 1 }), optional: true },
|
|
109
|
+
conditions: { of: arrayOf(stringOf({ minLength: 1 })), optional: true },
|
|
110
|
+
check: { of: booleanOf(), optional: true },
|
|
111
|
+
aside: {
|
|
112
|
+
of: objectOf({
|
|
113
|
+
packages: { of: arrayOf(stringOf({ minLength: 1 })), optional: true },
|
|
114
|
+
moving: { of: distTagsOf(), optional: true },
|
|
115
|
+
none: { of: stringOf({ minLength: 1 }), optional: true }
|
|
116
|
+
}),
|
|
117
|
+
optional: true
|
|
118
|
+
},
|
|
119
|
+
tarballDir: { of: stringOf({ minLength: 1 }), optional: true },
|
|
120
|
+
pack: { of: arrayOf(stringOf({ minLength: 1 })), optional: true },
|
|
121
|
+
forbid: { of: arrayOf(stringOf({ minLength: 1 })), optional: true }
|
|
122
|
+
});
|
|
123
|
+
/** The error of the faults of the packages of a release, of how to go on after them. */
|
|
124
|
+
const checkError = (issues, details) => new NpmError('EPUBLISHCHECK', `The packages would not publish as they should:\n${issues.map((issue) => `- ${formatIssue(issue)}`).join('\n')}`, details);
|
|
125
|
+
/**
|
|
126
|
+
* The faults of the packages of `aside`: `EPUBLISHCHECK` of a name of no package of the workspace,
|
|
127
|
+
* which puts nothing aside. One of no package of the plan is none, as of `aside` at the root of a
|
|
128
|
+
* config of several parts of the repo, each of its own release.
|
|
129
|
+
*/
|
|
130
|
+
const asideFaults = (aside, workspace) => {
|
|
131
|
+
const names = new Set(workspace.map(({ name }) => name));
|
|
132
|
+
const unknown = (aside?.packages ?? []).filter((name) => !names.has(name));
|
|
133
|
+
return unknown.length === 0
|
|
134
|
+
? []
|
|
135
|
+
: [
|
|
136
|
+
new NpmError('EPUBLISHCHECK', `\`aside\` names ${unknown.join(', ')}, of no package of the workspace.`, 'Name a package of the workspace in `aside`, by the name of its package.json.')
|
|
137
|
+
];
|
|
138
|
+
};
|
|
94
139
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* of
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* each export of the source stripped; and of each private package of the train of `pack`, the same,
|
|
101
|
-
* of no check. It writes nothing. Throws `EDEPENDENCYUNSATISFIED` of a range no release of the other
|
|
102
|
-
* train satisfies, `EDEPENDENCYNOTRAIN` and `EDEPENDENCYNORELEASE` of a range of a package of no
|
|
103
|
-
* train, or of a train with no release, that reaches the registry, and `EPUBLISHCHECK` of what is
|
|
104
|
-
* wrong with a manifest.
|
|
140
|
+
* Checks the packages of a plan as they are in the repo, before a release makes them ready: each
|
|
141
|
+
* scoped one public, of a license and a repository, none running with a private package, and an
|
|
142
|
+
* order of publishing that holds, unless `check` is `false`; and each name of `aside` of a package
|
|
143
|
+
* of the workspace. It reads the workspace of the folder of the repo, and writes nothing. Gives the
|
|
144
|
+
* name of each package that publishes, in order; throws `EPUBLISHCHECK` of what is wrong.
|
|
105
145
|
*
|
|
106
|
-
* @param
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
146
|
+
* @param root - The folder of the repo, a handle of the File System standard.
|
|
147
|
+
* @param plan - The packages that publish, in order, and what is wrong with their order.
|
|
148
|
+
* @param options - Whether the packages are checked, the access of each, and the packages of
|
|
149
|
+
* `aside`.
|
|
150
|
+
* @returns The name of each package that publishes, in the order of publishing.
|
|
109
151
|
*/
|
|
110
|
-
export async function
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
152
|
+
export async function checkPlan(root, plan, options = {}) {
|
|
153
|
+
const workspace = await readWorkspace(root);
|
|
154
|
+
const issues = options.check === false
|
|
155
|
+
? []
|
|
156
|
+
: checkPackages(plan.own, {
|
|
157
|
+
prepared: false,
|
|
158
|
+
faults: faultsOf(plan),
|
|
159
|
+
workspace,
|
|
160
|
+
access: options.access
|
|
161
|
+
});
|
|
162
|
+
// A name of `aside` of no package fails here, before anything is packed, with each fault of the
|
|
163
|
+
// packages, together.
|
|
122
164
|
throwAll([
|
|
123
|
-
...asideFaults(
|
|
124
|
-
...(
|
|
165
|
+
...asideFaults(options.aside, workspace),
|
|
166
|
+
...(issues.length === 0
|
|
167
|
+
? []
|
|
168
|
+
: [checkError(issues, 'Fix each before the release: nothing is published until each is.')])
|
|
125
169
|
]);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
170
|
+
return plan.own.map(({ name }) => name);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Checks a release before anything of it is written: its version, one of semver
|
|
174
|
+
* (`EPUBLISHVERSION`), as npm publishes no other; its options, by {@link npmOptionsSchema}
|
|
175
|
+
* (`EOPTIONS`, and `EPUBLISHER` of a publisher that is none); and the packages of its plan as they
|
|
176
|
+
* are in the repo, by {@link checkPlan} (`EPUBLISHCHECK`). The faults of the version and of the
|
|
177
|
+
* options are thrown together, before the packages are read.
|
|
178
|
+
*
|
|
179
|
+
* @param release - The version of the release, the folder of the repo and the platform.
|
|
180
|
+
* @param plan - The packages that publish, in order.
|
|
181
|
+
* @param options - The options of the release.
|
|
182
|
+
*/
|
|
183
|
+
export async function verifyRelease(release, plan, options) {
|
|
184
|
+
const { version } = release;
|
|
185
|
+
throwAll([
|
|
186
|
+
...(semver.valid(version) === version.split('+')[0]
|
|
187
|
+
? []
|
|
188
|
+
: [
|
|
189
|
+
new NpmError('EPUBLISHVERSION', `${version} is no version of semver, which npm publishes.`, 'Give the release a version of semver, as `1.2.0` or `1.2.0-beta.1`, of no `v`.')
|
|
190
|
+
]),
|
|
191
|
+
...errorsOf(npmOptionsSchema, options, NpmError)
|
|
192
|
+
]);
|
|
193
|
+
await checkPlan(release.root, plan, options);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The manifest of each package of the plan that publishes, as it publishes, in the order of the
|
|
197
|
+
* plan, and checked: of the version of the release; each `workspace:` range of a package of the
|
|
198
|
+
* plan resolved to that version, as pnpm resolves `workspace:*`, `workspace:^` and `workspace:~`,
|
|
199
|
+
* and of another package of the repo to its version of the plan's `versions`; each export of the
|
|
200
|
+
* source stripped; and of each private package of `pack`, the same, of no check. A devDependency of
|
|
201
|
+
* a package of the workspace of no version is dropped, as no consumer installs it; any other range
|
|
202
|
+
* of no version is left, for the check to find. It writes nothing. Throws `EPUBLISHCHECK` of what
|
|
203
|
+
* is wrong with a manifest, and of a name of `aside` of no package of the workspace.
|
|
204
|
+
*
|
|
205
|
+
* @param release - The version of the release, and the folder of the repo, whose workspace it
|
|
206
|
+
* reads.
|
|
207
|
+
* @param plan - The packages that publish, in order, the versions of the repo, and the packages of
|
|
208
|
+
* `pack`.
|
|
209
|
+
* @param options - The access, the conditions of the source, whether to check, the packages of
|
|
210
|
+
* `aside`, and of `pack`.
|
|
211
|
+
* @returns The packages of the release, each manifest as it publishes, in the order to publish.
|
|
212
|
+
*/
|
|
213
|
+
export async function resolvePlan(release, plan, options = {}) {
|
|
214
|
+
const { version } = release;
|
|
215
|
+
const workspace = await readWorkspace(release.root);
|
|
216
|
+
throwAll(asideFaults(options.aside, workspace));
|
|
217
|
+
const own = new Set(plan.own.map(({ name }) => name));
|
|
218
|
+
// A private package never publishes: it has no version to resolve to, so a devDependency on it is
|
|
219
|
+
// dropped, and any other range of it is left for the check to find.
|
|
220
|
+
const publishable = new Set(workspace.flatMap(({ name, json }) => name !== undefined && json['private'] !== true ? [name] : []));
|
|
135
221
|
const versionOf = (each) => {
|
|
136
222
|
if (!publishable.has(each))
|
|
137
223
|
return undefined;
|
|
138
|
-
|
|
139
|
-
return version;
|
|
140
|
-
const owner = owners.get(each);
|
|
141
|
-
return owner === undefined ? undefined : versions.get(owner);
|
|
224
|
+
return own.has(each) ? version : plan.versions.get(each);
|
|
142
225
|
};
|
|
143
|
-
const names = new Set(workspace.flatMap(({ name
|
|
144
|
-
const prepared =
|
|
145
|
-
|
|
226
|
+
const names = new Set(workspace.flatMap(({ name }) => (name === undefined ? [] : [name])));
|
|
227
|
+
const prepared = plan.own.map(({ name, dir, json }) => ({
|
|
228
|
+
name,
|
|
229
|
+
dir,
|
|
230
|
+
json: prepareManifest(json, {
|
|
146
231
|
version,
|
|
147
232
|
versionOf,
|
|
148
233
|
workspace: names,
|
|
149
|
-
conditions:
|
|
234
|
+
conditions: options.conditions
|
|
150
235
|
}).manifest
|
|
151
236
|
}));
|
|
152
|
-
if (
|
|
237
|
+
if (options.check !== false) {
|
|
153
238
|
const issues = checkPackages(prepared, {
|
|
154
|
-
faults,
|
|
239
|
+
faults: faultsOf(plan),
|
|
155
240
|
workspace,
|
|
156
|
-
access:
|
|
157
|
-
conditions:
|
|
241
|
+
access: options.access,
|
|
242
|
+
conditions: options.conditions
|
|
158
243
|
});
|
|
159
244
|
if (issues.length > 0)
|
|
160
|
-
throw
|
|
245
|
+
throw checkError(issues, 'Fix each, and run the release again: nothing was published.');
|
|
161
246
|
}
|
|
162
247
|
// Each private package of `pack`, of the version of the release, as each private package of the
|
|
163
248
|
// workspace it lists is: none of them has a release of its own to resolve to.
|
|
164
|
-
const packs = pathMatcher(
|
|
165
|
-
const packOnly = packages.filter(({ dir, json }) => json['private'] === true && packs(dir));
|
|
249
|
+
const packs = pathMatcher(options.pack ?? []);
|
|
250
|
+
const packOnly = (plan.packages ?? packagesOfManifests(workspace)).filter(({ dir, json }) => json['private'] === true && packs(dir));
|
|
166
251
|
return {
|
|
167
|
-
train: name,
|
|
168
252
|
version,
|
|
169
|
-
|
|
170
|
-
packages: prepared.map(({ dir, json }) => ({
|
|
171
|
-
name: json['name'],
|
|
172
|
-
dir,
|
|
173
|
-
manifest: json
|
|
174
|
-
})),
|
|
253
|
+
packages: prepared.map(({ name, dir, json }) => ({ name, dir, manifest: json })),
|
|
175
254
|
packOnly: packOnly
|
|
176
255
|
.toSorted((a, b) => a.dir.localeCompare(b.dir))
|
|
177
|
-
.map(({ dir, json }) => ({
|
|
178
|
-
name
|
|
256
|
+
.map(({ name, dir, json }) => ({
|
|
257
|
+
name,
|
|
179
258
|
dir,
|
|
180
259
|
manifest: prepareManifest(json, {
|
|
181
260
|
version,
|
|
182
261
|
versionOf: (each) => versionOf(each) ?? (names.has(each) ? version : undefined),
|
|
183
262
|
workspace: names,
|
|
184
|
-
conditions:
|
|
263
|
+
conditions: options.conditions
|
|
185
264
|
}).manifest
|
|
186
265
|
}))
|
|
187
266
|
};
|
|
188
267
|
}
|
|
189
268
|
/**
|
|
190
|
-
* Packs the packages of a release, of the manifests {@link
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
269
|
+
* Packs the packages of a release, of the manifests {@link resolvePlan} gave: each package's folder
|
|
270
|
+
* copied, but its `node_modules`, into a temporary folder of the platform, its manifest as it
|
|
271
|
+
* publishes written into the copy, and each packed there by a publisher that packs, all before the
|
|
272
|
+
* first publish. The repo is left as it is. The copies and the tarballs stay until `cleanup`, and
|
|
273
|
+
* the tarballs of a `tarballDir` the caller names after it too; of a pack that fails, they are
|
|
274
|
+
* removed.
|
|
196
275
|
*
|
|
197
|
-
* @param resolved - The packages of the release, of {@link
|
|
198
|
-
* @param options - The publisher, the folder of the repo, the
|
|
199
|
-
* and the log.
|
|
276
|
+
* @param resolved - The packages of the release, of {@link resolvePlan}.
|
|
277
|
+
* @param options - The publisher, the folder of the repo, the platform, the folder of the
|
|
278
|
+
* tarballs, and the log.
|
|
200
279
|
* @returns The packages packed, their copies and their tarballs, and how each goes.
|
|
201
280
|
*/
|
|
202
|
-
export async function
|
|
281
|
+
export async function packRelease(resolved, options) {
|
|
203
282
|
const context = contextOf(options);
|
|
204
|
-
const {
|
|
283
|
+
const { root, platform, log } = context;
|
|
205
284
|
const publisher = options.publisher ?? npmPublisher;
|
|
206
|
-
const {
|
|
207
|
-
const
|
|
285
|
+
const { version } = resolved;
|
|
286
|
+
const folder = await tempFolder(platform, { prefix: `release-npm-${version}-` });
|
|
287
|
+
const staging = folder.path;
|
|
208
288
|
const tarballDir = options.tarballDir === undefined
|
|
209
289
|
? joinPath(staging, '.tarballs')
|
|
210
|
-
: resolvePath(cwd, options.tarballDir);
|
|
290
|
+
: resolvePath(platform.dirs.cwd, options.tarballDir);
|
|
211
291
|
const tarballs = new Map();
|
|
212
292
|
// The folder of the tarballs by default is in the staging, which goes. One the caller names keeps
|
|
213
293
|
// them, as for a later plugin to attach to the release of the host.
|
|
214
|
-
const cleanup = () =>
|
|
294
|
+
const cleanup = () => folder.remove();
|
|
215
295
|
const discard = async () => {
|
|
216
296
|
await Promise.allSettled([
|
|
217
297
|
cleanup(),
|
|
218
|
-
...[...tarballs.values()].map((tarball) =>
|
|
298
|
+
...[...tarballs.values()].map((tarball) => removeAt(platform, tarball, { recursive: true }))
|
|
219
299
|
]);
|
|
220
300
|
};
|
|
221
301
|
try {
|
|
222
|
-
await system.fs.rm(staging);
|
|
223
302
|
const packages = [];
|
|
224
303
|
const packOnly = [];
|
|
225
304
|
const copies = [
|
|
226
305
|
...resolved.packages.map((each) => [each, packages]),
|
|
227
|
-
...
|
|
306
|
+
...resolved.packOnly.map((each) => [each, packOnly])
|
|
228
307
|
];
|
|
229
308
|
for (const [{ name, dir, manifest }, into] of copies) {
|
|
230
|
-
const from = joinPath(cwd, dir);
|
|
231
|
-
const to = joinPath(staging, dir);
|
|
232
309
|
// oxlint-disable-next-line no-await-in-loop -- one package after another
|
|
233
|
-
const entries = await
|
|
310
|
+
const entries = await readDir(root, dir);
|
|
234
311
|
for (const entry of entries.filter(({ name: each }) => each !== 'node_modules'))
|
|
235
312
|
// oxlint-disable-next-line no-await-in-loop -- one file after another
|
|
236
|
-
await
|
|
313
|
+
await copy(root, joinPath(dir, entry.name), folder.handle, joinPath(dir, entry.name));
|
|
237
314
|
// oxlint-disable-next-line no-await-in-loop -- one package after another
|
|
238
|
-
await
|
|
239
|
-
into.push({ name, version, dir:
|
|
315
|
+
await writeFile(folder.handle, joinPath(dir, 'package.json'), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
316
|
+
into.push({ name, version, dir: joinPath(staging, dir), manifest });
|
|
240
317
|
}
|
|
241
318
|
if (publisher.pack !== undefined) {
|
|
242
319
|
for (const pkg of [...packages, ...packOnly])
|
|
243
320
|
// oxlint-disable-next-line no-await-in-loop -- in order, one after the other
|
|
244
321
|
tarballs.set(pkg.name, await publisher.pack(pkg, tarballDir, context));
|
|
245
|
-
log(`Packed ${tarballs.size} package(s)
|
|
322
|
+
log(`Packed ${tarballs.size} package(s) at ${version}.`);
|
|
246
323
|
}
|
|
247
324
|
return {
|
|
248
|
-
train,
|
|
249
325
|
version,
|
|
250
|
-
distTag,
|
|
251
326
|
publisher,
|
|
252
327
|
packages,
|
|
253
328
|
packOnly,
|
|
@@ -264,114 +339,60 @@ export async function packTrain(resolved, options) {
|
|
|
264
339
|
throw error;
|
|
265
340
|
}
|
|
266
341
|
}
|
|
267
|
-
/**
|
|
268
|
-
* The dist-tag a release of `version` is published under beside a newer one of `distTag`: of its
|
|
269
|
-
* major's line, `release-<major>.x` of `latest`, as semantic-release names a channel of maintenance,
|
|
270
|
-
* and `<dist-tag>-<major>.x` of another.
|
|
271
|
-
*/
|
|
272
|
-
const asideOf = (version, distTag, maintenance) => {
|
|
273
|
-
const major = semver.major(version);
|
|
274
|
-
// A release of a branch of maintenance, or a dist-tag of a line already, has none aside of it: a
|
|
275
|
-
// package of it whose dist-tag points above the release is behind in its line. A line's is
|
|
276
|
-
// `release-<range>` of the names semantic-release takes for a range of maintenance, as
|
|
277
|
-
// `release-1.x` or `release-1.2.x`, not any `release-` name a range may read; or `-<major>.x`.
|
|
278
|
-
const ofRange = /^release-\d+(?:\.(?:\d+|x))?\.x$/.test(distTag);
|
|
279
|
-
if (maintenance || ofRange || distTag.endsWith(`-${major}.x`))
|
|
280
|
-
return undefined;
|
|
281
|
-
return distTag === 'latest' ? `release-${major}.x` : `${distTag}-${major}.x`;
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* The faults of `aside`: `EPUBLISHCHECK` of a name of no package of the workspace, which puts nothing
|
|
285
|
-
* aside. One of another train's is none, as of `aside` at the root of a config of several trains.
|
|
286
|
-
*/
|
|
287
|
-
const asideFaults = (aside, workspace) => {
|
|
288
|
-
const names = new Set(workspace.map(({ name }) => name));
|
|
289
|
-
const unknown = (aside ?? []).filter((name) => !names.has(name));
|
|
290
|
-
return unknown.length === 0
|
|
291
|
-
? []
|
|
292
|
-
: [
|
|
293
|
-
new TrainsError('EPUBLISHCHECK', `\`aside\` names ${unknown.join(', ')}, of no package of the workspace.`, 'Name a package of the workspace in `aside`, by the name of its package.json.')
|
|
294
|
-
];
|
|
295
|
-
};
|
|
296
342
|
/**
|
|
297
343
|
* The packages of a packed release that the registry has at its version already, by name, asked by
|
|
298
|
-
* the publisher's {@link Publisher.lookup}, a few at a time
|
|
299
|
-
* dist-tags, `EPUBLISHBEHIND` of a package it has not whose dist-tag
|
|
300
|
-
* of an older release published after a newer one, which would move
|
|
301
|
-
* package of `aside`, which goes under the dist-
|
|
302
|
-
* package it has is no fault: an older release run
|
|
303
|
-
*
|
|
304
|
-
* first publish.
|
|
344
|
+
* the publisher's {@link Publisher.lookup}, a few at a time, of the first dist-tag of `moving`;
|
|
345
|
+
* and, of a publisher that reads dist-tags, `EPUBLISHBEHIND` of a package it has not whose dist-tag
|
|
346
|
+
* points above the release, as of an older release published after a newer one, which would move
|
|
347
|
+
* the dist-tag back, but of a package of `aside`, which goes under the dist-tags of `aside.moving`,
|
|
348
|
+
* unless the first of them points above it too. A package it has is no fault: an older release run
|
|
349
|
+
* again, all of it on the registry, publishes nothing. {@link prepareRelease} asks it, before
|
|
350
|
+
* anything is published, and {@link publishPacked} before the first publish.
|
|
305
351
|
*
|
|
306
|
-
* @param packed - The release asked of: its packages, its version
|
|
307
|
-
* @param run - The registry, the packages of `aside`, the
|
|
352
|
+
* @param packed - The release asked of: its packages, its version and its publisher.
|
|
353
|
+
* @param run - The dist-tags, the registry, the packages of `aside`, the platform and the log the
|
|
354
|
+
* run asks by.
|
|
308
355
|
* @returns The packages the registry has at the version, and those that go aside.
|
|
309
356
|
*/
|
|
310
357
|
export function publishedOf(packed, run) {
|
|
311
358
|
return publishedIn(packed, run, contextOf(run));
|
|
312
359
|
}
|
|
313
|
-
/**
|
|
314
|
-
* {@link publishedOf} of a release {@link resolveManifests} resolved, packed of nothing: each
|
|
315
|
-
* package of its folder in the repo, by the publisher of `run`, npm's by default. As the job of a
|
|
316
|
-
* release asks it of the next version before the tag: what it would find, with no pack.
|
|
317
|
-
*
|
|
318
|
-
* @param resolved - The packages of the release, of {@link resolveManifests}.
|
|
319
|
-
* @param run - The publisher, the registry, the packages of `aside`, the system and the log the run
|
|
320
|
-
* asks by.
|
|
321
|
-
* @returns The packages the registry has at the version, and those that go aside.
|
|
322
|
-
*/
|
|
323
|
-
export function publishedOfResolved(resolved, run) {
|
|
324
|
-
const cwd = run.cwd ?? run.system.cwd;
|
|
325
|
-
return publishedOf({
|
|
326
|
-
train: resolved.train,
|
|
327
|
-
version: resolved.version,
|
|
328
|
-
distTag: resolved.distTag,
|
|
329
|
-
publisher: run.publisher ?? npmPublisher,
|
|
330
|
-
packages: resolved.packages.map(({ name, dir, manifest }) => ({
|
|
331
|
-
name,
|
|
332
|
-
version: resolved.version,
|
|
333
|
-
dir: joinPath(cwd, dir),
|
|
334
|
-
manifest
|
|
335
|
-
}))
|
|
336
|
-
}, run);
|
|
337
|
-
}
|
|
338
360
|
/**
|
|
339
361
|
* {@link publishedOf} in the context `context`, so a caller that publishes after it keeps one store
|
|
340
362
|
* of the registry's answers, of which a publish forgets what it changes.
|
|
341
363
|
*/
|
|
342
364
|
async function publishedIn(packed, run, context) {
|
|
343
|
-
const { version,
|
|
344
|
-
|
|
345
|
-
//
|
|
346
|
-
|
|
365
|
+
const { version, publisher, packages } = packed;
|
|
366
|
+
const [distTag] = run.moving;
|
|
367
|
+
// Its names are checked of the workspace where it is read, as `resolvePlan` and `checkPlan` do: a
|
|
368
|
+
// name of no package of the release here is another release's.
|
|
369
|
+
const asidePackages = new Set(run.aside?.packages ?? []);
|
|
347
370
|
const asked = await lookupAll(publisher, packages.map((pkg) => ({ pkg })), version, distTag, context, run.registry);
|
|
348
371
|
const behind = asked.filter(({ published, tagged }) => !published && isAhead(tagged, version, distTag));
|
|
349
|
-
const aside =
|
|
372
|
+
const aside = run.aside?.moving?.[0];
|
|
350
373
|
const blocking = behind.filter(({ pkg }) => aside === undefined || !asidePackages.has(pkg.name));
|
|
351
374
|
const faults = blocking.length === 0
|
|
352
375
|
? []
|
|
353
376
|
: [
|
|
354
|
-
new
|
|
355
|
-
? run.
|
|
356
|
-
? `This run published nothing. Release forward: a release of a branch of maintenance puts nothing aside, as its channel, ${distTag}, is its line.`
|
|
357
|
-
: `This run published nothing. Release forward: ${distTag} is of a line already, which has no other aside of it.`
|
|
377
|
+
new NpmError('EPUBLISHBEHIND', `${version} is below what the dist-tag ${distTag} points at, ${blocking.map(({ pkg, tagged }) => `${pkg.name}@${tagged}`).join(', ')}: publishing it would move ${distTag} back.`, aside === undefined
|
|
378
|
+
? `This run published nothing. Release forward${run.aside?.none === undefined ? '.' : `: ${run.aside.none}`}`
|
|
358
379
|
: `This run published nothing. Release forward; or, of a package that joined the train at a higher version of its own, name it in \`aside\`, which publishes it under ${aside}, and its ${distTag} stays.`)
|
|
359
380
|
];
|
|
360
381
|
const published = new Set(asked.flatMap(({ pkg, published: has }) => (has ? [pkg.name] : [])));
|
|
361
382
|
if (aside === undefined) {
|
|
362
383
|
throwAll(faults);
|
|
363
|
-
return { published, aside: new Set()
|
|
384
|
+
return { published, aside: new Set() };
|
|
364
385
|
}
|
|
365
|
-
// Each to publish that goes aside: of `aside`, behind the
|
|
386
|
+
// Each to publish that goes aside: of `aside`, behind the release's dist-tag.
|
|
366
387
|
const goes = behind.filter(({ pkg }) => asidePackages.has(pkg.name));
|
|
367
388
|
// A package of `aside` the registry has already, whose dist-tag points above the release, and
|
|
368
|
-
// whose dist-tag
|
|
369
|
-
//
|
|
389
|
+
// whose dist-tag aside points at it, went aside of an earlier run of it, as of a retry: so it is
|
|
390
|
+
// recorded. One the dist-tag aside points elsewhere at went out on the release's.
|
|
370
391
|
const maybe = asked.filter(({ pkg, published: has, tagged }) => has && asidePackages.has(pkg.name) && isAhead(tagged, version, distTag));
|
|
371
|
-
// The dist-tag
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
//
|
|
392
|
+
// The dist-tag aside is no more to move back than the release's: each to publish is asked of it
|
|
393
|
+
// too, in the same round as those of an earlier run, each in its place, and of a package that
|
|
394
|
+
// blocks the release too, so every fault is thrown together. Each is marked of what it is asked
|
|
395
|
+
// for.
|
|
375
396
|
const ofLine = maybe.length + goes.length === 0
|
|
376
397
|
? []
|
|
377
398
|
: await lookupAll(publisher, [
|
|
@@ -385,36 +406,55 @@ async function publishedIn(packed, run, context) {
|
|
|
385
406
|
...(asideAhead.length === 0
|
|
386
407
|
? []
|
|
387
408
|
: [
|
|
388
|
-
new
|
|
409
|
+
new NpmError('EPUBLISHBEHIND', `${version} is below what the dist-tag ${aside} points at, ${asideAhead.map(({ pkg, tagged }) => `${pkg.name}@${tagged}`).join(', ')}: publishing it aside would move ${aside} back.`, 'This run published nothing. Release forward.')
|
|
389
410
|
])
|
|
390
411
|
]);
|
|
391
|
-
return {
|
|
392
|
-
published,
|
|
393
|
-
aside: new Set([...goes, ...went].map(({ pkg }) => pkg.name)),
|
|
394
|
-
asideTag: aside
|
|
395
|
-
};
|
|
412
|
+
return { published, aside: new Set([...goes, ...went].map(({ pkg }) => pkg.name)) };
|
|
396
413
|
}
|
|
397
414
|
/**
|
|
398
|
-
* Publishes the packages {@link
|
|
399
|
-
*
|
|
400
|
-
* registry has at the version already
|
|
401
|
-
*
|
|
402
|
-
*
|
|
415
|
+
* Publishes the packages {@link packRelease} packed, each in order, under the first dist-tag of
|
|
416
|
+
* `moving`, with the provenance of the build where the CI gives an ID token, and skips each the
|
|
417
|
+
* registry has at the version already; then points each other dist-tag of `moving` at the version,
|
|
418
|
+
* of each package, as {@link moveRelease} does, and of a package aside each other of
|
|
419
|
+
* `aside.moving`. Before the first, it asks the registry by {@link publishedOf}: `EPUBLISHBEHIND`
|
|
420
|
+
* of a release that would move a dist-tag back, and nothing published. It removes what it packed
|
|
421
|
+
* after: every tarball, of a `tarballDir` named too, of a publish that fails, whose error is the
|
|
422
|
+
* one thrown, as a release that failed has no assets; the copies, and the tarballs but of a
|
|
423
|
+
* `tarballDir` named, of one that passes. A copy that cannot be removed then fails nothing: the log
|
|
424
|
+
* says where it stays.
|
|
403
425
|
*
|
|
404
|
-
* @param packed - The packages of the release, of {@link
|
|
405
|
-
* @param run - The access, the provenance, the registry, the
|
|
426
|
+
* @param packed - The packages of the release, of {@link packRelease}.
|
|
427
|
+
* @param run - The dist-tags, the access, the provenance, the registry, the packages of `aside`,
|
|
428
|
+
* the platform and the log of the publish.
|
|
406
429
|
* @returns What was published, and what was skipped, of each package.
|
|
407
430
|
*/
|
|
408
|
-
export async function
|
|
431
|
+
export async function publishPacked(packed, run) {
|
|
432
|
+
let published;
|
|
433
|
+
try {
|
|
434
|
+
published = await publishAll(packed, run);
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
await packed.discard();
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
await packed.cleanup().catch((error) => {
|
|
441
|
+
run.log?.(`Left ${packed.staging}: ${error.message}`);
|
|
442
|
+
});
|
|
443
|
+
return published;
|
|
444
|
+
}
|
|
445
|
+
/** {@link publishPacked}, of no removal of what was packed. */
|
|
446
|
+
async function publishAll(packed, run) {
|
|
409
447
|
const context = contextOf(run);
|
|
410
|
-
const {
|
|
411
|
-
const { version,
|
|
412
|
-
const
|
|
413
|
-
const
|
|
448
|
+
const { platform, dryRun, log } = context;
|
|
449
|
+
const { version, publisher, packages } = packed;
|
|
450
|
+
const [distTag, ...more] = run.moving;
|
|
451
|
+
const provenance = provenanceOf(run.provenance, platform.env);
|
|
452
|
+
const { published, aside } = await publishedIn(packed, run, context);
|
|
453
|
+
const [asideTag, ...asideMore] = run.aside?.moving ?? [];
|
|
414
454
|
const done = [];
|
|
415
455
|
for (const pkg of packages) {
|
|
416
456
|
const skip = published.has(pkg.name);
|
|
417
|
-
// A package of `aside` whose dist-tag points above the release, under the dist-tag
|
|
457
|
+
// A package of `aside` whose dist-tag points above the release, under the dist-tag aside.
|
|
418
458
|
const tag = aside.has(pkg.name) && asideTag !== undefined ? asideTag : distTag;
|
|
419
459
|
if (!skip) {
|
|
420
460
|
const access = run.access ??
|
|
@@ -438,9 +478,22 @@ export async function publishTrain(packed, run) {
|
|
|
438
478
|
status: skip ? 'skipped' : 'published',
|
|
439
479
|
// Of one published aside, of this run or an earlier one of the release, its dist-tag.
|
|
440
480
|
...(tag === distTag ? {} : { distTag: tag }),
|
|
441
|
-
page: publisher.page?.(pkg, version, run.registry)
|
|
481
|
+
page: publisher.page?.(pkg, version, run.registry),
|
|
482
|
+
registry: registryOf(pkg, run.registry)
|
|
442
483
|
});
|
|
443
484
|
}
|
|
485
|
+
// Each other dist-tag of the release, or aside, pointed at the version too, each as a move does.
|
|
486
|
+
const of = (goesAside) => packages
|
|
487
|
+
.filter(({ name }) => aside.has(name) === goesAside)
|
|
488
|
+
.map((pkg) => ({ pkg, dir: relativePath(packed.staging, pkg.dir) || '.' }));
|
|
489
|
+
for (const [tags, items] of [
|
|
490
|
+
[more, of(false)],
|
|
491
|
+
[asideMore, of(true)]
|
|
492
|
+
])
|
|
493
|
+
for (const tag of tags)
|
|
494
|
+
// oxlint-disable-next-line no-await-in-loop -- one dist-tag after another
|
|
495
|
+
if (items.length > 0)
|
|
496
|
+
await moveTag(publisher, items, version, tag, context, run.registry);
|
|
444
497
|
return { version, distTag, publisher: publisher.name, packages: done };
|
|
445
498
|
}
|
|
446
499
|
/** How many questions {@link lookupAll} asks the registry at a time: as many processes of npm. */
|
|
@@ -448,9 +501,9 @@ const LOOKUPS = 4;
|
|
|
448
501
|
/**
|
|
449
502
|
* What the registry has of the package of each of `items`, in their order, each item given back
|
|
450
503
|
* with the {@link Lookup} of its package, by the publisher's {@link Publisher.lookup},
|
|
451
|
-
* {@link LOOKUPS} at a time. Each settles before a fault is thrown, so no question runs on in a
|
|
452
|
-
* the caller then removes; a fault of the code is thrown as it is, and every question that
|
|
453
|
-
* together, each by `advise`.
|
|
504
|
+
* {@link LOOKUPS} at a time. Each settles before a fault is thrown, so no question runs on in a
|
|
505
|
+
* copy the caller then removes; a fault of the code is thrown as it is, and every question that
|
|
506
|
+
* failed, together, each by `advise`.
|
|
454
507
|
*/
|
|
455
508
|
async function lookupAll(publisher, items, version, distTag, context, registry, advise = (error) => error) {
|
|
456
509
|
// At most LOOKUPS questions at a time, each package's answer in its place.
|
|
@@ -475,7 +528,7 @@ async function lookupAll(publisher, items, version, distTag, context, registry,
|
|
|
475
528
|
await Promise.all(Array.from({ length: Math.min(LOOKUPS, items.length) }, worker));
|
|
476
529
|
const failed = settled.flatMap((each) => each.status === 'rejected' ? [each.reason] : []);
|
|
477
530
|
// By its index, so a rejection of no reason, as `undefined`, is thrown as it is too.
|
|
478
|
-
const unexpected = failed.findIndex((error) => !(error
|
|
531
|
+
const unexpected = failed.findIndex((error) => !isReleaseError(error));
|
|
479
532
|
if (unexpected !== -1)
|
|
480
533
|
throw failed[unexpected];
|
|
481
534
|
// An answer that is no Lookup, as a boolean of a publisher's own, would read as not published,
|
|
@@ -498,7 +551,7 @@ async function lookupAll(publisher, items, version, distTag, context, registry,
|
|
|
498
551
|
...(malformed.length === 0
|
|
499
552
|
? []
|
|
500
553
|
: [
|
|
501
|
-
new
|
|
554
|
+
new NpmError('EPUBLISHER', `The publisher ${publisher.name} looked up ${malformed.join(', ')} with no Lookup.`, 'A lookup answers `{ published, tagged }`: `published` a boolean, `tagged` a version, or none, as `undefined` or `null`. See the Publisher type.')
|
|
502
555
|
])
|
|
503
556
|
]);
|
|
504
557
|
// The two answers alone, so no other key of a publisher's own answer, as `pkg`, overwrites the
|
|
@@ -509,11 +562,10 @@ async function lookupAll(publisher, items, version, distTag, context, registry,
|
|
|
509
562
|
return { ...item, published, tagged: tagged ?? undefined };
|
|
510
563
|
});
|
|
511
564
|
}
|
|
512
|
-
/** The context a publisher runs in, of a run's options: the
|
|
565
|
+
/** The context a publisher runs in, of a run's options: the folder of the repo, the platform. */
|
|
513
566
|
const contextOf = (run) => ({
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
env: run.env ?? run.system.env,
|
|
567
|
+
root: run.root,
|
|
568
|
+
platform: run.platform,
|
|
517
569
|
dryRun: run.dryRun ?? false,
|
|
518
570
|
log: run.log ?? (() => { }),
|
|
519
571
|
// One store of the registry's answers a step: each step asks afresh.
|
|
@@ -531,114 +583,83 @@ const isAhead = (at, version, distTag) => at !== undefined &&
|
|
|
531
583
|
semver.gt(at, version) &&
|
|
532
584
|
(distTag !== 'latest' || semver.prerelease(at) === null || semver.prerelease(version) !== null);
|
|
533
585
|
/**
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
* published ({@link publishTrain}). The copies go after, and the tarballs but of a `tarballDir`
|
|
537
|
-
* named; every tarball goes of a publish that fails, whose error is the one thrown. A copy that
|
|
538
|
-
* cannot be removed after the publish fails nothing: the log says where it stays.
|
|
539
|
-
*
|
|
540
|
-
* @param release - The release, and what each of its three steps takes.
|
|
541
|
-
* @returns What was published, and what was skipped, of each package.
|
|
586
|
+
* The dist-tag `tag` of each package of `items` pointed at `version`, in order, as
|
|
587
|
+
* {@link moveRelease} moves each.
|
|
542
588
|
*/
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
* Publishes a release {@link packTrain} packed, by {@link publishTrain}, and removes what it packed:
|
|
548
|
-
* every tarball, of a `tarballDir` named too, of a publish that fails, whose error is the one
|
|
549
|
-
* thrown, as a release that failed has no assets; the copies, and the tarballs but of a
|
|
550
|
-
* `tarballDir` named, of one that passes. A copy that cannot be removed then fails nothing: the log
|
|
551
|
-
* says where it stays.
|
|
552
|
-
*
|
|
553
|
-
* @param packed - The packages of the release, of {@link packTrain}.
|
|
554
|
-
* @param run - The access, the provenance, the registry, the system and the log of the publish.
|
|
555
|
-
* @returns What was published, and what was skipped, of each package.
|
|
556
|
-
*/
|
|
557
|
-
export async function publishPacked(packed, run) {
|
|
558
|
-
let published;
|
|
559
|
-
try {
|
|
560
|
-
published = await publishTrain(packed, run);
|
|
561
|
-
}
|
|
562
|
-
catch (error) {
|
|
563
|
-
await packed.discard();
|
|
564
|
-
throw error;
|
|
565
|
-
}
|
|
566
|
-
await packed.cleanup().catch((error) => {
|
|
567
|
-
run.log?.(`Left ${packed.staging}: ${error.message}`);
|
|
568
|
-
});
|
|
569
|
-
return published;
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Moves a release of a train published already to the channel of `channel`: the dist-tag of each
|
|
573
|
-
* package of the train that publishes pointed at the version, in the order of publishing, by the
|
|
574
|
-
* publisher's {@link Publisher.tag}; each the registry does not have at the version, as a package
|
|
575
|
-
* that joined the train after the release, skipped, and each whose dist-tag points above the
|
|
576
|
-
* version, of a publisher that reads dist-tags, as of an older release moved after a newer one,
|
|
577
|
-
* which would move it back; one whose dist-tag points at the version already is on the channel,
|
|
578
|
-
* and not moved again. The registry is asked of every package, a few at a time, by the
|
|
579
|
-
* publisher's {@link Publisher.lookup}, before the first dist-tag moves. A publisher that moves no
|
|
580
|
-
* dist-tag moves none, and says so: the release stays on its channel.
|
|
581
|
-
*
|
|
582
|
-
* @param release - The trains, the train, the version and the channel of the release, the
|
|
583
|
-
* publisher, the system and the log.
|
|
584
|
-
* @returns What was moved, and what was skipped, of each package.
|
|
585
|
-
*/
|
|
586
|
-
export async function tagTrain(release) {
|
|
587
|
-
const { version } = release;
|
|
588
|
-
const context = contextOf(release);
|
|
589
|
-
const { system, cwd, log } = context;
|
|
590
|
-
const publisher = release.publisher ?? npmPublisher;
|
|
591
|
-
const distTag = distTagOfChannel(release.channel, version);
|
|
592
|
-
// The train is selected first, so a run of no train fails of a publisher that moves nothing too.
|
|
593
|
-
const { order } = await publishingOf(release.trains, release.train, {
|
|
594
|
-
cwd,
|
|
595
|
-
system,
|
|
596
|
-
first: release.first,
|
|
597
|
-
last: release.last
|
|
598
|
-
});
|
|
599
|
-
if (publisher.tag === undefined) {
|
|
600
|
-
log(`The publisher ${publisher.name} moves no dist-tag: ${version} stays on its channel.`);
|
|
601
|
-
return { version, distTag, publisher: publisher.name, packages: [] };
|
|
602
|
-
}
|
|
603
|
-
// Each package with its folder from the root of the repo, as the order gives it.
|
|
604
|
-
const listed = order.map(({ name: each, dir, json }) => ({
|
|
605
|
-
dir,
|
|
606
|
-
pkg: { name: each, version, dir: joinPath(cwd, dir), manifest: json }
|
|
607
|
-
}));
|
|
589
|
+
async function moveTag(publisher, items, version, tag, context, registry) {
|
|
590
|
+
const { log } = context;
|
|
591
|
+
if (publisher.tag === undefined)
|
|
592
|
+
return [];
|
|
608
593
|
// The question to the registry of each package, a few at a time, before the first dist-tag moves:
|
|
609
|
-
// a question that fails moves none.
|
|
610
|
-
|
|
611
|
-
// `addChannel`.
|
|
612
|
-
const asked = await lookupAll(publisher, listed, version, distTag, context, release.registry, (error) => new TrainsError(error.code, error.message, `Once the cause is fixed, point the dist-tag ${distTag} at ${version} by hand, of each package of the train the registry has at ${version} whose ${distTag} is not above it, as one above it would move back: a run of semantic-release again moves no dist-tag, as it records the channel of a release before it asks for \`addChannel\`.`));
|
|
594
|
+
// a question that fails moves none.
|
|
595
|
+
const asked = await lookupAll(publisher, items, version, tag, context, registry, (error) => new NpmError(error.code, error.message, `Once the cause is fixed, move the release to ${tag} again: a dist-tag that points at ${version} already is not moved again, and one above it stays.`));
|
|
613
596
|
const done = [];
|
|
614
597
|
for (const { pkg, dir, published: has, tagged: at } of asked) {
|
|
615
598
|
const each = pkg.name;
|
|
616
599
|
// A dist-tag that points above the release stays, as a retry of an older release would move it
|
|
617
600
|
// back.
|
|
618
|
-
const behind = has && isAhead(at, version,
|
|
601
|
+
const behind = has && isAhead(at, version, tag);
|
|
619
602
|
// A dist-tag that points at the version already is on the channel: it is not moved again.
|
|
620
603
|
const there = has && at === version;
|
|
621
604
|
const move = has && !behind && !there;
|
|
622
605
|
// oxlint-disable-next-line no-await-in-loop -- in order, one after the other
|
|
623
606
|
if (move)
|
|
624
|
-
await publisher.tag(pkg, version,
|
|
607
|
+
await publisher.tag(pkg, version, tag, context, registry);
|
|
625
608
|
log(move
|
|
626
|
-
? `${context.dryRun ? 'WOULD TAG' : 'TAGGED'} ${each}@${version} ${
|
|
609
|
+
? `${context.dryRun ? 'WOULD TAG' : 'TAGGED'} ${each}@${version} ${tag} by ${publisher.name}.`
|
|
627
610
|
: there
|
|
628
|
-
? `TAGGED ${each}@${version} ${
|
|
611
|
+
? `TAGGED ${each}@${version} ${tag} already.`
|
|
629
612
|
: behind
|
|
630
|
-
? `SKIP ${each}@${version}: ${
|
|
613
|
+
? `SKIP ${each}@${version}: ${tag} points at ${at}, above it, and stays.`
|
|
631
614
|
: `SKIP ${each}@${version}: not on the registry, so no dist-tag to move.`);
|
|
632
615
|
done.push({
|
|
633
616
|
name: each,
|
|
634
617
|
version,
|
|
635
618
|
dir,
|
|
619
|
+
tag,
|
|
636
620
|
status: move || there ? 'tagged' : 'skipped',
|
|
637
621
|
// A version the registry has not has no page.
|
|
638
|
-
page: has ? publisher.page?.(pkg, version,
|
|
622
|
+
page: has ? publisher.page?.(pkg, version, registry) : undefined,
|
|
623
|
+
registry: registryOf(pkg, registry)
|
|
639
624
|
});
|
|
640
625
|
}
|
|
641
|
-
return
|
|
626
|
+
return done;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Moves a release published already to the dist-tags of `moving`: each pointed at the version, of
|
|
630
|
+
* each package of the plan, in the order of publishing, by the publisher's {@link Publisher.tag};
|
|
631
|
+
* each the registry does not have at the version, as a package that joined the release after it was
|
|
632
|
+
* published, skipped, and each whose dist-tag points above the version, of a publisher that reads
|
|
633
|
+
* dist-tags, as of an older release moved after a newer one, which would move it back; one whose
|
|
634
|
+
* dist-tag points at the version already is there, and not moved again. The registry is asked of
|
|
635
|
+
* every package, a few at a time, by the publisher's {@link Publisher.lookup}, before the first
|
|
636
|
+
* dist-tag moves. A publisher that moves no dist-tag moves none, and says so: the release stays
|
|
637
|
+
* where it was published.
|
|
638
|
+
*
|
|
639
|
+
* @param release - The version of the release, the folder of the repo, the platform and the log.
|
|
640
|
+
* @param plan - The packages that publish, in order.
|
|
641
|
+
* @param options - The dist-tags, the publisher and the registry.
|
|
642
|
+
* @returns What was moved, and what was skipped, of each package and each dist-tag.
|
|
643
|
+
*/
|
|
644
|
+
export async function moveRelease(release, plan, options) {
|
|
645
|
+
const { version } = release;
|
|
646
|
+
const context = contextOf(release);
|
|
647
|
+
const cwd = context.platform.dirs.cwd;
|
|
648
|
+
const publisher = options.publisher ?? npmPublisher;
|
|
649
|
+
if (publisher.tag === undefined) {
|
|
650
|
+
context.log(`The publisher ${publisher.name} moves no dist-tag: ${version} stays on its channel.`);
|
|
651
|
+
return { version, publisher: publisher.name, packages: [] };
|
|
652
|
+
}
|
|
653
|
+
// Each package with its folder from the root of the repo, as the plan gives it.
|
|
654
|
+
const items = plan.own.map(({ name, dir, json }) => ({
|
|
655
|
+
dir,
|
|
656
|
+
pkg: { name, version, dir: joinPath(cwd, dir), manifest: json }
|
|
657
|
+
}));
|
|
658
|
+
const packages = [];
|
|
659
|
+
for (const tag of options.moving)
|
|
660
|
+
// oxlint-disable-next-line no-await-in-loop -- one dist-tag after another
|
|
661
|
+
packages.push(...(await moveTag(publisher, items, version, tag, context, options.registry)));
|
|
662
|
+
return { version, publisher: publisher.name, packages };
|
|
642
663
|
}
|
|
643
664
|
/**
|
|
644
665
|
* Whether a release is published with provenance: of the option, or of an ID token of the CI on a
|
|
@@ -648,39 +669,143 @@ const provenanceOf = (option, env) => option === undefined || option === 'auto'
|
|
|
648
669
|
? ID_TOKENS.some((name) => Boolean(env[name])) &&
|
|
649
670
|
!RUNNER_ENVIRONMENTS.some((name) => env[name] === 'self-hosted')
|
|
650
671
|
: option;
|
|
672
|
+
/** What `prepare` packed, by the folder of the repo, the version and the packages. */
|
|
673
|
+
const packed = new Map();
|
|
674
|
+
/** The key of what is packed of a release and its plan. */
|
|
675
|
+
const keyOf = ({ platform, version }, plan) => `${platform.dirs.cwd}\0${version}\0${plan.own.map(({ name }) => name).join('\0')}`;
|
|
676
|
+
/** The options of a pack and a publish of a step, of the release and the options of the release. */
|
|
677
|
+
const runOf = (release, options) => ({
|
|
678
|
+
...options,
|
|
679
|
+
root: release.root,
|
|
680
|
+
platform: release.platform,
|
|
681
|
+
dryRun: release.dryRun,
|
|
682
|
+
log: release.log
|
|
683
|
+
});
|
|
651
684
|
/**
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
685
|
+
* The packages of a release packed: what `prepare` packed of it in this process, which a later step
|
|
686
|
+
* takes, or packed anew of its plan.
|
|
687
|
+
*/
|
|
688
|
+
async function packedOf(release, plan, options) {
|
|
689
|
+
const kept = packed.get(keyOf(release, plan));
|
|
690
|
+
if (kept !== undefined)
|
|
691
|
+
return { release: kept, kept: true };
|
|
692
|
+
const run = runOf(release, options);
|
|
693
|
+
return { release: await packRelease(await resolvePlan(release, plan, options), run), kept: false };
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Prepares a release: each manifest of its plan resolved as it publishes and checked
|
|
697
|
+
* ({@link resolvePlan}), each package packed from a copy in a temporary folder of the platform
|
|
698
|
+
* ({@link packRelease}), and the registry asked ({@link publishedOf}), so a range of no version, a
|
|
699
|
+
* package that cannot be packed, or a release below the version its dist-tag points at on the
|
|
700
|
+
* registry (`EPUBLISHBEHIND`) fails before anything is published. What it packed is kept, of the
|
|
701
|
+
* folder of the repo, the version and the packages, for `smoke` and `publish` of the same process;
|
|
702
|
+
* of a step that fails, it is removed. Nothing of npm is committed: it writes no file of the repo,
|
|
703
|
+
* and gives none.
|
|
657
704
|
*
|
|
658
|
-
* @param release - The
|
|
659
|
-
* the
|
|
660
|
-
* @
|
|
705
|
+
* @param release - The version of the release, the folder of the repo, the platform and the log.
|
|
706
|
+
* @param plan - The packages that publish, in order, and the versions of the repo.
|
|
707
|
+
* @param options - The options of the release.
|
|
708
|
+
* @returns No file: none of npm is committed, as the version is the release's alone.
|
|
661
709
|
*/
|
|
662
|
-
export async function
|
|
663
|
-
const
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
710
|
+
export async function prepareRelease(release, plan, options) {
|
|
711
|
+
const run = runOf(release, options);
|
|
712
|
+
const packing = await packRelease(await resolvePlan(release, plan, options), run);
|
|
713
|
+
// A release that would move a dist-tag back fails here, before anything is published.
|
|
714
|
+
try {
|
|
715
|
+
await publishedOf(packing, run);
|
|
716
|
+
}
|
|
717
|
+
catch (error) {
|
|
718
|
+
await packing.discard();
|
|
719
|
+
throw error;
|
|
720
|
+
}
|
|
721
|
+
const key = keyOf(release, plan);
|
|
722
|
+
await packed.get(key)?.cleanup();
|
|
723
|
+
packed.set(key, packing);
|
|
724
|
+
return [];
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Tries each package of a release as a consumer installs it, and each private package of `pack`, by
|
|
728
|
+
* `smokePacked` of `./smoke`, of the globs of `forbid` and the conditions of the source: of what
|
|
729
|
+
* `prepare` packed in this process, or of a pack of its own, which it removes after. Throws
|
|
730
|
+
* `EPUBLISHSMOKE` of every fault together; what `prepare` packed is removed then too.
|
|
731
|
+
*
|
|
732
|
+
* @param release - The version of the release, the folder of the repo, the platform and the log.
|
|
733
|
+
* @param plan - The packages that publish, in order, and the versions of the repo.
|
|
734
|
+
* @param options - The options of the release.
|
|
735
|
+
*/
|
|
736
|
+
export async function smokeRelease(release, plan, options) {
|
|
737
|
+
const of = await packedOf(release, plan, options);
|
|
738
|
+
try {
|
|
739
|
+
await smokePacked({
|
|
740
|
+
packed: [of.release],
|
|
741
|
+
forbid: options.forbid,
|
|
742
|
+
conditions: options.conditions,
|
|
743
|
+
platform: release.platform,
|
|
744
|
+
log: release.log
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
catch (error) {
|
|
748
|
+
packed.delete(keyOf(release, plan));
|
|
749
|
+
await of.release.discard();
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
if (!of.kept)
|
|
753
|
+
await of.release.discard();
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Each package of a published release, for its links: of each package published or skipped, its
|
|
757
|
+
* page, the registry it was published to, and its tarball; of each package of `pack`, its tarball
|
|
758
|
+
* alone. A tarball is there of a `tarballDir` alone, as the publish removes the others.
|
|
759
|
+
*/
|
|
760
|
+
function releasedOf(published, of, kept) {
|
|
761
|
+
const file = (name) => (kept ? of.tarballs.get(name) : undefined);
|
|
762
|
+
return [
|
|
763
|
+
...published.packages.map(({ name, version, page, registry }) => ({
|
|
764
|
+
ecosystem: 'npm',
|
|
765
|
+
name,
|
|
766
|
+
version,
|
|
767
|
+
page,
|
|
768
|
+
registry: registry === undefined ? undefined : { url: registry, type: 'npm', name },
|
|
769
|
+
file: file(name)
|
|
770
|
+
})),
|
|
771
|
+
...of.packOnly.map(({ name }) => ({
|
|
772
|
+
ecosystem: 'npm',
|
|
773
|
+
name,
|
|
774
|
+
version: of.version,
|
|
775
|
+
file: file(name)
|
|
776
|
+
}))
|
|
777
|
+
];
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Publishes a release: what `prepare` packed of it in this process, or its plan resolved and packed
|
|
781
|
+
* anew ({@link resolvePlan}, {@link packRelease}), each package published in order by
|
|
782
|
+
* {@link publishPacked}, each the registry has already skipped, so a publish run again finishes a
|
|
783
|
+
* release; and what it packed removed, the tarballs of a `tarballDir` kept. Of a dry run, the
|
|
784
|
+
* publisher says what it would publish, and publishes nothing.
|
|
785
|
+
*
|
|
786
|
+
* @param release - The version of the release, the folder of the repo, the platform and the log.
|
|
787
|
+
* @param plan - The packages that publish, in order, and the versions of the repo.
|
|
788
|
+
* @param options - The options of the release.
|
|
789
|
+
* @returns Each package published, or found published, and each of `pack`: its page, its registry
|
|
790
|
+
* and, of a `tarballDir`, its tarball.
|
|
791
|
+
*/
|
|
792
|
+
export async function publishRelease(release, plan, options) {
|
|
793
|
+
const of = await packedOf(release, plan, options);
|
|
794
|
+
packed.delete(keyOf(release, plan));
|
|
795
|
+
const published = await publishPacked(of.release, runOf(release, options));
|
|
796
|
+
return releasedOf(published, of.release, options.tarballDir !== undefined);
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Removes what `prepare` packed of a release and its plan in this process, the copies and every
|
|
800
|
+
* tarball, of a `tarballDir` too, as of a release that goes no further: none of none.
|
|
801
|
+
*
|
|
802
|
+
* @param release - The version of the release and the platform, of the folder of the repo.
|
|
803
|
+
* @param plan - The packages that publish.
|
|
804
|
+
*/
|
|
805
|
+
export async function discardPacked(release, plan) {
|
|
806
|
+
const key = keyOf(release, plan);
|
|
807
|
+
const kept = packed.get(key);
|
|
808
|
+
packed.delete(key);
|
|
809
|
+
await kept?.discard();
|
|
685
810
|
}
|
|
686
811
|
//# sourceMappingURL=release.js.map
|