diff --git a/packages/publish-config/src/index.d.ts b/packages/publish-config/src/index.d.ts index b372c59..b299e0b 100644 --- a/packages/publish-config/src/index.d.ts +++ b/packages/publish-config/src/index.d.ts @@ -31,6 +31,8 @@ export type Options = { 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 } /** https://tanstack.com/config/latest/docs/publish */ diff --git a/packages/publish-config/src/index.js b/packages/publish-config/src/index.js index 52d71fa..effec67 100644 --- a/packages/publish-config/src/index.js +++ b/packages/publish-config/src/index.js @@ -45,7 +45,15 @@ function currentGitBranch() { * @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' @@ -250,16 +258,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.