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(register): exclude internal js files from compilation process #796

Closed

Conversation

fargito
Copy link
Contributor

@fargito fargito commented Jun 30, 2024

Hello,

I encountered an issue to upgrade a monorepo to @swc-node/register version 1.10.0. See the PR and the workflow run.

The issue was that a TS file imported a JS file from within the monorepo (from an internal package).

@swc-node/register propertly excluded plain JS file located in the node_modules folder from being sent to swc for compilation, however, the logic failed when the plain JS file was located outside of node_modules.

In my understanding, checking whether a file is located in node_modules is irrelevant. What matters is:

  • if the file is a ts file, send it to swc, then pass the js result to node
  • otherwise, return early and let node perform its resolve algorithm

This PR therefore reduces the check. It will only validate that the file is not a ts file in order to return early.

Also since I remove the check with the AVAILABLE_EXTENSION_PATTERN regex, it became unused so I deleted it. LMK if I should leave it there.

@fargito fargito marked this pull request as draft July 1, 2024 20:24
@fargito
Copy link
Contributor Author

fargito commented Jul 1, 2024

Ci is failing, and It looks legitimate. My change may be an issue if a typescript file is importing a js file, due to potential cjs/esm discrepancies. I will continue to investigate and edit the PR

@fargito fargito closed this Jul 1, 2024
@fargito fargito deleted the fix/monorepo-ts-to-js-import branch July 1, 2024 20:56
@fargito fargito restored the fix/monorepo-ts-to-js-import branch July 1, 2024 20:58
@fargito fargito deleted the fix/monorepo-ts-to-js-import branch July 1, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant