Skip to content

Commit

Permalink
feat(core): allow local execution transpiler overriding with env var (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yharaskrik authored Apr 4, 2023
1 parent 8092df3 commit 6e86866
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

1 comment on commit 6e86866

@vercel
Copy link

@vercel vercel bot commented on 6e86866 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.