-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Allow plugins to override other plugins #5878
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 contains 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 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 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,51 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
import type {GlobalConfig} from 'types/Config'; | ||
import type {WatchPlugin, UsageData} from '../types'; | ||
|
||
export const filterInteractivePlugins = ( | ||
watchPlugins: Array<WatchPlugin>, | ||
globalConfig: GlobalConfig, | ||
): Array<WatchPlugin> => { | ||
const usageInfos = watchPlugins.map( | ||
p => p.getUsageInfo && p.getUsageInfo(globalConfig), | ||
); | ||
|
||
return watchPlugins.filter((plugin, i, array) => { | ||
if (usageInfos[i]) { | ||
const {key} = usageInfos[i]; | ||
return !usageInfos.slice(i + 1).some(u => u && key === u.key); | ||
} | ||
|
||
return false; | ||
}); | ||
}; | ||
|
||
export const getSortedUsageRows = ( | ||
watchPlugins: Array<WatchPlugin>, | ||
globalConfig: GlobalConfig, | ||
): Array<UsageData> => { | ||
return filterInteractivePlugins(watchPlugins, globalConfig) | ||
.sort((a: WatchPlugin, b: WatchPlugin) => { | ||
if (a.isInternal) { | ||
return -1; | ||
} | ||
|
||
const usageInfoA = a.getUsageInfo && a.getUsageInfo(globalConfig); | ||
const usageInfoB = b.getUsageInfo && b.getUsageInfo(globalConfig); | ||
|
||
if (usageInfoA && usageInfoB) { | ||
return usageInfoA.key - usageInfoB.key; | ||
} | ||
|
||
return 0; | ||
}) | ||
.map(p => p.getUsageInfo && p.getUsageInfo(globalConfig)) | ||
.filter(Boolean); | ||
}; |
This file contains 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 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 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 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 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 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 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
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.
Should the base class every watch plugin extends have a
getUsageInfo
function which returnsnull
or empty string so you don't have to check for its existence?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.
I think this will make the implementation easier, but I'm worried about making the API for the consumers a bit harder. Given that there will be plugins that do not implement it
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.
I sometimes wonder if we should just move everything to be a jest hook, and make the whole API just around jest hooks
instead of
Seems like the plugin architecture is working already, which means that changing to an API like the one above should not be that hard.
This means that the
apply
method is the only method that exists in the class and everything else is a jestHook. Seems that if we would like to make this changes it is better to do them now than later.thoughts? Which API seems cleaner? Which API would be easier to document?
@rickhanlonii @orta @cpojer @SimenB
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.
I'm worried about the first API being too open. There are other open source tools out there that allow people to do anything they want in a plugin and it generally causes the entire system to slow down considerably. I think we should stick with a more limited API that guides user to build plugins in the way we expect them to be built. Of course, it's still possible to completely break out of that system and do harmful slow things but it is less likely to happen.
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.
+1 to @cpojer and I like that the current Watch Plugin API is similar in structure to the runner and reporter - implement a class with a specific structure
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.
+1 - slow and deliberate improvements as we need them, I think this looks great
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.
Perfect! 😄