@umijs/mfsu 4.0.24 → 4.0.26

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.
@@ -48,9 +48,9 @@ function MFImport_default() {
48
48
  CallExpression: {
49
49
  exit(path, { opts }) {
50
50
  const { node } = path;
51
- if (t.isImport(node.callee) && node.arguments.length === 1 && node.arguments[0].type === "StringLiteral") {
51
+ if (t.isImport(node.callee) && node.arguments.length === 1 && t.isStringLiteral(node.arguments[0])) {
52
52
  const newValue = opts.resolveImportSource(node.arguments[0].value);
53
- node.arguments[0] = t.stringLiteral(newValue);
53
+ node.arguments[0].value = newValue;
54
54
  }
55
55
  }
56
56
  }
@@ -53,7 +53,7 @@ export declare class MFSU {
53
53
  getCacheFilePath(): string;
54
54
  }
55
55
  export interface IMFSUStrategy {
56
- init(): void;
56
+ init(webpackConfig: Configuration): void;
57
57
  shouldBuild(): string | boolean;
58
58
  getBabelPlugin(): any[];
59
59
  getBuildDepPlugConfig(): IBuildDepPluginOpts;
package/dist/mfsu/mfsu.js CHANGED
@@ -181,7 +181,7 @@ promise new Promise(resolve => {
181
181
  ]);
182
182
  import_utils.lodash.set(opts.config, "experiments.topLevelAwait", true);
183
183
  this.depConfig = opts.depConfig;
184
- this.strategy.init();
184
+ this.strategy.init(opts.config);
185
185
  }
186
186
  async buildDeps() {
187
187
  try {
@@ -1,5 +1,6 @@
1
1
  import { IBuildDepPluginOpts } from '../webpackPlugins/buildDepPlugin';
2
2
  import type { IMFSUStrategy, MFSU } from './mfsu';
3
+ import type { Configuration } from 'webpack';
3
4
  export declare class StaticAnalyzeStrategy implements IMFSUStrategy {
4
5
  private readonly mfsu;
5
6
  private staticDepInfo;
@@ -7,7 +8,7 @@ export declare class StaticAnalyzeStrategy implements IMFSUStrategy {
7
8
  mfsu: MFSU;
8
9
  srcCodeCache: any;
9
10
  });
10
- init(): void;
11
+ init(webpackConfig: Configuration): void;
11
12
  getDepModules(): Record<string, {
12
13
  file: string;
13
14
  version: string;
@@ -29,6 +29,7 @@ var import_utils = require("@umijs/utils");
29
29
  var import_checkMatch = require("../babelPlugins/awaitImport/checkMatch");
30
30
  var import_MFImport = __toESM(require("../babelPlugins/awaitImport/MFImport"));
31
31
  var import_staticDepInfo = require("../staticDepInfo/staticDepInfo");
32
+ var import_webpackUtils = require("../utils/webpackUtils");
32
33
  var StaticAnalyzeStrategy = class {
33
34
  constructor({ mfsu, srcCodeCache }) {
34
35
  this.mfsu = mfsu;
@@ -37,7 +38,9 @@ var StaticAnalyzeStrategy = class {
37
38
  srcCodeCache
38
39
  });
39
40
  }
40
- init() {
41
+ init(webpackConfig) {
42
+ const config = (0, import_webpackUtils.extractBabelPluginImportOptions)(webpackConfig);
43
+ this.staticDepInfo.setBabelPluginImportConfig(config);
41
44
  this.staticDepInfo.init();
42
45
  }
43
46
  getDepModules() {
@@ -122,16 +125,20 @@ var StaticAnalyzeStrategy = class {
122
125
  if (!c.modifiedFiles || c.modifiedFiles.size === 0) {
123
126
  return;
124
127
  }
128
+ if (!hasJSCodeFiles(c.modifiedFiles) && !hasJSCodeFiles(c.removedFiles)) {
129
+ return;
130
+ }
125
131
  const start = Date.now();
126
132
  let event = this.staticDepInfo.getProducedEvent();
127
133
  while (event.length === 0) {
128
- await sleep(200);
134
+ await sleep(100);
129
135
  event = this.staticDepInfo.getProducedEvent();
130
136
  if (Date.now() - start > 5e3) {
131
137
  import_utils.logger.warn("webpack wait mfsu deps too long");
132
138
  break;
133
139
  }
134
140
  }
141
+ import_utils.logger.debug(`webpack waited ${Date.now() - start} ms`);
135
142
  },
136
143
  onCompileDone: () => {
137
144
  }
@@ -151,6 +158,15 @@ function sleep(ms) {
151
158
  }, ms);
152
159
  });
153
160
  }
161
+ var REG_CODE_EXT = /\.(jsx|js|ts|tsx)$/;
162
+ function hasJSCodeFiles(files) {
163
+ for (let file of files.values()) {
164
+ if (REG_CODE_EXT.test(file)) {
165
+ return true;
166
+ }
167
+ }
168
+ return false;
169
+ }
154
170
  // Annotate the CommonJS export names for ESM import in node:
155
171
  0 && (module.exports = {
156
172
  StaticAnalyzeStrategy
@@ -46,7 +46,7 @@ function createHandle(importOptions) {
46
46
  retMatched.push({
47
47
  isMatch: true,
48
48
  value: unAliasedModulePath,
49
- replaceValue: `${mfName}/${unAliasedModulePath}`,
49
+ replaceValue: `${mfName}/${(0, import_utils.winPath)(unAliasedModulePath)}`,
50
50
  version
51
51
  });
52
52
  const unAliasedStylePath = (0, import_getAliasedPath.getAliasedPathWithLoopDetect)({
@@ -56,7 +56,7 @@ function createHandle(importOptions) {
56
56
  retMatched.push({
57
57
  isMatch: true,
58
58
  value: unAliasedStylePath,
59
- replaceValue: `${mfName}/${unAliasedStylePath}`,
59
+ replaceValue: `${mfName}/${(0, import_utils.winPath)(unAliasedStylePath)}`,
60
60
  version
61
61
  });
62
62
  };
@@ -52,5 +52,6 @@ export declare class StaticDepInfo {
52
52
  private simulateRuntimeTransform;
53
53
  private appendIncludeList;
54
54
  allRuntimeHelpers(): Promise<void>;
55
+ setBabelPluginImportConfig(config: Map<string, any>): void;
55
56
  }
56
57
  export {};
@@ -46,24 +46,7 @@ var StaticDepInfo = class {
46
46
  this.produced.push({ changes: info.events });
47
47
  this.currentDep = this._getDependencies(info.code, info.imports);
48
48
  });
49
- this.runtimeSimulations = [
50
- {
51
- packageName: "antd",
52
- handleImports: (0, import_babel_plugin_import.default)({
53
- libraryName: "antd",
54
- style: true,
55
- libraryDirectory: "es"
56
- })
57
- },
58
- {
59
- packageName: "@alipay/bigfish/antd",
60
- handleImports: (0, import_babel_plugin_import.default)({
61
- libraryName: "@alipay/bigfish/antd",
62
- style: true,
63
- libraryDirectory: "es"
64
- })
65
- }
66
- ];
49
+ this.runtimeSimulations = [];
67
50
  }
68
51
  getProducedEvent() {
69
52
  return this.produced;
@@ -150,6 +133,9 @@ var StaticDepInfo = class {
150
133
  const pkgNames = this.runtimeSimulations.map(({ packageName }) => packageName);
151
134
  const groupedMockImports = {};
152
135
  for (const imp of imports) {
136
+ if (!imp.n) {
137
+ continue;
138
+ }
153
139
  if (pkgNames.indexOf(imp.n) >= 0) {
154
140
  const name = imp.n;
155
141
  if (groupedMockImports[name]) {
@@ -230,6 +216,14 @@ var StaticDepInfo = class {
230
216
  }
231
217
  async allRuntimeHelpers() {
232
218
  }
219
+ setBabelPluginImportConfig(config) {
220
+ for (const [key, c] of config.entries()) {
221
+ this.runtimeSimulations.push({
222
+ packageName: key,
223
+ handleImports: (0, import_babel_plugin_import.default)(c)
224
+ });
225
+ }
226
+ }
233
227
  };
234
228
  // Annotate the CommonJS export names for ESM import in node:
235
229
  0 && (module.exports = {
@@ -0,0 +1,2 @@
1
+ import type { Configuration } from 'webpack';
2
+ export declare function extractBabelPluginImportOptions(webpackConfig: Configuration): Map<string, any>;
@@ -0,0 +1,47 @@
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/utils/webpackUtils.ts
20
+ var webpackUtils_exports = {};
21
+ __export(webpackUtils_exports, {
22
+ extractBabelPluginImportOptions: () => extractBabelPluginImportOptions
23
+ });
24
+ module.exports = __toCommonJS(webpackUtils_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ var { property, compact, flatMap } = import_utils.lodash;
27
+ function extractBabelPluginImportOptions(webpackConfig) {
28
+ var _a;
29
+ const rules = ((_a = webpackConfig.module) == null ? void 0 : _a.rules) || [];
30
+ const uses = compact(flatMap(rules, property(["use"]))).filter((u) => {
31
+ var _a2;
32
+ return ((_a2 = u == null ? void 0 : u.loader) == null ? void 0 : _a2.indexOf("babel-loader")) >= 0;
33
+ });
34
+ const pluginConfigs = compact(flatMap(uses, property(["options", "plugins"]))).filter((p) => {
35
+ var _a2, _b;
36
+ return Array.isArray(p) && ((_b = (_a2 = p[0]) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b.call(_a2, "babel-plugin-import")) >= 0;
37
+ });
38
+ const configs = /* @__PURE__ */ new Map();
39
+ for (const c of pluginConfigs) {
40
+ !configs.has(c[1].libraryName) && configs.set(c[1].libraryName, c[1]);
41
+ }
42
+ return configs;
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ extractBabelPluginImportOptions
47
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.24",
3
+ "version": "4.0.26",
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.24",
27
- "@umijs/bundler-utils": "4.0.24",
28
- "@umijs/utils": "4.0.24",
26
+ "@umijs/bundler-esbuild": "4.0.26",
27
+ "@umijs/bundler-utils": "4.0.26",
28
+ "@umijs/utils": "4.0.26",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },