forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vite6): re-apply default conditions if using vite 6 or later
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
- Loading branch information
thebanjomatic
committed
Dec 11, 2024
1 parent
4e60333
commit c15f198
Showing
3 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { version } from 'vite' | ||
|
||
const [major] = version.split('.').map(Number) | ||
|
||
const hasDefaultConditions = major >= 6 | ||
|
||
interface DefaultConditions { | ||
defaultClientConditions: string[] | ||
defaultServerConditions: string[] | ||
} | ||
|
||
async function getDefaultConditions(): Promise<DefaultConditions> { | ||
if (!hasDefaultConditions) { | ||
return { defaultClientConditions: [], defaultServerConditions: [] } | ||
} | ||
|
||
type Vite6Options = typeof import('vite') & DefaultConditions | ||
return (await import('vite')) as Vite6Options | ||
} | ||
|
||
export async function getConditions() { | ||
const defaults = await getDefaultConditions() | ||
return { | ||
clientConditions: ['browser', ...defaults.defaultClientConditions], | ||
serverConditions: ['node', ...defaults.defaultServerConditions], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters