@umijs/mfsu 4.0.0-beta.8 → 4.0.0-canary-20240513.3

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.
Files changed (100) hide show
  1. package/compiled/is-absolute-url/LICENSE +9 -0
  2. package/compiled/is-absolute-url/index.d.ts +20 -0
  3. package/compiled/is-absolute-url/index.js +1 -0
  4. package/compiled/is-absolute-url/package.json +1 -0
  5. package/compiled/mrmime/package.json +1 -1
  6. package/compiled/webpack-virtual-modules/index.js +1 -1
  7. package/compiled/webpack-virtual-modules/package.json +1 -1
  8. package/dist/babelPlugins/awaitImport/MFImport.d.ts +24 -0
  9. package/dist/babelPlugins/awaitImport/MFImport.js +66 -0
  10. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
  11. package/dist/babelPlugins/awaitImport/awaitImport.js +111 -112
  12. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +3 -1
  13. package/dist/babelPlugins/awaitImport/checkMatch.js +166 -109
  14. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +2 -2
  15. package/dist/babelPlugins/awaitImport/getAliasedPath.js +44 -33
  16. package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
  17. package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
  18. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +62 -47
  19. package/dist/constants.d.ts +1 -0
  20. package/dist/constants.js +50 -10
  21. package/dist/dep/dep.d.ts +11 -4
  22. package/dist/dep/dep.js +118 -80
  23. package/dist/dep/getCJSExports.js +83 -47
  24. package/dist/dep/getExposeFromContent.d.ts +0 -1
  25. package/dist/dep/getExposeFromContent.js +99 -74
  26. package/dist/dep/getModuleExports.js +58 -43
  27. package/dist/depBuilder/depBuilder.d.ts +6 -2
  28. package/dist/depBuilder/depBuilder.js +222 -158
  29. package/dist/depBuilder/getESBuildEntry.d.ts +1 -1
  30. package/dist/depBuilder/getESBuildEntry.js +50 -14
  31. package/dist/depInfo.d.ts +20 -6
  32. package/dist/depInfo.js +90 -39
  33. package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
  34. package/dist/esbuildHandlers/autoCssModules.js +48 -0
  35. package/dist/esbuildHandlers/awaitImport/index.d.ts +15 -0
  36. package/dist/esbuildHandlers/awaitImport/index.js +86 -0
  37. package/dist/index.d.ts +3 -2
  38. package/dist/index.js +35 -13
  39. package/dist/loader/esbuild.d.ts +5 -0
  40. package/dist/loader/esbuild.js +79 -0
  41. package/dist/mfsu/mfsu.d.ts +69 -0
  42. package/dist/mfsu/mfsu.js +319 -0
  43. package/dist/mfsu/strategyCompileTime.d.ts +20 -0
  44. package/dist/mfsu/strategyCompileTime.js +142 -0
  45. package/dist/mfsu/strategyStaticAnalyze.d.ts +24 -0
  46. package/dist/mfsu/strategyStaticAnalyze.js +196 -0
  47. package/dist/moduleGraph.d.ts +6 -9
  48. package/dist/moduleGraph.js +228 -178
  49. package/dist/staticDepInfo/importParser.d.ts +4 -0
  50. package/dist/staticDepInfo/importParser.js +28 -0
  51. package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +15 -0
  52. package/dist/staticDepInfo/simulations/babel-plugin-import.js +118 -0
  53. package/dist/staticDepInfo/staticDepInfo.d.ts +61 -0
  54. package/dist/staticDepInfo/staticDepInfo.js +274 -0
  55. package/dist/types.d.ts +12 -0
  56. package/dist/types.js +33 -8
  57. package/dist/utils/makeArray.js +29 -5
  58. package/dist/utils/resolveUtils.d.ts +1 -0
  59. package/dist/utils/resolveUtils.js +104 -0
  60. package/dist/utils/trimFileContent.js +29 -5
  61. package/dist/utils/webpackUtils.d.ts +3 -0
  62. package/dist/utils/webpackUtils.js +80 -0
  63. package/dist/webpackPlugins/buildDepPlugin.d.ts +4 -3
  64. package/dist/webpackPlugins/buildDepPlugin.js +61 -17
  65. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +1 -1
  66. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +47 -19
  67. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +55 -27
  68. package/dist/webpackPlugins/writeCachePlugin.js +45 -15
  69. package/package.json +32 -28
  70. package/vendors/importParser/_importParser.js +683 -0
  71. package/vendors/importParser/importParser.jison +105 -0
  72. package/dist/babelPlugins/autoExport.d.ts +0 -7
  73. package/dist/babelPlugins/autoExport.d.ts.map +0 -1
  74. package/dist/babelPlugins/autoExport.js +0 -61
  75. package/dist/babelPlugins/awaitImport/awaitImport.d.ts.map +0 -1
  76. package/dist/babelPlugins/awaitImport/checkMatch.d.ts.map +0 -1
  77. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts.map +0 -1
  78. package/dist/babelPlugins/awaitImport/getRealPath.d.ts.map +0 -1
  79. package/dist/babelPlugins/awaitImport/isExternals.d.ts.map +0 -1
  80. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts.map +0 -1
  81. package/dist/constants.d.ts.map +0 -1
  82. package/dist/dep/dep.d.ts.map +0 -1
  83. package/dist/dep/getCJSExports.d.ts.map +0 -1
  84. package/dist/dep/getExposeFromContent.d.ts.map +0 -1
  85. package/dist/dep/getModuleExports.d.ts.map +0 -1
  86. package/dist/depBuilder/depBuilder.d.ts.map +0 -1
  87. package/dist/depBuilder/getESBuildEntry.d.ts.map +0 -1
  88. package/dist/depInfo.d.ts.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/mfsu.d.ts +0 -55
  91. package/dist/mfsu.d.ts.map +0 -1
  92. package/dist/mfsu.js +0 -173
  93. package/dist/moduleGraph.d.ts.map +0 -1
  94. package/dist/types.d.ts.map +0 -1
  95. package/dist/utils/makeArray.d.ts.map +0 -1
  96. package/dist/utils/trimFileContent.d.ts.map +0 -1
  97. package/dist/webpackPlugins/buildDepPlugin.d.ts.map +0 -1
  98. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts.map +0 -1
  99. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts.map +0 -1
  100. package/dist/webpackPlugins/writeCachePlugin.d.ts.map +0 -1
@@ -1,45 +1,60 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
10
8
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getModuleExports = void 0;
13
- const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
14
- const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
15
- const path_1 = require("path");
16
- const getCJSExports_1 = require("./getCJSExports");
17
- function getModuleExports({ content, filePath, }) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- // Support tsx and jsx
20
- if (filePath && /\.(tsx|jsx)$/.test(filePath)) {
21
- content = (yield (0, esbuild_1.transform)(content, {
22
- sourcemap: false,
23
- sourcefile: filePath,
24
- format: 'esm',
25
- target: 'es6',
26
- loader: (0, path_1.extname)(filePath).slice(1),
27
- })).code;
28
- }
29
- yield es_module_lexer_1.init;
30
- const [imports, exports] = (0, es_module_lexer_1.parse)(content);
31
- let isCJS = !imports.length && !exports.length;
32
- let cjsEsmExports = null;
33
- if (isCJS) {
34
- cjsEsmExports = (0, getCJSExports_1.getCJSExports)({ content });
35
- if (cjsEsmExports.includes('__esModule')) {
36
- isCJS = false;
37
- }
38
- }
39
- return {
40
- exports: cjsEsmExports || exports,
41
- isCJS,
42
- };
43
- });
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/dep/getModuleExports.ts
20
+ var getModuleExports_exports = {};
21
+ __export(getModuleExports_exports, {
22
+ getModuleExports: () => getModuleExports
23
+ });
24
+ module.exports = __toCommonJS(getModuleExports_exports);
25
+ var import_es_module_lexer = require("@umijs/bundler-utils/compiled/es-module-lexer");
26
+ var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
27
+ var import_path = require("path");
28
+ var import_getCJSExports = require("./getCJSExports");
29
+ async function getModuleExports({
30
+ content,
31
+ filePath
32
+ }) {
33
+ if (filePath && /\.(tsx|jsx)$/.test(filePath)) {
34
+ content = (await (0, import_esbuild.transform)(content, {
35
+ sourcemap: false,
36
+ sourcefile: filePath,
37
+ format: "esm",
38
+ target: "es6",
39
+ loader: (0, import_path.extname)(filePath).slice(1)
40
+ })).code;
41
+ }
42
+ await import_es_module_lexer.init;
43
+ const [imports, exports] = (0, import_es_module_lexer.parse)(content);
44
+ let isCJS = !imports.length && !exports.length;
45
+ let cjsEsmExports = null;
46
+ if (isCJS) {
47
+ cjsEsmExports = (0, import_getCJSExports.getCJSExports)({ content });
48
+ if (cjsEsmExports.includes("__esModule")) {
49
+ isCJS = false;
50
+ }
51
+ }
52
+ return {
53
+ exports: cjsEsmExports || exports,
54
+ isCJS
55
+ };
44
56
  }
45
- exports.getModuleExports = getModuleExports;
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ getModuleExports
60
+ });
@@ -1,5 +1,5 @@
1
1
  import { Dep } from '../dep/dep';
2
- import { MFSU } from '../mfsu';
2
+ import { MFSU } from '../mfsu/mfsu';
3
3
  interface IOpts {
4
4
  mfsu: MFSU;
5
5
  }
@@ -16,8 +16,13 @@ export declare class DepBuilder {
16
16
  onBuildComplete: Function;
17
17
  deps: Dep[];
18
18
  }): Promise<void>;
19
+ buildWithWorker(opts: {
20
+ onBuildComplete: Function;
21
+ deps: Dep[];
22
+ }): Promise<void>;
19
23
  build(opts: {
20
24
  deps: Dep[];
25
+ useWorker: boolean;
21
26
  }): Promise<void>;
22
27
  onBuildComplete(fn: Function): void;
23
28
  writeMFFiles(opts: {
@@ -28,4 +33,3 @@ export declare class DepBuilder {
28
33
  }): import("webpack").Configuration;
29
34
  }
30
35
  export {};
31
- //# sourceMappingURL=depBuilder.d.ts.map
@@ -1,165 +1,229 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
10
8
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DepBuilder = void 0;
13
- const bundler_esbuild_1 = require("@umijs/bundler-esbuild");
14
- const utils_1 = require("@umijs/utils");
15
- const fs_1 = require("fs");
16
- const path_1 = require("path");
17
- const constants_1 = require("../constants");
18
- const depChunkIdPrefixPlugin_1 = require("../webpackPlugins/depChunkIdPrefixPlugin");
19
- const stripSourceMapUrlPlugin_1 = require("../webpackPlugins/stripSourceMapUrlPlugin");
20
- const getESBuildEntry_1 = require("./getESBuildEntry");
21
- class DepBuilder {
22
- constructor(opts) {
23
- this.completeFns = [];
24
- this.isBuilding = false;
25
- this.opts = opts;
26
- }
27
- buildWithWebpack(opts) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const config = this.getWebpackConfig({ deps: opts.deps });
30
- return new Promise((resolve, reject) => {
31
- const compiler = this.opts.mfsu.opts.implementor(config);
32
- compiler.run((err, stats) => {
33
- opts.onBuildComplete();
34
- if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
35
- if (err) {
36
- reject(err);
37
- }
38
- if (stats) {
39
- const errorMsg = stats.toString('errors-only');
40
- // console.error(errorMsg);
41
- reject(new Error(errorMsg));
42
- }
43
- }
44
- else {
45
- resolve(stats);
46
- }
47
- compiler.close(() => { });
48
- });
49
- });
50
- });
51
- }
52
- // TODO: support watch and rebuild
53
- buildWithESBuild(opts) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const entryContent = (0, getESBuildEntry_1.getESBuildEntry)({ deps: opts.deps });
56
- const ENTRY_FILE = 'esbuild-entry.js';
57
- const tmpDir = this.opts.mfsu.opts.tmpBase;
58
- const entryPath = (0, path_1.join)(tmpDir, ENTRY_FILE);
59
- (0, fs_1.writeFileSync)(entryPath, entryContent, 'utf-8');
60
- const date = new Date().getTime();
61
- yield (0, bundler_esbuild_1.build)({
62
- cwd: this.opts.mfsu.opts.cwd,
63
- entry: {
64
- [`${constants_1.MF_VA_PREFIX}remoteEntry`]: entryPath,
65
- },
66
- config: {
67
- outputPath: tmpDir,
68
- alias: this.opts.mfsu.alias,
69
- externals: this.opts.mfsu.externals,
70
- },
71
- });
72
- utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
73
- opts.onBuildComplete();
74
- });
75
- }
76
- build(opts) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- this.isBuilding = true;
79
- yield this.writeMFFiles({ deps: opts.deps });
80
- const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
81
- this.isBuilding = false;
82
- this.completeFns.forEach((fn) => fn());
83
- this.completeFns = [];
84
- } });
85
- if (this.opts.mfsu.opts.buildDepWithESBuild) {
86
- yield this.buildWithESBuild(newOpts);
87
- }
88
- else {
89
- yield this.buildWithWebpack(newOpts);
90
- }
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/depBuilder/depBuilder.ts
20
+ var depBuilder_exports = {};
21
+ __export(depBuilder_exports, {
22
+ DepBuilder: () => DepBuilder
23
+ });
24
+ module.exports = __toCommonJS(depBuilder_exports);
25
+ var import_bundler_esbuild = require("@umijs/bundler-esbuild");
26
+ var import_utils = require("@umijs/utils");
27
+ var import_fs = require("fs");
28
+ var import_path = require("path");
29
+ var import_constants = require("../constants");
30
+ var import_depChunkIdPrefixPlugin = require("../webpackPlugins/depChunkIdPrefixPlugin");
31
+ var import_stripSourceMapUrlPlugin = require("../webpackPlugins/stripSourceMapUrlPlugin");
32
+ var import_getESBuildEntry = require("./getESBuildEntry");
33
+ var MF_ENTRY = "mf_index.js";
34
+ var DepBuilder = class {
35
+ constructor(opts) {
36
+ this.completeFns = [];
37
+ this.isBuilding = false;
38
+ this.opts = opts;
39
+ }
40
+ async buildWithWebpack(opts) {
41
+ const config = this.getWebpackConfig({ deps: opts.deps });
42
+ return new Promise((resolve, reject) => {
43
+ const compiler = this.opts.mfsu.opts.implementor(config);
44
+ compiler.run((err, stats) => {
45
+ opts.onBuildComplete();
46
+ if (err || (stats == null ? void 0 : stats.hasErrors())) {
47
+ if (err) {
48
+ reject(err);
49
+ }
50
+ if (stats) {
51
+ const errorMsg = stats.toString("errors-only");
52
+ reject(new Error(errorMsg));
53
+ }
54
+ } else {
55
+ resolve(stats);
56
+ }
57
+ compiler.close(() => {
91
58
  });
92
- }
93
- onBuildComplete(fn) {
94
- if (this.isBuilding) {
95
- this.completeFns.push(fn);
59
+ });
60
+ });
61
+ }
62
+ // TODO: support watch and rebuild
63
+ async buildWithESBuild(opts) {
64
+ const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({
65
+ mfName: this.opts.mfsu.opts.mfName,
66
+ deps: opts.deps
67
+ });
68
+ const ENTRY_FILE = "esbuild-entry.js";
69
+ const tmpDir = this.opts.mfsu.opts.tmpBase;
70
+ const entryPath = (0, import_path.join)(tmpDir, ENTRY_FILE);
71
+ (0, import_fs.writeFileSync)(entryPath, entryContent, "utf-8");
72
+ const date = (/* @__PURE__ */ new Date()).getTime();
73
+ await (0, import_bundler_esbuild.build)({
74
+ cwd: this.opts.mfsu.opts.cwd,
75
+ entry: {
76
+ [`${import_constants.MF_VA_PREFIX}remoteEntry`]: entryPath
77
+ },
78
+ config: {
79
+ ...this.opts.mfsu.opts.depBuildConfig,
80
+ outputPath: tmpDir,
81
+ alias: this.opts.mfsu.alias,
82
+ externals: this.opts.mfsu.externals
83
+ },
84
+ inlineStyle: true
85
+ });
86
+ import_utils.logger.event(
87
+ `[mfsu] compiled with esbuild successfully in ${+/* @__PURE__ */ new Date() - date} ms`
88
+ );
89
+ opts.onBuildComplete();
90
+ }
91
+ async buildWithWorker(opts) {
92
+ const worker = this.opts.mfsu.opts.startBuildWorker(opts.deps);
93
+ worker.postMessage(opts.deps);
94
+ return new Promise((resolve, reject) => {
95
+ const onMessage = ({
96
+ progress,
97
+ done
98
+ }) => {
99
+ if (done) {
100
+ opts.onBuildComplete();
101
+ worker.off("message", onMessage);
102
+ if (done.withError) {
103
+ import_utils.logger.debug("[MFSU][eager][main] build failed", done.withError);
104
+ reject(done.withError);
105
+ } else {
106
+ resolve();
107
+ }
96
108
  }
97
- else {
98
- fn();
109
+ if (progress) {
110
+ this.opts.mfsu.onProgress(progress);
99
111
  }
112
+ };
113
+ worker.on("message", onMessage);
114
+ worker.once("error", (e) => {
115
+ import_utils.logger.error("[MFSU][eager] worker got Error", e);
116
+ opts.onBuildComplete();
117
+ reject(e);
118
+ });
119
+ });
120
+ }
121
+ async build(opts) {
122
+ this.isBuilding = true;
123
+ const onBuildComplete = () => {
124
+ this.isBuilding = false;
125
+ this.completeFns.forEach((fn) => fn());
126
+ this.completeFns = [];
127
+ };
128
+ try {
129
+ const buildOpts = {
130
+ ...opts,
131
+ onBuildComplete
132
+ };
133
+ if (this.opts.mfsu.opts.strategy === "eager" && opts.useWorker) {
134
+ await this.buildWithWorker(buildOpts);
135
+ return;
136
+ }
137
+ await this.writeMFFiles({ deps: opts.deps });
138
+ if (this.opts.mfsu.opts.buildDepWithESBuild) {
139
+ await this.buildWithESBuild(buildOpts);
140
+ } else {
141
+ await this.buildWithWebpack(buildOpts);
142
+ }
143
+ } catch (e) {
144
+ onBuildComplete();
145
+ throw e;
100
146
  }
101
- writeMFFiles(opts) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- const tmpBase = this.opts.mfsu.opts.tmpBase;
104
- // expose files
105
- for (const dep of opts.deps) {
106
- const content = yield dep.buildExposeContent();
107
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
108
- }
109
- // index file
110
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"😛"', 'utf-8');
111
- });
147
+ }
148
+ onBuildComplete(fn) {
149
+ if (this.isBuilding) {
150
+ this.completeFns.push(fn);
151
+ } else {
152
+ fn();
112
153
  }
113
- getWebpackConfig(opts) {
114
- var _a, _b;
115
- const mfName = this.opts.mfsu.opts.mfName;
116
- const depConfig = utils_1.lodash.cloneDeep(this.opts.mfsu.depConfig);
117
- // depConfig.stats = 'none';
118
- depConfig.entry = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, 'index.js');
119
- depConfig.output.path = this.opts.mfsu.opts.tmpBase;
120
- // disable devtool
121
- depConfig.devtool = false;
122
- // disable library
123
- // library 会影响 external 的语法,导致报错
124
- // ref: https://github.com/umijs/plugins/blob/6d3fc2d/packages/plugin-qiankun/src/slave/index.ts#L83
125
- if ((_a = depConfig.output) === null || _a === void 0 ? void 0 : _a.library)
126
- delete depConfig.output.library;
127
- if ((_b = depConfig.output) === null || _b === void 0 ? void 0 : _b.libraryTarget)
128
- delete depConfig.output.libraryTarget;
129
- // merge all deps to vendor
130
- depConfig.optimization || (depConfig.optimization = {});
131
- depConfig.optimization.splitChunks = {
132
- chunks: 'all',
133
- maxInitialRequests: Infinity,
134
- minSize: 0,
135
- cacheGroups: {
136
- vendor: {
137
- test: /.+/,
138
- name(_module, _chunks, cacheGroupKey) {
139
- return `${constants_1.MF_DEP_PREFIX}___${cacheGroupKey}`;
140
- },
141
- },
142
- },
143
- };
144
- depConfig.plugins = depConfig.plugins || [];
145
- depConfig.plugins.push(new depChunkIdPrefixPlugin_1.DepChunkIdPrefixPlugin());
146
- depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
147
- webpack: this.opts.mfsu.opts.implementor,
148
- }));
149
- const exposes = opts.deps.reduce((memo, dep) => {
150
- memo[`./${dep.shortFile}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
151
- return memo;
152
- }, {});
153
- depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
154
- library: {
155
- type: 'global',
156
- name: mfName,
157
- },
158
- name: mfName,
159
- filename: constants_1.REMOTE_FILE_FULL,
160
- exposes,
161
- }));
162
- return depConfig;
154
+ }
155
+ async writeMFFiles(opts) {
156
+ const tmpBase = this.opts.mfsu.opts.tmpBase;
157
+ import_utils.fsExtra.mkdirpSync(tmpBase);
158
+ for (const dep of opts.deps) {
159
+ const content = await dep.buildExposeContent();
160
+ (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, dep.filePath), content, "utf-8");
163
161
  }
164
- }
165
- exports.DepBuilder = DepBuilder;
162
+ (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, MF_ENTRY), '"😛"', "utf-8");
163
+ }
164
+ getWebpackConfig(opts) {
165
+ var _a, _b;
166
+ const mfName = this.opts.mfsu.opts.mfName;
167
+ const depConfig = import_utils.lodash.cloneDeep(this.opts.mfsu.depConfig);
168
+ depConfig.entry = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, MF_ENTRY);
169
+ depConfig.output.path = this.opts.mfsu.opts.tmpBase;
170
+ depConfig.output.publicPath = "auto";
171
+ depConfig.devtool = false;
172
+ if ((_a = depConfig.output) == null ? void 0 : _a.library)
173
+ delete depConfig.output.library;
174
+ if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
175
+ delete depConfig.output.libraryTarget;
176
+ depConfig.optimization || (depConfig.optimization = {});
177
+ depConfig.optimization.splitChunks = {
178
+ chunks: (chunk) => {
179
+ const hasShared = chunk.getModules().some((m) => {
180
+ return m.type === "consume-shared-module" || m.type === "provide-module" || m.type === "provide-shared-module";
181
+ });
182
+ return !hasShared;
183
+ },
184
+ maxInitialRequests: Infinity,
185
+ minSize: 0,
186
+ cacheGroups: {
187
+ vendor: {
188
+ test: /.+/,
189
+ name(_module, _chunks, cacheGroupKey) {
190
+ return `${import_constants.MF_DEP_PREFIX}___${cacheGroupKey}`;
191
+ }
192
+ }
193
+ }
194
+ };
195
+ depConfig.plugins = depConfig.plugins || [];
196
+ depConfig.plugins.push(new import_depChunkIdPrefixPlugin.DepChunkIdPrefixPlugin());
197
+ depConfig.plugins.push(
198
+ new import_stripSourceMapUrlPlugin.StripSourceMapUrlPlugin({
199
+ webpack: this.opts.mfsu.opts.implementor
200
+ })
201
+ );
202
+ depConfig.plugins.push(
203
+ new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
204
+ this.opts.mfsu.onProgress({ percent, status: msg });
205
+ })
206
+ );
207
+ const exposes = opts.deps.reduce((memo, dep) => {
208
+ memo[`./${dep.file}`] = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
209
+ return memo;
210
+ }, {});
211
+ depConfig.plugins.push(
212
+ new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
213
+ library: {
214
+ type: "global",
215
+ name: mfName
216
+ },
217
+ name: mfName,
218
+ filename: import_constants.REMOTE_FILE_FULL,
219
+ exposes,
220
+ shared: this.opts.mfsu.opts.shared || {}
221
+ })
222
+ );
223
+ return depConfig;
224
+ }
225
+ };
226
+ // Annotate the CommonJS export names for ESM import in node:
227
+ 0 && (module.exports = {
228
+ DepBuilder
229
+ });
@@ -1,5 +1,5 @@
1
1
  import { Dep } from '../dep/dep';
2
2
  export declare function getESBuildEntry(opts: {
3
+ mfName: string;
3
4
  deps: Dep[];
4
5
  }): string;
5
- //# sourceMappingURL=getESBuildEntry.d.ts.map
@@ -1,9 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getESBuildEntry = void 0;
4
- const constants_1 = require("../constants");
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/depBuilder/getESBuildEntry.ts
20
+ var getESBuildEntry_exports = {};
21
+ __export(getESBuildEntry_exports, {
22
+ getESBuildEntry: () => getESBuildEntry
23
+ });
24
+ module.exports = __toCommonJS(getESBuildEntry_exports);
25
+ var import_constants = require("../constants");
26
+ var ES_INTEROP_FUNC = `__exportStar`;
27
+ var ES_INTEROP_HELPER = `
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var ${ES_INTEROP_FUNC} = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ `;
5
39
  function getESBuildEntry(opts) {
6
- return `
40
+ return `
7
41
  (function() {
8
42
  /******/ "use strict";
9
43
  /******/ var __webpack_modules__ = ({});
@@ -266,8 +300,9 @@ function getESBuildEntry(opts) {
266
300
  var __webpack_exports__ = {};
267
301
  (function() {
268
302
  var exports = __webpack_exports__;
303
+ ${ES_INTEROP_HELPER}
269
304
  var moduleMap = {
270
- ${opts.deps.map(getDepModuleStr).join(',\n')}
305
+ ${opts.deps.map(getDepModuleStr).join(",\n")}
271
306
  };
272
307
  var get = function(module, getScope) {
273
308
  __webpack_require__.R = getScope;
@@ -293,23 +328,24 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
293
328
  get: function() { return get; },
294
329
  init: function() { return init; }
295
330
  });
296
- self.mf = __webpack_exports__;
331
+ self.${opts.mfName} = __webpack_exports__;
297
332
  })();
298
333
  })();
299
334
  `;
300
335
  }
301
- exports.getESBuildEntry = getESBuildEntry;
302
- function normalizeFile(file) {
303
- return file.replace(/\//g, '_');
304
- }
305
336
  function getDepModuleStr(dep) {
306
- return `
337
+ return `
307
338
  "./${dep.file}": function() {
308
339
  return new Promise(resolve => {
309
- import('./${constants_1.MF_VA_PREFIX}${normalizeFile(dep.file)}.js').then(module => {
310
- resolve(() => module);
340
+ import('./${import_constants.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
341
+ module.default && ${ES_INTEROP_FUNC}(module, module.default);
342
+ resolve(() => module.default || module);
311
343
  });
312
344
  })
313
345
  }
314
346
  `.trim();
315
347
  }
348
+ // Annotate the CommonJS export names for ESM import in node:
349
+ 0 && (module.exports = {
350
+ getESBuildEntry
351
+ });
package/dist/depInfo.d.ts CHANGED
@@ -1,18 +1,32 @@
1
- import { MFSU } from './mfsu';
1
+ import { MFSU } from './mfsu/mfsu';
2
2
  import { ModuleGraph } from './moduleGraph';
3
3
  interface IOpts {
4
4
  mfsu: MFSU;
5
5
  }
6
- export declare class DepInfo {
6
+ export declare type DepModule = {
7
+ file: string;
8
+ version: string;
9
+ importer?: string;
10
+ };
11
+ export interface IDepInfo {
12
+ shouldBuild(): string | boolean;
13
+ snapshot(): void;
14
+ loadCache(): void;
15
+ writeCache(): void;
16
+ getCacheFilePath(): string;
17
+ getDepModules(): Record<string, DepModule>;
18
+ }
19
+ export declare class DepInfo implements IDepInfo {
7
20
  private opts;
8
- cacheFilePath: string;
21
+ private readonly cacheFilePath;
9
22
  moduleGraph: ModuleGraph;
10
- cacheDependency: object;
23
+ private cacheDependency;
11
24
  constructor(opts: IOpts);
12
- shouldBuild(): boolean;
25
+ shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
13
26
  snapshot(): void;
14
27
  loadCache(): void;
15
28
  writeCache(): void;
29
+ getDepModules(): Record<string, DepModule>;
30
+ getCacheFilePath(): string;
16
31
  }
17
32
  export {};
18
- //# sourceMappingURL=depInfo.d.ts.map