-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vitest): always resolve vitest to the root version (#6369)
- Loading branch information
1 parent
5388f0c
commit 163d762
Showing
6 changed files
with
28 additions
and
8 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
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 |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import type { Plugin } from 'vite' | ||
import { join } from 'pathe' | ||
import type { Vitest } from '../core' | ||
|
||
export function VitestResolver(ctx: Vitest): Plugin { | ||
return { | ||
const plugin: Plugin = { | ||
name: 'vitest:resolve-root', | ||
enforce: 'pre', | ||
async resolveId(id) { | ||
async resolveId(id, _, { ssr }) { | ||
if (id === 'vitest' || id.startsWith('@vitest/')) { | ||
return this.resolve(id, join(ctx.config.root, 'index.html'), { | ||
skipSelf: true, | ||
// always redirect the request to the root vitest plugin since | ||
// it will be the one used to run Vitest | ||
const resolved = await ctx.server.pluginContainer.resolveId(id, undefined, { | ||
skip: new Set([plugin]), | ||
ssr, | ||
}) | ||
return resolved | ||
} | ||
}, | ||
} | ||
return plugin | ||
} |
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,3 @@ | ||
exports.defineProject = (c) => { | ||
return c | ||
} |
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 @@ | ||
throw new Error('should not import from fake vitest') |
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,8 @@ | ||
{ | ||
"name": "vitest", | ||
"type": "commonjs", | ||
"exports": { | ||
".": "./index.js", | ||
"./config": "./config.js" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
{ | ||
"name": "@vitest/space_3", | ||
"private": true | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"dependencies": { | ||
"vitest": "link:./fake-vitest" | ||
} | ||
} |