From 223cfffe381555ca035709113dc8cfacb3fd1fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 8 Jan 2025 17:19:31 +0100 Subject: [PATCH] feat(js): simplify generated tsconfig.base.json compiler options in ts solution setup --- .../ts-solution/tsconfig.base.json__tmpl__ | 16 +----- packages/js/src/generators/init/init.spec.ts | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/packages/js/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ b/packages/js/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ index 8dcc4290023ec..20df75790409c 100644 --- a/packages/js/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ +++ b/packages/js/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ @@ -1,17 +1,9 @@ { "compilerOptions": { - "allowJs": false, - "allowSyntheticDefaultImports": true, "composite": true, - "declaration": true, "declarationMap": true, "emitDeclarationOnly": true, - "emitDecoratorMetadata": false, - "esModuleInterop": true, - "experimentalDecorators": false, - "forceConsistentCasingInFileNames": true, "importHelpers": true, - "incremental": true, "isolatedModules": true, "lib": ["es2022"], "module": "NodeNext", @@ -21,14 +13,8 @@ "noImplicitOverride": true, "noImplicitReturns": true, "noUnusedLocals": true, - "pretty": true, - "removeComments": false, - "resolveJsonModule": false, - "skipDefaultLibCheck": false, "skipLibCheck": true, - "sourceMap": false, "strict": true, - "target": "es2022", - "verbatimModuleSyntax": false + "target": "es2022" } } diff --git a/packages/js/src/generators/init/init.spec.ts b/packages/js/src/generators/init/init.spec.ts index a3835c059c4d8..cbcfcdc582df4 100644 --- a/packages/js/src/generators/init/init.spec.ts +++ b/packages/js/src/generators/init/init.spec.ts @@ -1,4 +1,4 @@ -import { writeJson, readJson, Tree, updateJson } from '@nx/devkit'; +import { writeJson, readJson, Tree, updateJson, readNxJson } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import init from './init'; import { typescriptVersion } from '../../utils/versions'; @@ -166,4 +166,52 @@ describe('js init generator', () => { expect(!!packageJson.devDependencies?.['tslib']).toBe(shouldAdd); } ); + + it('should register the @nx/js/typescript plugin when addTsPlugin is true', async () => { + await init(tree, { addTsPlugin: true }); + + const nxJson = readNxJson(tree); + const typescriptPlugin = nxJson.plugins.find( + (plugin) => + typeof plugin === 'object' && plugin.plugin === '@nx/js/typescript' + ); + expect(typescriptPlugin).toBeDefined(); + }); + + it('should create tsconfig.json and tsconfig.base.json files when addTsPlugin is true', async () => { + await init(tree, { addTsPlugin: true }); + + expect(tree.read('tsconfig.json', 'utf-8')).toMatchInlineSnapshot(` + "{ + "extends": "./tsconfig.base.json", + "compileOnSave": false, + "files": [], + "references": [] + } + " + `); + expect(tree.read('tsconfig.base.json', 'utf-8')).toMatchInlineSnapshot(` + "{ + "compilerOptions": { + "composite": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "importHelpers": true, + "isolatedModules": true, + "lib": ["es2022"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noEmitOnError": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "skipLibCheck": true, + "strict": true, + "target": "es2022" + } + } + " + `); + }); });