@umijs/mfsu 4.0.51 → 4.0.53

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.
@@ -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
  ));
@@ -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
  ));
@@ -53,6 +57,7 @@ function awaitImport_default() {
53
57
  const node = path.node.body[index];
54
58
  if (t.isImportDeclaration(node)) {
55
59
  const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
60
+ // @ts-ignore
56
61
  cache: this.cache,
57
62
  value: node.source.value,
58
63
  opts,
@@ -63,6 +68,7 @@ function awaitImport_default() {
63
68
  }
64
69
  } else if (t.isExportAllDeclaration(node)) {
65
70
  const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
71
+ // @ts-ignore
66
72
  cache: this.cache,
67
73
  value: node.source.value,
68
74
  opts,
@@ -73,6 +79,7 @@ function awaitImport_default() {
73
79
  }
74
80
  } else if (t.isExportNamedDeclaration(node) && node.source) {
75
81
  const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
82
+ // @ts-ignore
76
83
  cache: this.cache,
77
84
  value: node.source.value,
78
85
  opts,
@@ -91,6 +98,7 @@ function awaitImport_default() {
91
98
  const { node } = path;
92
99
  if (t.isImport(node.callee) && node.arguments.length === 1 && node.arguments[0].type === "StringLiteral") {
93
100
  const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
101
+ // @ts-ignore
94
102
  cache: this.cache,
95
103
  value: node.arguments[0].value,
96
104
  opts,
@@ -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
  ));
@@ -73,7 +77,17 @@ function checkMatch({
73
77
  value = value.replace(/^@fs\//, "/");
74
78
  const unMatchLibsRegex = genUnMatchLibsRegex(opts.unMatchLibs);
75
79
  const mfPathInitial = `${remoteName}/`;
76
- if ((unMatchLibsRegex == null ? void 0 : unMatchLibsRegex.test(value)) || value.includes("client/client/client.js") || (0, import_utils.winPath)(value).includes("babel/svgr-webpack") || value.startsWith("!!") || (0, import_isExternals.isExternals)({ value, externals: opts.externals }) || value.startsWith(".")) {
80
+ if (
81
+ // unMatch specified libs
82
+ (unMatchLibsRegex == null ? void 0 : unMatchLibsRegex.test(value)) || // do not match bundler-webpack/client/client/client.js
83
+ value.includes("client/client/client.js") || // don't match dynamic path
84
+ // e.g. @umijs/deps/compiled/babel/svgr-webpack.js?-svgo,+titleProp,+ref!./umi.svg
85
+ (0, import_utils.winPath)(value).includes("babel/svgr-webpack") || // don't match webpack loader
86
+ // e.g. !!dumi-raw-code-loader!/path/to/VerticalProgress/index.module.less?dumi-raw-code
87
+ value.startsWith("!!") || // don't match externals
88
+ (0, import_isExternals.isExternals)({ value, externals: opts.externals }) || // relative import
89
+ value.startsWith(".")
90
+ ) {
77
91
  isMatch = false;
78
92
  } else if (value.startsWith(mfPathInitial)) {
79
93
  isMatch = true;
@@ -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
  ));
package/dist/dep/dep.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
  ));
@@ -27,13 +27,19 @@ function getCJSExports({ content }) {
27
27
  /Object\.defineProperty\(\s*exports\s*\,\s*[\"|\'](\w+)[\"|\']/g,
28
28
  content
29
29
  ).concat(
30
+ // Support export['default']
31
+ // ref: https://unpkg.alibaba-inc.com/browse/echarts-for-react@2.0.16/lib/core.js
30
32
  matchAll(
31
33
  /exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g,
32
34
  content
33
35
  )
34
36
  ).concat(
37
+ // Support __webpack_exports__["default"]
38
+ // ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8429
35
39
  matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, content)
36
40
  ).concat(
41
+ // Support __webpack_require__.d(__webpack_exports, "EditorState")
42
+ // ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8347
37
43
  matchAll(
38
44
  /__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g,
39
45
  content
@@ -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
  ));
@@ -66,7 +70,10 @@ export default _;`.trim();
66
70
  ret.push(`export default _;`);
67
71
  hasExports = true;
68
72
  }
69
- if (hasNonDefaultExports(exports) || /export\s*\*\s*from/.test(opts.content)) {
73
+ if (hasNonDefaultExports(exports) || // export * from 不会有 exports,只会有 imports
74
+ // case: export*from'.'
75
+ // export * from '.'
76
+ /export\s*\*\s*from/.test(opts.content)) {
70
77
  ret.push(`export * from '${importPath}';`);
71
78
  hasExports = true;
72
79
  }
@@ -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
- `.trimLeft() : `${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
  }
@@ -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
  ));
@@ -104,6 +108,7 @@ var StrategyCompileTime = class {
104
108
  }) => {
105
109
  this.depInfo.moduleGraph.onFileChange({
106
110
  file,
111
+ // @ts-ignore
107
112
  deps: [
108
113
  ...Array.from(data.matched).map((item) => ({
109
114
  file: item.sourceValue,
@@ -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
  ));
@@ -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
  ));
@@ -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
  ));
@@ -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
  ));
@@ -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
  ));
@@ -60,6 +64,7 @@ function getResolver(opts) {
60
64
  const context = opts.context ?? process.cwd();
61
65
  const resolveDefaults = {
62
66
  extensions: [".tsx", ".ts", ".jsx", ".js"],
67
+ // keep same with previous mfsu version
63
68
  roots: [context]
64
69
  };
65
70
  const mergedResolve = import_webpack.util.cleverMerge(resolveDefaults, opts.resolve);
@@ -29,7 +29,10 @@ var WriteCachePlugin = class {
29
29
  }
30
30
  apply(compiler) {
31
31
  compiler.cache.hooks.store.tap(
32
- { name: PLUGIN_NAME, stage: 10 },
32
+ { name: PLUGIN_NAME, stage: (
33
+ /*Cache.STAGE_DISK*/
34
+ 10
35
+ ) },
33
36
  () => {
34
37
  this.opts.onWriteCache();
35
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.51",
3
+ "version": "4.0.53",
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.51",
27
- "@umijs/bundler-utils": "4.0.51",
28
- "@umijs/utils": "4.0.51",
26
+ "@umijs/bundler-esbuild": "4.0.53",
27
+ "@umijs/bundler-utils": "4.0.53",
28
+ "@umijs/utils": "4.0.53",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },