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): allow local execution transpiler overriding with env var #16037

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/shared/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The following environment variables are ones that you can set to change the beha
| NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. |
| NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. |
| NX_GENERATE_QUIET | boolean | If set to `true`, will prevent Nx logging file operations during generate |
| NX_PREFER_TS_NODE | boolean | If set to `true`, Nx will use ts-node for local execution of plugins even if `@swc-node/register` is installed. |

Nx will set the following environment variables so they can be accessible within the process even outside of executors and generators

Expand Down
6 changes: 4 additions & 2 deletions packages/nx/src/utils/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ export function registerTranspiler(
// Function to register transpiler that returns cleanup function
let registerTranspiler: () => () => void;

if (swcNodeInstalled) {
const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true';

if (swcNodeInstalled && !preferTsNode) {
// These are requires to prevent it from registering when it shouldn't
const { register } =
require('@swc-node/register/register') as typeof import('@swc-node/register/register');

registerTranspiler = () => register(compilerOptions);
} else {
// We can fall back on ts-node if its available
// We can fall back on ts-node if it's available

if (tsNodeInstalled) {
const { register } = require('ts-node') as typeof import('ts-node');
Expand Down