-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow plugin keys to be overriden by other plugins (#5878)
- Loading branch information
Showing
10 changed files
with
142 additions
and
19 deletions.
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