@umijs/mfsu 4.0.0-rc.8 → 4.0.0-rc.9

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
@@ -1,6 +1,5 @@
1
1
  import type { NextFunction, Request, Response } from '@umijs/bundler-utils/compiled/express';
2
2
  import webpack, { Configuration } from 'webpack';
3
- import autoExport from './babelPlugins/autoExport';
4
3
  import awaitImport from './babelPlugins/awaitImport/awaitImport';
5
4
  import { DepBuilder } from './depBuilder/depBuilder';
6
5
  import { DepInfo } from './depInfo';
@@ -26,6 +25,7 @@ export declare class MFSU {
26
25
  depInfo: DepInfo;
27
26
  depBuilder: DepBuilder;
28
27
  depConfig: Configuration | null;
28
+ buildDepsAgain: boolean;
29
29
  constructor(opts: IOpts);
30
30
  asyncImport(content: string): string;
31
31
  setWebpackConfig(opts: {
@@ -35,7 +35,7 @@ export declare class MFSU {
35
35
  buildDeps(): Promise<void>;
36
36
  getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
37
37
  private getAwaitImportCollectOpts;
38
- getBabelPlugins(): (typeof autoExport | ({
38
+ getBabelPlugins(): ({
39
39
  onTransformDeps: () => void;
40
40
  onCollect: ({ file, data, }: {
41
41
  file: string;
@@ -53,7 +53,7 @@ export declare class MFSU {
53
53
  remoteName: string | undefined;
54
54
  alias: Record<string, string>;
55
55
  externals: (Function | Record<string, string>)[];
56
- } | typeof awaitImport)[])[];
56
+ } | typeof awaitImport)[][];
57
57
  getEsbuildLoaderHandler(): any[];
58
58
  }
59
59
  export {};
package/dist/mfsu.js CHANGED
@@ -21,24 +21,22 @@ const path_1 = require("path");
21
21
  const mrmime_1 = require("../compiled/mrmime");
22
22
  // @ts-ignore
23
23
  const webpack_virtual_modules_1 = __importDefault(require("../compiled/webpack-virtual-modules"));
24
- const autoExport_1 = __importDefault(require("./babelPlugins/autoExport"));
25
24
  const awaitImport_1 = __importDefault(require("./babelPlugins/awaitImport/awaitImport"));
26
25
  const getRealPath_1 = require("./babelPlugins/awaitImport/getRealPath");
27
26
  const constants_1 = require("./constants");
28
27
  const dep_1 = require("./dep/dep");
29
28
  const depBuilder_1 = require("./depBuilder/depBuilder");
30
29
  const depInfo_1 = require("./depInfo");
31
- const autoExport_2 = __importDefault(require("./esbuildHandlers/autoExport"));
32
30
  const awaitImport_2 = __importDefault(require("./esbuildHandlers/awaitImport"));
33
31
  const types_1 = require("./types");
34
32
  const makeArray_1 = require("./utils/makeArray");
35
33
  const buildDepPlugin_1 = require("./webpackPlugins/buildDepPlugin");
36
- const writeCachePlugin_1 = require("./webpackPlugins/writeCachePlugin");
37
34
  class MFSU {
38
35
  constructor(opts) {
39
36
  this.alias = {};
40
37
  this.externals = [];
41
38
  this.depConfig = null;
39
+ this.buildDepsAgain = false;
42
40
  this.opts = opts;
43
41
  this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
44
42
  this.opts.tmpBase =
@@ -162,16 +160,21 @@ promise new Promise(resolve => {
162
160
  }),
163
161
  new buildDepPlugin_1.BuildDepPlugin({
164
162
  onCompileDone: () => {
165
- this.buildDeps().catch((e) => {
166
- utils_1.logger.error(e);
167
- });
163
+ if (this.depBuilder.isBuilding) {
164
+ this.buildDepsAgain = true;
165
+ }
166
+ else {
167
+ this.buildDeps().catch((e) => {
168
+ utils_1.logger.error(e);
169
+ });
170
+ }
168
171
  },
169
172
  }),
170
- new writeCachePlugin_1.WriteCachePlugin({
171
- onWriteCache: utils_1.lodash.debounce(() => {
172
- this.depInfo.writeCache();
173
- }, 300),
174
- }),
173
+ // new WriteCachePlugin({
174
+ // onWriteCache: lodash.debounce(() => {
175
+ // this.depInfo.writeCache();
176
+ // }, 300),
177
+ // }),
175
178
  ]);
176
179
  // ensure topLevelAwait enabled
177
180
  utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
@@ -183,7 +186,8 @@ promise new Promise(resolve => {
183
186
  }
184
187
  buildDeps() {
185
188
  return __awaiter(this, void 0, void 0, function* () {
186
- if (!this.depInfo.shouldBuild()) {
189
+ const shouldBuild = this.depInfo.shouldBuild();
190
+ if (!shouldBuild) {
187
191
  utils_1.logger.info('MFSU skip buildDeps');
188
192
  return;
189
193
  }
@@ -193,11 +197,20 @@ promise new Promise(resolve => {
193
197
  cwd: this.opts.cwd,
194
198
  mfsu: this,
195
199
  });
196
- utils_1.logger.info('MFSU buildDeps');
200
+ utils_1.logger.info(`MFSU buildDeps since ${shouldBuild}`);
197
201
  utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
198
202
  yield this.depBuilder.build({
199
203
  deps,
200
204
  });
205
+ // Write cache
206
+ this.depInfo.writeCache();
207
+ if (this.buildDepsAgain) {
208
+ utils_1.logger.info('MFSU buildDepsAgain');
209
+ this.buildDepsAgain = false;
210
+ this.buildDeps().catch((e) => {
211
+ utils_1.logger.error(e);
212
+ });
213
+ }
201
214
  });
202
215
  }
203
216
  getMiddlewares() {
@@ -258,13 +271,12 @@ promise new Promise(resolve => {
258
271
  };
259
272
  }
260
273
  getBabelPlugins() {
261
- return [autoExport_1.default, [awaitImport_1.default, this.getAwaitImportCollectOpts()]];
274
+ return [[awaitImport_1.default, this.getAwaitImportCollectOpts()]];
262
275
  }
263
276
  getEsbuildLoaderHandler() {
264
277
  const cache = new Map();
265
278
  const checkOpts = this.getAwaitImportCollectOpts();
266
279
  return [
267
- autoExport_2.default,
268
280
  (0, awaitImport_2.default)({
269
281
  cache,
270
282
  opts: checkOpts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-rc.8",
3
+ "version": "4.0.0-rc.9",
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-rc.8",
26
- "@umijs/bundler-utils": "4.0.0-rc.8",
27
- "@umijs/utils": "4.0.0-rc.8",
25
+ "@umijs/bundler-esbuild": "4.0.0-rc.9",
26
+ "@umijs/bundler-utils": "4.0.0-rc.9",
27
+ "@umijs/utils": "4.0.0-rc.9",
28
28
  "enhanced-resolve": "5.9.2"
29
29
  },
30
30
  "devDependencies": {
@@ -1,7 +0,0 @@
1
- import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
- import * as t from '@umijs/bundler-utils/compiled/babel/types';
3
- export default function (): {
4
- visitor: {
5
- Program(path: Babel.NodePath<t.Program>): void;
6
- };
7
- };
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
27
- function default_1() {
28
- return {
29
- visitor: {
30
- Program(path) {
31
- let hasExport = false;
32
- path.node.body.forEach((node) => {
33
- if (
34
- // esm
35
- t.isExportNamedDeclaration(node) ||
36
- t.isExportDefaultDeclaration(node) ||
37
- t.isExportAllDeclaration(node) ||
38
- // cjs
39
- (t.isExpressionStatement(node) &&
40
- t.isAssignmentExpression(node.expression) &&
41
- t.isMemberExpression(node.expression.left) &&
42
- // exports.xxx =
43
- (t.isIdentifier(node.expression.left.object, {
44
- name: 'exports',
45
- }) ||
46
- // module.exports =
47
- (t.isIdentifier(node.expression.left.object, {
48
- name: 'module',
49
- }) &&
50
- t.isIdentifier(node.expression.left.property, {
51
- name: 'exports',
52
- }))))) {
53
- hasExport = true;
54
- }
55
- });
56
- if (!hasExport) {
57
- path.node.body.push(t.exportNamedDeclaration(t.variableDeclaration('const', [
58
- t.variableDeclarator(t.identifier('__mfsu'), t.numericLiteral(1)),
59
- ])));
60
- }
61
- },
62
- },
63
- };
64
- }
65
- exports.default = default_1;
@@ -1,6 +0,0 @@
1
- interface IOpts {
2
- exports: string[];
3
- code: string;
4
- }
5
- export default function autoExportHandler(opts: IOpts): string;
6
- export {};
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function autoExportHandler(opts) {
4
- if (!opts.exports.length) {
5
- return `${opts.code}\nexport const __mfsu = 1;`;
6
- }
7
- return opts.code;
8
- }
9
- exports.default = autoExportHandler;