Skip to content

Commit

Permalink
Add --registry argument to npm publish if set in `publishConfig.reg…
Browse files Browse the repository at this point in the history
…istry`
  • Loading branch information
webpro committed Mar 24, 2023
1 parent 7c86856 commit c59d55e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/plugin/npm/npm.js
Expand Up @@ -238,11 +238,13 @@ class npm extends Plugin {
const { private: isPrivate, tag = DEFAULT_TAG } = this.getContext();
const otpArg = otp ? `--otp ${otp}` : '';
const dryRunArg = this.config.isDryRun ? '--dry-run' : '';
const registry = this.getRegistry();
const registryArg = registry ? `--registry ${registry}` : '';
if (isPrivate) {
this.log.warn('Skip publish: package is private.');
return false;
}
const args = [publishPath, `--tag ${tag}`, otpArg, dryRunArg, ...fixArgs(publishArgs)].filter(Boolean);
const args = [publishPath, `--tag ${tag}`, otpArg, dryRunArg, registryArg, ...fixArgs(publishArgs)].filter(Boolean);
return this.exec(`npm publish ${args.join(' ')}`, { options })
.then(() => {
this.setContext({ isReleased: true });
Expand Down
2 changes: 1 addition & 1 deletion test/npm.js
Expand Up @@ -328,7 +328,7 @@ test('should publish to a different/scoped registry', async t => {
'npm show @my-scope/my-pkg@latest version --registry https://gitlab.com/api/v4/projects/my-scope%2Fmy-pkg/packages/npm/',
'npm --version',
'npm version 1.0.1 --no-git-tag-version',
'npm publish . --tag latest'
'npm publish . --tag latest --registry https://gitlab.com/api/v4/projects/my-scope%2Fmy-pkg/packages/npm/'
]);

exec.restore();
Expand Down

0 comments on commit c59d55e

Please sign in to comment.