@umijs/mfsu 4.0.6 → 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.
Files changed (40) hide show
  1. package/compiled/is-absolute-url/LICENSE +9 -0
  2. package/compiled/is-absolute-url/index.d.ts +22 -0
  3. package/compiled/is-absolute-url/index.js +1 -0
  4. package/compiled/is-absolute-url/package.json +1 -0
  5. package/dist/babelPlugins/awaitImport/MFImport.js +59 -66
  6. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
  7. package/dist/babelPlugins/awaitImport/awaitImport.js +103 -117
  8. package/dist/babelPlugins/awaitImport/checkMatch.js +131 -119
  9. package/dist/babelPlugins/awaitImport/getAliasedPath.js +54 -35
  10. package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
  11. package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
  12. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +51 -52
  13. package/dist/constants.js +47 -10
  14. package/dist/dep/dep.js +112 -83
  15. package/dist/dep/getCJSExports.js +60 -53
  16. package/dist/dep/getExposeFromContent.js +71 -59
  17. package/dist/dep/getModuleExports.js +58 -32
  18. package/dist/depBuilder/depBuilder.js +184 -158
  19. package/dist/depBuilder/getESBuildEntry.js +35 -12
  20. package/dist/depInfo.js +75 -53
  21. package/dist/esbuildHandlers/autoCssModules.js +43 -22
  22. package/dist/esbuildHandlers/awaitImport/index.js +82 -70
  23. package/dist/index.js +32 -22
  24. package/dist/loader/esbuild.js +87 -35
  25. package/dist/mfsu/mfsu.d.ts +1 -1
  26. package/dist/mfsu/mfsu.js +231 -257
  27. package/dist/mfsu/strategyCompileTime.js +123 -99
  28. package/dist/mfsu/strategyStaticAnalyze.js +135 -117
  29. package/dist/moduleGraph.js +227 -186
  30. package/dist/staticDepInfo/importParser.js +28 -6
  31. package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
  32. package/dist/staticDepInfo/staticDepInfo.js +230 -197
  33. package/dist/types.js +33 -8
  34. package/dist/utils/makeArray.js +29 -5
  35. package/dist/utils/trimFileContent.js +29 -5
  36. package/dist/webpackPlugins/buildDepPlugin.js +49 -25
  37. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +44 -19
  38. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +46 -27
  39. package/dist/webpackPlugins/writeCachePlugin.js +39 -15
  40. package/package.json +8 -6
package/dist/mfsu/mfsu.js CHANGED
@@ -1,179 +1,164 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
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
- Object.defineProperty(o, k2, desc);
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 __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
27
24
  };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.MFSU = void 0;
30
- const bundler_utils_1 = require("@umijs/bundler-utils");
31
- const utils_1 = require("@umijs/utils");
32
- const assert_1 = __importDefault(require("assert"));
33
- const fs_1 = require("fs");
34
- const path_1 = require("path");
35
- const mrmime_1 = require("../../compiled/mrmime");
36
- // @ts-ignore
37
- const webpack_virtual_modules_1 = __importDefault(require("../../compiled/webpack-virtual-modules"));
38
- const constants_1 = require("../constants");
39
- const dep_1 = require("../dep/dep");
40
- const depBuilder_1 = require("../depBuilder/depBuilder");
41
- const awaitImport_1 = __importStar(require("../esbuildHandlers/awaitImport"));
42
- const types_1 = require("../types");
43
- const makeArray_1 = require("../utils/makeArray");
44
- const buildDepPlugin_1 = require("../webpackPlugins/buildDepPlugin");
45
- const strategyCompileTime_1 = require("./strategyCompileTime");
46
- const strategyStaticAnalyze_1 = require("./strategyStaticAnalyze");
47
- class MFSU {
48
- constructor(opts) {
49
- this.alias = {};
50
- this.externals = [];
51
- this.depConfig = null;
52
- this.buildDepsAgain = false;
53
- this.progress = { done: false };
54
- this.publicPath = '/';
55
- this.opts = opts;
56
- this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
57
- this.opts.tmpBase =
58
- this.opts.tmpBase || (0, path_1.join)(process.cwd(), constants_1.DEFAULT_TMP_DIR_NAME);
59
- this.opts.mode = this.opts.mode || types_1.Mode.development;
60
- this.opts.getCacheDependency = this.opts.getCacheDependency || (() => ({}));
61
- this.onProgress = (progress) => {
62
- var _a, _b;
63
- this.progress = {
64
- ...this.progress,
65
- ...progress,
66
- };
67
- (_b = (_a = this.opts).onMFSUProgress) === null || _b === void 0 ? void 0 : _b.call(_a, this.progress);
68
- };
69
- this.opts.cwd = this.opts.cwd || process.cwd();
70
- if (this.opts.strategy === 'eager') {
71
- if (opts.srcCodeCache) {
72
- utils_1.logger.info('MFSU eager strategy enabled');
73
- this.strategy = new strategyStaticAnalyze_1.StaticAnalyzeStrategy({
74
- mfsu: this,
75
- srcCodeCache: opts.srcCodeCache,
76
- });
77
- }
78
- else {
79
- utils_1.logger.warn('fallback to MFSU normal strategy, due to srcCache is not provided');
80
- this.strategy = new strategyCompileTime_1.StrategyCompileTime({ mfsu: this });
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
- else {
84
- this.strategy = new strategyCompileTime_1.StrategyCompileTime({ mfsu: this });
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
- this.strategy.loadCache();
87
- this.depBuilder = new depBuilder_1.DepBuilder({ mfsu: this });
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
- // swc don't support top-level await
90
- // ref: https://github.com/vercel/next.js/issues/31054
91
- asyncImport(content) {
92
- return `await import('${(0, utils_1.winPath)(content)}');`;
93
- // return `(async () => await import('${content}'))();`;
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
- async setWebpackConfig(opts) {
96
- var _a;
97
- const { mfName } = this.opts;
98
- /**
99
- * config
100
- */
101
- // set alias and externals with reference for babel plugin
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 || '/') + '${constants_1.REMOTE_FILE_FULL}';
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.logger.error(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
- getMiddlewares() {
246
- return [
247
- (req, res, next) => {
248
- const publicPath = this.publicPath;
249
- const isMF = req.path.startsWith(`${publicPath}${constants_1.MF_VA_PREFIX}`) ||
250
- req.path.startsWith(`${publicPath}${constants_1.MF_DEP_PREFIX}`) ||
251
- req.path.startsWith(`${publicPath}${constants_1.MF_STATIC_PREFIX}`);
252
- if (isMF) {
253
- this.depBuilder.onBuildComplete(() => {
254
- if (!req.path.includes(constants_1.REMOTE_FILE)) {
255
- res.setHeader('cache-control', 'max-age=31536000,immutable');
256
- }
257
- res.setHeader('content-type', (0, mrmime_1.lookup)((0, path_1.extname)(req.path)) || 'text/plain');
258
- const relativePath = req.path.replace(new RegExp(`^${publicPath}`), '/');
259
- const content = (0, fs_1.readFileSync)((0, path_1.join)(this.opts.tmpBase, relativePath));
260
- res.send(content);
261
- });
262
- }
263
- else {
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
- getEsbuildLoaderHandler() {
273
- if (this.opts.strategy === 'eager') {
274
- const opts = this.strategy.getBabelPlugin()[1];
275
- return [(0, awaitImport_1.getImportHandlerV4)(opts)];
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
- const cache = new Map();
278
- const checkOpts = this.strategy.getBabelPlugin()[1];
279
- return [
280
- (0, awaitImport_1.default)({
281
- cache,
282
- opts: checkOpts,
283
- }),
284
- ];
285
- }
286
- getCacheFilePath() {
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
- exports.MFSU = MFSU;
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
+ });