create-portfoliable 1.2.5 → 1.2.6
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/package.json
CHANGED
|
@@ -201,6 +201,24 @@ export function isVersionPublished(publishedVersions, candidateVersion) {
|
|
|
201
201
|
return Array.isArray(publishedVersions) && publishedVersions.includes(candidateVersion);
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
export function resolveNextUniqueVersion(currentVersion, level, publishedVersions) {
|
|
205
|
+
let candidate = currentVersion;
|
|
206
|
+
let attempts = 0;
|
|
207
|
+
|
|
208
|
+
while (isVersionPublished(publishedVersions, candidate) && attempts < 20) {
|
|
209
|
+
candidate = bumpVersion(candidate, level);
|
|
210
|
+
attempts += 1;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (isVersionPublished(publishedVersions, candidate)) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Unable to find an unpublished ${level} version after ${attempts} attempts starting from ${currentVersion}.`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return candidate;
|
|
220
|
+
}
|
|
221
|
+
|
|
204
222
|
function getPublishedVersionsForPackage(packageName) {
|
|
205
223
|
try {
|
|
206
224
|
const output = execFileSync("npm", ["view", packageName, "versions", "--json"], {
|
|
@@ -305,15 +323,14 @@ function createReleasePlan(pkg) {
|
|
|
305
323
|
};
|
|
306
324
|
}
|
|
307
325
|
|
|
308
|
-
// Reads current package version and computes next semantic version/tag.
|
|
326
|
+
// Reads current package version and computes the next unpublished semantic version/tag.
|
|
309
327
|
const currentVersion = JSON.parse(readFileSync(pkg.packageJsonPath, "utf8")).version;
|
|
310
|
-
// Computes next version using selected bump level.
|
|
311
|
-
const nextVersion = bumpVersion(currentVersion, bump);
|
|
312
328
|
const publishedVersions = getPublishedVersionsForPackage(pkg.npmPackageName);
|
|
329
|
+
const nextVersion = resolveNextUniqueVersion(currentVersion, bump, publishedVersions);
|
|
313
330
|
|
|
314
|
-
if (isVersionPublished(publishedVersions,
|
|
315
|
-
|
|
316
|
-
`
|
|
331
|
+
if (isVersionPublished(publishedVersions, currentVersion)) {
|
|
332
|
+
console.log(
|
|
333
|
+
`Current version ${currentVersion} already exists on npm for ${pkg.npmPackageName}; advancing to ${nextVersion}.`
|
|
317
334
|
);
|
|
318
335
|
}
|
|
319
336
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isVersionPublished,
|
|
4
|
+
parsePublishedVersionList,
|
|
5
|
+
resolveNextUniqueVersion,
|
|
6
|
+
} from './release-orchestrator.mjs';
|
|
3
7
|
|
|
4
8
|
describe('release orchestrator version guard', () => {
|
|
5
9
|
it('detects versions already published to npm', () => {
|
|
@@ -8,4 +12,9 @@ describe('release orchestrator version guard', () => {
|
|
|
8
12
|
expect(isVersionPublished(['1.2.2', '1.2.3'], '1.2.3')).toBe(true);
|
|
9
13
|
expect(isVersionPublished(['1.2.2', '1.2.3'], '1.2.4')).toBe(false);
|
|
10
14
|
});
|
|
15
|
+
|
|
16
|
+
it('bumps until it finds an unpublished version', () => {
|
|
17
|
+
expect(resolveNextUniqueVersion('1.2.4', 'patch', ['1.2.4', '1.2.5'])).toBe('1.2.6');
|
|
18
|
+
expect(resolveNextUniqueVersion('1.2.3', 'patch', ['1.2.3', '1.2.4'])).toBe('1.2.5');
|
|
19
|
+
});
|
|
11
20
|
});
|