Skip to content

Commit

Permalink
fix(vitest): use esm module resolution to resolve env (#3951)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 15, 2023
1 parent a428f8d commit edb322f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/env/index.ts
@@ -1,6 +1,6 @@
import { pathToFileURL } from 'node:url'
import { normalize, resolve } from 'pathe'
import { resolveModule } from 'local-pkg'
import { resolvePath } from 'mlly'
import type { BuiltinEnvironment, VitestEnvironment } from '../../types/config'
import type { Environment } from '../../types'
import node from './node'
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function loadEnvironment(name: VitestEnvironment, root: string): Pr
return environments[name]
const packageId = name[0] === '.' || name[0] === '/'
? resolve(root, name)
: resolveModule(`vitest-environment-${name}`, { paths: [root] }) ?? resolve(root, name)
: await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name)
const pkg = await import(pathToFileURL(normalize(packageId)).href)
if (!pkg || !pkg.default || typeof pkg.default !== 'object') {
throw new TypeError(
Expand Down
4 changes: 3 additions & 1 deletion test/env-custom/vitest-environment-custom/package.json
@@ -1,5 +1,7 @@
{
"name": "vitest-environment-custom",
"private": true,
"main": "index.mjs"
"exports": {
".": "./index.mjs"
}
}

0 comments on commit edb322f

Please sign in to comment.