fix(misc): ensure swc transpiler process required files #21674
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current Behavior
When having
@swc-node/[email protected]
installed, loading a config (or similar files needing transpilation in-process) might error complaining about invalid syntax or import statements used outside of a module.This happens because, in version 1.8.0 of the
@swc-node/register
package, a fix was released where the utility now correctly uses the provided compiler options. The Nx helper to register the TS transpiler uses the@swc-node/register/read-default-tsconfig#readDefaultTsConfig
to read those compiler options, and that utility returns an additionalfiles
property which, if present, is used by the@swc-node/register/register#register
function to filter files out from processing. This is all fine, but while the Nx helper reads the compiler options (and hence the TS projectfiles
) from the provided tsconfig file (normally a project-specific one), it sets theSWC_NODE_PROJECT
to the root tsconfig file. This means that before@swc-node/[email protected]
, the compiler options read from the project's tsconfig file were ignored and the root tsconfig file was always used, so effectively getting all files in the workspaces as part of the TS program. With@swc-node/[email protected]
now the project's tsconfig file compiler options are used and only the files included in that tsconfig file are part of the program.The above is not aligned with the
ts-node
transpilation, where the project's tsconfig file compiler options are correctly used, and the files are not a factor.Expected Behavior
Loading a config (or similar files needing transpilation in-process) should work correctly.
Related Issue(s)
Fixes #21639
Fixes #21643