Skip to content

Commit 3fac58f

Browse files
committed
fix(config): tsconfig should support other formats too
1 parent 2f5f74d commit 3fac58f

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

packages/@ngtools/webpack/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class AotPlugin implements Tapable {
103103

104104
let tsConfigJson: any = null;
105105
try {
106-
tsConfigJson = JSON.parse(fs.readFileSync(this._tsConfigPath, 'utf8'));
106+
tsConfigJson = JSON.parse(ts.sys.readFile(this._tsConfigPath));
107107
} catch (err) {
108108
throw new Error(`An error happened while parsing ${this._tsConfigPath} JSON: ${err}.`);
109109
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {ng} from '../../utils/process';
2+
import * as fs from '../../utils/fs';
3+
import {getGlobalVariable} from '../../utils/env';
4+
import {expectGitToBeClean} from '../../utils/git';
5+
import {join} from 'path';
6+
7+
const tsconfig = `{
8+
"compilerOptions": {
9+
"baseUrl": "",
10+
"declaration": false,
11+
"emitDecoratorMetadata": true,
12+
"experimentalDecorators": true,
13+
"lib": [
14+
"es2016",
15+
"dom"
16+
],
17+
"mapRoot": "./",
18+
"module": "es2015",
19+
"moduleResolution": "node",
20+
"outDir": "../dist/out-tsc",
21+
"sourceMap": true,
22+
"target": "es5",
23+
"typeRoots": [
24+
"../node_modules/@types"
25+
]
26+
}
27+
}`;
28+
29+
const options = {
30+
encoding: 'utf8'
31+
};
32+
33+
export default function() {
34+
return Promise.resolve()
35+
.then(() => process.chdir(getGlobalVariable('tmp-root')))
36+
.then(() => ng('new', 'foo'))
37+
.then(() => fs.expectFileToExist(join(process.cwd(), 'foo')))
38+
.then(() => process.chdir('./foo'))
39+
.then(() => fs.deleteFile('./src/tsconfig.json'))
40+
.then(() => fs.writeFile('./src/tsconfig.json', '\ufeff' + tsconfig, options))
41+
.then(() => ng('build', '--env=dev'))
42+
.then(() => fs.expectFileToMatch('dist/index.html', 'main.bundle.js'))
43+
.then(() => expectGitToBeClean());
44+
}

tests/e2e/utils/fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export function readFile(fileName: string) {
1515
});
1616
}
1717

18-
export function writeFile(fileName: string, content: string) {
18+
export function writeFile(fileName: string, content: string, options?: any) {
1919
return new Promise<void>((resolve, reject) => {
20-
fs.writeFile(fileName, content, (err: any) => {
20+
fs.writeFile(fileName, content, options, (err: any) => {
2121
if (err) {
2222
reject(err);
2323
} else {

0 commit comments

Comments
 (0)