diff --git a/packages/@angular/cli/models/config/config.ts b/packages/@angular/cli/models/config/config.ts index 37290ed3808d..594e5aab1225 100644 --- a/packages/@angular/cli/models/config/config.ts +++ b/packages/@angular/cli/models/config/config.ts @@ -1,5 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; +import * as ts from 'typescript'; import {SchemaClass, SchemaClassFactory} from '@ngtools/json-schema'; @@ -70,11 +71,11 @@ export class CliConfig { static fromConfigPath(configPath: string, otherPath: string[] = []): CliConfig { const configContent = fs.existsSync(configPath) - ? fs.readFileSync(configPath, 'utf-8') + ? ts.sys.readFile(configPath) : '{}'; const schemaContent = fs.readFileSync(DEFAULT_CONFIG_SCHEMA_PATH, 'utf-8'); const otherContents = otherPath - .map(path => fs.existsSync(path) && fs.readFileSync(path, 'utf-8')) + .map(path => fs.existsSync(path) && ts.sys.readFile(path)) .filter(content => !!content); let content: T; diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index acf7e2b2f629..e744a0a04532 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -103,7 +103,7 @@ export class AotPlugin implements Tapable { let tsConfigJson: any = null; try { - tsConfigJson = JSON.parse(fs.readFileSync(this._tsConfigPath, 'utf8')); + tsConfigJson = JSON.parse(ts.sys.readFile(this._tsConfigPath)); } catch (err) { throw new Error(`An error happened while parsing ${this._tsConfigPath} JSON: ${err}.`); } diff --git a/tests/e2e/tests/misc/different-file-format.ts b/tests/e2e/tests/misc/different-file-format.ts new file mode 100644 index 000000000000..d3bb097f9955 --- /dev/null +++ b/tests/e2e/tests/misc/different-file-format.ts @@ -0,0 +1,15 @@ +import {ng} from '../../utils/process'; +import * as fs from '../../utils/fs'; + + +const options = { + encoding: 'utf8' +}; + + +export default function() { + return Promise.resolve() + .then(() => fs.prependToFile('./src/tsconfig.json', '\ufeff', options)) + .then(() => fs.prependToFile('./angular-cli.json', '\ufeff', options)) + .then(() => ng('build', '--env=dev')); +} diff --git a/tests/e2e/utils/fs.ts b/tests/e2e/utils/fs.ts index b1f8606c0184..fa53ad0725a7 100644 --- a/tests/e2e/utils/fs.ts +++ b/tests/e2e/utils/fs.ts @@ -15,9 +15,9 @@ export function readFile(fileName: string) { }); } -export function writeFile(fileName: string, content: string) { +export function writeFile(fileName: string, content: string, options?: any) { return new Promise((resolve, reject) => { - fs.writeFile(fileName, content, (err: any) => { + fs.writeFile(fileName, content, options, (err: any) => { if (err) { reject(err); } else { @@ -97,15 +97,15 @@ export function replaceInFile(filePath: string, match: RegExp, replacement: stri } -export function appendToFile(filePath: string, text: string) { +export function appendToFile(filePath: string, text: string, options?: any) { return readFile(filePath) - .then((content: string) => writeFile(filePath, content.concat(text))); + .then((content: string) => writeFile(filePath, content.concat(text), options)); } -export function prependToFile(filePath: string, text: string) { +export function prependToFile(filePath: string, text: string, options?: any) { return readFile(filePath) - .then((content: string) => writeFile(filePath, text.concat(content))); + .then((content: string) => writeFile(filePath, text.concat(content), options)); }