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

feat: add config.operation #12298

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 7 additions & 7 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('preview config', () => {
const config: InlineConfig = {
server: serverConfig(),
}
expect(await resolveConfig(config, 'serve')).toMatchObject({
expect(await resolveConfig(config, 'serve', 'preview')).toMatchObject({
preview: {
...serverConfig(),
port: undefined,
Expand All @@ -238,7 +238,7 @@ describe('preview config', () => {
port: 3006,
},
}
expect(await resolveConfig(config, 'serve')).toMatchObject({
expect(await resolveConfig(config, 'serve', 'preview')).toMatchObject({
preview: {
...serverConfig(),
port: 3006,
Expand All @@ -261,7 +261,7 @@ describe('preview config', () => {
server: serverConfig(),
preview: previewConfig(),
}
expect(await resolveConfig(config, 'serve')).toMatchObject({
expect(await resolveConfig(config, 'serve', 'preview')).toMatchObject({
preview: previewConfig(),
})
})
Expand Down Expand Up @@ -293,8 +293,8 @@ describe('resolveConfig', () => {
clearScreen: true,
}

const results1 = await resolveConfig(config1, 'build')
const results2 = await resolveConfig(config2, 'build')
const results1 = await resolveConfig(config1, 'build', 'build')
const results2 = await resolveConfig(config2, 'build', 'build')

expect(results1.clearScreen).toBe(false)
expect(results2.clearScreen).toBe(false)
Expand All @@ -307,8 +307,8 @@ describe('resolveConfig', () => {
clearScreen: true,
}

const results1 = await resolveConfig(config1, 'build')
const results2 = await resolveConfig(config2, 'build')
const results1 = await resolveConfig(config1, 'build', 'build')
const results2 = await resolveConfig(config2, 'build', 'build')

expect(results1.clearScreen).toBe(false)
expect(results2.clearScreen).toBe(false)
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/__tests__/dev.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('resolveBuildOptions in dev', () => {
},
},
'serve',
'dev',
)

expect(config.build.rollupOptions).not.toHaveProperty('input')
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/plugins/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function createCssPluginTransform(
files?: Record<string, string>,
inlineConfig: InlineConfig = {},
) {
const config = await resolveConfig(inlineConfig, 'serve')
const config = await resolveConfig(inlineConfig, 'serve', 'dev')
const { transform, buildStart } = cssPlugin(config)

// @ts-expect-error buildStart is function
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/__tests__/plugins/define.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ async function createDefinePluginTransform(
build = true,
ssr = false,
) {
const config = await resolveConfig({ define }, build ? 'build' : 'serve')
const config = await resolveConfig(
{ define },
build ? 'build' : 'serve',
build ? 'build' : 'dev',
)
const instance = definePlugin(config)
return async (code: string) => {
const result = await (instance.transform as any).call({}, code, 'foo.ts', {
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export async function build(
const config = await resolveConfig(
inlineConfig,
'build',
'build',
'production',
'production',
)
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ cli
logLevel: options.logLevel,
},
'serve',
'optimize',
)
await optimizeDeps(config, options.force, true)
} catch (e) {
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type {
export interface ConfigEnv {
command: 'build' | 'serve'
mode: string
cmd: 'build' | 'dev' | 'preview' | 'optimize'
/**
* @experimental
*/
Expand Down Expand Up @@ -335,7 +336,8 @@ export type ResolvedConfig = Readonly<
rawBase: string
publicDir: string
cacheDir: string
command: 'build' | 'serve'
// #12298
cmd: 'build' | 'dev' | 'preview' | 'optimize'
mode: string
isWorker: boolean
// in nested worker bundle to find the main config
Expand Down Expand Up @@ -380,6 +382,7 @@ export type ResolveFn = (
export async function resolveConfig(
inlineConfig: InlineConfig,
command: 'build' | 'serve',
cmd: 'build' | 'dev' | 'preview' | 'optimize',
defaultMode = 'development',
defaultNodeEnv = 'development',
): Promise<ResolvedConfig> {
Expand All @@ -397,6 +400,7 @@ export async function resolveConfig(
const configEnv = {
mode,
command,
cmd,
ssrBuild: !!config.build?.ssr,
}

Expand Down Expand Up @@ -649,6 +653,7 @@ export async function resolveConfig(
resolve: resolveOptions,
publicDir: resolvedPublicDir,
cacheDir,
cmd,
command,
mode,
ssr,
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export async function preview(
const config = await resolveConfig(
inlineConfig,
'serve',
'preview',
'production',
'production',
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ async function getPluginContainer(
const config = await resolveConfig(
{ configFile: false, ...inlineConfig },
'serve',
'dev',
)

// @ts-expect-error This plugin requires a ViteDevServer instance.
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export interface ResolvedServerUrls {
export async function createServer(
inlineConfig: InlineConfig = {},
): Promise<ViteDevServer> {
const config = await resolveConfig(inlineConfig, 'serve')
const config = await resolveConfig(inlineConfig, 'serve', 'dev')
const { root, server: serverConfig } = config
const httpsOptions = await resolveHttpsConfig(config.server.https)
const { middlewareMode } = serverConfig
Expand Down
1 change: 1 addition & 0 deletions playground/vitestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function loadConfigFromDir(dir: string) {
return loadConfigFromFile(
{
command: isBuild ? 'build' : 'serve',
operation: isBuild ? 'build' : 'dev',
mode: isBuild ? 'production' : 'development',
},
undefined,
Expand Down