fix: add main to default publish branch

close #2995
PR #3064
This commit is contained in:
Yao Ding
2021-01-13 04:56:14 -05:00
committed by GitHub
parent e665f51054
commit 6af60416cb
3 changed files with 11 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-publishing": patch
---
add 'main' to default publish branch

View File

@@ -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,
})
}

View File

@@ -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'.")
)
})