Skip to content

Commit 51a42c6

Browse files
authored
fix: make --force work for all environments (#18901)
1 parent 612332b commit 51a42c6

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

packages/vite/src/node/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ cli
189189
configLoader: options.configLoader,
190190
logLevel: options.logLevel,
191191
clearScreen: options.clearScreen,
192-
optimizeDeps: { force: options.force },
193192
server: cleanGlobalCLIOptions(options),
193+
forceOptimizeDeps: options.force,
194194
})
195195

196196
if (!server.httpServer) {

packages/vite/src/node/config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ export interface InlineConfig extends UserConfig {
548548
/** @experimental */
549549
configLoader?: 'bundle' | 'runner'
550550
envFile?: false
551+
forceOptimizeDeps?: boolean
551552
}
552553

553554
export interface ResolvedConfig
@@ -775,6 +776,7 @@ function resolveEnvironmentOptions(
775776
options: EnvironmentOptions,
776777
alias: Alias[],
777778
preserveSymlinks: boolean,
779+
forceOptimizeDeps: boolean | undefined,
778780
logger: Logger,
779781
environmentName: string,
780782
// Backward compatibility
@@ -804,6 +806,7 @@ function resolveEnvironmentOptions(
804806
optimizeDeps: resolveDepOptimizationOptions(
805807
options.optimizeDeps,
806808
resolve.preserveSymlinks,
809+
forceOptimizeDeps,
807810
consumer,
808811
),
809812
dev: resolveDevEnvironmentOptions(
@@ -980,6 +983,7 @@ function resolveResolveOptions(
980983
function resolveDepOptimizationOptions(
981984
optimizeDeps: DepOptimizationOptions | undefined,
982985
preserveSymlinks: boolean,
986+
forceOptimizeDeps: boolean | undefined,
983987
consumer: 'client' | 'server' | undefined,
984988
): DepOptimizationOptions {
985989
return mergeWithDefaults(
@@ -990,6 +994,7 @@ function resolveDepOptimizationOptions(
990994
esbuildOptions: {
991995
preserveSymlinks,
992996
},
997+
force: forceOptimizeDeps ?? configDefaults.optimizeDeps.force,
993998
},
994999
optimizeDeps ?? {},
9951000
)
@@ -1202,6 +1207,7 @@ export async function resolveConfig(
12021207
config.environments[environmentName],
12031208
resolvedDefaultResolve.alias,
12041209
resolvedDefaultResolve.preserveSymlinks,
1210+
inlineConfig.forceOptimizeDeps,
12051211
logger,
12061212
environmentName,
12071213
config.experimental?.skipSsrTransform,

packages/vite/src/node/optimizer/index.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -373,24 +373,36 @@ export async function loadCachedDepOptimizationMetadata(
373373
if (cachedMetadata.lockfileHash !== getLockfileHash(environment)) {
374374
environment.logger.info(
375375
'Re-optimizing dependencies because lockfile has changed',
376+
{
377+
timestamp: true,
378+
},
376379
)
377380
} else if (cachedMetadata.configHash !== getConfigHash(environment)) {
378381
environment.logger.info(
379382
'Re-optimizing dependencies because vite config has changed',
383+
{
384+
timestamp: true,
385+
},
380386
)
381387
} else {
382-
log?.('Hash is consistent. Skipping. Use --force to override.')
388+
log?.(
389+
`(${environment.name}) Hash is consistent. Skipping. Use --force to override.`,
390+
)
383391
// Nothing to commit or cancel as we are using the cache, we only
384392
// need to resolve the processing promise so requests can move on
385393
return cachedMetadata
386394
}
387395
}
388396
} else {
389-
environment.logger.info('Forced re-optimization of dependencies')
397+
environment.logger.info('Forced re-optimization of dependencies', {
398+
timestamp: true,
399+
})
390400
}
391401

392402
// Start with a fresh cache
393-
debug?.(colors.green(`removing old cache dir ${depsCacheDir}`))
403+
debug?.(
404+
`(${environment.name}) ${colors.green(`removing old cache dir ${depsCacheDir}`)}`,
405+
)
394406
await fsp.rm(depsCacheDir, { recursive: true, force: true })
395407
}
396408

packages/vite/src/node/server/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,7 @@ async function restartServer(server: ViteDevServer) {
11641164
let inlineConfig = server.config.inlineConfig
11651165
if (server._forceOptimizeOnRestart) {
11661166
inlineConfig = mergeConfig(inlineConfig, {
1167-
optimizeDeps: {
1168-
force: true,
1169-
},
1167+
forceOptimizeDeps: true,
11701168
})
11711169
}
11721170

0 commit comments

Comments
 (0)