Repository: vercel/next.js
File: packages/next/src/build/swc/jest-transformer.ts (TypeScript)

Code before:
DEALINGS IN THE SOFTWARE.
*/

import vm from 'vm'
import { transformSync } from './index'
import { getJestSWCOptions } from './options'
import type {
  TransformerCreator,
  TransformOptions,
  SyncTransformer,
} from '@jest/transform'
import type { Config } from '@jest/types'
import type { NextConfig, ExperimentalConfig } from '../../server/config-shared'
import type { ResolvedBaseUrl } from '../load-jsconfig'

type TransformerConfig = Config.TransformerConfig[1]
export interface JestTransformerConfig extends TransformerConfig {
  jsConfig: any
  resolvedBaseUrl?: ResolvedBaseUrl
  pagesDir?: string
  serverComponents?: boolean
  isEsmProject: boolean
  modularizeImports?: NextConfig['modularizeImports']
  swcPlugins: ExperimentalConfig['swcPlugins']
  compilerOptions: NextConfig['compiler']
  imageConfig?: Record<string, unknown>
}

// Jest use the `vm` [Module API](https://nodejs.org/api/vm.html#vm_class_vm_module) for ESM.
// see https://github.com/facebook/jest/issues/9430
const isSupportEsm = 'Module' in vm

function getJestConfig(
  jestConfig: TransformOptions<JestTransformerConfig>
): Config.ProjectConfig {
  return 'config' in jestConfig
    ? // jest 27
      jestConfig.config
    : // jest 26
      (jestConfig as unknown as Config.ProjectConfig)
}

function isEsm(
  isEsmProject: boolean,
  filename: string,
  jestConfig: Config.ProjectConfig
): boolean {
  return (
    (/\.jsx?$/.test(filename) && isEsmProject) ||
    jestConfig.extensionsToTreatAsEsm?.some((ext: any) =>
      filename.endsWith(ext)

Review comment (suggestion):
```suggestion
  imageConfig?: Partial<NextConfig['images']>
```

Code after:
DEALINGS IN THE SOFTWARE.
*/

import vm from 'vm'
import { transformSync } from './index'
import { getJestSWCOptions } from './options'
import type {
  TransformerCreator,
  TransformOptions,
  SyncTransformer,
} from '@jest/transform'
import type { Config } from '@jest/types'
import type { NextConfig, ExperimentalConfig } from '../../server/config-shared'
import type { ResolvedBaseUrl } from '../load-jsconfig'

type TransformerConfig = Config.TransformerConfig[1]
export interface JestTransformerConfig extends TransformerConfig {
  jsConfig: any
  resolvedBaseUrl?: ResolvedBaseUrl
  pagesDir?: string
  serverComponents?: boolean
  isEsmProject: boolean
  modularizeImports?: NextConfig['modularizeImports']
  swcPlugins: ExperimentalConfig['swcPlugins']
  compilerOptions: NextConfig['compiler']
  imageConfig?: Partial<NextConfig['images']>
}

// Jest use the `vm` [Module API](https://nodejs.org/api/vm.html#vm_class_vm_module) for ESM.
// see https://github.com/facebook/jest/issues/9430
const isSupportEsm = 'Module' in vm

function getJestConfig(
  jestConfig: TransformOptions<JestTransformerConfig>
): Config.ProjectConfig {
  return 'config' in jestConfig
    ? // jest 27
      jestConfig.config
    : // jest 26
      (jestConfig as unknown as Config.ProjectConfig)
}

function isEsm(
  isEsmProject: boolean,
  filename: string,
  jestConfig: Config.ProjectConfig
): boolean {
  return (
    (/\.jsx?$/.test(filename) && isEsmProject) ||
    jestConfig.extensionsToTreatAsEsm?.some((ext: any) =>
      filename.endsWith(ext)