Skip to content

fix: NPX apply changelog (npx @changesets/cli version)#1562

Merged
Andarist merged 7 commits intochangesets:mainfrom
Netail:fix/npx-apply-changelog
Jan 24, 2025
Merged

fix: NPX apply changelog (npx @changesets/cli version)#1562
Andarist merged 7 commits intochangesets:mainfrom
Netail:fix/npx-apply-changelog

Conversation

@Netail
Copy link
Copy Markdown
Contributor

@Netail Netail commented Jan 20, 2025

#1500, but a bit simpler

fixes: #566
fixes: #1426

If you would like to test it yourself;
npx @netail/changeset-cli@2.27.15 version

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.00%. Comparing base (a8c474f) to head (3e44749).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/apply-release-plan/src/index.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1562      +/-   ##
==========================================
- Coverage   81.02%   81.00%   -0.02%     
==========================================
  Files          54       54              
  Lines        2229     2232       +3     
  Branches      662      663       +1     
==========================================
+ Hits         1806     1808       +2     
- Misses        419      420       +1     
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 20, 2025

🦋 Changeset detected

Latest commit: 3e44749

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@changesets/apply-release-plan Patch
@changesets/cli Patch

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

changelogPath = resolveFrom(changesetPath, config.changelog[0]);
} catch {
changelogPath = resolveFrom(
path.join(__dirname, "..", ".."),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you are doing here but I don't think we should just blindly~ escape the current directory like this in hope to end up in the correct directory. This alternative cwd should be passed down as part of the options to this function

Copy link
Copy Markdown
Contributor Author

@Netail Netail Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveForm does not seem to accept options.

But isn't cwd the issue here as NPX installs the npm package into a npm cache folder somewhere in the home directory or %localappdata% for windows, while the process itself gets executed in a workspace (potentially) far from this cache directory. Resulting in changeset searching in the local node_modules where the process is executed, while it should search in the npm-cache (close to where the changeset/cli cache is located)

Packages located here:
~/.npm/_npx/<hash>/node_modules/@changesets/cli
~/.npm/_npx/<hash>/node_modules/@changesets/apply-release-plan
~/.npm/_npx/<hash>/node_modules/@changesets/git

Executed here:
~/Documents/React/<project>


__dirname: ~/npm/<hash>/node_modules/@changesets/apply-release-plan/index.js
cwd: ~/Documents/React/<project>

Copy link
Copy Markdown
Contributor Author

@Netail Netail Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I get what you mean. Applied & testing, seems to work :)

try {
changelogPath = resolveFrom(changesetPath, config.changelog[0]);
} catch {
changelogPath = resolveFrom(__dirname, config.changelog[0]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better but this "context dir" should come from options. I feel like we want to resolve this in the context of the executed @changesets/cli and not in the context of @changesets/apply-release-plan, even if that ends up resolving to the same location in the majority of cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like 3c786a6 you mean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this version works for me 👍 Have you tried testing the current state of this PR in "the real world"?

Copy link
Copy Markdown
Contributor Author

@Netail Netail Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't yet since 3c786a6 (Since the __dirname coming from the cli package), before that I did. https://www.npmjs.com/package/@netail/changeset-cli + underlying https://www.npmjs.com/package/@netail/changesets-apply-release-plan

I can check the latest changes tonight

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can check the latest changes tonight

I'd appreciate it 👍

Copy link
Copy Markdown
Contributor Author

@Netail Netail Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, seems to work

ref npx @netail/changeset-cli@2.27.21 version (https://www.npmjs.com/package/@netail/changeset-cli)

@Andarist Andarist merged commit a0f87f1 into changesets:main Jan 24, 2025
@github-actions github-actions bot mentioned this pull request Jan 24, 2025
@Netail Netail deleted the fix/npx-apply-changelog branch January 24, 2025 10:05
jacktwomey pushed a commit to jacktwomey/changesets that referenced this pull request Feb 16, 2025
…1562)

* Resolve module from global node_modules

Fixes changesets#566

* fix: NPX apply changelog

* fix: feedback

* fix: feedback v2

* fix: feedback v3

* Create seven-beans-jump.md

* Apply suggestions from code review

---------

Co-authored-by: Cefn Hoile <github.com@cefn.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
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

Successfully merging this pull request may close these issues.

Using the changeset CLI with the NPX command changeset version can't be executed using npx

3 participants