Repository navigation
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| /** | ||
| * Escapes a string for use as a literal in a `RegExp` (`RegExp.escape()` needs | ||
| * Node 24) | ||
| */ | ||
| function escapeRegExp(text: string): string { | ||
| return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| } |
There was a problem hiding this comment.
| /** | |
| * Escapes a string for use as a literal in a `RegExp` (`RegExp.escape()` needs | |
| * Node 24) | |
| */ | |
| function escapeRegExp(text: string): string { | |
| return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |
| } | |
| const ESCAPE_REGEX_PATTERN = /[.*+?^${}()|[\]\\]/g; | |
| function escapeRegExp(str: string): string { | |
| return str.replace(ESCAPE_REGEX_PATTERN, '\\$&'); | |
| } |
Its generally a good practice to define the regex separately so that it is compiled once rather than being created on every invocation
There was a problem hiding this comment.
Also update the regex to /[/\\^$*+?.()|[\]{}]/g. This is what Rolldown uses for the same
Overview
wxt buildfails when the project's absolute path contains regex syntax such as+, e.g. a git worktree named after a branch with a slash (sync/foo→.claude/worktrees/sync+foo):removeEntrypointMainFunctionbuilds its transform filter asnew RegExp(^${absPath}$)without escaping the path. With a+, the filter never matches the entrypoint, so its main function and imports aren't removed when WXT imports it to read its options. When the entrypoint imports CSS, Vite's module runner evaluates it, andvite:css-postcrashes, sincecssModulesCacheis only populated inbuildStart. Before the switch to hook filters (0.20.11), the plugin comparedid === absPath.This escapes the path before building the regex. I wrote a small helper rather than use
RegExp.escape(), which needs Node 24 (WXT supports Node 22). The othernew RegExp()filters in the Vite plugins are built from fixed virtual module IDs, not paths, so they're left as they are.The new unit test checks that the filter matches entrypoints in paths with
+,( ),[ ]and., and that it matches the path literally. Without the fix, 4 of its 6 cases fail.Manual Testing
Reproduction: https://github.com/namuorg/wxt-plus-path-repro (four files, WXT 0.21.5)
After replacing
node_modules/wxt/dist/internal/builders/vite/plugins/remove-entrypoint-main-function.mjswith this branch's build (bun run --filter wxt build), the same build succeeds. A clone into a path without+builds either way.bun run --filter wxt checkpassesbun run --filter wxt test run: 576 passed, 2 skipped, 2 todoRelated Issue
This PR closes #2718