[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(vitest): always resolve vitest to the root version (#6369)

authored by

Vladimir and committed by
GitHub
(Aug 20, 2024, 1:46 PM +0200) 163d7624 5388f0c0

+28 -8
+7 -1
test/workspaces/space_3/package.json
··· 1 1 { 2 2 "name": "@vitest/space_3", 3 - "private": true 3 + "private": true, 4 + "scripts": { 5 + "test": "vitest" 6 + }, 7 + "dependencies": { 8 + "vitest": "link:./fake-vitest" 9 + } 4 10 }
+3
test/workspaces/space_3/fake-vitest/config.js
··· 1 + exports.defineProject = (c) => { 2 + return c 3 + }
+1
test/workspaces/space_3/fake-vitest/index.js
··· 1 + throw new Error('should not import from fake vitest')
+8
test/workspaces/space_3/fake-vitest/package.json
··· 1 + { 2 + "name": "vitest", 3 + "type": "commonjs", 4 + "exports": { 5 + ".": "./index.js", 6 + "./config": "./config.js" 7 + } 8 + }
-2
packages/vitest/src/node/plugins/index.ts
··· 21 21 hijackVitePluginInject, 22 22 resolveFsAllow, 23 23 } from './utils' 24 - import { VitestResolver } from './vitestResolver' 25 24 import { VitestOptimizer } from './optimizer' 26 25 import { NormalizeURLPlugin } from './normalizeURL' 27 26 ··· 256 255 CoverageTransform(ctx), 257 256 options.ui ? await UIPlugin() : null, 258 257 ...MocksPlugins(), 259 - VitestResolver(ctx), 260 258 VitestOptimizer(), 261 259 NormalizeURLPlugin(), 262 260 ].filter(notNullish)
+9 -5
packages/vitest/src/node/plugins/vitestResolver.ts
··· 1 1 import type { Plugin } from 'vite' 2 - import { join } from 'pathe' 3 2 import type { Vitest } from '../core' 4 3 5 4 export function VitestResolver(ctx: Vitest): Plugin { 6 - return { 5 + const plugin: Plugin = { 7 6 name: 'vitest:resolve-root', 8 7 enforce: 'pre', 9 - async resolveId(id) { 8 + async resolveId(id, _, { ssr }) { 10 9 if (id === 'vitest' || id.startsWith('@vitest/')) { 11 - return this.resolve(id, join(ctx.config.root, 'index.html'), { 12 - skipSelf: true, 10 + // always redirect the request to the root vitest plugin since 11 + // it will be the one used to run Vitest 12 + const resolved = await ctx.server.pluginContainer.resolveId(id, undefined, { 13 + skip: new Set([plugin]), 14 + ssr, 13 15 }) 16 + return resolved 14 17 } 15 18 }, 16 19 } 20 + return plugin 17 21 }