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: make --force work for all environments #18901

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ cli
configFile: options.config,
logLevel: options.logLevel,
clearScreen: options.clearScreen,
optimizeDeps: { force: options.force },
server: cleanGlobalCLIOptions(options),
forceOptimizeDeps: options.force,
})

if (!server.httpServer) {
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export interface ResolvedWorkerOptions {
export interface InlineConfig extends UserConfig {
configFile?: string | false
envFile?: false
forceOptimizeDeps?: boolean
}

export type ResolvedConfig = Readonly<
Expand Down Expand Up @@ -742,6 +743,7 @@ function resolveEnvironmentOptions(
options: EnvironmentOptions,
alias: Alias[],
preserveSymlinks: boolean,
forceOptimizeDeps: boolean | undefined,
logger: Logger,
environmentName: string,
// Backward compatibility
Expand Down Expand Up @@ -771,6 +773,7 @@ function resolveEnvironmentOptions(
optimizeDeps: resolveDepOptimizationOptions(
options.optimizeDeps,
resolve.preserveSymlinks,
forceOptimizeDeps,
consumer,
),
dev: resolveDevEnvironmentOptions(
Expand Down Expand Up @@ -938,6 +941,7 @@ function resolveResolveOptions(
function resolveDepOptimizationOptions(
optimizeDeps: DepOptimizationOptions | undefined,
preserveSymlinks: boolean,
forceOptimizeDeps: boolean | undefined,
consumer: 'client' | 'server' | undefined,
): DepOptimizationOptions {
return mergeWithDefaults(
Expand All @@ -948,6 +952,7 @@ function resolveDepOptimizationOptions(
esbuildOptions: {
preserveSymlinks,
},
force: forceOptimizeDeps ?? configDefaults.optimizeDeps.force,
},
optimizeDeps ?? {},
)
Expand Down Expand Up @@ -1159,6 +1164,7 @@ export async function resolveConfig(
config.environments[environmentName],
resolvedDefaultResolve.alias,
resolvedDefaultResolve.preserveSymlinks,
inlineConfig.forceOptimizeDeps,
logger,
environmentName,
config.experimental?.skipSsrTransform,
Expand Down
18 changes: 15 additions & 3 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,24 +373,36 @@ export async function loadCachedDepOptimizationMetadata(
if (cachedMetadata.lockfileHash !== getLockfileHash(environment)) {
environment.logger.info(
'Re-optimizing dependencies because lockfile has changed',
{
timestamp: true,
},
)
} else if (cachedMetadata.configHash !== getConfigHash(environment)) {
environment.logger.info(
'Re-optimizing dependencies because vite config has changed',
{
timestamp: true,
},
)
} else {
log?.('Hash is consistent. Skipping. Use --force to override.')
log?.(
`(${environment.name}) Hash is consistent. Skipping. Use --force to override.`,
)
// Nothing to commit or cancel as we are using the cache, we only
// need to resolve the processing promise so requests can move on
return cachedMetadata
}
}
} else {
environment.logger.info('Forced re-optimization of dependencies')
environment.logger.info('Forced re-optimization of dependencies', {
timestamp: true,
})
}

// Start with a fresh cache
debug?.(colors.green(`removing old cache dir ${depsCacheDir}`))
debug?.(
`(${environment.name}) ${colors.green(`removing old cache dir ${depsCacheDir}`)}`,
)
await fsp.rm(depsCacheDir, { recursive: true, force: true })
}

Expand Down
4 changes: 1 addition & 3 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,7 @@ async function restartServer(server: ViteDevServer) {
let inlineConfig = server.config.inlineConfig
if (server._forceOptimizeOnRestart) {
inlineConfig = mergeConfig(inlineConfig, {
optimizeDeps: {
force: true,
},
forceOptimizeDeps: true,
})
}

Expand Down
Loading