Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 92
perf: stop build plugins doing work the bundler can filter#871
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
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,64 @@ | ||
| /** | ||
| * Mirrors unplugin's `StringFilter`. Declared here because `unplugin` is a dependency of | ||
| * the module package, not of the test root. | ||
| */ | ||
| type FilterPattern = string | RegExp | Array<string | RegExp> | ||
| type StringFilter = FilterPattern | { include?: FilterPattern, exclude?: FilterPattern } | ||
| /** | ||
| * Calling `plugin.transform.handler` directly skips the declared `transform.filter`, | ||
| * so a filter that stops matching the files it should would fail no test. These helpers | ||
| * apply the filter first, the way a bundler does. | ||
| * | ||
| * Semantics mirror unplugin's `createFilterForTransform`: a string pattern is a | ||
| * substring test, a RegExp is `test()`, an array is OR, and any `exclude` match vetoes. | ||
| */ | ||
| function matches(pattern: string | RegExp, value: string): boolean { | ||
| return typeof pattern === 'string' ? value.includes(pattern) : pattern.test(value) | ||
| } | ||
| function matchesFilter(filter: StringFilter | undefined, value: string): boolean { | ||
| if (filter === undefined) | ||
| return true | ||
| if (typeof filter === 'string' || filter instanceof RegExp) | ||
| return matches(filter, value) | ||
| if (Array.isArray(filter)) | ||
| return filter.some(pattern => matches(pattern, value)) | ||
| const { include, exclude } = filter | ||
| if (exclude !== undefined) { | ||
| const excluded = Array.isArray(exclude) | ||
| ? exclude.some(pattern => matches(pattern, value)) | ||
| : matches(exclude, value) | ||
| if (excluded) | ||
| return false | ||
| } | ||
| if (include === undefined) | ||
| return true | ||
| return Array.isArray(include) | ||
| ? include.some(pattern => matches(pattern, value)) | ||
| : matches(include, value) | ||
| } | ||
| /** Would a bundler hand this module to the plugin's transform hook? */ | ||
| export function transformAccepts(plugin: any, id: string, code: string): boolean { | ||
| const filter = plugin.transform?.filter | ||
| if (!filter) | ||
| return true | ||
| return matchesFilter(filter.id, id) && matchesFilter(filter.code, code) | ||
| } | ||
| /** | ||
| * Run a transform the way a bundler would: filter, then handler. | ||
| * Returns `undefined` when the filter rejects the module, matching a hook that never ran. | ||
| */ | ||
| export async function runTransform( | ||
| plugin: any, | ||
| { id, code, context = {} }: { id: string, code: string, context?: Record<string, unknown> }, | ||
| ): Promise<any> { | ||
| if (!transformAccepts(plugin, id, code)) | ||
| return undefined | ||
| const handler = plugin.transform?.handler ?? plugin.transform | ||
| return handler.call(context, code, id) | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use path-only extension matching in both plugins.
packages/script/src/plugins/transform.ts#L25-L33: anchorVUE_REandJS_REto the module path before?; otherwise query values can skip valid transforms or invoke parsing for non-JavaScript IDs.packages/script/src/plugins/check-scripts.ts#L6-L9: apply the same path-only rule toVUE_REto avoid unnecessary handler calls.📍 Affects 2 files
packages/script/src/plugins/transform.ts#L25-L33(this comment)packages/script/src/plugins/check-scripts.ts#L6-L9🤖 Prompt for AI Agents