@umijs/mfsu 4.0.0-beta.8 → 4.0.0-canary-20240513.3

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 (100) hide show
  1. package/compiled/is-absolute-url/LICENSE +9 -0
  2. package/compiled/is-absolute-url/index.d.ts +20 -0
  3. package/compiled/is-absolute-url/index.js +1 -0
  4. package/compiled/is-absolute-url/package.json +1 -0
  5. package/compiled/mrmime/package.json +1 -1
  6. package/compiled/webpack-virtual-modules/index.js +1 -1
  7. package/compiled/webpack-virtual-modules/package.json +1 -1
  8. package/dist/babelPlugins/awaitImport/MFImport.d.ts +24 -0
  9. package/dist/babelPlugins/awaitImport/MFImport.js +66 -0
  10. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
  11. package/dist/babelPlugins/awaitImport/awaitImport.js +111 -112
  12. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +3 -1
  13. package/dist/babelPlugins/awaitImport/checkMatch.js +166 -109
  14. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +2 -2
  15. package/dist/babelPlugins/awaitImport/getAliasedPath.js +44 -33
  16. package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
  17. package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
  18. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +62 -47
  19. package/dist/constants.d.ts +1 -0
  20. package/dist/constants.js +50 -10
  21. package/dist/dep/dep.d.ts +11 -4
  22. package/dist/dep/dep.js +118 -80
  23. package/dist/dep/getCJSExports.js +83 -47
  24. package/dist/dep/getExposeFromContent.d.ts +0 -1
  25. package/dist/dep/getExposeFromContent.js +99 -74
  26. package/dist/dep/getModuleExports.js +58 -43
  27. package/dist/depBuilder/depBuilder.d.ts +6 -2
  28. package/dist/depBuilder/depBuilder.js +222 -158
  29. package/dist/depBuilder/getESBuildEntry.d.ts +1 -1
  30. package/dist/depBuilder/getESBuildEntry.js +50 -14
  31. package/dist/depInfo.d.ts +20 -6
  32. package/dist/depInfo.js +90 -39
  33. package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
  34. package/dist/esbuildHandlers/autoCssModules.js +48 -0
  35. package/dist/esbuildHandlers/awaitImport/index.d.ts +15 -0
  36. package/dist/esbuildHandlers/awaitImport/index.js +86 -0
  37. package/dist/index.d.ts +3 -2
  38. package/dist/index.js +35 -13
  39. package/dist/loader/esbuild.d.ts +5 -0
  40. package/dist/loader/esbuild.js +79 -0
  41. package/dist/mfsu/mfsu.d.ts +69 -0
  42. package/dist/mfsu/mfsu.js +319 -0
  43. package/dist/mfsu/strategyCompileTime.d.ts +20 -0
  44. package/dist/mfsu/strategyCompileTime.js +142 -0
  45. package/dist/mfsu/strategyStaticAnalyze.d.ts +24 -0
  46. package/dist/mfsu/strategyStaticAnalyze.js +196 -0
  47. package/dist/moduleGraph.d.ts +6 -9
  48. package/dist/moduleGraph.js +228 -178
  49. package/dist/staticDepInfo/importParser.d.ts +4 -0
  50. package/dist/staticDepInfo/importParser.js +28 -0
  51. package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +15 -0
  52. package/dist/staticDepInfo/simulations/babel-plugin-import.js +118 -0
  53. package/dist/staticDepInfo/staticDepInfo.d.ts +61 -0
  54. package/dist/staticDepInfo/staticDepInfo.js +274 -0
  55. package/dist/types.d.ts +12 -0
  56. package/dist/types.js +33 -8
  57. package/dist/utils/makeArray.js +29 -5
  58. package/dist/utils/resolveUtils.d.ts +1 -0
  59. package/dist/utils/resolveUtils.js +104 -0
  60. package/dist/utils/trimFileContent.js +29 -5
  61. package/dist/utils/webpackUtils.d.ts +3 -0
  62. package/dist/utils/webpackUtils.js +80 -0
  63. package/dist/webpackPlugins/buildDepPlugin.d.ts +4 -3
  64. package/dist/webpackPlugins/buildDepPlugin.js +61 -17
  65. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +1 -1
  66. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +47 -19
  67. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +55 -27
  68. package/dist/webpackPlugins/writeCachePlugin.js +45 -15
  69. package/package.json +32 -28
  70. package/vendors/importParser/_importParser.js +683 -0
  71. package/vendors/importParser/importParser.jison +105 -0
  72. package/dist/babelPlugins/autoExport.d.ts +0 -7
  73. package/dist/babelPlugins/autoExport.d.ts.map +0 -1
  74. package/dist/babelPlugins/autoExport.js +0 -61
  75. package/dist/babelPlugins/awaitImport/awaitImport.d.ts.map +0 -1
  76. package/dist/babelPlugins/awaitImport/checkMatch.d.ts.map +0 -1
  77. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts.map +0 -1
  78. package/dist/babelPlugins/awaitImport/getRealPath.d.ts.map +0 -1
  79. package/dist/babelPlugins/awaitImport/isExternals.d.ts.map +0 -1
  80. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts.map +0 -1
  81. package/dist/constants.d.ts.map +0 -1
  82. package/dist/dep/dep.d.ts.map +0 -1
  83. package/dist/dep/getCJSExports.d.ts.map +0 -1
  84. package/dist/dep/getExposeFromContent.d.ts.map +0 -1
  85. package/dist/dep/getModuleExports.d.ts.map +0 -1
  86. package/dist/depBuilder/depBuilder.d.ts.map +0 -1
  87. package/dist/depBuilder/getESBuildEntry.d.ts.map +0 -1
  88. package/dist/depInfo.d.ts.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/mfsu.d.ts +0 -55
  91. package/dist/mfsu.d.ts.map +0 -1
  92. package/dist/mfsu.js +0 -173
  93. package/dist/moduleGraph.d.ts.map +0 -1
  94. package/dist/types.d.ts.map +0 -1
  95. package/dist/utils/makeArray.d.ts.map +0 -1
  96. package/dist/utils/trimFileContent.d.ts.map +0 -1
  97. package/dist/webpackPlugins/buildDepPlugin.d.ts.map +0 -1
  98. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts.map +0 -1
  99. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts.map +0 -1
  100. package/dist/webpackPlugins/writeCachePlugin.d.ts.map +0 -1
package/dist/depInfo.js CHANGED
@@ -1,43 +1,94 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DepInfo = void 0;
4
- const utils_1 = require("@umijs/utils");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- const moduleGraph_1 = require("./moduleGraph");
8
- class DepInfo {
9
- constructor(opts) {
10
- this.moduleGraph = new moduleGraph_1.ModuleGraph();
11
- this.cacheDependency = {};
12
- this.opts = opts;
13
- this.cacheFilePath = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, 'MFSU_CACHE.json');
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/depInfo.ts
20
+ var depInfo_exports = {};
21
+ __export(depInfo_exports, {
22
+ DepInfo: () => DepInfo
23
+ });
24
+ module.exports = __toCommonJS(depInfo_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ var import_fs = require("fs");
27
+ var import_path = require("path");
28
+ var import_moduleGraph = require("./moduleGraph");
29
+ var DepInfo = class {
30
+ constructor(opts) {
31
+ this.moduleGraph = new import_moduleGraph.ModuleGraph();
32
+ this.cacheDependency = {};
33
+ this.opts = opts;
34
+ this.cacheFilePath = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, "MFSU_CACHE.json");
35
+ }
36
+ shouldBuild() {
37
+ if (!import_utils.lodash.isEqual(
38
+ this.cacheDependency,
39
+ this.opts.mfsu.opts.getCacheDependency()
40
+ )) {
41
+ return "cacheDependency has changed";
14
42
  }
15
- shouldBuild() {
16
- if (!utils_1.lodash.isEqual(this.cacheDependency, this.opts.mfsu.opts.getCacheDependency())) {
17
- return true;
18
- }
19
- if (this.moduleGraph.hasDepChanged()) {
20
- return true;
21
- }
22
- return false;
43
+ if (this.moduleGraph.hasDepChanged()) {
44
+ return "moduleGraph has changed";
23
45
  }
24
- snapshot() {
25
- this.cacheDependency = this.opts.mfsu.opts.getCacheDependency();
26
- this.moduleGraph.snapshotDeps();
46
+ return false;
47
+ }
48
+ snapshot() {
49
+ this.cacheDependency = this.opts.mfsu.opts.getCacheDependency();
50
+ this.moduleGraph.snapshotDeps();
51
+ }
52
+ loadCache() {
53
+ if ((0, import_fs.existsSync)(this.cacheFilePath)) {
54
+ import_utils.logger.info("[MFSU] restore cache");
55
+ try {
56
+ const { cacheDependency, moduleGraph } = JSON.parse(
57
+ (0, import_fs.readFileSync)(this.cacheFilePath, "utf-8")
58
+ );
59
+ this.cacheDependency = cacheDependency;
60
+ this.moduleGraph.restore(moduleGraph);
61
+ } catch (e) {
62
+ import_utils.logger.error("[MFSU] restore cache failed", e);
63
+ import_utils.logger.error("please `rm -rf node_modules/.cache`, and try again");
64
+ throw e;
65
+ }
27
66
  }
28
- loadCache() {
29
- if ((0, fs_1.existsSync)(this.cacheFilePath)) {
30
- const { cacheDependency, moduleGraph } = JSON.parse((0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8'));
31
- this.cacheDependency = cacheDependency;
32
- this.moduleGraph.restore(moduleGraph);
33
- }
67
+ }
68
+ writeCache() {
69
+ import_utils.fsExtra.mkdirpSync((0, import_path.dirname)(this.cacheFilePath));
70
+ const newContent = JSON.stringify(
71
+ {
72
+ cacheDependency: this.cacheDependency,
73
+ moduleGraph: this.moduleGraph.toJSON()
74
+ },
75
+ null,
76
+ 2
77
+ );
78
+ if ((0, import_fs.existsSync)(this.cacheFilePath) && (0, import_fs.readFileSync)(this.cacheFilePath, "utf-8") === newContent) {
79
+ return;
34
80
  }
35
- writeCache() {
36
- utils_1.fsExtra.mkdirpSync((0, path_1.dirname)(this.cacheFilePath));
37
- (0, fs_1.writeFileSync)(this.cacheFilePath, JSON.stringify({
38
- cacheDependency: this.cacheDependency,
39
- moduleGraph: this.moduleGraph.toJSON(),
40
- }, null, 2), 'utf-8');
41
- }
42
- }
43
- exports.DepInfo = DepInfo;
81
+ import_utils.logger.info("[MFSU] write cache");
82
+ (0, import_fs.writeFileSync)(this.cacheFilePath, newContent, "utf-8");
83
+ }
84
+ getDepModules() {
85
+ return this.moduleGraph.depSnapshotModules;
86
+ }
87
+ getCacheFilePath() {
88
+ return this.cacheFilePath;
89
+ }
90
+ };
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ DepInfo
94
+ });
@@ -0,0 +1,2 @@
1
+ import { IEsbuildLoaderHandlerParams } from '../types';
2
+ export declare function autoCssModulesHandler(opts: IEsbuildLoaderHandlerParams): string;
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/esbuildHandlers/autoCssModules.ts
20
+ var autoCssModules_exports = {};
21
+ __export(autoCssModules_exports, {
22
+ autoCssModulesHandler: () => autoCssModulesHandler
23
+ });
24
+ module.exports = __toCommonJS(autoCssModules_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ var CSS_MODULES_QUERY = "?modules";
27
+ var QUERY_LENGTH = CSS_MODULES_QUERY.length;
28
+ function autoCssModulesHandler(opts) {
29
+ let { code } = opts;
30
+ let offset = 0;
31
+ opts.imports.forEach((i) => {
32
+ if (i.d < 0 && (0, import_utils.isStyleFile)({ filename: i.n })) {
33
+ const importSegment = code.substring(i.ss + offset, i.s + offset);
34
+ if (~importSegment.indexOf(" from")) {
35
+ code = `${code.substring(
36
+ 0,
37
+ i.e + offset
38
+ )}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
39
+ offset += QUERY_LENGTH;
40
+ }
41
+ }
42
+ });
43
+ return code;
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ autoCssModulesHandler
48
+ });
@@ -0,0 +1,15 @@
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 declare function getImportHandlerV4(params: {
12
+ resolveImportSource: (source: string) => string;
13
+ }): (opts: IOpts) => string;
14
+ export default function getAwaitImportHandler(params: IParams): (opts: IOpts) => string;
15
+ export {};
@@ -0,0 +1,86 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/esbuildHandlers/awaitImport/index.ts
20
+ var awaitImport_exports = {};
21
+ __export(awaitImport_exports, {
22
+ default: () => getAwaitImportHandler,
23
+ getImportHandlerV4: () => getImportHandlerV4
24
+ });
25
+ module.exports = __toCommonJS(awaitImport_exports);
26
+ var import_checkMatch = require("../../babelPlugins/awaitImport/checkMatch");
27
+ function getImportHandlerV4(params) {
28
+ return function awaitImportHandler(opts) {
29
+ let offset = 0;
30
+ let { code } = opts;
31
+ const { imports } = opts;
32
+ imports.forEach((i) => {
33
+ if (!i.n)
34
+ return;
35
+ const isLazyImport = i.d > 0;
36
+ const from = i.n;
37
+ const replaceValue = params.resolveImportSource(from);
38
+ if (replaceValue !== from) {
39
+ const preSeg = code.substring(0, i.s + offset);
40
+ const tailSeg = code.substring(i.e + offset);
41
+ const quote = isLazyImport ? '"' : "";
42
+ code = `${preSeg}${quote}${replaceValue}${quote}${tailSeg}`;
43
+ offset += replaceValue.length - from.length;
44
+ }
45
+ });
46
+ return code;
47
+ };
48
+ }
49
+ function getAwaitImportHandler(params) {
50
+ return function awaitImportHandler(opts) {
51
+ var _a, _b;
52
+ let offset = 0;
53
+ let { code } = opts;
54
+ const { filePath, imports } = opts;
55
+ imports.forEach((i) => {
56
+ if (!i.n)
57
+ return;
58
+ const isLazyImport = i.d > 0;
59
+ const from = i.n;
60
+ const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
61
+ cache: params.cache,
62
+ value: from,
63
+ opts: params.opts,
64
+ filename: filePath
65
+ });
66
+ if (isMatch) {
67
+ const preSeg = code.substring(0, i.s + offset);
68
+ const tailSeg = code.substring(i.e + offset);
69
+ const quote = isLazyImport ? '"' : "";
70
+ code = `${preSeg}${quote}${replaceValue}${quote}${tailSeg}`;
71
+ offset += replaceValue.length - from.length;
72
+ }
73
+ });
74
+ if (params.cache.has(filePath)) {
75
+ (_b = (_a = params.opts).onCollect) == null ? void 0 : _b.call(_a, {
76
+ file: filePath,
77
+ data: params.cache.get(filePath)
78
+ });
79
+ }
80
+ return code;
81
+ };
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ getImportHandlerV4
86
+ });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './constants';
2
- export * from './mfsu';
3
- //# sourceMappingURL=index.d.ts.map
2
+ export * from './esbuildHandlers/autoCssModules';
3
+ export { esbuildLoader } from './loader/esbuild';
4
+ export * from './mfsu/mfsu';
package/dist/index.js CHANGED
@@ -1,14 +1,36 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
11
8
  };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./constants"), exports);
14
- __exportStar(require("./mfsu"), exports);
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ esbuildLoader: () => import_esbuild.esbuildLoader
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ __reExport(src_exports, require("./constants"), module.exports);
27
+ __reExport(src_exports, require("./esbuildHandlers/autoCssModules"), module.exports);
28
+ var import_esbuild = require("./loader/esbuild");
29
+ __reExport(src_exports, require("./mfsu/mfsu"), module.exports);
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ esbuildLoader,
33
+ ...require("./constants"),
34
+ ...require("./esbuildHandlers/autoCssModules"),
35
+ ...require("./mfsu/mfsu")
36
+ });
@@ -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,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/loader/esbuild.ts
20
+ var esbuild_exports = {};
21
+ __export(esbuild_exports, {
22
+ default: () => esbuild_default,
23
+ esbuildLoader: () => esbuildLoader
24
+ });
25
+ module.exports = __toCommonJS(esbuild_exports);
26
+ var import_es_module_lexer = require("@umijs/bundler-utils/compiled/es-module-lexer");
27
+ var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
28
+ var import_path = require("path");
29
+ var LOADER_MAP = {
30
+ // js
31
+ js: "js",
32
+ cjs: "js",
33
+ mjs: "js",
34
+ jsx: "jsx",
35
+ cjsx: "jsx",
36
+ mjsx: "jsx",
37
+ // ts
38
+ ts: "ts",
39
+ cts: "ts",
40
+ mts: "ts",
41
+ tsx: "tsx",
42
+ ctsx: "tsx",
43
+ mtsx: "tsx"
44
+ };
45
+ async function esbuildTranspiler(source) {
46
+ const done = this.async();
47
+ const options = this.getOptions();
48
+ const { handler = [], implementation, ...otherOptions } = options;
49
+ const transform = (implementation == null ? void 0 : implementation.transform) || import_esbuild.transform;
50
+ const filePath = this.resourcePath;
51
+ const ext = (0, import_path.extname)(filePath).slice(1);
52
+ const loader = LOADER_MAP[ext] ?? "default";
53
+ const transformOptions = {
54
+ ...otherOptions,
55
+ target: options.target ?? "es2015",
56
+ loader,
57
+ sourcemap: this.sourceMap,
58
+ sourcefile: filePath
59
+ };
60
+ try {
61
+ let { code, map } = await transform(source, transformOptions);
62
+ if (handler.length) {
63
+ await import_es_module_lexer.init;
64
+ handler.forEach((handle) => {
65
+ const [imports, exports] = (0, import_es_module_lexer.parse)(code);
66
+ code = handle({ code, imports, exports, filePath });
67
+ });
68
+ }
69
+ done(null, code, map && JSON.parse(map));
70
+ } catch (error) {
71
+ done(error);
72
+ }
73
+ }
74
+ var esbuild_default = esbuildTranspiler;
75
+ var esbuildLoader = __filename;
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ esbuildLoader
79
+ });
@@ -0,0 +1,69 @@
1
+ /// <reference types="node" />
2
+ import type { NextFunction, Request, Response } from '@umijs/bundler-utils/compiled/express';
3
+ import webpack, { Configuration } from 'webpack';
4
+ import type { Worker } from 'worker_threads';
5
+ import { DepBuilder } from '../depBuilder/depBuilder';
6
+ import { DepModule } from '../depInfo';
7
+ import { Mode } from '../types';
8
+ import { IBuildDepPluginOpts } from '../webpackPlugins/buildDepPlugin';
9
+ interface IOpts {
10
+ cwd?: string;
11
+ excludeNodeNatives?: boolean;
12
+ exportAllMembers?: Record<string, string[]>;
13
+ getCacheDependency?: Function;
14
+ onMFSUProgress?: Function;
15
+ mfName?: string;
16
+ mode?: Mode;
17
+ tmpBase?: string;
18
+ unMatchLibs?: Array<string | RegExp>;
19
+ runtimePublicPath?: boolean | string;
20
+ implementor: typeof webpack;
21
+ buildDepWithESBuild?: boolean;
22
+ depBuildConfig: any;
23
+ strategy?: 'eager' | 'normal';
24
+ include?: string[];
25
+ srcCodeCache?: any;
26
+ shared?: any;
27
+ remoteName?: string;
28
+ remoteAliases?: string[];
29
+ startBuildWorker: (dep: any[]) => Worker;
30
+ }
31
+ export declare class MFSU {
32
+ opts: IOpts;
33
+ alias: Record<string, string>;
34
+ externals: (Record<string, string> | Function)[];
35
+ depBuilder: DepBuilder;
36
+ depConfig: Configuration | null;
37
+ buildDepsAgain: boolean;
38
+ progress: any;
39
+ onProgress: Function;
40
+ publicPath: string;
41
+ private strategy;
42
+ private lastBuildError;
43
+ constructor(opts: IOpts);
44
+ asyncImport(content: string): string;
45
+ setWebpackConfig(opts: {
46
+ config: Configuration;
47
+ depConfig: Configuration;
48
+ }): Promise<void>;
49
+ buildDeps(opts?: {
50
+ useWorker: boolean;
51
+ }): Promise<void>;
52
+ getMiddlewares(): (((req: Request, res: Response, next: NextFunction) => void) | import("@umijs/bundler-utils/compiled/express/serve-static").RequestHandler<Response<any, Record<string, any>>>)[];
53
+ getBabelPlugins(): any[][];
54
+ getEsbuildLoaderHandler(): any[];
55
+ getCacheFilePath(): string;
56
+ }
57
+ export declare function resolvePublicPath(config: Configuration): string;
58
+ export interface IMFSUStrategy {
59
+ init(webpackConfig: Configuration): void;
60
+ shouldBuild(): string | boolean;
61
+ getBabelPlugin(): any[];
62
+ getBuildDepPlugConfig(): IBuildDepPluginOpts;
63
+ loadCache(): void;
64
+ getCacheFilePath(): string;
65
+ getDepModules(): Record<string, DepModule>;
66
+ refresh(): void;
67
+ writeCache(): void;
68
+ }
69
+ export {};