fix(release): scope fallback to project history for new packages#35323
Open
zanlucathiago wants to merge 1 commit intonrwl:masterfrom
Open
fix(release): scope fallback to project history for new packages#35323zanlucathiago wants to merge 1 commit intonrwl:masterfrom
zanlucathiago wants to merge 1 commit intonrwl:masterfrom
Conversation
…for new packages When a project has no release tags (e.g., newly added to a monorepo), `nx release` falls back to `getFirstGitCommit()` which scans the entire repository history. In large monorepos with thousands of commits, this causes: 1. Severe performance degradation (5+ minutes for the release step) 2. Noisy "package not found" warnings for packages referenced in old commits that no longer exist in the workspace This commit introduces `getFirstProjectCommit(projectRoot)` which finds the first commit that touched the project's `package.json`, scoping the conventional commits analysis to only the relevant portion of git history. The fallback is applied in two places: - `deriveSpecifierFromConventionalCommits` (version bumps) - `resolveChangelogFromSHA` (changelog generation) For workspace-level and fixed release group changelogs, the existing `getFirstGitCommit()` behavior is preserved since there is no single project root to scope to. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for nx-docs canceled.
|
✅ Deploy Preview for nx-dev canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
Closes #35327
When a project has no release tags (e.g., newly added to a monorepo),
nx releasefalls back togetFirstGitCommit()— the very first commit in the entire repository. This meansgit log <first-commit>..HEADscans every commit ever made, regardless of whether they are relevant to the new project.In large monorepos this causes:
"The affected projects might have not been identified properly. The package(s) X were not found"for every old/renamed/removed package referenced in ancient commitsReproduction
release.changelog.automaticFromRef: trueandrelease.version.conventionalCommits: truenx release --skip-publishExpected Behavior
For new packages without release tags,
nx releaseshould only scan commits since the project was first introduced — not the entire repository history.Implementation
Adds
getFirstProjectCommit(projectRoot)inutils/git.ts:This finds the first commit that touched the project's
package.jsonand returns its parent, so thatfrom..HEADranges include the creation commit itself.The function is used as the fallback in two places:
deriveSpecifierFromConventionalCommitsgetFirstGitCommit()getFirstProjectCommit(projectRoot)resolveChangelogFromSHAgetFirstGitCommit()getFirstProjectCommit(projectRoot)whenprojectRootis providedFor workspace-level and fixed release group changelogs (where there's no single project root), the existing
getFirstGitCommit()behavior is preserved.Fallback safety
If
getFirstProjectCommitfails for any reason (e.g., the project root doesn't contain apackage.json, or the git command fails), it gracefully falls back togetFirstGitCommit()— maintaining backward compatibility.Impact
For a real-world monorepo with ~1200 commits and 4 new packages: