Repository: facebook/jest
File: packages/jest-config/src/readConfigFileAndSetRootDir.ts (TypeScript)

Code before:
};

let registeredCompilerPromise: Promise<TsLoader>;

function getRegisteredCompiler(loader: TsLoaderModule) {
  // Cache the promise to avoid multiple registrations
  registeredCompilerPromise =
    registeredCompilerPromise ?? registerTsLoader(loader);
  return registeredCompilerPromise;
}

async function registerTsLoader(loader: TsLoaderModule): Promise<TsLoader> {
  try {
    // Register TypeScript compiler instance
    if (loader === 'ts-node') {
      const tsLoader = await import(/* webpackIgnore: true */ 'ts-node');

      return tsLoader.register({
        compilerOptions: {
          module: 'CommonJS',
        },
        moduleTypes: {
          '**': 'cjs',
        },
        swc: extraTSLoaderOptions?.swc,
        transpileOnly: extraTSLoaderOptions?.transpileOnly,
      });
    } else if (loader === 'esbuild-register') {
      const tsLoader = await import(
        /* webpackIgnore: true */ 'esbuild-register/dist/node'
      );

      let instance: {unregister: () => void} | undefined;

      return {
        enabled: (bool: boolean) => {
          if (bool) {
            instance = tsLoader.register({
              target: `node${process.version.slice(1)}`,
            });
          } else {
            instance?.unregister();
          }
        },
      };
    }

    throw new Error(
      `Jest: '${loader}' is not a valid TypeScript configuration loader.`,
    );
  } catch (error) {

Review comment (suggestion):
Instead of setting these two, can we just spread the config passed?

i.e.

```ts
tsLoader.register({
  compilerOptions: {
    module: 'CommonJS',
  },
  moduleTypes: {
    '**': 'cjs',
  },
  ...extraTSLoaderOptions,
});
```

Code after:

let registeredCompilerPromise: Promise<TsLoader>;

function getRegisteredCompiler(loader: TsLoaderModule) {
  // Cache the promise to avoid multiple registrations
  registeredCompilerPromise =
    registeredCompilerPromise ?? registerTsLoader(loader);
  return registeredCompilerPromise;
}

async function registerTsLoader(loader: TsLoaderModule): Promise<TsLoader> {
  try {
    // Register TypeScript compiler instance
    if (loader === 'ts-node') {
      const tsLoader = await import(/* webpackIgnore: true */ 'ts-node');

      return tsLoader.register({
        compilerOptions: {
          module: 'CommonJS',
        },
        moduleTypes: {
          '**': 'cjs',
        },
        ...extraTSLoaderOptions,
      });
    } else if (loader === 'esbuild-register') {
      const tsLoader = await import(
        /* webpackIgnore: true */ 'esbuild-register/dist/node'
      );

      let instance: {unregister: () => void} | undefined;

      return {
        enabled: (bool: boolean) => {
          if (bool) {
            instance = tsLoader.register({
              target: `node${process.version.slice(1)}`,
              ...extraTSLoaderOptions,
            });
          } else {
            instance?.unregister();
          }
        },
      };
    }

    throw new Error(
      `Jest: '${loader}' is not a valid TypeScript configuration loader.`,
    );
  } catch (error) {
    if (