@halospv3/hce.shared-config 2.6.4 → 3.0.0-develop.2

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +356 -101
  2. package/README.md +100 -87
  3. package/dotnet/.github/workflows/_unit_test.yml +6 -3
  4. package/dotnet/.github/workflows/ci.yml +2 -2
  5. package/dotnet/.github/workflows/dotnet-release.yml +31 -28
  6. package/dotnet/.github/workflows/sample-dotnet-build.yml +16 -11
  7. package/dotnet/ExecNupkgDeterministicator.README.md +20 -0
  8. package/dotnet/ExecNupkgDeterministicator.targets +173 -0
  9. package/dotnet/GitVersion.yml +3 -1
  10. package/dotnet/GitVersion6.0.yml +3 -1
  11. package/dotnet/HCE.Shared.sln +34 -0
  12. package/dotnet/HCE.Shared.targets +1 -0
  13. package/dotnet/PublishAll.targets +2 -0
  14. package/dotnet/SignAfterPack.targets +104 -0
  15. package/dotnet/samples/HCE.Shared.DeterministicNupkg/Dummy.cs +6 -0
  16. package/dotnet/samples/HCE.Shared.DeterministicNupkg/HCE.Shared.DeterministicNupkg.csproj +21 -0
  17. package/dotnet/samples/HCE.Shared.SignAfterPack/Class1.cs +6 -0
  18. package/dotnet/samples/HCE.Shared.SignAfterPack/HCE.Shared.SignAfterPack.csproj +21 -0
  19. package/dotnet/samples/HCE.Shared.SignAfterPack/sampleCert.samplepfx +0 -0
  20. package/dotnet/samples/README.md +7 -0
  21. package/package.json +72 -73
  22. package/src/CaseInsensitiveMap.ts +34 -0
  23. package/src/commitlintConfig.ts +17 -9
  24. package/src/debug.ts +3 -3
  25. package/src/dotnet/GithubNugetRegistryInfo.ts +60 -0
  26. package/src/dotnet/GitlabNugetRegistryInfo.ts +112 -0
  27. package/src/dotnet/IsNextVersionAlreadyPublished.cli.ts +44 -0
  28. package/src/dotnet/MSBuildProject.ts +557 -76
  29. package/src/dotnet/MSBuildProjectProperties.ts +280 -15
  30. package/src/dotnet/NugetProjectProperties.ts +608 -0
  31. package/src/dotnet/NugetRegistryInfo.ts +939 -0
  32. package/src/dotnet/helpers.ts +448 -0
  33. package/src/eslintConfig.ts +174 -71
  34. package/src/index.ts +1 -3
  35. package/src/semantic-release__commit-analyzer.d.ts +44 -38
  36. package/src/semantic-release__exec.d.ts +15 -0
  37. package/src/semantic-release__git.d.ts +85 -88
  38. package/src/semantic-release__github.d.ts +139 -139
  39. package/src/semanticReleaseConfig.ts +106 -47
  40. package/src/semanticReleaseConfigDotnet.ts +394 -104
  41. package/src/setupGitPluginSpec.ts +149 -57
  42. package/src/tsconfig.json +8 -8
  43. package/src/utils/Exact.ts +49 -0
  44. package/src/utils/GracefulRecursion.d.ts +12 -0
  45. package/src/utils/env.ts +44 -0
  46. package/src/utils/execAsync.ts +77 -0
  47. package/src/utils/miscTypes.ts +17 -0
  48. package/src/utils/reflection/FunctionLike.d.ts +17 -0
  49. package/src/utils/reflection/GetterDescriptor.d.ts +8 -0
  50. package/src/utils/reflection/InstancePropertyDescriptorMap.d.ts +32 -0
  51. package/src/utils/reflection/InstanceTypeOrSelfPropertyDescriptorMap.d.ts +20 -0
  52. package/src/utils/reflection/OwnGetterDescriptorMap.d.ts +17 -0
  53. package/src/utils/reflection/OwnKeyOf.d.ts +20 -0
  54. package/src/utils/reflection/OwnPropertyDescriptorMap.d.ts +82 -0
  55. package/src/utils/reflection/PropertyDescriptorMap.d.ts +15 -0
  56. package/src/utils/reflection/filterForGetters.ts +59 -0
  57. package/src/utils/reflection/getOwnPropertyDescriptors.ts +52 -0
  58. package/src/utils/reflection/getOwnPropertyDescriptorsRecursively.ts +127 -0
  59. package/src/utils/reflection/getPrototypeChainOf.ts +85 -0
  60. package/src/utils/reflection/getPrototypeOf.ts +12 -0
  61. package/src/utils/reflection/inheritance.ts +262 -0
  62. package/src/utils/reflection/isConstructor.ts +74 -0
  63. package/src/utils/reflection/isGetterDescriptor.ts +11 -0
  64. package/src/utils/reflection/listOwnGetters.ts +80 -0
  65. package/src/utils/reflection.ts +18 -0
  66. package/cjs/commitlintConfig-wrapper.mjs +0 -6
  67. package/cjs/commitlintConfig.cjs +0 -14
  68. package/cjs/commitlintConfig.cjs.map +0 -1
  69. package/cjs/commitlintConfig.d.ts +0 -4
  70. package/cjs/commitlintConfig.d.ts.map +0 -1
  71. package/cjs/debug.cjs +0 -13
  72. package/cjs/debug.cjs.map +0 -1
  73. package/cjs/debug.d.ts +0 -4
  74. package/cjs/debug.d.ts.map +0 -1
  75. package/cjs/dotnet/MSBuildProject.cjs +0 -84
  76. package/cjs/dotnet/MSBuildProject.cjs.map +0 -1
  77. package/cjs/dotnet/MSBuildProject.d.ts +0 -42
  78. package/cjs/dotnet/MSBuildProject.d.ts.map +0 -1
  79. package/cjs/dotnet/MSBuildProjectProperties.cjs +0 -22
  80. package/cjs/dotnet/MSBuildProjectProperties.cjs.map +0 -1
  81. package/cjs/dotnet/MSBuildProjectProperties.d.ts +0 -13
  82. package/cjs/dotnet/MSBuildProjectProperties.d.ts.map +0 -1
  83. package/cjs/dotnet/createDummyNupkg.cjs +0 -26
  84. package/cjs/dotnet/createDummyNupkg.cjs.map +0 -1
  85. package/cjs/dotnet/createDummyNupkg.d.ts +0 -2
  86. package/cjs/dotnet/createDummyNupkg.d.ts.map +0 -1
  87. package/cjs/dotnet/dotnetGHPR.cjs +0 -173
  88. package/cjs/dotnet/dotnetGHPR.cjs.map +0 -1
  89. package/cjs/dotnet/dotnetGHPR.d.ts +0 -37
  90. package/cjs/dotnet/dotnetGHPR.d.ts.map +0 -1
  91. package/cjs/dotnet/dotnetGLPR.cjs +0 -41
  92. package/cjs/dotnet/dotnetGLPR.cjs.map +0 -1
  93. package/cjs/dotnet/dotnetGLPR.d.ts +0 -13
  94. package/cjs/dotnet/dotnetGLPR.d.ts.map +0 -1
  95. package/cjs/dotnet/dotnetHelpers.cjs +0 -141
  96. package/cjs/dotnet/dotnetHelpers.cjs.map +0 -1
  97. package/cjs/dotnet/dotnetHelpers.d.ts +0 -26
  98. package/cjs/dotnet/dotnetHelpers.d.ts.map +0 -1
  99. package/cjs/dotnet-wrapper.mjs +0 -6
  100. package/cjs/dotnet.cjs +0 -15
  101. package/cjs/dotnet.cjs.map +0 -1
  102. package/cjs/dotnet.d.ts +0 -7
  103. package/cjs/dotnet.d.ts.map +0 -1
  104. package/cjs/envUtils-wrapper.mjs +0 -6
  105. package/cjs/envUtils.cjs +0 -37
  106. package/cjs/envUtils.cjs.map +0 -1
  107. package/cjs/envUtils.d.ts +0 -15
  108. package/cjs/envUtils.d.ts.map +0 -1
  109. package/cjs/eslintConfig-wrapper.mjs +0 -6
  110. package/cjs/eslintConfig.cjs +0 -52
  111. package/cjs/eslintConfig.cjs.map +0 -1
  112. package/cjs/eslintConfig.d.ts +0 -3
  113. package/cjs/eslintConfig.d.ts.map +0 -1
  114. package/cjs/findStaticConfig-wrapper.mjs +0 -6
  115. package/cjs/findStaticConfig.cjs +0 -34
  116. package/cjs/findStaticConfig.cjs.map +0 -1
  117. package/cjs/findStaticConfig.d.ts +0 -2
  118. package/cjs/findStaticConfig.d.ts.map +0 -1
  119. package/cjs/index-wrapper.mjs +0 -6
  120. package/cjs/index.cjs +0 -10
  121. package/cjs/index.cjs.map +0 -1
  122. package/cjs/index.d.ts +0 -5
  123. package/cjs/index.d.ts.map +0 -1
  124. package/cjs/semantic-release__commit-analyzer.d.cjs +0 -2
  125. package/cjs/semantic-release__commit-analyzer.d.cjs.map +0 -1
  126. package/cjs/semantic-release__git.d.cjs +0 -2
  127. package/cjs/semantic-release__git.d.cjs.map +0 -1
  128. package/cjs/semantic-release__github.d.cjs +0 -2
  129. package/cjs/semantic-release__github.d.cjs.map +0 -1
  130. package/cjs/semanticReleaseConfig-wrapper.mjs +0 -6
  131. package/cjs/semanticReleaseConfig.cjs +0 -33
  132. package/cjs/semanticReleaseConfig.cjs.map +0 -1
  133. package/cjs/semanticReleaseConfig.d.ts +0 -4
  134. package/cjs/semanticReleaseConfig.d.ts.map +0 -1
  135. package/cjs/semanticReleaseConfigDotnet-wrapper.mjs +0 -7
  136. package/cjs/semanticReleaseConfigDotnet.cjs +0 -112
  137. package/cjs/semanticReleaseConfigDotnet.cjs.map +0 -1
  138. package/cjs/semanticReleaseConfigDotnet.d.ts +0 -51
  139. package/cjs/semanticReleaseConfigDotnet.d.ts.map +0 -1
  140. package/cjs/setupGitPluginSpec-wrapper.mjs +0 -6
  141. package/cjs/setupGitPluginSpec.cjs +0 -67
  142. package/cjs/setupGitPluginSpec.cjs.map +0 -1
  143. package/cjs/setupGitPluginSpec.d.ts +0 -19
  144. package/cjs/setupGitPluginSpec.d.ts.map +0 -1
  145. package/src/dotnet/createDummyNupkg.ts +0 -30
  146. package/src/dotnet/dotnetGHPR.ts +0 -232
  147. package/src/dotnet/dotnetGLPR.ts +0 -46
  148. package/src/dotnet/dotnetHelpers.ts +0 -184
  149. package/src/dotnet.ts +0 -6
  150. package/src/envUtils.ts +0 -36
  151. package/src/findStaticConfig.ts +0 -31
  152. package/static/.releaserc.yml +0 -35
@@ -1,10 +1,10 @@
1
- /** Semantic-Release Config Factory (dotnet)
1
+ /**
2
+ * # Semantic-Release Config Factory (dotnet)
2
3
  * A functional Semantic-Release configuration for dotnet projects
3
4
  *
4
5
  * extends {@link baseConfig }
5
6
  *
6
7
  * <-- TABLE OF CONTENTS -->
7
- * - evaluateProperties
8
8
  * - configureDotnetRelease
9
9
  * - Insert-Edit Plugins
10
10
  * - Append Plugins
@@ -12,119 +12,409 @@
12
12
  */
13
13
 
14
14
  import { inspect } from 'node:util';
15
- import type { Options, PluginSpec } from 'semantic-release';
15
+ import type { Options } from 'semantic-release';
16
+ import type { Options as SRExecOptions } from '@semantic-release/exec';
16
17
  import debug from './debug.js';
17
- import { configureDotnetNugetPush, configurePrepareCmd } from './dotnet/dotnetHelpers.js';
18
- import { getEnvVarValue } from './envUtils.js';
19
- import { baseConfig, defaultPlugins } from './semanticReleaseConfig.js';
20
- import { setupGitPluginSpec } from './setupGitPluginSpec.js';
18
+ import { configureDotnetNugetPush, configurePrepareCmd } from './dotnet/helpers.js';
19
+ import { getEnvVarValue } from './utils/env.js';
20
+ import { baseConfig } from './semanticReleaseConfig.js';
21
+ import { NugetRegistryInfo } from './dotnet/NugetRegistryInfo.js';
22
+ import { MSBuildProject } from './dotnet/MSBuildProject.js';
23
+ import { NPPGetterNames } from './dotnet/NugetProjectProperties.js';
24
+
25
+ type UnArray<T> = T extends (infer U)[] ? U : T;
26
+ interface SRConfigDotnetOptions extends Omit<typeof baseConfig, 'plugins'> {
27
+ plugins: (UnArray<typeof baseConfig.plugins> | [string, unknown])[];
28
+ }
21
29
 
22
30
  /**
23
- * TODO: options/params for inserts/edits. NOT ready for production. Currently, this can only add Git plugin's options if undefined or one or more is missing.
24
- * Insert (`array.splice`) and/or configure plugins.\
25
- * Can be used to...\
26
- * ...load plugin A before plugin B\
27
- * ...edit a plugin's existing configuration
28
- *
29
- * @param config An instance of {@link Options}
30
- * @returns a modified copy of {@link config}
31
31
  */
32
- export function insertAndEditPlugins(config: Options): Options {
33
- // const insertAndEditCommands = [];
34
- config.plugins = [...(config.plugins ?? defaultPlugins)];
32
+ export class SemanticReleaseConfigDotnet {
33
+ private readonly options: SRConfigDotnetOptions;
34
+ private readonly _projectsToPublish: string[] | MSBuildProject[];
35
+ private _projectsToPackAndPush: string[] | NugetRegistryInfo[];
36
+ private readonly _evaluatedProjects: MSBuildProject[];
35
37
 
36
- config.plugins = setupGitPluginSpec(config.plugins as PluginSpec[]);
38
+ /**
39
+ * Creates an instance of SemanticReleaseConfigDotnet.
40
+ * Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet` publish, pack, and push.
41
+ *
42
+ * Note: To sign packages, create a Target in the corresponding project(s) e.g.
43
+ * ```xml
44
+ * <Target Name="SignNupkgs" AfterTargets="Pack">
45
+ * <Exec Command="dotnet nuget sign $(PackageOutputPath) [remaining args]" ConsoleToMsBuild="true" />
46
+ * </Target>
47
+ * ```
48
+ * Alternatively, splice your signing commands into the publishCmd string,
49
+ * inserting them before `dotnet nuget push`.
50
+ * If you sign different signatures depending on the NuGet registry,
51
+ * splice your signing command (with "overwrite signature" enabled, if
52
+ * desired) before the corresponding registry's `dotnet nuget push` command.
53
+ * @param projectsToPublish An array of dotnet projects' relative paths. If
54
+ * empty or unspecified, tries getting projects' semi-colon-separated relative
55
+ * paths from the `PROJECTS_TO_PUBLISH` environment variable. If configured as
56
+ * recommended, the projects' publish outputs will be zipped to '$PWD/publish'
57
+ * for use in the `publish` semantic-release step (typically, GitHub release).
58
+ * @param projectsToPackAndPush An array of dotnet projects' relative paths.
59
+ * If empty or unspecified, tries getting projects' semi-colon-separated
60
+ * relative paths from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.
61
+ * Otherwise, no packages will be packed and pushed.
62
+ * If configured as recommended, `dotnet pack` will output the nupkg/snupkg
63
+ * files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.
64
+ */
65
+ constructor(
66
+ projectsToPublish: string[] | MSBuildProject[],
67
+ projectsToPackAndPush: string[] | NugetRegistryInfo[],
68
+ ) {
69
+ this.options = baseConfig;
70
+ /* normalize PluginSpecs to tuples */
71
+ this.options.plugins = this.options.plugins.map(pluginSpec => typeof pluginSpec === 'string'
72
+ ? [pluginSpec, {}]
73
+ : pluginSpec,
74
+ );
37
75
 
38
- return config;
39
- }
76
+ this._projectsToPublish = projectsToPublish;
77
+ if (this._projectsToPublish.length === 0) {
78
+ const p = getEnvVarValue('PROJECTS_TO_PUBLISH')?.split(';');
79
+ if (p && p.length > 0) {
80
+ this._projectsToPublish = p;
81
+ }
82
+ else if (debug.enabled) {
83
+ debug.log(new Error('At least one project must be published. `projectsToPackAndPush` is empty and environment variable `PROJECTS_TO_PUBLISH` is undefined or empty.'));
84
+ }
85
+ }
40
86
 
41
- /**
42
- * Currently, only configures `@semantic-release/exec` with `prepareCmd: configurePrepareCmd(projectsToPublish, projectsToPackAndPush)` and `publishCmd: configureDotnetNugetPush()`
43
- * @param config
44
- * @param projectsToPublish
45
- * @param projectsToPackAndPush
46
- * @returns config with the specified plugins and plugin options.
47
- */
48
- export function appendPlugins(
49
- config: Options,
50
- projectsToPublish: string[],
51
- projectsToPackAndPush: string[] | false,
52
- ): Options {
53
- if (config.plugins === undefined)
54
- throw new Error('Plugins array was undefined when it should be an array!');
55
- (config.plugins as PluginSpec[]).push(
56
- // APPEND this array of [pluginName, pluginConfig] to plugins
57
- // https://github.com/semantic-release/exec#usage
58
- [
59
- '@semantic-release/exec',
60
- {
61
- // 'ZipPublishDir' zips each publish folder to ./publish/*.zip
62
- prepareCmd: configurePrepareCmd(projectsToPublish, projectsToPackAndPush),
63
- publishCmd: configureDotnetNugetPush(),
64
- },
65
- ],
66
- );
67
- return config;
87
+ this._projectsToPackAndPush = projectsToPackAndPush;
88
+ if (this._projectsToPackAndPush.length === 0) {
89
+ const p = getEnvVarValue('PROJECTS_TO_PACK_AND_PUSH')?.split(';');
90
+ if (p && p.length > 0) {
91
+ this._projectsToPackAndPush = p;
92
+ }
93
+ else if (debug.enabled) {
94
+ debug.log(new Error('projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path.'));
95
+ }
96
+ }
97
+
98
+ // may be zero-length array
99
+ this._evaluatedProjects = [
100
+ ...this._projectsToPublish.filter(v => v instanceof MSBuildProject),
101
+ ...this._projectsToPackAndPush
102
+ .filter(v => v instanceof NugetRegistryInfo)
103
+ .map(v => v.project),
104
+ ];
105
+ }
106
+
107
+ get ProjectsToPublish(): string[] | MSBuildProject[] {
108
+ return this._projectsToPublish;
109
+ }
110
+
111
+ get ProjectsToPackAndPush(): string[] | NugetRegistryInfo[] {
112
+ return this._projectsToPackAndPush;
113
+ }
114
+
115
+ get EvaluatedProjects(): MSBuildProject[] {
116
+ return this._evaluatedProjects;
117
+ }
118
+
119
+ insertPlugin(
120
+ afterPluginsIDs: string[],
121
+ insertPluginIDs: string[],
122
+ beforePluginsIDs: string[],
123
+ ) {
124
+ const pluginIDs = this.options.plugins.map(v =>
125
+ typeof v === 'string' ? v : v[0],
126
+ );
127
+
128
+ // if any beforePluginIDs are ordered before the last afterPlugin, throw. Impossible to sort.
129
+
130
+ const indexOfLastAfter = afterPluginsIDs
131
+ .filter(v => pluginIDs.includes(v))
132
+ .map(v => pluginIDs.indexOf(v))
133
+ .sort()
134
+ .find((_v, i, obj) => i === obj.length - 1);
135
+ if (!indexOfLastAfter)
136
+ throw new ReferenceError(
137
+ 'An attempt to get the last element of an array returned undefined.',
138
+ );
139
+
140
+ const indicesOfBefore = beforePluginsIDs
141
+ .filter(v => pluginIDs.includes(v))
142
+ .map(v => pluginIDs.indexOf(v))
143
+ .sort();
144
+
145
+ // This for-of collects *all* sorting errors. The resulting AggregateError
146
+ // notifies the API user of *all* errors in the order rather than just the
147
+ // first error encountered.
148
+ const errors: Error[] = [];
149
+ for (const index of indicesOfBefore) {
150
+ if (index <= indexOfLastAfter) {
151
+ errors.push(
152
+ new Error(
153
+ `insertPlugin was instructed to insert one or more plugins after [${afterPluginsIDs.map(v => '"' + v + '"').join(', ')}] and before [${beforePluginsIDs.map(v => `"${v}"`).join(', ')}], but ${JSON.stringify(pluginIDs[indexOfLastAfter])} comes after ${JSON.stringify(pluginIDs[index])}!`,
154
+ ),
155
+ );
156
+ }
157
+ }
158
+ if (errors.length > 0)
159
+ throw new AggregateError(errors, 'One or more errors occurred while inserting plugin configs into the Semantic Release config!');
160
+
161
+ // insert plugin(s)
162
+ this.options.plugins.splice(
163
+ indexOfLastAfter + 1,
164
+ 0,
165
+ ...insertPluginIDs.map(id =>
166
+ [id, {}] as [string, unknown],
167
+ ),
168
+ );
169
+ }
170
+
171
+ /**
172
+ * generate dotnet commands for \@semantic-release/exec, appending commands with ' && ' when necessary.
173
+ * ?todo: change to builder method? e.g. static async SetupDotnetCommands(this: SemanticReleaseConfigDotnet): Promise<SemanticReleaseConfigDotnet>
174
+ * @async
175
+ * @see https://github.com/semantic-release/exec#usage
176
+ */
177
+ async setupDotnetCommands(): Promise<void> {
178
+ const srExecIndex = this.options.plugins.findIndex(
179
+ v => v[0] === '@semantic-release/exec',
180
+ );
181
+ const execOptions = this.options.plugins[srExecIndex] as SRExecOptions;
182
+
183
+ // TODO: move configurePrepareCmd into SemanticReleaseConfigDotnet
184
+ // ensure all packable projects are evaluated
185
+ this._projectsToPackAndPush = await Promise.all(
186
+ this.ProjectsToPackAndPush.map(async (v) => {
187
+ if (typeof v === 'string') {
188
+ const msbp = await MSBuildProject.Evaluate({
189
+ FullName: v,
190
+ GetItem: [],
191
+ GetProperty: [
192
+ ...MSBuildProject.MatrixProperties,
193
+ ...NPPGetterNames.InstanceGettersRecursive,
194
+ ],
195
+ GetTargetResult: [],
196
+ Property: {},
197
+ Targets: ['Restore', 'Pack'],
198
+ });
199
+
200
+ this._evaluatedProjects.push(msbp);
201
+
202
+ return new NugetRegistryInfo({ project: msbp });
203
+ }
204
+ else return v;
205
+ }),
206
+ );
207
+ // todo: double-check token-testing commands. Are they formatted prepended correctly?
208
+ const prepareCmdAppendix = await configurePrepareCmd(
209
+ this._projectsToPublish,
210
+ this._projectsToPackAndPush,
211
+ );
212
+
213
+ // 'ZipPublishDir' zips each publish folder to ./publish/*.zip
214
+ execOptions.prepareCmd
215
+ = execOptions.prepareCmd !== undefined && execOptions.prepareCmd.length > 0
216
+ ? `${execOptions.prepareCmd} && ${prepareCmdAppendix}`
217
+ : prepareCmdAppendix;
218
+
219
+ // FINISHED execOptions.prepareCmd
220
+ // STARTING execOptions.publishCmd
221
+ if (this._projectsToPackAndPush.length > 0) {
222
+ const publishCmdAppendix: string = configureDotnetNugetPush(
223
+ this._projectsToPackAndPush,
224
+ );
225
+ execOptions.publishCmd
226
+ = execOptions.publishCmd && execOptions.publishCmd.length > 0
227
+ ? `${execOptions.publishCmd} && ${publishCmdAppendix}`
228
+ : publishCmdAppendix;
229
+ }
230
+
231
+ // FINISHED execOptions.publishCmd
232
+ }
233
+
234
+ /**
235
+ * Insert a plugin into the plugins array.
236
+ * @deprecated EXPERIMENTAL: needs thorough tests implemented before use in production!
237
+ * @param insertAfterPluginIDs Plugins which should appear BEFORE
238
+ * {@link insertPluginIDs}.
239
+ * @param insertPluginIDs The plugin(s) to insert into the plugins array.
240
+ * @param insertBeforePluginsIDs plugins which should appear AFTER the
241
+ * inserted plugin(s).
242
+ */
243
+ splicePlugin(
244
+ insertAfterPluginIDs: string[],
245
+ insertPluginIDs: string[],
246
+ insertBeforePluginsIDs: string[],
247
+ ): void {
248
+ const errors: Error[] = [];
249
+ const pluginIDs = this.options.plugins.map(v =>
250
+ typeof v === 'string' ? v : v[0],
251
+ ) as (typeof this.options.plugins[number])[][0];
252
+
253
+ // if any beforePluginIDs are ordered before the last afterPlugin, throw. Impossible to sort.
254
+
255
+ const indexOfLastPreceding: number | undefined = insertAfterPluginIDs
256
+ .filter(v => pluginIDs.includes(v))
257
+ .map(v => pluginIDs.indexOf(v))
258
+ .sort()
259
+ .find((_v, i, obj) => i === obj.length - 1);
260
+ if (!indexOfLastPreceding)
261
+ throw new ReferenceError(
262
+ 'An attempt to get the last element of indexOfLastAfter returned undefined.',
263
+ );
264
+
265
+ const indicesOfBefore: number[] = insertBeforePluginsIDs
266
+ .filter(v => pluginIDs.includes(v))
267
+ .map(v => pluginIDs.indexOf(v))
268
+ .sort();
269
+
270
+ for (const index of indicesOfBefore) {
271
+ if (index <= indexOfLastPreceding) {
272
+ const formattedInsertIds: string
273
+ = '[' + insertPluginIDs.map(v => `"${v}"`).join(', ') + ']';
274
+ const formattedAfterIds: string
275
+ = '[' + insertAfterPluginIDs.map(v => `"${v}"`).join(', ') + ']';
276
+ const formattedBeforeIds: string
277
+ = '[' + insertBeforePluginsIDs.map(v => `"${v}"`).join(', ') + ']';
278
+ errors.push(
279
+ new Error(
280
+ `insertPlugin was instructed to insert ${formattedInsertIds} after ${formattedAfterIds} and before ${formattedBeforeIds}, `
281
+ + `but ${JSON.stringify(pluginIDs[indexOfLastPreceding])} is ordered after ${JSON.stringify(pluginIDs[index])}!`,
282
+ ),
283
+ );
284
+ }
285
+ }
286
+
287
+ if (errors.length > 0)
288
+ throw new AggregateError(errors, 'One or more errors occurred while splicing plugin-option tuples into the Semantic Release config!');
289
+
290
+ this.options.plugins.splice(
291
+ indexOfLastPreceding + 1,
292
+ 0,
293
+ ...insertPluginIDs.map(v => [v, {}] satisfies [string, unknown]),
294
+ );
295
+ }
296
+
297
+ // todo: join result with dummy pack commands
298
+ protected async getTokenTestingCommands(): Promise<string> {
299
+ const promiseProjects = this.ProjectsToPackAndPush.every(nri => nri instanceof NugetRegistryInfo)
300
+ ? this.ProjectsToPackAndPush.map(nri => nri.project)
301
+ : await Promise.all(await MSBuildProject.PackableProjectsToMSBuildProjects(this.ProjectsToPackAndPush));
302
+
303
+ /** if a project is not in {@link EvaluatedProjects}, add it */
304
+ for (const project of promiseProjects) {
305
+ if (!this.EvaluatedProjects.includes(project))
306
+ this.EvaluatedProjects.push(project);
307
+ }
308
+
309
+ const regInfos = promiseProjects.map(
310
+ p => new NugetRegistryInfo({ project: p }),
311
+ );
312
+ const nupkgPaths = await Promise.all(
313
+ regInfos.map(async nri =>
314
+ nri.PackDummyPackage({}).then((nupkgs) => {
315
+ // this is a full file path.
316
+ const mainNupkg = nupkgs.find(nupkg =>
317
+ new RegExp(/(?<!symbols)\.nupkg$/).test(nupkg),
318
+ );
319
+ if (mainNupkg !== undefined)
320
+ return { nri: nri, nupkgPath: mainNupkg } as const;
321
+ throw new Error(
322
+ 'None of the following dummy packages are non-symbol .nupkg files:\n'
323
+ + nupkgs.map(nupkg => ` - ${nupkg}`).join('\n')
324
+ + '\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".',
325
+ );
326
+ }),
327
+ ),
328
+ );
329
+ const pushCommands = nupkgPaths.map(pair =>
330
+ pair.nri.GetPushDummyCommand({}),
331
+ );
332
+ return pushCommands.join(' && ');
333
+ }
334
+
335
+ toOptions(): Options {
336
+ return this.options;
337
+ }
68
338
  }
69
339
 
70
340
  /**
71
341
  * Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet` publish, pack, and push.
72
- * @param projectsToPublish An array of dotnet projects' relative paths. If
73
- * empty or unspecified, tries getting projects' semi-colon-separated relative
74
- * paths from the `PROJECTS_TO_PUBLISH` environment variable. If configured as
75
- * recommended, the projects' publish outputs will be zipped to '$PWD/publish'
76
- * for use in the `publish` semantic-release step (typically, GitHub release).
77
- * @param projectsToPackAndPush An array of dotnet projects' relative paths. If
78
- * false, `dotnet pack` and `dotnet nuget push` will be left out of the exec
79
- * commands. If empty or unspecified, tries getting projects'
80
- * semi-colon-separated relative paths from the `PROJECTS_TO_PACK_AND_PUSH`
81
- * environment variable. If configured as recommended, `dotnet pack` will output
82
- * the nupkg/snupk files to `$PWD/publish` where they will be globbed by `dotnet
83
- * nuget push`.
84
- * @returns a semantic-release Options object, based on `@halospv3/hce.shared-config` (our base config), with the `@semantic-release/exec` plugin configured to `dotnet publish`, `pack`, and `push` the specified projects.
342
+ * @param projectsToPublish An array of dotnet projects' relative paths.
343
+ * If empty, tries getting projects' semi-colon-separated relative
344
+ * paths from the `PROJECTS_TO_PUBLISH` environment variable.
345
+ * If configured as recommended, the projects' publish outputs will be zipped to
346
+ * '$PWD/publish' for use in the `publish` semantic-release step (typically,
347
+ * GitHub release).
348
+ * @param projectsToPackAndPush An array of dotnet projects' relative paths.
349
+ * If empty, `dotnet pack` and `dotnet nuget push` commands will not be configured.
350
+ * If undefined, tries getting projects' semi-colon-separated relative paths
351
+ * from the `PROJECTS_TO_PACK_AND_PUSH` environment variable.
352
+ * With the recommended configuration, `dotnet pack` will write the nupkg/snupkg
353
+ * files to `$PWD/publish` where they will be globbed by `dotnet nuget push`.
354
+ * @returns a semantic-release Options object, based on
355
+ * `@halospv3/hce.shared-config` (our base config), with the
356
+ * `@semantic-release/exec` plugin configured to `dotnet publish`, `pack`, and
357
+ * `push` the specified projects.
85
358
  */
86
- export function getConfig(projectsToPublish: string[] = [], projectsToPackAndPush: string[] | false = []): Options {
87
- if (debug.enabled) {
88
- console.debug('hce.shared-config:\n' + inspect(baseConfig, false, Infinity, true));
89
- }
90
-
91
- const errors: Error[] = [];
92
-
93
- if (projectsToPublish.length === 0) {
94
- const _ = getEnvVarValue("PROJECTS_TO_PUBLISH");
95
- if (_ === undefined)
96
- errors.push(new Error("projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path."));
97
- else
98
- projectsToPublish = _.split(';');
99
- }
100
-
101
- if (projectsToPackAndPush !== false && projectsToPackAndPush.length === 0) {
102
- const _ = getEnvVarValue("PROJECTS_TO_PACK_AND_PUSH")
103
- if (_ === undefined)
104
- errors.push(new Error("projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path."));
105
- else
106
- projectsToPackAndPush = _.split(';');
107
- }
108
-
109
- if (errors.length > 0) {
110
- throw new Error(
111
- [
112
- "getConfig cannot continue. One or more errors occurred.",
113
- ...(errors.map(v => v.stack))
114
- ].join('\n')
115
- )
116
- }
117
-
118
- let config = { ...baseConfig };
119
- config = insertAndEditPlugins(config);
120
- if (projectsToPublish)
121
- config = appendPlugins(config, projectsToPublish, projectsToPackAndPush);
122
-
123
- if (debug.enabled) {
124
- console.debug(`modified plugins array:\n${inspect(config.plugins, false, Infinity)}`);
125
- }
126
-
127
- return config;
359
+ export async function getConfig(
360
+ projectsToPublish: string[] | MSBuildProject[],
361
+ projectsToPackAndPush?: string[] | NugetRegistryInfo[],
362
+ ): Promise<Options> {
363
+ if (debug.enabled) {
364
+ debug.log(
365
+ 'hce.shared-config:\n' + inspect(baseConfig, false, Infinity, true),
366
+ );
367
+ }
368
+
369
+ const errors: Error[] = [];
370
+
371
+ if (projectsToPublish.length === 0) {
372
+ const _ = getEnvVarValue('PROJECTS_TO_PUBLISH');
373
+ if (_ === undefined)
374
+ errors.push(
375
+ new Error(
376
+ 'projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path.',
377
+ ),
378
+ );
379
+ else projectsToPublish = _.split(';');
380
+ }
381
+
382
+ if (!projectsToPackAndPush) {
383
+ const _ = getEnvVarValue('PROJECTS_TO_PACK_AND_PUSH');
384
+ if (_ === undefined)
385
+ errors.push(
386
+ new Error(
387
+ 'projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path.',
388
+ ),
389
+ );
390
+ else projectsToPackAndPush = _.split(';');
391
+ }
392
+
393
+ if (errors.length > 0) {
394
+ throw new Error(
395
+ [
396
+ 'getConfig cannot continue. One or more errors occurred.',
397
+ ...errors.map(v => v.stack),
398
+ ].join('\n'),
399
+ );
400
+ }
401
+
402
+ const config = new SemanticReleaseConfigDotnet(
403
+ projectsToPublish,
404
+ projectsToPackAndPush ?? [],
405
+ );
406
+ await config.setupDotnetCommands();
407
+
408
+ const options: Options = config.toOptions();
409
+ if (debug.enabled) {
410
+ console.debug(
411
+ `modified plugins array:\n${inspect(options.plugins, false, Infinity)}`,
412
+ );
413
+ }
414
+
415
+ return options;
128
416
  }
129
417
 
130
- export default getConfig;
418
+ /**
419
+ * @module semanticReleaseConfigDotnet
420
+ */