Skip to content

feat(experimental): implement sync module runner with lazy evaluation - #12149

Draft
sheremet-va wants to merge 52 commits into
mainfrom
feat/lazy-imports
Draft

sheremet-va wants to merge 52 commits into
mainfrom
feat/lazy-imports

Conversation

@sheremet-va

Copy link
Copy Markdown
Member

work in progress

@netlify

netlify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 4e8041b
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6b0eeb2b7386218103805fee
😎 Deploy Preview https://deploy-preview-12149--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va

Copy link
Copy Markdown
Member Author

Nothing to look at!

Screenshot 2026-12-01 at 10 30 06

Sync module linker that loads the static import graph in one request and evaluates modules without side effects on first access, with mock support, the link transform, and test call collection for preParse.
Global setup, the server runner, custom environments, web workers and vm pools run linked environments through ModuleLinker.
A static vi.mock in an imported module applies to the modules that run after it, and prepare() keeps the walk promise.
linkTransform hoists vi.mock calls itself, and mock factories run before the code of the module that reads them.
LinkRecords are shared per worker and Vite environment, each vm context keeps its own linker state. Also renames LinkedEnvironmentLoader to LinkedEnvironmentModuleRunner and restores GET_BUILTIN_MODULE from main in moduleEvaluator.ts.
ModuleLinker becomes ModuleLoader in runtime/moduleRunner/moduleLoader/ (loader, records, types, utils).
createNodeImportMeta uses pathToFileURL from node:url, so a lazy module that runs after vi.stubGlobal('URL', ...) still gets import.meta.
A module linked before vi.resetModules gets the instances of its own graph, import() after the reset gets new ones.
The server resolves literal `vi.requireActual` and `vi.requireMock` paths
and adds the modules to the graph of the file, they run at the call.
The errors of the sync APIs keep their message in a `vi.mock` factory.
…import, not on access to simplify tree shaking
`require()` of an ES module graph with top-level await throws before a
module of the graph runs. The loader marks the external and requests
the modules that wait for it again, so `import()` loads it at its import.

The selection has the names that the code reads from a package without
side effects. Their files run with the importer.
The export entries of es-module-lexer 3 have the source and the name of
each re-export, so the files of a package without side effects are not
parsed with oxc.
One session class for the module graph of a loader, one environment check, and the options of the flag in the resolved config.
The response has the number of a module in place of its id in each import, no keys without a value, and the names of the code files. The worker keeps a record class with the resolved target of each import, so the loader does no lookup by a string for an import.
The module instance is a class that owns its namespace object, and the modules that Node loads have their own class. The loader keeps the load, the link check and the order of evaluation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant