Skip to content

Commit 3aacf41

Browse files
dmorosinottoKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@schematics/angular): regression tsconfig.json #16708 (#16709)
* fix(@schematics/angular): regression tsconfig.json 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 * 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 * 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 * 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
1 parent 237c1dc commit 3aacf41

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

packages/schematics/angular/library/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function updateJsonFile<T>(host: Tree, path: string, callback: UpdateJsonFn<T>):
5555
return host;
5656
}
5757

58-
function updateTsConfig(packageName: string, distRoot: string) {
58+
function updateTsConfig(packageName: string, ...paths: string[]) {
5959

6060
return (host: Tree) => {
6161
if (!host.exists('tsconfig.json')) { return host; }
@@ -67,7 +67,7 @@ function updateTsConfig(packageName: string, distRoot: string) {
6767
if (!tsconfig.compilerOptions.paths[packageName]) {
6868
tsconfig.compilerOptions.paths[packageName] = [];
6969
}
70-
tsconfig.compilerOptions.paths[packageName].push(distRoot);
70+
tsconfig.compilerOptions.paths[packageName].push(...paths);
7171
});
7272
};
7373
}
@@ -192,6 +192,7 @@ export default function (options: LibraryOptions): Rule {
192192
const folderName = `${scopeFolder}${strings.dasherize(options.name)}`;
193193
const projectRoot = join(normalize(newProjectRoot), folderName);
194194
const distRoot = `dist/${folderName}`;
195+
const pathImportLib = `${distRoot}/${folderName.replace('/', '-')}`;
195196
const sourceDir = `${projectRoot}/src/lib`;
196197

197198
const templateSource = apply(url('./files'), [
@@ -214,7 +215,7 @@ export default function (options: LibraryOptions): Rule {
214215
mergeWith(templateSource),
215216
addLibToWorkspaceFile(options, projectRoot, projectName),
216217
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
217-
options.skipTsConfig ? noop() : updateTsConfig(packageName, distRoot),
218+
options.skipTsConfig ? noop() : updateTsConfig(packageName, pathImportLib, distRoot),
218219
schematic('module', {
219220
name: options.name,
220221
commonModule: false,

packages/schematics/angular/library/index_spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ describe('Library Schematic', () => {
206206

207207
const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json');
208208
expect(tsConfigJson.compilerOptions.paths.foo).toBeTruthy();
209-
expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(1);
210-
expect(tsConfigJson.compilerOptions.paths.foo[0]).toEqual('dist/foo');
209+
expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(2);
210+
expect(tsConfigJson.compilerOptions.paths.foo[0]).toEqual('dist/foo/foo');
211+
expect(tsConfigJson.compilerOptions.paths.foo[1]).toEqual('dist/foo');
211212
});
212213

213214
it(`should append to existing paths mappings`, async () => {
@@ -223,8 +224,9 @@ describe('Library Schematic', () => {
223224

224225
const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json');
225226
expect(tsConfigJson.compilerOptions.paths.foo).toBeTruthy();
226-
expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(2);
227-
expect(tsConfigJson.compilerOptions.paths.foo[1]).toEqual('dist/foo');
227+
expect(tsConfigJson.compilerOptions.paths.foo.length).toEqual(3);
228+
expect(tsConfigJson.compilerOptions.paths.foo[1]).toEqual('dist/foo/foo');
229+
expect(tsConfigJson.compilerOptions.paths.foo[2]).toEqual('dist/foo');
228230
});
229231

230232
it(`should not modify the file when --skipTsConfig`, async () => {
@@ -268,7 +270,7 @@ describe('Library Schematic', () => {
268270
expect(cfg.projects['@myscope/mylib']).toBeDefined();
269271

270272
const rootTsCfg = JSON.parse(tree.readContent('/tsconfig.json'));
271-
expect(rootTsCfg.compilerOptions.paths['@myscope/mylib']).toEqual(['dist/myscope/mylib']);
273+
expect(rootTsCfg.compilerOptions.paths['@myscope/mylib']).toEqual(['dist/myscope/mylib/myscope-mylib', 'dist/myscope/mylib']);
272274

273275
const karmaConf = getFileContent(tree, '/projects/myscope/mylib/karma.conf.js');
274276
expect(karmaConf).toContain(`dir: require('path').join(__dirname, '../../../coverage/myscope/mylib')`);

packages/schematics/angular/workspace/files/tsconfig.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compileOnSave": false,
33
"compilerOptions": {
44
"baseUrl": "./",
5-
"outDir": "./dist",<% if (strict) { %>
5+
"outDir": "./dist/out-tsc",<% if (strict) { %>
66
"noImplicitAny": true,
77
"noImplicitReturns": true,
88
"noImplicitThis": true,

0 commit comments

Comments
 (0)