@module-federation/esbuild 0.0.0-next-20240528203231 → 0.0.0-next-20240529015908

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.
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
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)=>{
4
+ var _config_shared;
5
+ const shared = Object.keys((_config_shared = config.shared) != null ? _config_shared : {});
6
+ var _config_remotes;
7
+ const remotes = (_config_remotes = config.remotes) != null ? _config_remotes : {};
8
+ const remoteKeys = Object.keys(remotes).reduce((acc, key)=>{
8
9
  if (!key) return acc;
9
10
  acc.push(key);
10
11
  acc.push(key + '/*');
@@ -12,7 +13,7 @@ function getExternals(config) {
12
13
  }, []);
13
14
  const externals = [
14
15
  ...shared,
15
- ...sharedMappings
16
+ ...remoteKeys
16
17
  ];
17
18
  return externals;
18
19
  }
@@ -1,8 +1,9 @@
1
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)=>{
2
+ var _config_shared;
3
+ const shared = Object.keys((_config_shared = config.shared) != null ? _config_shared : {});
4
+ var _config_remotes;
5
+ const remotes = (_config_remotes = config.remotes) != null ? _config_remotes : {};
6
+ const remoteKeys = Object.keys(remotes).reduce((acc, key)=>{
6
7
  if (!key) return acc;
7
8
  acc.push(key);
8
9
  acc.push(key + '/*');
@@ -10,7 +11,7 @@ function getExternals(config) {
10
11
  }, []);
11
12
  const externals = [
12
13
  ...shared,
13
- ...sharedMappings
14
+ ...remoteKeys
14
15
  ];
15
16
  return externals;
16
17
  }
@@ -1 +1,2 @@
1
1
  export * from "./src/index";
2
+ export { default } from "./src/index";
package/dist/index.cjs.js CHANGED
@@ -1,14 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
3
+ var index = {};
4
4
 
5
- var nativeFederationRuntime = require('@module-federation/native-federation-runtime');
6
-
7
-
8
-
9
- Object.keys(nativeFederationRuntime).forEach(function (k) {
10
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
11
- enumerable: true,
12
- get: function () { return nativeFederationRuntime[k]; }
13
- });
14
- });
5
+ module.exports = index;
package/dist/index.esm.js CHANGED
@@ -1 +1,3 @@
1
- export * from '@module-federation/native-federation-runtime';
1
+ var index = {};
2
+
3
+ export { index as default };
package/dist/package.json CHANGED
@@ -19,10 +19,10 @@
19
19
  "import": "./dist/index.esm.js",
20
20
  "require": "./dist/index.cjs.js"
21
21
  },
22
- "./esbuild-adapter": {
22
+ "./plugin": {
23
23
  "types": "./dist/esbuild.cjs.d.ts",
24
- "import": "./dist/esbuild.esm.js",
25
- "require": "./dist/esbuild.cjs.js"
24
+ "import": "./dist/plugin.esm.js",
25
+ "require": "./dist/plugin.cjs.js"
26
26
  },
27
27
  "./build": {
28
28
  "types": "./dist/build.cjs.d.ts",
@@ -0,0 +1 @@
1
+ export * from "./src/adapters/lib/plugin";
@@ -1,45 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var esbuild$1 = require('esbuild');
4
- var rollup = require('rollup');
5
- var pluginNodeResolve = require('@rollup/plugin-node-resolve');
6
- var rollupPluginNodeExternals = require('rollup-plugin-node-externals');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
7
5
  var fs = require('fs');
8
- var path = require('path');
9
- var commonjs = require('@rollup/plugin-commonjs');
10
- var replace = require('@rollup/plugin-replace');
11
6
  var esModuleLexer = require('es-module-lexer');
12
7
  var cjsModuleLexer = require('cjs-module-lexer');
13
8
  var util = require('util');
14
9
  var enhancedResolve = require('enhanced-resolve');
10
+ var path = require('path');
15
11
  var getExternals = require('./get-externals.cjs.js');
16
12
 
17
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
14
 
19
- var esbuild__default = /*#__PURE__*/_interopDefaultLegacy(esbuild$1);
20
- var pluginNodeResolve__default = /*#__PURE__*/_interopDefaultLegacy(pluginNodeResolve);
21
15
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
22
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
23
- var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
24
- var replace__default = /*#__PURE__*/_interopDefaultLegacy(replace);
25
16
  var enhancedResolve__default = /*#__PURE__*/_interopDefaultLegacy(enhancedResolve);
26
-
27
- function getAugmentedNamespace(n) {
28
- if (n.__esModule) return n;
29
- var a = Object.defineProperty({}, '__esModule', {
30
- value: true
31
- });
32
- Object.keys(n).forEach(function(k) {
33
- var d = Object.getOwnPropertyDescriptor(n, k);
34
- Object.defineProperty(a, k, d.get ? d : {
35
- enumerable: true,
36
- get: function get() {
37
- return n[k];
38
- }
39
- });
40
- });
41
- return a;
42
- }
17
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
43
18
 
44
19
  const resolve = util.promisify(enhancedResolve__default["default"].create({
45
20
  mainFields: [
@@ -86,8 +61,8 @@ async function getExports(modulePath) {
86
61
 
87
62
  var version = "0.0.1";
88
63
 
89
- function _extends$2() {
90
- _extends$2 = Object.assign || function(target) {
64
+ function _extends$1() {
65
+ _extends$1 = Object.assign || function(target) {
91
66
  for(var i = 1; i < arguments.length; i++){
92
67
  var source = arguments[i];
93
68
  for(var key in source){
@@ -98,7 +73,7 @@ function _extends$2() {
98
73
  }
99
74
  return target;
100
75
  };
101
- return _extends$2.apply(this, arguments);
76
+ return _extends$1.apply(this, arguments);
102
77
  }
103
78
  const writeRemoteManifest = async (config, result)=>{
104
79
  var _result_metafile, _result_metafile1;
@@ -125,7 +100,7 @@ const writeRemoteManifest = async (config, result)=>{
125
100
  if (key.startsWith('container:') && key.endsWith(config.filename)) {
126
101
  containerName = key;
127
102
  }
128
- acc[key] = _extends$2({}, chunkValue, {
103
+ acc[key] = _extends$1({}, chunkValue, {
129
104
  chunk: chunkKey
130
105
  });
131
106
  return acc;
@@ -135,7 +110,7 @@ const writeRemoteManifest = async (config, result)=>{
135
110
  const { entryPoint } = chunkValue;
136
111
  const key = entryPoint || chunkKey;
137
112
  const trimKey = key.substring(0, key.lastIndexOf('.')) || key;
138
- acc[trimKey] = _extends$2({}, chunkValue, {
113
+ acc[trimKey] = _extends$1({}, chunkValue, {
139
114
  chunk: chunkKey
140
115
  });
141
116
  return acc;
@@ -744,7 +719,7 @@ const initializeHostPlugin = (config)=>({
744
719
  });
745
720
 
746
721
  // relys on import map since i dont know the named exports of a remote to return.
747
- const createVirtualRemoteModule = (name, ref)=>`
722
+ const createVirtualRemoteModule$1 = (name, ref)=>`
748
723
  export * from ${JSON.stringify('federationRemote/' + ref)}
749
724
  `;
750
725
  const linkRemotesPlugin = (config)=>({
@@ -778,7 +753,7 @@ const linkRemotesPlugin = (config)=>({
778
753
  namespace: 'remote-module'
779
754
  }, async (args)=>{
780
755
  return {
781
- contents: createVirtualRemoteModule(config.name, args.path),
756
+ contents: createVirtualRemoteModule$1(config.name, args.path),
782
757
  loader: 'js',
783
758
  resolveDir: path__default["default"].dirname(args.path)
784
759
  };
@@ -786,8 +761,8 @@ const linkRemotesPlugin = (config)=>({
786
761
  }
787
762
  });
788
763
 
789
- function _extends$1() {
790
- _extends$1 = Object.assign || function(target) {
764
+ function _extends() {
765
+ _extends = Object.assign || function(target) {
791
766
  for(var i = 1; i < arguments.length; i++){
792
767
  var source = arguments[i];
793
768
  for(var key in source){
@@ -798,7 +773,7 @@ function _extends$1() {
798
773
  }
799
774
  return target;
800
775
  };
801
- return _extends$1.apply(this, arguments);
776
+ return _extends.apply(this, arguments);
802
777
  }
803
778
  // Creates a virtual module for sharing dependencies
804
779
  const createVirtualShareModule = (name, ref, exports)=>`
@@ -808,6 +783,9 @@ const createVirtualShareModule = (name, ref, exports)=>`
808
783
 
809
784
  ${exports.map((e)=>e === 'default' ? `export default mfLsZJ92.default` : `export const ${e} = mfLsZJ92[${JSON.stringify(e)}];`).join('\n')}
810
785
  `;
786
+ const createVirtualRemoteModule = (name, ref)=>`
787
+ export * from ${JSON.stringify('federationRemote/' + ref)}
788
+ `;
811
789
  // Plugin to transform CommonJS modules to ESM
812
790
  const cjsToEsmPlugin = {
813
791
  name: 'cjs-to-esm',
@@ -830,7 +808,7 @@ const cjsToEsmPlugin = {
830
808
  contents: code,
831
809
  loader: 'js',
832
810
  resolveDir: path__default["default"].dirname(resolver),
833
- pluginData: _extends$1({}, args.pluginData, {
811
+ pluginData: _extends({}, args.pluginData, {
834
812
  path: resolver
835
813
  })
836
814
  };
@@ -840,7 +818,7 @@ const cjsToEsmPlugin = {
840
818
  contents: fileContent,
841
819
  loader: 'js',
842
820
  resolveDir: path__default["default"].dirname(resolver),
843
- pluginData: _extends$1({}, args.pluginData, {
821
+ pluginData: _extends({}, args.pluginData, {
844
822
  path: resolver
845
823
  })
846
824
  };
@@ -976,7 +954,7 @@ const moduleFederationPlugin = (config)=>({
976
954
  const key = entryPoint || chunkKey;
977
955
  const trimKey = key.substring(0, key.lastIndexOf('.')) || key;
978
956
  //@ts-ignore
979
- acc[trimKey] = _extends$1({}, chunkValue, {
957
+ acc[trimKey] = _extends({}, chunkValue, {
980
958
  chunk: chunkKey
981
959
  });
982
960
  return acc;
@@ -1007,171 +985,6 @@ const moduleFederationPlugin = (config)=>({
1007
985
  }
1008
986
  });
1009
987
 
1010
- function _extends() {
1011
- _extends = Object.assign || function(target) {
1012
- for(var i = 1; i < arguments.length; i++){
1013
- var source = arguments[i];
1014
- for(var key in source){
1015
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1016
- target[key] = source[key];
1017
- }
1018
- }
1019
- }
1020
- return target;
1021
- };
1022
- return _extends.apply(this, arguments);
1023
- }
1024
- function createEsBuildAdapter(config) {
1025
- if (!config.compensateExports) {
1026
- config.compensateExports = [
1027
- new RegExp('/react/')
1028
- ];
1029
- }
1030
- return async (options)=>{
1031
- const { entryPoints, external, outdir, hash, packageInfos, name, plugins = [] } = options;
1032
- // TODO: Do we need to prepare packages anymore as esbuild has evolved?
1033
- for (const entryPoint of entryPoints){
1034
- const isPkg = entryPoint.fileName.includes('node_modules');
1035
- const pkgName = isPkg ? inferePkgName(entryPoint.fileName) : '';
1036
- const tmpFolder = `node_modules/.tmp/${pkgName}`;
1037
- if (isPkg) {
1038
- await prepareNodePackage(entryPoint.fileName, external, tmpFolder, config, !!options.dev, name);
1039
- entryPoint.fileName = tmpFolder;
1040
- }
1041
- }
1042
- const ctx = await esbuild__default["default"].context({
1043
- entryPoints: entryPoints.map((ep)=>({
1044
- in: ep.fileName,
1045
- out: path__default["default"].parse(ep.outName).name
1046
- })),
1047
- write: false,
1048
- outdir,
1049
- entryNames: '[name]',
1050
- external,
1051
- loader: config.loader,
1052
- bundle: true,
1053
- splitting: true,
1054
- sourcemap: options.dev,
1055
- minify: !options.dev,
1056
- format: 'esm',
1057
- target: [
1058
- 'esnext'
1059
- ],
1060
- plugins: [
1061
- ...config.plugins,
1062
- ...plugins
1063
- ],
1064
- metafile: true,
1065
- define: {
1066
- MF_CURRENT_HOST: JSON.stringify(name)
1067
- }
1068
- });
1069
- const result = await ctx.rebuild();
1070
- result.outputFiles = result.outputFiles.reduce((acc, file, index)=>{
1071
- const sharedPack = packageInfos ? packageInfos[index] : null;
1072
- if (!sharedPack) {
1073
- acc.push(file);
1074
- return acc;
1075
- }
1076
- const fileName = path__default["default"].basename(file.path);
1077
- const filePath = path__default["default"].join(outdir, fileName);
1078
- const relative = path__default["default"].relative(process.cwd(), file.path);
1079
- const metadata = result.metafile.outputs[relative];
1080
- const replc = filePath.replace(filePath, 'mf_' + fileName);
1081
- acc.push(_extends({}, file, {
1082
- path: replc
1083
- }));
1084
- const vm = createVirtualShareModule(name, sharedPack.packageName, metadata.exports);
1085
- acc.push(_extends({}, file, {
1086
- contents: vm
1087
- }));
1088
- return acc;
1089
- }, []);
1090
- const writtenFiles = writeResult(result, outdir);
1091
- ctx.dispose();
1092
- return writtenFiles.map((fileName)=>({
1093
- fileName
1094
- }));
1095
- };
1096
- }
1097
- function writeResult(result, outdir) {
1098
- const outputFiles = result.outputFiles || [];
1099
- const writtenFiles = [];
1100
- for (const outFile of outputFiles){
1101
- const fileName = path__default["default"].basename(outFile.path);
1102
- const filePath = path__default["default"].join(outdir, fileName);
1103
- fs__default["default"].mkdirSync(path__default["default"].dirname(filePath), {
1104
- recursive: true
1105
- });
1106
- fs__default["default"].writeFileSync(filePath, outFile.contents);
1107
- writtenFiles.push(filePath);
1108
- }
1109
- return writtenFiles;
1110
- }
1111
- async function prepareNodePackage(entryPoint, external, tmpFolder, config, dev, name) {
1112
- if (config.fileReplacements) {
1113
- entryPoint = replaceEntryPoint(entryPoint, normalize(config.fileReplacements));
1114
- }
1115
- const env = dev ? 'development' : 'production';
1116
- const result = await rollup.rollup({
1117
- input: entryPoint,
1118
- plugins: [
1119
- commonjs__default["default"](),
1120
- rollupPluginNodeExternals.externals({
1121
- include: external
1122
- }),
1123
- pluginNodeResolve__default["default"](),
1124
- replace__default["default"]({
1125
- true: true,
1126
- values: {
1127
- 'process.env.NODE_ENV': `"${env}"`,
1128
- MF_CURRENT_HOST: JSON.stringify(name)
1129
- }
1130
- })
1131
- ]
1132
- });
1133
- await result.write({
1134
- format: 'esm',
1135
- file: tmpFolder,
1136
- sourcemap: dev,
1137
- exports: 'named'
1138
- });
1139
- }
1140
- function inferePkgName(entryPoint) {
1141
- return entryPoint.replace(/.*?node_modules/g, '').replace(/[^A-Za-z0-9.]/g, '_');
1142
- }
1143
- function normalize(config) {
1144
- const result = {};
1145
- for(const key in config){
1146
- if (typeof config[key] === 'string') {
1147
- result[key] = {
1148
- file: config[key]
1149
- };
1150
- } else {
1151
- result[key] = config[key];
1152
- }
1153
- }
1154
- return result;
1155
- }
1156
- function replaceEntryPoint(entryPoint, fileReplacements) {
1157
- entryPoint = entryPoint.replace(/\\/g, '/');
1158
- for(const key in fileReplacements){
1159
- entryPoint = entryPoint.replace(new RegExp(`${key}$`), fileReplacements[key].file);
1160
- }
1161
- return entryPoint;
1162
- }
1163
-
1164
- var adapter = /*#__PURE__*/Object.freeze({
1165
- __proto__: null,
1166
- createEsBuildAdapter: createEsBuildAdapter,
1167
- getExports: getExports,
1168
- resolve: resolve,
1169
- moduleFederationPlugin: moduleFederationPlugin
1170
- });
1171
-
1172
- var require$$0 = /*@__PURE__*/ getAugmentedNamespace(adapter);
1173
-
1174
- const Adapter = require$$0;
1175
- var esbuild = Adapter;
1176
-
1177
- module.exports = esbuild;
988
+ exports.createVirtualRemoteModule = createVirtualRemoteModule;
989
+ exports.createVirtualShareModule = createVirtualShareModule;
990
+ exports.moduleFederationPlugin = moduleFederationPlugin;