fix(core): correctly pass resolved compilerOptions to ts-node (#16240)

This commit is contained in:
Matt Lewis 2023-04-12 02:06:36 +01:00 committed by GitHub
parent 5b74232de0
commit 98b4aa6561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { ModuleKind, ScriptTarget } from 'typescript';
import { JsxEmit, ModuleKind, ScriptTarget } from 'typescript';
import { getTsNodeCompilerOptions } from './register';
describe('getTsNodeCompilerOptions', () => {
@ -17,4 +17,20 @@ describe('getTsNodeCompilerOptions', () => {
}).target
).toEqual('ES2020');
});
it('should remove jsx option', () => {
expect(
getTsNodeCompilerOptions({
jsx: JsxEmit.ReactJSX,
}).jsx
).toBeUndefined();
});
it('should use correct lib value', () => {
expect(
getTsNodeCompilerOptions({
lib: ['lib.es2022.d.ts'],
}).lib
).toEqual(['es2022']);
});
});

View File

@ -130,7 +130,7 @@ function readCompilerOptionsWithTypescript(tsConfigPath) {
const { readConfigFile, parseJsonConfigFileContent, sys } = ts;
const jsonContent = readConfigFile(tsConfigPath, sys.readFile);
const { options } = parseJsonConfigFileContent(
jsonContent,
jsonContent.config,
sys,
dirname(tsConfigPath)
);
@ -203,6 +203,15 @@ export function getTsNodeCompilerOptions(compilerOptions: CompilerOptions) {
delete result.pathsBasePath;
delete result.configFilePath;
// instead of mapping to enum value we just remove it as it shouldn't ever need to be set for ts-node
delete result.jsx;
// lib option is in the format `lib.es2022.d.ts`, so we need to remove the leading `lib.` and trailing `.d.ts` to make it valid
result.lib = result.lib?.map((value) => {
return value.replace(/^lib\./, '').replace(/\.d\.ts$/, '');
});
if (result.moduleResolution) {
result.moduleResolution =
result.moduleResolution === 'NodeJs'