Skip to content

Commit

Permalink
fix(config): tsconfig should support other formats too (#4469)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitarora authored and hansl committed Feb 8, 2017
1 parent d43fa14 commit aa87de7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/@angular/cli/models/config/config.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -70,11 +71,11 @@ export class CliConfig<JsonType> {

static fromConfigPath<T>(configPath: string, otherPath: string[] = []): CliConfig<T> {
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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}.`);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/tests/misc/different-file-format.ts
Original file line number Diff line number Diff line change
@@ -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'));
}
12 changes: 6 additions & 6 deletions tests/e2e/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve, reject) => {
fs.writeFile(fileName, content, (err: any) => {
fs.writeFile(fileName, content, options, (err: any) => {
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -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));
}


Expand Down

0 comments on commit aa87de7

Please sign in to comment.