-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: call resolveId('vitest')
after buildStart
#5646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: call resolveId('vitest')
after buildStart
#5646
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
require.resolve('vitest')
instead of resolveId
during initresolveId('vitest')
after buildStart
packages/vitest/src/node/core.ts
Outdated
@@ -386,6 +381,11 @@ export class Vitest { | |||
async start(filters?: string[]) { | |||
this._onClose = [] | |||
|
|||
// if Vitest is running globally, then we should still import local vitest if possible | |||
const projectVitestPath = await this.vitenode.resolveId('vitest') | |||
const vitestDir = projectVitestPath ? resolve(projectVitestPath.id, '../..') : rootDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vs code extension doesn't call start
at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, really...
I had createRequire
approach before 1037511. Would this work better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could delay it further to ctx.runFiles
. Let me think...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createRequire
approach is wrong because we need Vite to process it. Having it in runFiles is fine. We can have a guard to not check this path if it is resolved, and reset it in configureServer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need Vite's resolution? If the purpose is only to find local Vitest, would createRequire
with require.resolve('vitest', { paths: [config.root] })
do the same?
This was the approach used for package installer:
vitest/packages/vitest/src/node/packageInstaller.ts
Lines 15 to 18 in 04df286
if (process.versions.pnp) { | |
const targetRequire = createRequire(__dirname) | |
try { | |
targetRequire.resolve(dependency, { paths: [root, __dirname] }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need Vite's resolution because files importing vitest are processed by Vite. It's possible that Vitest is called globally and resolved id is not correct, or there is an alias or resolveId interception
Description
resolveId
is called beforebuildStart
with enforce: 'pre' #5616ctx.distPath
is only used by poolrunTests
, so we can moveresolveId
fromctx.setServer
toctx.start
.todo
pnpm.overrides
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.