@umijs/mfsu 4.0.0-rc.2 → 4.0.0-rc.22

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];
@@ -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
@@ -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
  };
@@ -23,16 +14,13 @@ const trimFileContent_1 = require("../utils/trimFileContent");
23
14
  const getExposeFromContent_1 = require("./getExposeFromContent");
24
15
  const resolver = enhanced_resolve_1.default.create({
25
16
  mainFields: ['module', 'browser', 'main'],
26
- extensions: ['.js', '.json', '.mjs'],
27
- // TODO: support exports
28
- // tried to add exports, but it don't work with swr
29
- exportsFields: [],
17
+ extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
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 {
@@ -45,49 +33,49 @@ class Dep {
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) {
@@ -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,68 +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: Object.assign(Object.assign({}, this.opts.mfsu.opts.depBuildConfig), { outputPath: tmpDir, alias: this.opts.mfsu.alias, externals: this.opts.mfsu.externals }),
67
- inlineStyle: true,
68
- });
69
- utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
70
- 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,
71
61
  });
62
+ utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
63
+ opts.onBuildComplete();
72
64
  }
73
- build(opts) {
74
- return __awaiter(this, void 0, void 0, function* () {
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
- } });
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
+ };
82
78
  if (this.opts.mfsu.opts.buildDepWithESBuild) {
83
- yield this.buildWithESBuild(newOpts);
79
+ await this.buildWithESBuild(newOpts);
84
80
  }
85
81
  else {
86
- yield this.buildWithWebpack(newOpts);
82
+ await this.buildWithWebpack(newOpts);
87
83
  }
88
- });
84
+ }
85
+ catch (e) {
86
+ onBuildComplete();
87
+ throw e;
88
+ }
89
89
  }
90
90
  onBuildComplete(fn) {
91
91
  if (this.isBuilding) {
@@ -95,18 +95,16 @@ class DepBuilder {
95
95
  fn();
96
96
  }
97
97
  }
98
- writeMFFiles(opts) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const tmpBase = this.opts.mfsu.opts.tmpBase;
101
- utils_1.fsExtra.mkdirpSync(tmpBase);
102
- // expose files
103
- for (const dep of opts.deps) {
104
- const content = yield dep.buildExposeContent();
105
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
106
- }
107
- // index file
108
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"😛"', 'utf-8');
109
- });
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');
110
108
  }
111
109
  getWebpackConfig(opts) {
112
110
  var _a, _b;
@@ -144,6 +142,9 @@ class DepBuilder {
144
142
  depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
145
143
  webpack: this.opts.mfsu.opts.implementor,
146
144
  }));
145
+ depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
146
+ this.opts.mfsu.onProgress({ percent, status: msg });
147
+ }));
147
148
  const exposes = opts.deps.reduce((memo, dep) => {
148
149
  memo[`./${dep.file}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
149
150
  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
  };
@@ -304,6 +319,7 @@ function getDepModuleStr(dep) {
304
319
  "./${dep.file}": function() {
305
320
  return new Promise(resolve => {
306
321
  import('./${constants_1.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
322
+ module.default && ${ES_INTEROP_FUNC}(module, module.default);
307
323
  resolve(() => module.default || module);
308
324
  });
309
325
  })
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;