Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c62b87e

Browse files
committedFeb 8, 2017
fix(config): tsconfig should support other formats too
1 parent 1ce50fa commit c62b87e

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed
 

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

Lines changed: 3 additions & 2 deletions
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

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: 15 additions & 0 deletions
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

Lines changed: 6 additions & 6 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 {
@@ -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)
Please sign in to comment.