-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 2020428: Adapt webpack 5 related code in dynamic plugin SDK #10433
Merged
openshift-merge-robot
merged 2 commits into
openshift:master
from
vojtechszocs:plugin-sdk-wp5
Nov 12, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
frontend/packages/console-dynamic-plugin-sdk/src/__tests__/shared-modules-init.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { sharedPluginModules } from '../shared-modules'; | ||
import { initSharedPluginModules } from '../shared-modules-init'; | ||
import { getEntryModuleMocks } from '../utils/test-utils'; | ||
|
||
describe('initSharedPluginModules', () => { | ||
const expectSameValues = (arr1: string[], arr2: string[]) => { | ||
expect(new Set(arr1)).toEqual(new Set(arr2)); | ||
}; | ||
|
||
it('is consistent with sharedPluginModules definition', () => { | ||
const [, entryModule] = getEntryModuleMocks({}); | ||
|
||
initSharedPluginModules(entryModule); | ||
|
||
expect(entryModule.init).toHaveBeenCalledTimes(1); | ||
|
||
expectSameValues(Object.keys(entryModule.init.mock.calls[0][0]), sharedPluginModules); | ||
}); | ||
|
||
it('supports plugins built with an older version of plugin SDK', () => { | ||
const [, entryModule] = getEntryModuleMocks({}); | ||
entryModule.override = jest.fn(); | ||
|
||
initSharedPluginModules(entryModule); | ||
|
||
expect(entryModule.override).toHaveBeenCalledTimes(1); | ||
expect(entryModule.init).not.toHaveBeenCalled(); | ||
|
||
expectSameValues(Object.keys(entryModule.override.mock.calls[0][0]), sharedPluginModules); | ||
}); | ||
}); |
17 changes: 0 additions & 17 deletions
17
frontend/packages/console-dynamic-plugin-sdk/src/__tests__/shared-modules-override.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
frontend/packages/console-dynamic-plugin-sdk/src/shared-modules-init.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable global-require */ | ||
/* eslint-disable @typescript-eslint/no-require-imports */ | ||
|
||
import { SharedModuleResolution, RemoteEntryModule } from './types'; | ||
|
||
const modules: SharedModuleResolution = { | ||
'@openshift-console/dynamic-plugin-sdk': async () => () => | ||
require('@console/dynamic-plugin-sdk/src/lib-core'), | ||
'@openshift-console/dynamic-plugin-sdk-internal': async () => () => | ||
require('@console/dynamic-plugin-sdk/src/lib-internal'), | ||
'@openshift-console/dynamic-plugin-sdk-internal-kubevirt': async () => () => | ||
require('@console/dynamic-plugin-sdk/src/lib-internal-kubevirt'), | ||
'@patternfly/react-core': async () => () => require('@patternfly/react-core'), | ||
'@patternfly/react-table': async () => () => require('@patternfly/react-table'), | ||
react: async () => () => require('react'), | ||
'react-helmet': async () => () => require('react-helmet'), | ||
'react-i18next': async () => () => require('react-i18next'), | ||
'react-router': async () => () => require('react-router'), | ||
'react-router-dom': async () => () => require('react-router-dom'), | ||
}; | ||
|
||
const sharedScope = Object.keys(modules).reduce( | ||
(acc, moduleRequest) => ({ | ||
...acc, | ||
[moduleRequest]: { | ||
// The '*' semver range means "this shared module matches all requested versions", | ||
// i.e. make sure the plugin always uses the Console-provided shared module version | ||
'*': { | ||
get: modules[moduleRequest], | ||
// Indicates that Console has already loaded the shared module | ||
loaded: true, | ||
}, | ||
}, | ||
}), | ||
{}, | ||
); | ||
|
||
/** | ||
* At runtime, the Console application will initialize shared modules for each | ||
* dynamic plugin before loading any of the modules exposed by the given plugin. | ||
* | ||
* Currently, module sharing is strictly unidirectional (Console -> plugins). | ||
* | ||
* Note: `__webpack_init_sharing__` global function is available in webpack 5+ builds. | ||
* Once Console gets built with webpack 5, evaluate if we need this global in order to | ||
* allow plugins to attempt to provide shared modules into the application shared scope. | ||
* | ||
* @see https://webpack.js.org/concepts/module-federation/#dynamic-remote-containers | ||
*/ | ||
export const initSharedPluginModules = (entryModule: RemoteEntryModule) => { | ||
if (typeof entryModule.override === 'function') { | ||
// Support plugins built with webpack 5.0.0-beta.16 | ||
entryModule.override(modules); | ||
return; | ||
} | ||
|
||
entryModule.init(sharedScope); | ||
}; |
44 changes: 0 additions & 44 deletions
44
frontend/packages/console-dynamic-plugin-sdk/src/shared-modules-override.ts
This file was deleted.
Oops, something went wrong.
44 changes: 12 additions & 32 deletions
44
frontend/packages/console-dynamic-plugin-sdk/src/shared-modules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,15 @@ | ||
/** | ||
* Modules shared between the Console application and its dynamic plugins. | ||
*/ | ||
export const sharedPluginModules = { | ||
'@openshift-console/dynamic-plugin-sdk': { | ||
singleton: true, | ||
}, | ||
'@openshift-console/dynamic-plugin-sdk-internal': { | ||
singleton: true, | ||
}, | ||
'@openshift-console/dynamic-plugin-sdk-internal-kubevirt': { | ||
singleton: true, | ||
}, | ||
'@patternfly/react-core': { | ||
singleton: true, | ||
}, | ||
'@patternfly/react-table': { | ||
singleton: true, | ||
}, | ||
react: { | ||
singleton: true, | ||
}, | ||
'react-helmet': { | ||
singleton: true, | ||
}, | ||
'react-i18next': { | ||
singleton: true, | ||
}, | ||
'react-router': { | ||
singleton: true, | ||
}, | ||
'react-router-dom': { | ||
singleton: true, | ||
}, | ||
}; | ||
export const sharedPluginModules = [ | ||
'@openshift-console/dynamic-plugin-sdk', | ||
'@openshift-console/dynamic-plugin-sdk-internal', | ||
'@openshift-console/dynamic-plugin-sdk-internal-kubevirt', | ||
'@patternfly/react-core', | ||
'@patternfly/react-table', | ||
'react', | ||
'react-helmet', | ||
'react-i18next', | ||
'react-router', | ||
'react-router-dom', | ||
]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍