diff --git a/README.md b/README.md index b89db3b..5aea7f1 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,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: '*'} }, @@ -310,7 +310,7 @@ const sharedModules = { const dynamicPlugin = new DynamicRemotePlugin({ extensions: [], sharedModules, - entryScriptfilename:'remoteModule.(fullhash].js', + entryScriptfilename:'remoteModule.(contenthash].js', pluginMetadata: { name: "remoteModule", version: "1.0.0", @@ -411,7 +411,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}} diff --git a/examples/test-app/src/entry.tsx b/examples/test-app/src/entry.tsx index ba7e410..f4b9081 100644 --- a/examples/test-app/src/entry.tsx +++ b/examples/test-app/src/entry.tsx @@ -39,7 +39,7 @@ const Entry = () => { `${script}`), diff --git a/examples/test-app/webpack.config.ts b/examples/test-app/webpack.config.ts index 067f62b..5b9a343 100644 --- a/examples/test-app/webpack.config.ts +++ b/examples/test-app/webpack.config.ts @@ -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', }, diff --git a/package-lock.json b/package-lock.json index 4235108..df41ef2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "@scalprum/source", "version": "1.0.6", + "hasInstallScript": true, "license": "MIT", "workspaces": [ "packages/*" @@ -17,7 +18,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", @@ -5517,9 +5518,9 @@ } }, "node_modules/@openshift/dynamic-plugin-sdk": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@openshift/dynamic-plugin-sdk/-/dynamic-plugin-sdk-4.0.0.tgz", - "integrity": "sha512-OQsRqpRFz8IO6dZP6oKqdS7fLpdK25jxteevhussWFDd6RETNaLAG9GaSfvN0oigrzNIUTwH59kJx8PP8PrMug==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@openshift/dynamic-plugin-sdk/-/dynamic-plugin-sdk-5.0.1.tgz", + "integrity": "sha512-+azUBN6FgcDmlcWMzG0bthcRUJC1u12wf9xa2aJGFbC/uTiOXwjrkcQ7LW/PyK5Em7wDhwaUdapaeOgh8I6Kjg==", "dependencies": { "lodash": "^4.17.21", "semver": "^7.3.7", @@ -5531,11 +5532,12 @@ } }, "node_modules/@openshift/dynamic-plugin-sdk-webpack": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@openshift/dynamic-plugin-sdk-webpack/-/dynamic-plugin-sdk-webpack-3.0.1.tgz", - "integrity": "sha512-W7tDWLwZ17ebbawrIsI1MEM+8ldmpqPTKcONVmKcY/k+VgqVrGHlISHQE/Ykpd2Zu4J7FMx/CLIb86Ad1wwPxg==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@openshift/dynamic-plugin-sdk-webpack/-/dynamic-plugin-sdk-webpack-4.0.1.tgz", + "integrity": "sha512-ZlY57t1WIl8B8XNPoq+CuU/+Ll4/ZX/7IO/dxn+7dp1S/NUmdvgwv01mXpUcjviOUhhgWl/dK2WvCQTzz6CoZg==", "dependencies": { "lodash": "^4.17.21", + "semver": "^7.3.7", "yup": "^0.32.11" }, "engines": { @@ -5545,6 +5547,36 @@ "webpack": "^5.75.0" } }, + "node_modules/@openshift/dynamic-plugin-sdk-webpack/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@openshift/dynamic-plugin-sdk-webpack/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@openshift/dynamic-plugin-sdk-webpack/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@openshift/dynamic-plugin-sdk/node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -32384,20 +32416,20 @@ }, "packages/core": { "name": "@scalprum/core", - "version": "0.6.4", + "version": "0.6.5", "license": "Apache-2.0", "dependencies": { - "@openshift/dynamic-plugin-sdk": "^4.0.0", + "@openshift/dynamic-plugin-sdk": "^5.0.1", "tslib": "^2.6.2" } }, "packages/react-core": { "name": "@scalprum/react-core", - "version": "0.6.4", + "version": "0.6.5", "license": "Apache-2.0", "dependencies": { - "@openshift/dynamic-plugin-sdk": "^4.0.0", - "@scalprum/core": "^0.6.4", + "@openshift/dynamic-plugin-sdk": "^5.0.1", + "@scalprum/core": "^0.6.5", "lodash": "^4.17.0" }, "devDependencies": { @@ -32411,12 +32443,12 @@ }, "packages/react-test-utils": { "name": "@scalprum/react-test-utils", - "version": "0.0.6", + "version": "0.0.7", "license": "Apache-2.0", "dependencies": { - "@openshift/dynamic-plugin-sdk": "^4.0.0", - "@scalprum/core": "^0.6.4", - "@scalprum/react-core": "^0.6.4", + "@openshift/dynamic-plugin-sdk": "^5.0.1", + "@scalprum/core": "^0.6.5", + "@scalprum/react-core": "^0.6.5", "tslib": "^2.6.2", "whatwg-fetch": "^3.6.0" }, diff --git a/package.json b/package.json index 59b1923..feec767 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/packages/core/package.json b/packages/core/package.json index f1ea116..3500786 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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" } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a08ee54..869a0c4 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -50,6 +50,7 @@ export type Scalprum = Record> = { scalprumOptions: ScalprumOptions; api: T; pluginStore: PluginStore; + pluginLoaderOptions: PluginLoaderOptions; }; export type Container = Window & Factory; @@ -243,6 +244,7 @@ export const initialize = = Record>( exposedModules: {}, scalprumOptions: defaultOptions, api: api || {}, + pluginLoaderOptions, pluginStore, }; @@ -289,7 +291,7 @@ function extractBaseURL(path: string) { export async function processManifest(url: string, scope: string, module: string, processor?: (manifest: any) => string[]): Promise { let pendingInjection = getPendingInjection(scope); - const { pluginStore } = getScalprum(); + const { pluginStore, pluginLoaderOptions } = getScalprum(); if (pendingInjection) { await pendingInjection; const exposedModule = await pluginStore.getExposedModule(scope, module); diff --git a/packages/react-core/package.json b/packages/react-core/package.json index 2e33983..f4ea6c1 100644 --- a/packages/react-core/package.json +++ b/packages/react-core/package.json @@ -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.5", "lodash": "^4.17.0" }, diff --git a/packages/react-core/src/scalprum-provider.tsx b/packages/react-core/src/scalprum-provider.tsx index 64bb50f..23f8c9e 100644 --- a/packages/react-core/src/scalprum-provider.tsx +++ b/packages/react-core/src/scalprum-provider.tsx @@ -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 @@ -14,29 +14,46 @@ export interface ScalprumProviderProps = Record `${manifest.baseURL}${script}`) }; +} + export function ScalprumProvider = Record>({ config, children, api, pluginSDKOptions, }: ScalprumProviderProps): 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({ appsConfig: config, api, + ...pluginSDKOptions, pluginLoaderOptions: { - postProcessManifest(manifest) { - return { ...manifest, loadScripts: manifest.loadScripts.map((script) => `${manifest.baseURL}${script}`) }; - }, ...pluginSDKOptions?.pluginLoaderOptions, + transformPluginManifest: internalTransformPluginManifest, }, - ...pluginSDKOptions, }), [], ); diff --git a/packages/react-test-utils/package.json b/packages/react-test-utils/package.json index bf6ce4f..418955a 100644 --- a/packages/react-test-utils/package.json +++ b/packages/react-test-utils/package.json @@ -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.5", "@scalprum/react-core": "^0.6.5", "tslib": "^2.6.2",