Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Incorrect npm tag for previous version release #24

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import {
*/
export const publish = async (options) => {
const { branchConfigs, packages, rootDir, branch, tag, ghToken } = options

const branchName = /** @type {string} */ (branch ?? currentGitBranch())
const isMainBranch = branchName === 'main'
const npmTag = isMainBranch ? 'latest' : branchName

/** @type {import('./types.js').BranchConfig | undefined} */
const branchConfig = branchConfigs[branchName]

const isMainBranch = branchName === 'main'
const isPreviousRelease = branchConfig?.previousVersion
const npmTag = isMainBranch ? 'latest' : branchName
if (!branchConfig) {
throw new Error(`No publish config found for branch: ${branchName}`)
}

// Get tags
/** @type {string[]} */
Expand All @@ -42,7 +46,7 @@ export const publish = async (options) => {
.filter((t) => semver.valid(t))
.filter((t) => {
// If this is an older release, filter to only include that version
if (isPreviousRelease) {
if (branchConfig.previousVersion) {
return t.startsWith(branchName)
}
if (semver.prerelease(t) === null) {
Expand Down Expand Up @@ -310,12 +314,6 @@ export const publish = async (options) => {
recommendedReleaseLevel = 0
}

if (!branchConfig) {
console.log(`No publish config found for branch: ${branchName}`)
console.log('Exiting...')
process.exit(0)
}

const releaseType = branchConfig.prerelease
? 'prerelease'
: /** @type {const} */ ({ 0: 'patch', 1: 'minor', 2: 'major' })[
Expand Down Expand Up @@ -381,15 +379,14 @@ export const publish = async (options) => {
}

console.info()
console.info('Publishing all packages to npm')
console.info(`Publishing all packages to npm with tag "${npmTag}"`)

// Publish each package
changedPackages.forEach((pkg) => {
const packageDir = path.join(rootDir, pkg.packageDir)
const tagParam = branchConfig.previousVersion ? '' : `--tag ${npmTag}`

const cmd = `cd ${packageDir} && pnpm publish ${tagParam} --access=public --no-git-checks`
console.info(` Publishing ${pkg.name}@${version} to npm "${tagParam}"...`)
const cmd = `cd ${packageDir} && pnpm publish --tag ${npmTag} --access=public --no-git-checks`
console.info(` Publishing ${pkg.name}@${version} to npm...`)
execSync(cmd, {
stdio: [process.stdin, process.stdout, process.stderr],
})
Expand Down