Repository navigation
Fix changeset version when run from a subdirectory - #2349
Open
MaxFreedomPollard wants to merge 1 commit into
Open
MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
Since the CLI moved to cac, each command resolves the project root itself with `getPackages(cwd)`. `version` does that too, but it still passes the raw `cwd` to `readChangesets` and `readPreState`, so running it from a package directory fails with "There is no .changeset directory in this project", while `add`, `status`, `pre` and `publish` work from the same directory. Before the refactor `cwd` was already the project root here, and running from nested directories has been supported since 2.30.0. `version` now reads the changesets, the pre state and the commit module from `packages.rootDir`, like the other commands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 04f332b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for changesets ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2349 +/- ##
=======================================
Coverage 87.48% 87.48%
=======================================
Files 78 78
Lines 2973 2973
Branches 851 851
=======================================
Hits 2601 2601
Misses 337 337
Partials 35 35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running
changeset versionfrom a package directory fails in v3, whilechangeset/add,status,preandpublishwork from the same directory:This was reported in #2248 (comment). Running the CLI from nested directories was added in 2.30.0 (#1806).
The cause is in
packages/cli/src/commands/version/index.ts. Since the cac refactor (#2009),version()resolves the project itself withgetPackages(cwd)(line 30), and checks for.changesetand reads the config frompackages.rootDir(lines 31-32). But it still passes the rawcwdtoreadChangesetsandreadPreState(lines 68-69), and togetCommitFunctions(line 129). Before the refactor,run()passed the project root in ascwd, so these calls were correct. NowreadChangesetslooks for<cwd>/.changeset, which doesn't exist in a package directory. A relative commit module path (e.g."commit": ["./commit.mjs", null]) is also resolved against<cwd>/.changeset. That lookup would only fail after the package.json and changelog files had already been written.The fix passes
packages.rootDirto those three calls, which is whatstatus(readChangesets/readPreState) andadd(getCommitFunctions) already do. The git calls keepcwd, since git works from any directory in the repository.I added a test to
packages/cli/src/commands/version/version.test.tsthat runsversion({ cwd })frompackages/pkg-aand checks that both packages are bumped. It mirrors the existing "should be able to add a changeset when called from subdirectory" test inadd.test.ts. A changeset (patch for@changesets/cli) is included.Testing: I could not run vitest, typecheck, lint or oxfmt, because I couldn't install the workspace dependencies in my environment (no access to the npm registry). Instead, I loaded
version.test.tswith plain Node 22 type stripping and a small vitest-compatible shim. The workspace packages ran from theirsrc/files, with the realsemverandpicomatchthat ship with Node's npm. The remaining third-party modules were replaced with small local stand-ins:@clack/prompts,human-idand@changesets/gitare automocked as in the test file, andvalibot,yaml,jsonc-parser,@manypkg/get-packages,import-meta-resolveand@changesets/formatgot minimal implementations. As a check, thevalibotstand-in reproduces the default-config snapshots inpackages/config/src/parse.test.ts.Error: There is no .changeset directory in this projectfromreadChangesets. With the fix, it passes.1.1.0-next.0whenversionruns from a subdirectory. A relative commit module in.changeset/is also found. With only thereadChangesets/readPreStatechange, the commit module lookup fails.🤖 Generated with Claude Code