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

feat: Release together flag #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
36 changes: 25 additions & 11 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,22 @@ export const publish = async (options) => {
.filter(Boolean)

/** Uses packages and changedFiles to determine which packages have changed */
const changedPackages = RELEASE_ALL
? 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
})
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
: 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
}