Skip to content

Commit c6c04db

Browse files
authored
fix(scanner): respect tsconfig.json (#21547)
1 parent 43358e9 commit c6c04db

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

packages/vite/src/node/optimizer/scan.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import { BaseEnvironment } from '../baseEnvironment'
3535
import type { DevEnvironment } from '../server/environment'
3636
import { transformGlobImport } from '../plugins/importMetaGlob'
3737
import { cleanUrl } from '../../shared/utils'
38-
import { loadTsconfigJsonForFile } from '../plugins/esbuild'
39-
import { setOxcTransformOptionsFromTsconfigOptions } from '../plugins/oxc'
38+
import { getRollupJsxPresets } from '../plugins/oxc'
4039

4140
export class ScanEnvironment extends BaseEnvironment {
4241
mode = 'scan' as const
@@ -253,23 +252,17 @@ async function prepareRolldownScanner(
253252
environment.config.optimizeDeps.rolldownOptions ?? {}
254253

255254
const plugins = await asyncFlatten(arraify(pluginsFromConfig))
256-
257255
plugins.push(...rolldownScanPlugin(environment, deps, missing, entries))
258256

259-
// The plugin pipeline automatically loads the closest tsconfig.json.
260-
// But Rolldown doesn't support reading tsconfig.json (https://github.com/rolldown/rolldown/issues/4968).
261-
// Due to syntax incompatibilities between the experimental decorators in TypeScript and TC39 decorators,
262-
// we cannot simply set `"experimentalDecorators": true` or `false`. (https://github.com/vitejs/vite/pull/15206#discussion_r1417414715)
263-
// Therefore, we use the closest tsconfig.json from the root to make it work in most cases.
264-
const { tsconfig } = await loadTsconfigJsonForFile(
265-
path.join(environment.config.root, '_dummy.js'),
266-
)
267257
const transformOptions = deepClone(rolldownOptions.transform) ?? {}
268-
setOxcTransformOptionsFromTsconfigOptions(
269-
transformOptions,
270-
tsconfig.compilerOptions,
271-
[], // NOTE: ignore warnings as the same warning will be shown by the plugin container
272-
)
258+
if (transformOptions.jsx === undefined) {
259+
transformOptions.jsx = {}
260+
} else if (
261+
transformOptions.jsx === 'react' ||
262+
transformOptions.jsx === 'react-jsx'
263+
) {
264+
transformOptions.jsx = getRollupJsxPresets(transformOptions.jsx)
265+
}
273266
if (typeof transformOptions.jsx === 'object') {
274267
transformOptions.jsx.development ??= !environment.config.isProduction
275268
}

packages/vite/src/node/plugins/oxc.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export interface OxcOptions extends Omit<
5353
jsxRefreshExclude?: string | RegExp | ReadonlyArray<string | RegExp>
5454
}
5555

56-
function getRollupJsxPresets(preset: 'react' | 'react-jsx'): OxcJsxOptions {
56+
export function getRollupJsxPresets(
57+
preset: 'react' | 'react-jsx',
58+
): OxcJsxOptions {
5759
switch (preset) {
5860
case 'react':
5961
return {
@@ -72,7 +74,7 @@ function getRollupJsxPresets(preset: 'react' | 'react-jsx'): OxcJsxOptions {
7274
preset satisfies never
7375
}
7476

75-
export function setOxcTransformOptionsFromTsconfigOptions(
77+
function setOxcTransformOptionsFromTsconfigOptions(
7678
oxcOptions: Omit<OxcTransformOptions, 'jsx'> & {
7779
jsx?:
7880
| OxcTransformOptions['jsx']

0 commit comments

Comments
 (0)