Skip to content

Commit aa87de7

Browse files
sumitarorahansl
authored andcommitted
fix(config): tsconfig should support other formats too (#4469)
1 parent d43fa14 commit aa87de7

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

packages/@angular/cli/models/config/config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3+
import * as ts from 'typescript';
34

45
import {SchemaClass, SchemaClassFactory} from '@ngtools/json-schema';
56

@@ -70,11 +71,11 @@ export class CliConfig<JsonType> {
7071

7172
static fromConfigPath<T>(configPath: string, otherPath: string[] = []): CliConfig<T> {
7273
const configContent = fs.existsSync(configPath)
73-
? fs.readFileSync(configPath, 'utf-8')
74+
? ts.sys.readFile(configPath)
7475
: '{}';
7576
const schemaContent = fs.readFileSync(DEFAULT_CONFIG_SCHEMA_PATH, 'utf-8');
7677
const otherContents = otherPath
77-
.map(path => fs.existsSync(path) && fs.readFileSync(path, 'utf-8'))
78+
.map(path => fs.existsSync(path) && ts.sys.readFile(path))
7879
.filter(content => !!content);
7980

8081
let content: T;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class AotPlugin implements Tapable {
104104

105105
let tsConfigJson: any = null;
106106
try {
107-
tsConfigJson = JSON.parse(fs.readFileSync(this._tsConfigPath, 'utf8'));
107+
tsConfigJson = JSON.parse(ts.sys.readFile(this._tsConfigPath));
108108
} catch (err) {
109109
throw new Error(`An error happened while parsing ${this._tsConfigPath} JSON: ${err}.`);
110110
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {ng} from '../../utils/process';
2+
import * as fs from '../../utils/fs';
3+
4+
5+
const options = {
6+
encoding: 'utf8'
7+
};
8+
9+
10+
export default function() {
11+
return Promise.resolve()
12+
.then(() => fs.prependToFile('./src/tsconfig.json', '\ufeff', options))
13+
.then(() => fs.prependToFile('./angular-cli.json', '\ufeff', options))
14+
.then(() => ng('build', '--env=dev'));
15+
}

tests/e2e/utils/fs.ts

+6-6
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 {
@@ -97,15 +97,15 @@ export function replaceInFile(filePath: string, match: RegExp, replacement: stri
9797
}
9898

9999

100-
export function appendToFile(filePath: string, text: string) {
100+
export function appendToFile(filePath: string, text: string, options?: any) {
101101
return readFile(filePath)
102-
.then((content: string) => writeFile(filePath, content.concat(text)));
102+
.then((content: string) => writeFile(filePath, content.concat(text), options));
103103
}
104104

105105

106-
export function prependToFile(filePath: string, text: string) {
106+
export function prependToFile(filePath: string, text: string, options?: any) {
107107
return readFile(filePath)
108-
.then((content: string) => writeFile(filePath, text.concat(content)));
108+
.then((content: string) => writeFile(filePath, text.concat(content), options));
109109
}
110110

111111

0 commit comments

Comments
 (0)