@umijs/mfsu 4.0.0-canary.20220718.2 β 4.0.0-canary.20220729.1
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.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/MFImport.js +59 -66
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/awaitImport.js +103 -117
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +129 -132
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +54 -35
- package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
- package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
- package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +51 -52
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +47 -10
- package/dist/dep/dep.d.ts +0 -1
- package/dist/dep/dep.js +112 -83
- package/dist/dep/getCJSExports.d.ts +0 -1
- package/dist/dep/getCJSExports.js +60 -53
- package/dist/dep/getExposeFromContent.d.ts +0 -1
- package/dist/dep/getExposeFromContent.js +71 -61
- package/dist/dep/getModuleExports.d.ts +0 -1
- package/dist/dep/getModuleExports.js +58 -32
- package/dist/depBuilder/depBuilder.d.ts +0 -1
- package/dist/depBuilder/depBuilder.js +192 -158
- package/dist/depBuilder/getESBuildEntry.d.ts +0 -1
- package/dist/depBuilder/getESBuildEntry.js +35 -12
- package/dist/depInfo.d.ts +0 -1
- package/dist/depInfo.js +75 -53
- package/dist/esbuildHandlers/autoCssModules.d.ts +0 -1
- package/dist/esbuildHandlers/autoCssModules.js +43 -22
- package/dist/esbuildHandlers/awaitImport/index.d.ts +0 -1
- package/dist/esbuildHandlers/awaitImport/index.js +82 -70
- package/dist/index.d.ts +0 -1
- package/dist/index.js +32 -22
- package/dist/loader/esbuild.d.ts +0 -1
- package/dist/loader/esbuild.js +87 -35
- package/dist/mfsu/mfsu.d.ts +4 -1
- package/dist/mfsu/mfsu.js +236 -257
- package/dist/mfsu/strategyCompileTime.d.ts +0 -1
- package/dist/mfsu/strategyCompileTime.js +131 -99
- package/dist/mfsu/strategyStaticAnalyze.d.ts +0 -1
- package/dist/mfsu/strategyStaticAnalyze.js +151 -115
- package/dist/moduleGraph.d.ts +0 -1
- package/dist/moduleGraph.js +227 -186
- package/dist/staticDepInfo/importParser.d.ts +0 -1
- package/dist/staticDepInfo/importParser.js +28 -6
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +0 -1
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
- package/dist/staticDepInfo/staticDepInfo.d.ts +0 -1
- package/dist/staticDepInfo/staticDepInfo.js +239 -197
- package/dist/types.d.ts +0 -1
- package/dist/types.js +33 -8
- package/dist/utils/makeArray.d.ts +0 -1
- package/dist/utils/makeArray.js +29 -5
- package/dist/utils/trimFileContent.d.ts +0 -1
- package/dist/utils/trimFileContent.js +29 -5
- package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -1
- package/dist/webpackPlugins/buildDepPlugin.js +49 -25
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +44 -19
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -1
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +46 -27
- package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -1
- package/dist/webpackPlugins/writeCachePlugin.js +39 -15
- package/package.json +8 -6
- package/dist/babelPlugins/awaitImport/MFImport.d.ts.map +0 -1
- 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/esbuildHandlers/autoCssModules.d.ts.map +0 -1
- package/dist/esbuildHandlers/awaitImport/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/loader/esbuild.d.ts.map +0 -1
- package/dist/mfsu/mfsu.d.ts.map +0 -1
- package/dist/mfsu/strategyCompileTime.d.ts.map +0 -1
- package/dist/mfsu/strategyStaticAnalyze.d.ts.map +0 -1
- package/dist/moduleGraph.d.ts.map +0 -1
- package/dist/staticDepInfo/importParser.d.ts.map +0 -1
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts.map +0 -1
- package/dist/staticDepInfo/staticDepInfo.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
|
@@ -1,71 +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
|
+
// src/dep/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
|
-
// case: export*from'.'
|
|
48
|
-
// export * from '.'
|
|
49
|
-
/export\s*\*\s*from/.test(opts.content)) {
|
|
50
|
-
ret.push(`export * from '${opts.dep.file}';`);
|
|
51
|
-
hasExports = true;
|
|
52
|
-
}
|
|
53
|
-
if (!hasExports) {
|
|
54
|
-
// εͺζ __esModule ηε
¨ιε―ΌεΊ
|
|
55
|
-
if (exports.includes('__esModule')) {
|
|
56
|
-
ret.push(`import _ from '${opts.dep.file}';`);
|
|
57
|
-
ret.push(`export default _;`);
|
|
58
|
-
ret.push(`export * from '${opts.dep.file}';`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
ret.push(`import '${opts.dep.file}';`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
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
|
+
}
|
|
65
71
|
}
|
|
72
|
+
return ret.join("\n");
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
|
-
exports.getExposeFromContent = getExposeFromContent;
|
|
68
75
|
function hasNonDefaultExports(exports) {
|
|
69
|
-
|
|
70
|
-
.length > 0);
|
|
76
|
+
return exports.filter((exp) => !["__esModule", "default"].includes(exp)).length > 0;
|
|
71
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
|
+
// src/dep/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
|
+
});
|
|
@@ -1,164 +1,198 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
inlineStyle: true,
|
|
61
|
-
});
|
|
62
|
-
utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
// src/depBuilder/depBuilder.ts
|
|
37
|
+
var depBuilder_exports = {};
|
|
38
|
+
__export(depBuilder_exports, {
|
|
39
|
+
DepBuilder: () => DepBuilder
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(depBuilder_exports);
|
|
42
|
+
var import_bundler_esbuild = require("@umijs/bundler-esbuild");
|
|
43
|
+
var import_utils = require("@umijs/utils");
|
|
44
|
+
var import_fs = require("fs");
|
|
45
|
+
var import_path = require("path");
|
|
46
|
+
var import_constants = require("../constants");
|
|
47
|
+
var import_depChunkIdPrefixPlugin = require("../webpackPlugins/depChunkIdPrefixPlugin");
|
|
48
|
+
var import_stripSourceMapUrlPlugin = require("../webpackPlugins/stripSourceMapUrlPlugin");
|
|
49
|
+
var import_getESBuildEntry = require("./getESBuildEntry");
|
|
50
|
+
var DepBuilder = class {
|
|
51
|
+
constructor(opts) {
|
|
52
|
+
this.completeFns = [];
|
|
53
|
+
this.isBuilding = false;
|
|
54
|
+
this.opts = opts;
|
|
55
|
+
}
|
|
56
|
+
async buildWithWebpack(opts) {
|
|
57
|
+
const config = this.getWebpackConfig({ deps: opts.deps });
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const compiler = this.opts.mfsu.opts.implementor(config);
|
|
60
|
+
compiler.run((err, stats) => {
|
|
63
61
|
opts.onBuildComplete();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const newOpts = {
|
|
75
|
-
...opts,
|
|
76
|
-
onBuildComplete,
|
|
77
|
-
};
|
|
78
|
-
if (this.opts.mfsu.opts.buildDepWithESBuild) {
|
|
79
|
-
await this.buildWithESBuild(newOpts);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
await this.buildWithWebpack(newOpts);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
onBuildComplete();
|
|
87
|
-
throw e;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
onBuildComplete(fn) {
|
|
91
|
-
if (this.isBuilding) {
|
|
92
|
-
this.completeFns.push(fn);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
fn();
|
|
62
|
+
if (err || (stats == null ? void 0 : stats.hasErrors())) {
|
|
63
|
+
if (err) {
|
|
64
|
+
reject(err);
|
|
65
|
+
}
|
|
66
|
+
if (stats) {
|
|
67
|
+
const errorMsg = stats.toString("errors-only");
|
|
68
|
+
reject(new Error(errorMsg));
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
resolve(stats);
|
|
96
72
|
}
|
|
73
|
+
compiler.close(() => {
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async buildWithESBuild(opts) {
|
|
79
|
+
const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({ deps: opts.deps });
|
|
80
|
+
const ENTRY_FILE = "esbuild-entry.js";
|
|
81
|
+
const tmpDir = this.opts.mfsu.opts.tmpBase;
|
|
82
|
+
const entryPath = (0, import_path.join)(tmpDir, ENTRY_FILE);
|
|
83
|
+
(0, import_fs.writeFileSync)(entryPath, entryContent, "utf-8");
|
|
84
|
+
const date = new Date().getTime();
|
|
85
|
+
await (0, import_bundler_esbuild.build)({
|
|
86
|
+
cwd: this.opts.mfsu.opts.cwd,
|
|
87
|
+
entry: {
|
|
88
|
+
[`${import_constants.MF_VA_PREFIX}remoteEntry`]: entryPath
|
|
89
|
+
},
|
|
90
|
+
config: __spreadProps(__spreadValues({}, this.opts.mfsu.opts.depBuildConfig), {
|
|
91
|
+
outputPath: tmpDir,
|
|
92
|
+
alias: this.opts.mfsu.alias,
|
|
93
|
+
externals: this.opts.mfsu.externals
|
|
94
|
+
}),
|
|
95
|
+
inlineStyle: true
|
|
96
|
+
});
|
|
97
|
+
import_utils.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
|
|
98
|
+
opts.onBuildComplete();
|
|
99
|
+
}
|
|
100
|
+
async build(opts) {
|
|
101
|
+
this.isBuilding = true;
|
|
102
|
+
const onBuildComplete = () => {
|
|
103
|
+
this.isBuilding = false;
|
|
104
|
+
this.completeFns.forEach((fn) => fn());
|
|
105
|
+
this.completeFns = [];
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
await this.writeMFFiles({ deps: opts.deps });
|
|
109
|
+
const newOpts = __spreadProps(__spreadValues({}, opts), {
|
|
110
|
+
onBuildComplete
|
|
111
|
+
});
|
|
112
|
+
if (this.opts.mfsu.opts.buildDepWithESBuild) {
|
|
113
|
+
await this.buildWithESBuild(newOpts);
|
|
114
|
+
} else {
|
|
115
|
+
await this.buildWithWebpack(newOpts);
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
onBuildComplete();
|
|
119
|
+
throw e;
|
|
97
120
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
|
|
105
|
-
}
|
|
106
|
-
// index file
|
|
107
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"π"', 'utf-8');
|
|
121
|
+
}
|
|
122
|
+
onBuildComplete(fn) {
|
|
123
|
+
if (this.isBuilding) {
|
|
124
|
+
this.completeFns.push(fn);
|
|
125
|
+
} else {
|
|
126
|
+
fn();
|
|
108
127
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// disable devtool
|
|
117
|
-
depConfig.devtool = false;
|
|
118
|
-
// disable library
|
|
119
|
-
// library δΌε½±ε external ηθ―ζ³οΌε―Όθ΄ζ₯ι
|
|
120
|
-
// ref: https://github.com/umijs/plugins/blob/6d3fc2d/packages/plugin-qiankun/src/slave/index.ts#L83
|
|
121
|
-
if ((_a = depConfig.output) === null || _a === void 0 ? void 0 : _a.library)
|
|
122
|
-
delete depConfig.output.library;
|
|
123
|
-
if ((_b = depConfig.output) === null || _b === void 0 ? void 0 : _b.libraryTarget)
|
|
124
|
-
delete depConfig.output.libraryTarget;
|
|
125
|
-
// merge all deps to vendor
|
|
126
|
-
depConfig.optimization || (depConfig.optimization = {});
|
|
127
|
-
depConfig.optimization.splitChunks = {
|
|
128
|
-
chunks: 'all',
|
|
129
|
-
maxInitialRequests: Infinity,
|
|
130
|
-
minSize: 0,
|
|
131
|
-
cacheGroups: {
|
|
132
|
-
vendor: {
|
|
133
|
-
test: /.+/,
|
|
134
|
-
name(_module, _chunks, cacheGroupKey) {
|
|
135
|
-
return `${constants_1.MF_DEP_PREFIX}___${cacheGroupKey}`;
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
depConfig.plugins = depConfig.plugins || [];
|
|
141
|
-
depConfig.plugins.push(new depChunkIdPrefixPlugin_1.DepChunkIdPrefixPlugin());
|
|
142
|
-
depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
|
|
143
|
-
webpack: this.opts.mfsu.opts.implementor,
|
|
144
|
-
}));
|
|
145
|
-
depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
|
|
146
|
-
this.opts.mfsu.onProgress({ percent, status: msg });
|
|
147
|
-
}));
|
|
148
|
-
const exposes = opts.deps.reduce((memo, dep) => {
|
|
149
|
-
memo[`./${dep.file}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
|
|
150
|
-
return memo;
|
|
151
|
-
}, {});
|
|
152
|
-
depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
|
|
153
|
-
library: {
|
|
154
|
-
type: 'global',
|
|
155
|
-
name: mfName,
|
|
156
|
-
},
|
|
157
|
-
name: mfName,
|
|
158
|
-
filename: constants_1.REMOTE_FILE_FULL,
|
|
159
|
-
exposes,
|
|
160
|
-
}));
|
|
161
|
-
return depConfig;
|
|
128
|
+
}
|
|
129
|
+
async writeMFFiles(opts) {
|
|
130
|
+
const tmpBase = this.opts.mfsu.opts.tmpBase;
|
|
131
|
+
import_utils.fsExtra.mkdirpSync(tmpBase);
|
|
132
|
+
for (const dep of opts.deps) {
|
|
133
|
+
const content = await dep.buildExposeContent();
|
|
134
|
+
(0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, dep.filePath), content, "utf-8");
|
|
162
135
|
}
|
|
163
|
-
|
|
164
|
-
|
|
136
|
+
(0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, "index.js"), `__webpack_public_path__ = document.currentScript.src + '/../';`, "utf-8");
|
|
137
|
+
}
|
|
138
|
+
getWebpackConfig(opts) {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
const mfName = this.opts.mfsu.opts.mfName;
|
|
141
|
+
const depConfig = import_utils.lodash.cloneDeep(this.opts.mfsu.depConfig);
|
|
142
|
+
depConfig.entry = {
|
|
143
|
+
[mfName]: (0, import_path.join)(this.opts.mfsu.opts.tmpBase, "index.js")
|
|
144
|
+
};
|
|
145
|
+
depConfig.output.path = this.opts.mfsu.opts.tmpBase;
|
|
146
|
+
depConfig.devtool = false;
|
|
147
|
+
if ((_a = depConfig.output) == null ? void 0 : _a.library)
|
|
148
|
+
delete depConfig.output.library;
|
|
149
|
+
if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
|
|
150
|
+
delete depConfig.output.libraryTarget;
|
|
151
|
+
depConfig.optimization || (depConfig.optimization = {});
|
|
152
|
+
depConfig.optimization.splitChunks = {
|
|
153
|
+
chunks: (chunk) => {
|
|
154
|
+
const hasShared = chunk.getModules().some((m) => {
|
|
155
|
+
return m.type === "consume-shared-module" || m.type === "provide-module" || m.type === "provide-shared-module";
|
|
156
|
+
});
|
|
157
|
+
return !hasShared;
|
|
158
|
+
},
|
|
159
|
+
maxInitialRequests: Infinity,
|
|
160
|
+
minSize: 0,
|
|
161
|
+
cacheGroups: {
|
|
162
|
+
vendor: {
|
|
163
|
+
test: /.+/,
|
|
164
|
+
name(_module, _chunks, cacheGroupKey) {
|
|
165
|
+
return `${import_constants.MF_DEP_PREFIX}___${cacheGroupKey}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
depConfig.plugins = depConfig.plugins || [];
|
|
171
|
+
depConfig.plugins.push(new import_depChunkIdPrefixPlugin.DepChunkIdPrefixPlugin());
|
|
172
|
+
depConfig.plugins.push(new import_stripSourceMapUrlPlugin.StripSourceMapUrlPlugin({
|
|
173
|
+
webpack: this.opts.mfsu.opts.implementor
|
|
174
|
+
}));
|
|
175
|
+
depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
|
|
176
|
+
this.opts.mfsu.onProgress({ percent, status: msg });
|
|
177
|
+
}));
|
|
178
|
+
const exposes = opts.deps.reduce((memo, dep) => {
|
|
179
|
+
memo[`./${dep.file}`] = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
|
|
180
|
+
return memo;
|
|
181
|
+
}, {});
|
|
182
|
+
depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
|
|
183
|
+
library: {
|
|
184
|
+
type: "global",
|
|
185
|
+
name: mfName
|
|
186
|
+
},
|
|
187
|
+
name: mfName,
|
|
188
|
+
filename: import_constants.REMOTE_FILE_FULL,
|
|
189
|
+
exposes,
|
|
190
|
+
shared: this.opts.mfsu.opts.shared || {}
|
|
191
|
+
}));
|
|
192
|
+
return depConfig;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
196
|
+
0 && (module.exports = {
|
|
197
|
+
DepBuilder
|
|
198
|
+
});
|