Repository: vitejs/vite
File: packages/vite/src/node/optimizer/scan.ts (TypeScript)

Code before:
      tsconfig.compilerOptions?.experimentalDecorators ||
      tsconfig.compilerOptions?.jsx ||
      tsconfig.compilerOptions?.jsxFactory ||
      tsconfig.compilerOptions?.jsxFragmentFactory ||
      tsconfig.compilerOptions?.jsxImportSource
    ) {
      tsconfigRaw = {
        compilerOptions: {
          experimentalDecorators:
            tsconfig.compilerOptions?.experimentalDecorators,
          jsx: tsconfig.compilerOptions?.jsx,
          jsxFactory: tsconfig.compilerOptions?.jsxFactory,
          jsxFragmentFactory: tsconfig.compilerOptions?.jsxFragmentFactory,
          jsxImportSource: tsconfig.compilerOptions?.jsxImportSource,
        },
      }
    }
  }

  return await esbuild.context({
    absWorkingDir: process.cwd(),
    write: false,
    stdin: {
      contents: entries.map((e) => `import ${JSON.stringify(e)}`).join('\n'),
      loader: 'js',
    },
    bundle: true,
    format: 'esm',
    logLevel: 'silent',
    plugins: [...plugins, plugin],
    jsxDev: !environment.config.isProduction,
    ...esbuildOptions,
    tsconfigRaw,
  })
}

function orderedDependencies(deps: Record<string, string>) {
  const depsList = Object.entries(deps)
  // Ensure the same browserHash for the same set of dependencies
  depsList.sort((a, b) => a[0].localeCompare(b[0]))
  return Object.fromEntries(depsList)
}

async function globEntries(
  patterns: string | string[],
  environment: ScanEnvironment,
) {
  const nodeModulesPatterns: string[] = []
  const regularPatterns: string[] = []

  for (const pattern of arraify(patterns)) {

Review comment (suggestion):
I think we need
https://github.com/vitejs/vite/blob/f0880df0eab077e61abb533c4edde6538bd729f9/packages/vite/src/node/plugins/esbuild.ts#L167-L174
here ([esbuild try](https://esbuild.github.io/try/#YgAwLjI1LjgALS1qc3g9YXV0b21hdGljIC0tdHNjb25maWctcmF3PSd7ImNvbXBpbGVyT3B0aW9ucyI6eyJqc3giOiAicmVhY3QifX0nAGUAZW50cnkuanN4AGNvbnNvbGUubG9nKDxkaXYgLz4p)).

Code after:
      tsconfig.compilerOptions?.experimentalDecorators ||
      tsconfig.compilerOptions?.jsx ||
      tsconfig.compilerOptions?.jsxFactory ||
      tsconfig.compilerOptions?.jsxFragmentFactory ||
      tsconfig.compilerOptions?.jsxImportSource
    ) {
      tsconfigRaw = {
        compilerOptions: {
          experimentalDecorators:
            tsconfig.compilerOptions?.experimentalDecorators,
          // esbuild uses tsconfig fields when both the normal options and tsconfig was set
          // but we want to prioritize the normal options
          jsx: esbuildOptions.jsx ? undefined : tsconfig.compilerOptions?.jsx,
          jsxFactory: esbuildOptions.jsxFactory
            ? undefined
            : tsconfig.compilerOptions?.jsxFactory,
          jsxFragmentFactory: esbuildOptions.jsxFragment
            ? undefined
            : tsconfig.compilerOptions?.jsxFragmentFactory,
          jsxImportSource: esbuildOptions.jsxImportSource
            ? undefined
            : tsconfig.compilerOptions?.jsxImportSource,
        },
      }
    }
  }

  return await esbuild.context({
    absWorkingDir: process.cwd(),
    write: false,
    stdin: {
      contents: entries.map((e) => `import ${JSON.stringify(e)}`).join('\n'),
      loader: 'js',
    },
    bundle: true,
    format: 'esm',
    logLevel: 'silent',
    plugins: [...plugins, plugin],
    jsxDev: !environment.config.isProduction,
    ...esbuildOptions,
    tsconfigRaw,
  })
}

function orderedDependencies(deps: Record<string, string>) {
  const depsList = Object.entries(deps)
  // Ensure the same browserHash for the same set of dependencies
  depsList.sort((a, b) => a[0].localeCompare(b[0]))
  return Object.fromEntries(depsList)
}