Skip to content

Commit 99897d2

Browse files
authored
fix: hasBothRollupOptionsAndRolldownOptions should return false for proxy case (#22043)
1 parent 0dad284 commit 99897d2

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

packages/vite/src/node/__tests__/config.spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { InlineConfig, PluginOption } from '..'
66
import type { UserConfig, UserConfigExport } from '../config'
77
import { defineConfig, loadConfigFromFile, resolveConfig } from '../config'
88
import { resolveEnvPrefix } from '../env'
9-
import { mergeConfig } from '../utils'
9+
import { hasBothRollupOptionsAndRolldownOptions, mergeConfig } from '../utils'
1010
import { createLogger } from '../logger'
1111

1212
describe('mergeConfig', () => {
@@ -560,6 +560,46 @@ describe('mergeConfig', () => {
560560
expect(downOutput.hashCharacters).toBe('base36')
561561
})
562562

563+
test('hasBothRollupOptionsAndRolldownOptions returns false when only rollupOptions is set', () => {
564+
// When mergeConfig is called with only rollupOptions in the override,
565+
// setupRollupOptionCompat creates a proxy where rollupOptions === rolldownOptions.
566+
// hasBothRollupOptionsAndRolldownOptions should return false in this case
567+
// to avoid false positive warnings.
568+
const baseConfig = defineConfig({
569+
build: {}, // Need existing build object for recursive merge to happen
570+
})
571+
const newConfig = defineConfig({
572+
build: {
573+
rollupOptions: {
574+
treeshake: false,
575+
},
576+
},
577+
})
578+
const mergedConfig: UserConfig = mergeConfig(baseConfig, newConfig)
579+
580+
expect(mergedConfig.build!.rollupOptions).toBeDefined()
581+
expect(mergedConfig.build!.rolldownOptions).toBeDefined()
582+
expect(mergedConfig.build!.rollupOptions).toBe(
583+
mergedConfig.build!.rolldownOptions,
584+
)
585+
586+
expect(hasBothRollupOptionsAndRolldownOptions(mergedConfig)).toBe(false)
587+
})
588+
589+
test('hasBothRollupOptionsAndRolldownOptions returns true when both are explicitly set to different values', () => {
590+
const config = defineConfig({
591+
build: {
592+
rollupOptions: {
593+
treeshake: false,
594+
},
595+
rolldownOptions: {
596+
platform: 'neutral',
597+
},
598+
},
599+
})
600+
expect(hasBothRollupOptionsAndRolldownOptions(config)).toBe(true)
601+
})
602+
563603
test('rollupOptions/rolldownOptions.platform', async () => {
564604
const testRollupOptions = await resolveConfig(
565605
{

packages/vite/src/node/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,9 @@ export function hasBothRollupOptionsAndRolldownOptions(
13171317
if (
13181318
opt != null &&
13191319
opt.rollupOptions != null &&
1320-
opt.rolldownOptions != null
1320+
opt.rolldownOptions != null &&
1321+
// Check they are not just proxy values created by setupRollupOptionCompat
1322+
opt.rollupOptions !== opt.rolldownOptions
13211323
) {
13221324
return true
13231325
}

0 commit comments

Comments
 (0)