Skip to content

Commit

Permalink
feat: allow using parseAst from rollup with VITE_USE_LEGACY_PARSE_AST
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 17, 2025
1 parent 608039f commit b120a59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const nodeConfig = defineConfig({
external: [
/^vite\//,
'fsevents',
'rollup/parseAst',
'rolldown/parseAst',
'rolldown/experimental',
/^tsx\//,
Expand Down
10 changes: 10 additions & 0 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export function throwClosedServerError(): never {
throw err
}

// NOTE: add a env var to use parseAst from rollup for now
const useLegacyParseAst = !!process.env.VITE_USE_LEGACY_PARSE_AST
let legacyParseAst: typeof import('rollup/parseAst').parseAst

export interface PluginContainerOptions {
cwd?: string
output?: OutputOptions
Expand All @@ -141,6 +145,9 @@ export async function createEnvironmentPluginContainer(
plugins,
watcher,
)
if (useLegacyParseAst) {
legacyParseAst = await import('rollup/parseAst').then((mod) => mod.parseAst)
}
await container.resolveRollupOptions()
return container
}
Expand Down Expand Up @@ -578,6 +585,9 @@ class PluginContext
}

parse(code: string, opts: any) {
if (useLegacyParseAst) {
return legacyParseAst(code, opts)
}
return rolldownParseAst(code, opts)
}

Expand Down

0 comments on commit b120a59

Please sign in to comment.