@umijs/mfsu 4.0.6 → 4.0.9
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.
- package/compiled/is-absolute-url/LICENSE +9 -0
- package/compiled/is-absolute-url/index.d.ts +22 -0
- package/compiled/is-absolute-url/index.js +1 -0
- package/compiled/is-absolute-url/package.json +1 -0
- package/dist/babelPlugins/awaitImport/MFImport.js +59 -66
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
- package/dist/babelPlugins/awaitImport/awaitImport.js +103 -117
- package/dist/babelPlugins/awaitImport/checkMatch.js +131 -119
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +54 -35
- package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
- package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +51 -52
- package/dist/constants.js +47 -10
- package/dist/dep/dep.js +112 -83
- package/dist/dep/getCJSExports.js +60 -53
- package/dist/dep/getExposeFromContent.js +71 -59
- package/dist/dep/getModuleExports.js +58 -32
- package/dist/depBuilder/depBuilder.js +184 -158
- package/dist/depBuilder/getESBuildEntry.js +35 -12
- package/dist/depInfo.js +75 -53
- package/dist/esbuildHandlers/autoCssModules.js +43 -22
- package/dist/esbuildHandlers/awaitImport/index.js +82 -70
- package/dist/index.js +32 -22
- package/dist/loader/esbuild.js +87 -35
- package/dist/mfsu/mfsu.d.ts +1 -1
- package/dist/mfsu/mfsu.js +231 -257
- package/dist/mfsu/strategyCompileTime.js +123 -99
- package/dist/mfsu/strategyStaticAnalyze.js +135 -117
- package/dist/moduleGraph.js +227 -186
- package/dist/staticDepInfo/importParser.js +28 -6
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
- package/dist/staticDepInfo/staticDepInfo.js +230 -197
- package/dist/types.js +33 -8
- package/dist/utils/makeArray.js +29 -5
- package/dist/utils/trimFileContent.js +29 -5
- package/dist/webpackPlugins/buildDepPlugin.js +49 -25
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +44 -19
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +46 -27
- package/dist/webpackPlugins/writeCachePlugin.js +39 -15
- package/package.json +8 -6
package/dist/constants.js
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
// 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
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(constants_exports);
|
|
31
|
+
var MF_VA_PREFIX = "mf-va_";
|
|
32
|
+
var MF_DEP_PREFIX = "mf-dep_";
|
|
33
|
+
var MF_STATIC_PREFIX = "mf-static/";
|
|
34
|
+
var DEFAULT_MF_NAME = "mf";
|
|
35
|
+
var DEFAULT_TMP_DIR_NAME = ".mfsu";
|
|
36
|
+
var REMOTE_FILE = "remoteEntry.js";
|
|
37
|
+
var REMOTE_FILE_FULL = `${MF_VA_PREFIX}${REMOTE_FILE}`;
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
DEFAULT_MF_NAME,
|
|
41
|
+
DEFAULT_TMP_DIR_NAME,
|
|
42
|
+
MF_DEP_PREFIX,
|
|
43
|
+
MF_STATIC_PREFIX,
|
|
44
|
+
MF_VA_PREFIX,
|
|
45
|
+
REMOTE_FILE,
|
|
46
|
+
REMOTE_FILE_FULL
|
|
47
|
+
});
|
package/dist/dep/dep.js
CHANGED
|
@@ -1,96 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
27
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// dep.ts
|
|
40
|
+
var dep_exports = {};
|
|
41
|
+
__export(dep_exports, {
|
|
42
|
+
Dep: () => Dep
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(dep_exports);
|
|
45
|
+
var import_utils = require("@umijs/utils");
|
|
46
|
+
var import_assert = __toESM(require("assert"));
|
|
47
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
48
|
+
var import_fs = require("fs");
|
|
49
|
+
var import_path = require("path");
|
|
50
|
+
var import_constants = require("../constants");
|
|
51
|
+
var import_trimFileContent = require("../utils/trimFileContent");
|
|
52
|
+
var import_getExposeFromContent = require("./getExposeFromContent");
|
|
53
|
+
var resolver = import_enhanced_resolve.default.create({
|
|
54
|
+
mainFields: ["module", "browser", "main"],
|
|
55
|
+
extensions: [".wasm", ".mjs", ".js", ".jsx", ".ts", ".tsx", ".json"],
|
|
56
|
+
exportsFields: ["exports"],
|
|
57
|
+
conditionNames: ["import", "module", "require", "node"]
|
|
20
58
|
});
|
|
21
59
|
async function resolve(context, path) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
60
|
+
return new Promise((resolve2, reject) => {
|
|
61
|
+
resolver(context, path, (err, result) => err ? reject(err) : resolve2(result));
|
|
62
|
+
});
|
|
25
63
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (isNodeNatives) {
|
|
41
|
-
return (0, trimFileContent_1.trimFileContent)(this.mfsu.opts.excludeNodeNatives
|
|
42
|
-
? `
|
|
64
|
+
var Dep = class {
|
|
65
|
+
constructor(opts) {
|
|
66
|
+
this.file = (0, import_utils.winPath)(opts.file);
|
|
67
|
+
this.version = opts.version;
|
|
68
|
+
this.cwd = opts.cwd;
|
|
69
|
+
this.shortFile = this.file;
|
|
70
|
+
this.normalizedFile = this.shortFile.replace(/\//g, "_").replace(/:/g, "_");
|
|
71
|
+
this.filePath = `${import_constants.MF_VA_PREFIX}${this.normalizedFile}.js`;
|
|
72
|
+
this.mfsu = opts.mfsu;
|
|
73
|
+
}
|
|
74
|
+
async buildExposeContent() {
|
|
75
|
+
const isNodeNatives = !!process.binding("natives")[this.file];
|
|
76
|
+
if (isNodeNatives) {
|
|
77
|
+
return (0, import_trimFileContent.trimFileContent)(this.mfsu.opts.excludeNodeNatives ? `
|
|
43
78
|
const _ = require('${this.file}');
|
|
44
79
|
module.exports = _;
|
|
45
|
-
`
|
|
46
|
-
: `
|
|
80
|
+
` : `
|
|
47
81
|
import _ from '${this.file}';
|
|
48
82
|
export default _;
|
|
49
83
|
export * from '${this.file}';
|
|
50
84
|
`);
|
|
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,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
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
|
-
}
|
|
71
85
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
const realFile = await this.getRealFile();
|
|
87
|
+
(0, import_assert.default)(realFile, `filePath not found of ${this.file}`);
|
|
88
|
+
const content = (0, import_fs.readFileSync)(realFile, "utf-8");
|
|
89
|
+
return await (0, import_getExposeFromContent.getExposeFromContent)({
|
|
90
|
+
content,
|
|
91
|
+
filePath: realFile,
|
|
92
|
+
dep: this
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async getRealFile() {
|
|
96
|
+
try {
|
|
97
|
+
return await resolve(this.cwd, this.file);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
return null;
|
|
80
100
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return require(pkg).version || null;
|
|
101
|
+
}
|
|
102
|
+
static buildDeps(opts) {
|
|
103
|
+
return Object.keys(opts.deps).map((file) => {
|
|
104
|
+
return new Dep(__spreadProps(__spreadValues({}, opts.deps[file]), {
|
|
105
|
+
cwd: opts.cwd,
|
|
106
|
+
mfsu: opts.mfsu
|
|
107
|
+
}));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
static getDepVersion(opts) {
|
|
111
|
+
if (!!process.binding("natives")[opts.dep]) {
|
|
112
|
+
return "*";
|
|
94
113
|
}
|
|
95
|
-
|
|
96
|
-
|
|
114
|
+
const dep = (0, import_path.isAbsolute)(opts.dep) ? opts.dep : (0, import_path.join)(opts.cwd, "node_modules", opts.dep);
|
|
115
|
+
const pkg = import_utils.pkgUp.pkgUpSync({
|
|
116
|
+
cwd: dep
|
|
117
|
+
});
|
|
118
|
+
(0, import_assert.default)(pkg, `package.json not found for ${opts.dep}`);
|
|
119
|
+
return require(pkg).version || null;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
Dep
|
|
125
|
+
});
|
|
@@ -1,58 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
// 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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++;
|
|
26
|
+
return matchAll(/Object\.defineProperty\(\s*exports\s*\,\s*[\"|\'](\w+)[\"|\']/g, content).concat(matchAll(/exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g, content)).concat(matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, content)).concat(matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g, content)).concat(...matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(\{)/g, content).map((matchResult) => {
|
|
27
|
+
const { index } = matchResult;
|
|
28
|
+
let idx = index;
|
|
29
|
+
let deep = 0;
|
|
30
|
+
let isMeetSymbol = false;
|
|
31
|
+
let symbolBeginIndex = index;
|
|
32
|
+
while (idx < content.length) {
|
|
33
|
+
if (!deep && isMeetSymbol) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (content[idx] === "{") {
|
|
37
|
+
if (!isMeetSymbol) {
|
|
38
|
+
isMeetSymbol = true;
|
|
39
|
+
symbolBeginIndex = idx;
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
deep++;
|
|
42
|
+
}
|
|
43
|
+
if (content[idx] === "}") {
|
|
44
|
+
deep--;
|
|
45
|
+
}
|
|
46
|
+
idx++;
|
|
47
|
+
}
|
|
48
|
+
let result = content.slice(symbolBeginIndex, idx);
|
|
49
|
+
return [
|
|
50
|
+
...matchAll(/(?:\"|\')(\w+)(?:\"|\')\s*\:\s*(?:function|\()/g, result)
|
|
51
|
+
];
|
|
52
|
+
})).map((result) => result[1]);
|
|
49
53
|
}
|
|
50
|
-
exports.getCJSExports = getCJSExports;
|
|
51
54
|
function matchAll(regexp, str) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const result = [];
|
|
56
|
+
let match;
|
|
57
|
+
while ((match = regexp.exec(str)) !== null) {
|
|
58
|
+
result.push(match);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
58
61
|
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
getCJSExports
|
|
65
|
+
});
|
|
@@ -1,69 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
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 });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// getExposeFromContent.ts
|
|
23
|
+
var getExposeFromContent_exports = {};
|
|
24
|
+
__export(getExposeFromContent_exports, {
|
|
25
|
+
getExposeFromContent: () => getExposeFromContent
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(getExposeFromContent_exports);
|
|
28
|
+
var import_assert = __toESM(require("assert"));
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var import_getModuleExports = require("./getModuleExports");
|
|
10
31
|
async function getExposeFromContent(opts) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 `
|
|
32
|
+
if (opts.filePath && /\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
|
|
33
|
+
return `import '${opts.dep.file}';`;
|
|
34
|
+
}
|
|
35
|
+
if (opts.filePath && /\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(opts.filePath)) {
|
|
36
|
+
return `
|
|
20
37
|
import _ from '${opts.dep.file}';
|
|
21
38
|
export default _;`.trim();
|
|
39
|
+
}
|
|
40
|
+
(0, import_assert.default)(/(js|jsx|mjs|ts|tsx)$/.test(opts.filePath), `file type not supported for ${(0, import_path.basename)(opts.filePath)}.`);
|
|
41
|
+
const { exports, isCJS } = await (0, import_getModuleExports.getModuleExports)({
|
|
42
|
+
content: opts.content,
|
|
43
|
+
filePath: opts.filePath
|
|
44
|
+
});
|
|
45
|
+
if (isCJS) {
|
|
46
|
+
return [
|
|
47
|
+
`import _ from '${opts.dep.file}';`,
|
|
48
|
+
`export default _;`,
|
|
49
|
+
`export * from '${opts.dep.file}';`
|
|
50
|
+
].join("\n");
|
|
51
|
+
} else {
|
|
52
|
+
const ret = [];
|
|
53
|
+
let hasExports = false;
|
|
54
|
+
if (exports.includes("default")) {
|
|
55
|
+
ret.push(`import _ from '${opts.dep.file}';`);
|
|
56
|
+
ret.push(`export default _;`);
|
|
57
|
+
hasExports = true;
|
|
22
58
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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');
|
|
59
|
+
if (hasNonDefaultExports(exports) || /export\s*\*\s*from/.test(opts.content)) {
|
|
60
|
+
ret.push(`export * from '${opts.dep.file}';`);
|
|
61
|
+
hasExports = true;
|
|
35
62
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
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;
|
|
50
|
-
}
|
|
51
|
-
if (!hasExports) {
|
|
52
|
-
// 只有 __esModule 的全量导出
|
|
53
|
-
if (exports.includes('__esModule')) {
|
|
54
|
-
ret.push(`import _ from '${opts.dep.file}';`);
|
|
55
|
-
ret.push(`export default _;`);
|
|
56
|
-
ret.push(`export * from '${opts.dep.file}';`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
ret.push(`import '${opts.dep.file}';`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return ret.join('\n');
|
|
63
|
+
if (!hasExports) {
|
|
64
|
+
if (exports.includes("__esModule")) {
|
|
65
|
+
ret.push(`import _ from '${opts.dep.file}';`);
|
|
66
|
+
ret.push(`export default _;`);
|
|
67
|
+
ret.push(`export * from '${opts.dep.file}';`);
|
|
68
|
+
} else {
|
|
69
|
+
ret.push(`import '${opts.dep.file}';`);
|
|
70
|
+
}
|
|
63
71
|
}
|
|
72
|
+
return ret.join("\n");
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
|
-
exports.getExposeFromContent = getExposeFromContent;
|
|
66
75
|
function hasNonDefaultExports(exports) {
|
|
67
|
-
|
|
68
|
-
.length > 0);
|
|
76
|
+
return exports.filter((exp) => !["__esModule", "default"].includes(exp)).length > 0;
|
|
69
77
|
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
getExposeFromContent
|
|
81
|
+
});
|
|
@@ -1,34 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
// getModuleExports.ts
|
|
20
|
+
var getModuleExports_exports = {};
|
|
21
|
+
__export(getModuleExports_exports, {
|
|
22
|
+
getModuleExports: () => getModuleExports
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(getModuleExports_exports);
|
|
25
|
+
var import_es_module_lexer = require("@umijs/bundler-utils/compiled/es-module-lexer");
|
|
26
|
+
var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var import_getCJSExports = require("./getCJSExports");
|
|
29
|
+
async function getModuleExports({
|
|
30
|
+
content,
|
|
31
|
+
filePath
|
|
32
|
+
}) {
|
|
33
|
+
if (filePath && /\.(tsx|jsx)$/.test(filePath)) {
|
|
34
|
+
content = (await (0, import_esbuild.transform)(content, {
|
|
35
|
+
sourcemap: false,
|
|
36
|
+
sourcefile: filePath,
|
|
37
|
+
format: "esm",
|
|
38
|
+
target: "es6",
|
|
39
|
+
loader: (0, import_path.extname)(filePath).slice(1)
|
|
40
|
+
})).code;
|
|
41
|
+
}
|
|
42
|
+
await import_es_module_lexer.init;
|
|
43
|
+
const [imports, exports] = (0, import_es_module_lexer.parse)(content);
|
|
44
|
+
let isCJS = !imports.length && !exports.length;
|
|
45
|
+
let cjsEsmExports = null;
|
|
46
|
+
if (isCJS) {
|
|
47
|
+
cjsEsmExports = (0, import_getCJSExports.getCJSExports)({ content });
|
|
48
|
+
if (cjsEsmExports.includes("__esModule")) {
|
|
49
|
+
isCJS = false;
|
|
18
50
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
cjsEsmExports = (0, getCJSExports_1.getCJSExports)({ content });
|
|
25
|
-
if (cjsEsmExports.includes('__esModule')) {
|
|
26
|
-
isCJS = false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
exports: cjsEsmExports || exports,
|
|
31
|
-
isCJS,
|
|
32
|
-
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
exports: cjsEsmExports || exports,
|
|
54
|
+
isCJS
|
|
55
|
+
};
|
|
33
56
|
}
|
|
34
|
-
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
getModuleExports
|
|
60
|
+
});
|