@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.
- package/compiled/is-absolute-url/LICENSE +9 -0
- package/compiled/is-absolute-url/index.d.ts +20 -0
- package/compiled/is-absolute-url/index.js +1 -0
- package/compiled/is-absolute-url/package.json +1 -0
- package/compiled/mrmime/package.json +1 -1
- package/compiled/webpack-virtual-modules/index.js +1 -1
- package/compiled/webpack-virtual-modules/package.json +1 -1
- package/dist/babelPlugins/awaitImport/MFImport.d.ts +24 -0
- package/dist/babelPlugins/awaitImport/MFImport.js +66 -0
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
- package/dist/babelPlugins/awaitImport/awaitImport.js +111 -112
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +3 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +166 -109
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +2 -2
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +44 -33
- package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
- package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +62 -47
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +50 -10
- package/dist/dep/dep.d.ts +11 -4
- package/dist/dep/dep.js +118 -80
- package/dist/dep/getCJSExports.js +83 -47
- package/dist/dep/getExposeFromContent.d.ts +0 -1
- package/dist/dep/getExposeFromContent.js +99 -74
- package/dist/dep/getModuleExports.js +58 -43
- package/dist/depBuilder/depBuilder.d.ts +6 -2
- package/dist/depBuilder/depBuilder.js +222 -158
- package/dist/depBuilder/getESBuildEntry.d.ts +1 -1
- package/dist/depBuilder/getESBuildEntry.js +50 -14
- package/dist/depInfo.d.ts +20 -6
- package/dist/depInfo.js +90 -39
- package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
- package/dist/esbuildHandlers/autoCssModules.js +48 -0
- package/dist/esbuildHandlers/awaitImport/index.d.ts +15 -0
- package/dist/esbuildHandlers/awaitImport/index.js +86 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +35 -13
- package/dist/loader/esbuild.d.ts +5 -0
- package/dist/loader/esbuild.js +79 -0
- package/dist/mfsu/mfsu.d.ts +69 -0
- package/dist/mfsu/mfsu.js +319 -0
- package/dist/mfsu/strategyCompileTime.d.ts +20 -0
- package/dist/mfsu/strategyCompileTime.js +142 -0
- package/dist/mfsu/strategyStaticAnalyze.d.ts +24 -0
- package/dist/mfsu/strategyStaticAnalyze.js +196 -0
- package/dist/moduleGraph.d.ts +6 -9
- package/dist/moduleGraph.js +228 -178
- package/dist/staticDepInfo/importParser.d.ts +4 -0
- package/dist/staticDepInfo/importParser.js +28 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +15 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +118 -0
- package/dist/staticDepInfo/staticDepInfo.d.ts +61 -0
- package/dist/staticDepInfo/staticDepInfo.js +274 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +33 -8
- package/dist/utils/makeArray.js +29 -5
- package/dist/utils/resolveUtils.d.ts +1 -0
- package/dist/utils/resolveUtils.js +104 -0
- package/dist/utils/trimFileContent.js +29 -5
- package/dist/utils/webpackUtils.d.ts +3 -0
- package/dist/utils/webpackUtils.js +80 -0
- package/dist/webpackPlugins/buildDepPlugin.d.ts +4 -3
- package/dist/webpackPlugins/buildDepPlugin.js +61 -17
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +1 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +47 -19
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +55 -27
- package/dist/webpackPlugins/writeCachePlugin.js +45 -15
- package/package.json +32 -28
- package/vendors/importParser/_importParser.js +683 -0
- package/vendors/importParser/importParser.jison +105 -0
- package/dist/babelPlugins/autoExport.d.ts +0 -7
- package/dist/babelPlugins/autoExport.d.ts.map +0 -1
- package/dist/babelPlugins/autoExport.js +0 -61
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/getRealPath.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/isExternals.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/dep/dep.d.ts.map +0 -1
- package/dist/dep/getCJSExports.d.ts.map +0 -1
- package/dist/dep/getExposeFromContent.d.ts.map +0 -1
- package/dist/dep/getModuleExports.d.ts.map +0 -1
- package/dist/depBuilder/depBuilder.d.ts.map +0 -1
- package/dist/depBuilder/getESBuildEntry.d.ts.map +0 -1
- package/dist/depInfo.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mfsu.d.ts +0 -55
- package/dist/mfsu.d.ts.map +0 -1
- package/dist/mfsu.js +0 -173
- package/dist/moduleGraph.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/makeArray.d.ts.map +0 -1
- package/dist/utils/trimFileContent.d.ts.map +0 -1
- package/dist/webpackPlugins/buildDepPlugin.d.ts.map +0 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts.map +0 -1
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts.map +0 -1
- package/dist/webpackPlugins/writeCachePlugin.d.ts.map +0 -1
package/dist/constants.js
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
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
|
+
// 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
|
-
|
|
9
|
+
excludeNodeNatives: boolean;
|
|
10
|
+
importer: string | undefined;
|
|
10
11
|
constructor(opts: {
|
|
11
12
|
file: string;
|
|
12
13
|
version: string;
|
|
13
14
|
cwd: string;
|
|
14
|
-
|
|
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
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
// 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
|
-
|
|
6
|
-
|
|
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(
|
|
10
|
-
|
|
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
|
-
|
|
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(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
});
|
|
@@ -1,80 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
+
});
|