Skip to content

Commit

Permalink
fix(core): ensure preinstall is only run once on repo, not on every d…
Browse files Browse the repository at this point in the history
…eps change
  • Loading branch information
meeroslav committed Aug 17, 2023
1 parent 5240896 commit 4cbe93b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/devkit/src/tasks/install-packages-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { requireNx } from '../../nx';

import type { Tree } from 'nx/src/generators/tree';
import type { PackageManager } from 'nx/src/utils/package-manager';
import { existsSync } from 'fs';
const { detectPackageManager, getPackageManagerCommand, joinPathFragments } =
requireNx();

Expand Down Expand Up @@ -42,7 +43,9 @@ export function installPackagesTask(
cwd: join(tree.root, cwd),
stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit',
};
if (pmc.preInstall) {
// only run preinstall if install hasn't been run yet
// this only happens during CNW when preset is adding its dependencies
if (pmc.preInstall && !existsSync(joinPathFragments(cwd, 'node_modules'))) {
execSync(pmc.preInstall, execSyncOptions);
}
execSync(pmc.install, execSyncOptions);
Expand Down

0 comments on commit 4cbe93b

Please # to comment.