@umijs/mfsu 4.0.0-canary.20220718.2 → 4.0.0-canary.20220720.1

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