forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared-modules.ts
69 lines (64 loc) · 2.26 KB
/
shared-modules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
type SharedModuleMetadata = Partial<{
/**
* If `true`, only a single version of the module can be loaded at runtime.
*
* @default false
*/
singleton: boolean;
/**
* If `true`, plugins will provide their own fallback version of the module.
*
* The fallback module will be loaded when a matching module is not found within
* the Console shared scope object. If the given module is declared as singleton
* and is already loaded, the fallback module will not load.
*
* @default true
*/
allowFallback: boolean;
}>;
/**
* Modules shared between the Console application and its dynamic plugins.
*/
export const sharedPluginModules = [
'@openshift-console/dynamic-plugin-sdk',
'@openshift-console/dynamic-plugin-sdk-internal',
'@patternfly/react-core',
'@patternfly/react-table',
'@patternfly/quickstarts',
'react',
'react-i18next',
'react-router',
'react-router-dom',
'react-router-dom-v5-compat',
'react-redux',
'redux',
'redux-thunk',
] as const;
export type SharedModuleNames = typeof sharedPluginModules[number];
/**
* Metadata associated with the shared modules.
*/
const sharedPluginModulesMetadata: Record<SharedModuleNames, SharedModuleMetadata> = {
'@openshift-console/dynamic-plugin-sdk': { singleton: true, allowFallback: false },
'@openshift-console/dynamic-plugin-sdk-internal': { singleton: true, allowFallback: false },
'@patternfly/react-core': {},
'@patternfly/react-table': {},
'@patternfly/quickstarts': {},
react: { singleton: true, allowFallback: false },
'react-i18next': { singleton: true, allowFallback: false },
'react-router': { singleton: true, allowFallback: false },
'react-router-dom': { singleton: true, allowFallback: false },
'react-router-dom-v5-compat': { singleton: true, allowFallback: false },
'react-redux': { singleton: true, allowFallback: false },
redux: { singleton: true, allowFallback: false },
'redux-thunk': { singleton: true, allowFallback: false },
};
/**
* Retrieve full metadata for the given shared module.
*/
export const getSharedModuleMetadata = (
moduleName: SharedModuleNames,
): Required<SharedModuleMetadata> => {
const { singleton = false, allowFallback = true } = sharedPluginModulesMetadata[moduleName];
return { singleton, allowFallback };
};