Skip to content

Commit

Permalink
fix(core): @nrwl/js is required for library generation (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Aug 1, 2022
1 parent c6e6c40 commit 13e2c93
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
25 changes: 25 additions & 0 deletions packages/core/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
addDependenciesToPackageJson,
GeneratorCallback,
logger,
NxJsonConfiguration,
readJson,
Expand All @@ -10,12 +12,14 @@ import {

import { DotNetClient, dotnetFactory } from '@nx-dotnet/dotnet';
import { CONFIG_FILE_PATH, isDryRun, NxDotnetConfig } from '@nx-dotnet/utils';
import type { PackageJson } from 'nx/src/utils/package-json';

export async function initGenerator(
host: Tree,
_: null, // Nx will populate this with options, which are currently unused.
dotnetClient = new DotNetClient(dotnetFactory()),
) {
const tasks: GeneratorCallback[] = [];
const initialized = host.isFile(CONFIG_FILE_PATH);

const configObject: NxDotnetConfig = initialized
Expand All @@ -33,13 +37,34 @@ export async function initGenerator(
if (!initialized) {
updateGitIgnore(host, readWorkspaceConfiguration(host));
addPrepareScript(host);
tasks.push(installNpmPackages(host));
}

initToolManifest(host, dotnetClient);

return async () => {
for (const task of tasks) {
await task();
}
};
}

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,
},
);
}

function updateGitIgnore(
host: Tree,
workspaceConfiguration: WorkspaceConfiguration,
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/generators/utils/generate-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
NxDotnetProjectGeneratorSchema,
} from '../../models';
import generateSwaggerSetup from '../add-swagger-target/add-swagger-target';
import initSchematic from '../init/generator';
import { initGenerator } from '../init/generator';
import { addToSolutionFile } from './add-to-sln';
import { GenerateTestProject } from './generate-test-project';
import { promptForTemplate } from './prompt-for-template';
Expand Down Expand Up @@ -182,7 +182,7 @@ export async function GenerateProject(
dotnetClient: DotNetClient,
projectType: ProjectType,
) {
await initSchematic(host, null, dotnetClient);
const installTask = await initGenerator(host, null, dotnetClient);

options.testTemplate = options.testTemplate ?? 'none';

Expand Down Expand Up @@ -253,7 +253,10 @@ export async function GenerateProject(
});
}

await formatFiles(host);
return async () => {
installTask();
await formatFiles(host);
};
}

export function setOutputPath(
Expand Down
2 changes: 1 addition & 1 deletion smoke/core/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('nx-dotnet smoke', () => {

it('should work', async () => {
execSync(
'npx create-nx-workspace@latest test --preset empty --nxCloud false',
'npx create-nx-workspace@latest test --preset ts --nxCloud false',
{
cwd: smokeDirectory,
env: process.env,
Expand Down

0 comments on commit 13e2c93

Please sign in to comment.