Skip to content

Commit

Permalink
fix(core): move pre install into new
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Aug 18, 2023
1 parent d9ce015 commit e7e494d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 0 additions & 6 deletions packages/devkit/src/tasks/install-packages-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}
9 changes: 9 additions & 0 deletions packages/workspace/src/generators/new/new.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
addDependenciesToPackageJson,
getPackageManagerCommand,
installPackagesTask,
names,
PackageManager,
Expand All @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit e7e494d

Please sign in to comment.