Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of 'extends' property in tsconfig.json (#33)
* Move code related to reading tsconfig.json into a function * Make getCompilerOptions options support "extends" prop in tsconfig * Add a test for extends functionality * Simplify base tsconfig * Simplify tsconfig * Remove not important comment * Run prettier
- Loading branch information
1 parent
e5f21bd
commit b1f1bd4
Showing
10 changed files
with
73 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ts from 'typescript' | ||
|
||
const DEFAULT_OPTIONS = ts.convertCompilerOptionsFromJson( | ||
{ | ||
allowSyntheticDefaultImports: true, | ||
strictFunctionTypes: false, | ||
noUnusedParameters: true, | ||
noImplicitReturns: true, | ||
moduleResolution: 'NodeJs', | ||
noUnusedLocals: true, | ||
stripInternal: true, | ||
allowJs: true, | ||
module: 'esnext', | ||
strict: true, | ||
noEmit: true, | ||
jsx: 'react' | ||
}, | ||
'./' | ||
).options | ||
|
||
export function getCompilerOptions(cwd, configName = 'tsconfig.json') { | ||
let configFileName = ts.findConfigFile(cwd, ts.sys.fileExists, configName) | ||
if (configFileName === undefined) { | ||
return DEFAULT_OPTIONS | ||
} | ||
let configFile = ts.readConfigFile(configFileName, ts.sys.readFile) | ||
let parsedCommandLine = ts.parseJsonConfigFileContent( | ||
configFile.config, | ||
ts.sys, | ||
cwd | ||
) | ||
return parsedCommandLine.options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare const a: number | null | ||
|
||
// THROWS Type 'number | null' is not assignable to type 'number'. | ||
export const b: number = a | ||
|
||
// This file checks whether the compiler performs strictNullChecks if it is enabled in the config file specified via extends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"strictNullChecks": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
// tsconfig should support extends | ||
"extends": "./tsconfig.base.json", | ||
"compilerOptions": { | ||
"noUnusedLocals": false, | ||
"target": "ES5", | ||
"moduleResolution": "Node" | ||
} | ||
} |