@module-federation/esbuild 0.0.0-next-20240524231356 → 0.0.0-next-20240528203231
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/README.md +22 -32
- package/dist/build.cjs.js +704 -29
- package/dist/build.esm.js +678 -4
- package/dist/esbuild.cjs.js +178 -176
- package/dist/esbuild.esm.js +178 -176
- package/dist/get-externals.cjs.js +20 -0
- package/dist/get-externals.esm.js +18 -0
- package/dist/src/adapters/lib/containerPlugin.d.ts +2 -1
- package/dist/src/adapters/lib/containerReference.d.ts +3 -2
- package/dist/src/adapters/lib/linkRemotesPlugin.d.ts +2 -1
- package/dist/src/adapters/lib/plugin.d.ts +2 -1
- package/package.json +2 -2
- package/dist/federation-builder.cjs.js +0 -741
- package/dist/federation-builder.esm.js +0 -697
package/dist/esbuild.esm.js
CHANGED
|
@@ -10,8 +10,7 @@ import { init, parse as parse$1 } from 'es-module-lexer';
|
|
|
10
10
|
import { init as init$1, parse } from 'cjs-module-lexer';
|
|
11
11
|
import { promisify } from 'util';
|
|
12
12
|
import enhancedResolve from 'enhanced-resolve';
|
|
13
|
-
import {
|
|
14
|
-
import 'npmlog';
|
|
13
|
+
import { g as getExternals } from './get-externals.esm.js';
|
|
15
14
|
|
|
16
15
|
function getAugmentedNamespace(n) {
|
|
17
16
|
if (n.__esModule) return n;
|
|
@@ -104,20 +103,17 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
104
103
|
name: config.name
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
|
-
const mfConfig = config;
|
|
108
106
|
var _process_env_NODE_ENV;
|
|
109
107
|
const envType = process.env['NODE_ENV'] === 'development' ? 'local' : (_process_env_NODE_ENV = process.env['NODE_ENV']) != null ? _process_env_NODE_ENV : '';
|
|
110
108
|
const publicPath = config.publicPath || 'auto';
|
|
111
109
|
let containerName = '';
|
|
112
110
|
const outputMap = Object.entries(((_result_metafile = result.metafile) == null ? void 0 : _result_metafile.outputs) || {}).reduce((acc, [chunkKey, chunkValue])=>{
|
|
113
|
-
|
|
114
|
-
const { entryPoint, kind = 'static-import' } = chunkValue;
|
|
111
|
+
const { entryPoint } = chunkValue;
|
|
115
112
|
const key = entryPoint || chunkKey;
|
|
116
|
-
if (key.startsWith('container:') && key.endsWith(
|
|
113
|
+
if (key.startsWith('container:') && key.endsWith(config.filename)) {
|
|
117
114
|
containerName = key;
|
|
118
115
|
}
|
|
119
116
|
acc[key] = _extends$2({}, chunkValue, {
|
|
120
|
-
kind,
|
|
121
117
|
chunk: chunkKey
|
|
122
118
|
});
|
|
123
119
|
return acc;
|
|
@@ -160,7 +156,7 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
160
156
|
}
|
|
161
157
|
return assets;
|
|
162
158
|
};
|
|
163
|
-
const shared =
|
|
159
|
+
const shared = config.shared ? await Promise.all(Object.entries(config.shared).map(async ([pkg, config])=>{
|
|
164
160
|
const meta = outputMap['esm-shares:' + pkg];
|
|
165
161
|
const chunks = getChunks(meta, outputMap);
|
|
166
162
|
let { version } = config;
|
|
@@ -175,7 +171,7 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
175
171
|
}
|
|
176
172
|
}
|
|
177
173
|
return {
|
|
178
|
-
id: `${
|
|
174
|
+
id: `${config.name}:${pkg}`,
|
|
179
175
|
name: pkg,
|
|
180
176
|
version: version || config.version,
|
|
181
177
|
singleton: config.singleton || false,
|
|
@@ -183,7 +179,7 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
183
179
|
assets: chunks
|
|
184
180
|
};
|
|
185
181
|
})) : [];
|
|
186
|
-
const remotes =
|
|
182
|
+
const remotes = config.remotes ? Object.entries(config.remotes).map(([alias, remote])=>{
|
|
187
183
|
const [federationContainerName, entry] = remote.includes('@') ? remote.split('@') : [
|
|
188
184
|
alias,
|
|
189
185
|
remote
|
|
@@ -195,11 +191,11 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
195
191
|
entry
|
|
196
192
|
};
|
|
197
193
|
}) : [];
|
|
198
|
-
const exposes =
|
|
194
|
+
const exposes = config.exposes ? await Promise.all(Object.entries(config.exposes).map(async ([expose, value])=>{
|
|
199
195
|
const exposedFound = outputMapWithoutExt[value.replace('./', '')];
|
|
200
196
|
const chunks = getChunks(exposedFound, outputMap);
|
|
201
197
|
return {
|
|
202
|
-
id: `${
|
|
198
|
+
id: `${config.name}:${expose.replace(/^\.\//, '')}`,
|
|
203
199
|
name: expose.replace(/^\.\//, ''),
|
|
204
200
|
assets: chunks,
|
|
205
201
|
path: expose
|
|
@@ -213,22 +209,22 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
213
209
|
};
|
|
214
210
|
var _packageJson_name;
|
|
215
211
|
const manifest = {
|
|
216
|
-
id:
|
|
217
|
-
name:
|
|
212
|
+
id: config.name,
|
|
213
|
+
name: config.name,
|
|
218
214
|
metaData: {
|
|
219
|
-
name:
|
|
215
|
+
name: config.name,
|
|
220
216
|
type: 'app',
|
|
221
217
|
buildInfo: {
|
|
222
218
|
buildVersion: envType,
|
|
223
219
|
buildName: ((_packageJson_name = packageJson.name) != null ? _packageJson_name : 'default').replace(/[^a-zA-Z0-9]/g, '_')
|
|
224
220
|
},
|
|
225
221
|
remoteEntry: {
|
|
226
|
-
name:
|
|
222
|
+
name: config.filename,
|
|
227
223
|
path: outputMap[containerName] ? path__default.dirname(outputMap[containerName].chunk) : '',
|
|
228
224
|
type: 'esm'
|
|
229
225
|
},
|
|
230
226
|
types,
|
|
231
|
-
globalName:
|
|
227
|
+
globalName: config.name,
|
|
232
228
|
pluginVersion: version,
|
|
233
229
|
publicPath
|
|
234
230
|
},
|
|
@@ -422,9 +418,7 @@ const createContainer = (federationOptions) => {
|
|
|
422
418
|
return __webpack_exports__;
|
|
423
419
|
}`;
|
|
424
420
|
|
|
425
|
-
|
|
426
|
-
//@ts-ignore
|
|
427
|
-
const buildContainerHost = ({ config })=>{
|
|
421
|
+
const buildContainerHost = (config)=>{
|
|
428
422
|
const { name, remotes = {}, shared = {}, exposes = {} } = config;
|
|
429
423
|
const remoteConfigs = Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
430
424
|
type: 'esm',
|
|
@@ -492,7 +486,6 @@ const buildContainerHost = ({ config })=>{
|
|
|
492
486
|
|
|
493
487
|
await Promise.all(remotePrefetch);
|
|
494
488
|
|
|
495
|
-
console.log('module map',moduleMap);
|
|
496
489
|
const map = Object.keys(moduleMap).reduce((acc, expose) => {
|
|
497
490
|
const importMap = importShim.getImportMap().imports;
|
|
498
491
|
const key = args.origin.name + expose.replace('.', '');
|
|
@@ -505,7 +498,6 @@ console.log('module map',moduleMap);
|
|
|
505
498
|
return acc;
|
|
506
499
|
}, {});
|
|
507
500
|
await importShim.addImportMap({ imports: map });
|
|
508
|
-
console.log('final map', importShim.getImportMap());
|
|
509
501
|
|
|
510
502
|
return args;
|
|
511
503
|
}
|
|
@@ -531,11 +523,11 @@ console.log('module map',moduleMap);
|
|
|
531
523
|
const createContainerPlugin = (config)=>({
|
|
532
524
|
name: 'createContainer',
|
|
533
525
|
setup (build) {
|
|
534
|
-
const {
|
|
526
|
+
const { filename } = config;
|
|
535
527
|
const filter = new RegExp([
|
|
536
528
|
filename
|
|
537
529
|
].map((name)=>`${name}$`).join('|'));
|
|
538
|
-
const sharedExternals = new RegExp(Object.keys(
|
|
530
|
+
const sharedExternals = new RegExp(Object.keys(config.shared || {}).map((name)=>`${name}$`).join('|'));
|
|
539
531
|
build.onResolve({
|
|
540
532
|
filter
|
|
541
533
|
}, async (args)=>({
|
|
@@ -597,8 +589,8 @@ const createContainerPlugin = (config)=>({
|
|
|
597
589
|
});
|
|
598
590
|
|
|
599
591
|
// Builds the federation host code
|
|
600
|
-
const buildFederationHost = ()=>{
|
|
601
|
-
const { name, remotes, shared } =
|
|
592
|
+
const buildFederationHost = (config)=>{
|
|
593
|
+
const { name, remotes, shared } = config;
|
|
602
594
|
const remoteConfigs = remotes ? JSON.stringify(Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
603
595
|
name: remoteAlias,
|
|
604
596
|
entry: remote,
|
|
@@ -684,104 +676,103 @@ const buildFederationHost = ()=>{
|
|
|
684
676
|
});
|
|
685
677
|
`;
|
|
686
678
|
};
|
|
687
|
-
const initializeHostPlugin = {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
build.onLoad({
|
|
701
|
-
filter: /.*/,
|
|
702
|
-
namespace: 'federation-host'
|
|
703
|
-
}, async (args)=>({
|
|
704
|
-
contents: buildFederationHost(),
|
|
705
|
-
resolveDir: args.pluginData.resolveDir
|
|
706
|
-
}));
|
|
707
|
-
// Add custom loaders
|
|
708
|
-
const loaders = build.initialOptions.loader || {};
|
|
709
|
-
// Apply custom loaders
|
|
710
|
-
for (const [ext, loader] of Object.entries(loaders)){
|
|
679
|
+
const initializeHostPlugin = (config)=>({
|
|
680
|
+
name: 'host-initialization',
|
|
681
|
+
setup (build) {
|
|
682
|
+
build.onResolve({
|
|
683
|
+
filter: /federation-host/
|
|
684
|
+
}, (args)=>({
|
|
685
|
+
path: args.path,
|
|
686
|
+
namespace: 'federation-host',
|
|
687
|
+
pluginData: {
|
|
688
|
+
kind: args.kind,
|
|
689
|
+
resolveDir: args.resolveDir
|
|
690
|
+
}
|
|
691
|
+
}));
|
|
711
692
|
build.onLoad({
|
|
712
|
-
filter:
|
|
693
|
+
filter: /.*/,
|
|
694
|
+
namespace: 'federation-host'
|
|
695
|
+
}, async (args)=>({
|
|
696
|
+
contents: buildFederationHost(config),
|
|
697
|
+
resolveDir: args.pluginData.resolveDir
|
|
698
|
+
}));
|
|
699
|
+
// Add custom loaders
|
|
700
|
+
const loaders = build.initialOptions.loader || {};
|
|
701
|
+
// Apply custom loaders
|
|
702
|
+
for (const [ext, loader] of Object.entries(loaders)){
|
|
703
|
+
build.onLoad({
|
|
704
|
+
filter: new RegExp(`\\${ext}$`),
|
|
705
|
+
namespace: 'file'
|
|
706
|
+
}, async (args)=>{
|
|
707
|
+
const contents = await fs__default.promises.readFile(args.path, 'utf8');
|
|
708
|
+
return {
|
|
709
|
+
contents: buildFederationHost(config) + contents,
|
|
710
|
+
loader
|
|
711
|
+
};
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
// Fallback loader for files not matched by custom loaders
|
|
715
|
+
const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
|
|
716
|
+
build.onLoad({
|
|
717
|
+
filter: /.*\.(ts|js|mjs)$/,
|
|
713
718
|
namespace: 'file'
|
|
714
|
-
},
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
719
|
+
}, //@ts-ignore
|
|
720
|
+
async (args)=>{
|
|
721
|
+
if (!fallbackFilter.test(args.path)) {
|
|
722
|
+
if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const contents = await fs__default.promises.readFile(args.path, 'utf8');
|
|
726
|
+
return {
|
|
727
|
+
contents: 'import "federation-host"; \n ' + contents
|
|
728
|
+
};
|
|
729
|
+
}
|
|
720
730
|
});
|
|
721
731
|
}
|
|
722
|
-
|
|
723
|
-
const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
|
|
724
|
-
build.onLoad({
|
|
725
|
-
filter: /.*\.(ts|js|mjs)$/,
|
|
726
|
-
namespace: 'file'
|
|
727
|
-
}, //@ts-ignore
|
|
728
|
-
async (args)=>{
|
|
729
|
-
if (!fallbackFilter.test(args.path)) {
|
|
730
|
-
if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) {
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
const contents = await fs__default.promises.readFile(args.path, 'utf8');
|
|
734
|
-
return {
|
|
735
|
-
contents: buildFederationHost() + contents
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
};
|
|
732
|
+
});
|
|
741
733
|
|
|
742
734
|
// relys on import map since i dont know the named exports of a remote to return.
|
|
743
735
|
const createVirtualRemoteModule = (name, ref)=>`
|
|
744
736
|
export * from ${JSON.stringify('federationRemote/' + ref)}
|
|
745
737
|
`;
|
|
746
|
-
const linkRemotesPlugin = {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
738
|
+
const linkRemotesPlugin = (config)=>({
|
|
739
|
+
name: 'linkRemotes',
|
|
740
|
+
setup (build) {
|
|
741
|
+
const remotes = config.remotes || {};
|
|
742
|
+
const filter = new RegExp(Object.keys(remotes).reduce((acc, key)=>{
|
|
743
|
+
if (!key) return acc;
|
|
744
|
+
acc.push(`^${key}`);
|
|
745
|
+
return acc;
|
|
746
|
+
}, []).join('|'));
|
|
747
|
+
build.onResolve({
|
|
748
|
+
filter: filter
|
|
749
|
+
}, async (args)=>{
|
|
750
|
+
return {
|
|
751
|
+
path: args.path,
|
|
752
|
+
namespace: 'remote-module'
|
|
753
|
+
};
|
|
754
|
+
});
|
|
755
|
+
build.onResolve({
|
|
756
|
+
filter: /^federationRemote/
|
|
757
|
+
}, async (args)=>{
|
|
758
|
+
return {
|
|
759
|
+
path: args.path.replace('federationRemote/', ''),
|
|
760
|
+
external: true,
|
|
761
|
+
namespace: 'externals'
|
|
762
|
+
};
|
|
763
|
+
});
|
|
764
|
+
build.onLoad({
|
|
765
|
+
filter,
|
|
761
766
|
namespace: 'remote-module'
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
};
|
|
772
|
-
});
|
|
773
|
-
build.onLoad({
|
|
774
|
-
filter,
|
|
775
|
-
namespace: 'remote-module'
|
|
776
|
-
}, async (args)=>{
|
|
777
|
-
return {
|
|
778
|
-
contents: createVirtualRemoteModule(federationBuilder.config.name, args.path),
|
|
779
|
-
loader: 'js',
|
|
780
|
-
resolveDir: path__default.dirname(args.path)
|
|
781
|
-
};
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
};
|
|
767
|
+
}, async (args)=>{
|
|
768
|
+
return {
|
|
769
|
+
contents: createVirtualRemoteModule(config.name, args.path),
|
|
770
|
+
loader: 'js',
|
|
771
|
+
resolveDir: path__default.dirname(args.path)
|
|
772
|
+
};
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
});
|
|
785
776
|
|
|
786
777
|
function _extends$1() {
|
|
787
778
|
_extends$1 = Object.assign || function(target) {
|
|
@@ -847,28 +838,14 @@ const cjsToEsmPlugin = {
|
|
|
847
838
|
}
|
|
848
839
|
};
|
|
849
840
|
// Plugin to link shared dependencies
|
|
850
|
-
const linkSharedPlugin = {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
return {
|
|
859
|
-
path: args.path,
|
|
860
|
-
namespace: 'virtual-share-module',
|
|
861
|
-
pluginData: {
|
|
862
|
-
kind: args.kind,
|
|
863
|
-
resolveDir: args.resolveDir
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
});
|
|
867
|
-
build.onResolve({
|
|
868
|
-
filter: /.*/,
|
|
869
|
-
namespace: 'esm-shares'
|
|
870
|
-
}, (args)=>{
|
|
871
|
-
if (filter.test(args.path)) {
|
|
841
|
+
const linkSharedPlugin = (config)=>({
|
|
842
|
+
name: 'linkShared',
|
|
843
|
+
setup (build) {
|
|
844
|
+
const filter = new RegExp(Object.keys(config.shared || {}).map((name)=>`${name}$`).join('|'));
|
|
845
|
+
build.onResolve({
|
|
846
|
+
filter
|
|
847
|
+
}, (args)=>{
|
|
848
|
+
if (args.namespace === 'esm-shares') return null;
|
|
872
849
|
return {
|
|
873
850
|
path: args.path,
|
|
874
851
|
namespace: 'virtual-share-module',
|
|
@@ -877,58 +854,83 @@ const linkSharedPlugin = {
|
|
|
877
854
|
resolveDir: args.resolveDir
|
|
878
855
|
}
|
|
879
856
|
};
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
857
|
+
});
|
|
858
|
+
build.onResolve({
|
|
859
|
+
filter: /.*/,
|
|
860
|
+
namespace: 'esm-shares'
|
|
861
|
+
}, (args)=>{
|
|
862
|
+
if (filter.test(args.path)) {
|
|
863
|
+
return {
|
|
864
|
+
path: args.path,
|
|
865
|
+
namespace: 'virtual-share-module',
|
|
866
|
+
pluginData: {
|
|
867
|
+
kind: args.kind,
|
|
868
|
+
resolveDir: args.resolveDir
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
if (filter.test(args.importer)) {
|
|
873
|
+
return {
|
|
874
|
+
path: args.path,
|
|
875
|
+
namespace: 'esm-shares',
|
|
876
|
+
pluginData: {
|
|
877
|
+
kind: args.kind,
|
|
878
|
+
resolveDir: args.resolveDir
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
return undefined;
|
|
883
|
+
});
|
|
884
|
+
build.onResolve({
|
|
885
|
+
filter: /^federationShare/
|
|
886
|
+
}, async (args)=>({
|
|
887
|
+
path: args.path.replace('federationShare/', ''),
|
|
884
888
|
namespace: 'esm-shares',
|
|
885
889
|
pluginData: {
|
|
886
890
|
kind: args.kind,
|
|
887
891
|
resolveDir: args.resolveDir
|
|
888
892
|
}
|
|
893
|
+
}));
|
|
894
|
+
build.onLoad({
|
|
895
|
+
filter,
|
|
896
|
+
namespace: 'virtual-share-module'
|
|
897
|
+
}, async (args)=>{
|
|
898
|
+
const exp = await getExports(args.path);
|
|
899
|
+
return {
|
|
900
|
+
contents: createVirtualShareModule(config.name, args.path, exp),
|
|
901
|
+
loader: 'js',
|
|
902
|
+
resolveDir: path__default.dirname(args.path)
|
|
889
903
|
};
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
build.onResolve({
|
|
894
|
-
filter: /^federationShare/
|
|
895
|
-
}, async (args)=>({
|
|
896
|
-
path: args.path.replace('federationShare/', ''),
|
|
897
|
-
namespace: 'esm-shares',
|
|
898
|
-
pluginData: {
|
|
899
|
-
kind: args.kind,
|
|
900
|
-
resolveDir: args.resolveDir
|
|
901
|
-
}
|
|
902
|
-
}));
|
|
903
|
-
build.onLoad({
|
|
904
|
-
filter,
|
|
905
|
-
namespace: 'virtual-share-module'
|
|
906
|
-
}, async (args)=>{
|
|
907
|
-
const exp = await getExports(args.path);
|
|
908
|
-
return {
|
|
909
|
-
contents: createVirtualShareModule(federationBuilder.config.name, args.path, exp),
|
|
910
|
-
loader: 'js',
|
|
911
|
-
resolveDir: path__default.dirname(args.path)
|
|
912
|
-
};
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
};
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
});
|
|
916
907
|
// Main module federation plugin
|
|
917
908
|
const moduleFederationPlugin = (config)=>({
|
|
918
909
|
name: 'module-federation',
|
|
919
910
|
setup (build) {
|
|
920
911
|
build.initialOptions.metafile = true;
|
|
912
|
+
const externals = getExternals(config);
|
|
913
|
+
if (build.initialOptions.external) {
|
|
914
|
+
build.initialOptions.external = [
|
|
915
|
+
...new Set([
|
|
916
|
+
...build.initialOptions.external,
|
|
917
|
+
...externals
|
|
918
|
+
])
|
|
919
|
+
];
|
|
920
|
+
} else {
|
|
921
|
+
build.initialOptions.external = externals;
|
|
922
|
+
}
|
|
921
923
|
const pluginStack = [];
|
|
922
|
-
const remotes = Object.keys(
|
|
923
|
-
const shared = Object.keys(
|
|
924
|
-
const exposes = Object.keys(
|
|
924
|
+
const remotes = Object.keys(config.remotes || {}).length;
|
|
925
|
+
const shared = Object.keys(config.shared || {}).length;
|
|
926
|
+
const exposes = Object.keys(config.exposes || {}).length;
|
|
925
927
|
const entryPoints = build.initialOptions.entryPoints;
|
|
926
|
-
const filename =
|
|
928
|
+
const filename = config.filename || 'remoteEntry.js';
|
|
927
929
|
if (remotes) {
|
|
928
|
-
pluginStack.push(linkRemotesPlugin);
|
|
930
|
+
pluginStack.push(linkRemotesPlugin(config));
|
|
929
931
|
}
|
|
930
932
|
if (shared) {
|
|
931
|
-
pluginStack.push(linkSharedPlugin);
|
|
933
|
+
pluginStack.push(linkSharedPlugin(config));
|
|
932
934
|
}
|
|
933
935
|
if (!entryPoints) {
|
|
934
936
|
build.initialOptions.entryPoints = [];
|
|
@@ -945,7 +947,7 @@ const moduleFederationPlugin = (config)=>({
|
|
|
945
947
|
}
|
|
946
948
|
}
|
|
947
949
|
[
|
|
948
|
-
initializeHostPlugin,
|
|
950
|
+
initializeHostPlugin(config),
|
|
949
951
|
createContainerPlugin(config),
|
|
950
952
|
cjsToEsmPlugin,
|
|
951
953
|
...pluginStack
|
|
@@ -953,8 +955,8 @@ const moduleFederationPlugin = (config)=>({
|
|
|
953
955
|
build.onEnd(async (result)=>{
|
|
954
956
|
if (!result.metafile) return;
|
|
955
957
|
if (exposes) {
|
|
956
|
-
const exposedConfig =
|
|
957
|
-
const remoteFile =
|
|
958
|
+
const exposedConfig = config.exposes || {};
|
|
959
|
+
const remoteFile = config.filename;
|
|
958
960
|
const exposedEntries = {};
|
|
959
961
|
const outputMapWithoutExt = Object.entries(result.metafile.outputs).reduce((acc, [chunkKey, chunkValue])=>{
|
|
960
962
|
//@ts-ignore
|
|
@@ -987,7 +989,7 @@ const moduleFederationPlugin = (config)=>({
|
|
|
987
989
|
fs__default.writeFileSync(outputPath, withExports, 'utf-8');
|
|
988
990
|
}
|
|
989
991
|
}
|
|
990
|
-
await writeRemoteManifest(
|
|
992
|
+
await writeRemoteManifest(config, result);
|
|
991
993
|
console.log(`build ended with ${result.errors.length} errors`);
|
|
992
994
|
});
|
|
993
995
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getExternals(config) {
|
|
4
|
+
const shared = Object.keys(config.shared);
|
|
5
|
+
const sharedMappings = config.sharedMappings.map((m)=>m.key);
|
|
6
|
+
const remotes = config.remotes;
|
|
7
|
+
Object.keys(remotes).reduce((acc, key)=>{
|
|
8
|
+
if (!key) return acc;
|
|
9
|
+
acc.push(key);
|
|
10
|
+
acc.push(key + '/*');
|
|
11
|
+
return acc;
|
|
12
|
+
}, []);
|
|
13
|
+
const externals = [
|
|
14
|
+
...shared,
|
|
15
|
+
...sharedMappings
|
|
16
|
+
];
|
|
17
|
+
return externals;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.getExternals = getExternals;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function getExternals(config) {
|
|
2
|
+
const shared = Object.keys(config.shared);
|
|
3
|
+
const sharedMappings = config.sharedMappings.map((m)=>m.key);
|
|
4
|
+
const remotes = config.remotes;
|
|
5
|
+
Object.keys(remotes).reduce((acc, key)=>{
|
|
6
|
+
if (!key) return acc;
|
|
7
|
+
acc.push(key);
|
|
8
|
+
acc.push(key + '/*');
|
|
9
|
+
return acc;
|
|
10
|
+
}, []);
|
|
11
|
+
const externals = [
|
|
12
|
+
...shared,
|
|
13
|
+
...sharedMappings
|
|
14
|
+
];
|
|
15
|
+
return externals;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { getExternals as g };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PluginBuild } from 'esbuild';
|
|
2
|
-
|
|
2
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config.js';
|
|
3
|
+
export declare const createContainerPlugin: (config: NormalizedFederationConfig) => {
|
|
3
4
|
name: string;
|
|
4
5
|
setup(build: PluginBuild): void;
|
|
5
6
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config';
|
|
2
|
+
export declare const buildFederationHost: (config: NormalizedFederationConfig) => string;
|
|
3
|
+
export declare const initializeHostPlugin: (config: NormalizedFederationConfig) => {
|
|
3
4
|
name: string;
|
|
4
5
|
setup(build: any): void;
|
|
5
6
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config';
|
|
1
2
|
export declare const createVirtualRemoteModule: (name: string, ref: string) => string;
|
|
2
|
-
export declare const linkRemotesPlugin: {
|
|
3
|
+
export declare const linkRemotesPlugin: (config: NormalizedFederationConfig) => {
|
|
3
4
|
name: string;
|
|
4
5
|
setup(build: any): void;
|
|
5
6
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PluginBuild } from 'esbuild';
|
|
2
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config.js';
|
|
2
3
|
export declare const createVirtualShareModule: (name: string, ref: string, exports: string[]) => string;
|
|
3
4
|
export declare const createVirtualRemoteModule: (name: string, ref: string) => string;
|
|
4
|
-
export declare const moduleFederationPlugin: (config:
|
|
5
|
+
export declare const moduleFederationPlugin: (config: NormalizedFederationConfig) => {
|
|
5
6
|
name: string;
|
|
6
7
|
setup(build: PluginBuild): void;
|
|
7
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/esbuild",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240528203231",
|
|
4
4
|
"author": "Zack Jackson (@ScriptedAlchemy)",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"esbuild": "^0.18.12",
|
|
66
66
|
"npmlog": "^6.0.2",
|
|
67
67
|
"acorn": "^8.8.1",
|
|
68
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
68
|
+
"@module-federation/sdk": "0.0.0-next-20240528203231"
|
|
69
69
|
}
|
|
70
70
|
}
|