Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
fix(core): Safer require for tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeesha committed May 27, 2020
1 parent 9d0457d commit 519bb19
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion integration/testproject/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"outDir": "./lib",
"outDir": "./lib", // this is a comment because tsconfig.json can have comments
"declaration": true,
"target": "es5",
"module": "commonjs",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"devDependencies": {
"@types/jest": "^25.2.1",
"@types/json5": "^0.0.30",
"@types/lodash": "^4.14.150",
"@types/minimist": "^1.2.0",
"@types/node": "^13.13.1",
Expand All @@ -32,6 +33,7 @@
"typescript": "^3.9.3"
},
"dependencies": {
"json5": "^2.1.3",
"lodash": "^4.17.15",
"minimist": "^1.2.5",
"true-myth": "^4.0.0",
Expand All @@ -47,4 +49,4 @@
"master"
]
}
}
}
6 changes: 5 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import minimist from "minimist";
import path from "path";
import JSON5 from "json5";
import fs from "fs";

import { analyze } from "./analyzer";
import { initialize } from "./initializer";
Expand All @@ -9,7 +11,9 @@ import { present } from "./presenter";
export const run = (argv = process.argv.slice(2), output = console.log) => {
const tsConfigPath = minimist(argv).p || "tsconfig.json";
const { project } = initialize(path.join(process.cwd(), tsConfigPath));
const entrypoints: string[] = require(path.join(process.cwd(), tsConfigPath))?.files?.map((file: string) => path.join(process.cwd(), file)) || [];
const tsConfigJSON = JSON5.parse(fs.readFileSync(path.join(process.cwd(), tsConfigPath), "utf-8"));

const entrypoints: string[] = tsConfigJSON?.files?.map((file: string) => path.join(process.cwd(), file)) || [];

const state = new State();

Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/json5@^0.0.30":
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.30.tgz#44cb52f32a809734ca562e685c6473b5754a7818"
integrity sha512-sqm9g7mHlPY/43fcSNrCYfOeX9zkTTK+euO5E6+CVijSMm5tTjkVdwdqRkY3ljjIAf8679vps5jKUoJBCLsMDA==

"@types/lodash@^4.14.150":
version "4.14.150"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.150.tgz#649fe44684c3f1fcb6164d943c5a61977e8cf0bd"
Expand Down Expand Up @@ -4151,7 +4156,7 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=

[email protected], json5@^2.1.2:
[email protected], json5@^2.1.2, json5@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.3.tgz#c9b0f7fa9233bfe5807fe66fcf3a5617ed597d43"
integrity sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==
Expand Down

0 comments on commit 519bb19

Please sign in to comment.