@umijs/mfsu 4.0.8 → 4.0.11
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 -0
- package/dist/babelPlugins/awaitImport/MFImport.js +1 -1
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/awaitImport.js +1 -1
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/checkMatch.js +129 -132
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +1 -1
- package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/getRealPath.js +1 -1
- package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/isExternals.js +1 -1
- package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +1 -1
- package/dist/constants.d.ts +0 -0
- package/dist/constants.js +1 -1
- package/dist/dep/dep.d.ts +0 -0
- package/dist/dep/dep.js +112 -83
- package/dist/dep/getCJSExports.d.ts +0 -0
- package/dist/dep/getCJSExports.js +1 -1
- package/dist/dep/getExposeFromContent.d.ts +0 -0
- package/dist/dep/getExposeFromContent.js +1 -1
- package/dist/dep/getModuleExports.d.ts +0 -0
- package/dist/dep/getModuleExports.js +1 -1
- package/dist/depBuilder/depBuilder.d.ts +0 -0
- package/dist/depBuilder/depBuilder.js +191 -158
- package/dist/depBuilder/getESBuildEntry.d.ts +0 -0
- package/dist/depBuilder/getESBuildEntry.js +1 -1
- package/dist/depInfo.d.ts +0 -0
- package/dist/depInfo.js +75 -53
- package/dist/esbuildHandlers/autoCssModules.d.ts +0 -0
- package/dist/esbuildHandlers/autoCssModules.js +43 -22
- package/dist/esbuildHandlers/awaitImport/index.d.ts +0 -0
- package/dist/esbuildHandlers/awaitImport/index.js +1 -1
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -1
- package/dist/loader/esbuild.d.ts +0 -0
- package/dist/loader/esbuild.js +1 -1
- package/dist/mfsu/mfsu.d.ts +4 -0
- package/dist/mfsu/mfsu.js +236 -257
- package/dist/mfsu/strategyCompileTime.d.ts +0 -0
- package/dist/mfsu/strategyCompileTime.js +131 -99
- package/dist/mfsu/strategyStaticAnalyze.d.ts +0 -0
- package/dist/mfsu/strategyStaticAnalyze.js +151 -115
- package/dist/moduleGraph.d.ts +0 -0
- package/dist/moduleGraph.js +227 -186
- package/dist/staticDepInfo/importParser.d.ts +0 -0
- package/dist/staticDepInfo/importParser.js +1 -1
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +0 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
- package/dist/staticDepInfo/staticDepInfo.d.ts +0 -0
- package/dist/staticDepInfo/staticDepInfo.js +239 -197
- package/dist/types.d.ts +0 -0
- package/dist/types.js +1 -1
- package/dist/utils/makeArray.d.ts +0 -0
- package/dist/utils/makeArray.js +1 -1
- package/dist/utils/trimFileContent.d.ts +0 -0
- package/dist/utils/trimFileContent.js +1 -1
- package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -0
- package/dist/webpackPlugins/buildDepPlugin.js +1 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -0
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +1 -1
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -0
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +1 -1
- package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -0
- package/dist/webpackPlugins/writeCachePlugin.js +1 -1
- package/package.json +8 -6
package/dist/mfsu/mfsu.js
CHANGED
|
@@ -1,179 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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]);
|
|
7
18
|
}
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
19
|
+
return a;
|
|
24
20
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
24
|
};
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
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));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
// src/mfsu/mfsu.ts
|
|
37
|
+
var mfsu_exports = {};
|
|
38
|
+
__export(mfsu_exports, {
|
|
39
|
+
MFSU: () => MFSU
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(mfsu_exports);
|
|
42
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
43
|
+
var import_utils = require("@umijs/utils");
|
|
44
|
+
var import_assert = __toESM(require("assert"));
|
|
45
|
+
var import_fs = require("fs");
|
|
46
|
+
var import_path = require("path");
|
|
47
|
+
var import_is_absolute_url = __toESM(require("../../compiled/is-absolute-url"));
|
|
48
|
+
var import_mrmime = require("../../compiled/mrmime");
|
|
49
|
+
var import_webpack_virtual_modules = __toESM(require("../../compiled/webpack-virtual-modules"));
|
|
50
|
+
var import_constants = require("../constants");
|
|
51
|
+
var import_dep = require("../dep/dep");
|
|
52
|
+
var import_depBuilder = require("../depBuilder/depBuilder");
|
|
53
|
+
var import_awaitImport = __toESM(require("../esbuildHandlers/awaitImport"));
|
|
54
|
+
var import_types = require("../types");
|
|
55
|
+
var import_makeArray = require("../utils/makeArray");
|
|
56
|
+
var import_buildDepPlugin = require("../webpackPlugins/buildDepPlugin");
|
|
57
|
+
var import_strategyCompileTime = require("./strategyCompileTime");
|
|
58
|
+
var import_strategyStaticAnalyze = require("./strategyStaticAnalyze");
|
|
59
|
+
var MFSU = class {
|
|
60
|
+
constructor(opts) {
|
|
61
|
+
this.alias = {};
|
|
62
|
+
this.externals = [];
|
|
63
|
+
this.depConfig = null;
|
|
64
|
+
this.buildDepsAgain = false;
|
|
65
|
+
this.progress = { done: false };
|
|
66
|
+
this.publicPath = "/";
|
|
67
|
+
this.opts = opts;
|
|
68
|
+
this.opts.mfName = this.opts.mfName || import_constants.DEFAULT_MF_NAME;
|
|
69
|
+
this.opts.tmpBase = this.opts.tmpBase || (0, import_path.join)(process.cwd(), import_constants.DEFAULT_TMP_DIR_NAME);
|
|
70
|
+
this.opts.mode = this.opts.mode || import_types.Mode.development;
|
|
71
|
+
this.opts.getCacheDependency = this.opts.getCacheDependency || (() => ({}));
|
|
72
|
+
this.onProgress = (progress) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
this.progress = __spreadValues(__spreadValues({}, this.progress), progress);
|
|
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("fallback to MFSU normal strategy, due to srcCache is not provided");
|
|
87
|
+
this.strategy = new import_strategyCompileTime.StrategyCompileTime({ mfsu: this });
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
this.strategy = new import_strategyCompileTime.StrategyCompileTime({ mfsu: this });
|
|
91
|
+
}
|
|
92
|
+
this.strategy.loadCache();
|
|
93
|
+
this.depBuilder = new import_depBuilder.DepBuilder({ mfsu: this });
|
|
94
|
+
}
|
|
95
|
+
asyncImport(content) {
|
|
96
|
+
return `await import('${(0, import_utils.winPath)(content)}');`;
|
|
97
|
+
}
|
|
98
|
+
async setWebpackConfig(opts) {
|
|
99
|
+
var _a;
|
|
100
|
+
const { mfName } = this.opts;
|
|
101
|
+
Object.assign(this.alias, ((_a = opts.config.resolve) == null ? void 0 : _a.alias) || {});
|
|
102
|
+
this.externals.push(...(0, import_makeArray.makeArray)(opts.config.externals || []));
|
|
103
|
+
const entry = {};
|
|
104
|
+
const virtualModules = {};
|
|
105
|
+
const entryObject = import_utils.lodash.isString(opts.config.entry) ? { default: [opts.config.entry] } : opts.config.entry;
|
|
106
|
+
(0, import_assert.default)(import_utils.lodash.isPlainObject(entryObject), `webpack config 'entry' value must be a string or an object.`);
|
|
107
|
+
for (const key of Object.keys(entryObject)) {
|
|
108
|
+
if (key === this.opts.remoteName) {
|
|
109
|
+
entry[key] = entryObject[key];
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const virtualPath = `./mfsu-virtual-entry/${key}.js`;
|
|
113
|
+
const virtualContent = [];
|
|
114
|
+
let index = 1;
|
|
115
|
+
let hasDefaultExport = false;
|
|
116
|
+
const entryFiles = import_utils.lodash.isArray(entryObject[key]) ? entryObject[key] : [entryObject[key]];
|
|
117
|
+
for (let entry2 of entryFiles) {
|
|
118
|
+
if ((0, import_fs.statSync)(entry2).isDirectory()) {
|
|
119
|
+
const realEntry = (0, import_utils.tryPaths)([
|
|
120
|
+
(0, import_path.join)(entry2, "index.tsx"),
|
|
121
|
+
(0, import_path.join)(entry2, "index.ts"),
|
|
122
|
+
(0, import_path.join)(entry2, "index.jsx"),
|
|
123
|
+
(0, import_path.join)(entry2, "index.js")
|
|
124
|
+
]);
|
|
125
|
+
(0, import_assert.default)(realEntry, `entry file not found, please configure the specific entry path. (e.g. 'src/index.tsx')`);
|
|
126
|
+
entry2 = realEntry;
|
|
82
127
|
}
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
const content = (0, import_fs.readFileSync)(entry2, "utf-8");
|
|
129
|
+
const [_imports, exports] = await (0, import_bundler_utils.parseModule)({ content, path: entry2 });
|
|
130
|
+
if (exports.length) {
|
|
131
|
+
virtualContent.push(`const k${index} = ${this.asyncImport(entry2)}`);
|
|
132
|
+
for (const exportName of exports) {
|
|
133
|
+
if (exportName === "default") {
|
|
134
|
+
hasDefaultExport = true;
|
|
135
|
+
virtualContent.push(`export default k${index}.${exportName}`);
|
|
136
|
+
} else {
|
|
137
|
+
virtualContent.push(`export const ${exportName} = k${index}.${exportName}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
virtualContent.push(this.asyncImport(entry2));
|
|
85
142
|
}
|
|
86
|
-
|
|
87
|
-
|
|
143
|
+
index += 1;
|
|
144
|
+
}
|
|
145
|
+
if (!hasDefaultExport) {
|
|
146
|
+
virtualContent.push(`export default 1;`);
|
|
147
|
+
}
|
|
148
|
+
virtualModules[virtualPath] = virtualContent.join("\n");
|
|
149
|
+
entry[key] = virtualPath;
|
|
88
150
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
151
|
+
opts.config.entry = entry;
|
|
152
|
+
opts.config.plugins = opts.config.plugins || [];
|
|
153
|
+
let publicPath = opts.config.output.publicPath;
|
|
154
|
+
if (publicPath === "auto") {
|
|
155
|
+
publicPath = "/";
|
|
94
156
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.externals.push(...(0, makeArray_1.makeArray)(opts.config.externals || []));
|
|
104
|
-
// entry
|
|
105
|
-
const entry = {};
|
|
106
|
-
const virtualModules = {};
|
|
107
|
-
// ensure entry object type
|
|
108
|
-
const entryObject = utils_1.lodash.isString(opts.config.entry)
|
|
109
|
-
? { default: [opts.config.entry] }
|
|
110
|
-
: opts.config.entry;
|
|
111
|
-
(0, assert_1.default)(utils_1.lodash.isPlainObject(entryObject), `webpack config 'entry' value must be a string or an object.`);
|
|
112
|
-
for (const key of Object.keys(entryObject)) {
|
|
113
|
-
const virtualPath = `./mfsu-virtual-entry/${key}.js`;
|
|
114
|
-
const virtualContent = [];
|
|
115
|
-
let index = 1;
|
|
116
|
-
let hasDefaultExport = false;
|
|
117
|
-
const entryFiles = utils_1.lodash.isArray(entryObject[key])
|
|
118
|
-
? entryObject[key]
|
|
119
|
-
: [entryObject[key]];
|
|
120
|
-
for (let entry of entryFiles) {
|
|
121
|
-
// ensure entry is a file
|
|
122
|
-
if ((0, fs_1.statSync)(entry).isDirectory()) {
|
|
123
|
-
const realEntry = (0, utils_1.tryPaths)([
|
|
124
|
-
(0, path_1.join)(entry, 'index.tsx'),
|
|
125
|
-
(0, path_1.join)(entry, 'index.ts'),
|
|
126
|
-
(0, path_1.join)(entry, 'index.jsx'),
|
|
127
|
-
(0, path_1.join)(entry, 'index.js'),
|
|
128
|
-
]);
|
|
129
|
-
(0, assert_1.default)(realEntry, `entry file not found, please configure the specific entry path. (e.g. 'src/index.tsx')`);
|
|
130
|
-
entry = realEntry;
|
|
131
|
-
}
|
|
132
|
-
const content = (0, fs_1.readFileSync)(entry, 'utf-8');
|
|
133
|
-
const [_imports, exports] = await (0, bundler_utils_1.parseModule)({ content, path: entry });
|
|
134
|
-
if (exports.length) {
|
|
135
|
-
virtualContent.push(`const k${index} = ${this.asyncImport(entry)}`);
|
|
136
|
-
for (const exportName of exports) {
|
|
137
|
-
if (exportName === 'default') {
|
|
138
|
-
hasDefaultExport = true;
|
|
139
|
-
virtualContent.push(`export default k${index}.${exportName}`);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
virtualContent.push(`export const ${exportName} = k${index}.${exportName}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
virtualContent.push(this.asyncImport(entry));
|
|
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
|
-
// plugins
|
|
159
|
-
opts.config.plugins = opts.config.plugins || [];
|
|
160
|
-
// support publicPath auto
|
|
161
|
-
let publicPath = opts.config.output.publicPath;
|
|
162
|
-
if (publicPath === 'auto') {
|
|
163
|
-
publicPath = '/';
|
|
164
|
-
}
|
|
165
|
-
this.publicPath = publicPath;
|
|
166
|
-
opts.config.plugins.push(...[
|
|
167
|
-
new webpack_virtual_modules_1.default(virtualModules),
|
|
168
|
-
new this.opts.implementor.container.ModuleFederationPlugin({
|
|
169
|
-
name: '__',
|
|
170
|
-
remotes: {
|
|
171
|
-
[mfName]: this.opts.runtimePublicPath
|
|
172
|
-
? // ref:
|
|
173
|
-
// https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes
|
|
174
|
-
`
|
|
157
|
+
this.publicPath = publicPath;
|
|
158
|
+
opts.config.plugins.push(...[
|
|
159
|
+
new import_webpack_virtual_modules.default(virtualModules),
|
|
160
|
+
new this.opts.implementor.container.ModuleFederationPlugin({
|
|
161
|
+
name: "__",
|
|
162
|
+
shared: this.opts.shared || {},
|
|
163
|
+
remotes: {
|
|
164
|
+
[mfName]: this.opts.runtimePublicPath ? `
|
|
175
165
|
promise new Promise(resolve => {
|
|
176
|
-
const remoteUrlWithVersion = (window.publicPath || '/') + '${
|
|
166
|
+
const remoteUrlWithVersion = (window.publicPath || '/') + '${import_constants.REMOTE_FILE_FULL}';
|
|
177
167
|
const script = document.createElement('script');
|
|
178
168
|
script.src = remoteUrlWithVersion;
|
|
179
169
|
script.onload = () => {
|
|
@@ -194,97 +184,86 @@ promise new Promise(resolve => {
|
|
|
194
184
|
// inject this script with the src set to the versioned remoteEntry.js
|
|
195
185
|
document.head.appendChild(script);
|
|
196
186
|
})
|
|
197
|
-
`.trimLeft()
|
|
198
|
-
: `${mfName}@${publicPath}${constants_1.REMOTE_FILE_FULL}`,
|
|
199
|
-
},
|
|
200
|
-
}),
|
|
201
|
-
new buildDepPlugin_1.BuildDepPlugin(this.strategy.getBuildDepPlugConfig()),
|
|
202
|
-
// new WriteCachePlugin({
|
|
203
|
-
// onWriteCache: lodash.debounce(() => {
|
|
204
|
-
// this.depInfo.writeCache();
|
|
205
|
-
// }, 300),
|
|
206
|
-
// }),
|
|
207
|
-
]);
|
|
208
|
-
// ensure topLevelAwait enabled
|
|
209
|
-
utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
|
|
210
|
-
/**
|
|
211
|
-
* depConfig
|
|
212
|
-
*/
|
|
213
|
-
this.depConfig = opts.depConfig;
|
|
214
|
-
this.strategy.init();
|
|
215
|
-
}
|
|
216
|
-
async buildDeps() {
|
|
217
|
-
const shouldBuild = this.strategy.shouldBuild();
|
|
218
|
-
if (!shouldBuild) {
|
|
219
|
-
utils_1.logger.info('[MFSU] skip buildDeps');
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
// Snapshot after compiled success
|
|
223
|
-
this.strategy.refresh();
|
|
224
|
-
const staticDeps = this.strategy.getDepModules();
|
|
225
|
-
const deps = dep_1.Dep.buildDeps({
|
|
226
|
-
deps: staticDeps,
|
|
227
|
-
cwd: this.opts.cwd,
|
|
228
|
-
mfsu: this,
|
|
229
|
-
});
|
|
230
|
-
utils_1.logger.info(`[MFSU] buildDeps since ${shouldBuild}`);
|
|
231
|
-
utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
|
|
232
|
-
await this.depBuilder.build({
|
|
233
|
-
deps,
|
|
234
|
-
});
|
|
235
|
-
// Write cache
|
|
236
|
-
this.strategy.writeCache();
|
|
237
|
-
if (this.buildDepsAgain) {
|
|
238
|
-
utils_1.logger.info('[MFSU] buildDepsAgain');
|
|
239
|
-
this.buildDepsAgain = false;
|
|
240
|
-
this.buildDeps().catch((e) => {
|
|
241
|
-
utils_1.printHelp.runtime(e);
|
|
242
|
-
});
|
|
187
|
+
`.trimLeft() : `${mfName}@${this.opts.serverBase || ""}${publicPath}${import_constants.REMOTE_FILE_FULL}`
|
|
243
188
|
}
|
|
189
|
+
}),
|
|
190
|
+
new import_buildDepPlugin.BuildDepPlugin(this.strategy.getBuildDepPlugConfig())
|
|
191
|
+
]);
|
|
192
|
+
import_utils.lodash.set(opts.config, "experiments.topLevelAwait", true);
|
|
193
|
+
this.depConfig = opts.depConfig;
|
|
194
|
+
this.strategy.init();
|
|
195
|
+
}
|
|
196
|
+
async buildDeps() {
|
|
197
|
+
const shouldBuild = this.strategy.shouldBuild();
|
|
198
|
+
if (!shouldBuild) {
|
|
199
|
+
import_utils.logger.info("[MFSU] skip buildDeps");
|
|
200
|
+
return;
|
|
244
201
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
next();
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
];
|
|
268
|
-
}
|
|
269
|
-
getBabelPlugins() {
|
|
270
|
-
return [this.strategy.getBabelPlugin()];
|
|
202
|
+
this.strategy.refresh();
|
|
203
|
+
const staticDeps = this.strategy.getDepModules();
|
|
204
|
+
const deps = import_dep.Dep.buildDeps({
|
|
205
|
+
deps: staticDeps,
|
|
206
|
+
cwd: this.opts.cwd,
|
|
207
|
+
mfsu: this
|
|
208
|
+
});
|
|
209
|
+
import_utils.logger.info(`[MFSU] buildDeps since ${shouldBuild}`);
|
|
210
|
+
import_utils.logger.debug(deps.map((dep) => dep.file).join(", "));
|
|
211
|
+
await this.depBuilder.build({
|
|
212
|
+
deps
|
|
213
|
+
});
|
|
214
|
+
this.strategy.writeCache();
|
|
215
|
+
if (this.buildDepsAgain) {
|
|
216
|
+
import_utils.logger.info("[MFSU] buildDepsAgain");
|
|
217
|
+
this.buildDepsAgain = false;
|
|
218
|
+
this.buildDeps().catch((e) => {
|
|
219
|
+
import_utils.printHelp.runtime(e);
|
|
220
|
+
});
|
|
271
221
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
222
|
+
}
|
|
223
|
+
getMiddlewares() {
|
|
224
|
+
return [
|
|
225
|
+
(req, res, next) => {
|
|
226
|
+
const publicPath = this.publicPath;
|
|
227
|
+
const relativePublicPath = (0, import_is_absolute_url.default)(publicPath) ? new URL(publicPath).pathname : publicPath;
|
|
228
|
+
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}`);
|
|
229
|
+
if (isMF) {
|
|
230
|
+
this.depBuilder.onBuildComplete(() => {
|
|
231
|
+
if (!req.path.includes(import_constants.REMOTE_FILE)) {
|
|
232
|
+
res.setHeader("cache-control", "max-age=31536000,immutable");
|
|
233
|
+
}
|
|
234
|
+
res.setHeader("content-type", (0, import_mrmime.lookup)((0, import_path.extname)(req.path)) || "text/plain");
|
|
235
|
+
const relativePath = req.path.replace(new RegExp(`^${relativePublicPath}`), "/");
|
|
236
|
+
const content = (0, import_fs.readFileSync)((0, import_path.join)(this.opts.tmpBase, relativePath));
|
|
237
|
+
res.send(content);
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
next();
|
|
276
241
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return this.strategy.getCacheFilePath();
|
|
242
|
+
}
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
getBabelPlugins() {
|
|
246
|
+
return [this.strategy.getBabelPlugin()];
|
|
247
|
+
}
|
|
248
|
+
getEsbuildLoaderHandler() {
|
|
249
|
+
if (this.opts.strategy === "eager") {
|
|
250
|
+
const opts = this.strategy.getBabelPlugin()[1];
|
|
251
|
+
return [(0, import_awaitImport.getImportHandlerV4)(opts)];
|
|
288
252
|
}
|
|
289
|
-
|
|
290
|
-
|
|
253
|
+
const cache = /* @__PURE__ */ new Map();
|
|
254
|
+
const checkOpts = this.strategy.getBabelPlugin()[1];
|
|
255
|
+
return [
|
|
256
|
+
(0, import_awaitImport.default)({
|
|
257
|
+
cache,
|
|
258
|
+
opts: checkOpts
|
|
259
|
+
})
|
|
260
|
+
];
|
|
261
|
+
}
|
|
262
|
+
getCacheFilePath() {
|
|
263
|
+
return this.strategy.getCacheFilePath();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
267
|
+
0 && (module.exports = {
|
|
268
|
+
MFSU
|
|
269
|
+
});
|
|
File without changes
|