Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import { BaseEnvironment } from '../baseEnvironment'
import type { DevEnvironment } from '../server/environment'
import { transformGlobImport } from '../plugins/importMetaGlob'
import { cleanUrl } from '../../shared/utils'
import { loadTsconfigJsonForFile } from '../plugins/esbuild'
import { setOxcTransformOptionsFromTsconfigOptions } from '../plugins/oxc'
import { getRollupJsxPresets } from '../plugins/oxc'

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

const plugins = await asyncFlatten(arraify(pluginsFromConfig))

plugins.push(...rolldownScanPlugin(environment, deps, missing, entries))

// The plugin pipeline automatically loads the closest tsconfig.json.
// But Rolldown doesn't support reading tsconfig.json (https://github.com/rolldown/rolldown/issues/4968).
// Due to syntax incompatibilities between the experimental decorators in TypeScript and TC39 decorators,
// we cannot simply set `"experimentalDecorators": true` or `false`. (https://github.com/vitejs/vite/pull/15206#discussion_r1417414715)
// Therefore, we use the closest tsconfig.json from the root to make it work in most cases.
const { tsconfig } = await loadTsconfigJsonForFile(
path.join(environment.config.root, '_dummy.js'),
)
const transformOptions = deepClone(rolldownOptions.transform) ?? {}
setOxcTransformOptionsFromTsconfigOptions(
transformOptions,
tsconfig.compilerOptions,
[], // NOTE: ignore warnings as the same warning will be shown by the plugin container
)
if (transformOptions.jsx === undefined) {
transformOptions.jsx = {}
} else if (
transformOptions.jsx === 'react' ||
transformOptions.jsx === 'react-jsx'
) {
transformOptions.jsx = getRollupJsxPresets(transformOptions.jsx)
}
Comment thread
sapphi-red marked this conversation as resolved.
Resolved
if (typeof transformOptions.jsx === 'object') {
transformOptions.jsx.development ??= !environment.config.isProduction
}
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/oxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export interface OxcOptions extends Omit<
jsxRefreshExclude?: string | RegExp | ReadonlyArray<string | RegExp>
}

function getRollupJsxPresets(preset: 'react' | 'react-jsx'): OxcJsxOptions {
export function getRollupJsxPresets(
preset: 'react' | 'react-jsx',
): OxcJsxOptions {
switch (preset) {
case 'react':
return {
Expand All @@ -72,7 +74,7 @@ function getRollupJsxPresets(preset: 'react' | 'react-jsx'): OxcJsxOptions {
preset satisfies never
}

export function setOxcTransformOptionsFromTsconfigOptions(
function setOxcTransformOptionsFromTsconfigOptions(
oxcOptions: Omit<OxcTransformOptions, 'jsx'> & {
jsx?:
| OxcTransformOptions['jsx']
Expand Down