11import React , { useMemo } from 'react' ;
22import { initialize , AppsConfig } from '@scalprum/core' ;
33import { 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' ;
55
66/**
77 * @deprecated
@@ -14,29 +14,46 @@ export interface ScalprumProviderProps<T extends Record<string, any> = Record<st
1414 children ?: React . ReactNode ;
1515 pluginSDKOptions ?: {
1616 pluginStoreFeatureFlags ?: FeatureFlags ;
17- pluginLoaderOptions ?: PluginLoaderOptions ;
17+ pluginLoaderOptions ?: PluginLoaderOptions & {
18+ /** @deprecated */
19+ postProcessManifest ?: PluginLoaderOptions [ 'transformPluginManifest' ] ;
20+ } ;
1821 pluginStoreOptions ?: PluginStoreOptions ;
1922 } ;
2023}
2124
25+ function baseTransformPluginManifest ( manifest : PluginManifest ) : PluginManifest {
26+ return { ...manifest , loadScripts : manifest . loadScripts . map ( ( script ) => `${ manifest . baseURL } ${ script } ` ) } ;
27+ }
28+
2229export function ScalprumProvider < T extends Record < string , any > = Record < string , any > > ( {
2330 config,
2431 children,
2532 api,
2633 pluginSDKOptions,
2734} : 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+ }
2847 const state = useMemo (
2948 ( ) =>
3049 initialize < T > ( {
3150 appsConfig : config ,
3251 api,
52+ ...pluginSDKOptions ,
3353 pluginLoaderOptions : {
34- postProcessManifest ( manifest ) {
35- return { ...manifest , loadScripts : manifest . loadScripts . map ( ( script ) => `${ manifest . baseURL } ${ script } ` ) } ;
36- } ,
3754 ...pluginSDKOptions ?. pluginLoaderOptions ,
55+ transformPluginManifest : internalTransformPluginManifest ,
3856 } ,
39- ...pluginSDKOptions ,
4057 } ) ,
4158 [ ] ,
4259 ) ;
0 commit comments