@wpelevator/wp-release 0.12.0 → 0.14.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 +150 -19
- package/dist/changeset-config.d.ts +91 -5
- package/dist/changeset-config.js +108 -11
- package/dist/changeset-dependents.d.ts +19 -8
- package/dist/changeset-dependents.js +96 -34
- package/dist/changeset-files.d.ts +6 -5
- package/dist/changeset-files.js +7 -5
- package/dist/changeset-packages.d.ts +55 -8
- package/dist/changeset-packages.js +85 -14
- package/dist/changeset-prompt.d.ts +119 -0
- package/dist/changeset-prompt.js +203 -0
- package/dist/changeset-release.d.ts +43 -5
- package/dist/changeset-release.js +99 -16
- package/dist/changesets.d.ts +6 -2
- package/dist/changesets.js +18 -12
- package/dist/cli.d.ts +7 -1
- package/dist/cli.js +51 -14
- package/dist/commands/args.d.ts +0 -21
- package/dist/commands/args.js +1 -35
- package/dist/commands/changeset-add.d.ts +5 -2
- package/dist/commands/changeset-add.js +109 -9
- package/dist/commands/changeset-args.d.ts +24 -5
- package/dist/commands/changeset-args.js +57 -14
- package/dist/commands/changeset-status.d.ts +3 -1
- package/dist/commands/changeset-status.js +2 -1
- package/dist/commands/changeset-tag.d.ts +1 -1
- package/dist/commands/changeset-tag.js +6 -3
- package/dist/commands/changeset-version.d.ts +7 -1
- package/dist/commands/changeset-version.js +17 -4
- package/dist/commands/checksums.js +2 -2
- package/dist/commands/command.d.ts +5 -0
- package/dist/commands/deploy-git.d.ts +24 -4
- package/dist/commands/deploy-git.js +57 -3
- package/dist/commands/deploy-svn.d.ts +24 -4
- package/dist/commands/deploy-svn.js +57 -2
- package/dist/commands/keygen.d.ts +3 -0
- package/dist/commands/keygen.js +6 -1
- package/dist/commands/package-deploys.d.ts +86 -0
- package/dist/commands/package-deploys.js +113 -0
- package/dist/commands/sign.d.ts +19 -1
- package/dist/commands/sign.js +47 -12
- package/dist/commands/verify.d.ts +3 -0
- package/dist/commands/verify.js +43 -24
- package/dist/commands/zip.d.ts +12 -8
- package/dist/commands/zip.js +135 -78
- package/dist/ed25519.d.ts +25 -0
- package/dist/ed25519.js +44 -0
- package/dist/file-selection.d.ts +21 -0
- package/dist/file-selection.js +35 -0
- package/dist/git-deploy.d.ts +32 -0
- package/dist/git-deploy.js +57 -1
- package/dist/git.d.ts +17 -0
- package/dist/git.js +23 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +7 -3
- package/dist/minisign.d.ts +41 -0
- package/dist/minisign.js +128 -0
- package/dist/package-deploy.d.ts +133 -0
- package/dist/package-deploy.js +323 -0
- package/dist/package-zip.d.ts +52 -0
- package/dist/package-zip.js +78 -0
- package/dist/release-repository.d.ts +18 -5
- package/dist/release-repository.js +51 -11
- package/dist/release-tags.d.ts +3 -1
- package/dist/release-tags.js +5 -2
- package/dist/signing.d.ts +64 -9
- package/dist/signing.js +113 -40
- package/dist/ssh-signature.d.ts +43 -0
- package/dist/ssh-signature.js +156 -0
- package/dist/summary.d.ts +3 -3
- package/dist/summary.js +2 -2
- package/dist/tag-format.d.ts +23 -14
- package/dist/tag-format.js +26 -40
- package/dist/version-files.d.ts +8 -8
- package/dist/version-files.js +22 -18
- package/dist/versions.d.ts +28 -3
- package/dist/versions.js +84 -9
- package/package.json +2 -2
package/dist/tag-format.js
CHANGED
|
@@ -1,51 +1,37 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* Tag format of the package releases, like plugins/alpha/1.2.0 in a
|
|
3
|
+
* monorepo, or 1.2.0 for a package at the repository root.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_TAG_FORMAT = '{path}/{version}';
|
|
6
|
+
/**
|
|
7
|
+
* Fill in a template of a package with {name}, {path} and {version}, like a
|
|
8
|
+
* deploy template. A package at the root of the repository has an empty
|
|
9
|
+
* {path}.
|
|
4
10
|
*
|
|
5
|
-
* @param format
|
|
6
|
-
* @param pkg Configured package.
|
|
7
|
-
* @param version Released version, empty
|
|
8
|
-
* @return
|
|
11
|
+
* @param format Template with {name}, {path} and {version}.
|
|
12
|
+
* @param pkg Configured package, with or without a version.
|
|
13
|
+
* @param version Released version, empty when there's none.
|
|
14
|
+
* @return Formatted text.
|
|
9
15
|
*/
|
|
10
|
-
export function
|
|
11
|
-
const type = pkg.group.tagType ?? defaultTagType(pkg.path, pkg.type);
|
|
16
|
+
export function formatTemplate(format, pkg, version) {
|
|
12
17
|
return format
|
|
13
18
|
.replaceAll('{name}', pkg.name)
|
|
14
|
-
.replaceAll('{
|
|
15
|
-
? path.basename(pkg.directory)
|
|
16
|
-
: path.basename(pkg.path))
|
|
17
|
-
.replaceAll('{path}', pkg.path)
|
|
18
|
-
.replaceAll('{type}', type)
|
|
19
|
+
.replaceAll('{path}', '.' === pkg.path ? '' : pkg.path)
|
|
19
20
|
.replaceAll('{version}', version);
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
|
-
* Format the tag
|
|
23
|
-
*
|
|
23
|
+
* Format the tag of a package release, or its tag prefix without a version.
|
|
24
|
+
* Empty placeholders leave no repeated or leading slashes, so a package at
|
|
25
|
+
* the repository root gets 1.2.0 for {path}/{version}. A trailing slash is
|
|
26
|
+
* kept, since it separates the tag prefix from the version.
|
|
24
27
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @return Tag prefix.
|
|
28
|
+
* @param format Tag format with {name}, {path} and {version}.
|
|
29
|
+
* @param pkg Configured package, with or without a version.
|
|
30
|
+
* @param version Released version, empty for the tag prefix of the package.
|
|
31
|
+
* @return Tag name or prefix.
|
|
29
32
|
*/
|
|
30
|
-
export function
|
|
31
|
-
return
|
|
32
|
-
.
|
|
33
|
-
.
|
|
34
|
-
.replaceAll('{name}', packagePath.split('/').at(-1) ?? packagePath)
|
|
35
|
-
.replaceAll('{slug}', packagePath.split('/').at(-1) ?? packagePath)
|
|
36
|
-
.replaceAll('{version}', '');
|
|
37
|
-
}
|
|
38
|
-
function defaultTagType(packagePath, type) {
|
|
39
|
-
if ('.' === packagePath && type) {
|
|
40
|
-
return type;
|
|
41
|
-
}
|
|
42
|
-
const first = packagePath.split('/')[0] ?? 'package';
|
|
43
|
-
const irregular = {
|
|
44
|
-
actions: 'action',
|
|
45
|
-
plugins: 'plugin',
|
|
46
|
-
themes: 'theme',
|
|
47
|
-
php: 'php',
|
|
48
|
-
js: 'js',
|
|
49
|
-
};
|
|
50
|
-
return irregular[first] ?? first.replace(/s$/, '');
|
|
33
|
+
export function formatTag(format, pkg, version) {
|
|
34
|
+
return formatTemplate(format, pkg, version)
|
|
35
|
+
.replace(/\/{2,}/g, '/')
|
|
36
|
+
.replace(/^\/+/, '');
|
|
51
37
|
}
|
package/dist/version-files.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { PackageVersionSource, PackageVersionTarget } from './changeset-config.ts';
|
|
2
|
-
import type { ConfiguredPackage } from './changeset-packages.ts';
|
|
2
|
+
import type { ConfiguredPackage, ConfiguredDeployPackage } from './changeset-packages.ts';
|
|
3
3
|
import type { FileJournal } from './file-journal.ts';
|
|
4
4
|
import type { ReleaseRepository } from './release-repository.ts';
|
|
5
5
|
/**
|
|
6
6
|
* Read the current version of a package from its configured source.
|
|
7
7
|
*
|
|
8
|
-
* @param repository
|
|
9
|
-
* @param directory
|
|
10
|
-
* @param descriptor
|
|
11
|
-
* @param
|
|
12
|
-
* @param tagType Configured {type} of the package tags.
|
|
8
|
+
* @param repository Repository, for versions stored as git tags.
|
|
9
|
+
* @param directory Package directory.
|
|
10
|
+
* @param descriptor Version source.
|
|
11
|
+
* @param pkg Package name and path, for the tags of a git-tag source.
|
|
13
12
|
* @return Current version.
|
|
14
13
|
* @throws {ValidationError} If the version is missing.
|
|
15
14
|
*/
|
|
16
|
-
export declare function readVersion(repository: ReleaseRepository, directory: string, descriptor: PackageVersionSource,
|
|
15
|
+
export declare function readVersion(repository: ReleaseRepository, directory: string, descriptor: PackageVersionSource, pkg: Pick<ConfiguredDeployPackage, 'name' | 'path'>): Promise<string>;
|
|
17
16
|
/**
|
|
18
17
|
* Write a version to a configured version target.
|
|
19
18
|
*
|
|
@@ -26,7 +25,8 @@ export declare function readVersion(repository: ReleaseRepository, directory: st
|
|
|
26
25
|
export declare function writeVersion(directory: string, descriptor: PackageVersionTarget, version: string, journal: FileJournal): Promise<void>;
|
|
27
26
|
/**
|
|
28
27
|
* Check that every version target of a package has the expected version.
|
|
29
|
-
* Optional targets that are absent are skipped
|
|
28
|
+
* Optional targets that are absent are skipped, and so is the readme Stable
|
|
29
|
+
* tag of a pre-release.
|
|
30
30
|
*
|
|
31
31
|
* @param repository Repository, for versions stored as git tags.
|
|
32
32
|
* @param pkg Configured package.
|
package/dist/version-files.js
CHANGED
|
@@ -4,21 +4,20 @@ import { ValidationError } from "./errors.js";
|
|
|
4
4
|
import { readJson } from "./json-files.js";
|
|
5
5
|
import { findMainPluginFile } from "./package-meta.js";
|
|
6
6
|
import { escapeRegExp } from "./regexp.js";
|
|
7
|
-
import {
|
|
7
|
+
import { DEFAULT_TAG_FORMAT, formatTag } from "./tag-format.js";
|
|
8
8
|
import { findConstantValues } from "./version-check.js";
|
|
9
|
-
import { compareVersions } from "./versions.js";
|
|
9
|
+
import { compareVersions, isPrerelease } from "./versions.js";
|
|
10
10
|
/**
|
|
11
11
|
* Read the current version of a package from its configured source.
|
|
12
12
|
*
|
|
13
|
-
* @param repository
|
|
14
|
-
* @param directory
|
|
15
|
-
* @param descriptor
|
|
16
|
-
* @param
|
|
17
|
-
* @param tagType Configured {type} of the package tags.
|
|
13
|
+
* @param repository Repository, for versions stored as git tags.
|
|
14
|
+
* @param directory Package directory.
|
|
15
|
+
* @param descriptor Version source.
|
|
16
|
+
* @param pkg Package name and path, for the tags of a git-tag source.
|
|
18
17
|
* @return Current version.
|
|
19
18
|
* @throws {ValidationError} If the version is missing.
|
|
20
19
|
*/
|
|
21
|
-
export async function readVersion(repository, directory, descriptor,
|
|
20
|
+
export async function readVersion(repository, directory, descriptor, pkg) {
|
|
22
21
|
if ('package-json' === descriptor.kind ||
|
|
23
22
|
'composer-json' === descriptor.kind) {
|
|
24
23
|
const manifest = await readJson(path.join(directory, descriptor.file));
|
|
@@ -29,16 +28,16 @@ export async function readVersion(repository, directory, descriptor, relativePat
|
|
|
29
28
|
throw new ValidationError(`Missing ${descriptor.file}#${descriptor.field} in ${directory}.`);
|
|
30
29
|
}
|
|
31
30
|
if ('git-tag' === descriptor.kind) {
|
|
32
|
-
const pattern = descriptor.pattern ??
|
|
33
|
-
const tags = await repository.listTags(
|
|
31
|
+
const pattern = descriptor.pattern ?? DEFAULT_TAG_FORMAT;
|
|
32
|
+
const tags = await repository.listTags(formatTag(pattern, pkg, ''));
|
|
34
33
|
const versions = tags
|
|
35
|
-
.map((tag) => tag.match(/(?:^|\/|v)(\d
|
|
34
|
+
.map((tag) => tag.match(/(?:^|\/|v)(\d+(?:\.\d+){1,3})$/)?.[1])
|
|
36
35
|
.filter((item) => Boolean(item));
|
|
37
36
|
versions.sort((a, b) => compareVersions(b, a));
|
|
38
37
|
if (versions[0]) {
|
|
39
38
|
return versions[0];
|
|
40
39
|
}
|
|
41
|
-
throw new ValidationError(`No git tag matches ${pattern} for ${
|
|
40
|
+
throw new ValidationError(`No git tag matches ${pattern} for ${pkg.path}.`);
|
|
42
41
|
}
|
|
43
42
|
if ('php-constant' === descriptor.kind) {
|
|
44
43
|
const file = path.join(directory, descriptor.file);
|
|
@@ -99,9 +98,12 @@ export async function writeVersion(directory, descriptor, version, journal) {
|
|
|
99
98
|
await writeFile(file, updated);
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
101
|
+
// The readme Stable tag keeps the last stable version for a pre-release,
|
|
102
|
+
// since WordPress.org offers the stable tag to every site.
|
|
102
103
|
if ('wordpress-stable-tag' === descriptor.kind &&
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
(isPrerelease(version) ||
|
|
105
|
+
(descriptor.ifPresent &&
|
|
106
|
+
!(await versionFileExists(directory, descriptor.kind, descriptor.file))))) {
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
109
|
const file = path.join(directory, await getVersionFile(directory, descriptor.kind, descriptor.file));
|
|
@@ -116,7 +118,8 @@ export async function writeVersion(directory, descriptor, version, journal) {
|
|
|
116
118
|
}
|
|
117
119
|
/**
|
|
118
120
|
* Check that every version target of a package has the expected version.
|
|
119
|
-
* Optional targets that are absent are skipped
|
|
121
|
+
* Optional targets that are absent are skipped, and so is the readme Stable
|
|
122
|
+
* tag of a pre-release.
|
|
120
123
|
*
|
|
121
124
|
* @param repository Repository, for versions stored as git tags.
|
|
122
125
|
* @param pkg Configured package.
|
|
@@ -132,12 +135,13 @@ export async function verifyVersionTargets(repository, pkg, expected) {
|
|
|
132
135
|
actual = undefined;
|
|
133
136
|
}
|
|
134
137
|
else if ('wordpress-stable-tag' === target.kind &&
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
(isPrerelease(expected) ||
|
|
139
|
+
(target.ifPresent &&
|
|
140
|
+
!(await versionFileExists(pkg.directory, target.kind, target.file))))) {
|
|
137
141
|
actual = undefined;
|
|
138
142
|
}
|
|
139
143
|
else {
|
|
140
|
-
actual = await readVersion(repository, pkg.directory, target, pkg
|
|
144
|
+
actual = await readVersion(repository, pkg.directory, target, pkg);
|
|
141
145
|
}
|
|
142
146
|
if (undefined !== actual && actual !== expected) {
|
|
143
147
|
throw new ValidationError(`Version mismatch for ${pkg.name}: expected ${expected}, found ${actual}.`);
|
package/dist/versions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Check whether a string is a
|
|
2
|
+
* Check whether a string is a version, like 1.2.0, 1.2.0-rc.1, 2.1 or 1.2.3.4.
|
|
3
3
|
*
|
|
4
4
|
* @param version Version.
|
|
5
5
|
* @return Whether the version is valid.
|
|
@@ -15,11 +15,36 @@ export declare function isPrerelease(version: string): boolean;
|
|
|
15
15
|
/**
|
|
16
16
|
* Compare two versions with SemVer precedence, where a pre-release like
|
|
17
17
|
* 1.0.0-rc.1 comes before 1.0.0. Unlike the semver package, it doesn't throw
|
|
18
|
-
* for versions outside SemVer, like
|
|
19
|
-
*
|
|
18
|
+
* for versions outside SemVer, like 1.2 or 1.2.3.4: every part is compared,
|
|
19
|
+
* and missing parts count as 0.
|
|
20
20
|
*
|
|
21
21
|
* @param left Version.
|
|
22
22
|
* @param right Version to compare with.
|
|
23
23
|
* @return Negative when left is lower, positive when higher, otherwise 0.
|
|
24
24
|
*/
|
|
25
25
|
export declare function compareVersions(left: string, right: string): number;
|
|
26
|
+
/**
|
|
27
|
+
* Get the pre-release version of a stable release version, like 1.3.0-rc.1
|
|
28
|
+
* for 1.3.0. A pre-release with a number, like rc.2, is used as is. Without a
|
|
29
|
+
* number, like rc, the number is one above the highest existing pre-release
|
|
30
|
+
* of that identifier and stable version, so the first one is rc.1.
|
|
31
|
+
*
|
|
32
|
+
* @param stable Stable version of the release, like 1.3.0.
|
|
33
|
+
* @param prerelease Pre-release identifier with an optional number, like rc or rc.2.
|
|
34
|
+
* @param existing Existing versions of the package, like those of its tags.
|
|
35
|
+
* @return Pre-release version.
|
|
36
|
+
* @throws {ValidationError} For an invalid input, or a version that exists.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getPrereleaseVersion(stable: string, prerelease: string, existing: string[]): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get the snapshot version of a stable release version, like
|
|
41
|
+
* 1.3.0-pr-251.20261012183000 for 1.3.0: the identifier and the UTC time,
|
|
42
|
+
* which keeps every snapshot unique and sorts them by time.
|
|
43
|
+
*
|
|
44
|
+
* @param stable Stable version of the release, like 1.3.0.
|
|
45
|
+
* @param id Snapshot identifier, like pr-251.
|
|
46
|
+
* @param time Time of the snapshot.
|
|
47
|
+
* @return Snapshot version.
|
|
48
|
+
* @throws {ValidationError} For an invalid identifier or a version that isn't stable.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getSnapshotVersion(stable: string, id: string, time: Date): string;
|
package/dist/versions.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import { ValidationError } from "./errors.js";
|
|
1
2
|
/**
|
|
2
|
-
* Stable or pre-release
|
|
3
|
+
* Stable or pre-release version without build metadata: SemVer x.y.z, or the
|
|
4
|
+
* x.y and x.y.z.w versions common in WordPress plugins.
|
|
3
5
|
*/
|
|
4
|
-
const VERSION_PATTERN = /^(0|[1-9]\d*)
|
|
6
|
+
const VERSION_PATTERN = /^(?:0|[1-9]\d*)(?:\.(?:0|[1-9]\d*)){1,3}(?:-([0-9A-Za-z.-]+))?$/;
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Pre-release input: an identifier with an optional number, like rc or rc.1.
|
|
9
|
+
*/
|
|
10
|
+
const PRERELEASE_INPUT_PATTERN = /^([A-Za-z][0-9A-Za-z-]*)(?:\.(0|[1-9]\d*))?$/;
|
|
11
|
+
/**
|
|
12
|
+
* Snapshot identifier: dot-separated SemVer pre-release identifiers that start
|
|
13
|
+
* with a letter, like pr-251 or pr-251.g1a2b3c4.
|
|
14
|
+
*/
|
|
15
|
+
const SNAPSHOT_ID_PATTERN = /^[A-Za-z][0-9A-Za-z-]*(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*$/;
|
|
16
|
+
/**
|
|
17
|
+
* Check whether a string is a version, like 1.2.0, 1.2.0-rc.1, 2.1 or 1.2.3.4.
|
|
7
18
|
*
|
|
8
19
|
* @param version Version.
|
|
9
20
|
* @return Whether the version is valid.
|
|
@@ -18,13 +29,13 @@ export function isVersion(version) {
|
|
|
18
29
|
* @return Whether the version is a valid pre-release.
|
|
19
30
|
*/
|
|
20
31
|
export function isPrerelease(version) {
|
|
21
|
-
return Boolean(VERSION_PATTERN.exec(version)?.[
|
|
32
|
+
return Boolean(VERSION_PATTERN.exec(version)?.[1]);
|
|
22
33
|
}
|
|
23
34
|
/**
|
|
24
35
|
* Compare two versions with SemVer precedence, where a pre-release like
|
|
25
36
|
* 1.0.0-rc.1 comes before 1.0.0. Unlike the semver package, it doesn't throw
|
|
26
|
-
* for versions outside SemVer, like
|
|
27
|
-
*
|
|
37
|
+
* for versions outside SemVer, like 1.2 or 1.2.3.4: every part is compared,
|
|
38
|
+
* and missing parts count as 0.
|
|
28
39
|
*
|
|
29
40
|
* @param left Version.
|
|
30
41
|
* @param right Version to compare with.
|
|
@@ -35,9 +46,7 @@ export function compareVersions(left, right) {
|
|
|
35
46
|
const [rightCore = '', rightPre] = splitPrerelease(right);
|
|
36
47
|
const a = leftCore.split('.').map(Number);
|
|
37
48
|
const b = rightCore.split('.').map(Number);
|
|
38
|
-
const core = (a
|
|
39
|
-
(a[1] ?? 0) - (b[1] ?? 0) ||
|
|
40
|
-
(a[2] ?? 0) - (b[2] ?? 0);
|
|
49
|
+
const core = compareParts(a, b);
|
|
41
50
|
if (core || leftPre === rightPre) {
|
|
42
51
|
return core;
|
|
43
52
|
}
|
|
@@ -46,6 +55,14 @@ export function compareVersions(left, right) {
|
|
|
46
55
|
}
|
|
47
56
|
return comparePrerelease(leftPre.split('.'), rightPre.split('.'));
|
|
48
57
|
}
|
|
58
|
+
function compareParts(left, right) {
|
|
59
|
+
const [a, ...leftRest] = left;
|
|
60
|
+
const [b, ...rightRest] = right;
|
|
61
|
+
if (undefined === a && undefined === b) {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
return (a ?? 0) - (b ?? 0) || compareParts(leftRest, rightRest);
|
|
65
|
+
}
|
|
49
66
|
function splitPrerelease(version) {
|
|
50
67
|
const index = version.indexOf('-');
|
|
51
68
|
return -1 === index
|
|
@@ -72,3 +89,61 @@ function compareIdentifier(a, b) {
|
|
|
72
89
|
}
|
|
73
90
|
return Number(a > b) - Number(a < b);
|
|
74
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the pre-release version of a stable release version, like 1.3.0-rc.1
|
|
94
|
+
* for 1.3.0. A pre-release with a number, like rc.2, is used as is. Without a
|
|
95
|
+
* number, like rc, the number is one above the highest existing pre-release
|
|
96
|
+
* of that identifier and stable version, so the first one is rc.1.
|
|
97
|
+
*
|
|
98
|
+
* @param stable Stable version of the release, like 1.3.0.
|
|
99
|
+
* @param prerelease Pre-release identifier with an optional number, like rc or rc.2.
|
|
100
|
+
* @param existing Existing versions of the package, like those of its tags.
|
|
101
|
+
* @return Pre-release version.
|
|
102
|
+
* @throws {ValidationError} For an invalid input, or a version that exists.
|
|
103
|
+
*/
|
|
104
|
+
export function getPrereleaseVersion(stable, prerelease, existing) {
|
|
105
|
+
const match = PRERELEASE_INPUT_PATTERN.exec(prerelease);
|
|
106
|
+
if (!match) {
|
|
107
|
+
throw new ValidationError(`Invalid pre-release "${prerelease}"; expected an identifier with an optional number, like rc or rc.1.`);
|
|
108
|
+
}
|
|
109
|
+
if (!isVersion(stable) || isPrerelease(stable)) {
|
|
110
|
+
throw new ValidationError(`Cannot release "${stable}" as a pre-release: expected a stable version.`);
|
|
111
|
+
}
|
|
112
|
+
const identifier = match[1] ?? '';
|
|
113
|
+
const version = match[2]
|
|
114
|
+
? `${stable}-${prerelease}`
|
|
115
|
+
: `${stable}-${identifier}.${getNextPrereleaseNumber(`${stable}-${identifier}.`, existing)}`;
|
|
116
|
+
if (existing.includes(version)) {
|
|
117
|
+
throw new ValidationError(`Version ${version} already exists; pass a pre-release without a number to release the next one.`);
|
|
118
|
+
}
|
|
119
|
+
return version;
|
|
120
|
+
}
|
|
121
|
+
function getNextPrereleaseNumber(prefix, existing) {
|
|
122
|
+
const numbers = existing
|
|
123
|
+
.filter((version) => version.startsWith(prefix))
|
|
124
|
+
.map((version) => version.slice(prefix.length))
|
|
125
|
+
.filter((number) => /^\d+$/.test(number))
|
|
126
|
+
.map(Number);
|
|
127
|
+
return Math.max(0, ...numbers) + 1;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get the snapshot version of a stable release version, like
|
|
131
|
+
* 1.3.0-pr-251.20261012183000 for 1.3.0: the identifier and the UTC time,
|
|
132
|
+
* which keeps every snapshot unique and sorts them by time.
|
|
133
|
+
*
|
|
134
|
+
* @param stable Stable version of the release, like 1.3.0.
|
|
135
|
+
* @param id Snapshot identifier, like pr-251.
|
|
136
|
+
* @param time Time of the snapshot.
|
|
137
|
+
* @return Snapshot version.
|
|
138
|
+
* @throws {ValidationError} For an invalid identifier or a version that isn't stable.
|
|
139
|
+
*/
|
|
140
|
+
export function getSnapshotVersion(stable, id, time) {
|
|
141
|
+
if (!SNAPSHOT_ID_PATTERN.test(id)) {
|
|
142
|
+
throw new ValidationError(`Invalid snapshot "${id}"; expected SemVer pre-release identifiers that start with a letter, like pr-251.`);
|
|
143
|
+
}
|
|
144
|
+
if (!isVersion(stable) || isPrerelease(stable)) {
|
|
145
|
+
throw new ValidationError(`Cannot release "${stable}" as a snapshot: expected a stable version.`);
|
|
146
|
+
}
|
|
147
|
+
const timestamp = time.toISOString().replace(/\D/g, '').slice(0, 14);
|
|
148
|
+
return `${stable}-${id}.${timestamp}`;
|
|
149
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wpelevator/wp-release",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Package, checksum, sign, verify and version-check WordPress plugins and themes, and deploy plugins to WordPress.org SVN",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"build": "tsc -p tsconfig.build.json",
|
|
59
59
|
"prepack": "npm run build",
|
|
60
60
|
"lint": "npm-run-all lint:*",
|
|
61
|
-
"lint:js": "wp-scripts lint-js
|
|
61
|
+
"lint:js": "wp-scripts lint-js",
|
|
62
62
|
"lint:types": "tsc -p tsconfig.json",
|
|
63
63
|
"format": "wp-scripts format src",
|
|
64
64
|
"test": "node --test --conditions=wpelevator-source"
|