Skip to content

Commit

Permalink
fix: use ssr.resolve.conditions on Vite 6
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 21, 2025
1 parent 62bb62e commit 9ef7071
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ export function createPool(ctx: Vitest): ProcessPool {
// in addition to resolve.conditions Vite also adds production/development,
// see: https://github.com/vitejs/vite/blob/af2aa09575229462635b7cbb6d248ca853057ba2/packages/vite/src/node/plugins/resolve.ts#L1056-L1080
const viteMajor = Number(viteVersion.split('.')[0])
const potentialConditions = new Set([
...viteMajor >= 6 ? [] : ['production', 'development'],
...ctx.vite.config.resolve.conditions,
])
const potentialConditions = new Set(viteMajor >= 6
? (ctx.vite.config.ssr.resolve?.conditions ?? [])
: [
'production',
'development',
...ctx.vite.config.resolve.conditions,
])
const conditions = [...potentialConditions]
.filter((condition) => {
if (condition === 'production') {
Expand Down
5 changes: 5 additions & 0 deletions test/config/test/conditions-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ test('correctly imports external dependencies with a custom condition', async ()
resolve: {
conditions: ['custom'],
},
ssr: {
resolve: {
conditions: ['custom'],
},
},
define: {
TEST_CONDITION: '"custom"',
},
Expand Down

0 comments on commit 9ef7071

Please sign in to comment.