Skip to content

Commit

Permalink
fix: webpackRequire.S has been attached with instance.shareScopeMap (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 authored Jan 15, 2024
1 parent b129098 commit 2ad29a6
Showing 5 changed files with 35 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .changeset/shy-spoons-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@module-federation/webpack-bundler-runtime': patch
'@module-federation/enhanced': patch
'@module-federation/runtime': patch
---

fix: remove duplicate init shareScopeMap
fix: normalize schemas path
fix: shared is loaded if it has lib attr
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@

import type { Compiler, WebpackPluginInstance } from 'webpack';
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
import isValidExternalsType from 'webpack/schemas/plugins/container/ExternalsType.check.js';
import type { ModuleFederationPluginOptions } from './ModuleFederationPluginTypes';
import SharePlugin from '../sharing/SharePlugin';
import ContainerPlugin from './ContainerPlugin';
@@ -16,6 +15,12 @@ import checkOptions from '../../schemas/container/ModuleFederationPlugin.check';
import schema from '../../schemas/container/ModuleFederationPlugin';
import FederationRuntimePlugin from './runtime/FederationRuntimePlugin';

const isValidExternalsType = require(
normalizeWebpackPath(
'webpack/schemas/plugins/container/ExternalsType.check.js',
),
) as typeof import('webpack/schemas/plugins/container/ExternalsType.check.js');

const createSchemaValidation = require(
normalizeWebpackPath('webpack/lib/util/create-schema-validation'),
) as typeof import('webpack/lib/util/create-schema-validation');
13 changes: 11 additions & 2 deletions packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts
Original file line number Diff line number Diff line change
@@ -48,8 +48,17 @@ const createSchemaValidation = require(

const validate = createSchemaValidation(
//eslint-disable-next-line
require('webpack/schemas/plugins/sharing/ConsumeSharedPlugin.check.js'),
() => require('webpack/schemas/plugins/sharing/ConsumeSharedPlugin.json'),
require(
normalizeWebpackPath(
'webpack/schemas/plugins/sharing/ConsumeSharedPlugin.check.js',
),
),
() =>
require(
normalizeWebpackPath(
'webpack/schemas/plugins/sharing/ConsumeSharedPlugin.json',
),
),
{
name: 'Consume Shared Plugin',
baseDataPath: 'options',
13 changes: 9 additions & 4 deletions packages/runtime/src/utils/share.ts
Original file line number Diff line number Diff line change
@@ -105,14 +105,18 @@ const findVersion = (
}, 0) as string;
};

const isLoaded = (shared: Shared) => {
return Boolean(shared.loaded) || typeof shared.lib === 'function';
};

function findSingletonVersionOrderByVersion(
shareScopeMap: ShareScopeMap,
scope: string,
pkgName: string,
): string {
const versions = shareScopeMap[scope][pkgName];
const callback = function (prev: string, cur: string): boolean {
return !versions[prev].loaded && versionLt(prev, cur);
return !isLoaded(versions[prev]) && versionLt(prev, cur);
};

return findVersion(shareScopeMap, scope, pkgName, callback);
@@ -124,15 +128,16 @@ function findSingletonVersionOrderByLoaded(
pkgName: string,
): string {
const versions = shareScopeMap[scope][pkgName];

const callback = function (prev: string, cur: string): boolean {
if (versions[cur].loaded) {
if (versions[prev].loaded) {
if (isLoaded(versions[cur])) {
if (isLoaded(versions[prev])) {
return Boolean(versionLt(prev, cur));
} else {
return true;
}
}
if (versions[prev].loaded) {
if (isLoaded(versions[prev])) {
return false;
}
return versionLt(prev, cur);
1 change: 0 additions & 1 deletion packages/webpack-bundler-runtime/src/initContainerEntry.ts
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ export function initContainerEntry(

federationInstance.initShareScopeMap(name, shareScope);

webpackRequire.S[name] = shareScope;
if (webpackRequire.federation.attachShareScopeMap) {
webpackRequire.federation.attachShareScopeMap(webpackRequire);
}

0 comments on commit 2ad29a6

Please sign in to comment.