@umijs/mfsu 4.0.0-canary.20220317.1 → 4.0.0-canary.20220323.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.
@@ -28,6 +28,8 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, })
28
28
  if (
29
29
  // unMatch specified libs
30
30
  ((_a = opts.unMatchLibs) === null || _a === void 0 ? void 0 : _a.includes(value)) ||
31
+ // do not match bundler-webpack/client/client/client.js
32
+ value.includes('client/client/client.js') ||
31
33
  // already handled
32
34
  value.startsWith(`${remoteName}/`) ||
33
35
  // don't match dynamic path
@@ -73,17 +73,24 @@ class DepBuilder {
73
73
  build(opts) {
74
74
  return __awaiter(this, void 0, void 0, function* () {
75
75
  this.isBuilding = true;
76
- yield this.writeMFFiles({ deps: opts.deps });
77
- const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
78
- this.isBuilding = false;
79
- this.completeFns.forEach((fn) => fn());
80
- this.completeFns = [];
81
- } });
82
- if (this.opts.mfsu.opts.buildDepWithESBuild) {
83
- yield this.buildWithESBuild(newOpts);
76
+ const onBuildComplete = () => {
77
+ this.isBuilding = false;
78
+ this.completeFns.forEach((fn) => fn());
79
+ this.completeFns = [];
80
+ };
81
+ try {
82
+ yield this.writeMFFiles({ deps: opts.deps });
83
+ const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete });
84
+ if (this.opts.mfsu.opts.buildDepWithESBuild) {
85
+ yield this.buildWithESBuild(newOpts);
86
+ }
87
+ else {
88
+ yield this.buildWithWebpack(newOpts);
89
+ }
84
90
  }
85
- else {
86
- yield this.buildWithWebpack(newOpts);
91
+ catch (e) {
92
+ onBuildComplete();
93
+ throw e;
87
94
  }
88
95
  });
89
96
  }
package/dist/depInfo.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare class DepInfo {
9
9
  moduleGraph: ModuleGraph;
10
10
  cacheDependency: object;
11
11
  constructor(opts: IOpts);
12
- shouldBuild(): boolean;
12
+ shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
13
13
  snapshot(): void;
14
14
  loadCache(): void;
15
15
  writeCache(): void;
package/dist/depInfo.js CHANGED
@@ -14,10 +14,10 @@ class DepInfo {
14
14
  }
15
15
  shouldBuild() {
16
16
  if (!utils_1.lodash.isEqual(this.cacheDependency, this.opts.mfsu.opts.getCacheDependency())) {
17
- return true;
17
+ return 'cacheDependency has changed';
18
18
  }
19
19
  if (this.moduleGraph.hasDepChanged()) {
20
- return true;
20
+ return 'moduleGraph has changed';
21
21
  }
22
22
  return false;
23
23
  }
@@ -35,11 +35,16 @@ class DepInfo {
35
35
  }
36
36
  writeCache() {
37
37
  utils_1.fsExtra.mkdirpSync((0, path_1.dirname)(this.cacheFilePath));
38
- utils_1.logger.info('MFSU write cache');
39
- (0, fs_1.writeFileSync)(this.cacheFilePath, JSON.stringify({
38
+ const newContent = JSON.stringify({
40
39
  cacheDependency: this.cacheDependency,
41
40
  moduleGraph: this.moduleGraph.toJSON(),
42
- }, null, 2), 'utf-8');
41
+ }, null, 2);
42
+ if ((0, fs_1.existsSync)(this.cacheFilePath) &&
43
+ (0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8') === newContent) {
44
+ return;
45
+ }
46
+ utils_1.logger.info('MFSU write cache');
47
+ (0, fs_1.writeFileSync)(this.cacheFilePath, newContent, 'utf-8');
43
48
  }
44
49
  }
45
50
  exports.DepInfo = DepInfo;
package/dist/mfsu.d.ts CHANGED
@@ -26,6 +26,7 @@ export declare class MFSU {
26
26
  depInfo: DepInfo;
27
27
  depBuilder: DepBuilder;
28
28
  depConfig: Configuration | null;
29
+ buildDepsAgain: boolean;
29
30
  constructor(opts: IOpts);
30
31
  asyncImport(content: string): string;
31
32
  setWebpackConfig(opts: {
package/dist/mfsu.js CHANGED
@@ -33,12 +33,12 @@ const awaitImport_2 = __importDefault(require("./esbuildHandlers/awaitImport"));
33
33
  const types_1 = require("./types");
34
34
  const makeArray_1 = require("./utils/makeArray");
35
35
  const buildDepPlugin_1 = require("./webpackPlugins/buildDepPlugin");
36
- const writeCachePlugin_1 = require("./webpackPlugins/writeCachePlugin");
37
36
  class MFSU {
38
37
  constructor(opts) {
39
38
  this.alias = {};
40
39
  this.externals = [];
41
40
  this.depConfig = null;
41
+ this.buildDepsAgain = false;
42
42
  this.opts = opts;
43
43
  this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
44
44
  this.opts.tmpBase =
@@ -162,16 +162,21 @@ promise new Promise(resolve => {
162
162
  }),
163
163
  new buildDepPlugin_1.BuildDepPlugin({
164
164
  onCompileDone: () => {
165
- this.buildDeps().catch((e) => {
166
- utils_1.logger.error(e);
167
- });
165
+ if (this.depBuilder.isBuilding) {
166
+ this.buildDepsAgain = true;
167
+ }
168
+ else {
169
+ this.buildDeps().catch((e) => {
170
+ utils_1.logger.error(e);
171
+ });
172
+ }
168
173
  },
169
174
  }),
170
- new writeCachePlugin_1.WriteCachePlugin({
171
- onWriteCache: utils_1.lodash.debounce(() => {
172
- this.depInfo.writeCache();
173
- }, 300),
174
- }),
175
+ // new WriteCachePlugin({
176
+ // onWriteCache: lodash.debounce(() => {
177
+ // this.depInfo.writeCache();
178
+ // }, 300),
179
+ // }),
175
180
  ]);
176
181
  // ensure topLevelAwait enabled
177
182
  utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
@@ -183,7 +188,8 @@ promise new Promise(resolve => {
183
188
  }
184
189
  buildDeps() {
185
190
  return __awaiter(this, void 0, void 0, function* () {
186
- if (!this.depInfo.shouldBuild()) {
191
+ const shouldBuild = this.depInfo.shouldBuild();
192
+ if (!shouldBuild) {
187
193
  utils_1.logger.info('MFSU skip buildDeps');
188
194
  return;
189
195
  }
@@ -193,11 +199,20 @@ promise new Promise(resolve => {
193
199
  cwd: this.opts.cwd,
194
200
  mfsu: this,
195
201
  });
196
- utils_1.logger.info('MFSU buildDeps');
202
+ utils_1.logger.info(`MFSU buildDeps since ${shouldBuild}`);
197
203
  utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
198
204
  yield this.depBuilder.build({
199
205
  deps,
200
206
  });
207
+ // Write cache
208
+ this.depInfo.writeCache();
209
+ if (this.buildDepsAgain) {
210
+ utils_1.logger.info('MFSU buildDepsAgain');
211
+ this.buildDepsAgain = false;
212
+ this.buildDeps().catch((e) => {
213
+ utils_1.logger.error(e);
214
+ });
215
+ }
201
216
  });
202
217
  }
203
218
  getMiddlewares() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-canary.20220317.1",
3
+ "version": "4.0.0-canary.20220323.1",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -22,9 +22,9 @@
22
22
  "test": "jest -c ../../jest.turbo.config.ts"
23
23
  },
24
24
  "dependencies": {
25
- "@umijs/bundler-esbuild": "4.0.0-canary.20220317.1",
26
- "@umijs/bundler-utils": "4.0.0-canary.20220317.1",
27
- "@umijs/utils": "4.0.0-canary.20220317.1",
25
+ "@umijs/bundler-esbuild": "4.0.0-canary.20220323.1",
26
+ "@umijs/bundler-utils": "4.0.0-canary.20220323.1",
27
+ "@umijs/utils": "4.0.0-canary.20220323.1",
28
28
  "enhanced-resolve": "5.9.2"
29
29
  },
30
30
  "devDependencies": {