Open jdb8 opened 3 years ago
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?
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
Would you like to prepare a PR for this?
@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
...
This issue can be closed maybe? For me it works now with:
with:
version: yarn changeset version
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.