Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ const argsProjectIndex = args.findIndex(arg =>
const argsProjectValue =
argsProjectIndex !== -1 ? args[argsProjectIndex + 1] : undefined

const files = args.filter(file => /\.(ts|tsx)$/.test(file))
// Load existing config
const tsconfigPath = argsProjectValue || resolveFromRoot('tsconfig.json')
const tsconfigContent = fs.readFileSync(tsconfigPath).toString()
// Use 'eval' to read the JSON as regular JavaScript syntax so that comments are allowed
let tsconfig = {}
eval(`tsconfig = ${tsconfigContent}`)

// if we allow AND check js files, test for js|jsx extensions as well, otherwise they will get passed
// along with other arguments and we will get the error that -p cannot be used alongside with the
// files option
const files = tsconfig.compilerOptions.allowJs && tsconfig.compilerOptions.checkJs
? args.filter(file => /\.(ts|tsx|js|jsx)$/.test(file))
: args.filter(file => /\.(ts|tsx)$/.test(file));

if (files.length === 0) {
process.exit(0)
}
Expand All @@ -37,12 +50,7 @@ if (argsProjectIndex !== -1) {
remainingArgsToForward.splice(argsProjectIndex, 2)
}

// Load existing config
const tsconfigPath = argsProjectValue || resolveFromRoot('tsconfig.json')
const tsconfigContent = fs.readFileSync(tsconfigPath).toString()
// Use 'eval' to read the JSON as regular JavaScript syntax so that comments are allowed
let tsconfig = {}
eval(`tsconfig = ${tsconfigContent}`)


// Write a temp config file
const tmpTsconfigPath = resolveFromRoot(`tsconfig.${randomChars()}.json`)
Expand Down