Skip to content

Allow @changesets/cli/changelog to be resolved even when homed in global node_modules#1500

Closed
cefn wants to merge 1 commit intochangesets:mainfrom
cefn:patch-2
Closed

Allow @changesets/cli/changelog to be resolved even when homed in global node_modules#1500
cefn wants to merge 1 commit intochangesets:mainfrom
cefn:patch-2

Conversation

@cefn
Copy link
Copy Markdown
Contributor

@cefn cefn commented Oct 16, 2024

As described in the thread linked below, there is an edge case when using a npm install -g version of @changesets/cli because the bespoke resolution algorithm to resolve @changesets/cli/changelog breaks - it assumes the module must only exist relative to the changeset package root rather than the global node_modules.

This is impactful because changesets are among the things you want to calculate in a pipeline step without doing a full npm install (e.g. to reason about identities for docker images and what not). The difference in some cases could be minutes of performance.

Fixes #566

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Oct 16, 2024

⚠️ No Changeset found

Latest commit: c976e8f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.94%. Comparing base (7323704) to head (c976e8f).
Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
packages/apply-release-plan/src/index.ts 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1500      +/-   ##
==========================================
- Coverage   81.04%   80.94%   -0.11%     
==========================================
  Files          54       54              
  Lines        2221     2225       +4     
  Branches      657      662       +5     
==========================================
+ Hits         1800     1801       +1     
- Misses        417      420       +3     
  Partials        4        4              

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

@cefn
Copy link
Copy Markdown
Contributor Author

cefn commented Oct 16, 2024

I cannot add a Changeset because yarn changeset add throws an error as below. Maybe a special case because of some kind of buggy interaction between node 20, a private npm repo, (npm mirror), and corepack.

$ yarn changeset add       
yarn run v1.22.22
$ packages/cli/bin.js add
Error: Cannot find module 'package-manager-detector'
Require stack:
- /Users/choile/workspace/github/changesets/packages/cli/src/commands/publish/npm-utils.ts
- /Users/choile/workspace/github/changesets/packages/cli/src/commands/publish/publishPackages.ts
- /Users/choile/workspace/github/changesets/packages/cli/src/commands/publish/index.ts
- /Users/choile/workspace/github/changesets/packages/cli/src/run.ts
- /Users/choile/workspace/github/changesets/packages/cli/src/index.ts
- /Users/choile/workspace/github/changesets/packages/cli/dist/changesets-cli.cjs.js
- /Users/choile/workspace/github/changesets/packages/cli/bin.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1202:15)
    at Function.Module._load (node:internal/modules/cjs/loader:1027:27)
    at Module.require (node:internal/modules/cjs/loader:1290:19)
    at require (node:internal/modules/helpers:188:18)
    at Object.<anonymous> (/Users/choile/workspace/github/changesets/packages/cli/src/commands/publish/npm-utils.ts:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1455:14)
    at Module._compile (/Users/choile/workspace/github/changesets/node_modules/pirates/lib/index.js:117:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1534:10)
    at Object.newLoader [as .ts] (/Users/choile/workspace/github/changesets/node_modules/pirates/lib/index.js:121:7)
    at Module.load (node:internal/modules/cjs/loader:1265:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1081:12)
    at Module.require (node:internal/modules/cjs/loader:1290:19)
    at require (node:internal/modules/helpers:188:18)

@Netail
Copy link
Copy Markdown
Contributor

Netail commented Nov 18, 2024

Missing changeset

@cefn
Copy link
Copy Markdown
Contributor Author

cefn commented Nov 18, 2024

Missing changeset

@Netail see #1500 (comment) changesets is failing in my environment as shown. Changesets cannot be added.

@Netail
Copy link
Copy Markdown
Contributor

Netail commented Nov 18, 2024

Missing changeset

@Netail see #1500 (comment) changesets is failing in my environment as shown. Changesets cannot be added.

Ahh that's what you meant by that, they did push some new changes regarding changeset add, could give it a try

@Netail
Copy link
Copy Markdown
Contributor

Netail commented Nov 19, 2024

I forked your repo and tried adding a changeset myself, did seem to work

changelogPath = resolveFrom(changesetPath, config.changelog[0]);
} catch (error) {
const { execSync } = require("child_process");
const globalNodeModules = execSync("npm root -g", {
Copy link
Copy Markdown
Contributor

@Netail Netail Jan 14, 2025

Choose a reason for hiding this comment

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

Not sure about this execSync, you could have a runtime without npm

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.

Yeah, I don't like this either. I think passing down __dirname obtained by @changesets/cli should allow us to call resolveFrom(changesetPath, callerDir);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#1562 :)

@Andarist
Copy link
Copy Markdown
Member

This work was pulled into #1562 and landed as part of it. I'm sorry for not getting to your PR on time

@Andarist Andarist closed this Jan 24, 2025
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.

changeset version can't be executed using npx

3 participants