@umijs/mfsu 4.0.0-beta.9 → 4.0.0-canary.202200505.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.
@@ -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];
@@ -1,12 +1,13 @@
1
1
  import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
2
  import type { IOpts } from './awaitImport';
3
- export declare function checkMatch({ value, path, opts, isExportAll, depth, cache, }: {
3
+ export declare function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }: {
4
4
  value: string;
5
5
  path?: Babel.NodePath;
6
6
  opts?: IOpts;
7
7
  isExportAll?: boolean;
8
8
  depth?: number;
9
9
  cache?: Map<string, any>;
10
+ filename?: string;
10
11
  }): {
11
12
  isMatch: boolean;
12
13
  replaceValue: string;
@@ -12,7 +12,10 @@ const isExternals_1 = require("./isExternals");
12
12
  // const UNMATCH_LIBS = ['umi', 'dumi', '@alipay/bigfish'];
13
13
  const RE_NODE_MODULES = /node_modules/;
14
14
  const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
15
- function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
15
+ function isUmiLocalDev(path) {
16
+ return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
17
+ }
18
+ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
16
19
  var _a, _b;
17
20
  let isMatch;
18
21
  let replaceValue = '';
@@ -20,9 +23,13 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
20
23
  (0, assert_1.default)(depth <= 10, `endless loop detected in checkMatch, please check your alias config.`);
21
24
  opts = opts || {};
22
25
  const remoteName = opts.remoteName || 'mf';
26
+ // FIXME: hard code for vite mode
27
+ value = value.replace(/^@fs\//, '/');
23
28
  if (
24
29
  // unMatch specified libs
25
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') ||
26
33
  // already handled
27
34
  value.startsWith(`${remoteName}/`) ||
28
35
  // don't match dynamic path
@@ -38,7 +45,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
38
45
  isMatch = false;
39
46
  }
40
47
  else if ((0, path_1.isAbsolute)(value)) {
41
- isMatch = RE_NODE_MODULES.test(value) || RE_UMI_LOCAL_DEV.test(value);
48
+ isMatch = RE_NODE_MODULES.test(value) || isUmiLocalDev(value);
42
49
  }
43
50
  else {
44
51
  const aliasedPath = (0, getAliasedPath_1.getAliasedPath)({
@@ -53,6 +60,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
53
60
  isExportAll,
54
61
  depth: depth + 1,
55
62
  cache,
63
+ filename,
56
64
  });
57
65
  }
58
66
  else {
@@ -63,10 +71,10 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
63
71
  isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
64
72
  }
65
73
  if (isMatch) {
66
- replaceValue = `${remoteName}/${value}`;
74
+ replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
67
75
  }
68
76
  // @ts-ignore
69
- const file = path === null || path === void 0 ? void 0 : path.hub.file.opts.filename;
77
+ const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
70
78
  (_b = opts.onTransformDeps) === null || _b === void 0 ? void 0 : _b.call(opts, {
71
79
  sourceValue: value,
72
80
  replaceValue,
@@ -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
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -24,70 +15,67 @@ const getExposeFromContent_1 = require("./getExposeFromContent");
24
15
  const resolver = enhanced_resolve_1.default.create({
25
16
  mainFields: ['module', 'browser', 'main'],
26
17
  extensions: ['.js', '.json', '.mjs'],
27
- // TODO: support exports
28
- // tried to add exports, but it don't work with swr
29
- exportsFields: [],
18
+ exportsFields: ['exports'],
19
+ conditionNames: ['import', 'module', 'require', 'node'],
30
20
  });
31
- function resolve(context, path) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise((resolve, reject) => {
34
- resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
35
- });
21
+ async function resolve(context, path) {
22
+ return new Promise((resolve, reject) => {
23
+ resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
36
24
  });
37
25
  }
38
26
  class Dep {
39
27
  constructor(opts) {
40
- this.file = opts.file;
28
+ this.file = (0, utils_1.winPath)(opts.file);
41
29
  this.version = opts.version;
42
30
  this.cwd = opts.cwd;
43
- this.shortFile = this.file.replace(this.cwd, '$CWD$');
31
+ this.shortFile = this.file;
44
32
  this.normalizedFile = this.shortFile.replace(/\//g, '_').replace(/:/g, '_');
45
33
  this.filePath = `${constants_1.MF_VA_PREFIX}${this.normalizedFile}.js`;
46
34
  this.mfsu = opts.mfsu;
47
35
  }
48
- buildExposeContent() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- // node natives
51
- // @ts-ignore
52
- const isNodeNatives = !!process.binding('natives')[this.file];
53
- if (isNodeNatives) {
54
- return (0, trimFileContent_1.trimFileContent)(this.mfsu.opts.excludeNodeNatives
55
- ? `
36
+ async buildExposeContent() {
37
+ // node natives
38
+ // @ts-ignore
39
+ const isNodeNatives = !!process.binding('natives')[this.file];
40
+ if (isNodeNatives) {
41
+ return (0, trimFileContent_1.trimFileContent)(this.mfsu.opts.excludeNodeNatives
42
+ ? `
56
43
  const _ = require('${this.file}');
57
44
  module.exports = _;
58
45
  `
59
- : `
46
+ : `
60
47
  import _ from '${this.file}';
61
48
  export default _;
62
49
  export * from '${this.file}';
63
50
  `);
64
- }
65
- // none node natives
66
- const realFile = yield this.getRealFile();
67
- (0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
68
- const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
69
- return yield (0, getExposeFromContent_1.getExposeFromContent)({
70
- content,
71
- filePath: realFile,
72
- dep: this,
73
- });
51
+ }
52
+ // none node natives
53
+ const realFile = await this.getRealFile();
54
+ (0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
55
+ const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
56
+ return await (0, getExposeFromContent_1.getExposeFromContent)({
57
+ content,
58
+ filePath: realFile,
59
+ dep: this,
74
60
  });
75
61
  }
76
- getRealFile() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- try {
79
- // don't need to handle alias here
80
- // it's already handled by babel plugin
81
- return yield resolve(this.cwd, this.file);
82
- }
83
- catch (e) {
84
- return null;
85
- }
86
- });
62
+ async getRealFile() {
63
+ try {
64
+ // don't need to handle alias here
65
+ // it's already handled by babel plugin
66
+ return await resolve(this.cwd, this.file);
67
+ }
68
+ catch (e) {
69
+ return null;
70
+ }
87
71
  }
88
72
  static buildDeps(opts) {
89
73
  return Object.keys(opts.deps).map((file) => {
90
- return new Dep(Object.assign(Object.assign({}, opts.deps[file]), { cwd: opts.cwd, mfsu: opts.mfsu }));
74
+ return new Dep({
75
+ ...opts.deps[file],
76
+ cwd: opts.cwd,
77
+ mfsu: opts.mfsu,
78
+ });
91
79
  });
92
80
  }
93
81
  static getDepVersion(opts) {
@@ -98,7 +86,7 @@ export * from '${this.file}';
98
86
  const dep = (0, path_1.isAbsolute)(opts.dep)
99
87
  ? opts.dep
100
88
  : (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
101
- const pkg = utils_1.pkgUp.sync({
89
+ const pkg = utils_1.pkgUp.pkgUpSync({
102
90
  cwd: dep,
103
91
  });
104
92
  (0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,62 +7,60 @@ exports.getExposeFromContent = void 0;
16
7
  const assert_1 = __importDefault(require("assert"));
17
8
  const path_1 = require("path");
18
9
  const getModuleExports_1 = require("./getModuleExports");
19
- function getExposeFromContent(opts) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- // Support CSS
22
- if (opts.filePath &&
23
- /\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
24
- return `import '${opts.dep.file}';`;
25
- }
26
- // Support Assets Files
27
- if (opts.filePath &&
28
- /\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(opts.filePath)) {
29
- return `
10
+ async function getExposeFromContent(opts) {
11
+ // Support CSS
12
+ if (opts.filePath &&
13
+ /\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
14
+ return `import '${opts.dep.file}';`;
15
+ }
16
+ // Support Assets Files
17
+ if (opts.filePath &&
18
+ /\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(opts.filePath)) {
19
+ return `
30
20
  import _ from '${opts.dep.file}';
31
21
  export default _;`.trim();
22
+ }
23
+ (0, assert_1.default)(/(js|jsx|mjs|ts|tsx)$/.test(opts.filePath), `file type not supported for ${(0, path_1.basename)(opts.filePath)}.`);
24
+ const { exports, isCJS } = await (0, getModuleExports_1.getModuleExports)({
25
+ content: opts.content,
26
+ filePath: opts.filePath,
27
+ });
28
+ // cjs
29
+ if (isCJS) {
30
+ return [
31
+ `import _ from '${opts.dep.file}';`,
32
+ `export default _;`,
33
+ `export * from '${opts.dep.file}';`,
34
+ ].join('\n');
35
+ }
36
+ // esm
37
+ else {
38
+ const ret = [];
39
+ let hasExports = false;
40
+ if (exports.includes('default')) {
41
+ ret.push(`import _ from '${opts.dep.file}';`);
42
+ ret.push(`export default _;`);
43
+ hasExports = true;
32
44
  }
33
- (0, assert_1.default)(/(js|jsx|mjs|ts|tsx)$/.test(opts.filePath), `file type not supported for ${(0, path_1.basename)(opts.filePath)}.`);
34
- const { exports, isCJS } = yield (0, getModuleExports_1.getModuleExports)({
35
- content: opts.content,
36
- filePath: opts.filePath,
37
- });
38
- // cjs
39
- if (isCJS) {
40
- return [
41
- `import _ from '${opts.dep.file}';`,
42
- `export default _;`,
43
- `export * from '${opts.dep.file}';`,
44
- ].join('\n');
45
+ if (hasNonDefaultExports(exports) ||
46
+ // export * from 不会有 exports,只会有 imports
47
+ /export\s+\*\s+from/.test(opts.content)) {
48
+ ret.push(`export * from '${opts.dep.file}';`);
49
+ hasExports = true;
45
50
  }
46
- // esm
47
- else {
48
- const ret = [];
49
- let hasExports = false;
50
- if (exports.includes('default')) {
51
+ if (!hasExports) {
52
+ // 只有 __esModule 的全量导出
53
+ if (exports.includes('__esModule')) {
51
54
  ret.push(`import _ from '${opts.dep.file}';`);
52
55
  ret.push(`export default _;`);
53
- hasExports = true;
54
- }
55
- if (hasNonDefaultExports(exports) ||
56
- // export * from 不会有 exports,只会有 imports
57
- /export\s+\*\s+from/.test(opts.content)) {
58
56
  ret.push(`export * from '${opts.dep.file}';`);
59
- hasExports = true;
60
57
  }
61
- if (!hasExports) {
62
- // 只有 __esModule 的全量导出
63
- if (exports.includes('__esModule')) {
64
- ret.push(`import _ from '${opts.dep.file}';`);
65
- ret.push(`export default _;`);
66
- ret.push(`export * from '${opts.dep.file}';`);
67
- }
68
- else {
69
- ret.push(`import '${opts.dep.file}';`);
70
- }
58
+ else {
59
+ ret.push(`import '${opts.dep.file}';`);
71
60
  }
72
- return ret.join('\n');
73
61
  }
74
- });
62
+ return ret.join('\n');
63
+ }
75
64
  }
76
65
  exports.getExposeFromContent = getExposeFromContent;
77
66
  function hasNonDefaultExports(exports) {
@@ -1,45 +1,34 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getModuleExports = void 0;
13
4
  const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
14
5
  const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
15
6
  const path_1 = require("path");
16
7
  const getCJSExports_1 = require("./getCJSExports");
17
- function getModuleExports({ content, filePath, }) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- // Support tsx and jsx
20
- if (filePath && /\.(tsx|jsx)$/.test(filePath)) {
21
- content = (yield (0, esbuild_1.transform)(content, {
22
- sourcemap: false,
23
- sourcefile: filePath,
24
- format: 'esm',
25
- target: 'es6',
26
- loader: (0, path_1.extname)(filePath).slice(1),
27
- })).code;
8
+ async function getModuleExports({ content, filePath, }) {
9
+ // Support tsx and jsx
10
+ if (filePath && /\.(tsx|jsx)$/.test(filePath)) {
11
+ content = (await (0, esbuild_1.transform)(content, {
12
+ sourcemap: false,
13
+ sourcefile: filePath,
14
+ format: 'esm',
15
+ target: 'es6',
16
+ loader: (0, path_1.extname)(filePath).slice(1),
17
+ })).code;
18
+ }
19
+ await es_module_lexer_1.init;
20
+ const [imports, exports] = (0, es_module_lexer_1.parse)(content);
21
+ let isCJS = !imports.length && !exports.length;
22
+ let cjsEsmExports = null;
23
+ if (isCJS) {
24
+ cjsEsmExports = (0, getCJSExports_1.getCJSExports)({ content });
25
+ if (cjsEsmExports.includes('__esModule')) {
26
+ isCJS = false;
28
27
  }
29
- yield es_module_lexer_1.init;
30
- const [imports, exports] = (0, es_module_lexer_1.parse)(content);
31
- let isCJS = !imports.length && !exports.length;
32
- let cjsEsmExports = null;
33
- if (isCJS) {
34
- cjsEsmExports = (0, getCJSExports_1.getCJSExports)({ content });
35
- if (cjsEsmExports.includes('__esModule')) {
36
- isCJS = false;
37
- }
38
- }
39
- return {
40
- exports: cjsEsmExports || exports,
41
- isCJS,
42
- };
43
- });
28
+ }
29
+ return {
30
+ exports: cjsEsmExports || exports,
31
+ isCJS,
32
+ };
44
33
  }
45
34
  exports.getModuleExports = getModuleExports;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.DepBuilder = void 0;
13
4
  const bundler_esbuild_1 = require("@umijs/bundler-esbuild");
@@ -24,72 +15,77 @@ class DepBuilder {
24
15
  this.isBuilding = false;
25
16
  this.opts = opts;
26
17
  }
27
- buildWithWebpack(opts) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const config = this.getWebpackConfig({ deps: opts.deps });
30
- return new Promise((resolve, reject) => {
31
- const compiler = this.opts.mfsu.opts.implementor(config);
32
- compiler.run((err, stats) => {
33
- opts.onBuildComplete();
34
- if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
35
- if (err) {
36
- reject(err);
37
- }
38
- if (stats) {
39
- const errorMsg = stats.toString('errors-only');
40
- // console.error(errorMsg);
41
- reject(new Error(errorMsg));
42
- }
18
+ async buildWithWebpack(opts) {
19
+ const config = this.getWebpackConfig({ deps: opts.deps });
20
+ return new Promise((resolve, reject) => {
21
+ const compiler = this.opts.mfsu.opts.implementor(config);
22
+ compiler.run((err, stats) => {
23
+ opts.onBuildComplete();
24
+ if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
25
+ if (err) {
26
+ reject(err);
43
27
  }
44
- else {
45
- resolve(stats);
28
+ if (stats) {
29
+ const errorMsg = stats.toString('errors-only');
30
+ // console.error(errorMsg);
31
+ reject(new Error(errorMsg));
46
32
  }
47
- compiler.close(() => { });
48
- });
33
+ }
34
+ else {
35
+ resolve(stats);
36
+ }
37
+ compiler.close(() => { });
49
38
  });
50
39
  });
51
40
  }
52
41
  // TODO: support watch and rebuild
53
- buildWithESBuild(opts) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const entryContent = (0, getESBuildEntry_1.getESBuildEntry)({ deps: opts.deps });
56
- const ENTRY_FILE = 'esbuild-entry.js';
57
- const tmpDir = this.opts.mfsu.opts.tmpBase;
58
- const entryPath = (0, path_1.join)(tmpDir, ENTRY_FILE);
59
- (0, fs_1.writeFileSync)(entryPath, entryContent, 'utf-8');
60
- const date = new Date().getTime();
61
- yield (0, bundler_esbuild_1.build)({
62
- cwd: this.opts.mfsu.opts.cwd,
63
- entry: {
64
- [`${constants_1.MF_VA_PREFIX}remoteEntry`]: entryPath,
65
- },
66
- config: {
67
- outputPath: tmpDir,
68
- alias: this.opts.mfsu.alias,
69
- externals: this.opts.mfsu.externals,
70
- },
71
- inlineStyle: true,
72
- });
73
- utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
74
- opts.onBuildComplete();
42
+ async buildWithESBuild(opts) {
43
+ const entryContent = (0, getESBuildEntry_1.getESBuildEntry)({ deps: opts.deps });
44
+ const ENTRY_FILE = 'esbuild-entry.js';
45
+ const tmpDir = this.opts.mfsu.opts.tmpBase;
46
+ const entryPath = (0, path_1.join)(tmpDir, ENTRY_FILE);
47
+ (0, fs_1.writeFileSync)(entryPath, entryContent, 'utf-8');
48
+ const date = new Date().getTime();
49
+ await (0, bundler_esbuild_1.build)({
50
+ cwd: this.opts.mfsu.opts.cwd,
51
+ entry: {
52
+ [`${constants_1.MF_VA_PREFIX}remoteEntry`]: entryPath,
53
+ },
54
+ config: {
55
+ ...this.opts.mfsu.opts.depBuildConfig,
56
+ outputPath: tmpDir,
57
+ alias: this.opts.mfsu.alias,
58
+ externals: this.opts.mfsu.externals,
59
+ },
60
+ inlineStyle: true,
75
61
  });
62
+ utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
63
+ opts.onBuildComplete();
76
64
  }
77
- build(opts) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- this.isBuilding = true;
80
- yield this.writeMFFiles({ deps: opts.deps });
81
- const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
82
- this.isBuilding = false;
83
- this.completeFns.forEach((fn) => fn());
84
- this.completeFns = [];
85
- } });
65
+ async build(opts) {
66
+ this.isBuilding = true;
67
+ const onBuildComplete = () => {
68
+ this.isBuilding = false;
69
+ this.completeFns.forEach((fn) => fn());
70
+ this.completeFns = [];
71
+ };
72
+ try {
73
+ await this.writeMFFiles({ deps: opts.deps });
74
+ const newOpts = {
75
+ ...opts,
76
+ onBuildComplete,
77
+ };
86
78
  if (this.opts.mfsu.opts.buildDepWithESBuild) {
87
- yield this.buildWithESBuild(newOpts);
79
+ await this.buildWithESBuild(newOpts);
88
80
  }
89
81
  else {
90
- yield this.buildWithWebpack(newOpts);
82
+ await this.buildWithWebpack(newOpts);
91
83
  }
92
- });
84
+ }
85
+ catch (e) {
86
+ onBuildComplete();
87
+ throw e;
88
+ }
93
89
  }
94
90
  onBuildComplete(fn) {
95
91
  if (this.isBuilding) {
@@ -99,17 +95,16 @@ class DepBuilder {
99
95
  fn();
100
96
  }
101
97
  }
102
- writeMFFiles(opts) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- const tmpBase = this.opts.mfsu.opts.tmpBase;
105
- // expose files
106
- for (const dep of opts.deps) {
107
- const content = yield dep.buildExposeContent();
108
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
109
- }
110
- // index file
111
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"😛"', 'utf-8');
112
- });
98
+ async writeMFFiles(opts) {
99
+ const tmpBase = this.opts.mfsu.opts.tmpBase;
100
+ utils_1.fsExtra.mkdirpSync(tmpBase);
101
+ // expose files
102
+ for (const dep of opts.deps) {
103
+ const content = await dep.buildExposeContent();
104
+ (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
105
+ }
106
+ // index file
107
+ (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"😛"', 'utf-8');
113
108
  }
114
109
  getWebpackConfig(opts) {
115
110
  var _a, _b;
@@ -147,8 +142,11 @@ class DepBuilder {
147
142
  depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
148
143
  webpack: this.opts.mfsu.opts.implementor,
149
144
  }));
145
+ depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
146
+ this.opts.mfsu.onProgress({ percent, status: msg });
147
+ }));
150
148
  const exposes = opts.deps.reduce((memo, dep) => {
151
- memo[`./${dep.shortFile}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
149
+ memo[`./${dep.file}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
152
150
  return memo;
153
151
  }, {});
154
152
  depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({