Skip to content

Commit

Permalink
chore(tsconfig): abort on invalid json content (#3578)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
legendecas and dyladan committed Jan 31, 2023
1 parent 2a76d88 commit 2b59c28
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion experimental/backwards-compatability/node14/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.es5.json",
"extends": "../../../tsconfig.base.es5.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
Expand Down
2 changes: 1 addition & 1 deletion experimental/backwards-compatability/node16/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.es5.json",
"extends": "../../../tsconfig.base.es5.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"include": [
"src/**/*.ts",
"src/generated/*.js",
"test/**/*.ts"
],
"references": [
Expand Down
14 changes: 6 additions & 8 deletions scripts/update-ts-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ function resolvePackageMeta(pkgDir) {
}

function readAndMaybeMergeTsConfig(tsconfigPath, updates) {
let tsconfig;
try {
tsconfig = readJSON(tsconfigPath);
} catch {
return updates;
}
const tsconfig = readJSON(tsconfigPath);
updates = mergeTsConfig(tsconfig, updates);
return updates;
}
Expand Down Expand Up @@ -284,8 +279,11 @@ function hasEsTargets(pjson) {

function readJSON(filepath) {
const fileContent = fs.readFileSync(filepath, 'utf8');
const json = JSON.parse(fileContent);
return json;
try {
return JSON.parse(fileContent);
} catch (e) {
throw new Error(`Invalid JSON ${filepath}: ${e.message}`);
}
}

function writeJSON(filepath, content, dry) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.base.esm.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.es5.json",
"extends": "./tsconfig.base.es5.json",
"compilerOptions": {
"module": "ES6",
"moduleResolution": "node"
Expand Down

0 comments on commit 2b59c28

Please sign in to comment.