diff --git a/.changeset/proud-snakes-destroy.md b/.changeset/proud-snakes-destroy.md new file mode 100644 index 0000000000..df81d736a1 --- /dev/null +++ b/.changeset/proud-snakes-destroy.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": patch +--- + +fix: remove --publish-branch with branch name to npm publish args diff --git a/packages/plugin-commands-publishing/src/publish.ts b/packages/plugin-commands-publishing/src/publish.ts index 24ae3618ec..b1e0a03c6b 100644 --- a/packages/plugin-commands-publishing/src/publish.ts +++ b/packages/plugin-commands-publishing/src/publish.ts @@ -164,7 +164,20 @@ Do you want to continue?`, 'prepack', ], publishManifest) } - const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...opts.argv.original.slice(1)]) + + const args = opts.argv.original.slice(1) + const index = args.indexOf('--publish-branch') + if (index !== -1) { + // If --publish-branch follows with another cli option, only remove this argument + // otherwise remove the following argument as well + if (args[index + 1]?.startsWith('-')) { + args.splice(index, 1) + } else { + args.splice(index, 2) + } + } + + const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...args]) if (!opts.ignoreScripts) { await _runScriptsIfPresent([ 'publish', diff --git a/packages/plugin-commands-publishing/test/publish.ts b/packages/plugin-commands-publishing/test/publish.ts index f87978c346..2d5719d8bb 100644 --- a/packages/plugin-commands-publishing/test/publish.ts +++ b/packages/plugin-commands-publishing/test/publish.ts @@ -2,6 +2,7 @@ import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock' import prepare, { preparePackages } from '@pnpm/prepare' import { pack, publish } from '@pnpm/plugin-commands-publishing' import { DEFAULT_OPTS } from './utils' +import execa = require('execa') import path = require('path') import crossSpawn = require('cross-spawn') import fs = require('mz/fs') @@ -599,3 +600,25 @@ test('publish: ignores all the lifecycle scripts when --ignore-scripts is used', expect(await exists('package.json')).toBeTruthy() expect(await exists('output.json')).toBeFalsy() }) + +test('publish: with specified publish branch name', async () => { + prepare({ + name: 'test-publish-package.json', + version: '0.0.2', + }) + + const branch = 'some-random-publish-branch' + await execa('git', ['init']) + await execa('git', ['checkout', '-b', branch]) + await execa('git', ['config', 'user.email', 'x@y.z']) + await execa('git', ['config', 'user.name', 'xyz']) + await execa('git', ['add', '*']) + await execa('git', ['commit', '-m', 'init', '--no-gpg-sign']) + + await publish.handler({ + ...DEFAULT_OPTS, + argv: { original: ['publish', '--publish-branch', branch, ...CREDENTIALS] }, + dir: process.cwd(), + publishBranch: branch, + }, []) +})