@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
|
@@ -0,0 +1,319 @@
|
|
|
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
|
+
};
|
|
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(
|
|
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/mfsu/mfsu.ts
|
|
30
|
+
var mfsu_exports = {};
|
|
31
|
+
__export(mfsu_exports, {
|
|
32
|
+
MFSU: () => MFSU,
|
|
33
|
+
resolvePublicPath: () => resolvePublicPath
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(mfsu_exports);
|
|
36
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
37
|
+
var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
|
|
38
|
+
var import_utils = require("@umijs/utils");
|
|
39
|
+
var import_assert = __toESM(require("assert"));
|
|
40
|
+
var import_fs = require("fs");
|
|
41
|
+
var import_path = require("path");
|
|
42
|
+
var import_is_absolute_url = __toESM(require("../../compiled/is-absolute-url"));
|
|
43
|
+
var import_mrmime = require("../../compiled/mrmime");
|
|
44
|
+
var import_webpack_virtual_modules = __toESM(require("../../compiled/webpack-virtual-modules"));
|
|
45
|
+
var import_constants = require("../constants");
|
|
46
|
+
var import_dep = require("../dep/dep");
|
|
47
|
+
var import_depBuilder = require("../depBuilder/depBuilder");
|
|
48
|
+
var import_awaitImport = __toESM(require("../esbuildHandlers/awaitImport"));
|
|
49
|
+
var import_types = require("../types");
|
|
50
|
+
var import_makeArray = require("../utils/makeArray");
|
|
51
|
+
var import_webpackUtils = require("../utils/webpackUtils");
|
|
52
|
+
var import_buildDepPlugin = require("../webpackPlugins/buildDepPlugin");
|
|
53
|
+
var import_strategyCompileTime = require("./strategyCompileTime");
|
|
54
|
+
var import_strategyStaticAnalyze = require("./strategyStaticAnalyze");
|
|
55
|
+
var MFSU = class {
|
|
56
|
+
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
|
+
this.opts = opts;
|
|
65
|
+
this.opts.mfName = this.opts.mfName || import_constants.DEFAULT_MF_NAME;
|
|
66
|
+
this.opts.tmpBase = this.opts.tmpBase || (0, import_path.join)(process.cwd(), import_constants.DEFAULT_TMP_DIR_NAME);
|
|
67
|
+
this.opts.mode = this.opts.mode || import_types.Mode.development;
|
|
68
|
+
this.opts.getCacheDependency = this.opts.getCacheDependency || (() => ({}));
|
|
69
|
+
this.onProgress = (progress) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
this.progress = {
|
|
72
|
+
...this.progress,
|
|
73
|
+
...progress
|
|
74
|
+
};
|
|
75
|
+
(_b = (_a = this.opts).onMFSUProgress) == null ? void 0 : _b.call(_a, this.progress);
|
|
76
|
+
};
|
|
77
|
+
this.opts.cwd = this.opts.cwd || process.cwd();
|
|
78
|
+
if (this.opts.strategy === "eager") {
|
|
79
|
+
if (opts.srcCodeCache) {
|
|
80
|
+
import_utils.logger.info("MFSU eager strategy enabled");
|
|
81
|
+
this.strategy = new import_strategyStaticAnalyze.StaticAnalyzeStrategy({
|
|
82
|
+
mfsu: this,
|
|
83
|
+
srcCodeCache: opts.srcCodeCache
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
import_utils.logger.warn(
|
|
87
|
+
"fallback to MFSU normal strategy, due to srcCache is not provided"
|
|
88
|
+
);
|
|
89
|
+
this.strategy = new import_strategyCompileTime.StrategyCompileTime({ mfsu: this });
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
this.strategy = new import_strategyCompileTime.StrategyCompileTime({ mfsu: this });
|
|
93
|
+
}
|
|
94
|
+
this.strategy.loadCache();
|
|
95
|
+
this.depBuilder = new import_depBuilder.DepBuilder({ mfsu: this });
|
|
96
|
+
}
|
|
97
|
+
// swc don't support top-level await
|
|
98
|
+
// ref: https://github.com/vercel/next.js/issues/31054
|
|
99
|
+
asyncImport(content) {
|
|
100
|
+
return `await import('${(0, import_utils.winPath)(content)}');`;
|
|
101
|
+
}
|
|
102
|
+
async setWebpackConfig(opts) {
|
|
103
|
+
var _a;
|
|
104
|
+
const { mfName } = this.opts;
|
|
105
|
+
Object.assign(this.alias, ((_a = opts.config.resolve) == null ? void 0 : _a.alias) || {});
|
|
106
|
+
this.externals.push(...(0, import_makeArray.makeArray)(opts.config.externals || []));
|
|
107
|
+
const entry = {};
|
|
108
|
+
const virtualModules = {};
|
|
109
|
+
const entryObject = import_utils.lodash.isString(opts.config.entry) ? { default: [opts.config.entry] } : opts.config.entry;
|
|
110
|
+
(0, import_assert.default)(
|
|
111
|
+
import_utils.lodash.isPlainObject(entryObject),
|
|
112
|
+
`webpack config 'entry' value must be a string or an object.`
|
|
113
|
+
);
|
|
114
|
+
for (const key of Object.keys(entryObject)) {
|
|
115
|
+
if (key === this.opts.remoteName) {
|
|
116
|
+
entry[key] = entryObject[key];
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const virtualPath = `./${import_constants.VIRTUAL_ENTRY_DIR}/${key}.js`;
|
|
120
|
+
const virtualContent = [];
|
|
121
|
+
let index = 1;
|
|
122
|
+
let hasDefaultExport = false;
|
|
123
|
+
const entryFiles = import_utils.lodash.isArray(entryObject[key]) ? entryObject[key] : [entryObject[key]];
|
|
124
|
+
const resolver = (0, import_webpackUtils.getResolver)(opts.config);
|
|
125
|
+
for (let entry2 of entryFiles) {
|
|
126
|
+
const realEntry = resolver(entry2);
|
|
127
|
+
(0, import_assert.default)(
|
|
128
|
+
realEntry,
|
|
129
|
+
`entry file not found (${entry2}), please configure the specific entry path. (e.g. 'src/index.tsx')`
|
|
130
|
+
);
|
|
131
|
+
entry2 = realEntry;
|
|
132
|
+
const content = (0, import_fs.readFileSync)(entry2, "utf-8");
|
|
133
|
+
const [_imports, exports] = await (0, import_bundler_utils.parseModule)({ content, path: entry2 });
|
|
134
|
+
if (exports.length) {
|
|
135
|
+
virtualContent.push(`const k${index} = ${this.asyncImport(entry2)}`);
|
|
136
|
+
for (const exportName of exports) {
|
|
137
|
+
if (exportName === "default") {
|
|
138
|
+
hasDefaultExport = true;
|
|
139
|
+
virtualContent.push(`export default k${index}.${exportName}`);
|
|
140
|
+
} else {
|
|
141
|
+
virtualContent.push(
|
|
142
|
+
`export const ${exportName} = k${index}.${exportName}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
virtualContent.push(this.asyncImport(entry2));
|
|
148
|
+
}
|
|
149
|
+
index += 1;
|
|
150
|
+
}
|
|
151
|
+
if (!hasDefaultExport) {
|
|
152
|
+
virtualContent.push(`export default 1;`);
|
|
153
|
+
}
|
|
154
|
+
virtualModules[virtualPath] = virtualContent.join("\n");
|
|
155
|
+
entry[key] = virtualPath;
|
|
156
|
+
}
|
|
157
|
+
opts.config.entry = entry;
|
|
158
|
+
opts.config.plugins = opts.config.plugins || [];
|
|
159
|
+
let publicPath = resolvePublicPath(opts.config);
|
|
160
|
+
this.publicPath = publicPath;
|
|
161
|
+
opts.config.plugins.push(
|
|
162
|
+
...[
|
|
163
|
+
new import_webpack_virtual_modules.default(virtualModules),
|
|
164
|
+
new this.opts.implementor.container.ModuleFederationPlugin({
|
|
165
|
+
name: "__",
|
|
166
|
+
shared: this.opts.shared || {},
|
|
167
|
+
remotes: {
|
|
168
|
+
[mfName]: this.opts.runtimePublicPath ? (
|
|
169
|
+
// ref:
|
|
170
|
+
// https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes
|
|
171
|
+
`
|
|
172
|
+
promise new Promise(resolve => {
|
|
173
|
+
const remoteUrlWithVersion = (window.publicPath || '/') + '${import_constants.REMOTE_FILE_FULL}';
|
|
174
|
+
const script = document.createElement('script');
|
|
175
|
+
script.src = remoteUrlWithVersion;
|
|
176
|
+
script.onload = () => {
|
|
177
|
+
// the injected script has loaded and is available on window
|
|
178
|
+
// we can now resolve this Promise
|
|
179
|
+
const proxy = {
|
|
180
|
+
get: (request) => window['${mfName}'].get(request),
|
|
181
|
+
init: (arg) => {
|
|
182
|
+
try {
|
|
183
|
+
return window['${mfName}'].init(arg);
|
|
184
|
+
} catch(e) {
|
|
185
|
+
console.log('remote container already initialized');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
resolve(proxy);
|
|
190
|
+
}
|
|
191
|
+
// inject this script with the src set to the versioned remoteEntry.js
|
|
192
|
+
document.head.appendChild(script);
|
|
193
|
+
})
|
|
194
|
+
`.trimStart()
|
|
195
|
+
) : `${mfName}@${publicPath}${import_constants.REMOTE_FILE_FULL}`
|
|
196
|
+
// mfsu 的入口文件如果需要在其他的站点上被引用,需要显示的指定publicPath,以保证入口文件的正确访问
|
|
197
|
+
}
|
|
198
|
+
}),
|
|
199
|
+
new import_buildDepPlugin.BuildDepPlugin(this.strategy.getBuildDepPlugConfig())
|
|
200
|
+
// new WriteCachePlugin({
|
|
201
|
+
// onWriteCache: lodash.debounce(() => {
|
|
202
|
+
// this.depInfo.writeCache();
|
|
203
|
+
// }, 300),
|
|
204
|
+
// }),
|
|
205
|
+
]
|
|
206
|
+
);
|
|
207
|
+
import_utils.lodash.set(opts.config, "experiments.topLevelAwait", true);
|
|
208
|
+
this.depConfig = opts.depConfig;
|
|
209
|
+
this.strategy.init(opts.config);
|
|
210
|
+
}
|
|
211
|
+
async buildDeps(opts = { useWorker: true }) {
|
|
212
|
+
try {
|
|
213
|
+
const shouldBuild = this.strategy.shouldBuild();
|
|
214
|
+
if (!shouldBuild) {
|
|
215
|
+
import_utils.logger.info("[MFSU] skip buildDeps");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.strategy.refresh();
|
|
219
|
+
const staticDeps = this.strategy.getDepModules();
|
|
220
|
+
const deps = import_dep.Dep.buildDeps({
|
|
221
|
+
deps: staticDeps,
|
|
222
|
+
cwd: this.opts.cwd,
|
|
223
|
+
mfsu: this
|
|
224
|
+
});
|
|
225
|
+
import_utils.logger.info(`[MFSU] buildDeps since ${shouldBuild}`);
|
|
226
|
+
import_utils.logger.debug(deps.map((dep) => dep.file).join(", "));
|
|
227
|
+
await this.depBuilder.build({
|
|
228
|
+
deps,
|
|
229
|
+
useWorker: opts.useWorker
|
|
230
|
+
});
|
|
231
|
+
this.lastBuildError = null;
|
|
232
|
+
this.strategy.writeCache();
|
|
233
|
+
if (this.buildDepsAgain) {
|
|
234
|
+
import_utils.logger.info("[MFSU] buildDepsAgain");
|
|
235
|
+
this.buildDepsAgain = false;
|
|
236
|
+
this.buildDeps().catch((e) => {
|
|
237
|
+
import_utils.printHelp.runtime(e);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
} catch (e) {
|
|
241
|
+
this.lastBuildError = e;
|
|
242
|
+
throw e;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
getMiddlewares() {
|
|
246
|
+
return [
|
|
247
|
+
(req, res, next) => {
|
|
248
|
+
const publicPath = this.publicPath;
|
|
249
|
+
const relativePublicPath = (0, import_is_absolute_url.default)(publicPath) ? new URL(publicPath).pathname : publicPath;
|
|
250
|
+
const isMF = req.path.startsWith(`${relativePublicPath}${import_constants.MF_VA_PREFIX}`) || req.path.startsWith(`${relativePublicPath}${import_constants.MF_DEP_PREFIX}`) || req.path.startsWith(`${relativePublicPath}${import_constants.MF_STATIC_PREFIX}`);
|
|
251
|
+
if (isMF) {
|
|
252
|
+
this.depBuilder.onBuildComplete(() => {
|
|
253
|
+
if (!req.path.includes(import_constants.REMOTE_FILE)) {
|
|
254
|
+
res.setHeader("cache-control", "max-age=31536000,immutable");
|
|
255
|
+
}
|
|
256
|
+
res.setHeader(
|
|
257
|
+
"content-type",
|
|
258
|
+
(0, import_mrmime.lookup)((0, import_path.extname)(req.path)) || "text/plain"
|
|
259
|
+
);
|
|
260
|
+
const relativePath = req.path.replace(
|
|
261
|
+
new RegExp(`^${relativePublicPath}`),
|
|
262
|
+
"/"
|
|
263
|
+
);
|
|
264
|
+
const realFilePath = (0, import_path.join)(this.opts.tmpBase, relativePath);
|
|
265
|
+
if (!(0, import_fs.existsSync)(realFilePath)) {
|
|
266
|
+
import_utils.logger.error(`MFSU dist file: ${realFilePath} not found`);
|
|
267
|
+
if (this.lastBuildError) {
|
|
268
|
+
import_utils.logger.error(`MFSU latest build error: `, this.lastBuildError);
|
|
269
|
+
}
|
|
270
|
+
res.status(404);
|
|
271
|
+
return res.end();
|
|
272
|
+
}
|
|
273
|
+
const content = (0, import_fs.readFileSync)(realFilePath);
|
|
274
|
+
res.send(content);
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
next();
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
// 兜底依赖构建时, 代码中有指定 chunk 名的情况
|
|
281
|
+
// TODO: should respect to publicPath
|
|
282
|
+
import_express.default.static(this.opts.tmpBase)
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
getBabelPlugins() {
|
|
286
|
+
return [this.strategy.getBabelPlugin()];
|
|
287
|
+
}
|
|
288
|
+
getEsbuildLoaderHandler() {
|
|
289
|
+
if (this.opts.strategy === "eager") {
|
|
290
|
+
const opts = this.strategy.getBabelPlugin()[1];
|
|
291
|
+
return [(0, import_awaitImport.getImportHandlerV4)(opts)];
|
|
292
|
+
}
|
|
293
|
+
const cache = /* @__PURE__ */ new Map();
|
|
294
|
+
const checkOpts = this.strategy.getBabelPlugin()[1];
|
|
295
|
+
return [
|
|
296
|
+
(0, import_awaitImport.default)({
|
|
297
|
+
cache,
|
|
298
|
+
opts: checkOpts
|
|
299
|
+
})
|
|
300
|
+
];
|
|
301
|
+
}
|
|
302
|
+
getCacheFilePath() {
|
|
303
|
+
return this.strategy.getCacheFilePath();
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
function resolvePublicPath(config) {
|
|
307
|
+
var _a;
|
|
308
|
+
let publicPath = ((_a = config.output) == null ? void 0 : _a.publicPath) ?? "auto";
|
|
309
|
+
if (publicPath === "auto") {
|
|
310
|
+
publicPath = "/";
|
|
311
|
+
}
|
|
312
|
+
(0, import_assert.default)(typeof publicPath === "string", "Not support function publicPath now");
|
|
313
|
+
return publicPath;
|
|
314
|
+
}
|
|
315
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
316
|
+
0 && (module.exports = {
|
|
317
|
+
MFSU,
|
|
318
|
+
resolvePublicPath
|
|
319
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DepModule } from '../depInfo';
|
|
2
|
+
import { IBuildDepPluginOpts } from '../webpackPlugins/buildDepPlugin';
|
|
3
|
+
import type { IMFSUStrategy, MFSU } from './mfsu';
|
|
4
|
+
export declare class StrategyCompileTime implements IMFSUStrategy {
|
|
5
|
+
private readonly mfsu;
|
|
6
|
+
private depInfo;
|
|
7
|
+
constructor({ mfsu }: {
|
|
8
|
+
mfsu: MFSU;
|
|
9
|
+
});
|
|
10
|
+
getDepModules(): Record<string, DepModule>;
|
|
11
|
+
getCacheFilePath(): string;
|
|
12
|
+
init(): void;
|
|
13
|
+
shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
|
|
14
|
+
loadCache(): void;
|
|
15
|
+
writeCache(): void;
|
|
16
|
+
refresh(): void;
|
|
17
|
+
getBabelPlugin(): any[];
|
|
18
|
+
getBuildDepPlugConfig(): IBuildDepPluginOpts;
|
|
19
|
+
private getAwaitImportCollectOpts;
|
|
20
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
};
|
|
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(
|
|
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/mfsu/strategyCompileTime.ts
|
|
30
|
+
var strategyCompileTime_exports = {};
|
|
31
|
+
__export(strategyCompileTime_exports, {
|
|
32
|
+
StrategyCompileTime: () => StrategyCompileTime
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(strategyCompileTime_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_awaitImport = __toESM(require("../babelPlugins/awaitImport/awaitImport"));
|
|
37
|
+
var import_getRealPath = require("../babelPlugins/awaitImport/getRealPath");
|
|
38
|
+
var import_dep = require("../dep/dep");
|
|
39
|
+
var import_depInfo = require("../depInfo");
|
|
40
|
+
var StrategyCompileTime = class {
|
|
41
|
+
constructor({ mfsu }) {
|
|
42
|
+
this.mfsu = mfsu;
|
|
43
|
+
this.depInfo = new import_depInfo.DepInfo({ mfsu });
|
|
44
|
+
}
|
|
45
|
+
getDepModules() {
|
|
46
|
+
return this.depInfo.getDepModules();
|
|
47
|
+
}
|
|
48
|
+
getCacheFilePath() {
|
|
49
|
+
return this.depInfo.getCacheFilePath();
|
|
50
|
+
}
|
|
51
|
+
init() {
|
|
52
|
+
}
|
|
53
|
+
shouldBuild() {
|
|
54
|
+
return this.depInfo.shouldBuild();
|
|
55
|
+
}
|
|
56
|
+
loadCache() {
|
|
57
|
+
this.depInfo.loadCache();
|
|
58
|
+
}
|
|
59
|
+
writeCache() {
|
|
60
|
+
this.depInfo.writeCache();
|
|
61
|
+
}
|
|
62
|
+
refresh() {
|
|
63
|
+
this.depInfo.snapshot();
|
|
64
|
+
}
|
|
65
|
+
getBabelPlugin() {
|
|
66
|
+
return [import_awaitImport.default, this.getAwaitImportCollectOpts()];
|
|
67
|
+
}
|
|
68
|
+
getBuildDepPlugConfig() {
|
|
69
|
+
const mfsu = this.mfsu;
|
|
70
|
+
return {
|
|
71
|
+
onCompileDone: () => {
|
|
72
|
+
if (mfsu.depBuilder.isBuilding) {
|
|
73
|
+
mfsu.buildDepsAgain = true;
|
|
74
|
+
} else {
|
|
75
|
+
mfsu.buildDeps().then(() => {
|
|
76
|
+
mfsu.onProgress({
|
|
77
|
+
done: true
|
|
78
|
+
});
|
|
79
|
+
}).catch((e) => {
|
|
80
|
+
import_utils.printHelp.runtime(e);
|
|
81
|
+
mfsu.onProgress({
|
|
82
|
+
done: true
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
getAwaitImportCollectOpts() {
|
|
90
|
+
const mfsuOpts = this.mfsu.opts;
|
|
91
|
+
const mfsu = this.mfsu;
|
|
92
|
+
const userUnMatches = mfsuOpts.unMatchLibs || [];
|
|
93
|
+
const sharedUnMatches = Object.keys(mfsuOpts.shared || {});
|
|
94
|
+
const remoteAliasUnMatches = (mfsuOpts.remoteAliases || []).map(
|
|
95
|
+
(str) => new RegExp(`^${str}`)
|
|
96
|
+
);
|
|
97
|
+
const unMatches = [
|
|
98
|
+
...userUnMatches,
|
|
99
|
+
...sharedUnMatches,
|
|
100
|
+
...remoteAliasUnMatches
|
|
101
|
+
];
|
|
102
|
+
return {
|
|
103
|
+
onTransformDeps: () => {
|
|
104
|
+
},
|
|
105
|
+
onCollect: ({
|
|
106
|
+
file,
|
|
107
|
+
data
|
|
108
|
+
}) => {
|
|
109
|
+
this.depInfo.moduleGraph.onFileChange({
|
|
110
|
+
file,
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
deps: [
|
|
113
|
+
...Array.from(data.matched).map((item) => ({
|
|
114
|
+
file: item.sourceValue,
|
|
115
|
+
isDependency: true,
|
|
116
|
+
version: import_dep.Dep.getDepVersion({
|
|
117
|
+
dep: item.sourceValue,
|
|
118
|
+
cwd: mfsuOpts.cwd
|
|
119
|
+
})
|
|
120
|
+
})),
|
|
121
|
+
...Array.from(data.unMatched).map((item) => ({
|
|
122
|
+
file: (0, import_getRealPath.getRealPath)({
|
|
123
|
+
file,
|
|
124
|
+
dep: item.sourceValue
|
|
125
|
+
}),
|
|
126
|
+
isDependency: false
|
|
127
|
+
}))
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
exportAllMembers: mfsuOpts.exportAllMembers,
|
|
132
|
+
unMatchLibs: unMatches,
|
|
133
|
+
remoteName: mfsuOpts.mfName,
|
|
134
|
+
alias: mfsu.alias,
|
|
135
|
+
externals: mfsu.externals
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
StrategyCompileTime
|
|
142
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IBuildDepPluginOpts } from '../webpackPlugins/buildDepPlugin';
|
|
2
|
+
import type { IMFSUStrategy, MFSU } from './mfsu';
|
|
3
|
+
import type { Configuration } from 'webpack';
|
|
4
|
+
export declare class StaticAnalyzeStrategy implements IMFSUStrategy {
|
|
5
|
+
private readonly mfsu;
|
|
6
|
+
private staticDepInfo;
|
|
7
|
+
constructor({ mfsu, srcCodeCache }: {
|
|
8
|
+
mfsu: MFSU;
|
|
9
|
+
srcCodeCache: any;
|
|
10
|
+
});
|
|
11
|
+
init(webpackConfig: Configuration): void;
|
|
12
|
+
getDepModules(): Record<string, {
|
|
13
|
+
file: string;
|
|
14
|
+
version: string;
|
|
15
|
+
}>;
|
|
16
|
+
getCacheFilePath(): string;
|
|
17
|
+
shouldBuild(): false | "cacheDependency has changed" | "dependencies changed";
|
|
18
|
+
writeCache(): void;
|
|
19
|
+
getBabelPlugin(): any[];
|
|
20
|
+
private getMfImportOpts;
|
|
21
|
+
getBuildDepPlugConfig(): IBuildDepPluginOpts;
|
|
22
|
+
loadCache(): void;
|
|
23
|
+
refresh(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
};
|
|
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(
|
|
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/mfsu/strategyStaticAnalyze.ts
|
|
30
|
+
var strategyStaticAnalyze_exports = {};
|
|
31
|
+
__export(strategyStaticAnalyze_exports, {
|
|
32
|
+
StaticAnalyzeStrategy: () => StaticAnalyzeStrategy
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(strategyStaticAnalyze_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_checkMatch = require("../babelPlugins/awaitImport/checkMatch");
|
|
37
|
+
var import_MFImport = __toESM(require("../babelPlugins/awaitImport/MFImport"));
|
|
38
|
+
var import_staticDepInfo = require("../staticDepInfo/staticDepInfo");
|
|
39
|
+
var import_webpackUtils = require("../utils/webpackUtils");
|
|
40
|
+
var StaticAnalyzeStrategy = class {
|
|
41
|
+
constructor({ mfsu, srcCodeCache }) {
|
|
42
|
+
this.mfsu = mfsu;
|
|
43
|
+
this.staticDepInfo = new import_staticDepInfo.StaticDepInfo({
|
|
44
|
+
mfsu,
|
|
45
|
+
srcCodeCache
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
init(webpackConfig) {
|
|
49
|
+
const config = (0, import_webpackUtils.extractBabelPluginImportOptions)(webpackConfig);
|
|
50
|
+
this.staticDepInfo.setBabelPluginImportConfig(config);
|
|
51
|
+
this.staticDepInfo.init();
|
|
52
|
+
}
|
|
53
|
+
getDepModules() {
|
|
54
|
+
return this.staticDepInfo.getDepModules();
|
|
55
|
+
}
|
|
56
|
+
getCacheFilePath() {
|
|
57
|
+
return this.staticDepInfo.getCacheFilePath();
|
|
58
|
+
}
|
|
59
|
+
shouldBuild() {
|
|
60
|
+
return this.staticDepInfo.shouldBuild();
|
|
61
|
+
}
|
|
62
|
+
writeCache() {
|
|
63
|
+
this.staticDepInfo.writeCache();
|
|
64
|
+
}
|
|
65
|
+
getBabelPlugin() {
|
|
66
|
+
return [import_MFImport.default, this.getMfImportOpts()];
|
|
67
|
+
}
|
|
68
|
+
getMfImportOpts() {
|
|
69
|
+
const mfsu = this.mfsu;
|
|
70
|
+
const mfsuOpts = this.mfsu.opts;
|
|
71
|
+
const userUnMatches = mfsuOpts.unMatchLibs || [];
|
|
72
|
+
const sharedUnMatches = Object.keys(mfsuOpts.shared || {});
|
|
73
|
+
const remoteAliasUnMatches = (mfsuOpts.remoteAliases || []).map(
|
|
74
|
+
(str) => new RegExp(`^${str}`)
|
|
75
|
+
);
|
|
76
|
+
const unMatches = [
|
|
77
|
+
...userUnMatches,
|
|
78
|
+
...sharedUnMatches,
|
|
79
|
+
...remoteAliasUnMatches
|
|
80
|
+
];
|
|
81
|
+
return {
|
|
82
|
+
resolveImportSource: (source) => {
|
|
83
|
+
const match = (0, import_checkMatch.checkMatch)({
|
|
84
|
+
value: source,
|
|
85
|
+
filename: "_.js",
|
|
86
|
+
opts: {
|
|
87
|
+
exportAllMembers: mfsuOpts.exportAllMembers,
|
|
88
|
+
unMatchLibs: unMatches,
|
|
89
|
+
remoteName: mfsuOpts.mfName,
|
|
90
|
+
alias: mfsu.alias,
|
|
91
|
+
externals: mfsu.externals
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
if (!match.isMatch) {
|
|
95
|
+
return source;
|
|
96
|
+
}
|
|
97
|
+
const depMat = this.staticDepInfo.getDependencies();
|
|
98
|
+
const m = depMat[match.value];
|
|
99
|
+
if (m) {
|
|
100
|
+
return m.replaceValue;
|
|
101
|
+
}
|
|
102
|
+
return match.value;
|
|
103
|
+
},
|
|
104
|
+
exportAllMembers: mfsuOpts.exportAllMembers,
|
|
105
|
+
unMatchLibs: mfsuOpts.unMatchLibs,
|
|
106
|
+
remoteName: mfsuOpts.mfName,
|
|
107
|
+
alias: mfsu.alias,
|
|
108
|
+
externals: mfsu.externals
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
getBuildDepPlugConfig() {
|
|
112
|
+
const mfsu = this.mfsu;
|
|
113
|
+
return {
|
|
114
|
+
beforeCompile: async () => {
|
|
115
|
+
if (mfsu.depBuilder.isBuilding) {
|
|
116
|
+
mfsu.buildDepsAgain = true;
|
|
117
|
+
} else {
|
|
118
|
+
import_utils.logger.event(`[MFSU][eager] start build deps`);
|
|
119
|
+
this.staticDepInfo.consumeAllProducedEvents();
|
|
120
|
+
mfsu.buildDeps().then(() => {
|
|
121
|
+
mfsu.onProgress({
|
|
122
|
+
done: true
|
|
123
|
+
});
|
|
124
|
+
}).catch((e) => {
|
|
125
|
+
import_utils.printHelp.runtime(e);
|
|
126
|
+
mfsu.onProgress({
|
|
127
|
+
done: true
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
onFileChange: async (c) => {
|
|
133
|
+
import_utils.logger.debug(
|
|
134
|
+
"webpack found changes modified:",
|
|
135
|
+
c.modifiedFiles,
|
|
136
|
+
"removed:",
|
|
137
|
+
c.removedFiles
|
|
138
|
+
);
|
|
139
|
+
const srcPath = this.staticDepInfo.opts.srcCodeCache.getSrcPath();
|
|
140
|
+
const fileEvents = [
|
|
141
|
+
...this.staticDepInfo.opts.srcCodeCache.replayChangeEvents(),
|
|
142
|
+
...extractJSCodeFiles(srcPath, c.modifiedFiles).map((f) => {
|
|
143
|
+
return {
|
|
144
|
+
event: "change",
|
|
145
|
+
path: f
|
|
146
|
+
};
|
|
147
|
+
}),
|
|
148
|
+
...extractJSCodeFiles(srcPath, c.removedFiles).map((f) => {
|
|
149
|
+
return {
|
|
150
|
+
event: "unlink",
|
|
151
|
+
path: f
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
];
|
|
155
|
+
import_utils.logger.debug("all file events", fileEvents);
|
|
156
|
+
if (fileEvents.length === 0) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const start = Date.now();
|
|
160
|
+
try {
|
|
161
|
+
await this.staticDepInfo.opts.srcCodeCache.handleFileChangeEvents(
|
|
162
|
+
fileEvents
|
|
163
|
+
);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
import_utils.logger.error("MFSU[eager] analyze dependencies failed with error", e);
|
|
166
|
+
}
|
|
167
|
+
import_utils.logger.debug(`webpack waited ${Date.now() - start} ms`);
|
|
168
|
+
},
|
|
169
|
+
onCompileDone: () => {
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
loadCache() {
|
|
174
|
+
this.staticDepInfo.loadCache();
|
|
175
|
+
}
|
|
176
|
+
refresh() {
|
|
177
|
+
this.staticDepInfo.snapshot();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var REG_CODE_EXT = /\.(jsx|js|ts|tsx)$/;
|
|
181
|
+
function extractJSCodeFiles(folderBase, files) {
|
|
182
|
+
const jsFiles = [];
|
|
183
|
+
if (!files) {
|
|
184
|
+
return jsFiles;
|
|
185
|
+
}
|
|
186
|
+
for (let file of files.values()) {
|
|
187
|
+
if (file.startsWith(folderBase) && REG_CODE_EXT.test(file) && file.indexOf("node_modules") === -1) {
|
|
188
|
+
jsFiles.push(file);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return jsFiles;
|
|
192
|
+
}
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
StaticAnalyzeStrategy
|
|
196
|
+
});
|