Skip to content

Commit

Permalink
fix(core): install packages per migration when creating commits (#23820)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23505

(cherry picked from commit 6be46cf)
  • Loading branch information
leosvelperez authored and FrozenPandaz committed May 21, 2024
1 parent 5f82007 commit c3c118f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/nx/src/command-line/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,14 @@ export async function executeMigrations(
shouldCreateCommits: boolean,
commitPrefix: string
) {
const depsBeforeMigrations = getStringifiedPackageJsonDeps(root);
let initialDeps = getStringifiedPackageJsonDeps(root);
const installDepsIfChanged = () => {
const currentDeps = getStringifiedPackageJsonDeps(root);
if (initialDeps !== currentDeps) {
runInstall();
}
initialDeps = currentDeps;
};

const migrationsWithNoChanges: typeof migrations = [];
const sortedMigrations = migrations.sort((a, b) => {
Expand Down Expand Up @@ -1444,6 +1451,8 @@ export async function executeMigrations(
}

if (shouldCreateCommits) {
installDepsIfChanged();

const commitMessage = `${commitPrefix}${m.name}`;
try {
const committedSha = commitChanges(commitMessage);
Expand Down Expand Up @@ -1472,10 +1481,10 @@ export async function executeMigrations(
}
}

const depsAfterMigrations = getStringifiedPackageJsonDeps(root);
if (depsBeforeMigrations !== depsAfterMigrations) {
runInstall();
if (!shouldCreateCommits) {
installDepsIfChanged();
}

return migrationsWithNoChanges;
}

Expand Down

0 comments on commit c3c118f

Please sign in to comment.