Repository navigation
Conversation
A loader that expands globs, such as import.meta.glob, can now send
{ "watch:glob": [...] } through @oxc-node/core/watch-report. The watcher
walks the reported roots and restarts the app when a matching file
appears or goes. An edit is no change unless the app loaded the file.
The new runWatch option globMatcher lets the embedder match the files as
its loader does; the default uses path.matchesGlob.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a pass to the transform that expands import.meta.glob calls as Vite's plugin for unbundled code does. It runs after the TypeScript transform, on every load path, and only for files that contain import.meta while the switch is on (setImportGlob, OXC_IMPORT_GLOB). Patterns must be relative, because oxc-node has no project root and no aliases. The fast-glob crate matches the files. The binding records each expansion for watch mode (takeWatchGlobs), and GlobMatcher lets the watcher test new files with the same rules. oxnode watch uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guard skipped an at-once change for a file that caused one for the run before. A file that the first walk found new, and that was gone at the next report, was then skipped, so removing it did not restart the app. The guard now keys on the path and whether the file exists. Also build file URLs in the glob report tests that are absolute on Windows, and match the code frame path as join_errors prints it there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace fast-glob with globstar, pinned to the version that Rolldown pins. Its dot option reads a pattern part that spells the dot as picomatch does, so ./*/.config/*.ts now lists what Vite lists, and the walk asks match_dir() which folders to enter. Rewrite the picomatch forms that Vite reads and globstar lacks before matching: (a|b) groups, ranges of two characters, and POSIX classes. A pattern whose only glob syntax is a group also matches its literal text, as picomatch does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Encode the import specifiers of matched files. A specifier is a URL, so `#` started a fragment and `%20` loaded `name part.ts`. `%`, `#`, `?`, `\`, tabs, and line breaks are percent-encoded, as pathToFileURL encodes them. The keys stay the file names. - Apply --exclude to the files that a glob report lists. Before, the watcher registered them without the check, so removing an excluded file restarted the app. - Choose the prefix of generated names against the identifiers of the syntax tree when the source has a \u escape, so a name spelled `__vite_glob_0_0` is not declared twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pass ran only when the source contained the text "glob", but the call check read the decoded name. So `import.meta.glob()` threw on its own and expanded once an unrelated `/* glob */` comment was in the file. Vite finds the calls in the source text and never expands the escaped form, so a call now counts only when the source spells `glob` as written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oxc 0.160 removed `ObjectProperty::computed` and gave static string and number keys variants of their own, so the option parser did not compile against oxc-node's main. Tell a computed key by its span, which starts after the `[` of its property, and read the name with `static_name()`. Both work with oxc 0.156, which Vite+ builds with, and with 0.160. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Take main's oxc 0.160, which the glob option parser now compiles with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fengmk2
marked this pull request as ready for review
November 25, 2026 10:10
One folder rule:
- GlobSet::enters() is the walk's folder test, and GlobMatcher.mayEnter()
exposes it. runWatch's globMatcher returns { matches, mayEnter? }, so
the watcher prunes folders as the transform walks them: a new file in
./*/.config/ restarts, and exhaustive admits node_modules.
- A listed file is watched by the walk's rule (root, depth, pruned
folders, counts) instead of hard-coded names and a separate --exclude
filter. A `{` in a pattern no longer makes the depth unlimited.
One walker in DirWatcher:
- The --include roots and each glob are owners of one root list and one
walked map, instead of a second copy of the walker. `fire` is one
value, and `own: "run"` with a `presence` flag replaces `own: "glob"`.
Walks and events take fewer stats.
Smaller cleanups:
- OXC_IMPORT_GLOB is read in Rust like OXC_TRANSFORM_ALL, with
setImportGlob() as an override, so every entry point follows it.
- Shared helpers: parse_generated_program, scheme_len, posix_name_end,
toPaths, nodeMatchesGlob, Matcher.excludes, and encode_file_url_path
for specifiers. A relative path resolves against the transformer's
cwd. The pre-check needs `glob` as a word, resolve flushes skip
takeWatchGlobs, and dead state is gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Vite's
import.meta.globfinds modules by pattern. Server code that runs through Vite uses it to discover route files, for example:_404,_error,_renderer, and_middlewarefiles../admin/**/*.tsand./public/**/*.ts, without test files.Code like this cannot run under oxc-node today: the call reaches Node.js as written, and Node.js throws
TypeError: (intermediate value).glob is not a function.This PR expands the call in oxc-node's transform, and lets watch mode restart when a matching file appears or goes.
Switch
import.meta.globis not Node.js syntax, and a script may test for it, so the expansion is off by default.OXC_IMPORT_GLOB=1turns it on. The binding reads it as it readsOXC_TRANSFORM_ALL, with the same grammar, so every entry point follows it:oxnode,@oxc-node/core/register,@oxc-node/core/importer,OxcTransformer,transform, andtransformAsync.setImportGlob(enabled)overrides the variable for the calling thread, in both directions. A loader passesgetImportGlob()to itsmodule.register()hooks.import.metacosts nothing more. A file withimport.metacosts one substring search unless its source containsglob.Interface
The forms that oxc-node accepts, as a subset of Vite's
ImportGlobFunction(vite/types/importGlob.d.ts):globis one pattern or an array. Each pattern starts with./or../, or with!for a negative pattern (!**/xis valid).${}counts as a string.base, and starts with./or../. Keys are sorted, and the importer is never a key.Object.keys(import.meta.glob(...))andObject.values(import.meta.glob(...))import nothing for the part that they drop, as in Vite.import.meta.glob. A TypeScript project gets the type fromvite/client.Expansion
The pass runs in
transform_program, after the TypeScript transform, as Vite's plugin runs after Vite's TypeScript transform. Every load path goes through it: the CommonJS hook, the ESMload, and the module-runner importer.Object.assign({ "./routes/health.ts": () => import("./routes/health.ts") })replaces the call, and eager imports are the first statements. oxc's code generator makes the source map, so positions outside a call do not move.!patterns,eager,import, a relativebase,exhaustive,caseSensitive,Object.keys()andObject.values()./-rooted patterns and positive patterns that start with**(oxc-node has no project root), aliases and bare patterns,queryandas(Node.js loads a module, not text), non-literal arguments and option values, unknown options, and wrong option types.globstarcrate, pinned to=0.0.6, the version that Rolldown pins. Rolldown's glob plugin uses it for its dev-mode watch matcher.picomatchforms that Vite reads andglobstarlacks are rewritten first:(a|b)groups, ranges of two characters ({1..3}), and POSIX classes ([[:digit:]]). A pattern whose only glob syntax is a group also matches its literal text, aspicomatchdoes.., but a part of the pattern that spells the.does (./*/.config/*.ts), as inpicomatch. The walk asksglobstar'smatch_dir()which folders to enter.node_modulesis skipped unlessexhaustiveis set, the importer is removed, and keys are sorted. Extglob stays off, as Vite sets it.export {}, so it stays an ES module on the CommonJS path.%,#,?,\, tabs, and line breaks, aspathToFileURLdoes../routes/name#part.tsloads that file, not./routes/name. The keys stay the file names.__vite_glob_<call>_<file>) get more_until no name in the source starts with them, also a name spelled with a\uescape.Watch mode
{ "watch:glob": [...] }is a new report. Each entry hasroots(folders to walk, with an optional depth),includeandexclude(absolute patterns with/),dot,nocase, andfiles(what the app listed).takeWatchGlobs()returns the records, andflush,withFlush, andcreateRelayin@oxc-node/core/watch-reporttake it as a new optional argument.runWatchhas a new option,globMatcher: (glob) => { matches(file): boolean; mayEnter?(dir): boolean }.oxnode watchpasses the binding'sGlobMatcher, the same rules that listed the files and chose the folders to walk. Without the option, the watcher usespath.matchesGlob, and@oxc-node/cli/watchstill loads no binding.--includeroots. It enters the folders thatmayEnterallows, as the transform's walk does, so a new file in./*/.config/restarts the app. It always skips.gitand what--excludecovers. A listed file is watched by the same rule as a walked one. WithoutmayEnter, it skipsnode_modulesand dot folders unlessdotis set.hotUpdateignores edits for glob importers.--excludeholds for the listed files as for new ones: removing an excluded file restarts nothing.The README describes the switch, the forms, the errors, and the embedding API.
🤖 Generated with Claude Code