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

Add configurable publishCommand #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ With this configuration, the `package.json` files in your workspaces would be
updated with the new version information but the packages would not be
published.

### publishCommand

`@release-it-plugins/workspaces` uses `npm publish` by default.
Some repository configurations may wish to use a different publish command.
Using `publishCommand`, this can be changed:

```json
{
"release-it": {
"plugins": {
"@release-it-plugins/workspaces": {
"publishCommand": "pnpm publish"
}
}
}
}
```

With this configuration, `pnpm publish` will be used for each workspace instead of `npm publish`


### distTag

`@release-it-plugins/workspaces` uses the `latest` dist-tag when the
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ export default class WorkspacesPlugin extends Plugin {
return;
}

const publishCommand = this.getContext().publishCommand ?? 'npm publish';

try {
await this.exec(
`npm publish ./${workspaceInfo.relativeRoot} --tag ${tag}${accessArg}${otpArg}${dryRunArg}`,
`${publishCommand} ./${workspaceInfo.relativeRoot} --tag ${tag}${accessArg}${otpArg}${dryRunArg}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still assumes a bunch of details about the command. For example, it assumes --otp, --tag, --access, and --dry-run are valid arguments to the configured publish command. I think it would probably be better to allow the customized command to include the various arguments internally instead.

I think we can use some built in functionality to release-it to easily support templating here.

It will require some additional tweaks here, but not too much AFAICT. This would become something like:

const context = {
  pathToWorkspace: workspaceInfo.relativeRoot,
  otp: otp.value,
  access,
  dryRun: this.config.isDryRun
};
let publishCommand = this.getContext().publishCommand;

if (isPNPM ) {
  // you'll need to implement the `isPNPM` conditional above, and also the default command for it; but maybe it's basically the same as the `npm publish` one but with `p` prefixed?
} else {
  publishCommand = 'npm publish <%= pathToWorkspace %> --tag <%= tag %> <%= access ? "--access " + access : "" %> <%= otp.value ? "--otp " + otp.value : "" %> <%= dryRun ? "--dry-run" : "" %>';
}

await this.exec(publishCommand, options, context);

References:

{
options,
}
Expand Down
51 changes: 51 additions & 0 deletions tests/plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,57 @@
`);
});

it('uses custom publish command', async () => {
setupProject(['packages/*']);
let plugin = buildPlugin({
publishCommand: 'pnpm publish'

Check failure on line 617 in tests/plugin-test.js

View workflow job for this annotation

GitHub Actions / Node 16.x

Insert `,`

Check failure on line 617 in tests/plugin-test.js

View workflow job for this annotation

GitHub Actions / release-it@14.1.0

Insert `,`

Check failure on line 617 in tests/plugin-test.js

View workflow job for this annotation

GitHub Actions / Node 18.x

Insert `,`
});

await runTasks(plugin);

expect(plugin.operations).toMatchInlineSnapshot(`
[
{
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": undefined,
},
{
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": undefined,
},
{
"command": "pnpm publish ./packages/bar --tag latest",
"operationType": "command",
"options": {
"write": false,
},
},
{
"command": "pnpm publish ./packages/foo --tag latest",
"operationType": "command",
"options": {
"write": false,
},
},
{
"messages": [
"🔗 https://www.npmjs.com/package/bar",
],
"operationType": "log",
},
{
"messages": [
"🔗 https://www.npmjs.com/package/foo",
],
"operationType": "log",
},
]
`);
});

Check failure on line 662 in tests/plugin-test.js

View workflow job for this annotation

GitHub Actions / Node 16.x

Delete `⏎`

Check failure on line 662 in tests/plugin-test.js

View workflow job for this annotation

GitHub Actions / release-it@14.1.0

Delete `⏎`

Check failure on line 662 in tests/plugin-test.js

View workflow job for this annotation

GitHub Actions / Node 18.x

Delete `⏎`


it('uses custom registry', async () => {
setupProject(['packages/*'], { publishConfig: { registry: 'http://my-custom-registry' } });
let plugin = buildPlugin();
Expand Down
Loading