Repository navigation
feat: Overridable runner and entrypointFinder
#2647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c76231
feat: Overridable `runner` and `entrypointFinder`
aklinker1 9a93c16
Remove comments
aklinker1 e7e0066
Replace internal deprecated API usage
aklinker1 f1e9592
Fix checks
aklinker1 ba09dea
Update failed tests
aklinker1 f78912f
Cleanup
aklinker1 d4285a7
Cleanup
aklinker1 f782927
Fix failing tests
aklinker1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import type { | ||
| Entrypoint, | ||
| EntrypointFinder, | ||
| EntrypointInfo, | ||
| ResolvedConfig, | ||
| } from '../../types'; | ||
| import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from '../utils/constants'; | ||
| import { CSS_EXTENSIONS_PATTERN } from '../utils/paths'; | ||
| import picomatch from 'picomatch'; | ||
| import { glob } from 'tinyglobby'; | ||
| import { getEntrypointName } from '../utils/entrypoints'; | ||
| import { resolve } from 'node:path'; | ||
|
|
||
| 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', | ||
| }; | ||
|
|
||
| /** | ||
| * WXT's default entrypoint finder. It looks up entrypoints using a flat folder | ||
| * structure inside the `entrypoints.` directory, as described in the docs: | ||
| * https://wxt.dev/guide/essentials/entrypoints.html | ||
| */ | ||
| export class FlatEntrypointFinder implements EntrypointFinder { | ||
| constructor(public config: ResolvedConfig) {} | ||
|
|
||
| async findEntrypoints(): Promise<EntrypointInfo[]> { | ||
| 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; | ||
| }); | ||
|
Comment on lines
+73
to
+106
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-pasted with no changes |
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-pasted with no changes