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

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

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 17 additions & 1 deletion packages/nx/src/utils/register.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModuleKind, ScriptTarget } from 'typescript';
import { JsxEmit, ModuleKind, ScriptTarget } from 'typescript';
import { getTsNodeCompilerOptions } from './register';

describe('getTsNodeCompilerOptions', () => {
Expand All @@ -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']);
});
});
11 changes: 10 additions & 1 deletion packages/nx/src/utils/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -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'
Expand Down