Skip to content

Commit

Permalink
fix(misc): set nx property in root package.json when no replacing scr…
Browse files Browse the repository at this point in the history
…ipt in nx init (#21974)
  • Loading branch information
leosvelperez authored Feb 23, 2024
1 parent c2581dc commit 5161e41
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions packages/nx/src/command-line/init/init-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { output } from '../../utils/output';
import { getPackageManagerCommand } from '../../utils/package-manager';
import { generateDotNxSetup } from './implementation/dot-nx/add-nx-scripts';
import { runNxSync } from '../../utils/child-process';
import { readJsonFile } from '../../utils/fileutils';
import { readJsonFile, writeJsonFile } from '../../utils/fileutils';
import { nxVersion } from '../../utils/versions';
import {
addDepsToPackageJson,
Expand All @@ -21,6 +21,7 @@ import { globWithWorkspaceContext } from '../../utils/workspace-context';
import { connectExistingRepoToNxCloudPrompt } from '../connect/connect-to-nx-cloud';
import { addNxToNpmRepo } from './implementation/add-nx-to-npm-repo';
import { addNxToMonorepo } from './implementation/add-nx-to-monorepo';
import { join } from 'path';

export interface InitArgs {
interactive: boolean;
Expand Down Expand Up @@ -87,27 +88,32 @@ export async function initHandler(options: InitArgs): Promise<void> {
createNxJsonFile(repoRoot, [], [], {});
updateGitIgnore(repoRoot);

addDepsToPackageJson(repoRoot, detectPluginsResponse?.plugins ?? []);
addDepsToPackageJson(repoRoot, detectPluginsResponse.plugins);

output.log({ title: '📦 Installing Nx' });

runInstall(repoRoot, pmc);

if (detectPluginsResponse) {
output.log({ title: '🔨 Configuring plugins' });
for (const plugin of detectPluginsResponse.plugins) {
execSync(
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
detectPluginsResponse.updatePackageScripts
? '--updatePackageScripts'
: ''
} --no-interactive`,
{
stdio: [0, 1, 2],
cwd: repoRoot,
}
);
}
output.log({ title: '🔨 Configuring plugins' });
for (const plugin of detectPluginsResponse.plugins) {
execSync(
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
detectPluginsResponse.updatePackageScripts
? '--updatePackageScripts'
: ''
} --no-interactive`,
{
stdio: [0, 1, 2],
cwd: repoRoot,
}
);
}

if (!detectPluginsResponse.updatePackageScripts) {
const rootPackageJsonPath = join(repoRoot, 'package.json');
const json = readJsonFile<PackageJson>(rootPackageJsonPath);
json.nx = {};
writeJsonFile(rootPackageJsonPath, json);
}

if (useNxCloud) {
Expand Down

0 comments on commit 5161e41

Please sign in to comment.