forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared-modules-meta.ts
More file actions
67 lines (62 loc) · 1.91 KB
/
shared-modules-meta.ts
File metadata and controls
67 lines (62 loc) · 1.91 KB
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
type SharedModuleMetadata = Partial<{
/**
* If `true`, only a single version of the module can be loaded at runtime.
*
* @default true
*/
singleton: boolean;
/**
* If `true`, plugins may provide their own fallback version of the module.
*
* The fallback module will be loaded when a matching module is not found within
* the Console share scope object. If the given module is declared as singleton
* and is already loaded, the fallback module will not load.
*
* @default false
*/
allowFallback: boolean;
}>;
/**
* Modules shared between the Console application and its dynamic plugins.
*/
export const sharedPluginModules = [
'@openshift/dynamic-plugin-sdk',
'@openshift-console/dynamic-plugin-sdk',
'@openshift-console/dynamic-plugin-sdk-internal',
'@patternfly/react-topology',
'react',
'react-i18next',
'react-redux',
'react-router',
'react-router-dom',
'react-router-dom-v5-compat',
'redux',
'redux-thunk',
] as const;
export type SharedModuleNames = typeof sharedPluginModules[number];
/**
* Metadata associated with the shared modules.
*/
const sharedPluginModulesMetadata: Record<SharedModuleNames, SharedModuleMetadata> = {
'@openshift/dynamic-plugin-sdk': {},
'@openshift-console/dynamic-plugin-sdk': {},
'@openshift-console/dynamic-plugin-sdk-internal': {},
'@patternfly/react-topology': {},
react: {},
'react-i18next': {},
'react-redux': {},
'react-router': { singleton: false }, // fixes runtime error when both v5-compat and v5 are present
'react-router-dom': {},
'react-router-dom-v5-compat': {},
redux: {},
'redux-thunk': {},
};
/**
* Retrieve full metadata for the given shared module.
*/
export const getSharedModuleMetadata = (
moduleName: SharedModuleNames,
): Required<SharedModuleMetadata> => {
const { singleton = true, allowFallback = false } = sharedPluginModulesMetadata[moduleName];
return { singleton, allowFallback };
};