@umijs/mfsu 4.0.25 → 4.0.27

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.
@@ -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,13 +8,13 @@ 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;
14
15
  }>;
15
16
  getCacheFilePath(): string;
16
- shouldBuild(): false | "dependencies changed";
17
+ shouldBuild(): false | "cacheDependency has changed" | "dependencies changed";
17
18
  writeCache(): void;
18
19
  getBabelPlugin(): any[];
19
20
  private getMfImportOpts;
@@ -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() {
@@ -29,6 +29,7 @@ export declare class StaticDepInfo {
29
29
  private readonly include;
30
30
  private currentDep;
31
31
  private builtWithDep;
32
+ private cacheDependency;
32
33
  private produced;
33
34
  private readonly cwd;
34
35
  private readonly runtimeSimulations;
@@ -37,7 +38,7 @@ export declare class StaticDepInfo {
37
38
  changes: unknown[];
38
39
  }[];
39
40
  consumeAllProducedEvents(): void;
40
- shouldBuild(): false | "dependencies changed";
41
+ shouldBuild(): false | "cacheDependency has changed" | "dependencies changed";
41
42
  getDepModules(): Record<string, {
42
43
  file: string;
43
44
  version: string;
@@ -52,5 +53,6 @@ export declare class StaticDepInfo {
52
53
  private simulateRuntimeTransform;
53
54
  private appendIncludeList;
54
55
  allRuntimeHelpers(): Promise<void>;
56
+ setBabelPluginImportConfig(config: Map<string, any>): void;
55
57
  }
56
58
  export {};
@@ -36,6 +36,7 @@ var StaticDepInfo = class {
36
36
  constructor(opts) {
37
37
  this.currentDep = {};
38
38
  this.builtWithDep = {};
39
+ this.cacheDependency = {};
39
40
  this.produced = [];
40
41
  this.mfsu = opts.mfsu;
41
42
  this.include = this.mfsu.opts.include || [];
@@ -46,24 +47,7 @@ var StaticDepInfo = class {
46
47
  this.produced.push({ changes: info.events });
47
48
  this.currentDep = this._getDependencies(info.code, info.imports);
48
49
  });
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
- ];
50
+ this.runtimeSimulations = [];
67
51
  }
68
52
  getProducedEvent() {
69
53
  return this.produced;
@@ -72,6 +56,14 @@ var StaticDepInfo = class {
72
56
  this.produced = [];
73
57
  }
74
58
  shouldBuild() {
59
+ const currentCacheDep = this.opts.mfsu.opts.getCacheDependency();
60
+ if (!import_utils.lodash.isEqual(this.cacheDependency, currentCacheDep)) {
61
+ if (process.env.DEBUG_UMI) {
62
+ const reason = (0, import_why.default)(this.cacheDependency, currentCacheDep);
63
+ import_utils.logger.info("[MFSU][eager]: isEqual(cacheDependency,currentCacheDep) === false, because ", reason);
64
+ }
65
+ return "cacheDependency has changed";
66
+ }
75
67
  if (import_utils.lodash.isEqual(this.builtWithDep, this.currentDep)) {
76
68
  return false;
77
69
  } else {
@@ -96,11 +88,14 @@ var StaticDepInfo = class {
96
88
  }
97
89
  snapshot() {
98
90
  this.builtWithDep = this.currentDep;
91
+ this.cacheDependency = this.mfsu.opts.getCacheDependency();
99
92
  }
100
93
  loadCache() {
101
94
  if ((0, import_fs.existsSync)(this.cacheFilePath)) {
102
95
  try {
103
- this.builtWithDep = JSON.parse((0, import_fs.readFileSync)(this.cacheFilePath, "utf-8"));
96
+ const { dep = {}, cacheDependency = {} } = JSON.parse((0, import_fs.readFileSync)(this.cacheFilePath, "utf-8"));
97
+ this.builtWithDep = dep;
98
+ this.cacheDependency = cacheDependency;
104
99
  import_utils.logger.info("[MFSU][eager] restored cache");
105
100
  } catch (e) {
106
101
  import_utils.logger.warn("[MFSU][eager] restore cache failed, fallback to Empty dependency", e);
@@ -109,7 +104,10 @@ var StaticDepInfo = class {
109
104
  }
110
105
  writeCache() {
111
106
  import_utils.fsExtra.mkdirpSync((0, import_path.dirname)(this.cacheFilePath));
112
- const newContent = JSON.stringify(this.builtWithDep, null, 2);
107
+ const newContent = JSON.stringify({
108
+ dep: this.builtWithDep,
109
+ cacheDependency: this.cacheDependency
110
+ }, null, 2);
113
111
  if ((0, import_fs.existsSync)(this.cacheFilePath) && (0, import_fs.readFileSync)(this.cacheFilePath, "utf-8") === newContent) {
114
112
  return;
115
113
  }
@@ -233,6 +231,14 @@ var StaticDepInfo = class {
233
231
  }
234
232
  async allRuntimeHelpers() {
235
233
  }
234
+ setBabelPluginImportConfig(config) {
235
+ for (const [key, c] of config.entries()) {
236
+ this.runtimeSimulations.push({
237
+ packageName: key,
238
+ handleImports: (0, import_babel_plugin_import.default)(c)
239
+ });
240
+ }
241
+ }
236
242
  };
237
243
  // Annotate the CommonJS export names for ESM import in node:
238
244
  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.25",
3
+ "version": "4.0.27",
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.25",
27
- "@umijs/bundler-utils": "4.0.25",
28
- "@umijs/utils": "4.0.25",
26
+ "@umijs/bundler-esbuild": "4.0.27",
27
+ "@umijs/bundler-utils": "4.0.27",
28
+ "@umijs/utils": "4.0.27",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },