Skip to content

Commit 39ff8d7

Browse files
authored
Merge pull request #103 from Hyperkid123/update-sdk-4
Upgrade dynamic plugin SDK to v4
2 parents 3109d81 + 72c66bf commit 39ff8d7

File tree

7 files changed

+47
-39
lines changed

7 files changed

+47
-39
lines changed

package-lock.json

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

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scalprum/core",
3-
"version": "0.5.2",
3+
"version": "0.5.4",
44
"description": "Includes core functions for scalprum scaffolding.",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
@@ -20,6 +20,6 @@
2020
"start:cjs": "npm run build:cjs -- -w"
2121
},
2222
"dependencies": {
23-
"@openshift/dynamic-plugin-sdk": "^3.0.0"
23+
"@openshift/dynamic-plugin-sdk": "^4.0.0"
2424
}
2525
}

packages/core/src/index.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ describe('scalprum', () => {
9393
disableReason: undefined,
9494
enabled: true,
9595
manifest: { baseURL: '/foo/bar', extensions: [], loadScripts: [], registrationMethod: 'custom', name: 'testScope', version: '1.0.0' },
96-
pluginName: 'testScope',
9796
status: 'loaded',
9897
},
9998
];
@@ -103,7 +102,7 @@ describe('scalprum', () => {
103102
init: jest.fn(),
104103
get: jest.fn().mockReturnValue(jest.fn().mockReturnValue(jest.fn())),
105104
};
106-
await getScalprum().pluginStore.loadPlugin('http://foobar', testManifest);
105+
await getScalprum().pluginStore.loadPlugin(testManifest);
107106
expect(getScalprum().pluginStore.getPluginInfo()).toEqual(expectedPlugins);
108107
});
109108

@@ -115,7 +114,7 @@ describe('scalprum', () => {
115114
init: jest.fn(),
116115
get: jest.fn().mockReturnValue(jest.fn().mockReturnValue(jest.fn())),
117116
};
118-
await getScalprum().pluginStore.loadPlugin('http://foobar', testManifest);
117+
await getScalprum().pluginStore.loadPlugin(testManifest);
119118
// @ts-ignore
120119
expect(getCachedModule('testScope', './testModule')).toHaveProperty('cachedModule');
121120
/**
@@ -133,7 +132,7 @@ describe('scalprum', () => {
133132
init: jest.fn(),
134133
get: jest.fn().mockReturnValue(jest.fn()),
135134
};
136-
await getScalprum().pluginStore.loadPlugin('http://foobar', testManifest);
135+
await getScalprum().pluginStore.loadPlugin(testManifest);
137136
// @ts-ignore
138137
expect(getCachedModule('testScope', './testModule', true)).toEqual({});
139138
});

packages/core/src/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginLoader, PluginStore, FeatureFlags, PluginLoaderOptions, PluginStoreOptions, PluginManifest } from '@openshift/dynamic-plugin-sdk';
1+
import { PluginStore, FeatureFlags, PluginLoaderOptions, PluginStoreOptions, PluginManifest } from '@openshift/dynamic-plugin-sdk';
22
import { warnDuplicatePkg } from './warnDuplicatePkg';
33
export const GLOBAL_NAMESPACE = '__scalprum__';
44
export type AppMetadata<T extends {} = {}> = T & {
@@ -200,17 +200,15 @@ export const initialize = <T extends Record<string, any> = Record<string, any>>(
200200
...options,
201201
};
202202

203-
// Create new plugin loader instance
204-
const pluginLoader = new PluginLoader({
205-
sharedScope: getSharedScope(defaultOptions.enableScopeWarning),
206-
getPluginEntryModule: ({ name }) => (window as { [key: string]: any })[name],
207-
...pluginLoaderOptions,
208-
});
209-
210203
// Create new plugin store
211-
const pluginStore = new PluginStore(pluginStoreOptions);
212-
pluginLoader.registerPluginEntryCallback();
213-
pluginStore.setLoader(pluginLoader);
204+
const pluginStore = new PluginStore({
205+
...pluginStoreOptions,
206+
loaderOptions: {
207+
sharedScope: getSharedScope(defaultOptions.enableScopeWarning),
208+
getPluginEntryModule: ({ name }) => (window as { [key: string]: any })[name],
209+
...pluginLoaderOptions,
210+
},
211+
});
214212
pluginStore.setFeatureFlags(pluginStoreFeatureFlags);
215213

216214
scalprum = {
@@ -318,7 +316,8 @@ export async function processManifest(url: string, scope: string, module: string
318316
baseURL,
319317
};
320318
}
321-
await pluginStore.loadPlugin(sdkManifest.baseURL, sdkManifest);
319+
320+
await pluginStore.loadPlugin(sdkManifest);
322321
try {
323322
const exposedModule = await pluginStore.getExposedModule<ExposedScalprumModule>(scope, module);
324323
setExposedModule(getModuleIdentifier(scope, module), exposedModule);

packages/react-core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scalprum/react-core",
3-
"version": "0.5.2",
3+
"version": "0.5.4",
44
"description": "React binding for @scalprum/core package.",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
@@ -26,8 +26,8 @@
2626
"@types/react-router-dom": "^5.3.1"
2727
},
2828
"dependencies": {
29-
"@openshift/dynamic-plugin-sdk": "^3.0.0",
30-
"@scalprum/core": "^0.5.2",
29+
"@openshift/dynamic-plugin-sdk": "^4.0.0",
30+
"@scalprum/core": "^0.5.4",
3131
"lodash": "^4.17.0"
3232
},
3333
"peerDependencies": {

packages/react-core/src/scalprum-component.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('<ScalprumComponent />', () => {
1919
name: 'testApp',
2020
registrationMethod: 'custom',
2121
version: '1.0.0',
22-
baseURL: '/',
22+
baseURL: 'http://foobar/',
2323
};
2424
const mockInitScalprumConfig: AppsConfig = {
2525
appOne: {
@@ -275,7 +275,7 @@ describe('<ScalprumComponent />', () => {
275275
};
276276
ScalprumCore.initialize({ appsConfig: mockInitScalprumConfig });
277277
ScalprumCore.getScalprum().exposedModules[`cachedScope#./test`] = cachedModule;
278-
await ScalprumCore.getScalprum().pluginStore.loadPlugin('http://foobar', testManifest);
278+
await ScalprumCore.getScalprum().pluginStore.loadPlugin(testManifest);
279279

280280
const props: ScalprumComponentProps = {
281281
scope: 'cachedScope',

packages/test-app/src/entry.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const config: AppsConfig<{ assetsHost?: string }> = {
3636
const Entry = () => {
3737
return (
3838
<ScalprumProvider
39+
pluginSDKOptions={{
40+
pluginLoaderOptions: {
41+
postProcessManifest(manifest) {
42+
return {
43+
...manifest,
44+
loadScripts: manifest.loadScripts.map((script) => `${manifest.baseURL}/${script}`),
45+
};
46+
},
47+
},
48+
}}
3949
api={{
4050
chrome: {
4151
foo: 'bar',

0 commit comments

Comments
 (0)