@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
|
@@ -1,45 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
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 });
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
exports: cjsEsmExports || exports,
|
|
54
|
+
isCJS
|
|
55
|
+
};
|
|
44
56
|
}
|
|
45
|
-
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
getModuleExports
|
|
60
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dep } from '../dep/dep';
|
|
2
|
-
import { MFSU } from '../mfsu';
|
|
2
|
+
import { MFSU } from '../mfsu/mfsu';
|
|
3
3
|
interface IOpts {
|
|
4
4
|
mfsu: MFSU;
|
|
5
5
|
}
|
|
@@ -16,8 +16,13 @@ export declare class DepBuilder {
|
|
|
16
16
|
onBuildComplete: Function;
|
|
17
17
|
deps: Dep[];
|
|
18
18
|
}): Promise<void>;
|
|
19
|
+
buildWithWorker(opts: {
|
|
20
|
+
onBuildComplete: Function;
|
|
21
|
+
deps: Dep[];
|
|
22
|
+
}): Promise<void>;
|
|
19
23
|
build(opts: {
|
|
20
24
|
deps: Dep[];
|
|
25
|
+
useWorker: boolean;
|
|
21
26
|
}): Promise<void>;
|
|
22
27
|
onBuildComplete(fn: Function): void;
|
|
23
28
|
writeMFFiles(opts: {
|
|
@@ -28,4 +33,3 @@ export declare class DepBuilder {
|
|
|
28
33
|
}): import("webpack").Configuration;
|
|
29
34
|
}
|
|
30
35
|
export {};
|
|
31
|
-
//# sourceMappingURL=depBuilder.d.ts.map
|
|
@@ -1,165 +1,229 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
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 });
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
const date = new Date().getTime();
|
|
61
|
-
yield (0, bundler_esbuild_1.build)({
|
|
62
|
-
cwd: this.opts.mfsu.opts.cwd,
|
|
63
|
-
entry: {
|
|
64
|
-
[`${constants_1.MF_VA_PREFIX}remoteEntry`]: entryPath,
|
|
65
|
-
},
|
|
66
|
-
config: {
|
|
67
|
-
outputPath: tmpDir,
|
|
68
|
-
alias: this.opts.mfsu.alias,
|
|
69
|
-
externals: this.opts.mfsu.externals,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
|
|
73
|
-
opts.onBuildComplete();
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
build(opts) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
this.isBuilding = true;
|
|
79
|
-
yield this.writeMFFiles({ deps: opts.deps });
|
|
80
|
-
const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
|
|
81
|
-
this.isBuilding = false;
|
|
82
|
-
this.completeFns.forEach((fn) => fn());
|
|
83
|
-
this.completeFns = [];
|
|
84
|
-
} });
|
|
85
|
-
if (this.opts.mfsu.opts.buildDepWithESBuild) {
|
|
86
|
-
yield this.buildWithESBuild(newOpts);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
yield this.buildWithWebpack(newOpts);
|
|
90
|
-
}
|
|
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/depBuilder/depBuilder.ts
|
|
20
|
+
var depBuilder_exports = {};
|
|
21
|
+
__export(depBuilder_exports, {
|
|
22
|
+
DepBuilder: () => DepBuilder
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(depBuilder_exports);
|
|
25
|
+
var import_bundler_esbuild = require("@umijs/bundler-esbuild");
|
|
26
|
+
var import_utils = require("@umijs/utils");
|
|
27
|
+
var import_fs = require("fs");
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_constants = require("../constants");
|
|
30
|
+
var import_depChunkIdPrefixPlugin = require("../webpackPlugins/depChunkIdPrefixPlugin");
|
|
31
|
+
var import_stripSourceMapUrlPlugin = require("../webpackPlugins/stripSourceMapUrlPlugin");
|
|
32
|
+
var import_getESBuildEntry = require("./getESBuildEntry");
|
|
33
|
+
var MF_ENTRY = "mf_index.js";
|
|
34
|
+
var DepBuilder = class {
|
|
35
|
+
constructor(opts) {
|
|
36
|
+
this.completeFns = [];
|
|
37
|
+
this.isBuilding = false;
|
|
38
|
+
this.opts = opts;
|
|
39
|
+
}
|
|
40
|
+
async buildWithWebpack(opts) {
|
|
41
|
+
const config = this.getWebpackConfig({ deps: opts.deps });
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const compiler = this.opts.mfsu.opts.implementor(config);
|
|
44
|
+
compiler.run((err, stats) => {
|
|
45
|
+
opts.onBuildComplete();
|
|
46
|
+
if (err || (stats == null ? void 0 : stats.hasErrors())) {
|
|
47
|
+
if (err) {
|
|
48
|
+
reject(err);
|
|
49
|
+
}
|
|
50
|
+
if (stats) {
|
|
51
|
+
const errorMsg = stats.toString("errors-only");
|
|
52
|
+
reject(new Error(errorMsg));
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
resolve(stats);
|
|
56
|
+
}
|
|
57
|
+
compiler.close(() => {
|
|
91
58
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// TODO: support watch and rebuild
|
|
63
|
+
async buildWithESBuild(opts) {
|
|
64
|
+
const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({
|
|
65
|
+
mfName: this.opts.mfsu.opts.mfName,
|
|
66
|
+
deps: opts.deps
|
|
67
|
+
});
|
|
68
|
+
const ENTRY_FILE = "esbuild-entry.js";
|
|
69
|
+
const tmpDir = this.opts.mfsu.opts.tmpBase;
|
|
70
|
+
const entryPath = (0, import_path.join)(tmpDir, ENTRY_FILE);
|
|
71
|
+
(0, import_fs.writeFileSync)(entryPath, entryContent, "utf-8");
|
|
72
|
+
const date = (/* @__PURE__ */ new Date()).getTime();
|
|
73
|
+
await (0, import_bundler_esbuild.build)({
|
|
74
|
+
cwd: this.opts.mfsu.opts.cwd,
|
|
75
|
+
entry: {
|
|
76
|
+
[`${import_constants.MF_VA_PREFIX}remoteEntry`]: entryPath
|
|
77
|
+
},
|
|
78
|
+
config: {
|
|
79
|
+
...this.opts.mfsu.opts.depBuildConfig,
|
|
80
|
+
outputPath: tmpDir,
|
|
81
|
+
alias: this.opts.mfsu.alias,
|
|
82
|
+
externals: this.opts.mfsu.externals
|
|
83
|
+
},
|
|
84
|
+
inlineStyle: true
|
|
85
|
+
});
|
|
86
|
+
import_utils.logger.event(
|
|
87
|
+
`[mfsu] compiled with esbuild successfully in ${+/* @__PURE__ */ new Date() - date} ms`
|
|
88
|
+
);
|
|
89
|
+
opts.onBuildComplete();
|
|
90
|
+
}
|
|
91
|
+
async buildWithWorker(opts) {
|
|
92
|
+
const worker = this.opts.mfsu.opts.startBuildWorker(opts.deps);
|
|
93
|
+
worker.postMessage(opts.deps);
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const onMessage = ({
|
|
96
|
+
progress,
|
|
97
|
+
done
|
|
98
|
+
}) => {
|
|
99
|
+
if (done) {
|
|
100
|
+
opts.onBuildComplete();
|
|
101
|
+
worker.off("message", onMessage);
|
|
102
|
+
if (done.withError) {
|
|
103
|
+
import_utils.logger.debug("[MFSU][eager][main] build failed", done.withError);
|
|
104
|
+
reject(done.withError);
|
|
105
|
+
} else {
|
|
106
|
+
resolve();
|
|
107
|
+
}
|
|
96
108
|
}
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
if (progress) {
|
|
110
|
+
this.opts.mfsu.onProgress(progress);
|
|
99
111
|
}
|
|
112
|
+
};
|
|
113
|
+
worker.on("message", onMessage);
|
|
114
|
+
worker.once("error", (e) => {
|
|
115
|
+
import_utils.logger.error("[MFSU][eager] worker got Error", e);
|
|
116
|
+
opts.onBuildComplete();
|
|
117
|
+
reject(e);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async build(opts) {
|
|
122
|
+
this.isBuilding = true;
|
|
123
|
+
const onBuildComplete = () => {
|
|
124
|
+
this.isBuilding = false;
|
|
125
|
+
this.completeFns.forEach((fn) => fn());
|
|
126
|
+
this.completeFns = [];
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
const buildOpts = {
|
|
130
|
+
...opts,
|
|
131
|
+
onBuildComplete
|
|
132
|
+
};
|
|
133
|
+
if (this.opts.mfsu.opts.strategy === "eager" && opts.useWorker) {
|
|
134
|
+
await this.buildWithWorker(buildOpts);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await this.writeMFFiles({ deps: opts.deps });
|
|
138
|
+
if (this.opts.mfsu.opts.buildDepWithESBuild) {
|
|
139
|
+
await this.buildWithESBuild(buildOpts);
|
|
140
|
+
} else {
|
|
141
|
+
await this.buildWithWebpack(buildOpts);
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
onBuildComplete();
|
|
145
|
+
throw e;
|
|
100
146
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
|
|
108
|
-
}
|
|
109
|
-
// index file
|
|
110
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"😛"', 'utf-8');
|
|
111
|
-
});
|
|
147
|
+
}
|
|
148
|
+
onBuildComplete(fn) {
|
|
149
|
+
if (this.isBuilding) {
|
|
150
|
+
this.completeFns.push(fn);
|
|
151
|
+
} else {
|
|
152
|
+
fn();
|
|
112
153
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// disable devtool
|
|
121
|
-
depConfig.devtool = false;
|
|
122
|
-
// disable library
|
|
123
|
-
// library 会影响 external 的语法,导致报错
|
|
124
|
-
// ref: https://github.com/umijs/plugins/blob/6d3fc2d/packages/plugin-qiankun/src/slave/index.ts#L83
|
|
125
|
-
if ((_a = depConfig.output) === null || _a === void 0 ? void 0 : _a.library)
|
|
126
|
-
delete depConfig.output.library;
|
|
127
|
-
if ((_b = depConfig.output) === null || _b === void 0 ? void 0 : _b.libraryTarget)
|
|
128
|
-
delete depConfig.output.libraryTarget;
|
|
129
|
-
// merge all deps to vendor
|
|
130
|
-
depConfig.optimization || (depConfig.optimization = {});
|
|
131
|
-
depConfig.optimization.splitChunks = {
|
|
132
|
-
chunks: 'all',
|
|
133
|
-
maxInitialRequests: Infinity,
|
|
134
|
-
minSize: 0,
|
|
135
|
-
cacheGroups: {
|
|
136
|
-
vendor: {
|
|
137
|
-
test: /.+/,
|
|
138
|
-
name(_module, _chunks, cacheGroupKey) {
|
|
139
|
-
return `${constants_1.MF_DEP_PREFIX}___${cacheGroupKey}`;
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
depConfig.plugins = depConfig.plugins || [];
|
|
145
|
-
depConfig.plugins.push(new depChunkIdPrefixPlugin_1.DepChunkIdPrefixPlugin());
|
|
146
|
-
depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
|
|
147
|
-
webpack: this.opts.mfsu.opts.implementor,
|
|
148
|
-
}));
|
|
149
|
-
const exposes = opts.deps.reduce((memo, dep) => {
|
|
150
|
-
memo[`./${dep.shortFile}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
|
|
151
|
-
return memo;
|
|
152
|
-
}, {});
|
|
153
|
-
depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
|
|
154
|
-
library: {
|
|
155
|
-
type: 'global',
|
|
156
|
-
name: mfName,
|
|
157
|
-
},
|
|
158
|
-
name: mfName,
|
|
159
|
-
filename: constants_1.REMOTE_FILE_FULL,
|
|
160
|
-
exposes,
|
|
161
|
-
}));
|
|
162
|
-
return depConfig;
|
|
154
|
+
}
|
|
155
|
+
async writeMFFiles(opts) {
|
|
156
|
+
const tmpBase = this.opts.mfsu.opts.tmpBase;
|
|
157
|
+
import_utils.fsExtra.mkdirpSync(tmpBase);
|
|
158
|
+
for (const dep of opts.deps) {
|
|
159
|
+
const content = await dep.buildExposeContent();
|
|
160
|
+
(0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, dep.filePath), content, "utf-8");
|
|
163
161
|
}
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
(0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, MF_ENTRY), '"😛"', "utf-8");
|
|
163
|
+
}
|
|
164
|
+
getWebpackConfig(opts) {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
const mfName = this.opts.mfsu.opts.mfName;
|
|
167
|
+
const depConfig = import_utils.lodash.cloneDeep(this.opts.mfsu.depConfig);
|
|
168
|
+
depConfig.entry = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, MF_ENTRY);
|
|
169
|
+
depConfig.output.path = this.opts.mfsu.opts.tmpBase;
|
|
170
|
+
depConfig.output.publicPath = "auto";
|
|
171
|
+
depConfig.devtool = false;
|
|
172
|
+
if ((_a = depConfig.output) == null ? void 0 : _a.library)
|
|
173
|
+
delete depConfig.output.library;
|
|
174
|
+
if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
|
|
175
|
+
delete depConfig.output.libraryTarget;
|
|
176
|
+
depConfig.optimization || (depConfig.optimization = {});
|
|
177
|
+
depConfig.optimization.splitChunks = {
|
|
178
|
+
chunks: (chunk) => {
|
|
179
|
+
const hasShared = chunk.getModules().some((m) => {
|
|
180
|
+
return m.type === "consume-shared-module" || m.type === "provide-module" || m.type === "provide-shared-module";
|
|
181
|
+
});
|
|
182
|
+
return !hasShared;
|
|
183
|
+
},
|
|
184
|
+
maxInitialRequests: Infinity,
|
|
185
|
+
minSize: 0,
|
|
186
|
+
cacheGroups: {
|
|
187
|
+
vendor: {
|
|
188
|
+
test: /.+/,
|
|
189
|
+
name(_module, _chunks, cacheGroupKey) {
|
|
190
|
+
return `${import_constants.MF_DEP_PREFIX}___${cacheGroupKey}`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
depConfig.plugins = depConfig.plugins || [];
|
|
196
|
+
depConfig.plugins.push(new import_depChunkIdPrefixPlugin.DepChunkIdPrefixPlugin());
|
|
197
|
+
depConfig.plugins.push(
|
|
198
|
+
new import_stripSourceMapUrlPlugin.StripSourceMapUrlPlugin({
|
|
199
|
+
webpack: this.opts.mfsu.opts.implementor
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
depConfig.plugins.push(
|
|
203
|
+
new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
|
|
204
|
+
this.opts.mfsu.onProgress({ percent, status: msg });
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
const exposes = opts.deps.reduce((memo, dep) => {
|
|
208
|
+
memo[`./${dep.file}`] = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
|
|
209
|
+
return memo;
|
|
210
|
+
}, {});
|
|
211
|
+
depConfig.plugins.push(
|
|
212
|
+
new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
|
|
213
|
+
library: {
|
|
214
|
+
type: "global",
|
|
215
|
+
name: mfName
|
|
216
|
+
},
|
|
217
|
+
name: mfName,
|
|
218
|
+
filename: import_constants.REMOTE_FILE_FULL,
|
|
219
|
+
exposes,
|
|
220
|
+
shared: this.opts.mfsu.opts.shared || {}
|
|
221
|
+
})
|
|
222
|
+
);
|
|
223
|
+
return depConfig;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
227
|
+
0 && (module.exports = {
|
|
228
|
+
DepBuilder
|
|
229
|
+
});
|
|
@@ -1,9 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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/depBuilder/getESBuildEntry.ts
|
|
20
|
+
var getESBuildEntry_exports = {};
|
|
21
|
+
__export(getESBuildEntry_exports, {
|
|
22
|
+
getESBuildEntry: () => getESBuildEntry
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(getESBuildEntry_exports);
|
|
25
|
+
var import_constants = require("../constants");
|
|
26
|
+
var ES_INTEROP_FUNC = `__exportStar`;
|
|
27
|
+
var ES_INTEROP_HELPER = `
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
31
|
+
}) : (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
o[k2] = m[k];
|
|
34
|
+
}));
|
|
35
|
+
var ${ES_INTEROP_FUNC} = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
`;
|
|
5
39
|
function getESBuildEntry(opts) {
|
|
6
|
-
|
|
40
|
+
return `
|
|
7
41
|
(function() {
|
|
8
42
|
/******/ "use strict";
|
|
9
43
|
/******/ var __webpack_modules__ = ({});
|
|
@@ -266,8 +300,9 @@ function getESBuildEntry(opts) {
|
|
|
266
300
|
var __webpack_exports__ = {};
|
|
267
301
|
(function() {
|
|
268
302
|
var exports = __webpack_exports__;
|
|
303
|
+
${ES_INTEROP_HELPER}
|
|
269
304
|
var moduleMap = {
|
|
270
|
-
${opts.deps.map(getDepModuleStr).join(
|
|
305
|
+
${opts.deps.map(getDepModuleStr).join(",\n")}
|
|
271
306
|
};
|
|
272
307
|
var get = function(module, getScope) {
|
|
273
308
|
__webpack_require__.R = getScope;
|
|
@@ -293,23 +328,24 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
|
|
|
293
328
|
get: function() { return get; },
|
|
294
329
|
init: function() { return init; }
|
|
295
330
|
});
|
|
296
|
-
self.
|
|
331
|
+
self.${opts.mfName} = __webpack_exports__;
|
|
297
332
|
})();
|
|
298
333
|
})();
|
|
299
334
|
`;
|
|
300
335
|
}
|
|
301
|
-
exports.getESBuildEntry = getESBuildEntry;
|
|
302
|
-
function normalizeFile(file) {
|
|
303
|
-
return file.replace(/\//g, '_');
|
|
304
|
-
}
|
|
305
336
|
function getDepModuleStr(dep) {
|
|
306
|
-
|
|
337
|
+
return `
|
|
307
338
|
"./${dep.file}": function() {
|
|
308
339
|
return new Promise(resolve => {
|
|
309
|
-
import('./${
|
|
310
|
-
|
|
340
|
+
import('./${import_constants.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
|
|
341
|
+
module.default && ${ES_INTEROP_FUNC}(module, module.default);
|
|
342
|
+
resolve(() => module.default || module);
|
|
311
343
|
});
|
|
312
344
|
})
|
|
313
345
|
}
|
|
314
346
|
`.trim();
|
|
315
347
|
}
|
|
348
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
349
|
+
0 && (module.exports = {
|
|
350
|
+
getESBuildEntry
|
|
351
|
+
});
|
package/dist/depInfo.d.ts
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import { MFSU } from './mfsu';
|
|
1
|
+
import { MFSU } from './mfsu/mfsu';
|
|
2
2
|
import { ModuleGraph } from './moduleGraph';
|
|
3
3
|
interface IOpts {
|
|
4
4
|
mfsu: MFSU;
|
|
5
5
|
}
|
|
6
|
-
export declare
|
|
6
|
+
export declare type DepModule = {
|
|
7
|
+
file: string;
|
|
8
|
+
version: string;
|
|
9
|
+
importer?: string;
|
|
10
|
+
};
|
|
11
|
+
export interface IDepInfo {
|
|
12
|
+
shouldBuild(): string | boolean;
|
|
13
|
+
snapshot(): void;
|
|
14
|
+
loadCache(): void;
|
|
15
|
+
writeCache(): void;
|
|
16
|
+
getCacheFilePath(): string;
|
|
17
|
+
getDepModules(): Record<string, DepModule>;
|
|
18
|
+
}
|
|
19
|
+
export declare class DepInfo implements IDepInfo {
|
|
7
20
|
private opts;
|
|
8
|
-
cacheFilePath
|
|
21
|
+
private readonly cacheFilePath;
|
|
9
22
|
moduleGraph: ModuleGraph;
|
|
10
|
-
cacheDependency
|
|
23
|
+
private cacheDependency;
|
|
11
24
|
constructor(opts: IOpts);
|
|
12
|
-
shouldBuild():
|
|
25
|
+
shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
|
|
13
26
|
snapshot(): void;
|
|
14
27
|
loadCache(): void;
|
|
15
28
|
writeCache(): void;
|
|
29
|
+
getDepModules(): Record<string, DepModule>;
|
|
30
|
+
getCacheFilePath(): string;
|
|
16
31
|
}
|
|
17
32
|
export {};
|
|
18
|
-
//# sourceMappingURL=depInfo.d.ts.map
|