chore(tsconfig): abort on invalid json content (#3578)

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
This commit is contained in:
Chengzhong Wu 2023-02-01 04:11:08 +08:00 committed by GitHub
parent 2a76d881e4
commit 2b59c2820c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 11 deletions

View File

@ -1,5 +1,5 @@
{ {
"extends": "../../../tsconfig.es5.json", "extends": "../../../tsconfig.base.es5.json",
"compilerOptions": { "compilerOptions": {
"rootDir": ".", "rootDir": ".",
"outDir": "build" "outDir": "build"

View File

@ -1,5 +1,5 @@
{ {
"extends": "../../../tsconfig.es5.json", "extends": "../../../tsconfig.base.es5.json",
"compilerOptions": { "compilerOptions": {
"rootDir": ".", "rootDir": ".",
"outDir": "build" "outDir": "build"

View File

@ -6,6 +6,7 @@
}, },
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",
"src/generated/*.js",
"test/**/*.ts" "test/**/*.ts"
], ],
"references": [ "references": [

View File

@ -247,12 +247,7 @@ function resolvePackageMeta(pkgDir) {
} }
function readAndMaybeMergeTsConfig(tsconfigPath, updates) { function readAndMaybeMergeTsConfig(tsconfigPath, updates) {
let tsconfig; const tsconfig = readJSON(tsconfigPath);
try {
tsconfig = readJSON(tsconfigPath);
} catch {
return updates;
}
updates = mergeTsConfig(tsconfig, updates); updates = mergeTsConfig(tsconfig, updates);
return updates; return updates;
} }
@ -284,8 +279,11 @@ function hasEsTargets(pjson) {
function readJSON(filepath) { function readJSON(filepath) {
const fileContent = fs.readFileSync(filepath, 'utf8'); const fileContent = fs.readFileSync(filepath, 'utf8');
const json = JSON.parse(fileContent); try {
return json; return JSON.parse(fileContent);
} catch (e) {
throw new Error(`Invalid JSON ${filepath}: ${e.message}`);
}
} }
function writeJSON(filepath, content, dry) { function writeJSON(filepath, content, dry) {

View File

@ -1,5 +1,5 @@
{ {
"extends": "./tsconfig.es5.json", "extends": "./tsconfig.base.es5.json",
"compilerOptions": { "compilerOptions": {
"module": "ES6", "module": "ES6",
"moduleResolution": "node" "moduleResolution": "node"