@umijs/mfsu 4.0.0-canary.20230210.1 → 4.0.0-canary.20230216.1

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.
@@ -22,6 +22,7 @@ export declare class DepBuilder {
22
22
  }): Promise<void>;
23
23
  build(opts: {
24
24
  deps: Dep[];
25
+ useWorker: boolean;
25
26
  }): Promise<void>;
26
27
  onBuildComplete(fn: Function): void;
27
28
  writeMFFiles(opts: {
@@ -59,6 +59,7 @@ var DepBuilder = class {
59
59
  });
60
60
  });
61
61
  }
62
+ // TODO: support watch and rebuild
62
63
  async buildWithESBuild(opts) {
63
64
  const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({
64
65
  mfName: this.opts.mfsu.opts.mfName,
@@ -129,7 +130,7 @@ var DepBuilder = class {
129
130
  ...opts,
130
131
  onBuildComplete
131
132
  };
132
- if (this.opts.mfsu.opts.strategy === "eager") {
133
+ if (this.opts.mfsu.opts.strategy === "eager" && opts.useWorker) {
133
134
  await this.buildWithWorker(buildOpts);
134
135
  return;
135
136
  }
@@ -46,7 +46,9 @@ export declare class MFSU {
46
46
  config: Configuration;
47
47
  depConfig: Configuration;
48
48
  }): Promise<void>;
49
- buildDeps(): Promise<void>;
49
+ buildDeps(opts?: {
50
+ useWorker: boolean;
51
+ }): Promise<void>;
50
52
  getMiddlewares(): (((req: Request, res: Response, next: NextFunction) => void) | import("@umijs/bundler-utils/compiled/express/serve-static").RequestHandler<Response<any, Record<string, any>>>)[];
51
53
  getBabelPlugins(): any[][];
52
54
  getEsbuildLoaderHandler(): any[];
package/dist/mfsu/mfsu.js CHANGED
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -90,6 +94,8 @@ var MFSU = class {
90
94
  this.strategy.loadCache();
91
95
  this.depBuilder = new import_depBuilder.DepBuilder({ mfsu: this });
92
96
  }
97
+ // swc don't support top-level await
98
+ // ref: https://github.com/vercel/next.js/issues/31054
93
99
  asyncImport(content) {
94
100
  return `await import('${(0, import_utils.winPath)(content)}');`;
95
101
  }
@@ -159,7 +165,10 @@ var MFSU = class {
159
165
  name: "__",
160
166
  shared: this.opts.shared || {},
161
167
  remotes: {
162
- [mfName]: this.opts.runtimePublicPath ? `
168
+ [mfName]: this.opts.runtimePublicPath ? (
169
+ // ref:
170
+ // https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes
171
+ `
163
172
  promise new Promise(resolve => {
164
173
  const remoteUrlWithVersion = (window.publicPath || '/') + '${import_constants.REMOTE_FILE_FULL}';
165
174
  const script = document.createElement('script');
@@ -182,17 +191,24 @@ promise new Promise(resolve => {
182
191
  // inject this script with the src set to the versioned remoteEntry.js
183
192
  document.head.appendChild(script);
184
193
  })
185
- `.trimStart() : `${mfName}@${publicPath}${import_constants.REMOTE_FILE_FULL}`
194
+ `.trimStart()
195
+ ) : `${mfName}@${publicPath}${import_constants.REMOTE_FILE_FULL}`
196
+ // mfsu 的入口文件如果需要在其他的站点上被引用,需要显示的指定publicPath,以保证入口文件的正确访问
186
197
  }
187
198
  }),
188
199
  new import_buildDepPlugin.BuildDepPlugin(this.strategy.getBuildDepPlugConfig())
200
+ // new WriteCachePlugin({
201
+ // onWriteCache: lodash.debounce(() => {
202
+ // this.depInfo.writeCache();
203
+ // }, 300),
204
+ // }),
189
205
  ]
190
206
  );
191
207
  import_utils.lodash.set(opts.config, "experiments.topLevelAwait", true);
192
208
  this.depConfig = opts.depConfig;
193
209
  this.strategy.init(opts.config);
194
210
  }
195
- async buildDeps() {
211
+ async buildDeps(opts = { useWorker: true }) {
196
212
  try {
197
213
  const shouldBuild = this.strategy.shouldBuild();
198
214
  if (!shouldBuild) {
@@ -209,7 +225,8 @@ promise new Promise(resolve => {
209
225
  import_utils.logger.info(`[MFSU] buildDeps since ${shouldBuild}`);
210
226
  import_utils.logger.debug(deps.map((dep) => dep.file).join(", "));
211
227
  await this.depBuilder.build({
212
- deps
228
+ deps,
229
+ useWorker: opts.useWorker
213
230
  });
214
231
  this.lastBuildError = null;
215
232
  this.strategy.writeCache();
@@ -260,6 +277,8 @@ promise new Promise(resolve => {
260
277
  next();
261
278
  }
262
279
  },
280
+ // 兜底依赖构建时, 代码中有指定 chunk 名的情况
281
+ // TODO: should respect to publicPath
263
282
  import_express.default.static(this.opts.tmpBase)
264
283
  ];
265
284
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-canary.20230210.1",
3
+ "version": "4.0.0-canary.20230216.1",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -23,9 +23,9 @@
23
23
  "test": "umi-scripts jest-turbo"
24
24
  },
25
25
  "dependencies": {
26
- "@umijs/bundler-esbuild": "4.0.0-canary.20230210.1",
27
- "@umijs/bundler-utils": "4.0.0-canary.20230210.1",
28
- "@umijs/utils": "4.0.0-canary.20230210.1",
26
+ "@umijs/bundler-esbuild": "4.0.0-canary.20230216.1",
27
+ "@umijs/bundler-utils": "4.0.0-canary.20230216.1",
28
+ "@umijs/utils": "4.0.0-canary.20230216.1",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },