@umijs/mfsu 4.0.0-beta.7 → 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.
Files changed (33) hide show
  1. package/compiled/webpack-virtual-modules/LICENSE +21 -0
  2. package/compiled/webpack-virtual-modules/index.js +1 -0
  3. package/compiled/webpack-virtual-modules/package.json +1 -0
  4. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +5 -3
  5. package/dist/babelPlugins/awaitImport/awaitImport.js +26 -90
  6. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +2 -1
  7. package/dist/babelPlugins/awaitImport/checkMatch.js +12 -4
  8. package/dist/babelPlugins/awaitImport/getAliasedPath.js +5 -10
  9. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +5 -1
  10. package/dist/dep/dep.d.ts +4 -0
  11. package/dist/dep/dep.js +54 -50
  12. package/dist/dep/getExposeFromContent.js +44 -55
  13. package/dist/dep/getModuleExports.js +24 -35
  14. package/dist/depBuilder/depBuilder.js +73 -74
  15. package/dist/depBuilder/getESBuildEntry.js +18 -5
  16. package/dist/depInfo.d.ts +1 -1
  17. package/dist/depInfo.js +11 -4
  18. package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
  19. package/dist/esbuildHandlers/autoCssModules.js +24 -0
  20. package/dist/esbuildHandlers/awaitImport/index.d.ts +12 -0
  21. package/dist/esbuildHandlers/awaitImport/index.js +44 -0
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +10 -1
  24. package/dist/loader/esbuild.d.ts +5 -0
  25. package/dist/loader/esbuild.js +38 -0
  26. package/dist/mfsu.d.ts +14 -5
  27. package/dist/mfsu.js +205 -67
  28. package/dist/moduleGraph.d.ts +2 -1
  29. package/dist/moduleGraph.js +11 -3
  30. package/dist/types.d.ts +12 -0
  31. package/package.json +29 -24
  32. package/dist/babelPlugins/autoExport.d.ts +0 -7
  33. package/dist/babelPlugins/autoExport.js +0 -61
@@ -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,71 +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
- });
72
- utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
73
- 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,
74
61
  });
62
+ utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
63
+ opts.onBuildComplete();
75
64
  }
76
- build(opts) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- this.isBuilding = true;
79
- yield this.writeMFFiles({ deps: opts.deps });
80
- const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
81
- this.isBuilding = false;
82
- this.completeFns.forEach((fn) => fn());
83
- this.completeFns = [];
84
- } });
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
+ };
85
78
  if (this.opts.mfsu.opts.buildDepWithESBuild) {
86
- yield this.buildWithESBuild(newOpts);
79
+ await this.buildWithESBuild(newOpts);
87
80
  }
88
81
  else {
89
- yield this.buildWithWebpack(newOpts);
82
+ await this.buildWithWebpack(newOpts);
90
83
  }
91
- });
84
+ }
85
+ catch (e) {
86
+ onBuildComplete();
87
+ throw e;
88
+ }
92
89
  }
93
90
  onBuildComplete(fn) {
94
91
  if (this.isBuilding) {
@@ -98,17 +95,16 @@ class DepBuilder {
98
95
  fn();
99
96
  }
100
97
  }
101
- writeMFFiles(opts) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- const tmpBase = this.opts.mfsu.opts.tmpBase;
104
- // expose files
105
- for (const dep of opts.deps) {
106
- const content = yield dep.buildExposeContent();
107
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
108
- }
109
- // index file
110
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"😛"', 'utf-8');
111
- });
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');
112
108
  }
113
109
  getWebpackConfig(opts) {
114
110
  var _a, _b;
@@ -146,8 +142,11 @@ class DepBuilder {
146
142
  depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
147
143
  webpack: this.opts.mfsu.opts.implementor,
148
144
  }));
145
+ depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
146
+ this.opts.mfsu.onProgress({ percent, status: msg });
147
+ }));
149
148
  const exposes = opts.deps.reduce((memo, dep) => {
150
- 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);
151
150
  return memo;
152
151
  }, {});
153
152
  depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
@@ -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
  }
@@ -27,6 +27,7 @@ class DepInfo {
27
27
  }
28
28
  loadCache() {
29
29
  if ((0, fs_1.existsSync)(this.cacheFilePath)) {
30
+ utils_1.logger.info('MFSU restore cache');
30
31
  const { cacheDependency, moduleGraph } = JSON.parse((0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8'));
31
32
  this.cacheDependency = cacheDependency;
32
33
  this.moduleGraph.restore(moduleGraph);
@@ -34,10 +35,16 @@ class DepInfo {
34
35
  }
35
36
  writeCache() {
36
37
  utils_1.fsExtra.mkdirpSync((0, path_1.dirname)(this.cacheFilePath));
37
- (0, fs_1.writeFileSync)(this.cacheFilePath, JSON.stringify({
38
+ const newContent = JSON.stringify({
38
39
  cacheDependency: this.cacheDependency,
39
40
  moduleGraph: this.moduleGraph.toJSON(),
40
- }, 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');
41
48
  }
42
49
  }
43
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;
@@ -0,0 +1,12 @@
1
+ import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
2
+ interface IParams {
3
+ cache: Map<string, any>;
4
+ opts: any;
5
+ }
6
+ interface IOpts {
7
+ code: string;
8
+ imports: ImportSpecifier[];
9
+ filePath: string;
10
+ }
11
+ export default function getAwaitImportHandler(params: IParams): (opts: IOpts) => string;
12
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const checkMatch_1 = require("../../babelPlugins/awaitImport/checkMatch");
4
+ function getAwaitImportHandler(params) {
5
+ return function awaitImportHandler(opts) {
6
+ var _a, _b;
7
+ let offset = 0;
8
+ let { code } = opts;
9
+ const { filePath, imports } = opts;
10
+ imports.forEach((i) => {
11
+ if (!i.n)
12
+ return;
13
+ const isLazyImport = i.d > 0;
14
+ const from = i.n;
15
+ const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
16
+ cache: params.cache,
17
+ value: from,
18
+ opts: params.opts,
19
+ filename: filePath,
20
+ });
21
+ if (isMatch) {
22
+ // case: import x from './index.ts';
23
+ // import('./index.ts');
24
+ // import x from '
25
+ // import(
26
+ const preSeg = code.substring(0, i.s + offset);
27
+ // ';
28
+ // );
29
+ const tailSeg = code.substring(i.e + offset);
30
+ const quote = isLazyImport ? '"' : '';
31
+ code = `${preSeg}${quote}${replaceValue}${quote}${tailSeg}`;
32
+ offset += replaceValue.length - from.length;
33
+ }
34
+ });
35
+ if (params.cache.has(filePath)) {
36
+ (_b = (_a = params.opts).onCollect) === null || _b === void 0 ? void 0 : _b.call(_a, {
37
+ file: filePath,
38
+ data: params.cache.get(filePath),
39
+ });
40
+ }
41
+ return code;
42
+ };
43
+ }
44
+ exports.default = getAwaitImportHandler;
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,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.esbuildLoader = void 0;
4
+ const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
5
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
6
+ const path_1 = require("path");
7
+ async function esbuildTranspiler(source) {
8
+ var _a;
9
+ const done = this.async();
10
+ const options = this.getOptions();
11
+ const { handler = [], implementation, ...otherOptions } = options;
12
+ const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
13
+ const filePath = this.resourcePath;
14
+ const ext = (0, path_1.extname)(filePath).slice(1);
15
+ const transformOptions = {
16
+ ...otherOptions,
17
+ target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015',
18
+ loader: ext !== null && ext !== void 0 ? ext : 'js',
19
+ sourcemap: this.sourceMap,
20
+ sourcefile: filePath,
21
+ };
22
+ try {
23
+ let { code, map } = await transform(source, transformOptions);
24
+ if (handler.length) {
25
+ await es_module_lexer_1.init;
26
+ handler.forEach((handle) => {
27
+ const [imports, exports] = (0, es_module_lexer_1.parse)(code);
28
+ code = handle({ code, imports, exports, filePath });
29
+ });
30
+ }
31
+ done(null, code, map && JSON.parse(map));
32
+ }
33
+ catch (error) {
34
+ done(error);
35
+ }
36
+ }
37
+ exports.default = esbuildTranspiler;
38
+ 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,12 +9,15 @@ 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;
16
16
  unMatchLibs?: string[];
17
+ runtimePublicPath?: boolean | string;
17
18
  implementor: typeof webpack;
18
19
  buildDepWithESBuild?: boolean;
20
+ depBuildConfig: any;
19
21
  }
20
22
  export declare class MFSU {
21
23
  opts: IOpts;
@@ -24,14 +26,20 @@ export declare class MFSU {
24
26
  depInfo: DepInfo;
25
27
  depBuilder: DepBuilder;
26
28
  depConfig: Configuration | null;
29
+ buildDepsAgain: boolean;
30
+ progress: any;
31
+ onProgress: Function;
32
+ publicPath: string;
27
33
  constructor(opts: IOpts);
34
+ asyncImport(content: string): string;
28
35
  setWebpackConfig(opts: {
29
36
  config: Configuration;
30
37
  depConfig: Configuration;
31
- }): void;
38
+ }): Promise<void>;
32
39
  buildDeps(): Promise<void>;
33
40
  getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
34
- getBabelPlugins(): (typeof autoExport | (typeof awaitImport | {
41
+ private getAwaitImportCollectOpts;
42
+ getBabelPlugins(): ({
35
43
  onTransformDeps: () => void;
36
44
  onCollect: ({ file, data, }: {
37
45
  file: string;
@@ -49,6 +57,7 @@ export declare class MFSU {
49
57
  remoteName: string | undefined;
50
58
  alias: Record<string, string>;
51
59
  externals: (Function | Record<string, string>)[];
52
- })[])[];
60
+ } | typeof awaitImport)[][];
61
+ getEsbuildLoaderHandler(): any[];
53
62
  }
54
63
  export {};