Skip to content

Commit

Permalink
fix: hotfix important bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangHongEn committed Oct 12, 2024
1 parent e5f0faa commit c624f2d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 49 deletions.
68 changes: 34 additions & 34 deletions src/utils/normalizeModuleFederationOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ function normalizeShareItem(
shareItem:
| string
| {
name: string;
version?: string;
shareScope?: string;
singleton?: boolean;
requiredVersion?: string;
strictVersion?: boolean;
}
name: string;
version?: string;
shareScope?: string;
singleton?: boolean;
requiredVersion?: string;
strictVersion?: boolean;
}
): ShareItem {
let version: string | undefined;
try {
Expand Down Expand Up @@ -165,17 +165,17 @@ function normalizeShared(
shared:
| string[]
| Record<
string,
| string
| {
name?: string;
version?: string;
shareScope?: string;
singleton?: boolean;
requiredVersion?: string;
strictVersion?: boolean;
}
>
string,
| string
| {
name?: string;
version?: string;
shareScope?: string;
singleton?: boolean;
requiredVersion?: string;
strictVersion?: boolean;
}
>
| undefined
): NormalizedShared {
if (!shared) return {};
Expand Down Expand Up @@ -229,20 +229,20 @@ export type ModuleFederationOptions = {
runtime?: any;
shareScope?: string;
shared?:
| string[]
| Record<
string,
| string
| {
name?: string;
version?: string;
shareScope?: string;
singleton?: boolean;
requiredVersion?: string;
strictVersion?: boolean;
}
>
| undefined;
| string[]
| Record<
string,
| string
| {
name?: string;
version?: string;
shareScope?: string;
singleton?: boolean;
requiredVersion?: string;
strictVersion?: boolean;
}
>
| undefined;
runtimePlugins?: string[];
getPublicPath?: string;
implementation?: any;
Expand All @@ -267,7 +267,7 @@ export interface NormalizedModuleFederationOptions {
manifest: ManifestOptions | boolean;
dev?: boolean | PluginDevOptions;
dts?: boolean | PluginDtsOptions;
shareStrategy?: ShareStrategy;
shareStrategy: ShareStrategy;
getPublicPath?: string;
}

Expand Down Expand Up @@ -343,6 +343,6 @@ export function normalizeModuleFederationOptions(
dev: options.dev,
dts: options.dts,
getPublicPath: options.getPublicPath,
shareStrategy: options.shareStrategy,
shareStrategy: options.shareStrategy || "version-first",
});
}
35 changes: 20 additions & 15 deletions src/virtualModules/virtualRemoteEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ export function generateLocalSharedImportMap() {
return `
const importMap = {
${Array.from(getUsedShares())
.map(
(pkg) => `
.map(
(pkg) => `
${JSON.stringify(pkg)}: async () => {
let pkg = await import("${getPreBuildLibImportId(pkg)}")
return pkg
}
`
)
.join(',')}
)
.join(',')}
}
const usedShared = {
${Array.from(getUsedShares())
.map((key) => {
const shareItem = getNormalizeShareItem(key);
return `
.map((key) => {
const shareItem = getNormalizeShareItem(key);
return `
${JSON.stringify(key)}: {
name: ${JSON.stringify(key)},
version: ${JSON.stringify(shareItem.version)},
Expand All @@ -81,22 +81,22 @@ export function generateLocalSharedImportMap() {
}
}
`;
})
.join(',')}
})
.join(',')}
}
const usedRemotes = [${Object.keys(getUsedRemotesMap())
.map((key) => {
const remote = options.remotes[key];
return `
.map((key) => {
const remote = options.remotes[key];
return `
{
entryGlobalName: ${JSON.stringify(remote.entryGlobalName)},
name: ${JSON.stringify(remote.name)},
type: ${JSON.stringify(remote.type)},
entry: ${JSON.stringify(remote.entry)},
}
`;
})
.join(',')}
})
.join(',')}
]
export {
usedShared,
Expand Down Expand Up @@ -126,9 +126,14 @@ export function generateRemoteEntry(options: NormalizedModuleFederationOptions):
remotes: usedRemotes,
shared: usedShared,
plugins: [${pluginImportNames.map((item) => `${item[0]}()`).join(', ')}],
${options.shareStrategy ? `shareStrategy: ${options.shareStrategy}` : ''}
${options.shareStrategy ? `shareStrategy: '${options.shareStrategy}'` : ''}
});
initRes.initShareScopeMap('${options.shareScope}', shared);
try {
await Promise.all(await initRes.initializeSharing('${options.shareScope}', {strategy: '${options.shareStrategy}'}));
} catch (e) {
console.error(e)
}
initResolve(initRes)
return initRes
}
Expand Down

0 comments on commit c624f2d

Please sign in to comment.