Skip to content

Commit df3847f

Browse files
Charles Lydingfilipesilva
Charles Lyding
authored andcommitted
fix(@ngtools/webpack): allow comments in tsconfig files
Close #5216 Close #5230
1 parent 1ef8de5 commit df3847f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/@ngtools/webpack/src/plugin.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ export class AotPlugin implements Tapable {
113113
basePath = path.resolve(process.cwd(), options.basePath);
114114
}
115115

116-
let tsConfigJson: any = null;
117-
try {
118-
tsConfigJson = JSON.parse(ts.sys.readFile(this._tsConfigPath));
119-
} catch (err) {
120-
throw new Error(`An error happened while parsing ${this._tsConfigPath} JSON: ${err}.`);
116+
const configResult = ts.readConfigFile(this._tsConfigPath, ts.sys.readFile);
117+
if (configResult.error) {
118+
const diagnostic = configResult.error;
119+
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
120+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
121+
throw new Error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`);
121122
}
122123

124+
const tsConfigJson = configResult.config;
125+
123126
if (options.hasOwnProperty('compilerOptions')) {
124127
tsConfigJson.compilerOptions = Object.assign({},
125128
tsConfigJson.compilerOptions,

tests/e2e/assets/webpack/test-app/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
// Test comment
23
"compilerOptions": {
34
"baseUrl": "",
45
"module": "es2015",

0 commit comments

Comments
 (0)