From 31a6e4c173c7852c29f2f408df570d7056bb4781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 7 Feb 2024 16:17:11 +0100 Subject: [PATCH] fix(misc): ensure swc transpiler process required files --- packages/nx/src/plugins/js/utils/register.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/nx/src/plugins/js/utils/register.ts b/packages/nx/src/plugins/js/utils/register.ts index 5c22a19db92cd..a6f174f05c8e5 100644 --- a/packages/nx/src/plugins/js/utils/register.ts +++ b/packages/nx/src/plugins/js/utils/register.ts @@ -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 not part of the received tsconfig included files (e.g. shared helpers, or config files not in source, etc.). + delete compilerOptions.files; + return compilerOptions; +} + function readCompilerOptionsWithTypescript(tsConfigPath) { if (!ts) { ts = require('typescript');