Skip to content

Commit 80af3f3

Browse files
authored
fix: add protocol in node automaticly (#2560)
1 parent 28a2f58 commit 80af3f3

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

.changeset/eleven-seals-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
fix: add protocol in node automaticly

.changeset/seven-pans-argue.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/manifest': patch
3+
'@module-federation/sdk': patch
4+
---
5+
6+
fix: get remoteEntry type from options

packages/manifest/src/StatsManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Stats,
1212
StatsAssets,
1313
moduleFederationPlugin,
14+
RemoteEntryType,
1415
} from '@module-federation/sdk';
1516
import { Compilation, Compiler, StatsCompilation, StatsModule } from 'webpack';
1617
import {
@@ -116,7 +117,9 @@ class StatsManager {
116117
name: getRemoteEntryName(),
117118
path: '',
118119
// same as the types supported by runtime, currently only global/var/script is supported
119-
type: 'global',
120+
type:
121+
(this._options?.library?.type as RemoteEntryType | undefined) ||
122+
'global',
120123
},
121124
types: getTypesMetaInfo(this._options, compiler.context),
122125
globalName: globalName,

packages/runtime/src/plugins/snapshot/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { ModuleInfo, getResourceUrl } from '@module-federation/sdk';
2-
32
import { FederationRuntimePlugin } from '../../type/plugin';
4-
import { error, isPureRemoteEntry, isRemoteInfoWithEntry } from '../../utils';
3+
import {
4+
error,
5+
isBrowserEnv,
6+
isPureRemoteEntry,
7+
isRemoteInfoWithEntry,
8+
} from '../../utils';
59
import { PreloadOptions, RemoteInfo } from '../../type';
610
import { preloadAssets } from '../../utils/preload';
711

@@ -14,7 +18,11 @@ export function assignRemoteInfo(
1418
}
1519
const { remoteEntry } = remoteSnapshot;
1620

17-
const entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
21+
let entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
22+
23+
if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
24+
entryUrl = `https:${entryUrl}`;
25+
}
1826

1927
remoteInfo.type = remoteSnapshot.remoteEntryType;
2028
remoteInfo.entryGlobalName = remoteSnapshot.globalName;

packages/runtime/src/utils/load.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export async function loadEntryScript({
7777
return entryExports;
7878
})
7979
.catch((e) => {
80-
return e;
80+
throw e;
8181
});
8282
}
8383

@@ -101,7 +101,7 @@ export async function loadEntryScript({
101101
return entryExports;
102102
})
103103
.catch((e) => {
104-
return e;
104+
throw e;
105105
});
106106
}
107107

@@ -126,7 +126,7 @@ export async function getRemoteEntry({
126126
}
127127

128128
if (!globalLoading[uniqueKey]) {
129-
if (type === 'esm') {
129+
if (['esm', 'module'].includes(type)) {
130130
globalLoading[uniqueKey] = loadEsmEntry({
131131
entry,
132132
remoteEntryExports,

packages/sdk/src/types/stats.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
import { MFModuleType } from '../constant';
21
import type { RemoteWithEntry, RemoteWithVersion } from './common';
32

4-
export type RemoteEntryType = 'esm' | 'global';
3+
export type RemoteEntryType =
4+
| 'var'
5+
| 'module'
6+
| 'assign'
7+
| 'assign-properties'
8+
| 'this'
9+
| 'window'
10+
| 'self'
11+
| 'global'
12+
| 'commonjs'
13+
| 'commonjs2'
14+
| 'commonjs-module'
15+
| 'commonjs-static'
16+
| 'amd'
17+
| 'amd-require'
18+
| 'umd'
19+
| 'umd2'
20+
| 'jsonp'
21+
| 'system'
22+
| string;
523

624
interface ResourceInfo {
725
path: string;

0 commit comments

Comments
 (0)