Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various improvements: compatibility with windows, tsconfig file can be specified, tsconfig file allows comments, args can be passed to tsc #4

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ const fs = require('fs')
const yargsParser = require('yargs-parser')

const { randomChars, resolveFromModule, resolveFromRoot } = require('./utils')

const args = yargsParser(process.argv.slice(2))

const filesToCheck = args._.filter(file => /\.(ts|tsx)$/.test(file))
const argvCleaned = process.argv.slice(2)
const args = yargsParser(argvCleaned)
const filesToCheck = args._.filter(file => /\.(ts|tsx)$/.test(file)) // but what about globs ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you believe we should use glob instead of regex here? What would be the benefit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No , it's just that the file argument to the tsc cli can be a glob, as the example here shows:

tsc src/*.ts

And we should detect them because they should not be put in the files property of the temporary tsconfig, but in the include property.
I left that for later, but I put a comment to at least have the maintainers be aware of the potential issue ;-).


// cleaning arguments to keep only arguments to pass to tsc
const indexOfProjectInArgs = argvCleaned.includes('-p') ? argvCleaned.indexOf('-p') : argvCleaned.indexOf('--project')
if (indexOfProjectInArgs !== -1) {
argvCleaned.splice(indexOfProjectInArgs, 2)
}
const remainingArgsToPass = argvCleaned.filter(arg => !filesToCheck.includes(arg))

// Nothing to be type-checked?
if (filesToCheck.length === 0) {
Expand All @@ -33,8 +39,8 @@ fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2))

// Type-check our files
const { status } = spawnSync(
resolveFromModule('typescript', 'bin/tsc'),
['-p', tmpTsconfigPath, '--noEmit'],
resolveFromModule('typescript', `../.bin/tsc${process.platform === 'win32' ? '.cmd' : ''}`),
['-p', tmpTsconfigPath, ...remainingArgsToPass],
{ stdio: 'inherit' },
)

Expand Down