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

feat(core): add support for loading .ts files using ESM #21268

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Jan 22, 2024

This PR adds the ability to use ESM with .ts files. The strategy is as follows:

  1. In Nx CLI, when we don't have the module.register function to programmatically register ESM loaders (introduced in Node 20.6.0), fork the CLI again with the --experimental-loader ts-node/esm option.
  2. If we're in Nod 20.6.0, then the registerTsProject function will also register the ESM loader.
  3. For Node < 16, skip any ESM logic since the loader API does not exist.

Fixes @nx/playwright/plugin to be able to use ESM in playwright.config.ts file. Now, Epic Stack does nx init properly. :)

Screenshot 2024-01-22 at 4 37 26 PM

Performance impact

Based on local testing, reloading the process for Node < 20.6 is adding ~10ms to the Nx CLI. If this is a problem we can remove the logic from init-local.ts and ask users to update their Node version.

Copy link

vercel bot commented Jan 22, 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 Jan 31, 2024 1:12pm

@jaysoo jaysoo force-pushed the ts_esm_config branch 2 times, most recently from 3b41064 to b56ce6d Compare January 30, 2024 20:02
@jaysoo jaysoo marked this pull request as ready for review January 30, 2024 20:02
@jaysoo jaysoo requested review from a team as code owners January 30, 2024 20:02
@FrozenPandaz FrozenPandaz enabled auto-merge (squash) January 30, 2024 20:11
@jaysoo jaysoo force-pushed the ts_esm_config branch 3 times, most recently from de46274 to 27b369c Compare January 31, 2024 04:56
@FrozenPandaz FrozenPandaz merged commit 7a83e12 into nrwl:master Jan 31, 2024
6 checks passed
@jaysoo jaysoo deleted the ts_esm_config branch January 31, 2024 14:24
Copy link

github-actions bot commented Feb 6, 2024

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 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants