Skip to content

Commit 91c19f5

Browse files
authored
feat(misc): do not generate tsconfig.base.json for simple standalone … (nrwl#13605)
1 parent eb3242a commit 91c19f5

25 files changed

+263
-386
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# 4 space indentation
12+
[*.{js,ts,jsx,tsx}]
13+
indent_style = space
14+
indent_size = 2
15+
16+
[package.json]
17+
indent_style = space
18+
indent_size = 2

packages/angular/src/generators/application/angular-v14/files/tsconfig.json

-10
This file was deleted.

packages/angular/src/generators/application/angular-v14/lib/create-files.ts

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ export function createFiles(tree: Tree, options: NormalizedSchema) {
1010
options.appProjectRoot,
1111
{
1212
...options,
13-
rootTsConfigPath: getRelativePathToRootTsConfig(
14-
tree,
15-
options.appProjectRoot
16-
),
1713
tpl: '',
1814
}
1915
);

packages/angular/src/generators/application/angular-v14/lib/update-config-files.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ import {
1111
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
1212
import { E2eTestRunner, UnitTestRunner } from '../../../../utils/test-runners';
1313
import type { NormalizedSchema } from './normalized-schema';
14+
import {
15+
createTsConfig,
16+
extractTsConfigBase,
17+
} from '../../../utils/create-ts-config';
18+
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
1419

1520
export function updateConfigFiles(host: Tree, options: NormalizedSchema) {
21+
if (!options.rootProject) {
22+
extractTsConfigBase(host);
23+
}
1624
updateTsConfigOptions(host, options);
1725
updateAppAndE2EProjectConfigurations(host, options);
1826
}
@@ -36,14 +44,13 @@ function updateTsConfigOptions(host: Tree, options: NormalizedSchema) {
3644
],
3745
}));
3846

39-
// tsconfig.json
40-
updateJson(host, `${options.appProjectRoot}/tsconfig.json`, (json) => ({
41-
...json,
42-
compilerOptions: {
43-
...json.compilerOptions,
44-
target: 'es2020',
45-
},
46-
}));
47+
createTsConfig(
48+
host,
49+
options.appProjectRoot,
50+
'app',
51+
options,
52+
getRelativePathToRootTsConfig(host, options.appProjectRoot)
53+
);
4754
}
4855

4956
function updateAppAndE2EProjectConfigurations(

packages/angular/src/generators/application/application.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,7 @@ describe('app', () => {
10731073
expect(appTree.exists('src/app/app.module.ts')).toBe(true);
10741074
expect(appTree.exists('src/app/app.component.ts')).toBe(true);
10751075
expect(appTree.exists('e2e/cypress.config.ts')).toBe(true);
1076-
expect(readJson(appTree, 'tsconfig.json').extends).toEqual(
1077-
'./tsconfig.base.json'
1078-
);
1076+
expect(readJson(appTree, 'tsconfig.json').extends).toBeUndefined();
10791077
const project = readProjectConfiguration(appTree, 'my-app');
10801078
expect(project.targets.build.options['outputPath']).toBe('dist/my-app');
10811079
});

packages/angular/src/generators/application/application.v14.spec.ts

-24
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,6 @@ describe('app', () => {
214214
expect(appTsConfig.extends).toBe('../../tsconfig.base.json');
215215
});
216216

217-
it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
218-
// ARRANGE
219-
appTree.rename('tsconfig.base.json', 'tsconfig.json');
220-
221-
// ACT
222-
await generateApp(appTree, 'app');
223-
224-
// ASSERT
225-
const appTsConfig = readJson(appTree, 'apps/app/tsconfig.json');
226-
expect(appTsConfig.extends).toBe('../../tsconfig.json');
227-
});
228-
229217
it('should set default project', async () => {
230218
// ACT
231219
await generateApp(appTree);
@@ -339,18 +327,6 @@ describe('app', () => {
339327
const appTsConfig = readJson(appTree, 'apps/my-dir/app/tsconfig.json');
340328
expect(appTsConfig.extends).toBe('../../../tsconfig.base.json');
341329
});
342-
343-
it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
344-
// ARRANGE
345-
appTree.rename('tsconfig.base.json', 'tsconfig.json');
346-
347-
// ACT
348-
await generateApp(appTree, 'app', { directory: 'myDir' });
349-
350-
// ASSERT
351-
const appTsConfig = readJson(appTree, 'apps/my-dir/app/tsconfig.json');
352-
expect(appTsConfig.extends).toBe('../../../tsconfig.json');
353-
});
354330
});
355331

356332
describe('at the root', () => {

packages/angular/src/generators/application/files/tsconfig.json

-10
This file was deleted.

packages/angular/src/generators/application/lib/update-config-files.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
1212
import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners';
1313
import type { NormalizedSchema } from './normalized-schema';
14+
import { createTsConfig } from '../../utils/create-ts-config';
15+
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
1416

1517
export function updateConfigFiles(host: Tree, options: NormalizedSchema) {
1618
updateTsConfigOptions(host, options);
@@ -37,14 +39,13 @@ function updateTsConfigOptions(host: Tree, options: NormalizedSchema) {
3739
}));
3840

3941
// tsconfig.json
40-
updateJson(host, `${options.appProjectRoot}/tsconfig.json`, (json) => ({
41-
...json,
42-
compilerOptions: {
43-
...json.compilerOptions,
44-
target: 'es2022',
45-
useDefineForClassFields: false, // This will eventually need updated when Angular switch to using TC39 Compliant code
46-
},
47-
}));
42+
createTsConfig(
43+
host,
44+
options.appProjectRoot,
45+
'app',
46+
options,
47+
getRelativePathToRootTsConfig(host, options.appProjectRoot)
48+
);
4849
}
4950

5051
function updateAppAndE2EProjectConfigurations(

packages/angular/src/generators/library/files/lib/tsconfig.json__tpl__

-14
This file was deleted.

packages/angular/src/generators/library/lib/update-tsconfig.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import type { Tree } from '@nrwl/devkit';
22
import { joinPathFragments, updateJson } from '@nrwl/devkit';
3-
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
3+
import {
4+
getRelativePathToRootTsConfig,
5+
getRootTsConfigPathInTree,
6+
} from '@nrwl/workspace/src/utilities/typescript';
47
import { NormalizedSchema } from './normalized-schema';
8+
import {
9+
createTsConfig,
10+
extractTsConfigBase,
11+
} from '../../utils/create-ts-config';
512

613
function updateRootConfig(
714
host: Tree,
@@ -44,14 +51,13 @@ function updateProjectConfig(
4451
});
4552

4653
// tsconfig.json
47-
updateJson(host, `${options.projectRoot}/tsconfig.json`, (json) => ({
48-
...json,
49-
compilerOptions: {
50-
...json.compilerOptions,
51-
target: 'es2022',
52-
useDefineForClassFields: false,
53-
},
54-
}));
54+
createTsConfig(
55+
host,
56+
options.projectRoot,
57+
'lib',
58+
options,
59+
getRelativePathToRootTsConfig(host, options.projectRoot)
60+
);
5561
}
5662

5763
function updateProjectIvyConfig(
@@ -75,6 +81,7 @@ export function updateTsConfig(
7581
host: Tree,
7682
options: NormalizedSchema['libraryOptions']
7783
) {
84+
extractTsConfigBase(host);
7885
updateRootConfig(host, options);
7986
updateProjectConfig(host, options);
8087
updateProjectIvyConfig(host, options);

packages/angular/src/generators/library/library.spec.ts

+2-55
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,13 @@ describe('lib', () => {
313313
});
314314
});
315315

316-
it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
317-
// ARRANGE
316+
it('should create tsconfig.base.json when it is missing', async () => {
318317
tree.rename('tsconfig.base.json', 'tsconfig.json');
319318

320-
// ACT
321319
await runLibraryGeneratorWithOpts();
322320

323-
// ASSERT
324321
const appTsConfig = readJson(tree, 'libs/my-lib/tsconfig.json');
325-
expect(appTsConfig.extends).toBe('../../tsconfig.json');
322+
expect(appTsConfig.extends).toBe('../../tsconfig.base.json');
326323
});
327324

328325
it('should check for existence of spec files before deleting them', async () => {
@@ -663,56 +660,6 @@ describe('lib', () => {
663660
tsconfigJson.compilerOptions.paths['my-dir-my-lib/*']
664661
).toBeUndefined();
665662
});
666-
667-
it('should create a local tsconfig.json', async () => {
668-
// ACT
669-
await runLibraryGeneratorWithOpts({ directory: 'myDir' });
670-
671-
// ASSERT
672-
const tsconfigJson = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json');
673-
674-
expect(tsconfigJson).toEqual({
675-
extends: '../../../tsconfig.base.json',
676-
angularCompilerOptions: {
677-
enableI18nLegacyMessageIdFormat: false,
678-
strictInjectionParameters: true,
679-
strictInputAccessModifiers: true,
680-
strictTemplates: true,
681-
},
682-
compilerOptions: {
683-
forceConsistentCasingInFileNames: true,
684-
noFallthroughCasesInSwitch: true,
685-
noPropertyAccessFromIndexSignature: true,
686-
noImplicitOverride: true,
687-
noImplicitReturns: true,
688-
strict: true,
689-
target: 'es2022',
690-
useDefineForClassFields: false,
691-
},
692-
files: [],
693-
include: [],
694-
references: [
695-
{
696-
path: './tsconfig.lib.json',
697-
},
698-
{
699-
path: './tsconfig.spec.json',
700-
},
701-
],
702-
});
703-
});
704-
705-
it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
706-
// ARRANGE
707-
tree.rename('tsconfig.base.json', 'tsconfig.json');
708-
709-
// ACT
710-
await runLibraryGeneratorWithOpts({ directory: 'myDir' });
711-
712-
// ASSERT
713-
const appTsConfig = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json');
714-
expect(appTsConfig.extends).toBe('../../../tsconfig.json');
715-
});
716663
});
717664

718665
describe('at the root', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Tree } from 'nx/src/generators/tree';
2+
import { tsConfigBaseOptions } from '@nrwl/workspace/src/utils/create-ts-config';
3+
import { writeJson } from 'nx/src/generators/utils/json';
4+
export { extractTsConfigBase } from '@nrwl/workspace/src/utils/create-ts-config';
5+
6+
export function createTsConfig(
7+
host: Tree,
8+
projectRoot: string,
9+
type: 'app' | 'lib',
10+
options: {
11+
strict?: boolean;
12+
style?: string;
13+
bundler?: string;
14+
rootProject?: boolean;
15+
},
16+
relativePathToRootTsConfig: string
17+
) {
18+
const json = {
19+
compilerOptions: {
20+
target: 'es2022',
21+
useDefineForClassFields: false,
22+
},
23+
files: [],
24+
include: [],
25+
references: [
26+
{
27+
path: type === 'app' ? './tsconfig.app.json' : './tsconfig.lib.json',
28+
},
29+
],
30+
} as any;
31+
32+
// inline tsconfig.base.json into the project
33+
if (options.rootProject) {
34+
json.compileOnSave = false;
35+
json.compilerOptions = { ...tsConfigBaseOptions, ...json.compilerOptions };
36+
json.exclude = ['node_modules', 'tmp'];
37+
} else {
38+
json.extends = relativePathToRootTsConfig;
39+
}
40+
41+
writeJson(host, `${projectRoot}/tsconfig.json`, json);
42+
}

0 commit comments

Comments
 (0)