Skip to content

Commit

Permalink
feat(js): simplify generated tsconfig.base.json compiler options in t…
Browse files Browse the repository at this point in the history
…s solution setup
  • Loading branch information
leosvelperez committed Jan 8, 2025
1 parent 160800e commit 223cfff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
50 changes: 49 additions & 1 deletion packages/js/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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"
}
}
"
`);
});
});

0 comments on commit 223cfff

Please sign in to comment.