Skip to content

Commit

Permalink
fix: print unexpected error message if peer dependencies have a diffe…
Browse files Browse the repository at this point in the history
…rent version (#6446)
  • Loading branch information
sheremet-va authored Sep 5, 2024
1 parent c3ac43c commit b992b34
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"magic-string": "^0.30.11",
"msw": "^2.3.5",
"sirv": "^2.0.4",
"tinyrainbow": "^1.2.0",
"ws": "^8.18.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions packages/browser/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { WorkspaceProject } from 'vitest/node'
import type { Plugin } from 'vitest/config'
import { createServer } from 'vitest/node'
import c from 'tinyrainbow'
import { version } from '../../package.json'
import { setupBrowserRpc } from './rpc'
import { BrowserServer } from './server'
import BrowserPlugin from './plugin'
Expand All @@ -14,6 +16,16 @@ export async function createBrowserServer(
prePlugins: Plugin[] = [],
postPlugins: Plugin[] = [],
) {
if (project.ctx.version !== version) {
project.ctx.logger.warn(
c.yellow(
`Loaded ${c.inverse(c.yellow(` vitest@${project.ctx.version} `))} and ${c.inverse(c.yellow(` @vitest/browser@${version} `))}.`
+ '\nRunning mixed versions is not supported and may lead into bugs'
+ '\nUpdate your dependencies and make sure the versions match.',
),
)
}

const server = new BrowserServer(project, '/')

const configPath = typeof configFile === 'string' ? configFile : false
Expand Down
14 changes: 13 additions & 1 deletion packages/ui/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ import { basename, resolve } from 'pathe'
import sirv from 'sirv'
import type { Plugin } from 'vite'
import { coverageConfigDefaults } from 'vitest/config'
import type { Vitest } from 'vitest'
import type { Vitest } from 'vitest/node'
import { toArray } from '@vitest/utils'
import c from 'tinyrainbow'
import { version } from '../package.json'

export default (ctx: Vitest): Plugin => {
if (ctx.version !== version) {
ctx.logger.warn(
c.yellow(
`Loaded ${c.inverse(c.yellow(` vitest@${ctx.version} `))} and ${c.inverse(c.yellow(` @vitest/ui@${version} `))}.`
+ '\nRunning mixed versions is not supported and may lead into bugs'
+ '\nUpdate your dependencies and make sure the versions match.',
),
)
}

return <Plugin>{
name: 'vitest:ui',
apply: 'serve',
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b992b34

Please sign in to comment.