@umijs/mfsu 4.5.3 → 4.6.0
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/dist/dep/dep.js +10 -2
- package/dist/dep/getExposeFromContent.js +6 -6
- package/dist/dep/getModuleExports.js +3 -3
- package/dist/depBuilder/depBuilder.js +5 -6
- package/dist/depInfo.js +4 -2
- package/dist/esbuildHandlers/awaitImport/index.js +2 -4
- package/dist/loader/esbuild.js +2 -2
- package/dist/mfsu/mfsu.js +14 -10
- package/dist/mfsu/strategyCompileTime.js +2 -0
- package/dist/mfsu/strategyStaticAnalyze.js +2 -0
- package/dist/moduleGraph.js +13 -15
- package/dist/staticDepInfo/staticDepInfo.js +10 -4
- package/dist/webpackPlugins/buildDepPlugin.js +1 -0
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +1 -0
- package/dist/webpackPlugins/writeCachePlugin.js +1 -0
- package/package.json +4 -4
package/dist/dep/dep.js
CHANGED
|
@@ -41,7 +41,15 @@ var import_constants = require("../constants");
|
|
|
41
41
|
var import_resolveUtils = require("../utils/resolveUtils");
|
|
42
42
|
var import_trimFileContent = require("../utils/trimFileContent");
|
|
43
43
|
var import_getExposeFromContent = require("./getExposeFromContent");
|
|
44
|
-
var Dep = class {
|
|
44
|
+
var Dep = class _Dep {
|
|
45
|
+
file;
|
|
46
|
+
version;
|
|
47
|
+
cwd;
|
|
48
|
+
shortFile;
|
|
49
|
+
normalizedFile;
|
|
50
|
+
filePath;
|
|
51
|
+
excludeNodeNatives;
|
|
52
|
+
importer;
|
|
45
53
|
constructor(opts) {
|
|
46
54
|
this.file = (0, import_utils.winPath)(opts.file);
|
|
47
55
|
this.version = opts.version;
|
|
@@ -105,7 +113,7 @@ export * from '${this.file}';
|
|
|
105
113
|
}
|
|
106
114
|
static buildDeps(opts) {
|
|
107
115
|
return Object.keys(opts.deps).map((file) => {
|
|
108
|
-
return new
|
|
116
|
+
return new _Dep({
|
|
109
117
|
...opts.deps[file],
|
|
110
118
|
cwd: opts.cwd,
|
|
111
119
|
excludeNodeNatives: opts.mfsu.opts.excludeNodeNatives
|
|
@@ -59,7 +59,7 @@ export default _;`.trim();
|
|
|
59
59
|
(0, import_utils.isJavaScriptFile)(opts.filePath),
|
|
60
60
|
`file type not supported for ${(0, import_path.basename)(opts.filePath)}.`
|
|
61
61
|
);
|
|
62
|
-
const { exports, isCJS } = await (0, import_getModuleExports.getModuleExports)({
|
|
62
|
+
const { exports: exports2, isCJS } = await (0, import_getModuleExports.getModuleExports)({
|
|
63
63
|
content: opts.content,
|
|
64
64
|
filePath: opts.filePath
|
|
65
65
|
});
|
|
@@ -72,12 +72,12 @@ export default _;`.trim();
|
|
|
72
72
|
} else {
|
|
73
73
|
const ret = [];
|
|
74
74
|
let hasExports = false;
|
|
75
|
-
if (
|
|
75
|
+
if (exports2.includes("default")) {
|
|
76
76
|
ret.push(`import _ from '${importPath}';`);
|
|
77
77
|
ret.push(`export default _;`);
|
|
78
78
|
hasExports = true;
|
|
79
79
|
}
|
|
80
|
-
if (hasNonDefaultExports(
|
|
80
|
+
if (hasNonDefaultExports(exports2) || // export * from 不会有 exports,只会有 imports
|
|
81
81
|
// case: export*from'.'
|
|
82
82
|
// export * from '.'
|
|
83
83
|
/export\s*\*\s*from/.test(opts.content)) {
|
|
@@ -85,7 +85,7 @@ export default _;`.trim();
|
|
|
85
85
|
hasExports = true;
|
|
86
86
|
}
|
|
87
87
|
if (!hasExports) {
|
|
88
|
-
if (
|
|
88
|
+
if (exports2.includes("__esModule")) {
|
|
89
89
|
ret.push(`import _ from '${importPath}';`);
|
|
90
90
|
ret.push(`export default _;`);
|
|
91
91
|
ret.push(`export * from '${importPath}';`);
|
|
@@ -96,8 +96,8 @@ export default _;`.trim();
|
|
|
96
96
|
return ret.join("\n");
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function hasNonDefaultExports(
|
|
100
|
-
return
|
|
99
|
+
function hasNonDefaultExports(exports2) {
|
|
100
|
+
return exports2.filter((exp) => !["__esModule", "default"].includes(exp)).length > 0;
|
|
101
101
|
}
|
|
102
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
103
|
0 && (module.exports = {
|
|
@@ -40,8 +40,8 @@ async function getModuleExports({
|
|
|
40
40
|
})).code;
|
|
41
41
|
}
|
|
42
42
|
await import_es_module_lexer.init;
|
|
43
|
-
const [imports,
|
|
44
|
-
let isCJS = !imports.length && !
|
|
43
|
+
const [imports, exports2] = (0, import_es_module_lexer.parse)(content);
|
|
44
|
+
let isCJS = !imports.length && !exports2.length;
|
|
45
45
|
let cjsEsmExports = null;
|
|
46
46
|
if (isCJS) {
|
|
47
47
|
cjsEsmExports = (0, import_getCJSExports.getCJSExports)({ content });
|
|
@@ -50,7 +50,7 @@ async function getModuleExports({
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
return {
|
|
53
|
-
exports: cjsEsmExports ||
|
|
53
|
+
exports: cjsEsmExports || exports2,
|
|
54
54
|
isCJS
|
|
55
55
|
};
|
|
56
56
|
}
|
|
@@ -32,9 +32,10 @@ var import_stripSourceMapUrlPlugin = require("../webpackPlugins/stripSourceMapUr
|
|
|
32
32
|
var import_getESBuildEntry = require("./getESBuildEntry");
|
|
33
33
|
var MF_ENTRY = "mf_index.js";
|
|
34
34
|
var DepBuilder = class {
|
|
35
|
+
opts;
|
|
36
|
+
completeFns = [];
|
|
37
|
+
isBuilding = false;
|
|
35
38
|
constructor(opts) {
|
|
36
|
-
this.completeFns = [];
|
|
37
|
-
this.isBuilding = false;
|
|
38
39
|
this.opts = opts;
|
|
39
40
|
}
|
|
40
41
|
async buildWithWebpack(opts) {
|
|
@@ -169,10 +170,8 @@ var DepBuilder = class {
|
|
|
169
170
|
depConfig.output.path = this.opts.mfsu.opts.tmpBase;
|
|
170
171
|
depConfig.output.publicPath = "auto";
|
|
171
172
|
depConfig.devtool = false;
|
|
172
|
-
if ((_a = depConfig.output) == null ? void 0 : _a.library)
|
|
173
|
-
|
|
174
|
-
if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
|
|
175
|
-
delete depConfig.output.libraryTarget;
|
|
173
|
+
if ((_a = depConfig.output) == null ? void 0 : _a.library) delete depConfig.output.library;
|
|
174
|
+
if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget) delete depConfig.output.libraryTarget;
|
|
176
175
|
depConfig.optimization || (depConfig.optimization = {});
|
|
177
176
|
depConfig.optimization.splitChunks = {
|
|
178
177
|
chunks: (chunk) => {
|
package/dist/depInfo.js
CHANGED
|
@@ -27,9 +27,11 @@ var import_fs = require("fs");
|
|
|
27
27
|
var import_path = require("path");
|
|
28
28
|
var import_moduleGraph = require("./moduleGraph");
|
|
29
29
|
var DepInfo = class {
|
|
30
|
+
opts;
|
|
31
|
+
cacheFilePath;
|
|
32
|
+
moduleGraph = new import_moduleGraph.ModuleGraph();
|
|
33
|
+
cacheDependency = {};
|
|
30
34
|
constructor(opts) {
|
|
31
|
-
this.moduleGraph = new import_moduleGraph.ModuleGraph();
|
|
32
|
-
this.cacheDependency = {};
|
|
33
35
|
this.opts = opts;
|
|
34
36
|
this.cacheFilePath = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, "MFSU_CACHE.json");
|
|
35
37
|
}
|
|
@@ -30,8 +30,7 @@ function getImportHandlerV4(params) {
|
|
|
30
30
|
let { code } = opts;
|
|
31
31
|
const { imports } = opts;
|
|
32
32
|
imports.forEach((i) => {
|
|
33
|
-
if (!i.n)
|
|
34
|
-
return;
|
|
33
|
+
if (!i.n) return;
|
|
35
34
|
const isLazyImport = i.d > 0;
|
|
36
35
|
const from = i.n;
|
|
37
36
|
const replaceValue = params.resolveImportSource(from);
|
|
@@ -53,8 +52,7 @@ function getAwaitImportHandler(params) {
|
|
|
53
52
|
let { code } = opts;
|
|
54
53
|
const { filePath, imports } = opts;
|
|
55
54
|
imports.forEach((i) => {
|
|
56
|
-
if (!i.n)
|
|
57
|
-
return;
|
|
55
|
+
if (!i.n) return;
|
|
58
56
|
const isLazyImport = i.d > 0;
|
|
59
57
|
const from = i.n;
|
|
60
58
|
const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
|
package/dist/loader/esbuild.js
CHANGED
|
@@ -62,8 +62,8 @@ async function esbuildTranspiler(source) {
|
|
|
62
62
|
if (handler.length) {
|
|
63
63
|
await import_es_module_lexer.init;
|
|
64
64
|
handler.forEach((handle) => {
|
|
65
|
-
const [imports,
|
|
66
|
-
code = handle({ code, imports, exports, filePath });
|
|
65
|
+
const [imports, exports2] = (0, import_es_module_lexer.parse)(code);
|
|
66
|
+
code = handle({ code, imports, exports: exports2, filePath });
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
done(null, code, map && JSON.parse(map));
|
package/dist/mfsu/mfsu.js
CHANGED
|
@@ -53,14 +53,18 @@ var import_buildDepPlugin = require("../webpackPlugins/buildDepPlugin");
|
|
|
53
53
|
var import_strategyCompileTime = require("./strategyCompileTime");
|
|
54
54
|
var import_strategyStaticAnalyze = require("./strategyStaticAnalyze");
|
|
55
55
|
var MFSU = class {
|
|
56
|
+
opts;
|
|
57
|
+
alias = {};
|
|
58
|
+
externals = [];
|
|
59
|
+
depBuilder;
|
|
60
|
+
depConfig = null;
|
|
61
|
+
buildDepsAgain = false;
|
|
62
|
+
progress = { done: false };
|
|
63
|
+
onProgress;
|
|
64
|
+
publicPath = "/";
|
|
65
|
+
strategy;
|
|
66
|
+
lastBuildError = null;
|
|
56
67
|
constructor(opts) {
|
|
57
|
-
this.alias = {};
|
|
58
|
-
this.externals = [];
|
|
59
|
-
this.depConfig = null;
|
|
60
|
-
this.buildDepsAgain = false;
|
|
61
|
-
this.progress = { done: false };
|
|
62
|
-
this.publicPath = "/";
|
|
63
|
-
this.lastBuildError = null;
|
|
64
68
|
this.opts = opts;
|
|
65
69
|
this.opts.mfName = this.opts.mfName || import_constants.DEFAULT_MF_NAME;
|
|
66
70
|
this.opts.tmpBase = this.opts.tmpBase || (0, import_path.join)(process.cwd(), import_constants.DEFAULT_TMP_DIR_NAME);
|
|
@@ -130,10 +134,10 @@ var MFSU = class {
|
|
|
130
134
|
);
|
|
131
135
|
entry2 = realEntry;
|
|
132
136
|
const content = (0, import_fs.readFileSync)(entry2, "utf-8");
|
|
133
|
-
const [_imports,
|
|
134
|
-
if (
|
|
137
|
+
const [_imports, exports2] = await (0, import_bundler_utils.parseModule)({ content, path: entry2 });
|
|
138
|
+
if (exports2.length) {
|
|
135
139
|
virtualContent.push(`const k${index} = ${this.asyncImport(entry2)}`);
|
|
136
|
-
for (const exportName of
|
|
140
|
+
for (const exportName of exports2) {
|
|
137
141
|
if (exportName === "default") {
|
|
138
142
|
hasDefaultExport = true;
|
|
139
143
|
virtualContent.push(`export default k${index}.${exportName}`);
|
|
@@ -38,6 +38,8 @@ var import_getRealPath = require("../babelPlugins/awaitImport/getRealPath");
|
|
|
38
38
|
var import_dep = require("../dep/dep");
|
|
39
39
|
var import_depInfo = require("../depInfo");
|
|
40
40
|
var StrategyCompileTime = class {
|
|
41
|
+
mfsu;
|
|
42
|
+
depInfo;
|
|
41
43
|
constructor({ mfsu }) {
|
|
42
44
|
this.mfsu = mfsu;
|
|
43
45
|
this.depInfo = new import_depInfo.DepInfo({ mfsu });
|
|
@@ -38,6 +38,8 @@ var import_MFImport = __toESM(require("../babelPlugins/awaitImport/MFImport"));
|
|
|
38
38
|
var import_staticDepInfo = require("../staticDepInfo/staticDepInfo");
|
|
39
39
|
var import_webpackUtils = require("../utils/webpackUtils");
|
|
40
40
|
var StaticAnalyzeStrategy = class {
|
|
41
|
+
mfsu;
|
|
42
|
+
staticDepInfo;
|
|
41
43
|
constructor({ mfsu, srcCodeCache }) {
|
|
42
44
|
this.mfsu = mfsu;
|
|
43
45
|
this.staticDepInfo = new import_staticDepInfo.StaticDepInfo({
|
package/dist/moduleGraph.js
CHANGED
|
@@ -23,21 +23,22 @@ __export(moduleGraph_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(moduleGraph_exports);
|
|
25
25
|
var ModuleNode = class {
|
|
26
|
+
file;
|
|
27
|
+
importers = /* @__PURE__ */ new Set();
|
|
28
|
+
importedModules = /* @__PURE__ */ new Set();
|
|
29
|
+
isDependency = false;
|
|
30
|
+
isRoot = false;
|
|
31
|
+
version = null;
|
|
26
32
|
constructor(file) {
|
|
27
|
-
this.importers = /* @__PURE__ */ new Set();
|
|
28
|
-
this.importedModules = /* @__PURE__ */ new Set();
|
|
29
|
-
this.isDependency = false;
|
|
30
|
-
this.isRoot = false;
|
|
31
|
-
this.version = null;
|
|
32
33
|
this.file = file;
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
var ModuleGraph = class {
|
|
37
|
+
fileToModules = /* @__PURE__ */ new Map();
|
|
38
|
+
depToModules = /* @__PURE__ */ new Map();
|
|
39
|
+
depSnapshotModules = {};
|
|
40
|
+
rootModules = /* @__PURE__ */ new Set();
|
|
36
41
|
constructor() {
|
|
37
|
-
this.fileToModules = /* @__PURE__ */ new Map();
|
|
38
|
-
this.depToModules = /* @__PURE__ */ new Map();
|
|
39
|
-
this.depSnapshotModules = {};
|
|
40
|
-
this.rootModules = /* @__PURE__ */ new Set();
|
|
41
42
|
}
|
|
42
43
|
restore(data) {
|
|
43
44
|
const getModuleNode = (file) => {
|
|
@@ -60,8 +61,7 @@ var ModuleGraph = class {
|
|
|
60
61
|
info = data.depModules[file];
|
|
61
62
|
isDependency = true;
|
|
62
63
|
}
|
|
63
|
-
if (info.isRoot)
|
|
64
|
-
mod.isRoot = true;
|
|
64
|
+
if (info.isRoot) mod.isRoot = true;
|
|
65
65
|
if (importer) {
|
|
66
66
|
mod.importers.add(importer);
|
|
67
67
|
if (!importer.importedModules.has(mod)) {
|
|
@@ -201,13 +201,11 @@ var ModuleGraph = class {
|
|
|
201
201
|
let mod;
|
|
202
202
|
if (modules.has(opts.file)) {
|
|
203
203
|
mod = modules.get(opts.file);
|
|
204
|
-
if (opts.version !== void 0)
|
|
205
|
-
mod.version = opts.version;
|
|
204
|
+
if (opts.version !== void 0) mod.version = opts.version;
|
|
206
205
|
} else {
|
|
207
206
|
mod = new ModuleNode(opts.file);
|
|
208
207
|
mod.isDependency = opts.isDependency;
|
|
209
|
-
if (opts.version !== void 0)
|
|
210
|
-
mod.version = opts.version;
|
|
208
|
+
if (opts.version !== void 0) mod.version = opts.version;
|
|
211
209
|
modules.set(opts.file, mod);
|
|
212
210
|
}
|
|
213
211
|
if (!mod.importers.has(opts.importer)) {
|
|
@@ -40,11 +40,17 @@ var import_checkMatch = require("../babelPlugins/awaitImport/checkMatch");
|
|
|
40
40
|
var import_dep = require("../dep/dep");
|
|
41
41
|
var import_babel_plugin_import = __toESM(require("./simulations/babel-plugin-import"));
|
|
42
42
|
var StaticDepInfo = class {
|
|
43
|
+
opts;
|
|
44
|
+
cacheFilePath;
|
|
45
|
+
mfsu;
|
|
46
|
+
include;
|
|
47
|
+
currentDep = {};
|
|
48
|
+
builtWithDep = {};
|
|
49
|
+
cacheDependency = {};
|
|
50
|
+
produced = [];
|
|
51
|
+
cwd;
|
|
52
|
+
runtimeSimulations;
|
|
43
53
|
constructor(opts) {
|
|
44
|
-
this.currentDep = {};
|
|
45
|
-
this.builtWithDep = {};
|
|
46
|
-
this.cacheDependency = {};
|
|
47
|
-
this.produced = [];
|
|
48
54
|
this.mfsu = opts.mfsu;
|
|
49
55
|
this.include = this.mfsu.opts.include || [];
|
|
50
56
|
this.opts = opts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/mfsu",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "@umijs/mfsu",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/mfsu#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"enhanced-resolve": "5.9.3",
|
|
21
21
|
"is-equal": "^1.6.4",
|
|
22
|
-
"@umijs/bundler-
|
|
23
|
-
"@umijs/
|
|
24
|
-
"@umijs/
|
|
22
|
+
"@umijs/bundler-utils": "4.6.0",
|
|
23
|
+
"@umijs/utils": "4.6.0",
|
|
24
|
+
"@umijs/bundler-esbuild": "4.6.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"is-absolute-url": "^4.0.1",
|