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

Changesets bump the version of ignored packages #1304

Open
jbltx opened this issue Feb 5, 2024 · 0 comments
Open

Changesets bump the version of ignored packages #1304

jbltx opened this issue Feb 5, 2024 · 0 comments

Comments

@jbltx
Copy link

jbltx commented Feb 5, 2024

Affected Packages

  • cli
  • pre

Problem

I was in pre-release mode and I needed to publish one package out of pre-release. This package has no dependency with others packages so I guessed it won't be that complicated...

changeset pre exit
changeset version --ignore pkg1 --ignore pkg2 ...

No error so far

🦋  All files have been updated. Review them and commit at your leisure

But I can see that all my packages have bumped in version and their changelog has changed too. Nothing seems to be ignored at all.

From what I understand, changesets files related to the ignored packages are still present in the .changeset folder. But the version bump still occurs and we have to deal with resetting any changes for these packages.

Also, since we exited pre-release mode, I was expecting that the changesets array inside .changeset/pre.json would still be populated with changesets related to ignored packages...
But after the version bump, this file disappears, and when re-entering pre mode the new file contains an empty array.

Here again, the only solution is to modify the pre.json file manually or by script.

Proposed solution

  • Avoid bumping version of ignored packages
  • Make the ignore options work even in scenarios where we just exited pre-release mode.
  • When entering pre mode we should have the option to pre-populate the pre changesets list with already present changeset files.
  • Since the ignored packages should not be version bumped, I would expect that the version of packages listed in pre.json would still be correct.

Current Workaround

This is my script to do the expected result for now:

#!/bin/bash

if [ -z "$1" ]; then
  echo "Please provide an argument (either 'version' or 'publish')"
  exit 1
fi

if [ $1 != "version" ] && [ $1 != "publish" ]; then
  echo "Invalid argument. Please provide either 'version' or 'publish'"
  exit 1
fi

#### VERSION ####

if [ $1 == "version" ]; then 
    # Create a new branch to review version bump changes
    git checkout -b changeset-release

    # Exit Pre-Release Mode
    pnpm changeset pre exit

    # Bump version of a single package
    pnpm changeset version \
    --ignore pkg-1 \
    --ignore pkg2

    # Revert any changes in ignored packages
    git checkout -- \
    packages/pkg-1 \
    packages/pkg-2

    # Push the changes and create a PR
    git add .
    git commit -m "chore(release): changeset-release"
    git push -u origin changeset-release
fi

#### RELEASE ####

if [ $1 == "publish" ]; then 
    # Publish the package
    pnpm changeset publish

    # Go Back to Pre-Release Mode
    pnpm changeset pre enter pre

    # List all md files in .changeset folder and add them in .changeset/pre.json using jq
    names=""
    for file in .changeset/*.md; do
        name="$(basename $file .md)"
        if [ $name == "README" ]; then
            continue
        fi
        names="$names \"$name\","
    done
    names=${names%?}
    newPre="$(jq '.changesets = [ '"$names"' ]' .changeset/pre.json)"
    printf '%s\n' "$newPre" > .changeset/pre.json

    # Push the changes to the base branch
    git add .changeset
    git commit -m "chore(release): back to pre-release mode"
    git push --follow-tags
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant