@halospv3/hce.shared-config 3.4.7 → 3.4.8
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/CHANGELOG.md +25 -4
- package/mjs/CaseInsensitiveMap.mjs +27 -1
- package/mjs/CaseInsensitiveMap.mjs.map +1 -1
- package/mjs/commitlintConfig.mjs +13 -1
- package/mjs/commitlintConfig.mjs.map +1 -1
- package/mjs/debug.mjs +8 -1
- package/mjs/debug.mjs.map +1 -1
- package/mjs/dotnet/GithubNugetRegistryInfo.mjs +39 -1
- package/mjs/dotnet/GithubNugetRegistryInfo.mjs.map +1 -1
- package/mjs/dotnet/GitlabNugetRegistryInfo.mjs +81 -1
- package/mjs/dotnet/GitlabNugetRegistryInfo.mjs.map +1 -1
- package/mjs/dotnet/IsNextVersionAlreadyPublished.cli.mjs +42 -1
- package/mjs/dotnet/IsNextVersionAlreadyPublished.cli.mjs.map +1 -1
- package/mjs/dotnet/MSBuildProject.mjs +345 -2
- package/mjs/dotnet/MSBuildProject.mjs.map +1 -1
- package/mjs/dotnet/MSBuildProjectProperties.mjs +233 -1
- package/mjs/dotnet/MSBuildProjectProperties.mjs.map +1 -1
- package/mjs/dotnet/NugetProjectProperties.mjs +520 -1
- package/mjs/dotnet/NugetProjectProperties.mjs.map +1 -1
- package/mjs/dotnet/NugetRegistryInfo.mjs +599 -3
- package/mjs/dotnet/NugetRegistryInfo.mjs.map +1 -1
- package/mjs/dotnet/helpers.mjs +222 -1
- package/mjs/dotnet/helpers.mjs.map +1 -1
- package/mjs/dotnet/index.mjs +9 -1
- package/mjs/dotnet.mjs +9 -1
- package/mjs/eslintConfig.mjs +97 -1
- package/mjs/eslintConfig.mjs.map +1 -1
- package/mjs/index.mjs +2 -1
- package/mjs/insertPlugins.mjs +35 -1
- package/mjs/insertPlugins.mjs.map +1 -1
- package/mjs/semanticReleaseConfig.mjs +63 -1
- package/mjs/semanticReleaseConfig.mjs.map +1 -1
- package/mjs/semanticReleaseConfigDotnet.mjs +223 -6
- package/mjs/semanticReleaseConfigDotnet.mjs.map +1 -1
- package/mjs/setupGitPluginSpec.default.mjs +18 -2
- package/mjs/setupGitPluginSpec.default.mjs.map +1 -1
- package/mjs/setupGitPluginSpec.mjs +108 -1
- package/mjs/setupGitPluginSpec.mjs.map +1 -1
- package/mjs/utils/Exact.d.mts +10 -10
- package/mjs/utils/Exact.d.mts.map +1 -1
- package/mjs/utils/env.mjs +39 -1
- package/mjs/utils/env.mjs.map +1 -1
- package/mjs/utils/execAsync.mjs +54 -7
- package/mjs/utils/execAsync.mjs.map +1 -1
- package/mjs/utils/isError.mjs +17 -1
- package/mjs/utils/isError.mjs.map +1 -1
- package/mjs/utils/miscTypes.mjs +7 -1
- package/mjs/utils/miscTypes.mjs.map +1 -1
- package/mjs/utils/reflection/filterForGetters.mjs +25 -1
- package/mjs/utils/reflection/filterForGetters.mjs.map +1 -1
- package/mjs/utils/reflection/getOwnPropertyDescriptors.mjs +27 -1
- package/mjs/utils/reflection/getOwnPropertyDescriptors.mjs.map +1 -1
- package/mjs/utils/reflection/getOwnPropertyDescriptorsRecursively.mjs +34 -1
- package/mjs/utils/reflection/getOwnPropertyDescriptorsRecursively.mjs.map +1 -1
- package/mjs/utils/reflection/getPrototypeChainOf.mjs +39 -1
- package/mjs/utils/reflection/getPrototypeChainOf.mjs.map +1 -1
- package/mjs/utils/reflection/getPrototypeOf.mjs +12 -1
- package/mjs/utils/reflection/getPrototypeOf.mjs.map +1 -1
- package/mjs/utils/reflection/inheritance.mjs +10 -1
- package/mjs/utils/reflection/inheritance.mjs.map +1 -1
- package/mjs/utils/reflection/isConstructor.mjs +30 -1
- package/mjs/utils/reflection/isConstructor.mjs.map +1 -1
- package/mjs/utils/reflection/isGetterDescriptor.mjs +13 -1
- package/mjs/utils/reflection/isGetterDescriptor.mjs.map +1 -1
- package/mjs/utils/reflection/listOwnGetters.mjs +29 -1
- package/mjs/utils/reflection/listOwnGetters.mjs.map +1 -1
- package/mjs/utils/reflection.mjs +10 -1
- package/package.json +17 -43
- package/src/utils/Exact.d.ts +17 -0
- package/mjs/utils/Exact.mjs +0 -2
- package/mjs/utils/Exact.mjs.map +0 -1
- package/src/utils/Exact.ts +0 -49
|
@@ -1,7 +1,224 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { baseConfig } from "./semanticReleaseConfig.mjs";
|
|
2
|
+
import _debug from "./debug.mjs";
|
|
3
|
+
import { MSBuildProject } from "./dotnet/MSBuildProject.mjs";
|
|
4
|
+
import { getEnvVarValue } from "./utils/env.mjs";
|
|
5
|
+
import { NugetRegistryInfo } from "./dotnet/NugetRegistryInfo.mjs";
|
|
6
|
+
import { configureDotnetNugetPush, configurePrepareCmd } from "./dotnet/helpers.mjs";
|
|
7
|
+
import { insertPlugin } from "./insertPlugins.mjs";
|
|
8
|
+
import { inspect } from "node:util";
|
|
9
|
+
import * as console from "node:console";
|
|
10
|
+
//#region src/semanticReleaseConfigDotnet.ts
|
|
11
|
+
/**
|
|
12
|
+
* # Semantic-Release Config Factory (dotnet)
|
|
13
|
+
* A functional Semantic-Release configuration for dotnet projects
|
|
14
|
+
*
|
|
15
|
+
* extends {@link baseConfig }
|
|
16
|
+
*
|
|
17
|
+
* <-- TABLE OF CONTENTS -->
|
|
18
|
+
*
|
|
19
|
+
* EASY: {@link getConfig}
|
|
20
|
+
* Just provide the paths of the project file(s) and keep your API tokens ready.
|
|
21
|
+
* ADVANCED: {@link SemanticReleaseConfigDotnet}
|
|
22
|
+
* Allows for a hands-on customization if {@link getConfig} doesn't meet your needs.
|
|
23
|
+
* Use a copy of {@link getConfig} as the starting point of a new function and make changes from there.
|
|
24
|
+
* - {@link SemanticReleaseConfigDotnet#splicePlugin splicePlugin (insert/edit plugins)}
|
|
25
|
+
* - {@link SemanticReleaseConfigDotnet#setupDotnetCommands setupDotnetCommands}
|
|
26
|
+
* - {@link SemanticReleaseConfigDotnet#getTokenTestingCommands getTokenTestingCommands}
|
|
27
|
+
*/
|
|
28
|
+
var SemanticReleaseConfigDotnet = class {
|
|
29
|
+
options;
|
|
30
|
+
_projectsToPublish;
|
|
31
|
+
_projectsToPackAndPush;
|
|
32
|
+
_evaluatedProjects;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of SemanticReleaseConfigDotnet.
|
|
35
|
+
* Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet` publish, pack, and push.
|
|
36
|
+
*
|
|
37
|
+
* Note: To sign packages, create a Target in the corresponding project(s) e.g.
|
|
38
|
+
* ```xml
|
|
39
|
+
* <Target Name="SignNupkgs" AfterTargets="Pack">
|
|
40
|
+
* <Exec Command="dotnet nuget sign $(PackageOutputPath) [remaining args]" ConsoleToMsBuild="true" />
|
|
41
|
+
* </Target>
|
|
42
|
+
* ```
|
|
43
|
+
* Alternatively, splice your signing commands into the publishCmd string,
|
|
44
|
+
* inserting them before `dotnet nuget push`.
|
|
45
|
+
* If you sign different signatures depending on the NuGet registry,
|
|
46
|
+
* splice your signing command (with "overwrite signature" enabled, if
|
|
47
|
+
* desired) before the corresponding registry's `dotnet nuget push` command.
|
|
48
|
+
* @param projectsToPublish An array of dotnet projects' relative paths. If
|
|
49
|
+
* empty or unspecified, tries getting projects' semi-colon-separated relative
|
|
50
|
+
* paths from the `PROJECTS_TO_PUBLISH` environment variable. If configured as
|
|
51
|
+
* recommended, the projects' publish outputs will be zipped to '$PWD/publish'
|
|
52
|
+
* for use in the `publish` semantic-release step (typically, GitHub release).
|
|
53
|
+
* @param projectsToPackAndPush An array of dotnet projects' relative paths.
|
|
54
|
+
* If empty or unspecified, tries getting projects' semi-colon-separated
|
|
55
|
+
* relative paths from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.
|
|
56
|
+
* Otherwise, no packages will be packed and pushed.
|
|
57
|
+
* If configured as recommended, `dotnet pack` will output the nupkg/snupkg
|
|
58
|
+
* files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.
|
|
59
|
+
*/
|
|
60
|
+
constructor(projectsToPublish, projectsToPackAndPush) {
|
|
61
|
+
this.options = baseConfig;
|
|
62
|
+
this.options.plugins = this.options.plugins.map((pluginSpec) => typeof pluginSpec === "string" ? [pluginSpec, {}] : pluginSpec);
|
|
63
|
+
this._projectsToPublish = projectsToPublish;
|
|
64
|
+
if (this._projectsToPublish.length === 0) {
|
|
65
|
+
const p = getEnvVarValue("PROJECTS_TO_PUBLISH")?.split(";");
|
|
66
|
+
if (p && p.length > 0) this._projectsToPublish = p;
|
|
67
|
+
else if (_debug.enabled) _debug(/* @__PURE__ */ new Error("At least one project must be published. `projectsToPackAndPush` is empty and environment variable `PROJECTS_TO_PUBLISH` is undefined or empty."));
|
|
68
|
+
}
|
|
69
|
+
this._projectsToPackAndPush = projectsToPackAndPush;
|
|
70
|
+
if (this._projectsToPackAndPush.length === 0) {
|
|
71
|
+
const p = getEnvVarValue("PROJECTS_TO_PACK_AND_PUSH")?.split(";");
|
|
72
|
+
if (p && p.length > 0) this._projectsToPackAndPush = p;
|
|
73
|
+
else if (_debug.enabled) _debug(/* @__PURE__ */ new Error("projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path."));
|
|
74
|
+
}
|
|
75
|
+
this._evaluatedProjects = [...this._projectsToPublish.filter((v) => v instanceof MSBuildProject), ...this._projectsToPackAndPush.filter((v) => v instanceof NugetRegistryInfo).map((v) => v.project)];
|
|
76
|
+
}
|
|
77
|
+
get ProjectsToPublish() {
|
|
78
|
+
return this._projectsToPublish;
|
|
79
|
+
}
|
|
80
|
+
get ProjectsToPackAndPush() {
|
|
81
|
+
return this._projectsToPackAndPush;
|
|
82
|
+
}
|
|
83
|
+
get EvaluatedProjects() {
|
|
84
|
+
return this._evaluatedProjects;
|
|
85
|
+
}
|
|
86
|
+
/** @deprecated Superseded by {@link splicePlugin} */
|
|
87
|
+
insertPlugin(afterPluginsIDs, insertPluginIDs, beforePluginsIDs) {
|
|
88
|
+
this.options.plugins = insertPlugin(this.options.plugins, afterPluginsIDs, insertPluginIDs, beforePluginsIDs);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* generate dotnet commands for \@semantic-release/exec, appending commands with ' && ' when necessary.
|
|
92
|
+
*
|
|
93
|
+
* Note: All strings in {@link this.ProjectsToPackAndPush} will be converted to basic {@link NugetRegistryInfo} instances with default values.
|
|
94
|
+
* If you need specific NRI settings or you need to push to GitLab-like or GitHub-like registries, instantiate them instead of passing their paths.
|
|
95
|
+
* @todo change to builder method? e.g. static async SetupDotnetCommands(this: SemanticReleaseConfigDotnet): Promise<SemanticReleaseConfigDotnet>
|
|
96
|
+
* @todo Add options param to allow users to enable pushing to GitLab, GitHub, NuGet.org with default settings -OR- with entirely custom settings.
|
|
97
|
+
* @see https://github.com/semantic-release/exec#usage
|
|
98
|
+
*/
|
|
99
|
+
async setupDotnetCommands() {
|
|
100
|
+
let srExecIndex = this.options.plugins.findIndex((v) => v[0] === "@semantic-release/exec");
|
|
101
|
+
if (srExecIndex === -1) {
|
|
102
|
+
console.warn(`\
|
|
103
|
+
Unable to find\`['@semantic-release/exec', unknown]\` in plugins array!
|
|
104
|
+
Appending it to the end of the array...This may cause an unexpected order of operations!`);
|
|
105
|
+
srExecIndex = this.options.plugins.push(["@semantic-release/exec", {}]) - 1;
|
|
106
|
+
}
|
|
107
|
+
const execOptions = this.options.plugins[srExecIndex][1];
|
|
108
|
+
this._projectsToPackAndPush = await Promise.all(this._projectsToPackAndPush.map(async (project) => {
|
|
109
|
+
if (typeof project === "string") {
|
|
110
|
+
const packableProjects = await Promise.all(await MSBuildProject.PackableProjectsToMSBuildProjects([project]));
|
|
111
|
+
if (packableProjects.length === 0) throw new Error("No MSBuildProject instances were returned!");
|
|
112
|
+
this._evaluatedProjects.push(...packableProjects);
|
|
113
|
+
return packableProjects.map((project) => new NugetRegistryInfo({ project }));
|
|
114
|
+
} else return [project];
|
|
115
|
+
})).then((p) => p.flat());
|
|
116
|
+
const verifyConditionsCmdAppendix = await Promise.all(this._projectsToPackAndPush.map(async (project) => await project.PackDummyPackage({}).then(() => project.GetPushDummyCommand({})))).then((cmds) => cmds.join(" && "));
|
|
117
|
+
execOptions.verifyConditionsCmd = execOptions.verifyConditionsCmd && execOptions.verifyConditionsCmd.trim().length > 0 ? `${execOptions.verifyConditionsCmd} && ${verifyConditionsCmdAppendix}` : verifyConditionsCmdAppendix;
|
|
118
|
+
const verifyReleaseCmdAppendix = this.ProjectsToPackAndPush.filter((project) => typeof project !== "string").map((project) => project.GetIsNextVersionAlreadyPublishedCommand()).join(" && ");
|
|
119
|
+
execOptions.verifyReleaseCmd = execOptions.verifyReleaseCmd && execOptions.verifyReleaseCmd.trim().length > 0 ? `${execOptions.verifyReleaseCmd} && ${verifyReleaseCmdAppendix}` : verifyConditionsCmdAppendix;
|
|
120
|
+
const prepareCmdAppendix = await configurePrepareCmd(this._projectsToPublish, this._projectsToPackAndPush);
|
|
121
|
+
execOptions.prepareCmd = execOptions.prepareCmd && execOptions.prepareCmd.trim().length > 0 ? `${execOptions.prepareCmd} && ${prepareCmdAppendix}` : prepareCmdAppendix;
|
|
122
|
+
if (this._projectsToPackAndPush.length > 0) {
|
|
123
|
+
const publishCmdAppendix = configureDotnetNugetPush(this._projectsToPackAndPush);
|
|
124
|
+
execOptions.publishCmd = execOptions.publishCmd && execOptions.publishCmd.trim().length > 0 ? `${execOptions.publishCmd} && ${publishCmdAppendix}` : publishCmdAppendix;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Insert a plugin into the plugins array.
|
|
129
|
+
* @param insertAfterPluginIDs Plugins which should appear BEFORE
|
|
130
|
+
* {@link insertPluginIDs}.
|
|
131
|
+
* @param insertPluginIDs The plugin(s) to insert into the plugins array.
|
|
132
|
+
* @param insertBeforePluginsIDs plugins which should appear AFTER the
|
|
133
|
+
* inserted plugin(s).
|
|
134
|
+
*/
|
|
135
|
+
splicePlugin(insertAfterPluginIDs, insertPluginIDs, insertBeforePluginsIDs) {
|
|
136
|
+
const errors = [];
|
|
137
|
+
const pluginIDs = this.options.plugins.map((v) => typeof v === "string" ? v : v[0]);
|
|
138
|
+
const indexOfLastPreceding = insertAfterPluginIDs.filter((v) => pluginIDs.includes(v)).map((v) => pluginIDs.indexOf(v)).sort().find((_v, i, obj) => i === obj.length - 1);
|
|
139
|
+
if (!indexOfLastPreceding) throw new ReferenceError("An attempt to get the last element of indexOfLastAfter returned undefined.");
|
|
140
|
+
const indicesOfBefore = insertBeforePluginsIDs.filter((v) => pluginIDs.includes(v)).map((v) => pluginIDs.indexOf(v)).sort();
|
|
141
|
+
for (const index of indicesOfBefore) if (index <= indexOfLastPreceding) {
|
|
142
|
+
const formattedInsertIds = "[" + insertPluginIDs.map((v) => `"${v}"`).join(", ") + "]";
|
|
143
|
+
const formattedAfterIds = "[" + insertAfterPluginIDs.map((v) => `"${v}"`).join(", ") + "]";
|
|
144
|
+
const formattedBeforeIds = "[" + insertBeforePluginsIDs.map((v) => `"${v}"`).join(", ") + "]";
|
|
145
|
+
errors.push(/* @__PURE__ */ new Error(`insertPlugin was instructed to insert ${formattedInsertIds} after ${formattedAfterIds} and before ${formattedBeforeIds}, but ${JSON.stringify(pluginIDs[indexOfLastPreceding])} is ordered after ${JSON.stringify(pluginIDs[index])}!`));
|
|
146
|
+
}
|
|
147
|
+
if (errors.length > 0) throw new AggregateError(errors, "One or more errors occurred while splicing plugin-option tuples into the Semantic Release config!");
|
|
148
|
+
this.options.plugins.splice(indexOfLastPreceding + 1, 0, ...insertPluginIDs.map((v) => [v, {}]));
|
|
149
|
+
}
|
|
150
|
+
async getTokenTestingCommands() {
|
|
151
|
+
const promiseProjects = this.ProjectsToPackAndPush.every((nri) => nri instanceof NugetRegistryInfo) ? this.ProjectsToPackAndPush.map((nri) => nri.project) : await Promise.all(await MSBuildProject.PackableProjectsToMSBuildProjects(this.ProjectsToPackAndPush));
|
|
152
|
+
/** if a project is not in {@link EvaluatedProjects}, add it */
|
|
153
|
+
for (const project of promiseProjects) if (!this.EvaluatedProjects.includes(project)) this.EvaluatedProjects.push(project);
|
|
154
|
+
const regInfos = promiseProjects.map((p) => new NugetRegistryInfo({ project: p }));
|
|
155
|
+
return (await Promise.all(regInfos.map((nri) => nri.PackDummyPackage({}).then((nupkgs) => {
|
|
156
|
+
const mainNupkg = nupkgs.find((nupkg) => (/* @__PURE__ */ new RegExp(/(?<!symbols)\.nupkg$/)).test(nupkg));
|
|
157
|
+
if (mainNupkg !== void 0) return {
|
|
158
|
+
nri,
|
|
159
|
+
nupkgPath: mainNupkg
|
|
160
|
+
};
|
|
161
|
+
throw new Error("None of the following dummy packages are non-symbol .nupkg files:\n" + nupkgs.map((nupkg) => ` - ${nupkg}`).join("\n") + "\nIf you intended to push only symbol packages, check if a feature request already exists (https://github.com/HaloSPV3/HCE.Shared/issues?q=push+snupkg) and, if one does not exist, create one containing the keywords \"push snupkg\".");
|
|
162
|
+
})))).map((pair) => pair.nri.GetPushDummyCommand({})).join(" && ");
|
|
163
|
+
}
|
|
164
|
+
toOptions() {
|
|
165
|
+
return this.options;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet`
|
|
170
|
+
* publish, pack, and nuget-push.
|
|
171
|
+
* @param projectsToPublish
|
|
172
|
+
* An array of dotnet projects' relative paths -OR- an array of
|
|
173
|
+
* {@link MSBuildProject} instances.
|
|
174
|
+
* - If `MSBuildProject[]`, the instances will be used as-is.
|
|
175
|
+
* - If `[]`, tries getting projects' semi-colon-separated relative paths from
|
|
176
|
+
* the `PROJECTS_TO_PUBLISH` environment variable.
|
|
177
|
+
* - If configured as recommended, the projects' publish outputs will be zipped
|
|
178
|
+
* to '$PWD/publish' for use in the `publish` semantic-release step e.g. for a
|
|
179
|
+
* GitHub release.
|
|
180
|
+
* @param projectsToPackAndPush An array of dotnet projects' relative paths -OR-
|
|
181
|
+
* an array of instances of {@link NugetRegistryInfo} and/or derived classes.
|
|
182
|
+
* - If `NugetRegistryInfo[]`, no conversions or modifications will occur.
|
|
183
|
+
* - If `string[]`, the project paths will be converted to
|
|
184
|
+
* {@link NugetRegistryInfo} instances with default values. This may be undesired.
|
|
185
|
+
* - If `[]`, `dotnet pack` and `dotnet nuget push` commands will not be configured.
|
|
186
|
+
* - If `undefined`, tries getting projects' semi-colon-separated relative paths
|
|
187
|
+
* from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.
|
|
188
|
+
* With the recommended configuration, `dotnet pack` will write the nupkg/snupkg
|
|
189
|
+
* files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.
|
|
190
|
+
* @returns a semantic-release Options object, based on
|
|
191
|
+
* `@halospv3/hce.shared-config` (our base config), with the
|
|
192
|
+
* `@semantic-release/exec` plugin configured to `dotnet publish`, `pack`, and
|
|
193
|
+
* `push` the specified projects.
|
|
194
|
+
*/
|
|
195
|
+
async function getConfig(projectsToPublish, projectsToPackAndPush) {
|
|
196
|
+
if (_debug.enabled) _debug("hce.shared-config:\n" + inspect(baseConfig, false, Infinity, true));
|
|
197
|
+
const errors = [];
|
|
198
|
+
if (projectsToPublish.length === 0) {
|
|
199
|
+
const _ = getEnvVarValue("PROJECTS_TO_PUBLISH");
|
|
200
|
+
if (_ === void 0) errors.push(/* @__PURE__ */ new Error("projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path."));
|
|
201
|
+
else projectsToPublish = _.split(";");
|
|
202
|
+
}
|
|
203
|
+
if (!projectsToPackAndPush) {
|
|
204
|
+
const _ = getEnvVarValue("PROJECTS_TO_PACK_AND_PUSH");
|
|
205
|
+
if (_ === void 0) errors.push(/* @__PURE__ */ new Error("projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path."));
|
|
206
|
+
else projectsToPackAndPush = _.split(";");
|
|
207
|
+
}
|
|
208
|
+
if (errors.length > 0) throw new Error(["getConfig cannot continue. One or more errors occurred.", ...errors.map((v) => v.stack)].join("\n"));
|
|
209
|
+
const config = new SemanticReleaseConfigDotnet(projectsToPublish, projectsToPackAndPush ?? []);
|
|
210
|
+
await config.setupDotnetCommands();
|
|
211
|
+
const options = config.toOptions();
|
|
212
|
+
if (_debug.enabled) {
|
|
213
|
+
_debug("modified plugins array:");
|
|
214
|
+
_debug(inspect(options.plugins, false, Infinity));
|
|
215
|
+
}
|
|
216
|
+
return options;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @module semanticReleaseConfigDotnet
|
|
220
|
+
*/
|
|
221
|
+
//#endregion
|
|
222
|
+
export { SemanticReleaseConfigDotnet, getConfig };
|
|
223
|
+
|
|
7
224
|
//# sourceMappingURL=semanticReleaseConfigDotnet.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semanticReleaseConfigDotnet.mjs","names":["debug"],"sources":["../src/semanticReleaseConfigDotnet.ts"],"sourcesContent":["/**\n * # Semantic-Release Config Factory (dotnet)\n * A functional Semantic-Release configuration for dotnet projects\n *\n * extends {@link baseConfig }\n *\n * <-- TABLE OF CONTENTS -->\n *\n * EASY: {@link getConfig}\n * Just provide the paths of the project file(s) and keep your API tokens ready.\n * ADVANCED: {@link SemanticReleaseConfigDotnet}\n * Allows for a hands-on customization if {@link getConfig} doesn't meet your needs.\n * Use a copy of {@link getConfig} as the starting point of a new function and make changes from there.\n * - {@link SemanticReleaseConfigDotnet#splicePlugin splicePlugin (insert/edit plugins)}\n * - {@link SemanticReleaseConfigDotnet#setupDotnetCommands setupDotnetCommands}\n * - {@link SemanticReleaseConfigDotnet#getTokenTestingCommands getTokenTestingCommands}\n */\n\nimport { inspect } from 'node:util';\nimport type { Options } from 'semantic-release';\n// @ts-types=\"./semantic-release__exec.d.ts\"\nimport type { Options as SRExecOptions } from '@semantic-release/exec';\nimport * as console from 'node:console';\nimport debug from './debug.ts';\nimport { configureDotnetNugetPush, configurePrepareCmd } from './dotnet/helpers.ts';\nimport { getEnvVarValue } from './utils/env.ts';\nimport { baseConfig } from './semanticReleaseConfig.ts';\nimport { NugetRegistryInfo } from './dotnet/NugetRegistryInfo.ts';\nimport { MSBuildProject } from './dotnet/MSBuildProject.ts';\nimport { insertPlugin } from './insertPlugins.ts';\n\ntype UnArray<T> = T extends (infer U)[] ? U : T;\ninterface SRConfigDotnetOptions extends Omit<typeof baseConfig, 'plugins'> {\n plugins: (UnArray<typeof baseConfig.plugins> | [string, unknown])[];\n}\n\nexport class SemanticReleaseConfigDotnet {\n private readonly options: SRConfigDotnetOptions;\n private readonly _projectsToPublish: string[] | MSBuildProject[];\n private _projectsToPackAndPush: string[] | NugetRegistryInfo[];\n private readonly _evaluatedProjects: MSBuildProject[];\n\n /**\n * Creates an instance of SemanticReleaseConfigDotnet.\n * Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet` publish, pack, and push.\n *\n * Note: To sign packages, create a Target in the corresponding project(s) e.g.\n * ```xml\n * <Target Name=\"SignNupkgs\" AfterTargets=\"Pack\">\n * <Exec Command=\"dotnet nuget sign $(PackageOutputPath) [remaining args]\" ConsoleToMsBuild=\"true\" />\n * </Target>\n * ```\n * Alternatively, splice your signing commands into the publishCmd string,\n * inserting them before `dotnet nuget push`.\n * If you sign different signatures depending on the NuGet registry,\n * splice your signing command (with \"overwrite signature\" enabled, if\n * desired) before the corresponding registry's `dotnet nuget push` command.\n * @param projectsToPublish An array of dotnet projects' relative paths. If\n * empty or unspecified, tries getting projects' semi-colon-separated relative\n * paths from the `PROJECTS_TO_PUBLISH` environment variable. If configured as\n * recommended, the projects' publish outputs will be zipped to '$PWD/publish'\n * for use in the `publish` semantic-release step (typically, GitHub release).\n * @param projectsToPackAndPush An array of dotnet projects' relative paths.\n * If empty or unspecified, tries getting projects' semi-colon-separated\n * relative paths from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.\n * Otherwise, no packages will be packed and pushed.\n * If configured as recommended, `dotnet pack` will output the nupkg/snupkg\n * files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.\n */\n constructor(\n projectsToPublish: string[] | MSBuildProject[],\n projectsToPackAndPush: string[] | NugetRegistryInfo[],\n ) {\n this.options = baseConfig;\n /* normalize PluginSpecs to tuples */\n this.options.plugins = this.options.plugins.map(pluginSpec => typeof pluginSpec === 'string'\n ? [pluginSpec, {}]\n : pluginSpec,\n );\n\n this._projectsToPublish = projectsToPublish;\n if (this._projectsToPublish.length === 0) {\n const p = getEnvVarValue('PROJECTS_TO_PUBLISH')?.split(';');\n if (p && p.length > 0) {\n this._projectsToPublish = p;\n }\n else if (debug.enabled) {\n debug(new Error('At least one project must be published. `projectsToPackAndPush` is empty and environment variable `PROJECTS_TO_PUBLISH` is undefined or empty.'));\n }\n }\n\n this._projectsToPackAndPush = projectsToPackAndPush;\n if (this._projectsToPackAndPush.length === 0) {\n const p = getEnvVarValue('PROJECTS_TO_PACK_AND_PUSH')?.split(';');\n if (p && p.length > 0) {\n this._projectsToPackAndPush = p;\n }\n else if (debug.enabled) {\n debug(new Error('projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path.'));\n }\n }\n\n // may be zero-length array\n this._evaluatedProjects = [\n ...this._projectsToPublish.filter(v => v instanceof MSBuildProject),\n ...this._projectsToPackAndPush\n .filter(v => v instanceof NugetRegistryInfo)\n .map(v => v.project),\n ];\n }\n\n get ProjectsToPublish(): string[] | MSBuildProject[] {\n return this._projectsToPublish;\n }\n\n get ProjectsToPackAndPush(): string[] | NugetRegistryInfo[] {\n return this._projectsToPackAndPush;\n }\n\n get EvaluatedProjects(): MSBuildProject[] {\n return this._evaluatedProjects;\n }\n\n // eslint-disable-next-line jsdoc/require-param\n /** @deprecated Superseded by {@link splicePlugin} */\n insertPlugin(\n afterPluginsIDs: string[],\n insertPluginIDs: string[],\n beforePluginsIDs: string[],\n ): void {\n this.options.plugins = insertPlugin(this.options.plugins, afterPluginsIDs, insertPluginIDs, beforePluginsIDs);\n }\n\n /**\n * generate dotnet commands for \\@semantic-release/exec, appending commands with ' && ' when necessary.\n *\n * Note: All strings in {@link this.ProjectsToPackAndPush} will be converted to basic {@link NugetRegistryInfo} instances with default values.\n * If you need specific NRI settings or you need to push to GitLab-like or GitHub-like registries, instantiate them instead of passing their paths.\n * @todo change to builder method? e.g. static async SetupDotnetCommands(this: SemanticReleaseConfigDotnet): Promise<SemanticReleaseConfigDotnet>\n * @todo Add options param to allow users to enable pushing to GitLab, GitHub, NuGet.org with default settings -OR- with entirely custom settings.\n * @see https://github.com/semantic-release/exec#usage\n */\n async setupDotnetCommands(): Promise<void> {\n let srExecIndex = this.options.plugins.findIndex(\n v => v[0] === '@semantic-release/exec',\n );\n if (srExecIndex === -1) {\n const message = `\\\nUnable to find\\`['@semantic-release/exec', unknown]\\` in plugins array!\nAppending it to the end of the array...This may cause an unexpected order of operations!`;\n console.warn(message);\n srExecIndex = this.options.plugins.push(['@semantic-release/exec', {}]) - 1;\n }\n\n const plugin = this.options.plugins[srExecIndex] as ['@semantic-release/exec', SRExecOptions];\n const execOptions: SRExecOptions = plugin[1];\n\n // ensure all packable projects are evaluated\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n this._projectsToPackAndPush = await Promise.all(\n this._projectsToPackAndPush.map(async (project) => {\n if (typeof project === 'string') {\n const packableProjects = await Promise.all(\n await MSBuildProject.PackableProjectsToMSBuildProjects(\n [project],\n ),\n );\n if (packableProjects.length === 0)\n throw new Error('No MSBuildProject instances were returned!');\n this._evaluatedProjects.push(...packableProjects);\n\n // if the user doesn't want a defaulted NRI, they should pass their own NRI (or derived) instance.\n return packableProjects.map(project => new NugetRegistryInfo({ project }));\n }\n else return [project];\n }),\n ).then(p => p.flat()) as NugetRegistryInfo[];\n\n // todo: double-check token-testing commands. Are they formatted prepended correctly?\n const verifyConditionsCmdAppendix = await Promise.all(\n this._projectsToPackAndPush\n .map(async project =>\n await project.PackDummyPackage({})\n .then(() =>\n project.GetPushDummyCommand({}),\n ),\n ),\n ).then(cmds =>\n cmds.join(' && '),\n );\n execOptions.verifyConditionsCmd\n = execOptions.verifyConditionsCmd && execOptions.verifyConditionsCmd.trim().length > 0\n ? `${execOptions.verifyConditionsCmd} && ${verifyConditionsCmdAppendix}`\n : verifyConditionsCmdAppendix;\n\n const verifyReleaseCmdAppendix\n = this.ProjectsToPackAndPush\n .filter(project =>\n typeof project !== 'string',\n ).map(project =>\n project.GetIsNextVersionAlreadyPublishedCommand(),\n ).join(' && ');\n execOptions.verifyReleaseCmd\n = execOptions.verifyReleaseCmd && execOptions.verifyReleaseCmd.trim().length > 0\n ? `${execOptions.verifyReleaseCmd} && ${verifyReleaseCmdAppendix}`\n : verifyConditionsCmdAppendix;\n\n const prepareCmdAppendix = await configurePrepareCmd(\n this._projectsToPublish,\n this._projectsToPackAndPush,\n );\n\n // 'ZipPublishDir' zips each publish folder to ./publish/*.zip\n execOptions.prepareCmd\n = execOptions.prepareCmd && execOptions.prepareCmd.trim().length > 0\n ? `${execOptions.prepareCmd} && ${prepareCmdAppendix}`\n : prepareCmdAppendix;\n\n // FINISHED execOptions.prepareCmd\n // STARTING execOptions.publishCmd\n if (this._projectsToPackAndPush.length > 0) {\n const publishCmdAppendix: string = configureDotnetNugetPush(\n this._projectsToPackAndPush,\n );\n execOptions.publishCmd\n = execOptions.publishCmd && execOptions.publishCmd.trim().length > 0\n ? `${execOptions.publishCmd} && ${publishCmdAppendix}`\n : publishCmdAppendix;\n }\n\n // FINISHED execOptions.publishCmd\n }\n\n /**\n * Insert a plugin into the plugins array.\n * @param insertAfterPluginIDs Plugins which should appear BEFORE\n * {@link insertPluginIDs}.\n * @param insertPluginIDs The plugin(s) to insert into the plugins array.\n * @param insertBeforePluginsIDs plugins which should appear AFTER the\n * inserted plugin(s).\n */\n splicePlugin(\n insertAfterPluginIDs: string[],\n insertPluginIDs: string[],\n insertBeforePluginsIDs: string[],\n ): void {\n const errors: Error[] = [];\n const pluginIDs = this.options.plugins.map(v =>\n typeof v === 'string' ? v : v[0],\n ) as (typeof this.options.plugins[number])[][0];\n\n // if any beforePluginIDs are ordered before the last afterPlugin, throw. Impossible to sort.\n\n const indexOfLastPreceding: number | undefined = insertAfterPluginIDs\n .filter(v => pluginIDs.includes(v))\n .map(v => pluginIDs.indexOf(v))\n .sort()\n .find((_v, i, obj) => i === obj.length - 1);\n if (!indexOfLastPreceding)\n throw new ReferenceError(\n 'An attempt to get the last element of indexOfLastAfter returned undefined.',\n );\n\n const indicesOfBefore: number[] = insertBeforePluginsIDs\n .filter(v => pluginIDs.includes(v))\n .map(v => pluginIDs.indexOf(v))\n .sort();\n\n for (const index of indicesOfBefore) {\n if (index <= indexOfLastPreceding) {\n const formattedInsertIds: string\n = '[' + insertPluginIDs.map(v => `\"${v}\"`).join(', ') + ']';\n const formattedAfterIds: string\n = '[' + insertAfterPluginIDs.map(v => `\"${v}\"`).join(', ') + ']';\n const formattedBeforeIds: string\n = '[' + insertBeforePluginsIDs.map(v => `\"${v}\"`).join(', ') + ']';\n errors.push(\n new Error(\n `insertPlugin was instructed to insert ${formattedInsertIds} after ${formattedAfterIds} and before ${formattedBeforeIds}, `\n + `but ${JSON.stringify(pluginIDs[indexOfLastPreceding])} is ordered after ${JSON.stringify(pluginIDs[index])}!`,\n ),\n );\n }\n }\n\n if (errors.length > 0)\n throw new AggregateError(errors, 'One or more errors occurred while splicing plugin-option tuples into the Semantic Release config!');\n\n this.options.plugins.splice(\n indexOfLastPreceding + 1,\n 0,\n ...insertPluginIDs.map(v => [v, {}] satisfies [string, unknown]),\n );\n }\n\n // todo: join result with dummy pack commands\n protected async getTokenTestingCommands(): Promise<string> {\n const promiseProjects = this.ProjectsToPackAndPush.every(nri => nri instanceof NugetRegistryInfo)\n ? this.ProjectsToPackAndPush.map(nri => nri.project)\n : await Promise.all(await MSBuildProject.PackableProjectsToMSBuildProjects(this.ProjectsToPackAndPush));\n\n /** if a project is not in {@link EvaluatedProjects}, add it */\n for (const project of promiseProjects) {\n if (!this.EvaluatedProjects.includes(project))\n this.EvaluatedProjects.push(project);\n }\n\n const regInfos = promiseProjects.map(\n p => new NugetRegistryInfo({ project: p }),\n );\n const nupkgPaths = await Promise.all(\n regInfos.map(nri =>\n nri.PackDummyPackage({}).then((nupkgs) => {\n // this is a full file path.\n const mainNupkg = nupkgs.find(nupkg =>\n new RegExp(/(?<!symbols)\\.nupkg$/).test(nupkg),\n );\n if (mainNupkg !== undefined)\n return { nri: nri, nupkgPath: mainNupkg } as const;\n throw new Error(\n 'None of the following dummy packages are non-symbol .nupkg files:\\n'\n + nupkgs.map(nupkg => ` - ${nupkg}`).join('\\n')\n + '\\nIf you intended to push only symbol packages, check if a feature request already exists (https://github.com/HaloSPV3/HCE.Shared/issues?q=push+snupkg) and, if one does not exist, create one containing the keywords \"push snupkg\".',\n );\n }),\n ),\n );\n const pushCommands = nupkgPaths.map(pair =>\n pair.nri.GetPushDummyCommand({}),\n );\n return pushCommands.join(' && ');\n }\n\n toOptions(): Options {\n return this.options;\n }\n}\n\n/**\n * Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet`\n * publish, pack, and nuget-push.\n * @param projectsToPublish\n * An array of dotnet projects' relative paths -OR- an array of\n * {@link MSBuildProject} instances.\n * - If `MSBuildProject[]`, the instances will be used as-is.\n * - If `[]`, tries getting projects' semi-colon-separated relative paths from\n * the `PROJECTS_TO_PUBLISH` environment variable.\n * - If configured as recommended, the projects' publish outputs will be zipped\n * to '$PWD/publish' for use in the `publish` semantic-release step e.g. for a\n * GitHub release.\n * @param projectsToPackAndPush An array of dotnet projects' relative paths -OR-\n * an array of instances of {@link NugetRegistryInfo} and/or derived classes.\n * - If `NugetRegistryInfo[]`, no conversions or modifications will occur.\n * - If `string[]`, the project paths will be converted to\n * {@link NugetRegistryInfo} instances with default values. This may be undesired.\n * - If `[]`, `dotnet pack` and `dotnet nuget push` commands will not be configured.\n * - If `undefined`, tries getting projects' semi-colon-separated relative paths\n * from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.\n * With the recommended configuration, `dotnet pack` will write the nupkg/snupkg\n * files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.\n * @returns a semantic-release Options object, based on\n * `@halospv3/hce.shared-config` (our base config), with the\n * `@semantic-release/exec` plugin configured to `dotnet publish`, `pack`, and\n * `push` the specified projects.\n */\nexport async function getConfig(\n projectsToPublish: string[] | MSBuildProject[],\n projectsToPackAndPush?: string[] | NugetRegistryInfo[],\n): Promise<Options> {\n if (debug.enabled) {\n debug(\n 'hce.shared-config:\\n' + inspect(baseConfig, false, Infinity, true),\n );\n }\n\n const errors: Error[] = [];\n\n if (projectsToPublish.length === 0) {\n const _ = getEnvVarValue('PROJECTS_TO_PUBLISH');\n if (_ === undefined)\n errors.push(\n new Error(\n 'projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path.',\n ),\n );\n else projectsToPublish = _.split(';');\n }\n\n if (!projectsToPackAndPush) {\n const _ = getEnvVarValue('PROJECTS_TO_PACK_AND_PUSH');\n if (_ === undefined)\n errors.push(\n new Error(\n 'projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path.',\n ),\n );\n else projectsToPackAndPush = _.split(';');\n }\n\n if (errors.length > 0) {\n throw new Error(\n [\n 'getConfig cannot continue. One or more errors occurred.',\n ...errors.map(v => v.stack),\n ].join('\\n'),\n );\n }\n\n const config = new SemanticReleaseConfigDotnet(\n projectsToPublish,\n projectsToPackAndPush ?? [],\n );\n await config.setupDotnetCommands();\n\n const options: Options = config.toOptions();\n if (debug.enabled) {\n debug('modified plugins array:');\n debug(inspect(options.plugins, false, Infinity));\n }\n\n return options;\n}\n\n/**\n * @module semanticReleaseConfigDotnet\n */\n"],"mappings":"odAoCA,IAAa,EAAb,KAAyC,CACvC,QACA,mBACA,uBACA,mBA6BA,YACE,EACA,EACA,CASA,GARA,KAAK,QAAU,EAEf,KAAK,QAAQ,QAAU,KAAK,QAAQ,QAAQ,IA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AChC,EAAM,EAAQ,EAAQ,QAAS,GAAO,IAAS,CAAC,EAG3C"}
|
|
1
|
+
{"version":3,"file":"semanticReleaseConfigDotnet.mjs","names":["debug"],"sources":["../src/semanticReleaseConfigDotnet.ts"],"sourcesContent":["/**\n * # Semantic-Release Config Factory (dotnet)\n * A functional Semantic-Release configuration for dotnet projects\n *\n * extends {@link baseConfig }\n *\n * <-- TABLE OF CONTENTS -->\n *\n * EASY: {@link getConfig}\n * Just provide the paths of the project file(s) and keep your API tokens ready.\n * ADVANCED: {@link SemanticReleaseConfigDotnet}\n * Allows for a hands-on customization if {@link getConfig} doesn't meet your needs.\n * Use a copy of {@link getConfig} as the starting point of a new function and make changes from there.\n * - {@link SemanticReleaseConfigDotnet#splicePlugin splicePlugin (insert/edit plugins)}\n * - {@link SemanticReleaseConfigDotnet#setupDotnetCommands setupDotnetCommands}\n * - {@link SemanticReleaseConfigDotnet#getTokenTestingCommands getTokenTestingCommands}\n */\n\nimport { inspect } from 'node:util';\nimport type { Options } from 'semantic-release';\n// @ts-types=\"./semantic-release__exec.d.ts\"\nimport type { Options as SRExecOptions } from '@semantic-release/exec';\nimport * as console from 'node:console';\nimport debug from './debug.ts';\nimport { configureDotnetNugetPush, configurePrepareCmd } from './dotnet/helpers.ts';\nimport { getEnvVarValue } from './utils/env.ts';\nimport { baseConfig } from './semanticReleaseConfig.ts';\nimport { NugetRegistryInfo } from './dotnet/NugetRegistryInfo.ts';\nimport { MSBuildProject } from './dotnet/MSBuildProject.ts';\nimport { insertPlugin } from './insertPlugins.ts';\n\ntype UnArray<T> = T extends (infer U)[] ? U : T;\ninterface SRConfigDotnetOptions extends Omit<typeof baseConfig, 'plugins'> {\n plugins: (UnArray<typeof baseConfig.plugins> | [string, unknown])[];\n}\n\nexport class SemanticReleaseConfigDotnet {\n private readonly options: SRConfigDotnetOptions;\n private readonly _projectsToPublish: string[] | MSBuildProject[];\n private _projectsToPackAndPush: string[] | NugetRegistryInfo[];\n private readonly _evaluatedProjects: MSBuildProject[];\n\n /**\n * Creates an instance of SemanticReleaseConfigDotnet.\n * Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet` publish, pack, and push.\n *\n * Note: To sign packages, create a Target in the corresponding project(s) e.g.\n * ```xml\n * <Target Name=\"SignNupkgs\" AfterTargets=\"Pack\">\n * <Exec Command=\"dotnet nuget sign $(PackageOutputPath) [remaining args]\" ConsoleToMsBuild=\"true\" />\n * </Target>\n * ```\n * Alternatively, splice your signing commands into the publishCmd string,\n * inserting them before `dotnet nuget push`.\n * If you sign different signatures depending on the NuGet registry,\n * splice your signing command (with \"overwrite signature\" enabled, if\n * desired) before the corresponding registry's `dotnet nuget push` command.\n * @param projectsToPublish An array of dotnet projects' relative paths. If\n * empty or unspecified, tries getting projects' semi-colon-separated relative\n * paths from the `PROJECTS_TO_PUBLISH` environment variable. If configured as\n * recommended, the projects' publish outputs will be zipped to '$PWD/publish'\n * for use in the `publish` semantic-release step (typically, GitHub release).\n * @param projectsToPackAndPush An array of dotnet projects' relative paths.\n * If empty or unspecified, tries getting projects' semi-colon-separated\n * relative paths from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.\n * Otherwise, no packages will be packed and pushed.\n * If configured as recommended, `dotnet pack` will output the nupkg/snupkg\n * files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.\n */\n constructor(\n projectsToPublish: string[] | MSBuildProject[],\n projectsToPackAndPush: string[] | NugetRegistryInfo[],\n ) {\n this.options = baseConfig;\n /* normalize PluginSpecs to tuples */\n this.options.plugins = this.options.plugins.map(pluginSpec => typeof pluginSpec === 'string'\n ? [pluginSpec, {}]\n : pluginSpec,\n );\n\n this._projectsToPublish = projectsToPublish;\n if (this._projectsToPublish.length === 0) {\n const p = getEnvVarValue('PROJECTS_TO_PUBLISH')?.split(';');\n if (p && p.length > 0) {\n this._projectsToPublish = p;\n }\n else if (debug.enabled) {\n debug(new Error('At least one project must be published. `projectsToPackAndPush` is empty and environment variable `PROJECTS_TO_PUBLISH` is undefined or empty.'));\n }\n }\n\n this._projectsToPackAndPush = projectsToPackAndPush;\n if (this._projectsToPackAndPush.length === 0) {\n const p = getEnvVarValue('PROJECTS_TO_PACK_AND_PUSH')?.split(';');\n if (p && p.length > 0) {\n this._projectsToPackAndPush = p;\n }\n else if (debug.enabled) {\n debug(new Error('projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path.'));\n }\n }\n\n // may be zero-length array\n this._evaluatedProjects = [\n ...this._projectsToPublish.filter(v => v instanceof MSBuildProject),\n ...this._projectsToPackAndPush\n .filter(v => v instanceof NugetRegistryInfo)\n .map(v => v.project),\n ];\n }\n\n get ProjectsToPublish(): string[] | MSBuildProject[] {\n return this._projectsToPublish;\n }\n\n get ProjectsToPackAndPush(): string[] | NugetRegistryInfo[] {\n return this._projectsToPackAndPush;\n }\n\n get EvaluatedProjects(): MSBuildProject[] {\n return this._evaluatedProjects;\n }\n\n // eslint-disable-next-line jsdoc/require-param\n /** @deprecated Superseded by {@link splicePlugin} */\n insertPlugin(\n afterPluginsIDs: string[],\n insertPluginIDs: string[],\n beforePluginsIDs: string[],\n ): void {\n this.options.plugins = insertPlugin(this.options.plugins, afterPluginsIDs, insertPluginIDs, beforePluginsIDs);\n }\n\n /**\n * generate dotnet commands for \\@semantic-release/exec, appending commands with ' && ' when necessary.\n *\n * Note: All strings in {@link this.ProjectsToPackAndPush} will be converted to basic {@link NugetRegistryInfo} instances with default values.\n * If you need specific NRI settings or you need to push to GitLab-like or GitHub-like registries, instantiate them instead of passing their paths.\n * @todo change to builder method? e.g. static async SetupDotnetCommands(this: SemanticReleaseConfigDotnet): Promise<SemanticReleaseConfigDotnet>\n * @todo Add options param to allow users to enable pushing to GitLab, GitHub, NuGet.org with default settings -OR- with entirely custom settings.\n * @see https://github.com/semantic-release/exec#usage\n */\n async setupDotnetCommands(): Promise<void> {\n let srExecIndex = this.options.plugins.findIndex(\n v => v[0] === '@semantic-release/exec',\n );\n if (srExecIndex === -1) {\n const message = `\\\nUnable to find\\`['@semantic-release/exec', unknown]\\` in plugins array!\nAppending it to the end of the array...This may cause an unexpected order of operations!`;\n console.warn(message);\n srExecIndex = this.options.plugins.push(['@semantic-release/exec', {}]) - 1;\n }\n\n const plugin = this.options.plugins[srExecIndex] as ['@semantic-release/exec', SRExecOptions];\n const execOptions: SRExecOptions = plugin[1];\n\n // ensure all packable projects are evaluated\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n this._projectsToPackAndPush = await Promise.all(\n this._projectsToPackAndPush.map(async (project) => {\n if (typeof project === 'string') {\n const packableProjects = await Promise.all(\n await MSBuildProject.PackableProjectsToMSBuildProjects(\n [project],\n ),\n );\n if (packableProjects.length === 0)\n throw new Error('No MSBuildProject instances were returned!');\n this._evaluatedProjects.push(...packableProjects);\n\n // if the user doesn't want a defaulted NRI, they should pass their own NRI (or derived) instance.\n return packableProjects.map(project => new NugetRegistryInfo({ project }));\n }\n else return [project];\n }),\n ).then(p => p.flat()) as NugetRegistryInfo[];\n\n // todo: double-check token-testing commands. Are they formatted prepended correctly?\n const verifyConditionsCmdAppendix = await Promise.all(\n this._projectsToPackAndPush\n .map(async project =>\n await project.PackDummyPackage({})\n .then(() =>\n project.GetPushDummyCommand({}),\n ),\n ),\n ).then(cmds =>\n cmds.join(' && '),\n );\n execOptions.verifyConditionsCmd\n = execOptions.verifyConditionsCmd && execOptions.verifyConditionsCmd.trim().length > 0\n ? `${execOptions.verifyConditionsCmd} && ${verifyConditionsCmdAppendix}`\n : verifyConditionsCmdAppendix;\n\n const verifyReleaseCmdAppendix\n = this.ProjectsToPackAndPush\n .filter(project =>\n typeof project !== 'string',\n ).map(project =>\n project.GetIsNextVersionAlreadyPublishedCommand(),\n ).join(' && ');\n execOptions.verifyReleaseCmd\n = execOptions.verifyReleaseCmd && execOptions.verifyReleaseCmd.trim().length > 0\n ? `${execOptions.verifyReleaseCmd} && ${verifyReleaseCmdAppendix}`\n : verifyConditionsCmdAppendix;\n\n const prepareCmdAppendix = await configurePrepareCmd(\n this._projectsToPublish,\n this._projectsToPackAndPush,\n );\n\n // 'ZipPublishDir' zips each publish folder to ./publish/*.zip\n execOptions.prepareCmd\n = execOptions.prepareCmd && execOptions.prepareCmd.trim().length > 0\n ? `${execOptions.prepareCmd} && ${prepareCmdAppendix}`\n : prepareCmdAppendix;\n\n // FINISHED execOptions.prepareCmd\n // STARTING execOptions.publishCmd\n if (this._projectsToPackAndPush.length > 0) {\n const publishCmdAppendix: string = configureDotnetNugetPush(\n this._projectsToPackAndPush,\n );\n execOptions.publishCmd\n = execOptions.publishCmd && execOptions.publishCmd.trim().length > 0\n ? `${execOptions.publishCmd} && ${publishCmdAppendix}`\n : publishCmdAppendix;\n }\n\n // FINISHED execOptions.publishCmd\n }\n\n /**\n * Insert a plugin into the plugins array.\n * @param insertAfterPluginIDs Plugins which should appear BEFORE\n * {@link insertPluginIDs}.\n * @param insertPluginIDs The plugin(s) to insert into the plugins array.\n * @param insertBeforePluginsIDs plugins which should appear AFTER the\n * inserted plugin(s).\n */\n splicePlugin(\n insertAfterPluginIDs: string[],\n insertPluginIDs: string[],\n insertBeforePluginsIDs: string[],\n ): void {\n const errors: Error[] = [];\n const pluginIDs = this.options.plugins.map(v =>\n typeof v === 'string' ? v : v[0],\n ) as (typeof this.options.plugins[number])[][0];\n\n // if any beforePluginIDs are ordered before the last afterPlugin, throw. Impossible to sort.\n\n const indexOfLastPreceding: number | undefined = insertAfterPluginIDs\n .filter(v => pluginIDs.includes(v))\n .map(v => pluginIDs.indexOf(v))\n .sort()\n .find((_v, i, obj) => i === obj.length - 1);\n if (!indexOfLastPreceding)\n throw new ReferenceError(\n 'An attempt to get the last element of indexOfLastAfter returned undefined.',\n );\n\n const indicesOfBefore: number[] = insertBeforePluginsIDs\n .filter(v => pluginIDs.includes(v))\n .map(v => pluginIDs.indexOf(v))\n .sort();\n\n for (const index of indicesOfBefore) {\n if (index <= indexOfLastPreceding) {\n const formattedInsertIds: string\n = '[' + insertPluginIDs.map(v => `\"${v}\"`).join(', ') + ']';\n const formattedAfterIds: string\n = '[' + insertAfterPluginIDs.map(v => `\"${v}\"`).join(', ') + ']';\n const formattedBeforeIds: string\n = '[' + insertBeforePluginsIDs.map(v => `\"${v}\"`).join(', ') + ']';\n errors.push(\n new Error(\n `insertPlugin was instructed to insert ${formattedInsertIds} after ${formattedAfterIds} and before ${formattedBeforeIds}, `\n + `but ${JSON.stringify(pluginIDs[indexOfLastPreceding])} is ordered after ${JSON.stringify(pluginIDs[index])}!`,\n ),\n );\n }\n }\n\n if (errors.length > 0)\n throw new AggregateError(errors, 'One or more errors occurred while splicing plugin-option tuples into the Semantic Release config!');\n\n this.options.plugins.splice(\n indexOfLastPreceding + 1,\n 0,\n ...insertPluginIDs.map(v => [v, {}] satisfies [string, unknown]),\n );\n }\n\n // todo: join result with dummy pack commands\n protected async getTokenTestingCommands(): Promise<string> {\n const promiseProjects = this.ProjectsToPackAndPush.every(nri => nri instanceof NugetRegistryInfo)\n ? this.ProjectsToPackAndPush.map(nri => nri.project)\n : await Promise.all(await MSBuildProject.PackableProjectsToMSBuildProjects(this.ProjectsToPackAndPush));\n\n /** if a project is not in {@link EvaluatedProjects}, add it */\n for (const project of promiseProjects) {\n if (!this.EvaluatedProjects.includes(project))\n this.EvaluatedProjects.push(project);\n }\n\n const regInfos = promiseProjects.map(\n p => new NugetRegistryInfo({ project: p }),\n );\n const nupkgPaths = await Promise.all(\n regInfos.map(nri =>\n nri.PackDummyPackage({}).then((nupkgs) => {\n // this is a full file path.\n const mainNupkg = nupkgs.find(nupkg =>\n new RegExp(/(?<!symbols)\\.nupkg$/).test(nupkg),\n );\n if (mainNupkg !== undefined)\n return { nri: nri, nupkgPath: mainNupkg } as const;\n throw new Error(\n 'None of the following dummy packages are non-symbol .nupkg files:\\n'\n + nupkgs.map(nupkg => ` - ${nupkg}`).join('\\n')\n + '\\nIf you intended to push only symbol packages, check if a feature request already exists (https://github.com/HaloSPV3/HCE.Shared/issues?q=push+snupkg) and, if one does not exist, create one containing the keywords \"push snupkg\".',\n );\n }),\n ),\n );\n const pushCommands = nupkgPaths.map(pair =>\n pair.nri.GetPushDummyCommand({}),\n );\n return pushCommands.join(' && ');\n }\n\n toOptions(): Options {\n return this.options;\n }\n}\n\n/**\n * Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet`\n * publish, pack, and nuget-push.\n * @param projectsToPublish\n * An array of dotnet projects' relative paths -OR- an array of\n * {@link MSBuildProject} instances.\n * - If `MSBuildProject[]`, the instances will be used as-is.\n * - If `[]`, tries getting projects' semi-colon-separated relative paths from\n * the `PROJECTS_TO_PUBLISH` environment variable.\n * - If configured as recommended, the projects' publish outputs will be zipped\n * to '$PWD/publish' for use in the `publish` semantic-release step e.g. for a\n * GitHub release.\n * @param projectsToPackAndPush An array of dotnet projects' relative paths -OR-\n * an array of instances of {@link NugetRegistryInfo} and/or derived classes.\n * - If `NugetRegistryInfo[]`, no conversions or modifications will occur.\n * - If `string[]`, the project paths will be converted to\n * {@link NugetRegistryInfo} instances with default values. This may be undesired.\n * - If `[]`, `dotnet pack` and `dotnet nuget push` commands will not be configured.\n * - If `undefined`, tries getting projects' semi-colon-separated relative paths\n * from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.\n * With the recommended configuration, `dotnet pack` will write the nupkg/snupkg\n * files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.\n * @returns a semantic-release Options object, based on\n * `@halospv3/hce.shared-config` (our base config), with the\n * `@semantic-release/exec` plugin configured to `dotnet publish`, `pack`, and\n * `push` the specified projects.\n */\nexport async function getConfig(\n projectsToPublish: string[] | MSBuildProject[],\n projectsToPackAndPush?: string[] | NugetRegistryInfo[],\n): Promise<Options> {\n if (debug.enabled) {\n debug(\n 'hce.shared-config:\\n' + inspect(baseConfig, false, Infinity, true),\n );\n }\n\n const errors: Error[] = [];\n\n if (projectsToPublish.length === 0) {\n const _ = getEnvVarValue('PROJECTS_TO_PUBLISH');\n if (_ === undefined)\n errors.push(\n new Error(\n 'projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path.',\n ),\n );\n else projectsToPublish = _.split(';');\n }\n\n if (!projectsToPackAndPush) {\n const _ = getEnvVarValue('PROJECTS_TO_PACK_AND_PUSH');\n if (_ === undefined)\n errors.push(\n new Error(\n 'projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path.',\n ),\n );\n else projectsToPackAndPush = _.split(';');\n }\n\n if (errors.length > 0) {\n throw new Error(\n [\n 'getConfig cannot continue. One or more errors occurred.',\n ...errors.map(v => v.stack),\n ].join('\\n'),\n );\n }\n\n const config = new SemanticReleaseConfigDotnet(\n projectsToPublish,\n projectsToPackAndPush ?? [],\n );\n await config.setupDotnetCommands();\n\n const options: Options = config.toOptions();\n if (debug.enabled) {\n debug('modified plugins array:');\n debug(inspect(options.plugins, false, Infinity));\n }\n\n return options;\n}\n\n/**\n * @module semanticReleaseConfigDotnet\n */\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,8BAAb,MAAyC;CACvC;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BA,YACE,mBACA,uBACA;AACA,OAAK,UAAU;AAEf,OAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,KAAI,eAAc,OAAO,eAAe,WAChF,CAAC,YAAY,EAAE,CAAC,GAChB,WACH;AAED,OAAK,qBAAqB;AAC1B,MAAI,KAAK,mBAAmB,WAAW,GAAG;GACxC,MAAM,IAAI,eAAe,sBAAsB,EAAE,MAAM,IAAI;AAC3D,OAAI,KAAK,EAAE,SAAS,EAClB,MAAK,qBAAqB;YAEnBA,OAAM,QACb,wBAAM,IAAI,MAAM,iJAAiJ,CAAC;;AAItK,OAAK,yBAAyB;AAC9B,MAAI,KAAK,uBAAuB,WAAW,GAAG;GAC5C,MAAM,IAAI,eAAe,4BAA4B,EAAE,MAAM,IAAI;AACjE,OAAI,KAAK,EA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
|
-
|
|
1
|
+
//#region src/setupGitPluginSpec.default.ts
|
|
2
|
+
/**
|
|
3
|
+
* As specified at https://github.com/semantic-release/git#options
|
|
4
|
+
* To use, assign or create an object with the same (but mutable) properties and deeply-copy to the object
|
|
5
|
+
* @satisfies { GitOptions }
|
|
6
|
+
*/
|
|
7
|
+
const DefaultOptions = {
|
|
8
|
+
assets: [
|
|
9
|
+
"README.md",
|
|
10
|
+
"CHANGELOG.md",
|
|
11
|
+
"package.json",
|
|
12
|
+
"package-lock.json",
|
|
13
|
+
"npm-shrinkwrap.json"
|
|
14
|
+
],
|
|
15
|
+
message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { DefaultOptions };
|
|
2
19
|
|
|
3
|
-
\${nextRelease.notes}`};export{e as DefaultOptions};
|
|
4
20
|
//# sourceMappingURL=setupGitPluginSpec.default.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupGitPluginSpec.default.mjs","names":[],"sources":["../src/setupGitPluginSpec.default.ts"],"sourcesContent":["/// <reference file=\"./semantic-release__git.d.ts\">\n// @ts-types=\"./semantic-release__git.d.ts\"\nimport type { Options as GitOptions } from '@semantic-release/git';\n/**\n * As specified at https://github.com/semantic-release/git#options\n * To use, assign or create an object with the same (but mutable) properties and deeply-copy to the object\n * @satisfies { GitOptions }\n */\nexport const DefaultOptions: {\n readonly assets: ['README.md', 'CHANGELOG.md', 'package.json', 'package-lock.json', 'npm-shrinkwrap.json'];\n readonly message: 'chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}';\n} = {\n assets: [\n 'README.md',\n 'CHANGELOG.md',\n 'package.json',\n 'package-lock.json',\n 'npm-shrinkwrap.json',\n ],\n message:\n 'chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}',\n} as const satisfies GitOptions;\n"],"mappings":"AAQA,MAAa,
|
|
1
|
+
{"version":3,"file":"setupGitPluginSpec.default.mjs","names":[],"sources":["../src/setupGitPluginSpec.default.ts"],"sourcesContent":["/// <reference file=\"./semantic-release__git.d.ts\">\n// @ts-types=\"./semantic-release__git.d.ts\"\nimport type { Options as GitOptions } from '@semantic-release/git';\n/**\n * As specified at https://github.com/semantic-release/git#options\n * To use, assign or create an object with the same (but mutable) properties and deeply-copy to the object\n * @satisfies { GitOptions }\n */\nexport const DefaultOptions: {\n readonly assets: ['README.md', 'CHANGELOG.md', 'package.json', 'package-lock.json', 'npm-shrinkwrap.json'];\n readonly message: 'chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}';\n} = {\n assets: [\n 'README.md',\n 'CHANGELOG.md',\n 'package.json',\n 'package-lock.json',\n 'npm-shrinkwrap.json',\n ],\n message:\n 'chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}',\n} as const satisfies GitOptions;\n"],"mappings":";;;;;;AAQA,MAAa,iBAGT;CACF,QAAQ;EACN;EACA;EACA;EACA;EACA;EACD;CACD,SACE;CACH"}
|
|
@@ -1,2 +1,109 @@
|
|
|
1
|
-
import{DefaultOptions
|
|
1
|
+
import { DefaultOptions } from "./setupGitPluginSpec.default.mjs";
|
|
2
|
+
//#region src/setupGitPluginSpec.ts
|
|
3
|
+
const GitPluginId = "@semantic-release/git";
|
|
4
|
+
/**
|
|
5
|
+
* Check if {@link unk} is an {@link AssetEntry}.
|
|
6
|
+
* @param unk Anything.
|
|
7
|
+
* @returns `true` if {@link unk} is an {@link AssetEntry}. Else, `false`.
|
|
8
|
+
*/
|
|
9
|
+
function isGitAsset(unk) {
|
|
10
|
+
if (typeof unk === "string") return true;
|
|
11
|
+
if (typeof unk === "object" && unk != void 0 && "path" in unk) return typeof unk.path === "string";
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convert one or more {@link AssetEntry AssetEntries} to a `string[]`.
|
|
16
|
+
* @param assets The `assets` property of a {@link GitOptions} object. This may not be `false`.
|
|
17
|
+
* @returns A `string[]` of the given {@link AssetEntry} objects or strings.
|
|
18
|
+
*/
|
|
19
|
+
function gitAssetsToStringArray(assets) {
|
|
20
|
+
if (assets === void 0) return [];
|
|
21
|
+
if (Array.isArray(assets)) return assets.filter((asset) => isGitAsset(asset)).map((v) => typeof v === "string" ? v : v.path);
|
|
22
|
+
if (typeof assets === "string") return [assets];
|
|
23
|
+
if (typeof assets.path === "string") return [assets.path];
|
|
24
|
+
else throw new TypeError("assets is not typeof GitOptions['assets'!");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sanitize a {@link GitOptions} object so its {@link GitOptions#assets} property is either `false` or a `string[]`.
|
|
28
|
+
* @param opts A {@link GitOptions} object.
|
|
29
|
+
* @returns A {@link GitOptions} object whose {@link GitOptions#assets} is `string[] | false`.
|
|
30
|
+
*/
|
|
31
|
+
function sanitizeGitOptions(opts) {
|
|
32
|
+
return {
|
|
33
|
+
...opts,
|
|
34
|
+
assets: opts.assets === false ? opts.assets : gitAssetsToStringArray(opts.assets)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
*Determine if {@link opts} is a {@link GitOptions} object.
|
|
39
|
+
* @param opts Anything.
|
|
40
|
+
* @returns `true` if {@link opts} is a {@link GitOptions} object. Else, `false`.
|
|
41
|
+
*/
|
|
42
|
+
function isGitOptions(opts) {
|
|
43
|
+
let isOptions = false;
|
|
44
|
+
if (typeof opts !== "object" || opts == void 0) return isOptions;
|
|
45
|
+
if ("assets" in opts) isOptions = Array.isArray(opts.assets) ? opts.assets.every((unk) => isGitAsset(unk)) : isGitAsset(opts.assets);
|
|
46
|
+
if ("message" in opts) isOptions = typeof opts.message === "string";
|
|
47
|
+
return isOptions;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Determine if {@link pluginSpec} includes a {@link GitOptions} object.
|
|
51
|
+
* @param pluginSpec a {@link PluginSpecTuple}.
|
|
52
|
+
* @returns `true` if {@link pluginSpec[1]} is a {@link GitOptions} object. Else, `false`.
|
|
53
|
+
*/
|
|
54
|
+
function hasGitOptions(pluginSpec) {
|
|
55
|
+
return isGitOptions(pluginSpec[1]);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Determined if the plugin ID in {@link pluginSpec} is {@link GitPluginId}.
|
|
59
|
+
* @param pluginSpec A {@link PluginSpecTuple}
|
|
60
|
+
* @returns `true` if {@link pluginSpec[0]} is {@link GitPluginId}
|
|
61
|
+
*/
|
|
62
|
+
function isGitPluginSpecTuple(pluginSpec) {
|
|
63
|
+
return pluginSpec[0] === GitPluginId;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* https://github.com/semantic-release/git#options
|
|
67
|
+
*
|
|
68
|
+
* This plugin may be deprecated at a later date.
|
|
69
|
+
* Q: Why would I need to commit during release?
|
|
70
|
+
* A: This is for committing your changelog, README, and/or other files updated during the release procedure.
|
|
71
|
+
* @param plugins An ordered array of {@link PluginSpecTuple PluginSpecTuples}.
|
|
72
|
+
* @returns A {@link PluginSpecTuple}[]. Duplicate `@semantic-release/git` plugin entries are merged or overridden. The last entry takes priority e.g. if the last entry is `{assets: false}`, previous entries' assets are ignored.
|
|
73
|
+
*/
|
|
74
|
+
function setupGitPluginSpec(plugins) {
|
|
75
|
+
/** if Git plugin not in load order, return as-is. */
|
|
76
|
+
const firstGitPluginIndex = plugins.findIndex((plugin) => isGitPluginSpecTuple(plugin));
|
|
77
|
+
if (firstGitPluginIndex === -1) return plugins;
|
|
78
|
+
/**
|
|
79
|
+
* the following two const variables are references--not clones.
|
|
80
|
+
* Modifying them will affect the plugins array.
|
|
81
|
+
*/
|
|
82
|
+
const firstGitPlugin = plugins[firstGitPluginIndex];
|
|
83
|
+
const firstGitOpts = isGitOptions(firstGitPlugin[1]) ? sanitizeGitOptions(firstGitPlugin[1]) : DefaultOptions;
|
|
84
|
+
/**
|
|
85
|
+
* remove duplicate Git plugin entries;
|
|
86
|
+
* merge extra options into firstGitPlugin's options
|
|
87
|
+
* if `firstGitOpts.assets === false`, do not change it.
|
|
88
|
+
* All duplicate PluginSpecSRGit entries are then reassigned `undefined` and all
|
|
89
|
+
* `undefined` items are filtered from the plugins array.
|
|
90
|
+
*/
|
|
91
|
+
return plugins.map((current, index) => {
|
|
92
|
+
if (index <= firstGitPluginIndex || !isGitPluginSpecTuple(current)) return current;
|
|
93
|
+
/** if another Git PluginSpec is discovered, copy its options to the first Git PluginSpec and return undefined. */
|
|
94
|
+
if (hasGitOptions(current)) {
|
|
95
|
+
const currentGitOpts = sanitizeGitOptions(current[1]);
|
|
96
|
+
if (currentGitOpts.assets === false) firstGitOpts.assets = false;
|
|
97
|
+
else {
|
|
98
|
+
const assets = gitAssetsToStringArray(currentGitOpts.assets);
|
|
99
|
+
if (Array.isArray(firstGitOpts.assets)) firstGitOpts.assets.push(...assets);
|
|
100
|
+
else firstGitOpts.assets = assets;
|
|
101
|
+
}
|
|
102
|
+
if (typeof currentGitOpts.message === "string") firstGitOpts.message = currentGitOpts.message;
|
|
103
|
+
}
|
|
104
|
+
}).filter((pluginSpec) => pluginSpec !== void 0);
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { DefaultOptions, GitPluginId, setupGitPluginSpec };
|
|
108
|
+
|
|
2
109
|
//# sourceMappingURL=setupGitPluginSpec.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupGitPluginSpec.mjs","names":[],"sources":["../src/setupGitPluginSpec.ts"],"sourcesContent":["// @ts-types=\"./semantic-release__git.d.ts\"\nimport type { AssetEntry, Options as GitOptions } from '@semantic-release/git';\nimport type { PluginSpecSRGit, PluginSpecTuple } from './semanticReleaseConfig.ts';\nimport { DefaultOptions } from './setupGitPluginSpec.default.ts';\n\nexport const GitPluginId = '@semantic-release/git';\nexport { DefaultOptions } from './setupGitPluginSpec.default.ts';\n\n/**\n * Check if {@link unk} is an {@link AssetEntry}.\n * @param unk Anything.\n * @returns `true` if {@link unk} is an {@link AssetEntry}. Else, `false`.\n */\nfunction isGitAsset(unk: unknown): unk is AssetEntry {\n if (typeof unk === 'string')\n return true;\n // Avoid ending condition with `typeof unk.path === 'string'`.\n // TS narrowing is bugged; requires the check to be performed TWICE!!\n if (typeof unk === 'object' && unk != undefined && 'path' in unk) {\n return typeof unk.path === 'string';\n }\n return false;\n}\n\n/**\n * Convert one or more {@link AssetEntry AssetEntries} to a `string[]`.\n * @param assets The `assets` property of a {@link GitOptions} object. This may not be `false`.\n * @returns A `string[]` of the given {@link AssetEntry} objects or strings.\n */\nfunction gitAssetsToStringArray(\n assets: Exclude<GitOptions['assets'], false>,\n): string[] {\n if (assets === undefined)\n return [];\n if (Array.isArray(assets)) {\n return assets.filter(asset => isGitAsset(asset))\n .map(v => typeof v === 'string' ? v : v.path);\n }\n if (typeof assets === 'string')\n return [assets] as string[];\n if (typeof assets.path === 'string')\n return [assets.path];\n else\n throw new TypeError('assets is not typeof GitOptions[\\'assets\\'!');\n}\n\n/**\n * Sanitize a {@link GitOptions} object so its {@link GitOptions#assets} property is either `false` or a `string[]`.\n * @param opts A {@link GitOptions} object.\n * @returns A {@link GitOptions} object whose {@link GitOptions#assets} is `string[] | false`.\n */\nfunction sanitizeGitOptions(opts: GitOptions): Omit<GitOptions, 'assets'> & { assets: string[] | false } {\n return { ...opts, assets: opts.assets === false ? opts.assets : gitAssetsToStringArray(opts.assets) };\n}\n\n/**\n *Determine if {@link opts} is a {@link GitOptions} object.\n * @param opts Anything.\n * @returns `true` if {@link opts} is a {@link GitOptions} object. Else, `false`.\n */\nfunction isGitOptions(opts: unknown): opts is GitOptions {\n let isOptions = false;\n\n if (typeof opts !== 'object' || opts == undefined)\n return isOptions;\n if ('assets' in opts) {\n isOptions = Array.isArray(opts.assets)\n ? opts.assets.every(unk => isGitAsset(unk))\n : isGitAsset(opts.assets);\n }\n if ('message' in opts)\n isOptions = typeof opts.message === 'string';\n return isOptions;\n}\n\n/**\n * Determine if {@link pluginSpec} includes a {@link GitOptions} object.\n * @param pluginSpec a {@link PluginSpecTuple}.\n * @returns `true` if {@link pluginSpec[1]} is a {@link GitOptions} object. Else, `false`.\n */\nfunction hasGitOptions<P extends string>(pluginSpec: PluginSpecTuple<P>): pluginSpec is PluginSpecTuple<P, GitOptions> {\n return isGitOptions(pluginSpec[1]);\n};\n\n/**\n * Determined if the plugin ID in {@link pluginSpec} is {@link GitPluginId}.\n * @param pluginSpec A {@link PluginSpecTuple}\n * @returns `true` if {@link pluginSpec[0]} is {@link GitPluginId}\n */\nfunction isGitPluginSpecTuple<T>(pluginSpec: [string, T]): pluginSpec is [typeof GitPluginId, T] {\n return pluginSpec[0] === GitPluginId;\n}\n\n/**\n * https://github.com/semantic-release/git#options\n *\n * This plugin may be deprecated at a later date.\n * Q: Why would I need to commit during release?\n * A: This is for committing your changelog, README, and/or other files updated during the release procedure.\n * @param plugins An ordered array of {@link PluginSpecTuple PluginSpecTuples}.\n * @returns A {@link PluginSpecTuple}[]. Duplicate `@semantic-release/git` plugin entries are merged or overridden. The last entry takes priority e.g. if the last entry is `{assets: false}`, previous entries' assets are ignored.\n */\nexport function setupGitPluginSpec(plugins: PluginSpecTuple[]): PluginSpecTuple[] {\n /** if Git plugin not in load order, return as-is. */\n const firstGitPluginIndex = plugins.findIndex(plugin => isGitPluginSpecTuple(plugin));\n if (firstGitPluginIndex === -1)\n return plugins;\n\n /**\n * the following two const variables are references--not clones.\n * Modifying them will affect the plugins array.\n */\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const firstGitPlugin = plugins[firstGitPluginIndex]!;\n const firstGitOpts: ReturnType<typeof sanitizeGitOptions> = isGitOptions(firstGitPlugin[1])\n ? sanitizeGitOptions(firstGitPlugin[1])\n : DefaultOptions;\n\n /**\n * remove duplicate Git plugin entries;\n * merge extra options into firstGitPlugin's options\n * if `firstGitOpts.assets === false`, do not change it.\n * All duplicate PluginSpecSRGit entries are then reassigned `undefined` and all\n * `undefined` items are filtered from the plugins array.\n */\n return plugins.map((current: PluginSpecTuple, index): PluginSpecTuple | PluginSpecSRGit | undefined => {\n // skip everything up to and including the first Git PluginSpec\n if (index <= firstGitPluginIndex || !isGitPluginSpecTuple(current))\n return current;\n\n /** if another Git PluginSpec is discovered, copy its options to the first Git PluginSpec and return undefined. */\n if (hasGitOptions(current)) {\n const currentGitOpts = sanitizeGitOptions(current[1]);\n\n if (currentGitOpts.assets === false) {\n firstGitOpts.assets = false;\n }\n else {\n const assets: string[] = gitAssetsToStringArray(currentGitOpts.assets);\n if (Array.isArray(firstGitOpts.assets)) {\n firstGitOpts.assets.push(...assets);\n }\n else {\n firstGitOpts.assets = assets;\n }\n }\n\n if (typeof currentGitOpts.message === 'string')\n firstGitOpts.message = currentGitOpts.message;\n }\n return undefined;\n }).filter(pluginSpec => pluginSpec !== undefined);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"setupGitPluginSpec.mjs","names":[],"sources":["../src/setupGitPluginSpec.ts"],"sourcesContent":["// @ts-types=\"./semantic-release__git.d.ts\"\nimport type { AssetEntry, Options as GitOptions } from '@semantic-release/git';\nimport type { PluginSpecSRGit, PluginSpecTuple } from './semanticReleaseConfig.ts';\nimport { DefaultOptions } from './setupGitPluginSpec.default.ts';\n\nexport const GitPluginId = '@semantic-release/git';\nexport { DefaultOptions } from './setupGitPluginSpec.default.ts';\n\n/**\n * Check if {@link unk} is an {@link AssetEntry}.\n * @param unk Anything.\n * @returns `true` if {@link unk} is an {@link AssetEntry}. Else, `false`.\n */\nfunction isGitAsset(unk: unknown): unk is AssetEntry {\n if (typeof unk === 'string')\n return true;\n // Avoid ending condition with `typeof unk.path === 'string'`.\n // TS narrowing is bugged; requires the check to be performed TWICE!!\n if (typeof unk === 'object' && unk != undefined && 'path' in unk) {\n return typeof unk.path === 'string';\n }\n return false;\n}\n\n/**\n * Convert one or more {@link AssetEntry AssetEntries} to a `string[]`.\n * @param assets The `assets` property of a {@link GitOptions} object. This may not be `false`.\n * @returns A `string[]` of the given {@link AssetEntry} objects or strings.\n */\nfunction gitAssetsToStringArray(\n assets: Exclude<GitOptions['assets'], false>,\n): string[] {\n if (assets === undefined)\n return [];\n if (Array.isArray(assets)) {\n return assets.filter(asset => isGitAsset(asset))\n .map(v => typeof v === 'string' ? v : v.path);\n }\n if (typeof assets === 'string')\n return [assets] as string[];\n if (typeof assets.path === 'string')\n return [assets.path];\n else\n throw new TypeError('assets is not typeof GitOptions[\\'assets\\'!');\n}\n\n/**\n * Sanitize a {@link GitOptions} object so its {@link GitOptions#assets} property is either `false` or a `string[]`.\n * @param opts A {@link GitOptions} object.\n * @returns A {@link GitOptions} object whose {@link GitOptions#assets} is `string[] | false`.\n */\nfunction sanitizeGitOptions(opts: GitOptions): Omit<GitOptions, 'assets'> & { assets: string[] | false } {\n return { ...opts, assets: opts.assets === false ? opts.assets : gitAssetsToStringArray(opts.assets) };\n}\n\n/**\n *Determine if {@link opts} is a {@link GitOptions} object.\n * @param opts Anything.\n * @returns `true` if {@link opts} is a {@link GitOptions} object. Else, `false`.\n */\nfunction isGitOptions(opts: unknown): opts is GitOptions {\n let isOptions = false;\n\n if (typeof opts !== 'object' || opts == undefined)\n return isOptions;\n if ('assets' in opts) {\n isOptions = Array.isArray(opts.assets)\n ? opts.assets.every(unk => isGitAsset(unk))\n : isGitAsset(opts.assets);\n }\n if ('message' in opts)\n isOptions = typeof opts.message === 'string';\n return isOptions;\n}\n\n/**\n * Determine if {@link pluginSpec} includes a {@link GitOptions} object.\n * @param pluginSpec a {@link PluginSpecTuple}.\n * @returns `true` if {@link pluginSpec[1]} is a {@link GitOptions} object. Else, `false`.\n */\nfunction hasGitOptions<P extends string>(pluginSpec: PluginSpecTuple<P>): pluginSpec is PluginSpecTuple<P, GitOptions> {\n return isGitOptions(pluginSpec[1]);\n};\n\n/**\n * Determined if the plugin ID in {@link pluginSpec} is {@link GitPluginId}.\n * @param pluginSpec A {@link PluginSpecTuple}\n * @returns `true` if {@link pluginSpec[0]} is {@link GitPluginId}\n */\nfunction isGitPluginSpecTuple<T>(pluginSpec: [string, T]): pluginSpec is [typeof GitPluginId, T] {\n return pluginSpec[0] === GitPluginId;\n}\n\n/**\n * https://github.com/semantic-release/git#options\n *\n * This plugin may be deprecated at a later date.\n * Q: Why would I need to commit during release?\n * A: This is for committing your changelog, README, and/or other files updated during the release procedure.\n * @param plugins An ordered array of {@link PluginSpecTuple PluginSpecTuples}.\n * @returns A {@link PluginSpecTuple}[]. Duplicate `@semantic-release/git` plugin entries are merged or overridden. The last entry takes priority e.g. if the last entry is `{assets: false}`, previous entries' assets are ignored.\n */\nexport function setupGitPluginSpec(plugins: PluginSpecTuple[]): PluginSpecTuple[] {\n /** if Git plugin not in load order, return as-is. */\n const firstGitPluginIndex = plugins.findIndex(plugin => isGitPluginSpecTuple(plugin));\n if (firstGitPluginIndex === -1)\n return plugins;\n\n /**\n * the following two const variables are references--not clones.\n * Modifying them will affect the plugins array.\n */\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const firstGitPlugin = plugins[firstGitPluginIndex]!;\n const firstGitOpts: ReturnType<typeof sanitizeGitOptions> = isGitOptions(firstGitPlugin[1])\n ? sanitizeGitOptions(firstGitPlugin[1])\n : DefaultOptions;\n\n /**\n * remove duplicate Git plugin entries;\n * merge extra options into firstGitPlugin's options\n * if `firstGitOpts.assets === false`, do not change it.\n * All duplicate PluginSpecSRGit entries are then reassigned `undefined` and all\n * `undefined` items are filtered from the plugins array.\n */\n return plugins.map((current: PluginSpecTuple, index): PluginSpecTuple | PluginSpecSRGit | undefined => {\n // skip everything up to and including the first Git PluginSpec\n if (index <= firstGitPluginIndex || !isGitPluginSpecTuple(current))\n return current;\n\n /** if another Git PluginSpec is discovered, copy its options to the first Git PluginSpec and return undefined. */\n if (hasGitOptions(current)) {\n const currentGitOpts = sanitizeGitOptions(current[1]);\n\n if (currentGitOpts.assets === false) {\n firstGitOpts.assets = false;\n }\n else {\n const assets: string[] = gitAssetsToStringArray(currentGitOpts.assets);\n if (Array.isArray(firstGitOpts.assets)) {\n firstGitOpts.assets.push(...assets);\n }\n else {\n firstGitOpts.assets = assets;\n }\n }\n\n if (typeof currentGitOpts.message === 'string')\n firstGitOpts.message = currentGitOpts.message;\n }\n return undefined;\n }).filter(pluginSpec => pluginSpec !== undefined);\n}\n"],"mappings":";;AAKA,MAAa,cAAc;;;;;;AAQ3B,SAAS,WAAW,KAAiC;AACnD,KAAI,OAAO,QAAQ,SACjB,QAAO;AAGT,KAAI,OAAO,QAAQ,YAAY,OAAO,KAAA,KAAa,UAAU,IAC3D,QAAO,OAAO,IAAI,SAAS;AAE7B,QAAO;;;;;;;AAQT,SAAS,uBACP,QACU;AACV,KAAI,WAAW,KAAA,EACb,QAAO,EAAE;AACX,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,QAAO,UAAS,WAAW,MAAM,CAAC,CAC7C,KAAI,MAAK,OAAO,MAAM,WAAW,IAAI,EAAE,KAAK;AAEjD,KAAI,OAAO,WAAW,SACpB,QAAO,CAAC,OAAO;AACjB,KAAI,OAAO,OAAO,SAAS,SACzB,QAAO,CAAC,OAAO,KAAK;KAEpB,OAAM,IAAI,UAAU,4CAA8C;;;;;;;AAQtE,SAAS,mBAAmB,MAA6E;AACvG,QAAO;EAAE,GAAG;EAAM,QAAQ,KAAK,WAAW,QAAQ,KAAK,SAAS,uBAAuB,KAAK,OAAO;EAAE;;;;;;;AAQvG,SAAS,aAAa,MAAmC;CACvD,IAAI,YAAY;AAEhB,KAAI,OAAO,SAAS,YAAY,QAAQ,KAAA,EACtC,QAAO;AACT,KAAI,YAAY,KACd,aAAY,MAAM,QAAQ,KAAK,OAAO,GAClC,KAAK,OAAO,OAAM,QAAO,WAAW,IAAI,CAAC,GACzC,WAAW,KAAK,OAAO;AAE7B,KAAI,aAAa,KACf,aAAY,OAAO,KAAK,YAAY;AACtC,QAAO;;;;;;;AAQT,SAAS,cAAgC,YAA8E;AACrH,QAAO,aAAa,WAAW,GAAG;;;;;;;AAQpC,SAAS,qBAAwB,YAAgE;AAC/F,QAAO,WAAW,OAAO;;;;;;;;;;;AAY3B,SAAgB,mBAAmB,SAA+C;;CAEhF,MAAM,sBAAsB,QAAQ,WAAU,WAAU,qBAAqB,OAAO,CAAC;AACrF,KAAI,wBAAwB,GAC1B,QAAO;;;;;CAOT,MAAM,iBAAiB,QAAQ;CAC/B,MAAM,eAAsD,aAAa,eAAe,GAAG,GACvF,mBAAmB,eAAe,GAAG,GACrC;;;;;;;;AASJ,QAAO,QAAQ,KAAK,SAA0B,UAAyD;AAErG,MAAI,SAAS,uBAAuB,CAAC,qBAAqB,QAAQ,CAChE,QAAO;;AAGT,MAAI,cAAc,QAAQ,EAAE;GAC1B,MAAM,iBAAiB,mBAAmB,QAAQ,GAAG;AAErD,OAAI,eAAe,WAAW,MAC5B,cAAa,SAAS;QAEnB;IACH,MAAM,SAAmB,uBAAuB,eAAe,OAAO;AACtE,QAAI,MAAM,QAAQ,aAAa,OAAO,CACpC,cAAa,OAAO,KAAK,GAAG,OAAO;QAGnC,cAAa,SAAS;;AAI1B,OAAI,OAAO,eAAe,YAAY,SACpC,cAAa,UAAU,eAAe;;GAG1C,CAAC,QAAO,eAAc,eAAe,KAAA,EAAU"}
|
package/mjs/utils/Exact.d.mts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
//#region src/utils/Exact.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* ### `Exact<T, S>`
|
|
4
|
-
*
|
|
5
|
-
* [issue](https://github.com/microsoft/TypeScript/issues/12936#issuecomment-2816928183)\
|
|
6
|
-
* [author](https://github.com/ahrjarrett)\
|
|
7
|
-
* license: unlicensed[!]
|
|
8
|
-
* @see
|
|
9
|
-
* - {@link https://tsplay.dev/NnGG6m}
|
|
10
|
-
*/
|
|
3
|
+
* ### `Exact<T, S>`
|
|
4
|
+
*
|
|
5
|
+
* [issue](https://github.com/microsoft/TypeScript/issues/12936#issuecomment-2816928183)\
|
|
6
|
+
* [author](https://github.com/ahrjarrett)\
|
|
7
|
+
* license: unlicensed[!]
|
|
8
|
+
* @see
|
|
9
|
+
* - {@link https://tsplay.dev/NnGG6m}
|
|
10
|
+
*/
|
|
11
11
|
type Exact<T, S> = [keyof T] extends [keyof S] ? [T] extends [S] ? { [K in keyof T]: T[K] } : S : { [K in keyof T as K extends keyof S ? never : K]: TypeError<`Excess: '${Coerce<K>}'`> };
|
|
12
12
|
interface TypeError<Message> {
|
|
13
|
-
[
|
|
14
|
-
}
|
|
13
|
+
[' TypeError']: Message;
|
|
14
|
+
} // prior art: use arktype's ^^^ leading whitespace trick to avoid collisions
|
|
15
15
|
type Coerce<T> = `${T & (string | number)}`;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { Exact };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Exact.d.mts","names":[],"sources":["../../src/utils/Exact.ts"],"mappings":";;AASA;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Exact.d.mts","names":["Exact","T","S","K","Coerce","TypeError","Message"],"sources":["../../src/utils/Exact.d.ts"],"mappings":";;AASA;;;;;;;;KAAYA,KAAAA,gBAAqBC,CAAAA,iBAAkBC,CAAAA,KAC9CD,CAAAA,WAAYC,CAAAA,kBAAmBD,CAAAA,GAAIA,CAAAA,CAAEE,CAAAA,MAAOD,CAAAA,iBAC/BD,CAAAA,IAAKE,CAAAA,eAAgBD,CAAAA,WAAYC,CAAAA,GAAIE,SAAAA,aAAsBD,MAAAA,CAAOD,CAAAA;AAAAA,UAE1EE,SAAAA;EAAAA,CAAsB,YAAA,GAAeC,OAAAA;AAAAA;AAAAA,KAG1CF,MAAAA,SAAeH,CAAAA"}
|