Skip to content

Commit

Permalink
fix: add protocol in node automaticly (#2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 authored Jun 4, 2024
1 parent 28a2f58 commit 80af3f3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-seals-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

fix: add protocol in node automaticly
6 changes: 6 additions & 0 deletions .changeset/seven-pans-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/manifest': patch
'@module-federation/sdk': patch
---

fix: get remoteEntry type from options
5 changes: 4 additions & 1 deletion packages/manifest/src/StatsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Stats,
StatsAssets,
moduleFederationPlugin,
RemoteEntryType,
} from '@module-federation/sdk';
import { Compilation, Compiler, StatsCompilation, StatsModule } from 'webpack';
import {
Expand Down Expand Up @@ -116,7 +117,9 @@ class StatsManager {
name: getRemoteEntryName(),
path: '',
// same as the types supported by runtime, currently only global/var/script is supported
type: 'global',
type:
(this._options?.library?.type as RemoteEntryType | undefined) ||
'global',
},
types: getTypesMetaInfo(this._options, compiler.context),
globalName: globalName,
Expand Down
14 changes: 11 additions & 3 deletions packages/runtime/src/plugins/snapshot/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ModuleInfo, getResourceUrl } from '@module-federation/sdk';

import { FederationRuntimePlugin } from '../../type/plugin';
import { error, isPureRemoteEntry, isRemoteInfoWithEntry } from '../../utils';
import {
error,
isBrowserEnv,
isPureRemoteEntry,
isRemoteInfoWithEntry,
} from '../../utils';
import { PreloadOptions, RemoteInfo } from '../../type';
import { preloadAssets } from '../../utils/preload';

Expand All @@ -14,7 +18,11 @@ export function assignRemoteInfo(
}
const { remoteEntry } = remoteSnapshot;

const entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
let entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);

if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
entryUrl = `https:${entryUrl}`;
}

remoteInfo.type = remoteSnapshot.remoteEntryType;
remoteInfo.entryGlobalName = remoteSnapshot.globalName;
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/src/utils/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function loadEntryScript({
return entryExports;
})
.catch((e) => {
return e;
throw e;
});
}

Expand All @@ -101,7 +101,7 @@ export async function loadEntryScript({
return entryExports;
})
.catch((e) => {
return e;
throw e;
});
}

Expand All @@ -126,7 +126,7 @@ export async function getRemoteEntry({
}

if (!globalLoading[uniqueKey]) {
if (type === 'esm') {
if (['esm', 'module'].includes(type)) {
globalLoading[uniqueKey] = loadEsmEntry({
entry,
remoteEntryExports,
Expand Down
22 changes: 20 additions & 2 deletions packages/sdk/src/types/stats.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { MFModuleType } from '../constant';
import type { RemoteWithEntry, RemoteWithVersion } from './common';

export type RemoteEntryType = 'esm' | 'global';
export type RemoteEntryType =
| 'var'
| 'module'
| 'assign'
| 'assign-properties'
| 'this'
| 'window'
| 'self'
| 'global'
| 'commonjs'
| 'commonjs2'
| 'commonjs-module'
| 'commonjs-static'
| 'amd'
| 'amd-require'
| 'umd'
| 'umd2'
| 'jsonp'
| 'system'
| string;

interface ResourceInfo {
path: string;
Expand Down

0 comments on commit 80af3f3

Please sign in to comment.