Skip to content

Commit 32e60b7

Browse files
filipesilvahansl
authored andcommitted
fix(build): use baseUrl and paths from tsconfig (#2470)
1 parent cb598b9 commit 32e60b7

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

packages/angular-cli/models/webpack-build-test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const path = require('path');
44
const webpack = require('webpack');
5+
const atl = require('awesome-typescript-loader');
56

67
const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
78

@@ -11,7 +12,12 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
1112
devtool: 'inline-source-map',
1213
context: path.resolve(__dirname, './'),
1314
resolve: {
14-
extensions: ['.ts', '.js']
15+
extensions: ['.ts', '.js'],
16+
plugins: [
17+
new atl.TsConfigPathsPlugin({
18+
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
19+
})
20+
]
1521
},
1622
entry: {
1723
test: path.resolve(appRoot, appConfig.test)

packages/angular-cli/models/webpack-build-typescript.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo
1616
const lazyModules = findLazyModules(appRoot);
1717

1818
return {
19+
resolve: {
20+
plugins: [
21+
new atl.TsConfigPathsPlugin({
22+
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
23+
})
24+
]
25+
},
1926
module: {
2027
rules: [
2128
{

packages/angular-cli/tasks/build-webpack.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ export default <any>Task.extend({
4545

4646
if (err) {
4747
lastHash = null;
48-
console.error(err.stack || err);
49-
if (err.details) {
50-
console.error(err.details);
51-
}
52-
reject(err.details);
48+
console.error(err.details || err);
49+
reject(err.details || err);
5350
}
5451

5552
if (stats.hash !== lastHash) {

tests/e2e/tests/build/ts-paths.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {updateTsConfig} from '../../utils/project';
2+
import {writeMultipleFiles, appendToFile} from '../../utils/fs';
3+
import {ng} from '../../utils/process';
4+
import {stripIndents} from 'common-tags';
5+
6+
7+
export default function() {
8+
return updateTsConfig(json => {
9+
json['compilerOptions']['baseUrl'] = '.';
10+
json['compilerOptions']['paths'] = {
11+
'@shared': [
12+
'app/shared'
13+
],
14+
'@shared/*': [
15+
'app/shared/*'
16+
]
17+
};
18+
})
19+
.then(() => writeMultipleFiles({
20+
'src/app/shared/meaning.ts': 'export var meaning = 42;',
21+
'src/app/shared/index.ts': `export * from './meaning'`
22+
}))
23+
.then(() => appendToFile('src/app/app.component.ts', stripIndents`
24+
import { meaning } from 'app/shared/meaning';
25+
import { meaning as meaning2 } from '@shared';
26+
import { meaning as meaning3 } from '@shared/meaning';
27+
28+
// need to use imports otherwise they are ignored and
29+
// no error is outputted, even if baseUrl/paths don't work
30+
console.log(meaning)
31+
console.log(meaning2)
32+
console.log(meaning3)
33+
`))
34+
.then(() => ng('build'));
35+
}

tests/e2e/utils/fs.ts

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export function replaceInFile(filePath: string, match: RegExp, replacement: stri
9393
}
9494

9595

96+
export function appendToFile(filePath: string, text: string) {
97+
return readFile(filePath)
98+
.then((content: string) => writeFile(filePath, content.concat(text)));
99+
}
100+
96101

97102
export function expectFileToExist(fileName: string) {
98103
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)