Skip to content

Commit

Permalink
feat: Release together flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jprosevear committed Jun 26, 2024
1 parent df9dbda commit a1d399b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import {
* @returns {Promise<void>}
*/
export const publish = async (options) => {
const { branchConfigs, packages, rootDir, branch, tag, ghToken } = options
const {
branchConfigs,
packages,
rootDir,
branch,
tag,
ghToken,
releaseTogether = false,
} = options

const branchName = /** @type {string} */ (branch ?? currentGitBranch())
const isMainBranch = branchName === 'main'
Expand Down Expand Up @@ -227,16 +235,21 @@ export const publish = async (options) => {
.filter(Boolean)

/** Uses packages and changedFiles to determine which packages have changed */
const changedPackages = RELEASE_ALL
const packagesWithChanges = packages.filter((pkg) => {
const changed = changedFiles.some(
(file) =>
file.startsWith(path.join(pkg.packageDir, 'src'))
|| file.startsWith(path.join(pkg.packageDir, 'package.json')),
)
return changed
})

// If RELEASE_ALL is set, release all packages
// If releaseTogether is set, release all packages if any package has changed
// Otherwise, only release packages that have changed
const changedPackages = RELEASE_ALL || (releaseTogether && packagesWithChanges.length > 0)
? packages
: packages.filter((pkg) => {
const changed = changedFiles.some(
(file) =>
file.startsWith(path.join(pkg.packageDir, 'src')) ||
file.startsWith(path.join(pkg.packageDir, 'package.json')),
)
return changed
})
: packagesWithChanges

// If a package has a dependency that has been updated, we need to update the
// package that depends on it as well.
Expand Down
2 changes: 2 additions & 0 deletions src/publish/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ export type RunOptions = {
tag?: string
/** The GitHub token used to search for user metadata and make a GitHub release. */
ghToken?: string
/** If releasing any package, release all packages together. Defaults to false */
releaseTogether?: boolean
}

0 comments on commit a1d399b

Please sign in to comment.