-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(tegg-vitest): reuse runner module graph for prototypes #6029
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
Merged
elrrrrrrr
merged 5 commits into
eggjs:next
from
elrrrrrrr:codex/tegg-vitest-module-importer
Jul 12, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06d58d6
fix(tegg-vitest): reuse runner module graph for prototypes
elrrrrrrr 7cf3265
chore: publish tegg loader and vitest beta.22
elrrrrrrr 3ab0fe4
chore: leave package versions to release workflow
elrrrrrrr 0a4c757
fix(tegg-vitest): install module importer in test vm
elrrrrrrr 1f65fe4
Merge branch 'next' into codex/tegg-vitest-module-importer
elrrrrrrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import fs from 'node:fs'; | ||
| import { createRequire } from 'node:module'; | ||
| import path from 'node:path'; | ||
| import { pathToFileURL } from 'node:url'; | ||
|
|
||
| const nodeRequire = createRequire(import.meta.url); | ||
| const esmDirectoryCache = new Map<string, boolean>(); | ||
|
|
||
| function isEsmFile(filePath: string): boolean { | ||
| if (filePath.endsWith('.mjs')) return true; | ||
| if (filePath.endsWith('.cjs')) return false; | ||
|
|
||
| let directory = path.dirname(filePath); | ||
| const visited: string[] = []; | ||
| while (directory !== path.dirname(directory)) { | ||
| const cached = esmDirectoryCache.get(directory); | ||
| if (cached !== undefined) { | ||
| for (const item of visited) esmDirectoryCache.set(item, cached); | ||
| return cached; | ||
| } | ||
|
|
||
| visited.push(directory); | ||
| const packageFile = path.join(directory, 'package.json'); | ||
| if (fs.existsSync(packageFile)) { | ||
| let isEsm = false; | ||
| try { | ||
| isEsm = JSON.parse(fs.readFileSync(packageFile, 'utf8')).type === 'module'; | ||
| } catch { | ||
| // Invalid package metadata follows Node's CommonJS-compatible fallback. | ||
| } | ||
| for (const item of visited) esmDirectoryCache.set(item, isEsm); | ||
| return isEsm; | ||
| } | ||
| directory = path.dirname(directory); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // This setup file runs inside the test ViteVM. CJS files must use Node's | ||
| // require cache, while ESM files stay in Vitest's transformed import graph. | ||
| globalThis.__EGG_MODULE_IMPORTER__ = async (filePath: string) => { | ||
| if (isEsmFile(filePath)) return import(pathToFileURL(filePath).href); | ||
| return nodeRequire(filePath); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.