mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
Ensure readJson in build throws when errors are present (#55466)
This commit is contained in:
@@ -72,12 +72,18 @@ export class ExecError extends Error {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads JSON data with optional comments using the LKG TypeScript compiler
|
||||
* Reads JSON data with optional comments
|
||||
* @param {string} jsonPath
|
||||
*/
|
||||
export function readJson(jsonPath) {
|
||||
const jsonText = fs.readFileSync(jsonPath, "utf8");
|
||||
return JSONC.parse(jsonText);
|
||||
/** @type {JSONC.ParseError[]} */
|
||||
const errors = [];
|
||||
const result = JSONC.parse(jsonText, errors);
|
||||
if (errors.length) {
|
||||
throw new Error(`Error parsing ${jsonPath}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user