Skip to content

feat(vpx): support import.meta.glob in scripts - #3566

Draft
fengmk2 wants to merge 7 commits into
mainfrom
feat/vpx-import-meta-glob
Draft

fengmk2 wants to merge 7 commits into
mainfrom
feat/vpx-import-meta-glob

Conversation

@fengmk2

@fengmk2 fengmk2 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #3525

Note

This draft holds the design only. The implementation follows in this PR, after the oxc-node change lands and the pin moves.

vpx ./src/server.ts fails today when the script calls import.meta.glob, because no layer of the script loader expands the call and Node.js has no import.meta.glob:

TypeError: (intermediate value).glob is not a function

This PR adds a Glob Imports section to rfcs/vpx-script-execution.md and a short note to rfcs/script-import-loader.md.

Design

  • Expansion in oxc-node: a pass in oxc-node's Rust transform expands each call after the TypeScript transform, as Vite's plugin runs after its TypeScript transform. All load paths (pirates, in-thread and off-thread ESM hooks) go through that transform. The generated code has Vite's shape (Object.assign({...}) in place, eager imports first), and oxc's code generator makes the source map.
  • Switch: the pass is off by default in oxc-node. The vpx loader turns it on with setImportGlob(true), so every script that vpx or vite-plus/register runs has glob imports. A file without a glob call keeps its cost.
  • Matching: the globstar crate, which Rolldown's glob plugin uses for its dev-mode matcher, plus a walk with Vite's rules. The picomatch forms that globstar lacks are rewritten first: (a|b) groups, ranges of two characters, and POSIX classes. Dot names follow picomatch's rule, node_modules is skipped unless exhaustive, the importer is removed, and keys are sorted. The RFC lists the differences from Vite's unbundled tinyglobby/picomatch path.
  • Supported forms: relative patterns, arrays, ! patterns, eager, import, relative base, exhaustive, caseSensitive, Object.keys() and Object.values(). /-rooted patterns, aliases, query/as, and non-literal option values fail with a code frame, because vpx loads no Vite config.
  • Watch mode: the binding records each expansion, and the loader sends it as a watch:glob report. vpx --watch restarts when a matching file is created or deleted, as Vite's hotUpdate does. The watcher tests new files with the binding's GlobMatcher, the code that listed the map. An edit restarts the script only when the script loaded the file.
  • Layers: Vite+ takes the oxc-node change with a pin bump, forwards the new binding functions, and turns the pass on in its loader entries. The global CLI and the CLI/loader contract do not change, so the global vpx and the project-local vpx behave the same.

🤖 Generated with Claude Code

Add a Glob Imports section to the vpx script RFC. The loader expands
each import.meta.glob call before the oxc-node transform, keeps every
original line and column, and reports matched files and patterns to
the watcher so vpx --watch restarts when matches change.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-vpx-import-meta-glob-viteplus-dev.voidzero-docs.workers.dev (commit 6e40296)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://d25b990c-viteplus-dev.voidzero-docs.workers.dev 6e40296 2026-11-25T15:26:29.364Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c3034c73-viteplus-dev.voidzero-docs.workers.dev 302fbdd 2026-11-25T07:02:33.345Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a9fc1af7-viteplus-dev.voidzero-docs.workers.dev 25d253c 2026-11-25T06:02:09.293Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8440dfbe-viteplus-dev.voidzero-docs.workers.dev c36e714 2026-11-24T13:18:58.692Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://3612fe6e-viteplus-dev.voidzero-docs.workers.dev 761a33b 2026-11-24T10:07:27.074Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://74ae5865-viteplus-dev.voidzero-docs.workers.dev 2447e5a 2026-11-24T07:27:48.658Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ab838699-viteplus-dev.voidzero-docs.workers.dev d05dfcc 2026-11-24T06:59:29.908Z Visit the dashboard ↗

fengmk2 and others added 2 commits November 24, 2026 15:26
Use tinyglobby for the map and picomatch for watch restarts, with the
options of Vite's unbundled import-glob plugin. Expand oxc-node's output
in place, put eager imports first, and restart only when a matching file
is created or deleted, as Vite's hotUpdate does.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the glob expansion into a pass of oxc-node's Rust transform, with
Vite's code shape and the source map from oxc's code generator. The
binding records each expansion for the watcher, and its GlobMatcher
tests new files with the code that listed the map. Vite+ forwards the
new functions and turns the pass on in the vpx loader.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2

fengmk2 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

oxc-project/oxc-node#937

fengmk2 and others added 4 commits November 24, 2026 21:17
oxc-node now matches glob imports with the globstar crate, as Rolldown's
dev-mode matcher does, and rewrites the picomatch forms that globstar
lacks: (a|b) groups, ranges of two characters, and POSIX classes. Dot
names follow picomatch's rule, so that difference from Vite is gone.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record that oxc-node#937 implements the oxc-node part, and describe what
it does now: the rewrite of picomatch forms, the walk that asks
match_dir(), the shape of the watch entry, and the loop guard keyed on
the file's state. Add the interface, the two Vite messages that were
missing, real projects that use glob imports on the server, and the
open question about /-rooted patterns.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow oxc-node#937: generated specifiers percent-encode URL characters
while the keys keep the file names, eager import names avoid names that
the source spells with a \u escape, and --exclude holds for the files
that a glob report lists.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The watcher now enters the folders that GlobMatcher.mayEnter() allows,
so the dot-folder limit and its difference row are gone, and
globMatcher returns { matches, mayEnter }. oxc-node reads
OXC_IMPORT_GLOB in the binding for every entry point, with
setImportGlob() as an override.

Refs #3525

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

Support import.meta.glob in scripts run by vpx

1 participant