Skip to content

Commit

Permalink
fix(misc): ensure swc transpiler process required files
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Feb 7, 2024
1 parent 2413e5d commit 2fcae46
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/nx/src/plugins/js/utils/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,24 @@ function readCompilerOptions(tsConfigPath): CompilerOptions {
const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true';

if (swcNodeInstalled && !preferTsNode) {
const {
readDefaultTsConfig,
}: typeof import('@swc-node/register/read-default-tsconfig') = require('@swc-node/register/read-default-tsconfig');
return readDefaultTsConfig(tsConfigPath);
return readCompilerOptionsWithSwc(tsConfigPath);
} else {
return readCompilerOptionsWithTypescript(tsConfigPath);
}
}

function readCompilerOptionsWithSwc(tsConfigPath) {
const {
readDefaultTsConfig,
}: typeof import('@swc-node/register/read-default-tsconfig') = require('@swc-node/register/read-default-tsconfig');
const compilerOptions = readDefaultTsConfig(tsConfigPath);
// This is returned in compiler options for some reason, but not part of the typings.
// @swc-node/register filters the files to transpile based on it, but it can be limiting when processing
// files outside the tsconfig's rootDir (e.g. shared helpers or config outside projects).
delete compilerOptions.files;
return compilerOptions;
}

function readCompilerOptionsWithTypescript(tsConfigPath) {
if (!ts) {
ts = require('typescript');
Expand Down

0 comments on commit 2fcae46

Please sign in to comment.