From a9df43695dcf573adacbde14bd84a2d499da9283 Mon Sep 17 00:00:00 2001 From: Daniele Morosinotto Date: Sun, 19 Jan 2020 18:17:00 +0100 Subject: [PATCH 1/4] fix(@schematics/angular): regression tsconfig.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(@schematics/angular): regression tsconfig.json … Unverified 0e318ae Regression in tsconfig.json set `"outDir": "./dist/out-tsc"` for problems in VSCode TS(2307) when building library referred in tsconfig "paths" Closes: #16708 --- .../schematics/angular/workspace/files/tsconfig.json.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/schematics/angular/workspace/files/tsconfig.json.template b/packages/schematics/angular/workspace/files/tsconfig.json.template index f89b38bbce6c..b1ce7545b64c 100644 --- a/packages/schematics/angular/workspace/files/tsconfig.json.template +++ b/packages/schematics/angular/workspace/files/tsconfig.json.template @@ -2,7 +2,7 @@ "compileOnSave": false, "compilerOptions": { "baseUrl": "./", - "outDir": "./dist",<% if (strict) { %> + "outDir": "./dist/out-tsc",<% if (strict) { %> "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, From 07b9d45fa5985c2055893cbf985d5f00da6e198e Mon Sep 17 00:00:00 2001 From: Daniele Morosinotto Date: Mon, 20 Jan 2020 19:19:21 +0100 Subject: [PATCH 2/4] fix(@schematics/angular): regression tsconfig.json Improve paths in root tsconfig.json for better DX experience when using auto imports in IDE's. Closes #16709 --- packages/schematics/angular/library/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/schematics/angular/library/index.ts b/packages/schematics/angular/library/index.ts index 4ffcb1ff8fd0..791763b1b1eb 100644 --- a/packages/schematics/angular/library/index.ts +++ b/packages/schematics/angular/library/index.ts @@ -55,7 +55,7 @@ function updateJsonFile(host: Tree, path: string, callback: UpdateJsonFn): return host; } -function updateTsConfig(packageName: string, distRoot: string) { +function updateTsConfig(packageName: string, ...paths: string[]) { return (host: Tree) => { if (!host.exists('tsconfig.json')) { return host; } @@ -67,7 +67,7 @@ function updateTsConfig(packageName: string, distRoot: string) { if (!tsconfig.compilerOptions.paths[packageName]) { tsconfig.compilerOptions.paths[packageName] = []; } - tsconfig.compilerOptions.paths[packageName].push(distRoot); + tsconfig.compilerOptions.paths[packageName].push(...paths); }); }; } @@ -192,6 +192,7 @@ export default function (options: LibraryOptions): Rule { const folderName = `${scopeFolder}${strings.dasherize(options.name)}`; const projectRoot = join(normalize(newProjectRoot), folderName); const distRoot = `dist/${folderName}`; + const pathImportLib = `${distRoot}/${folderName.replace('/','-')}`; const sourceDir = `${projectRoot}/src/lib`; const templateSource = apply(url('./files'), [ @@ -214,7 +215,7 @@ export default function (options: LibraryOptions): Rule { mergeWith(templateSource), addLibToWorkspaceFile(options, projectRoot, projectName), options.skipPackageJson ? noop() : addDependenciesToPackageJson(), - options.skipTsConfig ? noop() : updateTsConfig(packageName, distRoot), + options.skipTsConfig ? noop() : updateTsConfig(packageName, pathImportLib, distRoot), schematic('module', { name: options.name, commonModule: false, From a6fdd5a3ad5d36be2a8ec1f952610219251c6e00 Mon Sep 17 00:00:00 2001 From: Daniele Morosinotto Date: Mon, 20 Jan 2020 19:52:23 +0100 Subject: [PATCH 3/4] fix(@schematics/angular): regression tsconfig.json Improve paths in root tsconfig.json for better DX experience when using auto imports in IDE's. Fix code lint. Closes #16709 --- packages/schematics/angular/library/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/schematics/angular/library/index.ts b/packages/schematics/angular/library/index.ts index 791763b1b1eb..dfa719e9fd83 100644 --- a/packages/schematics/angular/library/index.ts +++ b/packages/schematics/angular/library/index.ts @@ -192,7 +192,7 @@ export default function (options: LibraryOptions): Rule { const folderName = `${scopeFolder}${strings.dasherize(options.name)}`; const projectRoot = join(normalize(newProjectRoot), folderName); const distRoot = `dist/${folderName}`; - const pathImportLib = `${distRoot}/${folderName.replace('/','-')}`; + const pathImportLib = `${distRoot}/${folderName.replace('/', '-')}`; const sourceDir = `${projectRoot}/src/lib`; const templateSource = apply(url('./files'), [ From fc68986c03a39a3c6e3dca9bf66a1df41ef83070 Mon Sep 17 00:00:00 2001 From: Daniele Morosinotto Date: Mon, 20 Jan 2020 20:15:11 +0100 Subject: [PATCH 4/4] fix(@schematics/angular): regression tsconfig.json Improve paths in root tsconfig.json for better DX experience when using auto imports in IDE's. Fix test code to conform new behaviour. Closes #16709 --- packages/schematics/angular/library/index_spec.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/schematics/angular/library/index_spec.ts b/packages/schematics/angular/library/index_spec.ts index 609fa1d4c51d..977dd8bf9043 100644 --- a/packages/schematics/angular/library/index_spec.ts +++ b/packages/schematics/angular/library/index_spec.ts @@ -206,8 +206,9 @@ describe('Library Schematic', () => { const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json'); expect(tsConfigJson.compilerOptions.paths.foo).toBeTruthy(); - expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(1); - expect(tsConfigJson.compilerOptions.paths.foo[0]).toEqual('dist/foo'); + 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 () => { @@ -223,8 +224,9 @@ describe('Library Schematic', () => { 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[1]).toEqual('dist/foo'); + expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(3); + expect(tsConfigJson.compilerOptions.paths.foo[1]).toEqual('dist/foo/foo'); + expect(tsConfigJson.compilerOptions.paths.foo[2]).toEqual('dist/foo'); }); it(`should not modify the file when --skipTsConfig`, async () => { @@ -268,7 +270,7 @@ describe('Library Schematic', () => { expect(cfg.projects['@myscope/mylib']).toBeDefined(); const rootTsCfg = JSON.parse(tree.readContent('/tsconfig.json')); - expect(rootTsCfg.compilerOptions.paths['@myscope/mylib']).toEqual(['dist/myscope/mylib']); + 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'); expect(karmaConf).toContain(`dir: require('path').join(__dirname, '../../../coverage/myscope/mylib')`);