Skip to content

Commit

Permalink
Add CLI and programmatic option to disable implicit compiler options
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Feb 26, 2021
1 parent 7f33492 commit 994044d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/bin.ts
Expand Up @@ -45,6 +45,7 @@ export function main (argv: string[] = process.argv.slice(2), entrypointArgs: Re
'--compiler-host': Boolean,
'--pretty': Boolean,
'--skip-project': Boolean,
'--no-implicit-compiler-options': Boolean,
'--skip-ignore': Boolean,
'--prefer-ts-exts': Boolean,
'--log-error': Boolean,
Expand Down Expand Up @@ -90,6 +91,7 @@ export function main (argv: string[] = process.argv.slice(2), entrypointArgs: Re
'--files': files,
'--compiler': compiler,
'--compiler-options': compilerOptions,
'--no-implicit-compiler-options': noImplicitCompilerOptions,
'--project': project,
'--ignore-diagnostics': ignoreDiagnostics,
'--ignore': ignore,
Expand Down Expand Up @@ -132,6 +134,7 @@ export function main (argv: string[] = process.argv.slice(2), entrypointArgs: Re
--files Load \`files\`, \`include\` and \`exclude\` from \`tsconfig.json\` on startup
--pretty Use pretty diagnostic formatter (usually enabled by default)
--skip-project Skip reading \`tsconfig.json\`
--no-implicit-compiler-options Do not use a default \`tsconfig.json\` from @tsconfig/bases matching your node version.
--skip-ignore Skip \`--ignore\` checks
--prefer-ts-exts Prefer importing TypeScript files over JavaScript files
--log-error Logs TypeScript errors to stderr instead of throwing exceptions
Expand Down Expand Up @@ -172,6 +175,7 @@ export function main (argv: string[] = process.argv.slice(2), entrypointArgs: Re
compiler,
ignoreDiagnostics,
compilerOptions,
noImplicitCompilerOptions,
require: argsRequire,
readFile: code !== undefined ? evalAwarePartialHost.readFile : undefined,
fileExists: code !== undefined ? evalAwarePartialHost.fileExists : undefined
Expand Down
14 changes: 8 additions & 6 deletions src/index.ts
Expand Up @@ -265,12 +265,14 @@ export interface CreateOptions {
*/
skipProject?: boolean
/**
* Skip loading a default @tsconfig/* that matches the version of nodejs
* TODO needs a better name
* Do not apply compiler options from the @tsconfig/bases configuration matching your node version
*
* This option has no effect if a tsconfig.json is loaded, because loading a tsconfig.json disables
* implicit compiler options.
*
* @default false
*/
skipDefaultCompilerOptions?: boolean
noImplicitCompilerOptions?: boolean
/**
* Skip ignore check, so that compilation will be attempted for all files with matching extensions.
*
Expand Down Expand Up @@ -329,14 +331,14 @@ export interface TsConfigOptions extends Omit<RegisterOptions,
| 'readFile'
| 'fileExists'
| 'skipProject'
| 'noImplicitCompilerOptions'
| 'project'
| 'dir'
| 'cwd'
| 'projectSearchDir'
| 'scope'
| 'scopeDir'
| 'experimentalEsmLoader'
| 'skipDefaultCompilerOptions'
> {}

/**
Expand Down Expand Up @@ -384,7 +386,7 @@ export const DEFAULTS: RegisterOptions = {
compilerHost: yn(env.TS_NODE_COMPILER_HOST),
logError: yn(env.TS_NODE_LOG_ERROR),
experimentalEsmLoader: false,
skipDefaultCompilerOptions: false
noImplicitCompilerOptions: false
}

/**
Expand Down Expand Up @@ -1247,7 +1249,7 @@ function readConfig (
}

// Only if a config file is *not* loaded, load an implicit configuration from @tsconfig/bases
const skipDefaultCompilerOptions = configFilePath != null || (rawApiOptions.skipDefaultCompilerOptions ?? DEFAULTS.skipDefaultCompilerOptions) // tslint:disable-line
const skipDefaultCompilerOptions = configFilePath != null || (rawApiOptions.noImplicitCompilerOptions ?? DEFAULTS.noImplicitCompilerOptions) // tslint:disable-line
const defaultCompilerOptionsForNodeVersion = skipDefaultCompilerOptions ? undefined : getDefaultTsconfigJsonForNodeVersion(ts).compilerOptions

// Merge compilerOptions from all sources
Expand Down

0 comments on commit 994044d

Please sign in to comment.