@module-federation/esbuild 0.0.0-chore-bump-node-22-20260710161714
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.
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/adapters/lib/collect-exports.d.ts +3 -0
- package/dist/adapters/lib/collect-exports.js +153 -0
- package/dist/adapters/lib/collect-exports.mjs +80 -0
- package/dist/adapters/lib/commonjs.d.ts +101 -0
- package/dist/adapters/lib/commonjs.js +258 -0
- package/dist/adapters/lib/commonjs.mjs +182 -0
- package/dist/adapters/lib/containerPlugin.d.ts +6 -0
- package/dist/adapters/lib/containerPlugin.js +233 -0
- package/dist/adapters/lib/containerPlugin.mjs +179 -0
- package/dist/adapters/lib/containerReference.d.ts +6 -0
- package/dist/adapters/lib/containerReference.js +257 -0
- package/dist/adapters/lib/containerReference.mjs +188 -0
- package/dist/adapters/lib/lexer.d.ts +9 -0
- package/dist/adapters/lib/lexer.js +187 -0
- package/dist/adapters/lib/lexer.mjs +136 -0
- package/dist/adapters/lib/linkRemotesPlugin.d.ts +6 -0
- package/dist/adapters/lib/linkRemotesPlugin.js +117 -0
- package/dist/adapters/lib/linkRemotesPlugin.mjs +48 -0
- package/dist/adapters/lib/manifest.d.ts +2 -0
- package/dist/adapters/lib/manifest.js +227 -0
- package/dist/adapters/lib/manifest.mjs +159 -0
- package/dist/adapters/lib/plugin.d.ts +8 -0
- package/dist/adapters/lib/plugin.js +340 -0
- package/dist/adapters/lib/plugin.mjs +247 -0
- package/dist/adapters/lib/react-replacements.d.ts +9 -0
- package/dist/adapters/lib/react-replacements.js +86 -0
- package/dist/adapters/lib/react-replacements.mjs +34 -0
- package/dist/adapters/lib/transform.d.ts +8 -0
- package/dist/adapters/lib/transform.js +171 -0
- package/dist/adapters/lib/transform.mjs +116 -0
- package/dist/adapters/lib/utils.d.ts +3 -0
- package/dist/adapters/lib/utils.js +87 -0
- package/dist/adapters/lib/utils.mjs +31 -0
- package/dist/build.d.ts +5 -0
- package/dist/build.js +140 -0
- package/dist/build.mjs +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +55 -0
- package/dist/index.mjs +3 -0
- package/dist/lib/config/configuration-context.d.ts +7 -0
- package/dist/lib/config/configuration-context.js +73 -0
- package/dist/lib/config/configuration-context.mjs +18 -0
- package/dist/lib/config/federation-config.d.ts +30 -0
- package/dist/lib/config/federation-config.js +29 -0
- package/dist/lib/config/federation-config.mjs +3 -0
- package/dist/lib/config/share-utils.d.ts +29 -0
- package/dist/lib/config/share-utils.js +340 -0
- package/dist/lib/config/share-utils.mjs +245 -0
- package/dist/lib/config/with-native-federation.d.ts +23 -0
- package/dist/lib/config/with-native-federation.js +120 -0
- package/dist/lib/config/with-native-federation.mjs +66 -0
- package/dist/lib/core/build-adapter.d.ts +4 -0
- package/dist/lib/core/build-adapter.js +72 -0
- package/dist/lib/core/build-adapter.mjs +16 -0
- package/dist/lib/core/createContainerTemplate.d.ts +1 -0
- package/dist/lib/core/createContainerTemplate.js +235 -0
- package/dist/lib/core/createContainerTemplate.mjs +183 -0
- package/dist/lib/core/default-skip-list.d.ts +12 -0
- package/dist/lib/core/default-skip-list.js +103 -0
- package/dist/lib/core/default-skip-list.mjs +45 -0
- package/dist/lib/core/federation-options.d.ts +10 -0
- package/dist/lib/core/federation-options.js +29 -0
- package/dist/lib/core/federation-options.mjs +3 -0
- package/dist/lib/core/get-externals.d.ts +2 -0
- package/dist/lib/core/get-externals.js +68 -0
- package/dist/lib/core/get-externals.mjs +17 -0
- package/dist/lib/core/load-federation-config.d.ts +6 -0
- package/dist/lib/core/load-federation-config.js +71 -0
- package/dist/lib/core/load-federation-config.mjs +16 -0
- package/dist/lib/core/write-federation-info.d.ts +9 -0
- package/dist/lib/core/write-federation-info.js +67 -0
- package/dist/lib/core/write-federation-info.mjs +12 -0
- package/dist/lib/utils/logger.d.ts +11 -0
- package/dist/lib/utils/logger.js +113 -0
- package/dist/lib/utils/logger.mjs +44 -0
- package/dist/lib/utils/mapped-paths.d.ts +10 -0
- package/dist/lib/utils/mapped-paths.js +95 -0
- package/dist/lib/utils/mapped-paths.mjs +40 -0
- package/dist/lib/utils/normalize.d.ts +1 -0
- package/dist/lib/utils/normalize.js +66 -0
- package/dist/lib/utils/normalize.mjs +15 -0
- package/dist/lib/utils/package-info.d.ts +18 -0
- package/dist/lib/utils/package-info.js +325 -0
- package/dist/lib/utils/package-info.mjs +259 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.js +96 -0
- package/dist/plugin.mjs +4 -0
- package/dist/resolve/esm-resolver.mjs +19 -0
- package/dist/resolve/package.json +3 -0
- package/dist/rslib-runtime.mjs +31 -0
- package/package.json +75 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { createContainerCode } from "../../lib/core/createContainerTemplate.mjs";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const buildContainerHost = (config)=>{
|
|
6
|
+
const { name, remotes = {}, shared = {}, exposes = {} } = config;
|
|
7
|
+
const remoteConfigs = Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
8
|
+
type: 'esm',
|
|
9
|
+
name: remoteAlias,
|
|
10
|
+
entry: remote.entry,
|
|
11
|
+
alias: remoteAlias
|
|
12
|
+
}));
|
|
13
|
+
const sharedConfig = Object.entries(shared).reduce((acc, [pkg, config])=>{
|
|
14
|
+
const version = config.requiredVersion?.replace(/^[^0-9]/, '') || '';
|
|
15
|
+
acc += `${JSON.stringify(pkg)}: {
|
|
16
|
+
"package": "${pkg}",
|
|
17
|
+
"version": "${version}",
|
|
18
|
+
"scope": "default",
|
|
19
|
+
"get": async () => import('federationShare/${pkg}'),
|
|
20
|
+
"shareConfig": {
|
|
21
|
+
"singleton": ${config.singleton},
|
|
22
|
+
"requiredVersion": "${config.requiredVersion}",
|
|
23
|
+
"eager": ${config.eager},
|
|
24
|
+
"strictVersion": ${config.strictVersion}
|
|
25
|
+
}
|
|
26
|
+
},\n`;
|
|
27
|
+
return acc;
|
|
28
|
+
}, '{') + '}';
|
|
29
|
+
let exposesConfig = Object.entries(exposes).map(([exposeName, exposePath])=>`${JSON.stringify(exposeName)}: async () => await import('${exposePath}')`).join(',\n');
|
|
30
|
+
exposesConfig = `{${exposesConfig}}`;
|
|
31
|
+
const injectedContent = `
|
|
32
|
+
export const moduleMap = '__MODULE_MAP__';
|
|
33
|
+
|
|
34
|
+
function appendImportMap(importMap) {
|
|
35
|
+
const script = document.createElement('script');
|
|
36
|
+
script.type = 'importmap-shim';
|
|
37
|
+
script.innerHTML = JSON.stringify(importMap);
|
|
38
|
+
document.head.appendChild(script);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const createVirtualRemoteModule = (name, ref, exports) => {
|
|
42
|
+
const genExports = exports.map(e =>
|
|
43
|
+
e === 'default' ? 'export default mfLsZJ92.default' : \`export const \${e} = mfLsZJ92[\${JSON.stringify(e)}];\`
|
|
44
|
+
).join('');
|
|
45
|
+
|
|
46
|
+
const loadRef = \`const mfLsZJ92 = await container.loadRemote(\${JSON.stringify(ref)});\`;
|
|
47
|
+
|
|
48
|
+
return \`
|
|
49
|
+
const container = __FEDERATION__.__INSTANCES__.find(container => container.name === name) || __FEDERATION__.__INSTANCES__[0];
|
|
50
|
+
\${loadRef}
|
|
51
|
+
\${genExports}
|
|
52
|
+
\`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function encodeInlineESM(code) {
|
|
56
|
+
const encodedCode = encodeURIComponent(code);
|
|
57
|
+
return \`data:text/javascript;charset=utf-8,\${encodedCode}\`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const runtimePlugin = () => ({
|
|
61
|
+
name: 'import-maps-plugin',
|
|
62
|
+
async init(args) {
|
|
63
|
+
|
|
64
|
+
const remotePrefetch = args.options.remotes.map(async (remote) => {
|
|
65
|
+
if (remote.type === 'esm') {
|
|
66
|
+
await import(remote.entry);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
await Promise.all(remotePrefetch);
|
|
72
|
+
|
|
73
|
+
const map = Object.keys(moduleMap).reduce((acc, expose) => {
|
|
74
|
+
const importMap = importShim.getImportMap().imports;
|
|
75
|
+
const key = args.origin.name + expose.replace('.', '');
|
|
76
|
+
if (!importMap[key]) {
|
|
77
|
+
const encodedModule = encodeInlineESM(
|
|
78
|
+
createVirtualRemoteModule(args.origin.name, key, moduleMap[expose].exports)
|
|
79
|
+
);
|
|
80
|
+
acc[key] = encodedModule;
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
await importShim.addImportMap({ imports: map });
|
|
85
|
+
|
|
86
|
+
return args;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const createdContainer = await createContainer({
|
|
91
|
+
name: ${JSON.stringify(name)},
|
|
92
|
+
exposes: ${exposesConfig},
|
|
93
|
+
remotes: ${JSON.stringify(remoteConfigs)},
|
|
94
|
+
shared: ${sharedConfig},
|
|
95
|
+
plugins: [runtimePlugin()],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const get = createdContainer.get;
|
|
99
|
+
export const init = createdContainer.init;
|
|
100
|
+
`;
|
|
101
|
+
//replace with createContainer from bundler runtime - import it in the string as a dep etc
|
|
102
|
+
return [
|
|
103
|
+
createContainerCode,
|
|
104
|
+
injectedContent
|
|
105
|
+
].join('\n');
|
|
106
|
+
};
|
|
107
|
+
const createContainerPlugin = (config)=>({
|
|
108
|
+
name: 'createContainer',
|
|
109
|
+
setup (build) {
|
|
110
|
+
const { filename } = config;
|
|
111
|
+
const filter = new RegExp([
|
|
112
|
+
filename
|
|
113
|
+
].map((name)=>`${name}$`).join('|'));
|
|
114
|
+
const hasShared = Object.keys(config.shared || {}).length;
|
|
115
|
+
const shared = Object.keys(config.shared || {}).map((name)=>`${name}$`).join('|');
|
|
116
|
+
const sharedExternals = new RegExp(shared);
|
|
117
|
+
build.onResolve({
|
|
118
|
+
filter
|
|
119
|
+
}, async (args)=>({
|
|
120
|
+
path: args.path,
|
|
121
|
+
namespace: 'container',
|
|
122
|
+
pluginData: {
|
|
123
|
+
kind: args.kind,
|
|
124
|
+
resolveDir: args.resolveDir
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
build.onResolve({
|
|
128
|
+
filter: /^federationShare/
|
|
129
|
+
}, async (args)=>({
|
|
130
|
+
path: args.path.replace('federationShare/', ''),
|
|
131
|
+
namespace: 'esm-shares',
|
|
132
|
+
pluginData: {
|
|
133
|
+
kind: args.kind,
|
|
134
|
+
resolveDir: args.resolveDir
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
if (hasShared) {
|
|
138
|
+
build.onResolve({
|
|
139
|
+
filter: sharedExternals
|
|
140
|
+
}, (args)=>{
|
|
141
|
+
if (args.namespace === 'esm-shares') return null;
|
|
142
|
+
return {
|
|
143
|
+
path: args.path,
|
|
144
|
+
namespace: 'virtual-share-module',
|
|
145
|
+
pluginData: {
|
|
146
|
+
kind: args.kind,
|
|
147
|
+
resolveDir: args.resolveDir
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
build.onResolve({
|
|
152
|
+
filter: /.*/,
|
|
153
|
+
namespace: 'esm-shares'
|
|
154
|
+
}, async (args)=>{
|
|
155
|
+
if (sharedExternals.test(args.path)) {
|
|
156
|
+
return {
|
|
157
|
+
path: args.path,
|
|
158
|
+
namespace: 'virtual-share-module',
|
|
159
|
+
pluginData: {
|
|
160
|
+
kind: args.kind,
|
|
161
|
+
resolveDir: args.resolveDir
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
build.onLoad({
|
|
169
|
+
filter,
|
|
170
|
+
namespace: 'container'
|
|
171
|
+
}, async (args)=>({
|
|
172
|
+
contents: buildContainerHost(config),
|
|
173
|
+
loader: 'js',
|
|
174
|
+
resolveDir: args.pluginData.resolveDir
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export { createContainerPlugin };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config';
|
|
2
|
+
export declare const buildFederationHost: (config: NormalizedFederationConfig) => string;
|
|
3
|
+
export declare const initializeHostPlugin: (config: NormalizedFederationConfig) => {
|
|
4
|
+
name: string;
|
|
5
|
+
setup(build: any): void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
// webpack/runtime/compat_get_default_export
|
|
13
|
+
(() => {
|
|
14
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
15
|
+
__webpack_require__.n = (module) => {
|
|
16
|
+
var getter = module && module.__esModule ?
|
|
17
|
+
() => (module['default']) :
|
|
18
|
+
() => (module);
|
|
19
|
+
__webpack_require__.d(getter, { a: getter });
|
|
20
|
+
return getter;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
})();
|
|
24
|
+
// webpack/runtime/define_property_getters
|
|
25
|
+
(() => {
|
|
26
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
27
|
+
var define = (defs, kind) => {
|
|
28
|
+
for(var key in defs) {
|
|
29
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
30
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
define(getters, "get");
|
|
35
|
+
define(values, "value");
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
// webpack/runtime/has_own_property
|
|
39
|
+
(() => {
|
|
40
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
41
|
+
})();
|
|
42
|
+
// webpack/runtime/make_namespace_object
|
|
43
|
+
(() => {
|
|
44
|
+
// define __esModule on exports
|
|
45
|
+
__webpack_require__.r = (exports) => {
|
|
46
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
47
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
48
|
+
}
|
|
49
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
50
|
+
};
|
|
51
|
+
})();
|
|
52
|
+
var __webpack_exports__ = {};
|
|
53
|
+
// ESM COMPAT FLAG
|
|
54
|
+
__webpack_require__.r(__webpack_exports__);
|
|
55
|
+
|
|
56
|
+
// EXPORTS
|
|
57
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
58
|
+
buildFederationHost: () => (/* binding */ buildFederationHost),
|
|
59
|
+
initializeHostPlugin: () => (/* binding */ initializeHostPlugin)
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
;// CONCATENATED MODULE: external "fs"
|
|
63
|
+
const external_fs_namespaceObject = require("fs");
|
|
64
|
+
var external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject);
|
|
65
|
+
;// CONCATENATED MODULE: ./src/adapters/lib/containerReference.ts
|
|
66
|
+
|
|
67
|
+
// Builds the federation host code
|
|
68
|
+
const buildFederationHost = (config)=>{
|
|
69
|
+
const { name, remotes, shared } = config;
|
|
70
|
+
const remoteConfigs = remotes ? JSON.stringify(Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
71
|
+
name: remoteAlias,
|
|
72
|
+
entry: remote,
|
|
73
|
+
alias: remoteAlias,
|
|
74
|
+
type: 'esm'
|
|
75
|
+
}))) : '[]';
|
|
76
|
+
const sharedConfig = Object.entries(shared ?? {}).reduce((acc, [pkg, config])=>{
|
|
77
|
+
const version = config.requiredVersion?.replace(/^[^0-9]/, '') || '';
|
|
78
|
+
acc += `${JSON.stringify(pkg)}: {
|
|
79
|
+
"package": "${pkg}",
|
|
80
|
+
"version": "${version}",
|
|
81
|
+
"scope": "default",
|
|
82
|
+
"get": async () => await import('federationShare/${pkg}'),
|
|
83
|
+
"shareConfig": {
|
|
84
|
+
"singleton": ${config.singleton},
|
|
85
|
+
"requiredVersion": "${config.requiredVersion}",
|
|
86
|
+
"eager": ${config.eager},
|
|
87
|
+
"strictVersion": ${config.strictVersion}
|
|
88
|
+
}
|
|
89
|
+
},\n`;
|
|
90
|
+
return acc;
|
|
91
|
+
}, '{') + '}';
|
|
92
|
+
return `
|
|
93
|
+
import { init as initFederationHost } from "@module-federation/runtime";
|
|
94
|
+
|
|
95
|
+
const createVirtualRemoteModule = (name, ref, exports) => {
|
|
96
|
+
const genExports = exports.map(e =>
|
|
97
|
+
e === 'default'
|
|
98
|
+
? 'export default mfLsZJ92.default;'
|
|
99
|
+
: \`export const \${e} = mfLsZJ92[\${JSON.stringify(e)}];\`
|
|
100
|
+
).join('');
|
|
101
|
+
|
|
102
|
+
const loadRef = \`const mfLsZJ92 = await container.loadRemote(\${JSON.stringify(ref)});\`;
|
|
103
|
+
|
|
104
|
+
return \`
|
|
105
|
+
const container = __FEDERATION__.__INSTANCES__.find(container => container.name === name) || __FEDERATION__.__INSTANCES__[0];
|
|
106
|
+
\${loadRef}
|
|
107
|
+
\${genExports}
|
|
108
|
+
\`;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function encodeInlineESM(code) {
|
|
112
|
+
return 'data:text/javascript;charset=utf-8,' + encodeURIComponent(code);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const runtimePlugin = () => ({
|
|
116
|
+
name: 'import-maps-plugin',
|
|
117
|
+
async init(args) {
|
|
118
|
+
// Load all remotes and collect their moduleMaps
|
|
119
|
+
const remotesWithModuleMaps = await Promise.all(
|
|
120
|
+
args.options.remotes.map(async (remote) => {
|
|
121
|
+
console.log('remote', remote);
|
|
122
|
+
if (remote.type === 'esm') {
|
|
123
|
+
const remoteModule = await import(remote.entry);
|
|
124
|
+
return { remote, moduleMap: remoteModule.moduleMap };
|
|
125
|
+
}
|
|
126
|
+
return { remote, moduleMap: null };
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// Build import map entries for all remote modules
|
|
131
|
+
const allImports = {};
|
|
132
|
+
for (const { remote, moduleMap } of remotesWithModuleMaps) {
|
|
133
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
134
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
135
|
+
const currentImportMap = importShim.getImportMap().imports;
|
|
136
|
+
// Use remote name + expose path (e.g., "mfe1/component")
|
|
137
|
+
const key = remote.name + expose.replace('.', '');
|
|
138
|
+
if (!currentImportMap[key] && !allImports[key]) {
|
|
139
|
+
const encodedModule = encodeInlineESM(
|
|
140
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
141
|
+
);
|
|
142
|
+
allImports[key] = encodedModule;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (Object.keys(allImports).length > 0) {
|
|
149
|
+
await importShim.addImportMap({ imports: allImports });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return args;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const mfHoZJ92 = initFederationHost({
|
|
157
|
+
name: ${JSON.stringify(name)},
|
|
158
|
+
remotes: ${remoteConfigs},
|
|
159
|
+
shared: ${sharedConfig},
|
|
160
|
+
plugins: [runtimePlugin()],
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
await Promise.all(mfHoZJ92.initializeSharing('default', 'version-first'));
|
|
164
|
+
|
|
165
|
+
// Ensure import maps are registered before any code that uses remotes runs
|
|
166
|
+
const remotesList = ${remoteConfigs};
|
|
167
|
+
const allImports = {};
|
|
168
|
+
for (const remote of remotesList) {
|
|
169
|
+
if (remote.type === 'esm') {
|
|
170
|
+
try {
|
|
171
|
+
const remoteModule = await import(remote.entry);
|
|
172
|
+
const moduleMap = remoteModule.moduleMap;
|
|
173
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
174
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
175
|
+
const key = remote.name + expose.replace('.', '');
|
|
176
|
+
if (!allImports[key]) {
|
|
177
|
+
const encodedModule = encodeInlineESM(
|
|
178
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
179
|
+
);
|
|
180
|
+
allImports[key] = encodedModule;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.error('Failed to load remote:', remote.name, e);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (Object.keys(allImports).length > 0) {
|
|
190
|
+
await importShim.addImportMap({ imports: allImports });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
`;
|
|
194
|
+
};
|
|
195
|
+
const initializeHostPlugin = (config)=>({
|
|
196
|
+
name: 'host-initialization',
|
|
197
|
+
setup (build) {
|
|
198
|
+
build.onResolve({
|
|
199
|
+
filter: /federation-host/
|
|
200
|
+
}, (args)=>({
|
|
201
|
+
path: args.path,
|
|
202
|
+
namespace: 'federation-host',
|
|
203
|
+
pluginData: {
|
|
204
|
+
kind: args.kind,
|
|
205
|
+
resolveDir: args.resolveDir
|
|
206
|
+
}
|
|
207
|
+
}));
|
|
208
|
+
build.onLoad({
|
|
209
|
+
filter: /.*/,
|
|
210
|
+
namespace: 'federation-host'
|
|
211
|
+
}, async (args)=>({
|
|
212
|
+
contents: buildFederationHost(config),
|
|
213
|
+
resolveDir: args.pluginData.resolveDir
|
|
214
|
+
}));
|
|
215
|
+
// Add custom loaders
|
|
216
|
+
const loaders = build.initialOptions.loader || {};
|
|
217
|
+
// Apply custom loaders
|
|
218
|
+
for (const [ext, loader] of Object.entries(loaders)){
|
|
219
|
+
build.onLoad({
|
|
220
|
+
filter: new RegExp(`\\${ext}$`),
|
|
221
|
+
namespace: 'file'
|
|
222
|
+
}, async (args)=>{
|
|
223
|
+
const contents = await external_fs_default().promises.readFile(args.path, 'utf8');
|
|
224
|
+
return {
|
|
225
|
+
contents: buildFederationHost(config) + contents,
|
|
226
|
+
loader
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
// Fallback loader for files not matched by custom loaders
|
|
231
|
+
const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
|
|
232
|
+
build.onLoad({
|
|
233
|
+
filter: /.*\.(ts|js|mjs)$/,
|
|
234
|
+
namespace: 'file'
|
|
235
|
+
}, //@ts-ignore
|
|
236
|
+
async (args)=>{
|
|
237
|
+
if (!fallbackFilter.test(args.path)) {
|
|
238
|
+
if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const contents = await external_fs_default().promises.readFile(args.path, 'utf8');
|
|
242
|
+
return {
|
|
243
|
+
contents: 'import "federation-host"; \n ' + contents
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
exports.buildFederationHost = __webpack_exports__.buildFederationHost;
|
|
251
|
+
exports.initializeHostPlugin = __webpack_exports__.initializeHostPlugin;
|
|
252
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
253
|
+
if(["buildFederationHost","initializeHostPlugin"].indexOf(__rspack_i) === -1) {
|
|
254
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// Builds the federation host code
|
|
6
|
+
const buildFederationHost = (config)=>{
|
|
7
|
+
const { name, remotes, shared } = config;
|
|
8
|
+
const remoteConfigs = remotes ? JSON.stringify(Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
9
|
+
name: remoteAlias,
|
|
10
|
+
entry: remote,
|
|
11
|
+
alias: remoteAlias,
|
|
12
|
+
type: 'esm'
|
|
13
|
+
}))) : '[]';
|
|
14
|
+
const sharedConfig = Object.entries(shared ?? {}).reduce((acc, [pkg, config])=>{
|
|
15
|
+
const version = config.requiredVersion?.replace(/^[^0-9]/, '') || '';
|
|
16
|
+
acc += `${JSON.stringify(pkg)}: {
|
|
17
|
+
"package": "${pkg}",
|
|
18
|
+
"version": "${version}",
|
|
19
|
+
"scope": "default",
|
|
20
|
+
"get": async () => await import('federationShare/${pkg}'),
|
|
21
|
+
"shareConfig": {
|
|
22
|
+
"singleton": ${config.singleton},
|
|
23
|
+
"requiredVersion": "${config.requiredVersion}",
|
|
24
|
+
"eager": ${config.eager},
|
|
25
|
+
"strictVersion": ${config.strictVersion}
|
|
26
|
+
}
|
|
27
|
+
},\n`;
|
|
28
|
+
return acc;
|
|
29
|
+
}, '{') + '}';
|
|
30
|
+
return `
|
|
31
|
+
import { init as initFederationHost } from "@module-federation/runtime";
|
|
32
|
+
|
|
33
|
+
const createVirtualRemoteModule = (name, ref, exports) => {
|
|
34
|
+
const genExports = exports.map(e =>
|
|
35
|
+
e === 'default'
|
|
36
|
+
? 'export default mfLsZJ92.default;'
|
|
37
|
+
: \`export const \${e} = mfLsZJ92[\${JSON.stringify(e)}];\`
|
|
38
|
+
).join('');
|
|
39
|
+
|
|
40
|
+
const loadRef = \`const mfLsZJ92 = await container.loadRemote(\${JSON.stringify(ref)});\`;
|
|
41
|
+
|
|
42
|
+
return \`
|
|
43
|
+
const container = __FEDERATION__.__INSTANCES__.find(container => container.name === name) || __FEDERATION__.__INSTANCES__[0];
|
|
44
|
+
\${loadRef}
|
|
45
|
+
\${genExports}
|
|
46
|
+
\`;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function encodeInlineESM(code) {
|
|
50
|
+
return 'data:text/javascript;charset=utf-8,' + encodeURIComponent(code);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const runtimePlugin = () => ({
|
|
54
|
+
name: 'import-maps-plugin',
|
|
55
|
+
async init(args) {
|
|
56
|
+
// Load all remotes and collect their moduleMaps
|
|
57
|
+
const remotesWithModuleMaps = await Promise.all(
|
|
58
|
+
args.options.remotes.map(async (remote) => {
|
|
59
|
+
console.log('remote', remote);
|
|
60
|
+
if (remote.type === 'esm') {
|
|
61
|
+
const remoteModule = await import(remote.entry);
|
|
62
|
+
return { remote, moduleMap: remoteModule.moduleMap };
|
|
63
|
+
}
|
|
64
|
+
return { remote, moduleMap: null };
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Build import map entries for all remote modules
|
|
69
|
+
const allImports = {};
|
|
70
|
+
for (const { remote, moduleMap } of remotesWithModuleMaps) {
|
|
71
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
72
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
73
|
+
const currentImportMap = importShim.getImportMap().imports;
|
|
74
|
+
// Use remote name + expose path (e.g., "mfe1/component")
|
|
75
|
+
const key = remote.name + expose.replace('.', '');
|
|
76
|
+
if (!currentImportMap[key] && !allImports[key]) {
|
|
77
|
+
const encodedModule = encodeInlineESM(
|
|
78
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
79
|
+
);
|
|
80
|
+
allImports[key] = encodedModule;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (Object.keys(allImports).length > 0) {
|
|
87
|
+
await importShim.addImportMap({ imports: allImports });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return args;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const mfHoZJ92 = initFederationHost({
|
|
95
|
+
name: ${JSON.stringify(name)},
|
|
96
|
+
remotes: ${remoteConfigs},
|
|
97
|
+
shared: ${sharedConfig},
|
|
98
|
+
plugins: [runtimePlugin()],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await Promise.all(mfHoZJ92.initializeSharing('default', 'version-first'));
|
|
102
|
+
|
|
103
|
+
// Ensure import maps are registered before any code that uses remotes runs
|
|
104
|
+
const remotesList = ${remoteConfigs};
|
|
105
|
+
const allImports = {};
|
|
106
|
+
for (const remote of remotesList) {
|
|
107
|
+
if (remote.type === 'esm') {
|
|
108
|
+
try {
|
|
109
|
+
const remoteModule = await import(remote.entry);
|
|
110
|
+
const moduleMap = remoteModule.moduleMap;
|
|
111
|
+
if (moduleMap && typeof moduleMap === 'object') {
|
|
112
|
+
for (const expose of Object.keys(moduleMap)) {
|
|
113
|
+
const key = remote.name + expose.replace('.', '');
|
|
114
|
+
if (!allImports[key]) {
|
|
115
|
+
const encodedModule = encodeInlineESM(
|
|
116
|
+
createVirtualRemoteModule(remote.name, key, moduleMap[expose].exports)
|
|
117
|
+
);
|
|
118
|
+
allImports[key] = encodedModule;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.error('Failed to load remote:', remote.name, e);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (Object.keys(allImports).length > 0) {
|
|
128
|
+
await importShim.addImportMap({ imports: allImports });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
`;
|
|
132
|
+
};
|
|
133
|
+
const initializeHostPlugin = (config)=>({
|
|
134
|
+
name: 'host-initialization',
|
|
135
|
+
setup (build) {
|
|
136
|
+
build.onResolve({
|
|
137
|
+
filter: /federation-host/
|
|
138
|
+
}, (args)=>({
|
|
139
|
+
path: args.path,
|
|
140
|
+
namespace: 'federation-host',
|
|
141
|
+
pluginData: {
|
|
142
|
+
kind: args.kind,
|
|
143
|
+
resolveDir: args.resolveDir
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
build.onLoad({
|
|
147
|
+
filter: /.*/,
|
|
148
|
+
namespace: 'federation-host'
|
|
149
|
+
}, async (args)=>({
|
|
150
|
+
contents: buildFederationHost(config),
|
|
151
|
+
resolveDir: args.pluginData.resolveDir
|
|
152
|
+
}));
|
|
153
|
+
// Add custom loaders
|
|
154
|
+
const loaders = build.initialOptions.loader || {};
|
|
155
|
+
// Apply custom loaders
|
|
156
|
+
for (const [ext, loader] of Object.entries(loaders)){
|
|
157
|
+
build.onLoad({
|
|
158
|
+
filter: new RegExp(`\\${ext}$`),
|
|
159
|
+
namespace: 'file'
|
|
160
|
+
}, async (args)=>{
|
|
161
|
+
const contents = await fs.promises.readFile(args.path, 'utf8');
|
|
162
|
+
return {
|
|
163
|
+
contents: buildFederationHost(config) + contents,
|
|
164
|
+
loader
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
// Fallback loader for files not matched by custom loaders
|
|
169
|
+
const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
|
|
170
|
+
build.onLoad({
|
|
171
|
+
filter: /.*\.(ts|js|mjs)$/,
|
|
172
|
+
namespace: 'file'
|
|
173
|
+
}, //@ts-ignore
|
|
174
|
+
async (args)=>{
|
|
175
|
+
if (!fallbackFilter.test(args.path)) {
|
|
176
|
+
if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const contents = await fs.promises.readFile(args.path, 'utf8');
|
|
180
|
+
return {
|
|
181
|
+
contents: 'import "federation-host"; \n ' + contents
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export { buildFederationHost, initializeHostPlugin };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Lexer {
|
|
2
|
+
input: string;
|
|
3
|
+
pos: number;
|
|
4
|
+
readString(input: string, pos: number): string | null;
|
|
5
|
+
readEscapedChar(): string | null;
|
|
6
|
+
readInt(radix: number, len: number): number | null;
|
|
7
|
+
readHexChar(len: number): number | null;
|
|
8
|
+
readCodePoint(): number | null;
|
|
9
|
+
}
|