@module-federation/esbuild 0.0.96 → 0.0.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -114,28 +114,38 @@ const buildFederationHost = (config)=>{
|
|
|
114
114
|
const runtimePlugin = () => ({
|
|
115
115
|
name: 'import-maps-plugin',
|
|
116
116
|
async init(args) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
// Load all remotes and collect their moduleMaps
|
|
118
|
+
const remotesWithModuleMaps = await Promise.all(
|
|
119
|
+
args.options.remotes.map(async (remote) => {
|
|
120
|
+
console.log('remote', remote);
|
|
121
|
+
if (remote.type === 'esm') {
|
|
122
|
+
const remoteModule = await import(remote.entry);
|
|
123
|
+
return { remote, moduleMap: remoteModule.moduleMap };
|
|
124
|
+
}
|
|
125
|
+
return { remote, moduleMap: null };
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Build import map entries for all remote modules
|
|
130
|
+
const allImports = {};
|
|
131
|
+
for (const { remote, moduleMap } of remotesWithModuleMaps) {
|
|
132
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
133
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
134
|
+
const currentImportMap = importShim.getImportMap().imports;
|
|
135
|
+
// Use remote name + expose path (e.g., "mfe1/component")
|
|
136
|
+
const key = remote.name + expose.replace('.', '');
|
|
137
|
+
if (!currentImportMap[key] && !allImports[key]) {
|
|
138
|
+
const encodedModule = encodeInlineESM(
|
|
139
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
140
|
+
);
|
|
141
|
+
allImports[key] = encodedModule;
|
|
142
|
+
}
|
|
134
143
|
}
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
}
|
|
145
|
+
}
|
|
137
146
|
|
|
138
|
-
|
|
147
|
+
if (Object.keys(allImports).length > 0) {
|
|
148
|
+
await importShim.addImportMap({ imports: allImports });
|
|
139
149
|
}
|
|
140
150
|
|
|
141
151
|
return args;
|
|
@@ -151,6 +161,33 @@ const buildFederationHost = (config)=>{
|
|
|
151
161
|
|
|
152
162
|
await Promise.all(mfHoZJ92.initializeSharing('default', 'version-first'));
|
|
153
163
|
|
|
164
|
+
// Ensure import maps are registered before any code that uses remotes runs
|
|
165
|
+
const remotesList = ${remoteConfigs};
|
|
166
|
+
const allImports = {};
|
|
167
|
+
for (const remote of remotesList) {
|
|
168
|
+
if (remote.type === 'esm') {
|
|
169
|
+
try {
|
|
170
|
+
const remoteModule = await import(remote.entry);
|
|
171
|
+
const moduleMap = remoteModule.moduleMap;
|
|
172
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
173
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
174
|
+
const key = remote.name + expose.replace('.', '');
|
|
175
|
+
if (!allImports[key]) {
|
|
176
|
+
const encodedModule = encodeInlineESM(
|
|
177
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
178
|
+
);
|
|
179
|
+
allImports[key] = encodedModule;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch (e) {
|
|
184
|
+
console.error('Failed to load remote:', remote.name, e);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (Object.keys(allImports).length > 0) {
|
|
189
|
+
await importShim.addImportMap({ imports: allImports });
|
|
190
|
+
}
|
|
154
191
|
|
|
155
192
|
`;
|
|
156
193
|
};
|
|
@@ -56,28 +56,38 @@ const buildFederationHost = (config)=>{
|
|
|
56
56
|
const runtimePlugin = () => ({
|
|
57
57
|
name: 'import-maps-plugin',
|
|
58
58
|
async init(args) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
// Load all remotes and collect their moduleMaps
|
|
60
|
+
const remotesWithModuleMaps = await Promise.all(
|
|
61
|
+
args.options.remotes.map(async (remote) => {
|
|
62
|
+
console.log('remote', remote);
|
|
63
|
+
if (remote.type === 'esm') {
|
|
64
|
+
const remoteModule = await import(remote.entry);
|
|
65
|
+
return { remote, moduleMap: remoteModule.moduleMap };
|
|
66
|
+
}
|
|
67
|
+
return { remote, moduleMap: null };
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Build import map entries for all remote modules
|
|
72
|
+
const allImports = {};
|
|
73
|
+
for (const { remote, moduleMap } of remotesWithModuleMaps) {
|
|
74
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
75
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
76
|
+
const currentImportMap = importShim.getImportMap().imports;
|
|
77
|
+
// Use remote name + expose path (e.g., "mfe1/component")
|
|
78
|
+
const key = remote.name + expose.replace('.', '');
|
|
79
|
+
if (!currentImportMap[key] && !allImports[key]) {
|
|
80
|
+
const encodedModule = encodeInlineESM(
|
|
81
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
82
|
+
);
|
|
83
|
+
allImports[key] = encodedModule;
|
|
84
|
+
}
|
|
76
85
|
}
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
}
|
|
87
|
+
}
|
|
79
88
|
|
|
80
|
-
|
|
89
|
+
if (Object.keys(allImports).length > 0) {
|
|
90
|
+
await importShim.addImportMap({ imports: allImports });
|
|
81
91
|
}
|
|
82
92
|
|
|
83
93
|
return args;
|
|
@@ -93,6 +103,33 @@ const buildFederationHost = (config)=>{
|
|
|
93
103
|
|
|
94
104
|
await Promise.all(mfHoZJ92.initializeSharing('default', 'version-first'));
|
|
95
105
|
|
|
106
|
+
// Ensure import maps are registered before any code that uses remotes runs
|
|
107
|
+
const remotesList = ${remoteConfigs};
|
|
108
|
+
const allImports = {};
|
|
109
|
+
for (const remote of remotesList) {
|
|
110
|
+
if (remote.type === 'esm') {
|
|
111
|
+
try {
|
|
112
|
+
const remoteModule = await import(remote.entry);
|
|
113
|
+
const moduleMap = remoteModule.moduleMap;
|
|
114
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
115
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
116
|
+
const key = remote.name + expose.replace('.', '');
|
|
117
|
+
if (!allImports[key]) {
|
|
118
|
+
const encodedModule = encodeInlineESM(
|
|
119
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
120
|
+
);
|
|
121
|
+
allImports[key] = encodedModule;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.error('Failed to load remote:', remote.name, e);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (Object.keys(allImports).length > 0) {
|
|
131
|
+
await importShim.addImportMap({ imports: allImports });
|
|
132
|
+
}
|
|
96
133
|
|
|
97
134
|
`;
|
|
98
135
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/esbuild",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.98",
|
|
4
4
|
"author": "Zack Jackson (@ScriptedAlchemy)",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -58,9 +58,15 @@
|
|
|
58
58
|
"esbuild": "^0.25.0",
|
|
59
59
|
"json5": "^2.2.3",
|
|
60
60
|
"npmlog": "^7.0.1",
|
|
61
|
-
"@module-federation/sdk": "2.0
|
|
61
|
+
"@module-federation/sdk": "2.2.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@rslib/core": "^0.12.4"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "rslib build",
|
|
68
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
69
|
+
"build-debug": "FEDERATION_DEBUG=true rslib build",
|
|
70
|
+
"pre-release": "pnpm run build"
|
|
65
71
|
}
|
|
66
72
|
}
|