Skip to content

Commit

Permalink
fix(@schematics/angular): remove solution style tsconfig from new pro…
Browse files Browse the repository at this point in the history
…jects

Following the issues highlighted in https://docs.google.com/document/d/1eB6cGCG_2ircfS5GzpDC9dBgikeYYcMxghVH5sDESHw/edit?usp=sharing and discussions held with the TypeScript team. The best course of action is to rollback this feature.

In future, it is not excluded that solution style tsconfigs are re-introduced..

Closes #18040 and closes #18170
  • Loading branch information
alan-agius4 authored and filipesilva committed Aug 12, 2020
1 parent fc5d2b3 commit 8b96e52
Show file tree
Hide file tree
Showing 27 changed files with 72 additions and 344 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.base.json",
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
"compilerOptions": {
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/app",
"types": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.base.json",
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
"compilerOptions": {
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/spec",
"types": [
Expand Down
6 changes: 0 additions & 6 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { JSONFile } from '../utility/json-file';
import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { addTsConfigProjectReferences, verifyBaseTsConfigExists } from '../utility/tsconfig';
import { validateProjectName } from '../utility/validation';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders, ProjectType } from '../utility/workspace-models';
Expand Down Expand Up @@ -280,7 +279,6 @@ export default function (options: ApplicationOptions): Rule {
}

validateProjectName(options.name);
verifyBaseTsConfigExists(host);

const appRootSelector = `${options.prefix}-root`;
const componentOptions: Partial<ComponentOptions> = !options.minimal ?
Expand Down Expand Up @@ -363,10 +361,6 @@ export default function (options: ApplicationOptions): Rule {
}),
move(sourceDir),
]), MergeStrategy.Overwrite),
addTsConfigProjectReferences([
join(appDir, 'tsconfig.app.json'),
... options.minimal ? [] : [join(appDir, 'tsconfig.spec.json')],
]),
options.minimal ? noop() : schematic('e2e', e2eOptions),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),
options.lintFix ? applyLintFix(appDir) : noop(),
Expand Down
34 changes: 6 additions & 28 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,6 @@ describe('Application Schematic', () => {
expect(workspace.defaultProject).toBe('foo');
});

it('should add references in solution style tsconfig', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();

const { references } = readJsonFile(tree, '/tsconfig.json');
expect(references).toEqual([
{ path: './projects/foo/tsconfig.app.json' },
{ path: './projects/foo/tsconfig.spec.json' },
]);
});

it('minimal=true should add correct reference in tsconfig', async () => {
const options = { ...defaultOptions, minimal: true };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();

const { references } = readJsonFile(tree, '/tsconfig.json');
expect(references).toEqual([
{ path: './projects/foo/tsconfig.app.json' },
]);
});

it('should set the prefix to app if none is set', async () => {
const options = { ...defaultOptions };

Expand Down Expand Up @@ -166,15 +144,15 @@ describe('Application Schematic', () => {
.toPromise();
const { files, extends: _extends } = readJsonFile(tree, '/projects/foo/tsconfig.app.json');
expect(files).toEqual(['src/main.ts', 'src/polyfills.ts']);
expect(_extends).toBe('../../tsconfig.base.json');
expect(_extends).toBe('../../tsconfig.json');
});

it('should set the right paths in the tsconfig.spec.json', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const { files, extends: _extends } = readJsonFile(tree, '/projects/foo/tsconfig.spec.json');
expect(files).toEqual(['src/test.ts', 'src/polyfills.ts']);
expect(_extends).toBe('../../tsconfig.base.json');
expect(_extends).toBe('../../tsconfig.json');
});

it('should set the right path and prefix in the tslint file', async () => {
Expand Down Expand Up @@ -401,9 +379,9 @@ describe('Application Schematic', () => {
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const appTsConfig = readJsonFile(tree, '/tsconfig.app.json');
expect(appTsConfig.extends).toEqual('./tsconfig.base.json');
expect(appTsConfig.extends).toEqual('./tsconfig.json');
const specTsConfig = readJsonFile(tree, '/tsconfig.spec.json');
expect(specTsConfig.extends).toEqual('./tsconfig.base.json');
expect(specTsConfig.extends).toEqual('./tsconfig.json');
expect(specTsConfig.files).toEqual(['src/test.ts', 'src/polyfills.ts']);
});

Expand Down Expand Up @@ -447,9 +425,9 @@ describe('Application Schematic', () => {
expect(buildOpt.tsConfig).toEqual('foo/tsconfig.app.json');

const appTsConfig = readJsonFile(tree, '/foo/tsconfig.app.json');
expect(appTsConfig.extends).toEqual('../tsconfig.base.json');
expect(appTsConfig.extends).toEqual('../tsconfig.json');
const specTsConfig = readJsonFile(tree, '/foo/tsconfig.spec.json');
expect(specTsConfig.extends).toEqual('../tsconfig.base.json');
expect(specTsConfig.extends).toEqual('../tsconfig.json');
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.base.json",
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
"compilerOptions": {
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/e2e",
"module": "commonjs",
Expand Down
3 changes: 0 additions & 3 deletions packages/schematics/angular/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
url,
} from '@angular-devkit/schematics';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { verifyBaseTsConfigExists } from '../utility/tsconfig';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders } from '../utility/workspace-models';
import { Schema as E2eOptions } from './schema';
Expand All @@ -32,8 +31,6 @@ export default function (options: E2eOptions): Rule {
throw new SchematicsException(`Project name "${appProject}" doesn't not exist.`);
}

verifyBaseTsConfigExists(host);

const root = join(normalize(project.root), 'e2e');

project.targets.add({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.base.json",
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
"compilerOptions": {
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/lib",
"target": "es2015",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.base.json",
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
"compilerOptions": {
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/spec",
"types": [
Expand Down
10 changes: 2 additions & 8 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { NodeDependencyType, addPackageJsonDependency } from '../utility/depende
import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { addTsConfigProjectReferences, verifyBaseTsConfigExists } from '../utility/tsconfig';
import { validateProjectName } from '../utility/validation';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders, ProjectType } from '../utility/workspace-models';
Expand Down Expand Up @@ -59,9 +58,9 @@ function updateJsonFile<T>(host: Tree, path: string, callback: UpdateJsonFn<T>):
function updateTsConfig(packageName: string, ...paths: string[]) {

return (host: Tree) => {
if (!host.exists('tsconfig.base.json')) { return host; }
if (!host.exists('tsconfig.json')) { return host; }

return updateJsonFile(host, 'tsconfig.base.json', (tsconfig: TsConfigPartialType) => {
return updateJsonFile(host, 'tsconfig.json', (tsconfig: TsConfigPartialType) => {
if (!tsconfig.compilerOptions.paths) {
tsconfig.compilerOptions.paths = {};
}
Expand Down Expand Up @@ -174,7 +173,6 @@ export default function (options: LibraryOptions): Rule {
const prefix = options.prefix;

validateProjectName(options.name);
verifyBaseTsConfigExists(host);

// If scoped project (i.e. "@foo/bar"), convert projectDir to "foo/bar".
const projectName = options.name;
Expand Down Expand Up @@ -240,10 +238,6 @@ export default function (options: LibraryOptions): Rule {
path: sourceDir,
project: options.name,
}),
addTsConfigProjectReferences([
`${projectRoot}/tsconfig.lib.json`,
`${projectRoot}/tsconfig.spec.json`,
]),
options.lintFix ? applyLintFix(sourceDir) : noop(),
(_tree: Tree, context: SchematicContext) => {
if (!options.skipPackageJson && !options.skipInstall) {
Expand Down
30 changes: 9 additions & 21 deletions packages/schematics/angular/library/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ describe('Library Schematic', () => {
});
});

describe(`update tsconfig.base.json`, () => {
describe(`update tsconfig.json`, () => {
it(`should add paths mapping to empty tsconfig`, async () => {
const tree = await schematicRunner.runSchematicAsync('library', defaultOptions, workspaceTree).toPromise();

const tsConfigJson = getJsonFileContent(tree, 'tsconfig.base.json');
const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json');
expect(tsConfigJson.compilerOptions.paths.foo).toBeTruthy();
expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(2);
expect(tsConfigJson.compilerOptions.paths.foo[0]).toEqual('dist/foo/foo');
expect(tsConfigJson.compilerOptions.paths.foo[1]).toEqual('dist/foo');
});

it(`should append to existing paths mappings`, async () => {
workspaceTree.overwrite('tsconfig.base.json', JSON.stringify({
workspaceTree.overwrite('tsconfig.json', JSON.stringify({
compilerOptions: {
paths: {
'unrelated': ['./something/else.ts'],
Expand All @@ -224,7 +224,7 @@ describe('Library Schematic', () => {
}));
const tree = await schematicRunner.runSchematicAsync('library', defaultOptions, workspaceTree).toPromise();

const tsConfigJson = getJsonFileContent(tree, 'tsconfig.base.json');
const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json');
expect(tsConfigJson.compilerOptions.paths.foo).toBeTruthy();
expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(3);
expect(tsConfigJson.compilerOptions.paths.foo[1]).toEqual('dist/foo/foo');
Expand All @@ -237,7 +237,7 @@ describe('Library Schematic', () => {
skipTsConfig: true,
}, workspaceTree).toPromise();

const tsConfigJson = getJsonFileContent(tree, 'tsconfig.base.json');
const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json');
expect(tsConfigJson.compilerOptions.paths).toBeUndefined();
});
});
Expand Down Expand Up @@ -266,12 +266,12 @@ describe('Library Schematic', () => {
expect(pkgJson.name).toEqual(scopedName);

const tsConfigJson = getJsonFileContent(tree, '/projects/myscope/mylib/tsconfig.spec.json');
expect(tsConfigJson.extends).toEqual('../../../tsconfig.base.json');
expect(tsConfigJson.extends).toEqual('../../../tsconfig.json');

const cfg = JSON.parse(tree.readContent('/angular.json'));
expect(cfg.projects['@myscope/mylib']).toBeDefined();

const rootTsCfg = getJsonFileContent(tree, '/tsconfig.base.json');
const rootTsCfg = getJsonFileContent(tree, '/tsconfig.json');
expect(rootTsCfg.compilerOptions.paths['@myscope/mylib']).toEqual(['dist/myscope/mylib/myscope-mylib', 'dist/myscope/mylib']);

const karmaConf = getFileContent(tree, '/projects/myscope/mylib/karma.conf.js');
Expand Down Expand Up @@ -316,9 +316,9 @@ describe('Library Schematic', () => {
expect(buildOpt.tsConfig).toEqual('foo/tsconfig.lib.json');

const appTsConfig = getJsonFileContent(tree, '/foo/tsconfig.lib.json');
expect(appTsConfig.extends).toEqual('../tsconfig.base.json');
expect(appTsConfig.extends).toEqual('../tsconfig.json');
const specTsConfig = getJsonFileContent(tree, '/foo/tsconfig.spec.json');
expect(specTsConfig.extends).toEqual('../tsconfig.base.json');
expect(specTsConfig.extends).toEqual('../tsconfig.json');
});

it(`should add 'production' configuration`, async () => {
Expand All @@ -328,16 +328,4 @@ describe('Library Schematic', () => {
const workspace = JSON.parse(tree.readContent('/angular.json'));
expect(workspace.projects.foo.architect.build.configurations.production).toBeDefined();
});

it('should add reference in solution style tsconfig', async () => {
const tree = await schematicRunner.runSchematicAsync('library', defaultOptions, workspaceTree)
.toPromise();

// tslint:disable-next-line:no-any
const { references } = getJsonFileContent(tree, '/tsconfig.json');
expect(references).toEqual([
{ path: './projects/foo/tsconfig.lib.json' },
{ path: './projects/foo/tsconfig.spec.json' },
]);
});
});
2 changes: 1 addition & 1 deletion packages/schematics/angular/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"skipTsConfig": {
"type": "boolean",
"default": false,
"description": "When true, does not update \"tsconfig.base.json\" to add a path mapping for the new library. The path mapping is needed to use the library in an app, but can be disabled here to simplify development."
"description": "When true, does not update \"tsconfig.json\" to add a path mapping for the new library. The path mapping is needed to use the library in an app, but can be disabled here to simplify development."
},
"lintFix": {
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function updateTsconfigExtendsRule(): Rule {
}

// Rename workspace tsconfig to base tsconfig.
host.rename('tsconfig.json', 'tsconfig.base.json');
host.rename('tsconfig.json', 'tsconfig.json');

// Iterate over all tsconfig files and change the extends from 'tsconfig.json' 'tsconfig.base.json'
// Iterate over all tsconfig files and change the extends from 'tsconfig.json' 'tsconfig.json'
for (const [tsconfigPath, extendsAst] of visitExtendedJsonFiles(host.root, context.logger)) {
const tsConfigDir = dirname(normalize(tsconfigPath));
if ('/tsconfig.json' !== resolve(tsConfigDir, normalize(extendsAst.value))) {
Expand Down Expand Up @@ -127,7 +127,7 @@ export default function (): Rule {
return (host, context) => {
const logger = context.logger;

if (host.exists('tsconfig.base.json')) {
if (host.exists('tsconfig.json')) {
logger.info('Migration has already been executed.');

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ describe('Migration to create "Solution Style" tsconfig', () => {
createJsonFile(tree, 'src/tsconfig.worker.json', { extends: './../tsconfig.json', compilerOptions });
});

it(`should rename 'tsconfig.json' to 'tsconfig.base.json'`, async () => {
it(`should rename 'tsconfig.json' to 'tsconfig.json'`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('tsconfig.base.json')).toBeTrue();
expect(newTree.exists('tsconfig.json')).toBeTrue();
});

it(`should update extends from 'tsconfig.json' to 'tsconfig.base.json'`, async () => {
it(`should update extends from 'tsconfig.json' to 'tsconfig.json'`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(readJsonFile(newTree, 'src/tsconfig.json').extends).toEqual('./../tsconfig.base.json');
expect(readJsonFile(newTree, 'src/tsconfig.spec.json').extends).toEqual('./../tsconfig.base.json');
expect(readJsonFile(newTree, 'src/tsconfig.worker.json').extends).toEqual('./../tsconfig.base.json');
expect(readJsonFile(newTree, 'src/tsconfig.json').extends).toEqual('./../tsconfig.json');
expect(readJsonFile(newTree, 'src/tsconfig.spec.json').extends).toEqual('./../tsconfig.json');
expect(readJsonFile(newTree, 'src/tsconfig.worker.json').extends).toEqual('./../tsconfig.json');
});

it('should not update extends if not extended the root tsconfig', async () => {
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Migration to create "Solution Style" tsconfig', () => {
it('should not error out when a JSON file is a blank', async () => {
tree.create('blank.json', '');
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(readJsonFile(newTree, 'src/tsconfig.json').extends).toEqual('./../tsconfig.base.json');
expect(readJsonFile(newTree, 'src/tsconfig.json').extends).toEqual('./../tsconfig.json');
});

it('should show warning with full path when parsing invalid JSON', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default function (): Rule {
return async (host, { logger }) => {
// Workspace level tsconfig
try {
updateModuleAndTarget(host, 'tsconfig.base.json', {
updateModuleAndTarget(host, 'tsconfig.json', {
oldModule: 'esnext',
newModule: 'es2020',
});
} catch (error) {
logger.warn(
`Unable to update 'tsconfig.base.json' module option from 'esnext' to 'es2020': ${
`Unable to update 'tsconfig.json' module option from 'esnext' to 'es2020': ${
error.message || error
}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Migration to update target and module compiler options', () => {
const compilerOptions = { target: 'es2015', module: 'esnext' };

// Workspace
createJsonFile(tree, 'tsconfig.base.json', { compilerOptions });
createJsonFile(tree, 'tsconfig.json', { compilerOptions });

// Application
createJsonFile(tree, 'src/tsconfig.app.json', { compilerOptions });
Expand All @@ -106,19 +106,19 @@ describe('Migration to update target and module compiler options', () => {
createJsonFile(tree, 'src/tsconfig.server.json', { compilerOptions: { module: 'commonjs' } });
});

it(`should update module and target in workspace 'tsconfig.base.json'`, async () => {
it(`should update module and target in workspace 'tsconfig.json'`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { module } = readJsonFile(newTree, 'tsconfig.base.json').compilerOptions;
const { module } = readJsonFile(newTree, 'tsconfig.json').compilerOptions;
expect(module).toBe('es2020');
});

it(`should update module and target in 'tsconfig.base.json' which is referenced in option`, async () => {
it(`should update module and target in 'tsconfig.json' which is referenced in option`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { module } = readJsonFile(newTree, 'src/tsconfig.spec.json').compilerOptions;
expect(module).toBe('es2020');
});

it(`should update module and target in 'tsconfig.base.json' which is referenced in a configuration`, async () => {
it(`should update module and target in 'tsconfig.json' which is referenced in a configuration`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { module } = readJsonFile(newTree, 'src/tsconfig.app.prod.json').compilerOptions;
expect(module).toBe('es2020');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Migration to version 9', () => {
.toPromise();

// Pre version 9 - tsconfig.json was the base tsconfig file.
tree.overwrite('tsconfig.json', tree.readContent('tsconfig.base.json'));
tree.overwrite('tsconfig.json', tree.readContent('tsconfig.json'));
});

it('should update apps tsConfig with stricter files inclusions', async () => {
Expand Down
Loading

0 comments on commit 8b96e52

Please sign in to comment.