Skip to content

Commit

Permalink
fix: await init rollup/parseAst in buildStart
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jan 18, 2024
1 parent 63e2c1b commit ad32d57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/vite/src/node/plugins/assetImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '../config'
import type { ResolveFn } from '../'
import {
initRollupParseAst,
injectQuery,
isParentDirectory,
slash,
Expand Down Expand Up @@ -56,8 +55,6 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
/\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/dg
const cleanString = stripLiteral(code)

await initRollupParseAst()

let match: RegExpExecArray | null
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
const [[startIndex, endIndex], [urlStart, urlEnd]] = match.indices!
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
createDebugger,
ensureWatchedFile,
generateCodeFrame,
initRollupParseAst,
isExternalUrl,
isObject,
normalizePath,
Expand Down Expand Up @@ -164,6 +165,8 @@ export async function createPluginContainer(
const { getSortedPluginHooks, getSortedPlugins } =
createPluginHookUtils(plugins)

const initRollupParseAstPromise = initRollupParseAst()

const seenResolves: Record<string, true | undefined> = {}
const debugResolve = createDebugger('vite:resolve')
const debugPluginResolve = createDebugger('vite:plugin-resolve', {
Expand Down Expand Up @@ -655,6 +658,7 @@ export async function createPluginContainer(
getModuleInfo,

async buildStart() {
await initRollupParseAstPromise
await handleHookPromise(
hookParallel(
'buildStart',
Expand Down

0 comments on commit ad32d57

Please sign in to comment.