Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument --releaseAs [1.1.0] is ignored if --skip.bump is also used #130

Open
aheater18 opened this issue Feb 28, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@aheater18
Copy link

Describe the bug
Running commit-and-tag-version with the option to skip the bump step uses the current version in package.json instead of using the version specified with the argument releaseAs.

Current behavior
Steps following bump (changelog, commit, tag) run with the current version in package.json.

Expected behavior
Other steps (changelog, commit, tag) should run with the version specified with releaseAs.

Environment

  • commit-and-tag-version version(s): 12.2.0
  • Node/npm version: Node 20.5.0
  • OS: Windows 10

Possible Solution

In bump.js, the logic for determining the newVersion from releaseAs (I think lines 46-62) should be moved up to line 35, and the check for args.skip.bump should be moved to occur right after that, returning the releaseAs version if it exists.

Additional context
Add any other context about the problem here. Or a screenshot if applicable

@aheater18 aheater18 added the bug Something isn't working label Feb 28, 2024
@rob4226
Copy link

rob4226 commented Oct 29, 2024

I think something like this would work:

diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js
--- lib/lifecycles/bump.js
+++ lib/lifecycles/bump.js
@@ -19,9 +19,8 @@
   // reset the cache of updated config files each
   // time we perform the version bump step.
   configsToUpdate = {};
 
-  if (args.skip.bump) return version;
 
   if (
     args.releaseAs &&
     !(
@@ -34,34 +33,40 @@
     );
   }
 
   let newVersion = version;
+
+  if (semver.valid(args.releaseAs)) {
+    const releaseAs = new semver.SemVer(args.releaseAs);
+    if (
+      isString(args.prerelease) &&
+      releaseAs.prerelease.length &&
+      releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease
+    ) {
+      // If both releaseAs and the prerelease identifier are supplied, they must match. The behavior
+      // for a mismatch is undefined, so error out instead.
+      throw new Error(
+        'releaseAs and prerelease have conflicting prerelease identifiers',
+      );
+    } else if (isString(args.prerelease) && releaseAs.prerelease.length) {
+      newVersion = releaseAs.version;
+    } else if (isString(args.prerelease)) {
+      newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`;
+    } else {
+      newVersion = releaseAs.version;
+    }
+  }
+
+  if (args.skip.bump) return newVersion;
+
   await runLifecycleScript(args, 'prerelease');
   const stdout = await runLifecycleScript(args, 'prebump');
   if (stdout?.trim().length) {
     const prebumpString = stdout.trim().replace(sanitizeQuotesRegex, '');
     if (semver.valid(prebumpString)) args.releaseAs = prebumpString;
   }
   if (!args.firstRelease) {
     if (semver.valid(args.releaseAs)) {
-      const releaseAs = new semver.SemVer(args.releaseAs);
-      if (
-        isString(args.prerelease) &&
-        releaseAs.prerelease.length &&
-        releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease
-      ) {
-        // If both releaseAs and the prerelease identifier are supplied, they must match. The behavior
-        // for a mismatch is undefined, so error out instead.
-        throw new Error(
-          'releaseAs and prerelease have conflicting prerelease identifiers',
-        );
-      } else if (isString(args.prerelease) && releaseAs.prerelease.length) {
-        newVersion = releaseAs.version;
-      } else if (isString(args.prerelease)) {
-        newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`;
-      } else {
-        newVersion = releaseAs.version;
-      }
 
       // Check if the previous version is the same version and prerelease, and increment if so
       if (
         isString(args.prerelease) &&

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants