create-portfoliable 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,6 +23,10 @@ npx create-portfoliable my-site
23
23
  - Repo: https://github.com/portfoliablejs/portfoliable
24
24
  - Package: https://www.npmjs.com/package/create-portfoliable
25
25
 
26
+ ## Publishing
27
+
28
+ This package is released through the repository workflow and publishes to the `@portfoliablejs` npm org. The release process checks the live npm registry before publishing so it cannot reuse a version that already exists.
29
+
26
30
  ## License
27
31
 
28
32
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-portfoliable",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Unified Portfoliable package with initializer and runtime CLI",
5
5
  "private": false,
6
6
  "type": "module",
@@ -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, nextVersion)) {
315
- throw new Error(
316
- `Refusing to publish ${pkg.displayName} version ${nextVersion}: it is already published to npm (${pkg.npmPackageName}). Please bump the version before releasing.`
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 { isVersionPublished, parsePublishedVersionList } from './release-orchestrator.mjs';
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
  });