From e7e494df00bc65877cf206a726270d51af880d72 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 18 Aug 2023 10:16:26 +0200 Subject: [PATCH] fix(core): move pre install into new --- packages/devkit/src/tasks/install-packages-task.ts | 6 ------ packages/workspace/src/generators/new/new.ts | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/devkit/src/tasks/install-packages-task.ts b/packages/devkit/src/tasks/install-packages-task.ts index 2426fc95c62dfd..99ceaf4a2a6538 100644 --- a/packages/devkit/src/tasks/install-packages-task.ts +++ b/packages/devkit/src/tasks/install-packages-task.ts @@ -4,7 +4,6 @@ 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(); @@ -43,11 +42,6 @@ export function installPackagesTask( cwd: join(tree.root, cwd), stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit', }; - // 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); } } diff --git a/packages/workspace/src/generators/new/new.ts b/packages/workspace/src/generators/new/new.ts index d4483a5a1897f9..5909835c0b4c36 100644 --- a/packages/workspace/src/generators/new/new.ts +++ b/packages/workspace/src/generators/new/new.ts @@ -1,5 +1,6 @@ import { addDependenciesToPackageJson, + getPackageManagerCommand, installPackagesTask, names, PackageManager, @@ -11,6 +12,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 +50,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: host.root, + 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 (