UNPKG

1.74 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.getSortedUsageRows = exports.filterInteractivePlugins = void 0;
7
8/**
9 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
10 *
11 * This source code is licensed under the MIT license found in the
12 * LICENSE file in the root directory of this source tree.
13 */
14const filterInteractivePlugins = (watchPlugins, globalConfig) => {
15 const usageInfos = watchPlugins.map(
16 p => p.getUsageInfo && p.getUsageInfo(globalConfig)
17 );
18 return watchPlugins.filter((_plugin, i) => {
19 const usageInfo = usageInfos[i];
20
21 if (usageInfo) {
22 const {key} = usageInfo;
23 return !usageInfos.slice(i + 1).some(u => !!u && key === u.key);
24 }
25
26 return false;
27 });
28};
29
30exports.filterInteractivePlugins = filterInteractivePlugins;
31
32function notEmpty(value) {
33 return value != null;
34}
35
36const getSortedUsageRows = (watchPlugins, globalConfig) =>
37 filterInteractivePlugins(watchPlugins, globalConfig)
38 .sort((a, b) => {
39 if (a.isInternal && b.isInternal) {
40 // internal plugins in the order we specify them
41 return 0;
42 }
43
44 if (a.isInternal !== b.isInternal) {
45 // external plugins afterwards
46 return a.isInternal ? -1 : 1;
47 }
48
49 const usageInfoA = a.getUsageInfo && a.getUsageInfo(globalConfig);
50 const usageInfoB = b.getUsageInfo && b.getUsageInfo(globalConfig);
51
52 if (usageInfoA && usageInfoB) {
53 // external plugins in alphabetical order
54 return usageInfoA.key.localeCompare(usageInfoB.key);
55 }
56
57 return 0;
58 })
59 .map(p => p.getUsageInfo && p.getUsageInfo(globalConfig))
60 .filter(notEmpty);
61
62exports.getSortedUsageRows = getSortedUsageRows;