From a1d399b43d28e6981f25c5b2488aba918ef4982a Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Fri, 21 Jun 2024 09:53:24 -0400 Subject: [PATCH] feat: Release together flag --- src/publish/index.js | 33 +++++++++++++++++++++++---------- src/publish/types.d.ts | 2 ++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/publish/index.js b/src/publish/index.js index e1737c3..e7c5f99 100644 --- a/src/publish/index.js +++ b/src/publish/index.js @@ -22,7 +22,15 @@ import { * @returns {Promise} */ 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' @@ -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. diff --git a/src/publish/types.d.ts b/src/publish/types.d.ts index 30ef91e..8e582c1 100644 --- a/src/publish/types.d.ts +++ b/src/publish/types.d.ts @@ -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 }