Skip to content

Commit 13e2c93

Browse files
committed
fix(core): @nrwl/js is required for library generation (#484)
1 parent c6e6c40 commit 13e2c93

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

packages/core/src/generators/init/generator.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {
2+
addDependenciesToPackageJson,
3+
GeneratorCallback,
24
logger,
35
NxJsonConfiguration,
46
readJson,
@@ -10,12 +12,14 @@ import {
1012

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

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

2125
const configObject: NxDotnetConfig = initialized
@@ -33,13 +37,34 @@ export async function initGenerator(
3337
if (!initialized) {
3438
updateGitIgnore(host, readWorkspaceConfiguration(host));
3539
addPrepareScript(host);
40+
tasks.push(installNpmPackages(host));
3641
}
3742

3843
initToolManifest(host, dotnetClient);
44+
45+
return async () => {
46+
for (const task of tasks) {
47+
await task();
48+
}
49+
};
3950
}
4051

4152
export default initGenerator;
4253

54+
function installNpmPackages(host: Tree): GeneratorCallback {
55+
const packageJson = readJson<PackageJson>(host, 'package.json');
56+
const nxVersion: string =
57+
packageJson.devDependencies?.['nx'] ??
58+
(packageJson.dependencies?.['nx'] as string);
59+
return addDependenciesToPackageJson(
60+
host,
61+
{},
62+
{
63+
'@nrwl/js': nxVersion,
64+
},
65+
);
66+
}
67+
4368
function updateGitIgnore(
4469
host: Tree,
4570
workspaceConfiguration: WorkspaceConfiguration,

packages/core/src/generators/utils/generate-project.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
NxDotnetProjectGeneratorSchema,
3232
} from '../../models';
3333
import generateSwaggerSetup from '../add-swagger-target/add-swagger-target';
34-
import initSchematic from '../init/generator';
34+
import { initGenerator } from '../init/generator';
3535
import { addToSolutionFile } from './add-to-sln';
3636
import { GenerateTestProject } from './generate-test-project';
3737
import { promptForTemplate } from './prompt-for-template';
@@ -182,7 +182,7 @@ export async function GenerateProject(
182182
dotnetClient: DotNetClient,
183183
projectType: ProjectType,
184184
) {
185-
await initSchematic(host, null, dotnetClient);
185+
const installTask = await initGenerator(host, null, dotnetClient);
186186

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

@@ -253,7 +253,10 @@ export async function GenerateProject(
253253
});
254254
}
255255

256-
await formatFiles(host);
256+
return async () => {
257+
installTask();
258+
await formatFiles(host);
259+
};
257260
}
258261

259262
export function setOutputPath(

smoke/core/tests/nx-dotnet.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('nx-dotnet smoke', () => {
3737

3838
it('should work', async () => {
3939
execSync(
40-
'npx create-nx-workspace@latest test --preset empty --nxCloud false',
40+
'npx create-nx-workspace@latest test --preset ts --nxCloud false',
4141
{
4242
cwd: smokeDirectory,
4343
env: process.env,

0 commit comments

Comments
 (0)