Skip to content

Commit

Permalink
fix(core): remove dependency on workspace package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Feb 24, 2023
1 parent 04c1f1d commit d95a3ff
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions packages/core/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import type { PackageJson } from 'nx/src/utils/package-json';
import * as path from 'path';

const noop = () => void 0;

export async function initGenerator(
host: Tree,
_: null, // Nx will populate this with options, which are currently unused.
Expand Down Expand Up @@ -59,17 +61,21 @@ export async function initGenerator(
export default initGenerator;

function installNpmPackages(host: Tree): GeneratorCallback {
const packageJson = readJson<PackageJson>(host, 'package.json');
const nxVersion: string =
packageJson.devDependencies?.['nx'] ??
(packageJson.dependencies?.['nx'] as string);
return addDependenciesToPackageJson(
host,
{},
{
'@nrwl/js': nxVersion,
},
);
if (host.exists('package.json')) {
const packageJson = readJson<PackageJson>(host, 'package.json');
const nxVersion: string =
packageJson.devDependencies?.['nx'] ??
(packageJson.dependencies?.['nx'] as string);
return addDependenciesToPackageJson(
host,
{},
{
'@nrwl/js': nxVersion,
},
);
} else {
return noop;
}
}

function updateNxJson(host: Tree) {
Expand All @@ -90,18 +96,20 @@ function initToolManifest(host: Tree, dotnetClient: DotNetClient) {
}

function addPrepareScript(host: Tree) {
const packageJson = readJson(host, 'package.json');
const prepareSteps: string[] =
packageJson.scripts?.prepare?.split('&&').map((x: string) => x.trim()) ??
[];

const restoreScript = 'nx g @nx-dotnet/core:restore';
if (!prepareSteps.includes(restoreScript)) {
prepareSteps.push(restoreScript);
if (host.exists('package.json')) {
const packageJson = readJson(host, 'package.json');
const prepareSteps: string[] =
packageJson.scripts?.prepare?.split('&&').map((x: string) => x.trim()) ??
[];

const restoreScript = 'nx g @nx-dotnet/core:restore';
if (!prepareSteps.includes(restoreScript)) {
prepareSteps.push(restoreScript);
}
packageJson.scripts ??= {};
packageJson.scripts.prepare = prepareSteps.join(' && ');
writeJson(host, 'package.json', packageJson);
}
packageJson.scripts ??= {};
packageJson.scripts.prepare = prepareSteps.join(' && ');
writeJson(host, 'package.json', packageJson);
}

function initBuildCustomization(host: Tree) {
Expand Down

0 comments on commit d95a3ff

Please sign in to comment.