@umijs/mfsu 4.0.8 → 4.0.9
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 +0 -0
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/awaitImport.js +0 -0
- 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 +0 -0
- package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/getRealPath.js +0 -0
- package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/isExternals.js +0 -0
- package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -0
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +0 -0
- package/dist/constants.d.ts +0 -0
- package/dist/constants.js +0 -0
- 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 +0 -0
- package/dist/dep/getExposeFromContent.d.ts +0 -0
- package/dist/dep/getExposeFromContent.js +0 -0
- package/dist/dep/getModuleExports.d.ts +0 -0
- package/dist/dep/getModuleExports.js +0 -0
- package/dist/depBuilder/depBuilder.d.ts +0 -0
- package/dist/depBuilder/depBuilder.js +184 -158
- package/dist/depBuilder/getESBuildEntry.d.ts +0 -0
- package/dist/depBuilder/getESBuildEntry.js +0 -0
- 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 +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/loader/esbuild.d.ts +0 -0
- package/dist/loader/esbuild.js +0 -0
- package/dist/mfsu/mfsu.d.ts +0 -0
- package/dist/mfsu/mfsu.js +231 -257
- package/dist/mfsu/strategyCompileTime.d.ts +0 -0
- package/dist/mfsu/strategyCompileTime.js +123 -99
- package/dist/mfsu/strategyStaticAnalyze.d.ts +0 -0
- package/dist/mfsu/strategyStaticAnalyze.js +135 -117
- 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 +0 -0
- 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 +230 -197
- package/dist/types.d.ts +0 -0
- package/dist/types.js +0 -0
- package/dist/utils/makeArray.d.ts +0 -0
- package/dist/utils/makeArray.js +0 -0
- package/dist/utils/trimFileContent.d.ts +0 -0
- package/dist/utils/trimFileContent.js +0 -0
- package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -0
- package/dist/webpackPlugins/buildDepPlugin.js +0 -0
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -0
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +0 -0
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -0
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +0 -0
- package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -0
- package/dist/webpackPlugins/writeCachePlugin.js +0 -0
- package/package.json +8 -6
package/dist/mfsu/mfsu.js
CHANGED
|
@@ -1,179 +1,164 @@
|
|
|
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
|
+
// 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
|
+
const virtualPath = `./mfsu-virtual-entry/${key}.js`;
|
|
109
|
+
const virtualContent = [];
|
|
110
|
+
let index = 1;
|
|
111
|
+
let hasDefaultExport = false;
|
|
112
|
+
const entryFiles = import_utils.lodash.isArray(entryObject[key]) ? entryObject[key] : [entryObject[key]];
|
|
113
|
+
for (let entry2 of entryFiles) {
|
|
114
|
+
if ((0, import_fs.statSync)(entry2).isDirectory()) {
|
|
115
|
+
const realEntry = (0, import_utils.tryPaths)([
|
|
116
|
+
(0, import_path.join)(entry2, "index.tsx"),
|
|
117
|
+
(0, import_path.join)(entry2, "index.ts"),
|
|
118
|
+
(0, import_path.join)(entry2, "index.jsx"),
|
|
119
|
+
(0, import_path.join)(entry2, "index.js")
|
|
120
|
+
]);
|
|
121
|
+
(0, import_assert.default)(realEntry, `entry file not found, please configure the specific entry path. (e.g. 'src/index.tsx')`);
|
|
122
|
+
entry2 = realEntry;
|
|
82
123
|
}
|
|
83
|
-
|
|
84
|
-
|
|
124
|
+
const content = (0, import_fs.readFileSync)(entry2, "utf-8");
|
|
125
|
+
const [_imports, exports] = await (0, import_bundler_utils.parseModule)({ content, path: entry2 });
|
|
126
|
+
if (exports.length) {
|
|
127
|
+
virtualContent.push(`const k${index} = ${this.asyncImport(entry2)}`);
|
|
128
|
+
for (const exportName of exports) {
|
|
129
|
+
if (exportName === "default") {
|
|
130
|
+
hasDefaultExport = true;
|
|
131
|
+
virtualContent.push(`export default k${index}.${exportName}`);
|
|
132
|
+
} else {
|
|
133
|
+
virtualContent.push(`export const ${exportName} = k${index}.${exportName}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
virtualContent.push(this.asyncImport(entry2));
|
|
85
138
|
}
|
|
86
|
-
|
|
87
|
-
|
|
139
|
+
index += 1;
|
|
140
|
+
}
|
|
141
|
+
if (!hasDefaultExport) {
|
|
142
|
+
virtualContent.push(`export default 1;`);
|
|
143
|
+
}
|
|
144
|
+
virtualModules[virtualPath] = virtualContent.join("\n");
|
|
145
|
+
entry[key] = virtualPath;
|
|
88
146
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
147
|
+
opts.config.entry = entry;
|
|
148
|
+
opts.config.plugins = opts.config.plugins || [];
|
|
149
|
+
let publicPath = opts.config.output.publicPath;
|
|
150
|
+
if (publicPath === "auto") {
|
|
151
|
+
publicPath = "/";
|
|
94
152
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
Object.assign(this.alias, ((_a = opts.config.resolve) === null || _a === void 0 ? void 0 : _a.alias) || {});
|
|
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
|
-
`
|
|
153
|
+
this.publicPath = publicPath;
|
|
154
|
+
opts.config.plugins.push(...[
|
|
155
|
+
new import_webpack_virtual_modules.default(virtualModules),
|
|
156
|
+
new this.opts.implementor.container.ModuleFederationPlugin({
|
|
157
|
+
name: "__",
|
|
158
|
+
remotes: {
|
|
159
|
+
[mfName]: this.opts.runtimePublicPath ? `
|
|
175
160
|
promise new Promise(resolve => {
|
|
176
|
-
const remoteUrlWithVersion = (window.publicPath || '/') + '${
|
|
161
|
+
const remoteUrlWithVersion = (window.publicPath || '/') + '${import_constants.REMOTE_FILE_FULL}';
|
|
177
162
|
const script = document.createElement('script');
|
|
178
163
|
script.src = remoteUrlWithVersion;
|
|
179
164
|
script.onload = () => {
|
|
@@ -194,97 +179,86 @@ promise new Promise(resolve => {
|
|
|
194
179
|
// inject this script with the src set to the versioned remoteEntry.js
|
|
195
180
|
document.head.appendChild(script);
|
|
196
181
|
})
|
|
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
|
-
});
|
|
182
|
+
`.trimLeft() : `${mfName}@${publicPath}${import_constants.REMOTE_FILE_FULL}`
|
|
243
183
|
}
|
|
184
|
+
}),
|
|
185
|
+
new import_buildDepPlugin.BuildDepPlugin(this.strategy.getBuildDepPlugConfig())
|
|
186
|
+
]);
|
|
187
|
+
import_utils.lodash.set(opts.config, "experiments.topLevelAwait", true);
|
|
188
|
+
this.depConfig = opts.depConfig;
|
|
189
|
+
this.strategy.init();
|
|
190
|
+
}
|
|
191
|
+
async buildDeps() {
|
|
192
|
+
const shouldBuild = this.strategy.shouldBuild();
|
|
193
|
+
if (!shouldBuild) {
|
|
194
|
+
import_utils.logger.info("[MFSU] skip buildDeps");
|
|
195
|
+
return;
|
|
244
196
|
}
|
|
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()];
|
|
197
|
+
this.strategy.refresh();
|
|
198
|
+
const staticDeps = this.strategy.getDepModules();
|
|
199
|
+
const deps = import_dep.Dep.buildDeps({
|
|
200
|
+
deps: staticDeps,
|
|
201
|
+
cwd: this.opts.cwd,
|
|
202
|
+
mfsu: this
|
|
203
|
+
});
|
|
204
|
+
import_utils.logger.info(`[MFSU] buildDeps since ${shouldBuild}`);
|
|
205
|
+
import_utils.logger.debug(deps.map((dep) => dep.file).join(", "));
|
|
206
|
+
await this.depBuilder.build({
|
|
207
|
+
deps
|
|
208
|
+
});
|
|
209
|
+
this.strategy.writeCache();
|
|
210
|
+
if (this.buildDepsAgain) {
|
|
211
|
+
import_utils.logger.info("[MFSU] buildDepsAgain");
|
|
212
|
+
this.buildDepsAgain = false;
|
|
213
|
+
this.buildDeps().catch((e) => {
|
|
214
|
+
import_utils.printHelp.runtime(e);
|
|
215
|
+
});
|
|
271
216
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
217
|
+
}
|
|
218
|
+
getMiddlewares() {
|
|
219
|
+
return [
|
|
220
|
+
(req, res, next) => {
|
|
221
|
+
const publicPath = this.publicPath;
|
|
222
|
+
const relativePublicPath = (0, import_is_absolute_url.default)(publicPath) ? new URL(publicPath).pathname : publicPath;
|
|
223
|
+
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}`);
|
|
224
|
+
if (isMF) {
|
|
225
|
+
this.depBuilder.onBuildComplete(() => {
|
|
226
|
+
if (!req.path.includes(import_constants.REMOTE_FILE)) {
|
|
227
|
+
res.setHeader("cache-control", "max-age=31536000,immutable");
|
|
228
|
+
}
|
|
229
|
+
res.setHeader("content-type", (0, import_mrmime.lookup)((0, import_path.extname)(req.path)) || "text/plain");
|
|
230
|
+
const relativePath = req.path.replace(new RegExp(`^${relativePublicPath}`), "/");
|
|
231
|
+
const content = (0, import_fs.readFileSync)((0, import_path.join)(this.opts.tmpBase, relativePath));
|
|
232
|
+
res.send(content);
|
|
233
|
+
});
|
|
234
|
+
} else {
|
|
235
|
+
next();
|
|
276
236
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return this.strategy.getCacheFilePath();
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
getBabelPlugins() {
|
|
241
|
+
return [this.strategy.getBabelPlugin()];
|
|
242
|
+
}
|
|
243
|
+
getEsbuildLoaderHandler() {
|
|
244
|
+
if (this.opts.strategy === "eager") {
|
|
245
|
+
const opts = this.strategy.getBabelPlugin()[1];
|
|
246
|
+
return [(0, import_awaitImport.getImportHandlerV4)(opts)];
|
|
288
247
|
}
|
|
289
|
-
|
|
290
|
-
|
|
248
|
+
const cache = /* @__PURE__ */ new Map();
|
|
249
|
+
const checkOpts = this.strategy.getBabelPlugin()[1];
|
|
250
|
+
return [
|
|
251
|
+
(0, import_awaitImport.default)({
|
|
252
|
+
cache,
|
|
253
|
+
opts: checkOpts
|
|
254
|
+
})
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
getCacheFilePath() {
|
|
258
|
+
return this.strategy.getCacheFilePath();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
262
|
+
0 && (module.exports = {
|
|
263
|
+
MFSU
|
|
264
|
+
});
|
|
File without changes
|