Skip to content

feat(self): support virtual modules and synchronous plugins - #81

Merged
pi0 merged 4 commits into
mainfrom
feat/self-hooks
Oct 18, 2026
Merged

pi0 merged 4 commits into
mainfrom
feat/self-hooks

Conversation

@pi0x

@pi0x pi0x commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

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)

  • Hooks are registered in the host process before the entry is imported (virtual entries supported); updateVirtualModules() / invalidateModule() apply in-process, close() unregisters.
  • Each runner owns its registration (registerOwnedVirtualModules()), so concurrent self runners don't mutate each other's keys.
  • Since the module cache is process-wide: versions are process-wide, path keys always get a ?v=<n> query in the self runner (import.meta.url carries it), and a second self runner for the same entry imports it fresh (importFreshEntry()).
  • Fix (also workers): require() cache entries of non-path keys keep the version query, so repeated updates of a require()d key were stale.

Synchronous plugins

  • resolveId / load / transform chains in pipeline.ts are 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 typed Promise<PluginResolvedId | null> | PluginResolvedId | null (returns a value in sync mode; await keeps working).
  • Bun: later self runners' plugins are no longer shadowed by an earlier (unremovable) Bun.plugin registration.

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; vitest server.deps.external: [/\/dist\//], since vitest's module runner bypasses registerHooks), plus sync-driver unit tests. 1046 passed / 47 skipped; lint + typecheck clean.

🤖 Generated with AI assistant

pi0 added 2 commits October 18, 2026 15:03
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.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 210c1df6-251d-4259-8070-1f09fa975297
📥 Commits

Reviewing files that changed from the base of the PR and between 27cc639 and ccc43ea.

📒 Files selected for processing: 16
  • .agents/ARCHITECTURE.md
  • .agents/NODE-RUNNERS.md
  • .agents/PLUGINS.md
  • .agents/VIRTUAL-MODULES.md
  • AGENTS.md
  • README.md
  • src/common/base-runner.ts
  • src/common/virtual-modules.ts
  • src/common/worker-utils.ts
  • src/plugin/channel.ts
  • src/plugin/hooks.ts
  • src/plugin/pipeline.ts
  • src/runners/self/runner.ts
  • test/plugins.test.ts
  • test/virtual.test.ts
  • vitest.config.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/env-runner@81

commit: ccc43ea

# Conflicts:
#	src/runners/self/runner.ts
@pi0
pi0 merged commit f29478e into main Oct 18, 2026
11 checks passed
@pi0
pi0 deleted the feat/self-hooks branch October 18, 2026 15:41
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.

2 participants