@umijs/mfsu 4.0.0-rc.1 → 4.0.0-rc.12

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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -13,7 +13,7 @@ const isExternals_1 = require("./isExternals");
13
13
  const RE_NODE_MODULES = /node_modules/;
14
14
  const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
15
15
  function isUmiLocalDev(path) {
16
- return RE_UMI_LOCAL_DEV.test(path);
16
+ return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
17
17
  }
18
18
  function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
19
19
  var _a, _b;
@@ -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
@@ -69,7 +71,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, })
69
71
  isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
70
72
  }
71
73
  if (isMatch) {
72
- replaceValue = `${remoteName}/${value}`;
74
+ replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
73
75
  }
74
76
  // @ts-ignore
75
77
  const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAliasedPath = void 0;
4
- const path_1 = require("path");
5
4
  function getAliasedPath({ value, alias, }) {
6
5
  const importValue = value;
6
+ // equal alias
7
+ if (alias[value]) {
8
+ return alias[value];
9
+ }
7
10
  for (const key of Object.keys(alias)) {
8
11
  const aliasValue = alias[key];
9
12
  // exact alias
@@ -15,21 +18,13 @@ function getAliasedPath({ value, alias, }) {
15
18
  else
16
19
  continue;
17
20
  }
18
- // e.g. foo: path/to/foo
19
- if (importValue === key) {
20
- return aliasValue;
21
- }
22
21
  // e.g. foo: path/to/foo.js
23
- const slashedKey = isJSFile(aliasValue) ? key : addLastSlash(key);
24
- if (importValue.startsWith(slashedKey)) {
22
+ if (importValue.startsWith(addLastSlash(key))) {
25
23
  return importValue.replace(key, aliasValue);
26
24
  }
27
25
  }
28
26
  }
29
27
  exports.getAliasedPath = getAliasedPath;
30
- function isJSFile(path) {
31
- return ['.js', '.jsx', '.ts', '.tsx'].includes((0, path_1.extname)(path));
32
- }
33
28
  function addLastSlash(path) {
34
29
  return path.endsWith('/') ? path : `${path}/`;
35
30
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/dep/dep.js CHANGED
@@ -24,9 +24,8 @@ const getExposeFromContent_1 = require("./getExposeFromContent");
24
24
  const resolver = enhanced_resolve_1.default.create({
25
25
  mainFields: ['module', 'browser', 'main'],
26
26
  extensions: ['.js', '.json', '.mjs'],
27
- // TODO: support exports
28
- // tried to add exports, but it don't work with swr
29
- exportsFields: [],
27
+ exportsFields: ['exports'],
28
+ conditionNames: ['import', 'module', 'require', 'node'],
30
29
  });
31
30
  function resolve(context, path) {
32
31
  return __awaiter(this, void 0, void 0, function* () {
@@ -37,7 +36,7 @@ function resolve(context, path) {
37
36
  }
38
37
  class Dep {
39
38
  constructor(opts) {
40
- this.file = opts.file;
39
+ this.file = (0, utils_1.winPath)(opts.file);
41
40
  this.version = opts.version;
42
41
  this.cwd = opts.cwd;
43
42
  this.shortFile = this.file;
@@ -98,7 +97,7 @@ export * from '${this.file}';
98
97
  const dep = (0, path_1.isAbsolute)(opts.dep)
99
98
  ? opts.dep
100
99
  : (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
101
- const pkg = utils_1.pkgUp.sync({
100
+ const pkg = utils_1.pkgUp.pkgUpSync({
102
101
  cwd: dep,
103
102
  });
104
103
  (0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
@@ -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
  }
@@ -144,6 +151,9 @@ class DepBuilder {
144
151
  depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
145
152
  webpack: this.opts.mfsu.opts.implementor,
146
153
  }));
154
+ depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
155
+ this.opts.mfsu.onProgress({ percent, status: msg });
156
+ }));
147
157
  const exposes = opts.deps.reduce((memo, dep) => {
148
158
  memo[`./${dep.file}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
149
159
  return memo;
@@ -2,6 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getESBuildEntry = void 0;
4
4
  const constants_1 = require("../constants");
5
+ // from typescript `esModuleInterop`
6
+ const ES_INTEROP_FUNC = `__exportStar`;
7
+ const ES_INTEROP_HELPER = `
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var ${ES_INTEROP_FUNC} = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ `;
5
19
  function getESBuildEntry(opts) {
6
20
  return `
7
21
  (function() {
@@ -266,6 +280,7 @@ function getESBuildEntry(opts) {
266
280
  var __webpack_exports__ = {};
267
281
  (function() {
268
282
  var exports = __webpack_exports__;
283
+ ${ES_INTEROP_HELPER}
269
284
  var moduleMap = {
270
285
  ${opts.deps.map(getDepModuleStr).join(',\n')}
271
286
  };
@@ -299,15 +314,13 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
299
314
  `;
300
315
  }
301
316
  exports.getESBuildEntry = getESBuildEntry;
302
- function normalizeFile(file) {
303
- return file.replace(/\//g, '_');
304
- }
305
317
  function getDepModuleStr(dep) {
306
318
  return `
307
319
  "./${dep.file}": function() {
308
320
  return new Promise(resolve => {
309
- import('./${constants_1.MF_VA_PREFIX}${normalizeFile(dep.file)}.js').then(module => {
310
- resolve(() => module);
321
+ import('./${constants_1.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
322
+ module.default && ${ES_INTEROP_FUNC}(module, module.default);
323
+ resolve(() => module.default || module);
311
324
  });
312
325
  })
313
326
  }
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;
@@ -0,0 +1,2 @@
1
+ import { IEsbuildLoaderHandlerParams } from '../types';
2
+ export declare function autoCssModulesHandler(opts: IEsbuildLoaderHandlerParams): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoCssModulesHandler = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ const CSS_MODULES_QUERY = '?modules';
6
+ const QUERY_LENGTH = CSS_MODULES_QUERY.length;
7
+ function autoCssModulesHandler(opts) {
8
+ let { code } = opts;
9
+ let offset = 0;
10
+ opts.imports.forEach((i) => {
11
+ if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
12
+ // import x from './index.less'
13
+ // => import x from '
14
+ const importSegment = code.substring(i.ss + offset, i.s + offset);
15
+ // is css module
16
+ if (~importSegment.indexOf(' from')) {
17
+ code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
18
+ offset += QUERY_LENGTH;
19
+ }
20
+ }
21
+ });
22
+ return code;
23
+ }
24
+ exports.autoCssModulesHandler = autoCssModulesHandler;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './constants';
2
+ export * from './esbuildHandlers/autoCssModules';
3
+ export { esbuildLoader } from './loader/esbuild';
2
4
  export * from './mfsu';
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.esbuildLoader = void 0;
13
18
  __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./esbuildHandlers/autoCssModules"), exports);
20
+ // for independent use `esbuild-loader`
21
+ var esbuild_1 = require("./loader/esbuild");
22
+ Object.defineProperty(exports, "esbuildLoader", { enumerable: true, get: function () { return esbuild_1.esbuildLoader; } });
14
23
  __exportStar(require("./mfsu"), exports);
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ import type { IEsbuildLoaderOpts } from '../types';
3
+ declare function esbuildTranspiler(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
4
+ export default esbuildTranspiler;
5
+ export declare const esbuildLoader: string;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.esbuildLoader = void 0;
24
+ const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
25
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
26
+ const path_1 = require("path");
27
+ function esbuildTranspiler(source) {
28
+ var _a;
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const done = this.async();
31
+ const options = this.getOptions();
32
+ const { handler = [], implementation } = options, otherOptions = __rest(options, ["handler", "implementation"]);
33
+ const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
34
+ const filePath = this.resourcePath;
35
+ const ext = (0, path_1.extname)(filePath).slice(1);
36
+ const transformOptions = Object.assign(Object.assign({}, otherOptions), { target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015', loader: ext !== null && ext !== void 0 ? ext : 'js', sourcemap: this.sourceMap, sourcefile: filePath });
37
+ try {
38
+ let { code, map } = yield transform(source, transformOptions);
39
+ if (handler.length) {
40
+ yield es_module_lexer_1.init;
41
+ handler.forEach((handle) => {
42
+ const [imports, exports] = (0, es_module_lexer_1.parse)(code);
43
+ code = handle({ code, imports, exports, filePath });
44
+ });
45
+ }
46
+ done(null, code, map && JSON.parse(map));
47
+ }
48
+ catch (error) {
49
+ done(error);
50
+ }
51
+ });
52
+ }
53
+ exports.default = esbuildTranspiler;
54
+ exports.esbuildLoader = __filename;
package/dist/mfsu.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import type { NextFunction, Request, Response } from 'express';
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';
@@ -10,6 +9,7 @@ interface IOpts {
10
9
  excludeNodeNatives?: boolean;
11
10
  exportAllMembers?: Record<string, string[]>;
12
11
  getCacheDependency?: Function;
12
+ onMFSUProgress?: Function;
13
13
  mfName?: string;
14
14
  mode?: Mode;
15
15
  tmpBase?: string;
@@ -26,6 +26,9 @@ export declare class MFSU {
26
26
  depInfo: DepInfo;
27
27
  depBuilder: DepBuilder;
28
28
  depConfig: Configuration | null;
29
+ buildDepsAgain: boolean;
30
+ progress: any;
31
+ onProgress: Function;
29
32
  constructor(opts: IOpts);
30
33
  asyncImport(content: string): string;
31
34
  setWebpackConfig(opts: {
@@ -35,7 +38,7 @@ export declare class MFSU {
35
38
  buildDeps(): Promise<void>;
36
39
  getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
37
40
  private getAwaitImportCollectOpts;
38
- getBabelPlugins(): (typeof autoExport | ({
41
+ getBabelPlugins(): ({
39
42
  onTransformDeps: () => void;
40
43
  onCollect: ({ file, data, }: {
41
44
  file: string;
@@ -53,7 +56,7 @@ export declare class MFSU {
53
56
  remoteName: string | undefined;
54
57
  alias: Record<string, string>;
55
58
  externals: (Function | Record<string, string>)[];
56
- } | typeof awaitImport)[])[];
59
+ } | typeof awaitImport)[][];
57
60
  getEsbuildLoaderHandler(): any[];
58
61
  }
59
62
  export {};
package/dist/mfsu.js CHANGED
@@ -21,30 +21,34 @@ 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;
40
+ this.progress = { done: false };
42
41
  this.opts = opts;
43
42
  this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
44
43
  this.opts.tmpBase =
45
44
  this.opts.tmpBase || (0, path_1.join)(process.cwd(), constants_1.DEFAULT_TMP_DIR_NAME);
46
45
  this.opts.mode = this.opts.mode || types_1.Mode.development;
47
46
  this.opts.getCacheDependency = this.opts.getCacheDependency || (() => ({}));
47
+ this.onProgress = (progress) => {
48
+ var _a, _b;
49
+ this.progress = Object.assign(Object.assign({}, this.progress), progress);
50
+ (_b = (_a = this.opts).onMFSUProgress) === null || _b === void 0 ? void 0 : _b.call(_a, this.progress);
51
+ };
48
52
  this.opts.cwd = this.opts.cwd || process.cwd();
49
53
  this.depInfo = new depInfo_1.DepInfo({ mfsu: this });
50
54
  this.depBuilder = new depBuilder_1.DepBuilder({ mfsu: this });
@@ -53,7 +57,7 @@ class MFSU {
53
57
  // swc don't support top-level await
54
58
  // ref: https://github.com/vercel/next.js/issues/31054
55
59
  asyncImport(content) {
56
- return `await import('${content}');`;
60
+ return `await import('${(0, utils_1.winPath)(content)}');`;
57
61
  // return `(async () => await import('${content}'))();`;
58
62
  }
59
63
  setWebpackConfig(opts) {
@@ -162,16 +166,30 @@ promise new Promise(resolve => {
162
166
  }),
163
167
  new buildDepPlugin_1.BuildDepPlugin({
164
168
  onCompileDone: () => {
165
- this.buildDeps().catch((e) => {
166
- utils_1.logger.error(e);
167
- });
169
+ if (this.depBuilder.isBuilding) {
170
+ this.buildDepsAgain = true;
171
+ }
172
+ else {
173
+ this.buildDeps()
174
+ .then(() => {
175
+ this.onProgress({
176
+ done: true,
177
+ });
178
+ })
179
+ .catch((e) => {
180
+ utils_1.logger.error(e);
181
+ this.onProgress({
182
+ done: true,
183
+ });
184
+ });
185
+ }
168
186
  },
169
187
  }),
170
- new writeCachePlugin_1.WriteCachePlugin({
171
- onWriteCache: utils_1.lodash.debounce(() => {
172
- this.depInfo.writeCache();
173
- }, 300),
174
- }),
188
+ // new WriteCachePlugin({
189
+ // onWriteCache: lodash.debounce(() => {
190
+ // this.depInfo.writeCache();
191
+ // }, 300),
192
+ // }),
175
193
  ]);
176
194
  // ensure topLevelAwait enabled
177
195
  utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
@@ -183,7 +201,8 @@ promise new Promise(resolve => {
183
201
  }
184
202
  buildDeps() {
185
203
  return __awaiter(this, void 0, void 0, function* () {
186
- if (!this.depInfo.shouldBuild()) {
204
+ const shouldBuild = this.depInfo.shouldBuild();
205
+ if (!shouldBuild) {
187
206
  utils_1.logger.info('MFSU skip buildDeps');
188
207
  return;
189
208
  }
@@ -193,11 +212,20 @@ promise new Promise(resolve => {
193
212
  cwd: this.opts.cwd,
194
213
  mfsu: this,
195
214
  });
196
- utils_1.logger.info('MFSU buildDeps');
215
+ utils_1.logger.info(`MFSU buildDeps since ${shouldBuild}`);
197
216
  utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
198
217
  yield this.depBuilder.build({
199
218
  deps,
200
219
  });
220
+ // Write cache
221
+ this.depInfo.writeCache();
222
+ if (this.buildDepsAgain) {
223
+ utils_1.logger.info('MFSU buildDepsAgain');
224
+ this.buildDepsAgain = false;
225
+ this.buildDeps().catch((e) => {
226
+ utils_1.logger.error(e);
227
+ });
228
+ }
201
229
  });
202
230
  }
203
231
  getMiddlewares() {
@@ -258,13 +286,12 @@ promise new Promise(resolve => {
258
286
  };
259
287
  }
260
288
  getBabelPlugins() {
261
- return [autoExport_1.default, [awaitImport_1.default, this.getAwaitImportCollectOpts()]];
289
+ return [[awaitImport_1.default, this.getAwaitImportCollectOpts()]];
262
290
  }
263
291
  getEsbuildLoaderHandler() {
264
292
  const cache = new Map();
265
293
  const checkOpts = this.getAwaitImportCollectOpts();
266
294
  return [
267
- autoExport_2.default,
268
295
  (0, awaitImport_2.default)({
269
296
  cache,
270
297
  opts: checkOpts,
package/dist/types.d.ts CHANGED
@@ -1,4 +1,16 @@
1
+ import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
2
+ import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
1
3
  export declare enum Mode {
2
4
  development = "development",
3
5
  production = "production"
4
6
  }
7
+ export interface IEsbuildLoaderHandlerParams {
8
+ code: string;
9
+ filePath: string;
10
+ imports: readonly ImportSpecifier[];
11
+ exports: readonly string[];
12
+ }
13
+ export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
14
+ handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
15
+ implementation?: typeof import('@umijs/bundler-utils/compiled/esbuild');
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.12",
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",
@@ -18,18 +18,18 @@
18
18
  "scripts": {
19
19
  "build": "pnpm tsc",
20
20
  "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
21
- "dev": "pnpm build -- --watch"
21
+ "dev": "pnpm build -- --watch",
22
+ "test": "jest -c ../../jest.turbo.config.ts"
22
23
  },
23
24
  "dependencies": {
24
- "@umijs/bundler-esbuild": "4.0.0-rc.1",
25
- "@umijs/bundler-utils": "4.0.0-rc.1",
26
- "@umijs/utils": "4.0.0-rc.1"
25
+ "@umijs/bundler-esbuild": "4.0.0-rc.12",
26
+ "@umijs/bundler-utils": "4.0.0-rc.12",
27
+ "@umijs/utils": "4.0.0-rc.12",
28
+ "enhanced-resolve": "5.9.2"
27
29
  },
28
30
  "devDependencies": {
29
- "@types/express": "4.17.13",
30
- "enhanced-resolve": "5.8.3",
31
31
  "mrmime": "1.0.0",
32
- "webpack": "5.64.4",
32
+ "webpack": "5.72.0",
33
33
  "webpack-virtual-modules": "0.4.3"
34
34
  },
35
35
  "publishConfig": {
@@ -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,61 +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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
23
- function default_1() {
24
- return {
25
- visitor: {
26
- Program(path) {
27
- let hasExport = false;
28
- path.node.body.forEach((node) => {
29
- if (
30
- // esm
31
- t.isExportNamedDeclaration(node) ||
32
- t.isExportDefaultDeclaration(node) ||
33
- t.isExportAllDeclaration(node) ||
34
- // cjs
35
- (t.isExpressionStatement(node) &&
36
- t.isAssignmentExpression(node.expression) &&
37
- t.isMemberExpression(node.expression.left) &&
38
- // exports.xxx =
39
- (t.isIdentifier(node.expression.left.object, {
40
- name: 'exports',
41
- }) ||
42
- // module.exports =
43
- (t.isIdentifier(node.expression.left.object, {
44
- name: 'module',
45
- }) &&
46
- t.isIdentifier(node.expression.left.property, {
47
- name: 'exports',
48
- }))))) {
49
- hasExport = true;
50
- }
51
- });
52
- if (!hasExport) {
53
- path.node.body.push(t.exportNamedDeclaration(t.variableDeclaration('const', [
54
- t.variableDeclarator(t.identifier('__mfsu'), t.numericLiteral(1)),
55
- ])));
56
- }
57
- },
58
- },
59
- };
60
- }
61
- 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;