From 754ee6fc90f41b7520905c2a4ae30278f6e6b579 Mon Sep 17 00:00:00 2001 From: Charles Lyding Date: Sat, 4 Mar 2017 01:29:04 -0500 Subject: [PATCH] fix(@ngtools/webpack): allow comments in tsconfig files --- packages/@ngtools/webpack/src/plugin.ts | 13 ++++++++----- tests/e2e/assets/webpack/test-app/tsconfig.json | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index bff8a01e15ef..5f510ccd5c50 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -108,13 +108,16 @@ export class AotPlugin implements Tapable { basePath = path.resolve(process.cwd(), options.basePath); } - let tsConfigJson: any = null; - try { - tsConfigJson = JSON.parse(ts.sys.readFile(this._tsConfigPath)); - } catch (err) { - throw new Error(`An error happened while parsing ${this._tsConfigPath} JSON: ${err}.`); + const configResult = ts.readConfigFile(this._tsConfigPath, ts.sys.readFile); + if (configResult.error) { + const diagnostic = configResult.error; + const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + throw new Error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`); } + const tsConfigJson = configResult.config; + if (options.hasOwnProperty('compilerOptions')) { tsConfigJson.compilerOptions = Object.assign({}, tsConfigJson.compilerOptions, diff --git a/tests/e2e/assets/webpack/test-app/tsconfig.json b/tests/e2e/assets/webpack/test-app/tsconfig.json index cee38681d901..f9ca9f3932a5 100644 --- a/tests/e2e/assets/webpack/test-app/tsconfig.json +++ b/tests/e2e/assets/webpack/test-app/tsconfig.json @@ -1,4 +1,5 @@ { + // Test comment "compilerOptions": { "baseUrl": "", "module": "es2015",