Skip to content

Commit

Permalink
feat(misc): do not generate tsconfig.base.json for simple standalone … (
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin authored Dec 5, 2022
1 parent eb3242a commit 91c19f5
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 386 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# 4 space indentation
[*.{js,ts,jsx,tsx}]
indent_style = space
indent_size = 2

[package.json]
indent_style = space
indent_size = 2

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ export function createFiles(tree: Tree, options: NormalizedSchema) {
options.appProjectRoot,
{
...options,
rootTsConfigPath: getRelativePathToRootTsConfig(
tree,
options.appProjectRoot
),
tpl: '',
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ import {
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import { E2eTestRunner, UnitTestRunner } from '../../../../utils/test-runners';
import type { NormalizedSchema } from './normalized-schema';
import {
createTsConfig,
extractTsConfigBase,
} from '../../../utils/create-ts-config';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

export function updateConfigFiles(host: Tree, options: NormalizedSchema) {
if (!options.rootProject) {
extractTsConfigBase(host);
}
updateTsConfigOptions(host, options);
updateAppAndE2EProjectConfigurations(host, options);
}
Expand All @@ -36,14 +44,13 @@ function updateTsConfigOptions(host: Tree, options: NormalizedSchema) {
],
}));

// tsconfig.json
updateJson(host, `${options.appProjectRoot}/tsconfig.json`, (json) => ({
...json,
compilerOptions: {
...json.compilerOptions,
target: 'es2020',
},
}));
createTsConfig(
host,
options.appProjectRoot,
'app',
options,
getRelativePathToRootTsConfig(host, options.appProjectRoot)
);
}

function updateAppAndE2EProjectConfigurations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,7 @@ describe('app', () => {
expect(appTree.exists('src/app/app.module.ts')).toBe(true);
expect(appTree.exists('src/app/app.component.ts')).toBe(true);
expect(appTree.exists('e2e/cypress.config.ts')).toBe(true);
expect(readJson(appTree, 'tsconfig.json').extends).toEqual(
'./tsconfig.base.json'
);
expect(readJson(appTree, 'tsconfig.json').extends).toBeUndefined();
const project = readProjectConfiguration(appTree, 'my-app');
expect(project.targets.build.options['outputPath']).toBe('dist/my-app');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,6 @@ describe('app', () => {
expect(appTsConfig.extends).toBe('../../tsconfig.base.json');
});

it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
// ARRANGE
appTree.rename('tsconfig.base.json', 'tsconfig.json');

// ACT
await generateApp(appTree, 'app');

// ASSERT
const appTsConfig = readJson(appTree, 'apps/app/tsconfig.json');
expect(appTsConfig.extends).toBe('../../tsconfig.json');
});

it('should set default project', async () => {
// ACT
await generateApp(appTree);
Expand Down Expand Up @@ -339,18 +327,6 @@ describe('app', () => {
const appTsConfig = readJson(appTree, 'apps/my-dir/app/tsconfig.json');
expect(appTsConfig.extends).toBe('../../../tsconfig.base.json');
});

it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
// ARRANGE
appTree.rename('tsconfig.base.json', 'tsconfig.json');

// ACT
await generateApp(appTree, 'app', { directory: 'myDir' });

// ASSERT
const appTsConfig = readJson(appTree, 'apps/my-dir/app/tsconfig.json');
expect(appTsConfig.extends).toBe('../../../tsconfig.json');
});
});

describe('at the root', () => {
Expand Down
10 changes: 0 additions & 10 deletions packages/angular/src/generators/application/files/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners';
import type { NormalizedSchema } from './normalized-schema';
import { createTsConfig } from '../../utils/create-ts-config';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

export function updateConfigFiles(host: Tree, options: NormalizedSchema) {
updateTsConfigOptions(host, options);
Expand All @@ -37,14 +39,13 @@ function updateTsConfigOptions(host: Tree, options: NormalizedSchema) {
}));

// tsconfig.json
updateJson(host, `${options.appProjectRoot}/tsconfig.json`, (json) => ({
...json,
compilerOptions: {
...json.compilerOptions,
target: 'es2022',
useDefineForClassFields: false, // This will eventually need updated when Angular switch to using TC39 Compliant code
},
}));
createTsConfig(
host,
options.appProjectRoot,
'app',
options,
getRelativePathToRootTsConfig(host, options.appProjectRoot)
);
}

function updateAppAndE2EProjectConfigurations(
Expand Down

This file was deleted.

25 changes: 16 additions & 9 deletions packages/angular/src/generators/library/lib/update-tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { Tree } from '@nrwl/devkit';
import { joinPathFragments, updateJson } from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import {
getRelativePathToRootTsConfig,
getRootTsConfigPathInTree,
} from '@nrwl/workspace/src/utilities/typescript';
import { NormalizedSchema } from './normalized-schema';
import {
createTsConfig,
extractTsConfigBase,
} from '../../utils/create-ts-config';

function updateRootConfig(
host: Tree,
Expand Down Expand Up @@ -44,14 +51,13 @@ function updateProjectConfig(
});

// tsconfig.json
updateJson(host, `${options.projectRoot}/tsconfig.json`, (json) => ({
...json,
compilerOptions: {
...json.compilerOptions,
target: 'es2022',
useDefineForClassFields: false,
},
}));
createTsConfig(
host,
options.projectRoot,
'lib',
options,
getRelativePathToRootTsConfig(host, options.projectRoot)
);
}

function updateProjectIvyConfig(
Expand All @@ -75,6 +81,7 @@ export function updateTsConfig(
host: Tree,
options: NormalizedSchema['libraryOptions']
) {
extractTsConfigBase(host);
updateRootConfig(host, options);
updateProjectConfig(host, options);
updateProjectIvyConfig(host, options);
Expand Down
57 changes: 2 additions & 55 deletions packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,13 @@ describe('lib', () => {
});
});

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

// ACT
await runLibraryGeneratorWithOpts();

// ASSERT
const appTsConfig = readJson(tree, 'libs/my-lib/tsconfig.json');
expect(appTsConfig.extends).toBe('../../tsconfig.json');
expect(appTsConfig.extends).toBe('../../tsconfig.base.json');
});

it('should check for existence of spec files before deleting them', async () => {
Expand Down Expand Up @@ -663,56 +660,6 @@ describe('lib', () => {
tsconfigJson.compilerOptions.paths['my-dir-my-lib/*']
).toBeUndefined();
});

it('should create a local tsconfig.json', async () => {
// ACT
await runLibraryGeneratorWithOpts({ directory: 'myDir' });

// ASSERT
const tsconfigJson = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json');

expect(tsconfigJson).toEqual({
extends: '../../../tsconfig.base.json',
angularCompilerOptions: {
enableI18nLegacyMessageIdFormat: false,
strictInjectionParameters: true,
strictInputAccessModifiers: true,
strictTemplates: true,
},
compilerOptions: {
forceConsistentCasingInFileNames: true,
noFallthroughCasesInSwitch: true,
noPropertyAccessFromIndexSignature: true,
noImplicitOverride: true,
noImplicitReturns: true,
strict: true,
target: 'es2022',
useDefineForClassFields: false,
},
files: [],
include: [],
references: [
{
path: './tsconfig.lib.json',
},
{
path: './tsconfig.spec.json',
},
],
});
});

it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
// ARRANGE
tree.rename('tsconfig.base.json', 'tsconfig.json');

// ACT
await runLibraryGeneratorWithOpts({ directory: 'myDir' });

// ASSERT
const appTsConfig = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json');
expect(appTsConfig.extends).toBe('../../../tsconfig.json');
});
});

describe('at the root', () => {
Expand Down
42 changes: 42 additions & 0 deletions packages/angular/src/generators/utils/create-ts-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Tree } from 'nx/src/generators/tree';
import { tsConfigBaseOptions } from '@nrwl/workspace/src/utils/create-ts-config';
import { writeJson } from 'nx/src/generators/utils/json';
export { extractTsConfigBase } from '@nrwl/workspace/src/utils/create-ts-config';

export function createTsConfig(
host: Tree,
projectRoot: string,
type: 'app' | 'lib',
options: {
strict?: boolean;
style?: string;
bundler?: string;
rootProject?: boolean;
},
relativePathToRootTsConfig: string
) {
const json = {
compilerOptions: {
target: 'es2022',
useDefineForClassFields: false,
},
files: [],
include: [],
references: [
{
path: type === 'app' ? './tsconfig.app.json' : './tsconfig.lib.json',
},
],
} as any;

// inline tsconfig.base.json into the project
if (options.rootProject) {
json.compileOnSave = false;
json.compilerOptions = { ...tsConfigBaseOptions, ...json.compilerOptions };
json.exclude = ['node_modules', 'tmp'];
} else {
json.extends = relativePathToRootTsConfig;
}

writeJson(host, `${projectRoot}/tsconfig.json`, json);
}
Loading

1 comment on commit 91c19f5

@vercel
Copy link

@vercel vercel bot commented on 91c19f5 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.