@virmator/publish 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +13 -0
- package/dist/publish.d.ts +34 -0
- package/dist/publish.js +286 -0
- package/package.json +56 -0
package/LICENSE-CC0
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Creative Commons Legal Code
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 electrovir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @virmator/publish
|
|
2
|
+
|
|
3
|
+
A default plugin for [virmator](https://www.npmjs.com/package/virmator).
|
|
4
|
+
|
|
5
|
+
## Available commands
|
|
6
|
+
|
|
7
|
+
- **publish**
|
|
8
|
+
|
|
9
|
+
Publish a package or mono-repo to NPM with an optional test script and auto-incrementing package version.
|
|
10
|
+
|
|
11
|
+
- Examples
|
|
12
|
+
- With tests: `virmator publish npm test`
|
|
13
|
+
- Without tests: `virmator publish`
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A virmator plugin for publishing a package to npm. */
|
|
2
|
+
export declare const virmatorPublishPlugin: Readonly<Readonly<{
|
|
3
|
+
name: string;
|
|
4
|
+
cliCommands: NoInfer<{
|
|
5
|
+
readonly publish: {
|
|
6
|
+
readonly doc: {
|
|
7
|
+
readonly sections: readonly ["\n Publish a package or mono-repo to NPM with an optional test script and auto-incrementing package version.\n "];
|
|
8
|
+
readonly examples: readonly [{
|
|
9
|
+
readonly title: "With tests";
|
|
10
|
+
readonly content: "virmator publish npm test";
|
|
11
|
+
}, {
|
|
12
|
+
readonly title: "Without tests";
|
|
13
|
+
readonly content: "virmator publish";
|
|
14
|
+
}];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
}> & {
|
|
19
|
+
pluginPackageRootPath: string;
|
|
20
|
+
executor: import("@virmator/core").VirmatorPluginExecutor<NoInfer<{
|
|
21
|
+
readonly publish: {
|
|
22
|
+
readonly doc: {
|
|
23
|
+
readonly sections: readonly ["\n Publish a package or mono-repo to NPM with an optional test script and auto-incrementing package version.\n "];
|
|
24
|
+
readonly examples: readonly [{
|
|
25
|
+
readonly title: "With tests";
|
|
26
|
+
readonly content: "virmator publish npm test";
|
|
27
|
+
}, {
|
|
28
|
+
readonly title: "Without tests";
|
|
29
|
+
readonly content: "virmator publish";
|
|
30
|
+
}];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}>>;
|
|
34
|
+
}>;
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { awaitedBlockingMap, extractErrorMessage, isEnumValue, isTruthy, safeMatch, } from '@augment-vir/common';
|
|
2
|
+
import { askQuestionUntilConditionMet, readPackageJson, runShellCommand as runHiddenShellCommand, runShellCommand, } from '@augment-vir/node-js';
|
|
3
|
+
import { defineVirmatorPlugin, parseTsConfig, VirmatorNoTraceError, } from '@virmator/core';
|
|
4
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { join, relative, resolve } from 'node:path';
|
|
6
|
+
import { assertDefined } from 'run-time-assertions';
|
|
7
|
+
import semver from 'semver';
|
|
8
|
+
import simpleGit from 'simple-git';
|
|
9
|
+
const inVirmatorEnvKey = 'IN_VIRMATOR';
|
|
10
|
+
/** A virmator plugin for publishing a package to npm. */
|
|
11
|
+
export const virmatorPublishPlugin = defineVirmatorPlugin(import.meta.dirname, {
|
|
12
|
+
name: 'Publish',
|
|
13
|
+
cliCommands: {
|
|
14
|
+
publish: {
|
|
15
|
+
doc: {
|
|
16
|
+
sections: [
|
|
17
|
+
`
|
|
18
|
+
Publish a package or mono-repo to NPM with an optional test script and auto-incrementing package version.
|
|
19
|
+
`,
|
|
20
|
+
],
|
|
21
|
+
examples: [
|
|
22
|
+
{
|
|
23
|
+
title: 'With tests',
|
|
24
|
+
content: 'virmator publish npm test',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: 'Without tests',
|
|
28
|
+
content: 'virmator publish',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}, async ({ cliInputs: { filteredArgs }, package: { cwdValidPackageJson, monoRepoRootPath, monoRepoPackages }, log, cwd, runPerPackage, runShellCommand, }) => {
|
|
35
|
+
if (process.env[inVirmatorEnvKey]) {
|
|
36
|
+
return { noLog: true };
|
|
37
|
+
}
|
|
38
|
+
else if (!cwdValidPackageJson) {
|
|
39
|
+
throw new VirmatorNoTraceError(`Missing "name" / "version" package.json fields.`);
|
|
40
|
+
}
|
|
41
|
+
const monoRepoPackageJson = await readPackageJson(monoRepoRootPath);
|
|
42
|
+
const version = monoRepoPackageJson.version;
|
|
43
|
+
if (!version) {
|
|
44
|
+
throw new VirmatorNoTraceError(`No "version" found in package.json at '${relative(cwd, monoRepoRootPath)}'`);
|
|
45
|
+
}
|
|
46
|
+
else if (await doChangesExist(monoRepoRootPath)) {
|
|
47
|
+
throw new VirmatorNoTraceError('Git changes exist, cannot run publish. Commit or stash the changes.');
|
|
48
|
+
}
|
|
49
|
+
const flagArgs = filteredArgs.filter((arg) => arg.startsWith('--'));
|
|
50
|
+
const isDryRun = flagArgs.includes('--dry-run');
|
|
51
|
+
const monoRepoPackageJsonFiles = await Promise.all(monoRepoPackages.map(async (monoRepoPackage) => {
|
|
52
|
+
const packageJson = await readPackageJson(monoRepoPackage.fullPath);
|
|
53
|
+
if (!packageJson.name) {
|
|
54
|
+
throw new VirmatorNoTraceError(`No package.json name in '${monoRepoPackage.relativePath}'`);
|
|
55
|
+
}
|
|
56
|
+
else if (!packageJson.version) {
|
|
57
|
+
throw new VirmatorNoTraceError(`No package.json version in '${packageJson.name}'`);
|
|
58
|
+
}
|
|
59
|
+
return packageJson;
|
|
60
|
+
}));
|
|
61
|
+
const git = simpleGit(monoRepoRootPath);
|
|
62
|
+
if (await isVersionPublished(version, [
|
|
63
|
+
cwdValidPackageJson,
|
|
64
|
+
...monoRepoPackageJsonFiles,
|
|
65
|
+
])) {
|
|
66
|
+
let nextVersion;
|
|
67
|
+
try {
|
|
68
|
+
nextVersion = await determineNextVersion(git);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
log.faint(extractErrorMessage(error));
|
|
72
|
+
}
|
|
73
|
+
const allPackageJsonFiles = [
|
|
74
|
+
cwdValidPackageJson,
|
|
75
|
+
...monoRepoPackageJsonFiles,
|
|
76
|
+
];
|
|
77
|
+
if (!nextVersion || (await isVersionPublished(nextVersion, allPackageJsonFiles))) {
|
|
78
|
+
nextVersion = await askQuestionUntilConditionMet({
|
|
79
|
+
async conditionCallback(response) {
|
|
80
|
+
const version = semver.coerce(response)?.raw;
|
|
81
|
+
if (!version) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return !(await isVersionPublished(version, allPackageJsonFiles));
|
|
85
|
+
},
|
|
86
|
+
invalidInputMessage: 'Invalid semver version.',
|
|
87
|
+
questionToAsk: 'Failed to automatically determine next publish version. Please enter one:',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
await updateVersions(nextVersion, monoRepoRootPath, monoRepoPackages, log);
|
|
91
|
+
await runHiddenShellCommand('npm i');
|
|
92
|
+
}
|
|
93
|
+
await runShellCommand(filteredArgs.join(' '));
|
|
94
|
+
const publishCommand = [
|
|
95
|
+
`${inVirmatorEnvKey}=true`,
|
|
96
|
+
'npm',
|
|
97
|
+
'publish',
|
|
98
|
+
...flagArgs,
|
|
99
|
+
]
|
|
100
|
+
.filter(isTruthy)
|
|
101
|
+
.join(' ');
|
|
102
|
+
const alteredPackageJsonFiles = [];
|
|
103
|
+
async function alterPackageEntryPoints(packagePath) {
|
|
104
|
+
const packageJsonPath = join(packagePath, 'package.json');
|
|
105
|
+
let packageJsonContents = (await readFile(packageJsonPath)).toString();
|
|
106
|
+
const packageJson = await readPackageJson(packagePath);
|
|
107
|
+
const alteredJsonFile = {
|
|
108
|
+
path: packageJsonPath,
|
|
109
|
+
original: packageJsonContents,
|
|
110
|
+
};
|
|
111
|
+
const relativeOutDir = parseTsConfig(packagePath)?.options.outDir || 'dist';
|
|
112
|
+
const outDir = relative(packagePath, resolve(packagePath, relativeOutDir));
|
|
113
|
+
if (packageJson.main?.endsWith('.ts')) {
|
|
114
|
+
packageJsonContents = packageJsonContents.replace(`"main": "${packageJson.main}"`, `"main": "${packageJson.main.replace('src', outDir).replace('.ts', '.js')}"`);
|
|
115
|
+
}
|
|
116
|
+
if (packageJson.module?.endsWith('.ts')) {
|
|
117
|
+
packageJsonContents = packageJsonContents.replace(`"module": "${packageJson.module}"`, `"module": "${packageJson.module.replace('src', outDir).replace('.ts', '.js')}"`);
|
|
118
|
+
}
|
|
119
|
+
if (packageJson.types?.startsWith('src')) {
|
|
120
|
+
packageJsonContents = packageJsonContents.replace(`"types": "${packageJson.types}"`, `"types": "${packageJson.types.replace('src', outDir).replace('.ts', '.d.ts')}"`);
|
|
121
|
+
}
|
|
122
|
+
if (packageJsonContents !== alteredJsonFile.original) {
|
|
123
|
+
alteredPackageJsonFiles.push(alteredJsonFile);
|
|
124
|
+
await writeFile(alteredJsonFile.path, packageJsonContents);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
if (monoRepoPackages.length) {
|
|
129
|
+
await runPerPackage(async ({ packageCwd, packageName }) => {
|
|
130
|
+
const isPrivate = (await readPackageJson(packageCwd)).private;
|
|
131
|
+
if (isPrivate) {
|
|
132
|
+
log.faint(`Skipping ${packageName} because it's private.`);
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
await alterPackageEntryPoints(packageCwd);
|
|
136
|
+
return publishCommand;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const isPrivate = monoRepoPackageJson.private;
|
|
141
|
+
if (isPrivate) {
|
|
142
|
+
log.info(`This package is private. Skipping publish.`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
await alterPackageEntryPoints(monoRepoRootPath);
|
|
146
|
+
await runShellCommand(publishCommand);
|
|
147
|
+
}
|
|
148
|
+
if (!isDryRun) {
|
|
149
|
+
await updateGit(monoRepoRootPath);
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
await Promise.all(alteredPackageJsonFiles.map(async (alteredFile) => {
|
|
155
|
+
await writeFile(alteredFile.path, alteredFile.original);
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
async function updateGit(packageDirPath) {
|
|
160
|
+
const newVersion = (await readPackageJson(packageDirPath)).version;
|
|
161
|
+
assertDefined(newVersion);
|
|
162
|
+
if (await doChangesExist(packageDirPath)) {
|
|
163
|
+
await runShellCommand(`git commit -a --amend --no-edit`, {
|
|
164
|
+
cwd: packageDirPath,
|
|
165
|
+
rejectOnError: true,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
await runShellCommand(`git tag v${newVersion} && git push && git push --tags`, {
|
|
169
|
+
cwd: packageDirPath,
|
|
170
|
+
rejectOnError: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async function doChangesExist(repoDirPath) {
|
|
174
|
+
const getChangesOutput = await runHiddenShellCommand('git status --porcelain=v1 2>/dev/null', {
|
|
175
|
+
cwd: repoDirPath,
|
|
176
|
+
rejectOnError: true,
|
|
177
|
+
});
|
|
178
|
+
return !!getChangesOutput.stdout;
|
|
179
|
+
}
|
|
180
|
+
async function isVersionPublished(latestVersion, allPackageJsonFiles) {
|
|
181
|
+
let hasBeenPublished = false;
|
|
182
|
+
await Promise.all(allPackageJsonFiles.map(async (packageJson) => {
|
|
183
|
+
if (await isPublished({
|
|
184
|
+
name: packageJson.name,
|
|
185
|
+
version: latestVersion,
|
|
186
|
+
})) {
|
|
187
|
+
hasBeenPublished = true;
|
|
188
|
+
}
|
|
189
|
+
}));
|
|
190
|
+
return hasBeenPublished;
|
|
191
|
+
}
|
|
192
|
+
async function isPublished({ name, version }) {
|
|
193
|
+
const output = await runHiddenShellCommand(`npm show ${name}@${version}`);
|
|
194
|
+
return output.exitCode === 0;
|
|
195
|
+
}
|
|
196
|
+
const gitCommitFormatDelimiter = '<**..**>';
|
|
197
|
+
var ChangeMarker;
|
|
198
|
+
(function (ChangeMarker) {
|
|
199
|
+
ChangeMarker["Patch"] = "patch";
|
|
200
|
+
ChangeMarker["Minor"] = "minor";
|
|
201
|
+
ChangeMarker["Major"] = "major";
|
|
202
|
+
})(ChangeMarker || (ChangeMarker = {}));
|
|
203
|
+
async function getGitCommitVersion(decrement, git) {
|
|
204
|
+
const output = await git.raw(`show HEAD~${decrement} --pretty='%D${gitCommitFormatDelimiter}%s' -s`.split(' '));
|
|
205
|
+
const [maybeTag, message,] = output.split(gitCommitFormatDelimiter);
|
|
206
|
+
const tags = maybeTag
|
|
207
|
+
? Array.from(maybeTag.matchAll(/tag: ([^),]+)(?:\)|,)/g))
|
|
208
|
+
.map((entry) => entry[1])
|
|
209
|
+
.filter(isTruthy)
|
|
210
|
+
: [];
|
|
211
|
+
const versionTags = tags
|
|
212
|
+
.map((tag) => {
|
|
213
|
+
return semver.coerce(tag);
|
|
214
|
+
})
|
|
215
|
+
.filter(isTruthy);
|
|
216
|
+
const sortedVersionTags = semver.sort(versionTags);
|
|
217
|
+
const latestVersionTag = sortedVersionTags.slice(-1)[0];
|
|
218
|
+
const [, rawChangeMarker,] = message ? safeMatch(message.trim(), /^\[([^\]]+)]/) : [];
|
|
219
|
+
const changeMarker = rawChangeMarker && isEnumValue(rawChangeMarker, ChangeMarker) ? rawChangeMarker : undefined;
|
|
220
|
+
return {
|
|
221
|
+
version: latestVersionTag,
|
|
222
|
+
changeMarker,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
async function determineNextVersion(git) {
|
|
226
|
+
const changeMarkers = {
|
|
227
|
+
[ChangeMarker.Patch]: 0,
|
|
228
|
+
[ChangeMarker.Minor]: 0,
|
|
229
|
+
[ChangeMarker.Major]: 0,
|
|
230
|
+
};
|
|
231
|
+
let decrement = 0;
|
|
232
|
+
let latestVersion = undefined;
|
|
233
|
+
while (!latestVersion) {
|
|
234
|
+
if (decrement > 100) {
|
|
235
|
+
throw new Error("Couldn't find a version tag in the past 100 commits.");
|
|
236
|
+
}
|
|
237
|
+
const { changeMarker, version } = await getGitCommitVersion(decrement, git);
|
|
238
|
+
if (version) {
|
|
239
|
+
latestVersion = version;
|
|
240
|
+
}
|
|
241
|
+
else if (changeMarker) {
|
|
242
|
+
changeMarkers[changeMarker]++;
|
|
243
|
+
}
|
|
244
|
+
decrement++;
|
|
245
|
+
}
|
|
246
|
+
if (changeMarkers[ChangeMarker.Major]) {
|
|
247
|
+
return latestVersion.inc('major').raw;
|
|
248
|
+
}
|
|
249
|
+
else if (changeMarkers[ChangeMarker.Minor]) {
|
|
250
|
+
return latestVersion.inc('minor').raw;
|
|
251
|
+
}
|
|
252
|
+
else if (changeMarkers[ChangeMarker.Patch]) {
|
|
253
|
+
return latestVersion.inc('patch').raw;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
throw new Error('No change markers fround since last tagged version.');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async function updateVersions(version, monoRepoRootPath, monoPackages, log) {
|
|
260
|
+
const packagePaths = [
|
|
261
|
+
monoRepoRootPath,
|
|
262
|
+
...monoPackages.map((monoPackage) => {
|
|
263
|
+
return monoPackage.fullPath;
|
|
264
|
+
}),
|
|
265
|
+
];
|
|
266
|
+
await awaitedBlockingMap(packagePaths, async (packagePath) => {
|
|
267
|
+
const logPath = relative(monoRepoRootPath, join(monoRepoRootPath, packagePath, 'package.json'));
|
|
268
|
+
log.faint(`Updating ${logPath}...`);
|
|
269
|
+
await updateVersion(version, packagePath, monoPackages);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
async function updateVersion(version, packagePath, monoPackages) {
|
|
273
|
+
const packageJsonPath = join(packagePath, 'package.json');
|
|
274
|
+
const packageJsonContents = (await readFile(packageJsonPath)).toString();
|
|
275
|
+
const packageJson = JSON.parse(packageJsonContents);
|
|
276
|
+
const packageName = packageJson.name;
|
|
277
|
+
if (!packageName) {
|
|
278
|
+
throw new Error(`Missing package name in '${packagePath}'.`);
|
|
279
|
+
}
|
|
280
|
+
await writeFile(packageJsonPath, packageJsonContents.replace(/"version": "[^"]+"/, `"version": "${version}"`));
|
|
281
|
+
await awaitedBlockingMap(monoPackages, async (monoPackage) => {
|
|
282
|
+
const monoPackageJsonPath = join(monoPackage.fullPath, 'package.json');
|
|
283
|
+
const monoPackageJsonContents = (await readFile(monoPackageJsonPath)).toString();
|
|
284
|
+
await writeFile(monoPackageJsonPath, monoPackageJsonContents.replace(new RegExp(`"${packageName}": "[^"]+"`), `"${packageName}": "^${version}"`));
|
|
285
|
+
});
|
|
286
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@virmator/publish",
|
|
3
|
+
"version": "13.0.1",
|
|
4
|
+
"description": "Default publish plugin for virmator.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"virmator",
|
|
7
|
+
"npm",
|
|
8
|
+
"publish",
|
|
9
|
+
"deploy",
|
|
10
|
+
"pipeline"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/electrovir/virmator",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/electrovir/virmator/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/electrovir/virmator.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "(MIT or CC0 1.0)",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "electrovir",
|
|
23
|
+
"url": "https://github.com/electrovir"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "dist/publish.js",
|
|
27
|
+
"module": "dist/publish.js",
|
|
28
|
+
"types": "dist/publish.d.ts",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"compile": "virmator compile",
|
|
31
|
+
"test": "exit 0",
|
|
32
|
+
"test:coverage": "npm test",
|
|
33
|
+
"test:update": "npm test"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@augment-vir/common": "^29.3.0",
|
|
37
|
+
"@augment-vir/node-js": "^29.3.0",
|
|
38
|
+
"@virmator/core": "^13.0.1",
|
|
39
|
+
"chalk": "^5.3.0",
|
|
40
|
+
"mri": "^1.2.0",
|
|
41
|
+
"run-time-assertions": "^1.5.2",
|
|
42
|
+
"semver": "^7.6.3",
|
|
43
|
+
"simple-git": "^3.25.0",
|
|
44
|
+
"url-vir": "^1.5.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^22.1.0",
|
|
48
|
+
"@types/semver": "^7.5.8",
|
|
49
|
+
"markdown-code-example-inserter": "^1.0.0",
|
|
50
|
+
"type-fest": "^4.23.0",
|
|
51
|
+
"typedoc": "^0.26.5"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|