From c59d55eeaf4bc94653898f4c0b724aecde4f6cd3 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Fri, 24 Mar 2023 14:51:59 +0100 Subject: [PATCH] Add --registry argument to `npm publish` if set in `publishConfig.registry` --- lib/plugin/npm/npm.js | 4 +++- test/npm.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/plugin/npm/npm.js b/lib/plugin/npm/npm.js index 6f008602..af86d289 100644 --- a/lib/plugin/npm/npm.js +++ b/lib/plugin/npm/npm.js @@ -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 }); diff --git a/test/npm.js b/test/npm.js index e3f28b43..39516fd2 100644 --- a/test/npm.js +++ b/test/npm.js @@ -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();