@umijs/mfsu 4.0.29 → 4.0.31

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.
@@ -30,6 +30,7 @@ var import_constants = require("../constants");
30
30
  var import_depChunkIdPrefixPlugin = require("../webpackPlugins/depChunkIdPrefixPlugin");
31
31
  var import_stripSourceMapUrlPlugin = require("../webpackPlugins/stripSourceMapUrlPlugin");
32
32
  var import_getESBuildEntry = require("./getESBuildEntry");
33
+ var MF_ENTRY = "mf_index.js";
33
34
  var DepBuilder = class {
34
35
  constructor(opts) {
35
36
  this.completeFns = [];
@@ -154,13 +155,13 @@ var DepBuilder = class {
154
155
  const content = await dep.buildExposeContent();
155
156
  (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, dep.filePath), content, "utf-8");
156
157
  }
157
- (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, "index.js"), '"\u{1F61B}"', "utf-8");
158
+ (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, MF_ENTRY), '"\u{1F61B}"', "utf-8");
158
159
  }
159
160
  getWebpackConfig(opts) {
160
161
  var _a, _b;
161
162
  const mfName = this.opts.mfsu.opts.mfName;
162
163
  const depConfig = import_utils.lodash.cloneDeep(this.opts.mfsu.depConfig);
163
- depConfig.entry = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, "index.js");
164
+ depConfig.entry = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, MF_ENTRY);
164
165
  depConfig.output.path = this.opts.mfsu.opts.tmpBase;
165
166
  depConfig.output.publicPath = "auto";
166
167
  depConfig.devtool = false;
@@ -47,11 +47,12 @@ export declare class MFSU {
47
47
  depConfig: Configuration;
48
48
  }): Promise<void>;
49
49
  buildDeps(): Promise<void>;
50
- getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
50
+ getMiddlewares(): (((req: Request, res: Response, next: NextFunction) => void) | import("@umijs/bundler-utils/compiled/express/serve-static").RequestHandler<Response<any, Record<string, any>>>)[];
51
51
  getBabelPlugins(): any[][];
52
52
  getEsbuildLoaderHandler(): any[];
53
53
  getCacheFilePath(): string;
54
54
  }
55
+ export declare function resolvePublicPath(config: Configuration): string;
55
56
  export interface IMFSUStrategy {
56
57
  init(webpackConfig: Configuration): void;
57
58
  shouldBuild(): string | boolean;
package/dist/mfsu/mfsu.js CHANGED
@@ -22,10 +22,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/mfsu/mfsu.ts
23
23
  var mfsu_exports = {};
24
24
  __export(mfsu_exports, {
25
- MFSU: () => MFSU
25
+ MFSU: () => MFSU,
26
+ resolvePublicPath: () => resolvePublicPath
26
27
  });
27
28
  module.exports = __toCommonJS(mfsu_exports);
28
29
  var import_bundler_utils = require("@umijs/bundler-utils");
30
+ var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
29
31
  var import_utils = require("@umijs/utils");
30
32
  var import_assert = __toESM(require("assert"));
31
33
  var import_fs = require("fs");
@@ -140,10 +142,7 @@ var MFSU = class {
140
142
  }
141
143
  opts.config.entry = entry;
142
144
  opts.config.plugins = opts.config.plugins || [];
143
- let publicPath = opts.config.output.publicPath;
144
- if (publicPath === "auto") {
145
- publicPath = "/";
146
- }
145
+ let publicPath = resolvePublicPath(opts.config);
147
146
  this.publicPath = publicPath;
148
147
  opts.config.plugins.push(...[
149
148
  new import_webpack_virtual_modules.default(virtualModules),
@@ -244,7 +243,8 @@ promise new Promise(resolve => {
244
243
  } else {
245
244
  next();
246
245
  }
247
- }
246
+ },
247
+ import_express.default.static(this.opts.tmpBase)
248
248
  ];
249
249
  }
250
250
  getBabelPlugins() {
@@ -268,7 +268,17 @@ promise new Promise(resolve => {
268
268
  return this.strategy.getCacheFilePath();
269
269
  }
270
270
  };
271
+ function resolvePublicPath(config) {
272
+ var _a;
273
+ let publicPath = ((_a = config.output) == null ? void 0 : _a.publicPath) ?? "auto";
274
+ if (publicPath === "auto") {
275
+ publicPath = "/";
276
+ }
277
+ (0, import_assert.default)(typeof publicPath === "string", "Not support function publicPath now");
278
+ return publicPath;
279
+ }
271
280
  // Annotate the CommonJS export names for ESM import in node:
272
281
  0 && (module.exports = {
273
- MFSU
282
+ MFSU,
283
+ resolvePublicPath
274
284
  });
@@ -14,7 +14,7 @@ export declare class StaticAnalyzeStrategy implements IMFSUStrategy {
14
14
  version: string;
15
15
  }>;
16
16
  getCacheFilePath(): string;
17
- shouldBuild(): false | "dependencies changed";
17
+ shouldBuild(): false | "cacheDependency has changed" | "dependencies changed";
18
18
  writeCache(): void;
19
19
  getBabelPlugin(): any[];
20
20
  private getMfImportOpts;
@@ -122,21 +122,30 @@ var StaticAnalyzeStrategy = class {
122
122
  },
123
123
  onFileChange: async (c) => {
124
124
  import_utils.logger.debug("webpack found changes modified:", c.modifiedFiles, "removed:", c.removedFiles);
125
- if (!c.modifiedFiles || c.modifiedFiles.size === 0) {
126
- return;
127
- }
128
- if (!hasJSCodeFiles(c.modifiedFiles) && !hasJSCodeFiles(c.removedFiles)) {
125
+ const fileEvents = [
126
+ ...this.staticDepInfo.opts.srcCodeCache.replayChangeEvents(),
127
+ ...extractJSCodeFiles(c.modifiedFiles).map((f) => {
128
+ return {
129
+ event: "change",
130
+ path: f
131
+ };
132
+ }),
133
+ ...extractJSCodeFiles(c.removedFiles).map((f) => {
134
+ return {
135
+ event: "unlink",
136
+ path: f
137
+ };
138
+ })
139
+ ];
140
+ import_utils.logger.debug("all file events", fileEvents);
141
+ if (fileEvents.length === 0) {
129
142
  return;
130
143
  }
131
144
  const start = Date.now();
132
- let event = this.staticDepInfo.getProducedEvent();
133
- while (event.length === 0) {
134
- await sleep(100);
135
- event = this.staticDepInfo.getProducedEvent();
136
- if (Date.now() - start > 5e3) {
137
- import_utils.logger.warn("webpack wait mfsu deps too long");
138
- break;
139
- }
145
+ try {
146
+ await this.staticDepInfo.opts.srcCodeCache.handleFileChangeEvents(fileEvents);
147
+ } catch (e) {
148
+ import_utils.logger.error("MFSU[eager] analyze dependencies failed with error", e);
140
149
  }
141
150
  import_utils.logger.debug(`webpack waited ${Date.now() - start} ms`);
142
151
  },
@@ -151,21 +160,18 @@ var StaticAnalyzeStrategy = class {
151
160
  this.staticDepInfo.snapshot();
152
161
  }
153
162
  };
154
- function sleep(ms) {
155
- return new Promise((resolve) => {
156
- setTimeout(() => {
157
- resolve();
158
- }, ms);
159
- });
160
- }
161
163
  var REG_CODE_EXT = /\.(jsx|js|ts|tsx)$/;
162
- function hasJSCodeFiles(files) {
164
+ function extractJSCodeFiles(files) {
165
+ const jsFiles = [];
166
+ if (!files) {
167
+ return jsFiles;
168
+ }
163
169
  for (let file of files.values()) {
164
170
  if (REG_CODE_EXT.test(file)) {
165
- return true;
171
+ jsFiles.push(file);
166
172
  }
167
173
  }
168
- return false;
174
+ return jsFiles;
169
175
  }
170
176
  // Annotate the CommonJS export names for ESM import in node:
171
177
  0 && (module.exports = {
@@ -13,6 +13,8 @@ declare type MergedCodeInfo = {
13
13
  declare type AutoUpdateSrcCodeCache = {
14
14
  register(listener: (info: MergedCodeInfo) => void): void;
15
15
  getMergedCode(): MergedCodeInfo;
16
+ handleFileChangeEvents(events: FileChangeEvent[]): void;
17
+ replayChangeEvents(): FileChangeEvent[];
16
18
  };
17
19
  interface IOpts {
18
20
  mfsu: MFSU;
@@ -23,7 +25,7 @@ export declare type Match = ReturnType<typeof checkMatch> & {
23
25
  version: string;
24
26
  };
25
27
  export declare class StaticDepInfo {
26
- private opts;
28
+ opts: IOpts;
27
29
  private readonly cacheFilePath;
28
30
  private mfsu;
29
31
  private readonly include;
@@ -44,7 +44,6 @@ var StaticDepInfo = class {
44
44
  this.cacheFilePath = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, "MFSU_CACHE_v4.json");
45
45
  this.cwd = this.mfsu.opts.cwd;
46
46
  opts.srcCodeCache.register((info) => {
47
- this.produced.push({ changes: info.events });
48
47
  this.currentDep = this._getDependencies(info.code, info.imports);
49
48
  });
50
49
  this.runtimeSimulations = [];
@@ -22,6 +22,7 @@ __export(buildDepPlugin_exports, {
22
22
  BuildDepPlugin: () => BuildDepPlugin
23
23
  });
24
24
  module.exports = __toCommonJS(buildDepPlugin_exports);
25
+ var import_utils = require("@umijs/utils");
25
26
  var PLUGIN_NAME = "MFSUBuildDeps";
26
27
  var BuildDepPlugin = class {
27
28
  constructor(opts) {
@@ -30,6 +31,7 @@ var BuildDepPlugin = class {
30
31
  apply(compiler) {
31
32
  compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, (c) => {
32
33
  var _a, _b;
34
+ import_utils.logger.debug("webpack watched change", "modified: ", c.modifiedFiles, "removed: ", c.removedFiles);
33
35
  return ((_b = (_a = this.opts).onFileChange) == null ? void 0 : _b.call(_a, c)) || Promise.resolve();
34
36
  });
35
37
  compiler.hooks.beforeCompile.tap(PLUGIN_NAME, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.29",
3
+ "version": "4.0.31",
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.29",
27
- "@umijs/bundler-utils": "4.0.29",
28
- "@umijs/utils": "4.0.29",
26
+ "@umijs/bundler-esbuild": "4.0.31",
27
+ "@umijs/bundler-utils": "4.0.31",
28
+ "@umijs/utils": "4.0.31",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },