Skip to content

Commit

Permalink
Merge pull request #114 from scalprum/bump-sdk
Browse files Browse the repository at this point in the history
feat: support SDK v5
  • Loading branch information
Hyperkid123 authored Jan 22, 2024
2 parents 9a9311d + aa922b7 commit 5650294
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ if(domNode) {
// declare shared dependencies
const moduleFederationPlugin = new ModuleFederationPlugin({
name: 'host',
filename: 'host.[fullhash].js',
filename: 'host.[contenthash].js',
shared: [
{'@openshift/dynamic-plugin-sdk': { singleton: true, requiredVersion: '*'} },
{ '@scalprum/react-core': { singleton: true, requiredVersion: '*'} },
Expand Down Expand Up @@ -314,7 +314,7 @@ const sharedModules = {
const dynamicPlugin = new DynamicRemotePlugin({
extensions: [],
sharedModules,
entryScriptfilename:'remoteModule.(fullhash].js',
entryScriptfilename:'remoteModule.(contenthash].js',
pluginMetadata: {
name: "remoteModule",
version: "1.0.0",
Expand Down Expand Up @@ -415,7 +415,7 @@ const { ModuleFederationPlugin } = require('webpack').container;
// declare shared dependencies
const moduleFederationPlugin = new ModuleFederationPlugin({
name: 'host',
filename: 'host.[fullhash].js',
filename: 'host.[contenthash].js',
shared: [{
// These packages has to be shared and has to be marked as singleton!
{ '@openshift/dynamic-plugin-sdk', { singleton: true, eager: true}}
Expand Down
2 changes: 1 addition & 1 deletion examples/test-app/src/entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Entry = () => {
<ScalprumProvider
pluginSDKOptions={{
pluginLoaderOptions: {
postProcessManifest(manifest) {
transformPluginManifest(manifest) {
return {
...manifest,
loadScripts: manifest.loadScripts.map((script) => `${script}`),
Expand Down
2 changes: 1 addition & 1 deletion examples/test-app/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const TestModuleFederation = new ModuleFederationPlugin({
const TestSDKPLugin = new DynamicRemotePlugin({
extensions: [],
sharedModules,
entryScriptFilename: 'sdk-plugin.[fullhash].js',
entryScriptFilename: 'sdk-plugin.[contenthash].js',
moduleFederationSettings: {
libraryType: 'global',
},
Expand Down
64 changes: 48 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"test": "npm-run-all --parallel test:*",
"build": "nx run-many -t build",
"lint": "nx run-many -t lint",
"version": "nx run-many -t version --dryRun"
"version": "nx run-many -t version --dryRun",
"postinstall": "rm -rf .webpack-cache"
},
"private": true,
"dependencies": {
Expand All @@ -24,7 +25,7 @@
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.19",
"@nx/devkit": "17.1.3",
"@openshift/dynamic-plugin-sdk-webpack": "^3.0.0",
"@openshift/dynamic-plugin-sdk-webpack": "^4.0.1",
"@swc/helpers": "~0.5.2",
"eslint-plugin-prettier": "^5.0.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"scripts": {},
"dependencies": {
"@openshift/dynamic-plugin-sdk": "^4.0.0",
"@openshift/dynamic-plugin-sdk": "^5.0.1",
"tslib": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@types/react-dom": "^18.0.0"
},
"dependencies": {
"@openshift/dynamic-plugin-sdk": "^4.0.0",
"@openshift/dynamic-plugin-sdk": "^5.0.1",
"@scalprum/core": "^0.6.6",
"lodash": "^4.17.0"
},
Expand Down
29 changes: 23 additions & 6 deletions packages/react-core/src/scalprum-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import { initialize, AppsConfig } from '@scalprum/core';
import { ScalprumContext } from './scalprum-context';
import { FeatureFlags, PluginLoaderOptions, PluginStoreOptions, PluginStoreProvider } from '@openshift/dynamic-plugin-sdk';
import { FeatureFlags, PluginLoaderOptions, PluginManifest, PluginStoreOptions, PluginStoreProvider } from '@openshift/dynamic-plugin-sdk';

/**
* @deprecated
Expand All @@ -14,29 +14,46 @@ export interface ScalprumProviderProps<T extends Record<string, any> = Record<st
children?: React.ReactNode;
pluginSDKOptions?: {
pluginStoreFeatureFlags?: FeatureFlags;
pluginLoaderOptions?: PluginLoaderOptions;
pluginLoaderOptions?: PluginLoaderOptions & {
/** @deprecated */
postProcessManifest?: PluginLoaderOptions['transformPluginManifest'];
};
pluginStoreOptions?: PluginStoreOptions;
};
}

function baseTransformPluginManifest(manifest: PluginManifest): PluginManifest {
return { ...manifest, loadScripts: manifest.loadScripts.map((script) => `${manifest.baseURL}${script}`) };
}

export function ScalprumProvider<T extends Record<string, any> = Record<string, any>>({
config,
children,
api,
pluginSDKOptions,
}: ScalprumProviderProps<T>): React.ReactElement | React.ReactElement {
const { postProcessManifest, transformPluginManifest } = pluginSDKOptions?.pluginLoaderOptions || {};
// SDK v4 and v5 compatibility layer
const internalTransformPluginManifest: PluginLoaderOptions['transformPluginManifest'] =
(postProcessManifest || transformPluginManifest) ?? baseTransformPluginManifest;

if (postProcessManifest) {
console.error(
`[Scalprum] Deprecation warning!
Please use pluginSDKOptions.pluginLoaderOptions.transformPluginManifest instead of pluginSDKOptions.pluginLoaderOptions.postProcessManifest.
The postProcessManifest option will be removed in the next major release.`,
);
}
const state = useMemo(
() =>
initialize<T>({
appsConfig: config,
api,
...pluginSDKOptions,
pluginLoaderOptions: {
postProcessManifest(manifest) {
return { ...manifest, loadScripts: manifest.loadScripts.map((script) => `${manifest.baseURL}${script}`) };
},
...pluginSDKOptions?.pluginLoaderOptions,
transformPluginManifest: internalTransformPluginManifest,
},
...pluginSDKOptions,
}),
[],
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"scripts": {},
"dependencies": {
"@openshift/dynamic-plugin-sdk": "^4.0.0",
"@openshift/dynamic-plugin-sdk": "^5.0.1",
"@scalprum/core": "^0.6.6",
"@scalprum/react-core": "^0.6.7",
"tslib": "^2.6.2",
Expand Down

0 comments on commit 5650294

Please sign in to comment.