Skip to content

Commit 5650294

Browse files
authored
Merge pull request #114 from scalprum/bump-sdk
feat: support SDK v5
2 parents 9a9311d + aa922b7 commit 5650294

File tree

9 files changed

+82
-32
lines changed

9 files changed

+82
-32
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ if(domNode) {
265265
// declare shared dependencies
266266
const moduleFederationPlugin = new ModuleFederationPlugin({
267267
name: 'host',
268-
filename: 'host.[fullhash].js',
268+
filename: 'host.[contenthash].js',
269269
shared: [
270270
{'@openshift/dynamic-plugin-sdk': { singleton: true, requiredVersion: '*'} },
271271
{ '@scalprum/react-core': { singleton: true, requiredVersion: '*'} },
@@ -314,7 +314,7 @@ const sharedModules = {
314314
const dynamicPlugin = new DynamicRemotePlugin({
315315
extensions: [],
316316
sharedModules,
317-
entryScriptfilename:'remoteModule.(fullhash].js',
317+
entryScriptfilename:'remoteModule.(contenthash].js',
318318
pluginMetadata: {
319319
name: "remoteModule",
320320
version: "1.0.0",
@@ -415,7 +415,7 @@ const { ModuleFederationPlugin } = require('webpack').container;
415415
// declare shared dependencies
416416
const moduleFederationPlugin = new ModuleFederationPlugin({
417417
name: 'host',
418-
filename: 'host.[fullhash].js',
418+
filename: 'host.[contenthash].js',
419419
shared: [{
420420
// These packages has to be shared and has to be marked as singleton!
421421
{ '@openshift/dynamic-plugin-sdk', { singleton: true, eager: true}}

examples/test-app/src/entry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Entry = () => {
3939
<ScalprumProvider
4040
pluginSDKOptions={{
4141
pluginLoaderOptions: {
42-
postProcessManifest(manifest) {
42+
transformPluginManifest(manifest) {
4343
return {
4444
...manifest,
4545
loadScripts: manifest.loadScripts.map((script) => `${script}`),

examples/test-app/webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const TestModuleFederation = new ModuleFederationPlugin({
9090
const TestSDKPLugin = new DynamicRemotePlugin({
9191
extensions: [],
9292
sharedModules,
93-
entryScriptFilename: 'sdk-plugin.[fullhash].js',
93+
entryScriptFilename: 'sdk-plugin.[contenthash].js',
9494
moduleFederationSettings: {
9595
libraryType: 'global',
9696
},

package-lock.json

Lines changed: 48 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"test": "npm-run-all --parallel test:*",
1616
"build": "nx run-many -t build",
1717
"lint": "nx run-many -t lint",
18-
"version": "nx run-many -t version --dryRun"
18+
"version": "nx run-many -t version --dryRun",
19+
"postinstall": "rm -rf .webpack-cache"
1920
},
2021
"private": true,
2122
"dependencies": {
@@ -24,7 +25,7 @@
2425
"@mui/icons-material": "^5.14.19",
2526
"@mui/material": "^5.14.19",
2627
"@nx/devkit": "17.1.3",
27-
"@openshift/dynamic-plugin-sdk-webpack": "^3.0.0",
28+
"@openshift/dynamic-plugin-sdk-webpack": "^4.0.1",
2829
"@swc/helpers": "~0.5.2",
2930
"eslint-plugin-prettier": "^5.0.1",
3031
"react": "18.2.0",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "Apache-2.0",
1111
"scripts": {},
1212
"dependencies": {
13-
"@openshift/dynamic-plugin-sdk": "^4.0.0",
13+
"@openshift/dynamic-plugin-sdk": "^5.0.1",
1414
"tslib": "^2.6.2"
1515
}
1616
}

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@types/react-dom": "^18.0.0"
1515
},
1616
"dependencies": {
17-
"@openshift/dynamic-plugin-sdk": "^4.0.0",
17+
"@openshift/dynamic-plugin-sdk": "^5.0.1",
1818
"@scalprum/core": "^0.6.6",
1919
"lodash": "^4.17.0"
2020
},

packages/react-core/src/scalprum-provider.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useMemo } from 'react';
22
import { initialize, AppsConfig } from '@scalprum/core';
33
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';
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+
2229
export 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
);

packages/react-test-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "Apache-2.0",
1111
"scripts": {},
1212
"dependencies": {
13-
"@openshift/dynamic-plugin-sdk": "^4.0.0",
13+
"@openshift/dynamic-plugin-sdk": "^5.0.1",
1414
"@scalprum/core": "^0.6.6",
1515
"@scalprum/react-core": "^0.6.7",
1616
"tslib": "^2.6.2",

0 commit comments

Comments
 (0)