Skip to content

Commit

Permalink
fix(core): do not re-register ts-node twice for the same compiler opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
FrozenPandaz committed Jun 28, 2024
1 parent 22aa2d9 commit 254216e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/nx/src/plugins/js/utils/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ export function getSwcTranspiler(
return typeof cleanupFn === 'function' ? cleanupFn : () => {};
}

const registered = new Set<string>();

export function getTsNodeTranspiler(
compilerOptions: CompilerOptions,
tsNodeOptions?: TsConfigOptions
): (...args: unknown[]) => unknown {
// Just return if transpiler was already registered before.
const registrationKey = JSON.stringify(compilerOptions);
if (registered.has(registrationKey)) {
return () => {};
}

const { register } = require('ts-node') as typeof import('ts-node');
// ts-node doesn't provide a cleanup method
const service = register({
Expand All @@ -132,6 +140,7 @@ export function getTsNodeTranspiler(
// we already read and provide the compiler options, so prevent ts-node from reading them again
skipProject: true,
});
registered.add(registrationKey);

const { transpiler, swc } = service.options;

Expand All @@ -141,7 +150,7 @@ export function getTsNodeTranspiler(
}

return () => {
service.enabled(false);
// service.enabled(false);
};
}

Expand Down

0 comments on commit 254216e

Please sign in to comment.