diff --git a/packages/nx/src/utils/register.spec.ts b/packages/nx/src/utils/register.spec.ts index 7ba3b637b2cc6..3cdba50c48d15 100644 --- a/packages/nx/src/utils/register.spec.ts +++ b/packages/nx/src/utils/register.spec.ts @@ -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']); + }); }); diff --git a/packages/nx/src/utils/register.ts b/packages/nx/src/utils/register.ts index b0b39089f50f2..c727339f7677f 100644 --- a/packages/nx/src/utils/register.ts +++ b/packages/nx/src/utils/register.ts @@ -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'