Skip to content
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

Forbid imports and eager loading of core singleton packages. #2043

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/config-utils/src/federated-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const defaultPluginMetaDataJSON = {
extensions: [],
};

const createIncludes = (eager = false): { [module: string]: WebpackSharedConfig } => ({
'@patternfly/quickstarts': { singleton: true, eager },
'@redhat-cloud-services/chrome': { singleton: true },
const createIncludes = (): { [module: string]: WebpackSharedConfig } => ({
'@patternfly/quickstarts': { singleton: true, eager: false, import: false },
'@redhat-cloud-services/chrome': { singleton: true, import: false },
axios: {},
lodash: {},
react: { singleton: true, eager },
'react-dom': { singleton: true, eager },
react: { singleton: true, eager: false, import: false },
'react-dom': { singleton: true, eager: false, import: false },
});

export type FederatedModulesConfig = {
Expand Down Expand Up @@ -53,11 +53,10 @@ const federatedModules = ({
useFileHash = true,
separateRuntime = false,
exclude = [],
eager = false,
pluginMetadata,
extensions = [],
}: FederatedModulesConfig) => {
const include = createIncludes(eager);
const include = createIncludes();

const { dependencies, insights } = require(resolve(root, './package.json')) || {};
const appName = moduleName || (insights && jsVarName(insights.appname));
Expand Down Expand Up @@ -92,14 +91,19 @@ const federatedModules = ({
* No application should be installing/interacting with scalprum directly.
*/
if (dependencies['@redhat-cloud-services/frontend-components']) {
sharedDeps['@scalprum/react-core'] = { requiredVersion: '*', singleton: true, eager };
sharedDeps['@scalprum/react-core'] = { requiredVersion: '*', singleton: true, eager: false, import: false };
}

/**
* Make sure the unleash proxy client is a singleton
*/
if (dependencies['@unleash/proxy-client-react']) {
sharedDeps['@unleash/proxy-client-react'] = { singleton: true, requiredVersion: dependencies['@unleash/proxy-client-react'] };
sharedDeps['@unleash/proxy-client-react'] = {
singleton: true,
eager: false,
import: false,
requiredVersion: dependencies['@unleash/proxy-client-react'],
};
}

if (debug) {
Expand Down
Loading