Repository navigation
feat(self): support virtual modules and synchronous plugins - #81
Merged
Merged
Conversation
Register `data.virtual` in the host process before importing the entry, with per-runner ownership (`registerOwnedVirtualModules()`): updates and invalidation apply in-process to the runner's own registration, and `close()` unregisters it. Path keys (and keys an earlier self runner served) start versioned, and a repeated entry is imported fresh, so later runners don't reuse cached instances. Virtual module versions are now process-wide. Tests import the self runner from `dist` (externalized in vitest) so its entry import reaches the hooks.
The self runner registers the plugin loader hooks in the host process and runs the pipeline synchronously in them (`createDirectTransformClient()` → `pipeline.sync`), so no worker has to block while the host runs handlers. The pipeline's `resolveId`/`load`/`transform` chains are now generators yielding handler calls, run by an async driver (workers, miniflare) or a sync one that throws when a handler returns a Promise. In sync chains, `this.resolve()` returns the result itself. Virtual modules are still transformed with the async driver before registration and on updates. On Bun, each registration's `onLoad` callbacks dispatch to the latest live registration, since plugins can't be removed and the earliest matching `onLoad` runs.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 17 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
pi0
approved these changes
Oct 18, 2026
# Conflicts: # src/runners/self/runner.ts
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The self runner (in-process, no worker) can now be used for host/prod one-time server starts with virtual modules and plugins.
Virtual modules (
data.virtual)updateVirtualModules()/invalidateModule()apply in-process,close()unregisters.registerOwnedVirtualModules()), so concurrent self runners don't mutate each other's keys.?v=<n>query in the self runner (import.meta.urlcarries it), and a second self runner for the same entry imports it fresh (importFreshEntry()).require()cache entries of non-path keys keep the version query, so repeated updates of arequire()d key were stale.Synchronous plugins
resolveId/load/transformchains inpipeline.tsare generators run by an async driver (workers/miniflare, unchanged) or a sync driver (pipeline.sync.*). A handler returning a Promise on a disk module throws a clear error; virtual sources are still transformed by async plugins on the host before registration.registerPluginHooks()takes an injectable transport; the self runner calls the sync pipeline directly (createDirectTransformClient()).this.resolve()is typedPromise<PluginResolvedId | null> | PluginResolvedId | null(returns a value in sync mode;awaitkeeps working).Bun.pluginregistration.module.register()async hooks were not used: runtime-deprecated in Node 26 (DEP0205) and unavailable on Deno/Bun.Caveats (documented)
Hooks apply to every import in the host process; modules the process already loaded stay cached (untransformed); Bun plugins can't be removed; the module cache only grows.
Tests
Self runner joins the virtual-module and plugin suites (imported from
dist; vitestserver.deps.external: [/\/dist\//], since vitest's module runner bypassesregisterHooks), plus sync-driver unit tests. 1046 passed / 47 skipped; lint + typecheck clean.🤖 Generated with AI assistant