@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/constants.js CHANGED
@@ -1,10 +1,50 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REMOTE_FILE_FULL = exports.REMOTE_FILE = exports.DEFAULT_TMP_DIR_NAME = exports.DEFAULT_MF_NAME = exports.MF_STATIC_PREFIX = exports.MF_DEP_PREFIX = exports.MF_VA_PREFIX = void 0;
4
- exports.MF_VA_PREFIX = 'mf-va_';
5
- exports.MF_DEP_PREFIX = 'mf-dep_';
6
- exports.MF_STATIC_PREFIX = 'mf-static/';
7
- exports.DEFAULT_MF_NAME = 'mf';
8
- exports.DEFAULT_TMP_DIR_NAME = '.mfsu';
9
- exports.REMOTE_FILE = 'remoteEntry.js';
10
- exports.REMOTE_FILE_FULL = `${exports.MF_VA_PREFIX}${exports.REMOTE_FILE}`;
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/constants.ts
20
+ var constants_exports = {};
21
+ __export(constants_exports, {
22
+ DEFAULT_MF_NAME: () => DEFAULT_MF_NAME,
23
+ DEFAULT_TMP_DIR_NAME: () => DEFAULT_TMP_DIR_NAME,
24
+ MF_DEP_PREFIX: () => MF_DEP_PREFIX,
25
+ MF_STATIC_PREFIX: () => MF_STATIC_PREFIX,
26
+ MF_VA_PREFIX: () => MF_VA_PREFIX,
27
+ REMOTE_FILE: () => REMOTE_FILE,
28
+ REMOTE_FILE_FULL: () => REMOTE_FILE_FULL,
29
+ VIRTUAL_ENTRY_DIR: () => VIRTUAL_ENTRY_DIR
30
+ });
31
+ module.exports = __toCommonJS(constants_exports);
32
+ var MF_VA_PREFIX = "mf-va_";
33
+ var MF_DEP_PREFIX = "mf-dep_";
34
+ var MF_STATIC_PREFIX = "mf-static/";
35
+ var DEFAULT_MF_NAME = "mf";
36
+ var DEFAULT_TMP_DIR_NAME = ".mfsu";
37
+ var REMOTE_FILE = "remoteEntry.js";
38
+ var REMOTE_FILE_FULL = `${MF_VA_PREFIX}${REMOTE_FILE}`;
39
+ var VIRTUAL_ENTRY_DIR = `mfsu-virtual-entry`;
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ DEFAULT_MF_NAME,
43
+ DEFAULT_TMP_DIR_NAME,
44
+ MF_DEP_PREFIX,
45
+ MF_STATIC_PREFIX,
46
+ MF_VA_PREFIX,
47
+ REMOTE_FILE,
48
+ REMOTE_FILE_FULL,
49
+ VIRTUAL_ENTRY_DIR
50
+ });
package/dist/dep/dep.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MFSU } from '../mfsu';
1
+ import { MFSU } from '../mfsu/mfsu';
2
2
  export declare class Dep {
3
3
  file: string;
4
4
  version: string;
@@ -6,22 +6,29 @@ export declare class Dep {
6
6
  shortFile: string;
7
7
  normalizedFile: string;
8
8
  filePath: string;
9
- mfsu: MFSU;
9
+ excludeNodeNatives: boolean;
10
+ importer: string | undefined;
10
11
  constructor(opts: {
11
12
  file: string;
12
13
  version: string;
13
14
  cwd: string;
14
- mfsu: MFSU;
15
+ excludeNodeNatives: boolean;
16
+ importer?: string;
15
17
  });
18
+ private normalizePath;
16
19
  buildExposeContent(): Promise<string>;
17
20
  getRealFile(): Promise<string | null>;
18
21
  static buildDeps(opts: {
19
22
  deps: Record<string, {
20
23
  file: string;
21
24
  version: string;
25
+ importer?: string;
22
26
  }>;
23
27
  cwd: string;
24
28
  mfsu: MFSU;
25
29
  }): Dep[];
30
+ static getDepVersion(opts: {
31
+ dep: string;
32
+ cwd: string;
33
+ }): string;
26
34
  }
27
- //# sourceMappingURL=dep.d.ts.map
package/dist/dep/dep.js CHANGED
@@ -1,92 +1,130 @@
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
- });
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
13
18
  };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Dep = void 0;
16
- const assert_1 = __importDefault(require("assert"));
17
- const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
18
- const fs_1 = require("fs");
19
- const constants_1 = require("../constants");
20
- const trimFileContent_1 = require("../utils/trimFileContent");
21
- const getExposeFromContent_1 = require("./getExposeFromContent");
22
- const resolver = enhanced_resolve_1.default.create({
23
- mainFields: ['module', 'browser', 'main'],
24
- extensions: ['.js', '.json', '.mjs'],
25
- // TODO: support exports
26
- // tried to add exports, but it don't work with swr
27
- exportsFields: [],
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/dep/dep.ts
30
+ var dep_exports = {};
31
+ __export(dep_exports, {
32
+ Dep: () => Dep
28
33
  });
29
- function resolve(context, path) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- return new Promise((resolve, reject) => {
32
- resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
33
- });
34
- });
35
- }
36
- class Dep {
37
- constructor(opts) {
38
- this.file = opts.file;
39
- this.version = opts.version;
40
- this.cwd = opts.cwd;
41
- this.shortFile = this.file.replace(this.cwd, '$CWD$');
42
- this.normalizedFile = this.shortFile.replace(/\//g, '_').replace(/:/g, '_');
43
- this.filePath = `${constants_1.MF_VA_PREFIX}${this.normalizedFile}.js`;
44
- this.mfsu = opts.mfsu;
34
+ module.exports = __toCommonJS(dep_exports);
35
+ var import_utils = require("@umijs/utils");
36
+ var import_assert = __toESM(require("assert"));
37
+ var import_crypto = require("crypto");
38
+ var import_fs = require("fs");
39
+ var import_path = require("path");
40
+ var import_constants = require("../constants");
41
+ var import_resolveUtils = require("../utils/resolveUtils");
42
+ var import_trimFileContent = require("../utils/trimFileContent");
43
+ var import_getExposeFromContent = require("./getExposeFromContent");
44
+ var Dep = class {
45
+ constructor(opts) {
46
+ this.file = (0, import_utils.winPath)(opts.file);
47
+ this.version = opts.version;
48
+ this.cwd = opts.cwd;
49
+ this.shortFile = this.file;
50
+ this.normalizedFile = this.normalizePath(this.shortFile);
51
+ this.filePath = `${import_constants.MF_VA_PREFIX}${this.normalizedFile}.js`;
52
+ this.excludeNodeNatives = opts.excludeNodeNatives;
53
+ this.importer = opts.importer;
54
+ }
55
+ normalizePath(p) {
56
+ let longPath = p;
57
+ if (longPath.startsWith(this.cwd)) {
58
+ longPath = longPath.slice(this.cwd.length);
59
+ }
60
+ longPath = longPath.replace(/\//g, "_").replace(/:/g, "_");
61
+ if (longPath.length <= 200) {
62
+ return longPath;
45
63
  }
46
- buildExposeContent() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- // node natives
49
- // @ts-ignore
50
- const isNodeNatives = !!process.binding('natives')[this.file];
51
- if (isNodeNatives) {
52
- return (0, trimFileContent_1.trimFileContent)(this.mfsu.opts.excludeNodeNatives
53
- ? `
64
+ const hash = (0, import_crypto.createHash)("md5").update(longPath).digest("hex").slice(0, 16);
65
+ const post = longPath.slice(-200);
66
+ return `${hash}_${post}`;
67
+ }
68
+ async buildExposeContent() {
69
+ const isNodeNatives = !!process.binding("natives")[this.file];
70
+ if (isNodeNatives) {
71
+ return (0, import_trimFileContent.trimFileContent)(
72
+ this.excludeNodeNatives ? `
54
73
  const _ = require('${this.file}');
55
74
  module.exports = _;
56
- `
57
- : `
75
+ ` : `
58
76
  import _ from '${this.file}';
59
77
  export default _;
60
78
  export * from '${this.file}';
61
- `);
62
- }
63
- // none node natives
64
- const realFile = yield this.getRealFile();
65
- (0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
66
- const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
67
- return yield (0, getExposeFromContent_1.getExposeFromContent)({
68
- content,
69
- filePath: realFile,
70
- dep: this,
71
- });
72
- });
79
+ `
80
+ );
73
81
  }
74
- getRealFile() {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- try {
77
- // don't need to handle alias here
78
- // it's already handled by babel plugin
79
- return yield resolve(this.cwd, this.file);
80
- }
81
- catch (e) {
82
- return null;
83
- }
84
- });
82
+ const realFile = await this.getRealFile();
83
+ if (!realFile) {
84
+ import_utils.logger.error(
85
+ `Can not resolve dependence : '${import_utils.chalk.red(
86
+ this.file
87
+ )}', please install it`
88
+ );
85
89
  }
86
- static buildDeps(opts) {
87
- return Object.keys(opts.deps).map((file) => {
88
- return new Dep(Object.assign(Object.assign({}, opts.deps[file]), { cwd: opts.cwd, mfsu: opts.mfsu }));
89
- });
90
+ (0, import_assert.default)(realFile, `dependence not found: ${this.file}`);
91
+ const content = (0, import_fs.readFileSync)(realFile, "utf-8");
92
+ return await (0, import_getExposeFromContent.getExposeFromContent)({
93
+ content,
94
+ filePath: realFile,
95
+ dep: this
96
+ });
97
+ }
98
+ async getRealFile() {
99
+ try {
100
+ const contexts = this.importer ? [(0, import_path.dirname)(this.importer), this.cwd] : [this.cwd];
101
+ return await (0, import_resolveUtils.resolveFromContexts)(contexts, this.file);
102
+ } catch (e) {
103
+ return null;
90
104
  }
91
- }
92
- exports.Dep = Dep;
105
+ }
106
+ static buildDeps(opts) {
107
+ return Object.keys(opts.deps).map((file) => {
108
+ return new Dep({
109
+ ...opts.deps[file],
110
+ cwd: opts.cwd,
111
+ excludeNodeNatives: opts.mfsu.opts.excludeNodeNatives
112
+ });
113
+ });
114
+ }
115
+ static getDepVersion(opts) {
116
+ if (!!process.binding("natives")[opts.dep]) {
117
+ return "*";
118
+ }
119
+ const dep = (0, import_path.isAbsolute)(opts.dep) ? opts.dep : (0, import_path.join)(opts.cwd, "node_modules", opts.dep);
120
+ const pkg = import_utils.pkgUp.pkgUpSync({
121
+ cwd: dep
122
+ });
123
+ (0, import_assert.default)(pkg, `package.json not found for ${opts.dep}`);
124
+ return require(pkg).version || null;
125
+ }
126
+ };
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ Dep
130
+ });
@@ -1,58 +1,94 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCJSExports = void 0;
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/dep/getCJSExports.ts
20
+ var getCJSExports_exports = {};
21
+ __export(getCJSExports_exports, {
22
+ getCJSExports: () => getCJSExports
23
+ });
24
+ module.exports = __toCommonJS(getCJSExports_exports);
4
25
  function getCJSExports({ content }) {
5
- return matchAll(/Object\.defineProperty\(\s*exports\s*\,\s*[\"|\'](\w+)[\"|\']/g, content)
6
- .concat(
26
+ return matchAll(
27
+ /Object\.defineProperty\(\s*exports\s*\,\s*[\"|\'](\w+)[\"|\']/g,
28
+ content
29
+ ).concat(
7
30
  // Support export['default']
8
31
  // ref: https://unpkg.alibaba-inc.com/browse/echarts-for-react@2.0.16/lib/core.js
9
- matchAll(/exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g, content))
10
- .concat(
32
+ matchAll(
33
+ /exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g,
34
+ content
35
+ )
36
+ ).concat(
11
37
  // Support __webpack_exports__["default"]
12
38
  // ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8429
13
- matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, content))
14
- .concat(
39
+ matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, content)
40
+ ).concat(
15
41
  // Support __webpack_require__.d(__webpack_exports, "EditorState")
16
42
  // ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8347
17
- matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g, content))
18
- .concat(
19
- // Support __webpack_require__.d(__webpack_exports__, {"default": function() { return /* binding */ clipboard; }});
20
- // ref: https://unpkg.alibaba-inc.com/browse/clipboard@2.0.8/dist/clipboard.js L26
21
- ...matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(\{)/g, content).map((matchResult) => {
22
- const { index } = matchResult;
23
- let idx = index;
24
- let deep = 0;
25
- let isMeetSymbol = false;
26
- let symbolBeginIndex = index;
27
- while (idx < content.length) {
28
- if (!deep && isMeetSymbol) {
29
- break;
30
- }
31
- if (content[idx] === '{') {
32
- if (!isMeetSymbol) {
33
- isMeetSymbol = true;
34
- symbolBeginIndex = idx;
35
- }
36
- deep++;
37
- }
38
- if (content[idx] === '}') {
39
- deep--;
40
- }
41
- idx++;
43
+ matchAll(
44
+ /__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g,
45
+ content
46
+ )
47
+ ).concat(
48
+ ...matchAll(
49
+ /__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(\{)/g,
50
+ content
51
+ ).map((matchResult) => {
52
+ const { index } = matchResult;
53
+ let idx = index;
54
+ let deep = 0;
55
+ let isMeetSymbol = false;
56
+ let symbolBeginIndex = index;
57
+ while (idx < content.length) {
58
+ if (!deep && isMeetSymbol) {
59
+ break;
42
60
  }
43
- let result = content.slice(symbolBeginIndex, idx);
44
- return [
45
- ...matchAll(/(?:\"|\')(\w+)(?:\"|\')\s*\:\s*(?:function|\()/g, result),
46
- ];
47
- }))
48
- .map((result) => result[1]);
61
+ if (content[idx] === "{") {
62
+ if (!isMeetSymbol) {
63
+ isMeetSymbol = true;
64
+ symbolBeginIndex = idx;
65
+ }
66
+ deep++;
67
+ }
68
+ if (content[idx] === "}") {
69
+ deep--;
70
+ }
71
+ idx++;
72
+ }
73
+ let result = content.slice(symbolBeginIndex, idx);
74
+ return [
75
+ ...matchAll(
76
+ /(?:\"|\')(\w+)(?:\"|\')\s*\:\s*(?:function|\()/g,
77
+ result
78
+ )
79
+ ];
80
+ })
81
+ ).map((result) => result[1]);
49
82
  }
50
- exports.getCJSExports = getCJSExports;
51
83
  function matchAll(regexp, str) {
52
- const result = [];
53
- let match;
54
- while ((match = regexp.exec(str)) !== null) {
55
- result.push(match);
56
- }
57
- return result;
84
+ const result = [];
85
+ let match;
86
+ while ((match = regexp.exec(str)) !== null) {
87
+ result.push(match);
88
+ }
89
+ return result;
58
90
  }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ getCJSExports
94
+ });
@@ -4,4 +4,3 @@ export declare function getExposeFromContent(opts: {
4
4
  filePath: string;
5
5
  content: string;
6
6
  }): Promise<string>;
7
- //# sourceMappingURL=getExposeFromContent.d.ts.map
@@ -1,80 +1,105 @@
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
- });
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
13
18
  };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getExposeFromContent = void 0;
16
- const assert_1 = __importDefault(require("assert"));
17
- const path_1 = require("path");
18
- 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 `
30
- import _ from '${opts.dep.file}';
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/dep/getExposeFromContent.ts
30
+ var getExposeFromContent_exports = {};
31
+ __export(getExposeFromContent_exports, {
32
+ getExposeFromContent: () => getExposeFromContent
33
+ });
34
+ module.exports = __toCommonJS(getExposeFromContent_exports);
35
+ var import_utils = require("@umijs/utils");
36
+ var import_assert = __toESM(require("assert"));
37
+ var import_path = require("path");
38
+ var import_getModuleExports = require("./getModuleExports");
39
+ async function getExposeFromContent(opts) {
40
+ var _a;
41
+ const importPath = (0, import_utils.winPath)(opts.filePath);
42
+ if (opts.filePath && /\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
43
+ return `import '${importPath}';`;
44
+ }
45
+ if ((_a = opts.filePath) == null ? void 0 : _a.endsWith(".wasm")) {
46
+ return `
47
+ import _ from '${importPath}';
48
+ export default _;
49
+ export * from '${importPath}';`.trim();
50
+ }
51
+ if (opts.filePath && /\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(
52
+ opts.filePath
53
+ )) {
54
+ return `
55
+ import _ from '${importPath}';
31
56
  export default _;`.trim();
32
- }
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
- }
46
- // esm
47
- else {
48
- const ret = [];
49
- let hasExports = false;
50
- if (exports.includes('default')) {
51
- ret.push(`import _ from '${opts.dep.file}';`);
52
- 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
- ret.push(`export * from '${opts.dep.file}';`);
59
- hasExports = true;
60
- }
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
- }
71
- }
72
- return ret.join('\n');
73
- }
74
- });
57
+ }
58
+ (0, import_assert.default)(
59
+ (0, import_utils.isJavaScriptFile)(opts.filePath),
60
+ `file type not supported for ${(0, import_path.basename)(opts.filePath)}.`
61
+ );
62
+ const { exports, isCJS } = await (0, import_getModuleExports.getModuleExports)({
63
+ content: opts.content,
64
+ filePath: opts.filePath
65
+ });
66
+ if (isCJS) {
67
+ return [
68
+ `import _ from '${importPath}';`,
69
+ `export default _;`,
70
+ `export * from '${importPath}';`
71
+ ].join("\n");
72
+ } else {
73
+ const ret = [];
74
+ let hasExports = false;
75
+ if (exports.includes("default")) {
76
+ ret.push(`import _ from '${importPath}';`);
77
+ ret.push(`export default _;`);
78
+ hasExports = true;
79
+ }
80
+ if (hasNonDefaultExports(exports) || // export * from 不会有 exports,只会有 imports
81
+ // case: export*from'.'
82
+ // export * from '.'
83
+ /export\s*\*\s*from/.test(opts.content)) {
84
+ ret.push(`export * from '${importPath}';`);
85
+ hasExports = true;
86
+ }
87
+ if (!hasExports) {
88
+ if (exports.includes("__esModule")) {
89
+ ret.push(`import _ from '${importPath}';`);
90
+ ret.push(`export default _;`);
91
+ ret.push(`export * from '${importPath}';`);
92
+ } else {
93
+ ret.push(`import '${importPath}';`);
94
+ }
95
+ }
96
+ return ret.join("\n");
97
+ }
75
98
  }
76
- exports.getExposeFromContent = getExposeFromContent;
77
99
  function hasNonDefaultExports(exports) {
78
- return (exports.filter((exp) => !['__esModule', 'default'].includes(exp))
79
- .length > 0);
100
+ return exports.filter((exp) => !["__esModule", "default"].includes(exp)).length > 0;
80
101
  }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ getExposeFromContent
105
+ });