Require @changesets/cli resolving from cwd (#67)

* Resolve @changesets/cli with resolve-from

* Use require.resolve directly

* Add documentation section to README

* Add custom version command docs for Yarn 2
This commit is contained in:
Jacob Gillespie
2021-02-15 18:51:03 +01:00
committed by GitHub
parent b3300fad33
commit bf4c612018
3 changed files with 22 additions and 10 deletions
+11 -2
View File
@@ -4,7 +4,6 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
## Usage ## Usage
### Inputs ### Inputs
- publish - The command to use to build and publish packages - publish - The command to use to build and publish packages
@@ -101,7 +100,6 @@ jobs:
if: steps.changesets.outputs.published == 'true' if: steps.changesets.outputs.published == 'true'
# You can do something when a publish happens. # You can do something when a publish happens.
run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!" run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
``` ```
By default the GitHub Action creates a `.npmrc` file with the following content: By default the GitHub Action creates a `.npmrc` file with the following content:
@@ -164,3 +162,14 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
#### With Yarn 2 / Plug'n'Play
If you are using [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp), you should use a custom `version` command so that the action can resolve the `changeset` CLI:
```yaml
- uses: changesets/action@master
with:
version: yarn changeset version
...
```
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -7
View File
@@ -181,17 +181,20 @@ export async function runVersion({
let [versionCommand, ...versionArgs] = script.split(/\s+/); let [versionCommand, ...versionArgs] = script.split(/\s+/);
await exec(versionCommand, versionArgs, { cwd }); await exec(versionCommand, versionArgs, { cwd });
} else { } else {
let changesetsCliPkgJson = await require(path.join( let changesetsCliPkgJson = await require(require.resolve(
cwd, "@changesets/cli/package.json",
"node_modules", { paths: [cwd] }
"@changesets",
"cli",
"package.json"
)); ));
let cmd = semver.lt(changesetsCliPkgJson.version, "2.0.0") let cmd = semver.lt(changesetsCliPkgJson.version, "2.0.0")
? "bump" ? "bump"
: "version"; : "version";
await exec("node", ["./node_modules/@changesets/cli/bin.js", cmd], { cwd }); await exec(
"node",
[require.resolve("@changesets/cli/bin.js", { paths: [cwd] }), cmd],
{
cwd,
}
);
} }
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}`; let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}`;