Skip to content

Commit

Permalink
fix: fix ensurePackageInstalled on Yarn PnP (#4657)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj authored Dec 5, 2023
1 parent 1df2991 commit 574cc7d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/vitest/src/node/pkg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import url from 'node:url'
import { createRequire } from 'node:module'
import c from 'picocolors'
import { isPackageExists } from 'local-pkg'
import { EXIT_CODE_RESTART } from '../constants'
Expand All @@ -10,6 +11,16 @@ export async function ensurePackageInstalled(
dependency: string,
root: string,
) {
if (process.versions.pnp) {
const targetRequire = createRequire(__dirname)
try {
targetRequire.resolve(dependency, { paths: [root, __dirname] })
return true
}
catch (error) {
}
}

if (isPackageExists(dependency, { paths: [root, __dirname] }))
return true

Expand Down

0 comments on commit 574cc7d

Please sign in to comment.