diff --git a/e2e/node/src/node-ts-solution.test.ts b/e2e/node/src/node-ts-solution.test.ts index 0afb598677..ec15e7a5aa 100644 --- a/e2e/node/src/node-ts-solution.test.ts +++ b/e2e/node/src/node-ts-solution.test.ts @@ -131,6 +131,45 @@ describe('Node Applications', () => { expect(err).toBeFalsy(); } }, 300_000); + + it('should be able to generate a nest application', async () => { + const nestapp = uniq('nodeapp'); + const port = getRandomPort(); + process.env.PORT = `${port}`; + runCLI( + `generate @nx/nest:app apps/${nestapp} --linter=eslint --unitTestRunner=jest` + ); + + expect(() => runCLI(`lint ${nestapp}`)).not.toThrow(); + expect(() => runCLI(`test ${nestapp}`)).not.toThrow(); + + runCLI(`build ${nestapp}`); + checkFilesExist(`dist/apps/${nestapp}/main.js`); + + const p = await runCommandUntil( + `serve ${nestapp}`, + (output) => + output.includes( + `Application is running on: http://localhost:${port}/api` + ), + + { + env: { + NX_DAEMON: 'true', + }, + } + ); + + const result = await getData(port, '/api'); + expect(result.message).toMatch('Hello'); + + try { + await promisifiedTreeKill(p.pid, 'SIGKILL'); + expect(await killPorts(port)).toBeTruthy(); + } catch (err) { + expect(err).toBeFalsy(); + } + }, 300_000); }); function getRandomPort() { diff --git a/packages/nest/src/generators/application/application.spec.ts b/packages/nest/src/generators/application/application.spec.ts index e61ca42681..e453a96756 100644 --- a/packages/nest/src/generators/application/application.spec.ts +++ b/packages/nest/src/generators/application/application.spec.ts @@ -278,6 +278,7 @@ describe('application generator', () => { { "compilerOptions": { "emitDecoratorMetadata": true, + "experimentalDecorators": true, "module": "nodenext", "moduleResolution": "nodenext", "outDir": "out-tsc/myapp", @@ -307,6 +308,8 @@ describe('application generator', () => { expect(readJson(tree, 'myapp/tsconfig.spec.json')).toMatchInlineSnapshot(` { "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, "module": "nodenext", "moduleResolution": "nodenext", "outDir": "./out-tsc/jest", diff --git a/packages/nest/src/generators/application/lib/update-tsconfig.ts b/packages/nest/src/generators/application/lib/update-tsconfig.ts index 0e93a25a8d..693bb4cabd 100644 --- a/packages/nest/src/generators/application/lib/update-tsconfig.ts +++ b/packages/nest/src/generators/application/lib/update-tsconfig.ts @@ -1,12 +1,14 @@ import type { Tree } from '@nx/devkit'; import { joinPathFragments, updateJson } from '@nx/devkit'; import type { NormalizedOptions } from '../schema'; +import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; export function updateTsConfig(tree: Tree, options: NormalizedOptions): void { updateJson( tree, joinPathFragments(options.appProjectRoot, 'tsconfig.app.json'), (json) => { + json.compilerOptions.experimentalDecorators = true; json.compilerOptions.emitDecoratorMetadata = true; json.compilerOptions.target = 'es2021'; if (options.strict) { @@ -22,4 +24,20 @@ export function updateTsConfig(tree: Tree, options: NormalizedOptions): void { return json; } ); + + // For TS solution, we don't extend from shared tsconfig.json, so we need to make sure decorators are also turned on for spec tsconfig. + if (isUsingTsSolutionSetup(tree)) { + const tsconfigSpecPath = joinPathFragments( + options.appProjectRoot, + 'tsconfig.spec.json' + ); + if (tree.exists(tsconfigSpecPath)) { + updateJson(tree, tsconfigSpecPath, (json) => { + json.compilerOptions ??= {}; + json.compilerOptions.experimentalDecorators = true; + json.compilerOptions.emitDecoratorMetadata = true; + return json; + }); + } + } } diff --git a/packages/node/src/generators/e2e-project/e2e-project.spec.ts b/packages/node/src/generators/e2e-project/e2e-project.spec.ts index 9a9ac35950..beab2e8b32 100644 --- a/packages/node/src/generators/e2e-project/e2e-project.spec.ts +++ b/packages/node/src/generators/e2e-project/e2e-project.spec.ts @@ -153,11 +153,7 @@ describe('e2eProjectGenerator', () => { "jest.config.ts", "src/**/*.ts", ], - "references": [ - { - "path": "../api", - }, - ], + "references": [], } `); }); diff --git a/packages/node/src/generators/e2e-project/files/ts-solution/tsconfig.json__tmpl__ b/packages/node/src/generators/e2e-project/files/ts-solution/tsconfig.json__tmpl__ index 069363a8be..5b51afc787 100644 --- a/packages/node/src/generators/e2e-project/files/ts-solution/tsconfig.json__tmpl__ +++ b/packages/node/src/generators/e2e-project/files/ts-solution/tsconfig.json__tmpl__ @@ -10,7 +10,5 @@ "jest.config.ts", "src/**/*.ts" ], - "references": [ - { "path": "<%= relativeProjectReferencePath %>" } - ] + "references": [] }