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

Fails when using Yarn v2 + PnP #66

Open
jdb8 opened this issue Jan 19, 2021 · 5 comments
Open

Fails when using Yarn v2 + PnP #66

jdb8 opened this issue Jan 19, 2021 · 5 comments

Comments

@jdb8
Copy link

jdb8 commented Jan 19, 2021

It looks like there's a line that explicitly references node_modules here: https://github.com/changesets/action/blob/master/src/run.ts#L186. When using Yarn PnP, this fails, since node_modules doesn't exist.

Error: Cannot find module '/home/runner/work/<pkg>/<pkg>/node_modules/@changesets/cli/package.json'
Require stack:
- /home/runner/work/_actions/changesets/action/master/dist/index.js
Require stack:
- /home/runner/work/_actions/changesets/action/master/dist/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at f (/home/runner/work/_actions/changesets/action/master/dist/index.js:1:293)
    at f (/home/runner/work/_actions/changesets/action/master/dist/index.js:1:233)
    at p (/home/runner/work/_actions/changesets/action/master/dist/index.js:1:544)
    at Object.w [as runVersion] (/home/runner/work/_actions/changesets/action/master/dist/index.js:906:3310)
    at async /home/runner/work/_actions/changesets/action/master/dist/index.js:908:1597 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/work/_actions/changesets/action/master/dist/index.js'
  ]
}
@Andarist
Copy link
Member

Does require.resolve work with PnP in a way that we could use the resolved path to read the package.json file using fs APIs?

@merceyz
Copy link

merceyz commented Jan 20, 2021

Yes, you use require.resolve and all other node methods just like you normally would

const path = require('path');

const cliPath = require.resolve('@changesets/cli/package.json', { paths: [cwd] });

const changesetsCliPkgJson = require(cliPath); // or JSON.parse(fs.read*(cliPath) )

await exec('node', [path.resolve(cliPath, '../cli/bin.js'), cmd], { cwd });

You should always use something like this and not make assumptions about the node_modules layout, then the user can set NODE_OPTIONS="-r <cwd>./.pnp.(c)js" as an env variable in their CI to enable PnP

@Andarist
Copy link
Member

Would you like to prepare a PR for this?

@jacobwgillespie
Copy link
Contributor

jacobwgillespie commented Jan 28, 2021

@Andarist I've opened a PR for this here: #67

I can confirm that using that PR + the following GitHub Actions config, it works for us using Yarn 2 + PnP:

- uses: jacobwgillespie/changesets-action@resolve-from
  with:
    publish: ...
  env:
    NODE_OPTIONS: -r /home/runner/work/repo/repo/.pnp.js
    ...

@elpddev
Copy link

elpddev commented Jun 11, 2021

This issue can be closed maybe? For me it works now with:

with:
  version: yarn changeset version

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

5 participants