Skip to content

Commit

Permalink
fix(build): use baseUrl and paths from tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Oct 2, 2016
1 parent b224395 commit 8b8c5ff
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/angular-cli/models/webpack-build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const webpack = require('webpack');
const atl = require('awesome-typescript-loader');

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

Expand All @@ -11,7 +12,12 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
devtool: 'inline-source-map',
context: path.resolve(__dirname, './'),
resolve: {
extensions: ['.ts', '.js']
extensions: ['.ts', '.js'],
plugins: [
new atl.TsConfigPathsPlugin({
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
})
]
},
entry: {
test: path.resolve(appRoot, appConfig.test)
Expand Down
7 changes: 7 additions & 0 deletions packages/angular-cli/models/webpack-build-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo
const lazyModules = findLazyModules(appRoot);

return {
resolve: {
plugins: [
new atl.TsConfigPathsPlugin({
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
})
]
},
module: {
rules: [
{
Expand Down
7 changes: 2 additions & 5 deletions packages/angular-cli/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ export default <any>Task.extend({

if (err) {
lastHash = null;
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
reject(err.details);
console.error(err.details || err);
reject(err.details || err);
}

if (stats.hash !== lastHash) {
Expand Down
35 changes: 35 additions & 0 deletions tests/e2e/tests/build/ts-paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {updateTsConfig} from '../../utils/project';
import {writeMultipleFiles, appendToFile} from '../../utils/fs';
import {ng} from '../../utils/process';
import {stripIndents} from 'common-tags';


export default function() {
return updateTsConfig(json => {
json['compilerOptions']['baseUrl'] = '.';
json['compilerOptions']['paths'] = {
'@shared': [
'app/shared'
],
'@shared/*': [
'app/shared/*'
]
};
})
.then(() => writeMultipleFiles({
'src/shared/meaning.ts': 'export var meaning = 42;',
'src/shared/index.ts': `export * from './meaning'`
}))
.then(() => appendToFile('src/app/app.component.ts', stripIndents`
import { meaning } from 'app/shared/meaning';
import { meaning as meaning2 } from '@shared';
import { meaning as meaning3 } from '@shared/meaning';
// need to use imports otherwise they are ignored and
// no error is outputted, even if baseUrl/paths don't work
console.log(meaning)
console.log(meaning2)
console.log(meaning3)
`))
.then(() => ng('build'));
}
5 changes: 5 additions & 0 deletions tests/e2e/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export function replaceInFile(filePath: string, match: RegExp, replacement: stri
}


export function appendToFile(filePath: string, text: string) {
return readFile(filePath)
.then((content: string) => writeFile(filePath, content.concat(text)));
}


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

0 comments on commit 8b8c5ff

Please sign in to comment.