diff --git a/.changeset/stale-comics-press.md b/.changeset/stale-comics-press.md new file mode 100644 index 0000000000..3adc91a7e1 --- /dev/null +++ b/.changeset/stale-comics-press.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": patch +--- + +add 'main' to default publish branch diff --git a/packages/plugin-commands-publishing/src/publish.ts b/packages/plugin-commands-publishing/src/publish.ts index 3746237f7a..24ae3618ec 100644 --- a/packages/plugin-commands-publishing/src/publish.ts +++ b/packages/plugin-commands-publishing/src/publish.ts @@ -102,18 +102,18 @@ export async function handler ( hint: GIT_CHECKS_HINT, }) } - const branch = opts.publishBranch ?? 'master' + const branches = opts.publishBranch ? [opts.publishBranch] : ['master', 'main'] const currentBranch = await getCurrentBranch() - if (currentBranch !== branch) { + if (!branches.includes(currentBranch)) { const { confirm } = await prompt({ - message: `You're on branch "${currentBranch}" but your "publish-branch" is set to "${branch}". \ + message: `You're on branch "${currentBranch}" but your "publish-branch" is set to "${branches.join('|')}". \ Do you want to continue?`, name: 'confirm', type: 'confirm', } as any) as any // eslint-disable-line @typescript-eslint/no-explicit-any if (!confirm) { - throw new PnpmError('GIT_NOT_CORRECT_BRANCH', `Branch is not on '${branch}'.`, { + throw new PnpmError('GIT_NOT_CORRECT_BRANCH', `Branch is not on '${branches.join('|')}'.`, { hint: GIT_CHECKS_HINT, }) } diff --git a/packages/plugin-commands-publishing/test/gitChecks.ts b/packages/plugin-commands-publishing/test/gitChecks.ts index 5459b00ab3..598e604d73 100644 --- a/packages/plugin-commands-publishing/test/gitChecks.ts +++ b/packages/plugin-commands-publishing/test/gitChecks.ts @@ -24,7 +24,7 @@ const CREDENTIALS = [ `--//localhost:${REGISTRY_MOCK_PORT}/:email=foo@bar.net`, ] -test('publish: fails git check if branch is not on master', async () => { +test('publish: fails git check if branch is not on master or main', async () => { prepare({ name: 'test-publish-package.json', version: '0.0.0', @@ -48,7 +48,7 @@ test('publish: fails git check if branch is not on master', async () => { dir: process.cwd(), }, []) ).rejects.toThrow( - new PnpmError('GIT_NOT_CORRECT_BRANCH', "Branch is not on 'master'.") + new PnpmError('GIT_NOT_CORRECT_BRANCH', "Branch is not on 'master|main'.") ) })