Skip to content

Commit

Permalink
chore: revert rollup/parseAst changes
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jan 18, 2024
1 parent fa869e1 commit 9493220
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as Rollup from 'rollup'

export type { Rollup }
export { initRollupParseAst, parseAst, parseAstAsync } from './utils'
export { parseAst, parseAstAsync } from 'rollup/parseAst'
export {
defineConfig,
loadConfigFromFile,
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type { InlineConfig, ResolvedConfig } from '../config'
import { isDepsOptimizerEnabled, resolveConfig } from '../config'
import {
diffDnsOrderChange,
initRollupParseAst,
isInNodeModules,
isObject,
isParentDirectory,
Expand Down Expand Up @@ -817,7 +816,6 @@ export async function _createServer(
if (initingServer) return initingServer

initingServer = (async function () {
await initRollupParseAst()
await container.buildStart({})
// start deps optimizer after all container plugins are ready
if (isDepsOptimizerEnabled(config, false)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SOFTWARE.
import fs from 'node:fs'
import { join } from 'node:path'
import { performance } from 'node:perf_hooks'
import { parseAst as rollupParseAst } from 'rollup/parseAst'
import type {
AsyncPluginHooks,
CustomPluginOptions,
Expand Down Expand Up @@ -71,7 +72,6 @@ import {
isObject,
normalizePath,
numberToPos,
parseAst,
prettifyUrl,
rollupVersion,
timeFrom,
Expand Down Expand Up @@ -302,7 +302,7 @@ export async function createPluginContainer(
}

parse(code: string, opts: any) {
return parseAst(code, opts)
return rollupParseAst(code, opts)
}

async resolve(
Expand Down
42 changes: 1 addition & 41 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import debug from 'debug'
import type { Alias, AliasOptions } from 'dep-types/alias'
import type MagicString from 'magic-string'

import type { AstNode, ParseAst, ParseAstAsync, TransformResult } from 'rollup'
import type { TransformResult } from 'rollup'
import { createFilter as _createFilter } from '@rollup/pluginutils'
import {
CLIENT_ENTRY,
Expand All @@ -41,46 +41,6 @@ import {
} from './packages'
import type { CommonServerOptions } from '.'

let rollupParseAst: ParseAst
let rollupParseAstAsync: ParseAstAsync
let rollupInited: Promise<any> | boolean = false
export async function initRollupParseAst(): Promise<any | boolean> {
if (!rollupInited) {
const importRollupParseAst = import('rollup/parseAst')
rollupInited = importRollupParseAst
const { parseAst, parseAstAsync } = await importRollupParseAst
rollupParseAst = parseAst
rollupParseAstAsync = parseAstAsync
rollupInited = true
}
return rollupInited
}
export function parseAst(
code: string,
options?: {
allowReturnOutsideFunction?: boolean
},
): AstNode {
if (!rollupInited) {
throw new Error(
`rollup/parseAst is not initialized yet, call initRollupParseAst() first`,
)
}
return rollupParseAst(code, options)
}

export async function parseAstAsync(
code: string,
options?: {
allowReturnOutsideFunction?: boolean
},
): Promise<AstNode> {
if (rollupInited === false) {
await initRollupParseAst()
}
return rollupParseAstAsync(code, options)
}

/**
* Inlined to keep `@rollup/pluginutils` in devDependencies
*/
Expand Down

0 comments on commit 9493220

Please sign in to comment.