From 4113c1d6741d802292f424711a0d114a5f332a9a Mon Sep 17 00:00:00 2001 From: Grex Date: Mon, 20 Dec 2021 01:27:05 -0700 Subject: [PATCH] perf: only register ts-node once when loading TS config files (#12160) --- CHANGELOG.md | 2 ++ packages/jest-config/src/readConfigFileAndSetRootDir.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ebe7e025867..de59fb365eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ ### Performance +- `jest-config` perf: only register ts-node once when loading TS config files ([#12160](https://github.com/facebook/jest/pull/12160)) + ## 27.4.5 ### Fixes diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 09a2aaa8c896..6bf555c77911 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -79,15 +79,15 @@ export default async function readConfigFileAndSetRootDir( return configObject; } +let registerer: Service; + // Load the TypeScript configuration const loadTSConfigFile = async ( configPath: Config.Path, ): Promise => { - let registerer: Service; - // Register TypeScript compiler instance try { - registerer = require('ts-node').register({ + registerer ||= require('ts-node').register({ compilerOptions: { module: 'CommonJS', },