From bf2b559ea167c44da836c19f35a17e6d30d6ee78 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 2 Feb 2024 10:11:18 -0500 Subject: [PATCH] fix(nest): ensure dependencies are installed when generating nest libraries --- e2e/node/src/node.test.ts | 2 +- packages/nest/src/generators/application/application.ts | 2 +- packages/nest/src/generators/application/lib/index.ts | 1 - packages/nest/src/generators/library/library.ts | 4 +++- .../application/lib => utils}/ensure-dependencies.ts | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) rename packages/nest/src/{generators/application/lib => utils}/ensure-dependencies.ts (94%) diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index 486ef9aaeab698..c576f3f4610421 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -593,7 +593,7 @@ ${jslib}(); ); }, 60000); - it('should be able to generate a nest library w/ service', async () => { + it('xyz should be able to generate a nest library w/ service', async () => { const nestlib = uniq('nestlib'); runCLI(`generate @nx/nest:lib ${nestlib} --service`); diff --git a/packages/nest/src/generators/application/application.ts b/packages/nest/src/generators/application/application.ts index 0f78ef166b754b..9e40ce58accc2a 100644 --- a/packages/nest/src/generators/application/application.ts +++ b/packages/nest/src/generators/application/application.ts @@ -5,12 +5,12 @@ import { applicationGenerator as nodeApplicationGenerator } from '@nx/node'; import { initGenerator } from '../init/init'; import { createFiles, - ensureDependencies, normalizeOptions, toNodeApplicationGeneratorOptions, updateTsConfig, } from './lib'; import type { ApplicationGeneratorOptions } from './schema'; +import { ensureDependencies } from '../../utils/ensure-dependencies'; export async function applicationGenerator( tree: Tree, diff --git a/packages/nest/src/generators/application/lib/index.ts b/packages/nest/src/generators/application/lib/index.ts index 038e52c310855b..06951360844239 100644 --- a/packages/nest/src/generators/application/lib/index.ts +++ b/packages/nest/src/generators/application/lib/index.ts @@ -1,4 +1,3 @@ export * from './create-files'; -export * from './ensure-dependencies'; export * from './normalize-options'; export * from './update-tsconfig'; diff --git a/packages/nest/src/generators/library/library.ts b/packages/nest/src/generators/library/library.ts index 8c3f8bea954f67..96f998f58b90f7 100644 --- a/packages/nest/src/generators/library/library.ts +++ b/packages/nest/src/generators/library/library.ts @@ -1,7 +1,6 @@ import type { GeneratorCallback, Tree } from '@nx/devkit'; import { formatFiles, runTasksInSerial } from '@nx/devkit'; import { libraryGenerator as jsLibraryGenerator } from '@nx/js'; -import { addDependencies } from '../init/lib'; import { addExportsToBarrelFile, addProject, @@ -14,6 +13,7 @@ import { import type { LibraryGeneratorOptions } from './schema'; import initGenerator from '../init/init'; import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command'; +import { ensureDependencies } from '../../utils/ensure-dependencies'; export async function libraryGenerator( tree: Tree, @@ -33,6 +33,7 @@ export async function libraryGeneratorInternal( const options = await normalizeOptions(tree, rawOptions); await jsLibraryGenerator(tree, toJsLibraryGeneratorOptions(options)); const initTask = await initGenerator(tree, rawOptions); + const depsTask = ensureDependencies(tree); deleteFiles(tree, options); createFiles(tree, options); addExportsToBarrelFile(tree, options); @@ -46,6 +47,7 @@ export async function libraryGeneratorInternal( return runTasksInSerial( ...[ initTask, + depsTask, () => { logShowProjectCommand(options.projectName); }, diff --git a/packages/nest/src/generators/application/lib/ensure-dependencies.ts b/packages/nest/src/utils/ensure-dependencies.ts similarity index 94% rename from packages/nest/src/generators/application/lib/ensure-dependencies.ts rename to packages/nest/src/utils/ensure-dependencies.ts index 5bade7c309356d..1d9e3ce1447c88 100644 --- a/packages/nest/src/generators/application/lib/ensure-dependencies.ts +++ b/packages/nest/src/utils/ensure-dependencies.ts @@ -5,7 +5,7 @@ import { reflectMetadataVersion, rxjsVersion, tsLibVersion, -} from '../../../utils/versions'; +} from './versions'; export function ensureDependencies(tree: Tree): GeneratorCallback { return addDependenciesToPackageJson(