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(misc): ensure swc transpiler process required files #21674

Merged

Conversation

leosvelperez
Copy link
Member

@leosvelperez leosvelperez commented Feb 7, 2024

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 additional files 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 project files) from the provided tsconfig file (normally a project-specific one), it sets the SWC_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

@leosvelperez leosvelperez self-assigned this Feb 7, 2024
Copy link

vercel bot commented Feb 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2024 3:18pm

@leosvelperez leosvelperez force-pushed the misc/fix-swc-transpiler-files branch from 2fcae46 to 31a6e4c Compare February 7, 2024 15:17
@leosvelperez leosvelperez marked this pull request as ready for review February 7, 2024 15:21
@leosvelperez leosvelperez requested a review from a team as a code owner February 7, 2024 15:21
@FrozenPandaz FrozenPandaz merged commit 0f1207e into nrwl:master Feb 7, 2024
3 of 6 checks passed
FrozenPandaz pushed a commit that referenced this pull request Feb 7, 2024
@leosvelperez leosvelperez deleted the misc/fix-swc-transpiler-files branch February 8, 2024 08:27
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants