1
1
import React , { useMemo } from 'react' ;
2
2
import { initialize , AppsConfig } from '@scalprum/core' ;
3
3
import { ScalprumContext } from './scalprum-context' ;
4
- import { FeatureFlags , PluginLoaderOptions , PluginStoreOptions , PluginStoreProvider } from '@openshift/dynamic-plugin-sdk' ;
4
+ import { FeatureFlags , PluginLoaderOptions , PluginManifest , PluginStoreOptions , PluginStoreProvider } from '@openshift/dynamic-plugin-sdk' ;
5
5
6
6
/**
7
7
* @deprecated
@@ -14,29 +14,46 @@ export interface ScalprumProviderProps<T extends Record<string, any> = Record<st
14
14
children ?: React . ReactNode ;
15
15
pluginSDKOptions ?: {
16
16
pluginStoreFeatureFlags ?: FeatureFlags ;
17
- pluginLoaderOptions ?: PluginLoaderOptions ;
17
+ pluginLoaderOptions ?: PluginLoaderOptions & {
18
+ /** @deprecated */
19
+ postProcessManifest ?: PluginLoaderOptions [ 'transformPluginManifest' ] ;
20
+ } ;
18
21
pluginStoreOptions ?: PluginStoreOptions ;
19
22
} ;
20
23
}
21
24
25
+ function baseTransformPluginManifest ( manifest : PluginManifest ) : PluginManifest {
26
+ return { ...manifest , loadScripts : manifest . loadScripts . map ( ( script ) => `${ manifest . baseURL } ${ script } ` ) } ;
27
+ }
28
+
22
29
export function ScalprumProvider < T extends Record < string , any > = Record < string , any > > ( {
23
30
config,
24
31
children,
25
32
api,
26
33
pluginSDKOptions,
27
34
} : ScalprumProviderProps < T > ) : React . ReactElement | React . ReactElement {
35
+ const { postProcessManifest, transformPluginManifest } = pluginSDKOptions ?. pluginLoaderOptions || { } ;
36
+ // SDK v4 and v5 compatibility layer
37
+ const internalTransformPluginManifest : PluginLoaderOptions [ 'transformPluginManifest' ] =
38
+ ( postProcessManifest || transformPluginManifest ) ?? baseTransformPluginManifest ;
39
+
40
+ if ( postProcessManifest ) {
41
+ console . error (
42
+ `[Scalprum] Deprecation warning!
43
+ Please use pluginSDKOptions.pluginLoaderOptions.transformPluginManifest instead of pluginSDKOptions.pluginLoaderOptions.postProcessManifest.
44
+ The postProcessManifest option will be removed in the next major release.` ,
45
+ ) ;
46
+ }
28
47
const state = useMemo (
29
48
( ) =>
30
49
initialize < T > ( {
31
50
appsConfig : config ,
32
51
api,
52
+ ...pluginSDKOptions ,
33
53
pluginLoaderOptions : {
34
- postProcessManifest ( manifest ) {
35
- return { ...manifest , loadScripts : manifest . loadScripts . map ( ( script ) => `${ manifest . baseURL } ${ script } ` ) } ;
36
- } ,
37
54
...pluginSDKOptions ?. pluginLoaderOptions ,
55
+ transformPluginManifest : internalTransformPluginManifest ,
38
56
} ,
39
- ...pluginSDKOptions ,
40
57
} ) ,
41
58
[ ] ,
42
59
) ;
0 commit comments