Repository navigation
feat: Overridable runner and entrypointFinder - #2647
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 ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
| const PATH_GLOB_TO_TYPE_MAP: Record<string, Entrypoint['type']> = { | ||
| 'sandbox.html': 'sandbox', | ||
| 'sandbox/index.html': 'sandbox', | ||
| '*.sandbox.html': 'sandbox', | ||
| '*.sandbox/index.html': 'sandbox', | ||
|
|
||
| 'bookmarks.html': 'bookmarks', | ||
| 'bookmarks/index.html': 'bookmarks', | ||
|
|
||
| 'history.html': 'history', | ||
| 'history/index.html': 'history', | ||
|
|
||
| 'newtab.html': 'newtab', | ||
| 'newtab/index.html': 'newtab', | ||
|
|
||
| 'sidepanel.html': 'sidepanel', | ||
| 'sidepanel/index.html': 'sidepanel', | ||
| '*.sidepanel.html': 'sidepanel', | ||
| '*.sidepanel/index.html': 'sidepanel', | ||
|
|
||
| 'devtools.html': 'devtools', | ||
| 'devtools/index.html': 'devtools', | ||
|
|
||
| 'background.[jt]s': 'background', | ||
| 'background/index.[jt]s': 'background', | ||
| [VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: 'background', | ||
|
|
||
| 'content.[jt]s?(x)': 'content-script', | ||
| 'content/index.[jt]s?(x)': 'content-script', | ||
| '*.content.[jt]s?(x)': 'content-script', | ||
| '*.content/index.[jt]s?(x)': 'content-script', | ||
| [`content.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style', | ||
| [`*.content.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style', | ||
| [`content/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style', | ||
| [`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style', | ||
|
|
||
| 'popup.html': 'popup', | ||
| 'popup/index.html': 'popup', | ||
|
|
||
| 'options.html': 'options', | ||
| 'options/index.html': 'options', | ||
|
|
||
| '*.html': 'unlisted-page', | ||
| '*/index.html': 'unlisted-page', | ||
| '*.[jt]s?(x)': 'unlisted-script', | ||
| '*/index.[jt]s?(x)': 'unlisted-script', | ||
| [`*.${CSS_EXTENSIONS_PATTERN}`]: 'unlisted-style', | ||
| [`*/index.${CSS_EXTENSIONS_PATTERN}`]: 'unlisted-style', | ||
| }; |
There was a problem hiding this comment.
Copy-pasted with no changes
| const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), { | ||
| cwd: this.config.entrypointsDir, | ||
| expandDirectories: false, | ||
| }); | ||
| // Ensure consistent output | ||
| relativePaths.sort(); | ||
|
|
||
| const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP); | ||
| return relativePaths | ||
| .reduce<EntrypointInfo[]>((results, relativePath) => { | ||
| const inputPath = resolve(this.config.entrypointsDir, relativePath); | ||
| const name = getEntrypointName(this.config.entrypointsDir, inputPath); | ||
| const matchingGlob = pathGlobs.find((glob) => | ||
| picomatch(glob)(relativePath), | ||
| ); | ||
| if (matchingGlob) { | ||
| const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob]; | ||
| results.push({ name, inputPath, type }); | ||
| } | ||
| return results; | ||
| }, []) | ||
| .filter(({ name, inputPath }, _, entrypointInfos) => { | ||
| // Remove <name>/index.* if <name>/index.html exists | ||
| if (inputPath.endsWith('.html')) return true; | ||
| const isIndexFile = /index\..+$/.test(inputPath); | ||
| if (!isIndexFile) return true; | ||
|
|
||
| const hasIndexHtml = entrypointInfos.some( | ||
| (entry) => | ||
| entry.name === name && entry.inputPath.endsWith('index.html'), | ||
| ); | ||
|
|
||
| return !hasIndexHtml; | ||
| }); |
There was a problem hiding this comment.
Copy-pasted with no changes
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/is-background
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/runner
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
There was a problem hiding this comment.
Moved from E2E tests to unit tests now that the runner is a bit more isolated. Always better to write unit tests since they're faster than E2E tests.
There was a problem hiding this comment.
This file now lazy-loads web-ext and handles all the checks that were delegated to the WSL, safari, and manual runners from before.
| export * from './entrypoint-finders/flat'; | ||
| export * from './runners/manual'; | ||
| export * from './runners/web-ext'; |
| // TODO: Remove once config.runner is deprecated | ||
| Object.defineProperty(config, 'runner', { | ||
| get() { | ||
| return runner; | ||
| }, | ||
| set(value) { | ||
| wxt.runner = value; | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Keep runner on config to prevent a breaking change, but make it a proxy to wxt.runner.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2647 +/- ##
==========================================
+ Coverage 79.52% 80.18% +0.65%
==========================================
Files 135 134 -1
Lines 4054 4072 +18
Branches 944 944
==========================================
+ Hits 3224 3265 +41
+ Misses 734 712 -22
+ Partials 96 95 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Overview
While typing up #2646, I realized we could be doing a better job of abstracting some logic into "overridable" helpers. The idea being a WXT module/project hook can override part of WXT's logic instead of modifying the results via hooks.
There are three parts of WXT I want to be "overridable" on the
wxtobject:wxt.builder: already overridable today, no changeswxt.runner: currently exists atwxt.config.runner, and can be overwritten there. But I want all these accessble directly on thewxtobjectwxt.entrypointFinder: New abstraction that let's people completely replace WXT's built-in entrypoint discovery logicModules or projects can then set the values on
wxtobject to completely replace a chunk logic.To accomplish this, I had to refactor the
web-ext.tsrunner andfind-entrypoints.tsfile a bit.Manual Testing
See new unit tests.
Related Issue
N/A