Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): tsconfig should support other formats too #4469

Merged
merged 1 commit into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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}.`);
}
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