From adb39c464dcc3cbbc46fd0d5eef6a0e81a71e6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Fri, 18 Aug 2023 23:30:33 +0200 Subject: [PATCH] fix(core): ensure preinstall is only run once on repo (#18671) --- packages/devkit/src/tasks/install-packages-task.ts | 3 --- packages/workspace/src/generators/new/new.ts | 10 ++++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/devkit/src/tasks/install-packages-task.ts b/packages/devkit/src/tasks/install-packages-task.ts index 05adbf0632a61..99ceaf4a2a653 100644 --- a/packages/devkit/src/tasks/install-packages-task.ts +++ b/packages/devkit/src/tasks/install-packages-task.ts @@ -42,9 +42,6 @@ export function installPackagesTask( cwd: join(tree.root, cwd), stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit', }; - if (pmc.preInstall) { - execSync(pmc.preInstall, execSyncOptions); - } execSync(pmc.install, execSyncOptions); } } diff --git a/packages/workspace/src/generators/new/new.ts b/packages/workspace/src/generators/new/new.ts index d4483a5a1897f..c1cad2e2361aa 100644 --- a/packages/workspace/src/generators/new/new.ts +++ b/packages/workspace/src/generators/new/new.ts @@ -1,6 +1,8 @@ import { addDependenciesToPackageJson, + getPackageManagerCommand, installPackagesTask, + joinPathFragments, names, PackageManager, Tree, @@ -11,6 +13,7 @@ import { Preset } from '../utils/presets'; import { Linter } from '../../utils/lint'; import { generateWorkspaceFiles } from './generate-workspace-files'; import { addPresetDependencies, generatePreset } from './generate-preset'; +import { execSync } from 'child_process'; interface Schema { directory: string; @@ -48,6 +51,13 @@ export async function newGenerator(host: Tree, opts: Schema) { addCloudDependencies(host, options); return async () => { + const pmc = getPackageManagerCommand(options.packageManager); + if (pmc.preInstall) { + execSync(pmc.preInstall, { + cwd: joinPathFragments(host.root, options.directory), + stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit', + }); + } installPackagesTask(host, false, options.directory, options.packageManager); // TODO: move all of these into create-nx-workspace if (