@module-federation/sdk 0.6.7 → 0.6.8

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/dist/index.cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var polyfills = require('./polyfills.cjs.js');
6
4
 
7
5
  const FederationModuleManifest = 'federation-manifest.json';
@@ -71,6 +69,13 @@ const getProcessEnv = function() {
71
69
  };
72
70
 
73
71
  const DEBUG_LOG = '[ FEDERATION DEBUG ]';
72
+ function safeToString$1(info) {
73
+ try {
74
+ return JSON.stringify(info, null, 2);
75
+ } catch (e) {
76
+ return '';
77
+ }
78
+ }
74
79
  function safeGetLocalStorageItem() {
75
80
  try {
76
81
  if (typeof window !== 'undefined' && window.localStorage) {
@@ -84,7 +89,7 @@ function safeGetLocalStorageItem() {
84
89
  let Logger = class Logger {
85
90
  info(msg, info) {
86
91
  if (this.enable) {
87
- const argsToString = safeToString(info) || '';
92
+ const argsToString = safeToString$1(info) || '';
88
93
  if (isBrowserEnv()) {
89
94
  console.info(`%c ${this.identifier}: ${msg} ${argsToString}`, 'color:#3300CC');
90
95
  } else {
@@ -162,7 +167,7 @@ const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
162
167
  }
163
168
  };
164
169
  const logger = new Logger();
165
- const composeKeyWithSeparator = function(...args) {
170
+ const composeKeyWithSeparator = function(...args) {
166
171
  if (!args.length) {
167
172
  return '';
168
173
  }
@@ -176,7 +181,7 @@ const composeKeyWithSeparator = function(...args) {
176
181
  return `${sum}${SEPARATOR}${cur}`;
177
182
  }, '');
178
183
  };
179
- const encodeName = function(name, prefix = '', withExt = false) {
184
+ const encodeName = function(name, prefix = '', withExt = false) {
180
185
  try {
181
186
  const ext = withExt ? '.js' : '';
182
187
  return `${prefix}${name.replace(new RegExp(`${NameTransformSymbol.AT}`, 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, 'g'), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
@@ -184,7 +189,7 @@ const encodeName = function(name, prefix = '', withExt = false) {
184
189
  throw err;
185
190
  }
186
191
  };
187
- const decodeName = function(name, prefix, withExt) {
192
+ const decodeName = function(name, prefix, withExt) {
188
193
  try {
189
194
  let decodedName = name;
190
195
  if (prefix) {
@@ -202,7 +207,7 @@ const decodeName = function(name, prefix, withExt) {
202
207
  throw err;
203
208
  }
204
209
  };
205
- const generateExposeFilename = (exposeName, withExt)=>{
210
+ const generateExposeFilename = (exposeName, withExt)=>{
206
211
  if (!exposeName) {
207
212
  return '';
208
213
  }
@@ -215,7 +220,7 @@ const generateExposeFilename = (exposeName, withExt)=>{
215
220
  }
216
221
  return encodeName(expose, '__federation_expose_', withExt);
217
222
  };
218
- const generateShareFilename = (pkgName, withExt)=>{
223
+ const generateShareFilename = (pkgName, withExt)=>{
219
224
  if (!pkgName) {
220
225
  return '';
221
226
  }
@@ -383,7 +388,7 @@ function generateSnapshotFromManifest(manifest, options = {}) {
383
388
  if (ssrRemoteEntry) {
384
389
  const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
385
390
  remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
386
- remoteSnapshot.ssrRemoteEntryType = 'commonjs-module';
391
+ remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || 'commonjs-module';
387
392
  }
388
393
  return remoteSnapshot;
389
394
  }
@@ -430,8 +435,9 @@ function createScript(info) {
430
435
  }
431
436
  }
432
437
  if (!script) {
438
+ const attrs = info.attrs;
433
439
  script = document.createElement('script');
434
- script.type = 'text/javascript';
440
+ script.type = (attrs == null ? void 0 : attrs['type']) === 'module' ? 'module' : 'text/javascript';
435
441
  script.src = info.url;
436
442
  let createScriptRes = undefined;
437
443
  if (info.createScriptHook) {
@@ -447,7 +453,6 @@ function createScript(info) {
447
453
  }
448
454
  }
449
455
  }
450
- const attrs = info.attrs;
451
456
  if (attrs && !createScriptRes) {
452
457
  Object.keys(attrs).forEach((name)=>{
453
458
  if (script) {
@@ -638,7 +643,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
638
643
  };
639
644
  const handleScriptFetch = async (f, urlObj)=>{
640
645
  try {
641
- var _vm_constants;
646
+ var //@ts-ignore
647
+ _vm_constants;
642
648
  const res = await f(urlObj.href);
643
649
  const data = await res.text();
644
650
  const [path, vm] = await Promise.all([
@@ -670,7 +676,20 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
670
676
  cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
671
677
  }
672
678
  };
673
- getFetch().then((f)=>handleScriptFetch(f, urlObj)).catch((err)=>{
679
+ getFetch().then(async (f)=>{
680
+ if ((attrs == null ? void 0 : attrs['type']) === 'esm' || (attrs == null ? void 0 : attrs['type']) === 'module') {
681
+ return loadModule(urlObj.href, {
682
+ fetch: f,
683
+ vm: await importNodeModule('vm')
684
+ }).then(async (module)=>{
685
+ await module.evaluate();
686
+ cb(undefined, module.namespace);
687
+ }).catch((e)=>{
688
+ cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
689
+ });
690
+ }
691
+ handleScriptFetch(f, urlObj);
692
+ }).catch((err)=>{
674
693
  cb(err);
675
694
  });
676
695
  }
@@ -688,6 +707,24 @@ function loadScriptNode(url, info) {
688
707
  }, info.attrs, info.createScriptHook);
689
708
  });
690
709
  }
710
+ async function loadModule(url, options) {
711
+ const { fetch: fetch1, vm } = options;
712
+ const response = await fetch1(url);
713
+ const code = await response.text();
714
+ const module = new vm.SourceTextModule(code, {
715
+ // @ts-ignore
716
+ importModuleDynamically: async (specifier, script)=>{
717
+ const resolvedUrl = new URL(specifier, url).href;
718
+ return loadModule(resolvedUrl, options);
719
+ }
720
+ });
721
+ await module.link(async (specifier)=>{
722
+ const resolvedUrl = new URL(specifier, url).href;
723
+ const module = await loadModule(resolvedUrl, options);
724
+ return module;
725
+ });
726
+ return module;
727
+ }
691
728
 
692
729
  function normalizeOptions(enableDefault, defaultOptions, key) {
693
730
  return function(options) {
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/dist/index.esm.js CHANGED
@@ -67,6 +67,13 @@ const getProcessEnv = function() {
67
67
  };
68
68
 
69
69
  const DEBUG_LOG = '[ FEDERATION DEBUG ]';
70
+ function safeToString$1(info) {
71
+ try {
72
+ return JSON.stringify(info, null, 2);
73
+ } catch (e) {
74
+ return '';
75
+ }
76
+ }
70
77
  function safeGetLocalStorageItem() {
71
78
  try {
72
79
  if (typeof window !== 'undefined' && window.localStorage) {
@@ -80,7 +87,7 @@ function safeGetLocalStorageItem() {
80
87
  let Logger = class Logger {
81
88
  info(msg, info) {
82
89
  if (this.enable) {
83
- const argsToString = safeToString(info) || '';
90
+ const argsToString = safeToString$1(info) || '';
84
91
  if (isBrowserEnv()) {
85
92
  console.info(`%c ${this.identifier}: ${msg} ${argsToString}`, 'color:#3300CC');
86
93
  } else {
@@ -158,7 +165,7 @@ const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
158
165
  }
159
166
  };
160
167
  const logger = new Logger();
161
- const composeKeyWithSeparator = function(...args) {
168
+ const composeKeyWithSeparator = function(...args) {
162
169
  if (!args.length) {
163
170
  return '';
164
171
  }
@@ -172,7 +179,7 @@ const composeKeyWithSeparator = function(...args) {
172
179
  return `${sum}${SEPARATOR}${cur}`;
173
180
  }, '');
174
181
  };
175
- const encodeName = function(name, prefix = '', withExt = false) {
182
+ const encodeName = function(name, prefix = '', withExt = false) {
176
183
  try {
177
184
  const ext = withExt ? '.js' : '';
178
185
  return `${prefix}${name.replace(new RegExp(`${NameTransformSymbol.AT}`, 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, 'g'), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
@@ -180,7 +187,7 @@ const encodeName = function(name, prefix = '', withExt = false) {
180
187
  throw err;
181
188
  }
182
189
  };
183
- const decodeName = function(name, prefix, withExt) {
190
+ const decodeName = function(name, prefix, withExt) {
184
191
  try {
185
192
  let decodedName = name;
186
193
  if (prefix) {
@@ -198,7 +205,7 @@ const decodeName = function(name, prefix, withExt) {
198
205
  throw err;
199
206
  }
200
207
  };
201
- const generateExposeFilename = (exposeName, withExt)=>{
208
+ const generateExposeFilename = (exposeName, withExt)=>{
202
209
  if (!exposeName) {
203
210
  return '';
204
211
  }
@@ -211,7 +218,7 @@ const generateExposeFilename = (exposeName, withExt)=>{
211
218
  }
212
219
  return encodeName(expose, '__federation_expose_', withExt);
213
220
  };
214
- const generateShareFilename = (pkgName, withExt)=>{
221
+ const generateShareFilename = (pkgName, withExt)=>{
215
222
  if (!pkgName) {
216
223
  return '';
217
224
  }
@@ -379,7 +386,7 @@ function generateSnapshotFromManifest(manifest, options = {}) {
379
386
  if (ssrRemoteEntry) {
380
387
  const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
381
388
  remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
382
- remoteSnapshot.ssrRemoteEntryType = 'commonjs-module';
389
+ remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || 'commonjs-module';
383
390
  }
384
391
  return remoteSnapshot;
385
392
  }
@@ -426,8 +433,9 @@ function createScript(info) {
426
433
  }
427
434
  }
428
435
  if (!script) {
436
+ const attrs = info.attrs;
429
437
  script = document.createElement('script');
430
- script.type = 'text/javascript';
438
+ script.type = (attrs == null ? void 0 : attrs['type']) === 'module' ? 'module' : 'text/javascript';
431
439
  script.src = info.url;
432
440
  let createScriptRes = undefined;
433
441
  if (info.createScriptHook) {
@@ -443,7 +451,6 @@ function createScript(info) {
443
451
  }
444
452
  }
445
453
  }
446
- const attrs = info.attrs;
447
454
  if (attrs && !createScriptRes) {
448
455
  Object.keys(attrs).forEach((name)=>{
449
456
  if (script) {
@@ -634,7 +641,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
634
641
  };
635
642
  const handleScriptFetch = async (f, urlObj)=>{
636
643
  try {
637
- var _vm_constants;
644
+ var //@ts-ignore
645
+ _vm_constants;
638
646
  const res = await f(urlObj.href);
639
647
  const data = await res.text();
640
648
  const [path, vm] = await Promise.all([
@@ -666,7 +674,20 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
666
674
  cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
667
675
  }
668
676
  };
669
- getFetch().then((f)=>handleScriptFetch(f, urlObj)).catch((err)=>{
677
+ getFetch().then(async (f)=>{
678
+ if ((attrs == null ? void 0 : attrs['type']) === 'esm' || (attrs == null ? void 0 : attrs['type']) === 'module') {
679
+ return loadModule(urlObj.href, {
680
+ fetch: f,
681
+ vm: await importNodeModule('vm')
682
+ }).then(async (module)=>{
683
+ await module.evaluate();
684
+ cb(undefined, module.namespace);
685
+ }).catch((e)=>{
686
+ cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
687
+ });
688
+ }
689
+ handleScriptFetch(f, urlObj);
690
+ }).catch((err)=>{
670
691
  cb(err);
671
692
  });
672
693
  }
@@ -684,6 +705,24 @@ function loadScriptNode(url, info) {
684
705
  }, info.attrs, info.createScriptHook);
685
706
  });
686
707
  }
708
+ async function loadModule(url, options) {
709
+ const { fetch: fetch1, vm } = options;
710
+ const response = await fetch1(url);
711
+ const code = await response.text();
712
+ const module = new vm.SourceTextModule(code, {
713
+ // @ts-ignore
714
+ importModuleDynamically: async (specifier, script)=>{
715
+ const resolvedUrl = new URL(specifier, url).href;
716
+ return loadModule(resolvedUrl, options);
717
+ }
718
+ });
719
+ await module.link(async (specifier)=>{
720
+ const resolvedUrl = new URL(specifier, url).href;
721
+ const module = await loadModule(resolvedUrl, options);
722
+ return module;
723
+ });
724
+ return module;
725
+ }
687
726
 
688
727
  function normalizeOptions(enableDefault, defaultOptions, key) {
689
728
  return function(options) {
@@ -1,13 +1,7 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var path = require('path');
6
4
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
10
-
11
5
  function getWebpackPath(compiler, options = {
12
6
  framework: 'other'
13
7
  }) {
@@ -39,7 +33,7 @@ const normalizeWebpackPath = (fullPath)=>{
39
33
  return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
40
34
  }
41
35
  if (process.env['FEDERATION_WEBPACK_PATH']) {
42
- return path__default["default"].resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
36
+ return path.resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
43
37
  }
44
38
  return fullPath;
45
39
  };
@@ -0,0 +1 @@
1
+ export * from "./src/normalize-webpack-path";
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
@@ -41,4 +41,4 @@
41
41
  ]
42
42
  }
43
43
  }
44
- }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [