Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't modify config #9262

Merged
merged 5 commits into from Jul 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 56 additions & 49 deletions packages/vite/src/node/config.ts
Expand Up @@ -412,25 +412,6 @@ export async function resolveConfig(
}
})

let workerConfig = mergeConfig({}, config)
const [workerPrePlugins, workerNormalPlugins, workerPostPlugins] =
sortUserPlugins(rawWorkerUserPlugins)

// run config hooks
const workerUserPlugins = [
...workerPrePlugins,
...workerNormalPlugins,
...workerPostPlugins
]
for (const p of workerUserPlugins) {
if (p.config) {
const res = await p.config(workerConfig, configEnv)
if (res) {
workerConfig = mergeConfig(workerConfig, res)
}
}
}

// resolve plugins
const rawUserPlugins = (
(await asyncFlatten(config.plugins || [])) as Plugin[]
Expand Down Expand Up @@ -607,6 +588,24 @@ export async function resolveConfig(
const BASE_URL = resolvedBase

// resolve worker
let workerConfig = mergeConfig({}, config)
bluwy marked this conversation as resolved.
Show resolved Hide resolved
const [workerPrePlugins, workerNormalPlugins, workerPostPlugins] =
sortUserPlugins(rawWorkerUserPlugins)

// run config hooks
const workerUserPlugins = [
...workerPrePlugins,
...workerNormalPlugins,
...workerPostPlugins
]
for (const p of workerUserPlugins) {
if (p.config) {
const res = await p.config(workerConfig, configEnv)
if (res) {
workerConfig = mergeConfig(workerConfig, res)
}
}
}
const resolvedWorkerOptions: ResolveWorkerOptions = {
format: workerConfig.worker?.format || 'iife',
plugins: [],
Expand Down Expand Up @@ -663,7 +662,44 @@ export async function resolveConfig(
...config.experimental
}
}
const resolved: ResolvedConfig = Object.assign(config, resolvedConfig)
const resolved: ResolvedConfig = {
...config,
...resolvedConfig
}

;(resolved.plugins as Plugin[]) = await resolvePlugins(
resolved,
prePlugins,
normalPlugins,
postPlugins
)

const workerResolved: ResolvedConfig = {
...workerConfig,
...resolvedConfig,
isWorker: true,
bluwy marked this conversation as resolved.
Show resolved Hide resolved
mainConfig: resolved
}

resolvedConfig.worker.plugins = await resolvePlugins(
workerResolved,
workerPrePlugins,
workerNormalPlugins,
workerPostPlugins
)

// call configResolved hooks
await Promise.all(
userPlugins
.map((p) => p.configResolved?.(resolved))
.concat(
resolvedConfig.worker.plugins.map((p) =>
p.configResolved?.(workerResolved)
)
)
)

// validate config

if (middlewareMode === 'ssr') {
logger.warn(
Expand Down Expand Up @@ -695,35 +731,6 @@ export async function resolveConfig(
)
}

;(resolved.plugins as Plugin[]) = await resolvePlugins(
resolved,
prePlugins,
normalPlugins,
postPlugins
)

const workerResolved: ResolvedConfig = Object.assign(
workerConfig,
resolvedConfig,
{
isWorker: true,
mainConfig: resolved
}
)
resolved.worker.plugins = await resolvePlugins(
workerResolved,
workerPrePlugins,
workerNormalPlugins,
workerPostPlugins
)

// call configResolved hooks
await Promise.all(
userPlugins
.map((p) => p.configResolved?.(resolved))
.concat(workerUserPlugins.map((p) => p.configResolved?.(workerResolved)))
)

if (process.env.DEBUG) {
debug(`using resolved config: %O`, {
...resolved,
Expand Down