@module-federation/vite 1.0.0-alpha-ffc6e23 → 1.0.0-alpha-80b7215

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/lib/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  var pluginutils = require('@rollup/pluginutils');
2
- var path = require('path');
2
+ var path = require('pathe');
3
3
  var fs = require('fs');
4
4
  var estreeWalker = require('estree-walker');
5
5
  var MagicString = require('magic-string');
@@ -24,7 +24,6 @@ function _interopNamespace(e) {
24
24
  return n;
25
25
  }
26
26
 
27
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
28
27
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
29
28
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
30
29
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
@@ -134,7 +133,7 @@ function normalizeRemoteItem(key, remote) {
134
133
  function normalizeShareItem(key, shareItem) {
135
134
  var version;
136
135
  try {
137
- version = require(path__default["default"].join(key, 'package.json')).version;
136
+ version = require(path__namespace.join(key, 'package.json')).version;
138
137
  } catch (e) {
139
138
  console.log(e);
140
139
  }
@@ -227,7 +226,7 @@ var addEntry = function addEntry(_ref) {
227
226
  var _server$httpServer;
228
227
  (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', function () {
229
228
  var port = server.config.server.port;
230
- fetch("http://localhost:" + port + entryPath);
229
+ fetch(path__namespace.join("http://localhost:" + port, "" + entryPath))["catch"](function (e) {});
231
230
  });
232
231
  server.middlewares.use(function (req, res, next) {
233
232
  if (!fileName) {
@@ -241,7 +240,7 @@ var addEntry = function addEntry(_ref) {
241
240
  });
242
241
  },
243
242
  transformIndexHtml: function transformIndexHtml(c) {
244
- return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\/g, '/')) + "></script>");
243
+ return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
245
244
  }
246
245
  }, {
247
246
  name: "add-entry",
@@ -384,8 +383,8 @@ function overrideModule(options) {
384
383
  if (node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
385
384
  replaceIfMatch(node.source);
386
385
  }
387
- if (node.type === 'CallExpression' && node.callee.type === 'Import' && node.arguments.length && node.arguments[0].type === 'Literal') {
388
- replaceIfMatch(node.arguments[0]);
386
+ if (node.type === 'ImportExpression') {
387
+ replaceIfMatch(node.source);
389
388
  }
390
389
  if (node.type === 'CallExpression' && node.callee.name === 'require' && node.arguments.length && node.arguments[0].type === 'Literal') {
391
390
  replaceIfMatch(node.arguments[0]);
@@ -433,17 +432,19 @@ function generateRemoteEntry(options) {
433
432
  function wrapShare(id, shared) {
434
433
  var shareConfig = shared[id].shareConfig;
435
434
  return {
436
- code: "\n import {loadShare} from \"@module-federation/runtime\"\n const res = await loadShare(" + JSON.stringify(id) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareConfig.singleton + ",\n strictVersion: " + JSON.stringify(shareConfig.strictVersion) + ",\n requiredVersion: " + JSON.stringify(shareConfig.requiredVersion) + "\n }}})\n export default res()\n ",
435
+ code: "\n import {loadShare} from \"@module-federation/runtime\"\n const res = await loadShare(" + JSON.stringify(id) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareConfig.singleton + ",\n strictVersion: " + JSON.stringify(shareConfig.strictVersion) + ",\n requiredVersion: " + JSON.stringify(shareConfig.requiredVersion) + "\n }}})\n const exportModule = res()\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : exportModule\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
437
436
  map: null,
438
- syntheticNamedExports: 'default'
437
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
438
+ syntheticNamedExports: '__mf__dynamicExports'
439
439
  };
440
440
  }
441
441
  var con;
442
442
  function wrapRemote(id) {
443
443
  return {
444
- code: "\n import {loadRemote} from \"@module-federation/runtime\"\n export " + (command !== 'build' ? 'default' : 'const dynamicExport = ') + " await loadRemote(" + JSON.stringify(id) + ")\n ",
444
+ code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
445
445
  map: null,
446
- syntheticNamedExports: 'dynamicExport'
446
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
447
+ syntheticNamedExports: '__mf__dynamicExports'
447
448
  };
448
449
  }
449
450
  function federation(mfUserOptions) {
package/lib/index.esm.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
- import * as path from 'path';
3
- import path__default from 'path';
2
+ import * as path from 'pathe';
4
3
  import * as fs from 'fs';
5
4
  import { walk } from 'estree-walker';
6
5
  import MagicString from 'magic-string';
@@ -110,7 +109,7 @@ function normalizeRemoteItem(key, remote) {
110
109
  function normalizeShareItem(key, shareItem) {
111
110
  var version;
112
111
  try {
113
- version = require(path__default.join(key, 'package.json')).version;
112
+ version = require(path.join(key, 'package.json')).version;
114
113
  } catch (e) {
115
114
  console.log(e);
116
115
  }
@@ -203,7 +202,7 @@ var addEntry = function addEntry(_ref) {
203
202
  var _server$httpServer;
204
203
  (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', function () {
205
204
  var port = server.config.server.port;
206
- fetch("http://localhost:" + port + entryPath);
205
+ fetch(path.join("http://localhost:" + port, "" + entryPath))["catch"](function (e) {});
207
206
  });
208
207
  server.middlewares.use(function (req, res, next) {
209
208
  if (!fileName) {
@@ -217,7 +216,7 @@ var addEntry = function addEntry(_ref) {
217
216
  });
218
217
  },
219
218
  transformIndexHtml: function transformIndexHtml(c) {
220
- return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\/g, '/')) + "></script>");
219
+ return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
221
220
  }
222
221
  }, {
223
222
  name: "add-entry",
@@ -360,8 +359,8 @@ function overrideModule(options) {
360
359
  if (node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
361
360
  replaceIfMatch(node.source);
362
361
  }
363
- if (node.type === 'CallExpression' && node.callee.type === 'Import' && node.arguments.length && node.arguments[0].type === 'Literal') {
364
- replaceIfMatch(node.arguments[0]);
362
+ if (node.type === 'ImportExpression') {
363
+ replaceIfMatch(node.source);
365
364
  }
366
365
  if (node.type === 'CallExpression' && node.callee.name === 'require' && node.arguments.length && node.arguments[0].type === 'Literal') {
367
366
  replaceIfMatch(node.arguments[0]);
@@ -409,17 +408,19 @@ function generateRemoteEntry(options) {
409
408
  function wrapShare(id, shared) {
410
409
  var shareConfig = shared[id].shareConfig;
411
410
  return {
412
- code: "\n import {loadShare} from \"@module-federation/runtime\"\n const res = await loadShare(" + JSON.stringify(id) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareConfig.singleton + ",\n strictVersion: " + JSON.stringify(shareConfig.strictVersion) + ",\n requiredVersion: " + JSON.stringify(shareConfig.requiredVersion) + "\n }}})\n export default res()\n ",
411
+ code: "\n import {loadShare} from \"@module-federation/runtime\"\n const res = await loadShare(" + JSON.stringify(id) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareConfig.singleton + ",\n strictVersion: " + JSON.stringify(shareConfig.strictVersion) + ",\n requiredVersion: " + JSON.stringify(shareConfig.requiredVersion) + "\n }}})\n const exportModule = res()\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : exportModule\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
413
412
  map: null,
414
- syntheticNamedExports: 'default'
413
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
414
+ syntheticNamedExports: '__mf__dynamicExports'
415
415
  };
416
416
  }
417
417
  var con;
418
418
  function wrapRemote(id) {
419
419
  return {
420
- code: "\n import {loadRemote} from \"@module-federation/runtime\"\n export " + (command !== 'build' ? 'default' : 'const dynamicExport = ') + " await loadRemote(" + JSON.stringify(id) + ")\n ",
420
+ code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
421
421
  map: null,
422
- syntheticNamedExports: 'dynamicExport'
422
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
423
+ syntheticNamedExports: '__mf__dynamicExports'
423
424
  };
424
425
  }
425
426
  function federation(mfUserOptions) {
@@ -1,6 +1,5 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
- import * as path from 'path';
3
- import path__default from 'path';
2
+ import * as path from 'pathe';
4
3
  import * as fs from 'fs';
5
4
  import { walk } from 'estree-walker';
6
5
  import MagicString from 'magic-string';
@@ -108,7 +107,7 @@ function normalizeRemoteItem(key, remote) {
108
107
  function normalizeShareItem(key, shareItem) {
109
108
  let version;
110
109
  try {
111
- version = require(path__default.join(key, 'package.json')).version;
110
+ version = require(path.join(key, 'package.json')).version;
112
111
  } catch (e) {
113
112
  console.log(e);
114
113
  }
@@ -209,7 +208,7 @@ const addEntry = ({
209
208
  const {
210
209
  port
211
210
  } = server.config.server;
212
- fetch(`http://localhost:${port}${entryPath}`);
211
+ fetch(path.join(`http://localhost:${port}`, `${entryPath}`)).catch(e => {});
213
212
  });
214
213
  server.middlewares.use((req, res, next) => {
215
214
  if (!fileName) {
@@ -223,7 +222,7 @@ const addEntry = ({
223
222
  });
224
223
  },
225
224
  transformIndexHtml(c) {
226
- return c.replace('<head>', `<head><script type="module" src=${JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\/g, '/'))}></script>`);
225
+ return c.replace('<head>', `<head><script type="module" src=${JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/'))}></script>`);
227
226
  }
228
227
  }, {
229
228
  name: "add-entry",
@@ -333,8 +332,8 @@ function overrideModule(options = {}) {
333
332
  if (node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
334
333
  replaceIfMatch(node.source);
335
334
  }
336
- if (node.type === 'CallExpression' && node.callee.type === 'Import' && node.arguments.length && node.arguments[0].type === 'Literal') {
337
- replaceIfMatch(node.arguments[0]);
335
+ if (node.type === 'ImportExpression') {
336
+ replaceIfMatch(node.source);
338
337
  }
339
338
  if (node.type === 'CallExpression' && node.callee.name === 'require' && node.arguments.length && node.arguments[0].type === 'Literal') {
340
339
  replaceIfMatch(node.arguments[0]);
@@ -458,10 +457,18 @@ function wrapShare(id, shared) {
458
457
  strictVersion: ${JSON.stringify(shareConfig.strictVersion)},
459
458
  requiredVersion: ${JSON.stringify(shareConfig.requiredVersion)}
460
459
  }}})
461
- export default res()
460
+ const exportModule = res()
461
+ ${command === "build" && `
462
+ export default 'default' in (exportModule || {}) ? exportModule.default : exportModule
463
+ export const __mf__dynamicExports = exportModule
464
+ ` || ""}
465
+ ${command !== "build" && `
466
+ export default exportModule
467
+ ` || ""}
462
468
  `,
463
469
  map: null,
464
- syntheticNamedExports: 'default'
470
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
471
+ syntheticNamedExports: '__mf__dynamicExports'
465
472
  };
466
473
  }
467
474
  let con;
@@ -469,10 +476,18 @@ function wrapRemote(id) {
469
476
  return {
470
477
  code: `
471
478
  import {loadRemote} from "@module-federation/runtime"
472
- export ${command !== 'build' ? 'default' : 'const dynamicExport = '} await loadRemote(${JSON.stringify(id)})
479
+ const exportModule = await loadRemote(${JSON.stringify(id)})
480
+ ${command === "build" && `
481
+ export default 'default' in (exportModule || {}) ? exportModule.default : undefined
482
+ export const __mf__dynamicExports = exportModule
483
+ ` || ""}
484
+ ${command !== "build" && `
485
+ export default exportModule
486
+ ` || ""}
473
487
  `,
474
488
  map: null,
475
- syntheticNamedExports: 'dynamicExport'
489
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
490
+ syntheticNamedExports: '__mf__dynamicExports'
476
491
  };
477
492
  }
478
493
  function federation(mfUserOptions) {
package/lib/index.umd.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@rollup/pluginutils'), require('path'), require('fs'), require('estree-walker'), require('magic-string')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@rollup/pluginutils', 'path', 'fs', 'estree-walker', 'magic-string'], factory) :
4
- (global = global || self, factory(global.vite = {}, global.pluginutils, global.path, global.fs, global.estreeWalker, global.magicString));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@rollup/pluginutils'), require('pathe'), require('fs'), require('estree-walker'), require('magic-string')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@rollup/pluginutils', 'pathe', 'fs', 'estree-walker', 'magic-string'], factory) :
4
+ (global = global || self, factory(global.vite = {}, global.pluginutils, global.pathe, global.fs, global.estreeWalker, global.magicString));
5
5
  })(this, (function (exports, pluginutils, path, fs, estreeWalker, MagicString) {
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
@@ -23,7 +23,6 @@
23
23
  return n;
24
24
  }
25
25
 
26
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
27
26
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
28
27
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
29
28
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
@@ -133,7 +132,7 @@
133
132
  function normalizeShareItem(key, shareItem) {
134
133
  var version;
135
134
  try {
136
- version = require(path__default["default"].join(key, 'package.json')).version;
135
+ version = require(path__namespace.join(key, 'package.json')).version;
137
136
  } catch (e) {
138
137
  console.log(e);
139
138
  }
@@ -226,7 +225,7 @@
226
225
  var _server$httpServer;
227
226
  (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', function () {
228
227
  var port = server.config.server.port;
229
- fetch("http://localhost:" + port + entryPath);
228
+ fetch(path__namespace.join("http://localhost:" + port, "" + entryPath))["catch"](function (e) {});
230
229
  });
231
230
  server.middlewares.use(function (req, res, next) {
232
231
  if (!fileName) {
@@ -240,7 +239,7 @@
240
239
  });
241
240
  },
242
241
  transformIndexHtml: function transformIndexHtml(c) {
243
- return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\/g, '/')) + "></script>");
242
+ return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(entryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
244
243
  }
245
244
  }, {
246
245
  name: "add-entry",
@@ -383,8 +382,8 @@
383
382
  if (node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
384
383
  replaceIfMatch(node.source);
385
384
  }
386
- if (node.type === 'CallExpression' && node.callee.type === 'Import' && node.arguments.length && node.arguments[0].type === 'Literal') {
387
- replaceIfMatch(node.arguments[0]);
385
+ if (node.type === 'ImportExpression') {
386
+ replaceIfMatch(node.source);
388
387
  }
389
388
  if (node.type === 'CallExpression' && node.callee.name === 'require' && node.arguments.length && node.arguments[0].type === 'Literal') {
390
389
  replaceIfMatch(node.arguments[0]);
@@ -432,17 +431,19 @@
432
431
  function wrapShare(id, shared) {
433
432
  var shareConfig = shared[id].shareConfig;
434
433
  return {
435
- code: "\n import {loadShare} from \"@module-federation/runtime\"\n const res = await loadShare(" + JSON.stringify(id) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareConfig.singleton + ",\n strictVersion: " + JSON.stringify(shareConfig.strictVersion) + ",\n requiredVersion: " + JSON.stringify(shareConfig.requiredVersion) + "\n }}})\n export default res()\n ",
434
+ code: "\n import {loadShare} from \"@module-federation/runtime\"\n const res = await loadShare(" + JSON.stringify(id) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareConfig.singleton + ",\n strictVersion: " + JSON.stringify(shareConfig.strictVersion) + ",\n requiredVersion: " + JSON.stringify(shareConfig.requiredVersion) + "\n }}})\n const exportModule = res()\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : exportModule\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
436
435
  map: null,
437
- syntheticNamedExports: 'default'
436
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
437
+ syntheticNamedExports: '__mf__dynamicExports'
438
438
  };
439
439
  }
440
440
  var con;
441
441
  function wrapRemote(id) {
442
442
  return {
443
- code: "\n import {loadRemote} from \"@module-federation/runtime\"\n export " + (command !== 'build' ? 'default' : 'const dynamicExport = ') + " await loadRemote(" + JSON.stringify(id) + ")\n ",
443
+ code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
444
444
  map: null,
445
- syntheticNamedExports: 'dynamicExport'
445
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
446
+ syntheticNamedExports: '__mf__dynamicExports'
446
447
  };
447
448
  }
448
449
  function federation(mfUserOptions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.0.0-alpha-ffc6e23",
3
+ "version": "1.0.0-alpha-80b7215",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",
@@ -40,7 +40,8 @@
40
40
  "@rollup/pluginutils": "^5.1.0",
41
41
  "an-empty-js-file": "1.0.0",
42
42
  "estree-walker": "^2",
43
- "magic-string": "^0.30.10"
43
+ "magic-string": "^0.30.10",
44
+ "pathe": "^1.1.2"
44
45
  },
45
46
  "devDependencies": {
46
47
  "husky": "^8.0.3",