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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const pages = import.meta.glob('./pages/*.tsx')

export default <div />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default <main />
43 changes: 43 additions & 0 deletions packages/vite/src/node/__tests__/scan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,49 @@ test('scan jsx-runtime', async (ctx) => {
expect(mod1).toBe(mod2)
})

test('scan import.meta.glob respects rolldown transform jsx options', async (ctx) => {
const server = await createServer({
configFile: false,
logLevel: 'error',
root: path.join(import.meta.dirname, 'fixtures', 'scan-jsx-runtime'),
oxc: {
jsx: {
runtime: 'automatic',
importSource: 'react',
},
},
optimizeDeps: {
force: true,
noDiscovery: false,
entries: ['./entry-glob-custom-oxc.tsx'],
rolldownOptions: {
transform: {
jsx: {
runtime: 'automatic',
importSource: 'vue',
},
},
},
},
})
ctx.onTestFinished(() => server.close())

const { cancel, result } = scanImports(
devToScanEnvironment(server.environments.client),
)
ctx.onTestFinished(cancel)

const scanResult = await result

expect(scanResult).toMatchObject({
deps: {
'vue/jsx-dev-runtime': expect.any(String),
},
missing: {},
})
expect(scanResult.deps).not.toHaveProperty('react/jsx-runtime')
})

test('scan import.meta.glob package imports patterns', async (ctx) => {
const server = await createServer({
configFile: false,
Expand Down
19 changes: 16 additions & 3 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fsp from 'node:fs/promises'
import path from 'node:path'
import { performance } from 'node:perf_hooks'
import { scan } from 'rolldown/experimental'
import type { TransformOptions as OxcTransformOptions } from 'rolldown/utils'
import { transformSync } from 'rolldown/utils'
import type { PartialResolvedId, Plugin } from 'rolldown'
import colors from 'picocolors'
Expand Down Expand Up @@ -252,9 +253,6 @@ async function prepareRolldownScanner(
const { plugins: pluginsFromConfig = [], ...rolldownOptions } =
environment.config.optimizeDeps.rolldownOptions ?? {}

const plugins = await asyncFlatten(arraify(pluginsFromConfig))
plugins.push(...rolldownScanPlugin(environment, deps, missing, entries))

const transformOptions = deepClone(rolldownOptions.transform) ?? {}
if (transformOptions.jsx === undefined) {
transformOptions.jsx = {}
Expand All @@ -267,6 +265,19 @@ async function prepareRolldownScanner(
if (typeof transformOptions.jsx === 'object') {
transformOptions.jsx.development ??= !environment.config.isProduction
}
const transformSyncJsxOptions: OxcTransformOptions['jsx'] =
transformOptions.jsx === false ? undefined : transformOptions.jsx

const plugins = await asyncFlatten(arraify(pluginsFromConfig))
plugins.push(
...rolldownScanPlugin(
environment,
deps,
missing,
entries,
transformSyncJsxOptions,
),
)

async function build() {
await scan({
Expand Down Expand Up @@ -343,6 +354,7 @@ function rolldownScanPlugin(
depImports: Record<string, string>,
missing: Record<string, string>,
entries: string[],
jsxOptions: OxcTransformOptions['jsx'],
): Plugin[] {
const seen = new Map<string, string | undefined>()
async function resolveId(
Expand Down Expand Up @@ -397,6 +409,7 @@ function rolldownScanPlugin(
// transpile because `transformGlobImport` only expects js
if (loader !== 'js') {
const result = transformSync(id, contents, {
...(jsxOptions !== undefined ? { jsx: jsxOptions } : {}),
lang: loader,
tsconfig: false,
})
Expand Down
Loading