@bleedingdev/modern-js-server-core 3.2.0-ultramodern.120 → 3.2.0-ultramodern.121
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/dist/cjs/adapters/node/plugins/resource.js +1 -6
- package/dist/cjs/adapters/node/plugins/static.js +11 -185
- package/dist/cjs/adapters/node/plugins/staticModuleFederation.js +165 -0
- package/dist/cjs/adapters/node/plugins/staticPrecompressed.js +135 -0
- package/dist/cjs/index.js +34 -10
- package/dist/cjs/plugins/default.js +0 -2
- package/dist/cjs/plugins/index.js +2 -83
- package/dist/cjs/types/config/bffRuntime.js +18 -0
- package/dist/cjs/types/config/serverTelemetry.js +18 -0
- package/dist/cjs/utils/error.js +62 -0
- package/dist/esm/adapters/node/plugins/resource.mjs +1 -6
- package/dist/esm/adapters/node/plugins/static.mjs +7 -181
- package/dist/esm/adapters/node/plugins/staticModuleFederation.mjs +96 -0
- package/dist/esm/adapters/node/plugins/staticPrecompressed.mjs +91 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/plugins/default.mjs +0 -2
- package/dist/esm/plugins/index.mjs +0 -3
- package/dist/esm/types/config/bffRuntime.mjs +0 -0
- package/dist/esm/types/config/serverTelemetry.mjs +0 -0
- package/dist/esm/utils/error.mjs +54 -1
- package/dist/esm-node/adapters/node/plugins/resource.mjs +1 -6
- package/dist/esm-node/adapters/node/plugins/static.mjs +7 -181
- package/dist/esm-node/adapters/node/plugins/staticModuleFederation.mjs +97 -0
- package/dist/esm-node/adapters/node/plugins/staticPrecompressed.mjs +92 -0
- package/dist/esm-node/index.mjs +1 -1
- package/dist/esm-node/plugins/default.mjs +0 -2
- package/dist/esm-node/plugins/index.mjs +0 -3
- package/dist/esm-node/types/config/bffRuntime.mjs +1 -0
- package/dist/esm-node/types/config/serverTelemetry.mjs +1 -0
- package/dist/esm-node/utils/error.mjs +54 -1
- package/dist/types/adapters/node/plugins/staticModuleFederation.d.ts +13 -0
- package/dist/types/adapters/node/plugins/staticPrecompressed.d.ts +13 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/plugins/index.d.ts +0 -3
- package/dist/types/types/config/bff.d.ts +2 -97
- package/dist/types/types/config/bffRuntime.d.ts +105 -0
- package/dist/types/types/config/server.d.ts +3 -337
- package/dist/types/types/config/serverTelemetry.d.ts +319 -0
- package/dist/types/utils/error.d.ts +16 -0
- package/package.json +5 -5
- package/dist/cjs/adapters/node/plugins/moduleFederationCss.js +0 -176
- package/dist/cjs/plugins/contractGateAutopilot.js +0 -162
- package/dist/cjs/plugins/contractGateSnapshotStore.js +0 -243
- package/dist/cjs/plugins/mfCache.js +0 -82
- package/dist/cjs/plugins/telemetry.js +0 -1287
- package/dist/esm/adapters/node/plugins/moduleFederationCss.mjs +0 -125
- package/dist/esm/plugins/contractGateAutopilot.mjs +0 -124
- package/dist/esm/plugins/contractGateSnapshotStore.mjs +0 -180
- package/dist/esm/plugins/mfCache.mjs +0 -35
- package/dist/esm/plugins/telemetry.mjs +0 -1195
- package/dist/esm-node/adapters/node/plugins/moduleFederationCss.mjs +0 -126
- package/dist/esm-node/plugins/contractGateAutopilot.mjs +0 -125
- package/dist/esm-node/plugins/contractGateSnapshotStore.mjs +0 -182
- package/dist/esm-node/plugins/mfCache.mjs +0 -36
- package/dist/esm-node/plugins/telemetry.mjs +0 -1196
- package/dist/types/adapters/node/plugins/moduleFederationCss.d.ts +0 -33
- package/dist/types/plugins/contractGateAutopilot.d.ts +0 -35
- package/dist/types/plugins/contractGateSnapshotStore.d.ts +0 -57
- package/dist/types/plugins/mfCache.d.ts +0 -12
- package/dist/types/plugins/telemetry.d.ts +0 -309
|
@@ -52,7 +52,6 @@ const utils_namespaceObject = require("@modern-js/utils");
|
|
|
52
52
|
const external_path_namespaceObject = require("path");
|
|
53
53
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
54
54
|
const index_js_namespaceObject = require("../../../utils/index.js");
|
|
55
|
-
const external_moduleFederationCss_js_namespaceObject = require("./moduleFederationCss.js");
|
|
56
55
|
async function getHtmlTemplates(pwd, routes) {
|
|
57
56
|
const htmlRoutes = routes.filter((route)=>route.entryName);
|
|
58
57
|
const htmls = await Promise.all(htmlRoutes.map(async (route)=>{
|
|
@@ -107,16 +106,12 @@ async function getServerManifest(pwd, routes, monitors) {
|
|
|
107
106
|
const routeManifest = await (0, utils_namespaceObject.compatibleRequire)(routesManifestUri).catch((_)=>({}));
|
|
108
107
|
const nestedRoutesJsonPath = external_path_default().join(pwd, utils_namespaceObject.NESTED_ROUTE_SPEC_FILE);
|
|
109
108
|
const nestedRoutesJson = await (0, utils_namespaceObject.compatibleRequire)(nestedRoutesJsonPath).catch((_)=>({}));
|
|
110
|
-
const moduleFederationCssAssets = await (0, external_moduleFederationCss_js_namespaceObject.collectDirectRemoteModuleFederationCss)(pwd, {
|
|
111
|
-
monitors
|
|
112
|
-
});
|
|
113
109
|
return {
|
|
114
110
|
loaderBundles,
|
|
115
111
|
renderBundles,
|
|
116
112
|
loadableStats,
|
|
117
113
|
routeManifest,
|
|
118
|
-
nestedRoutesJson
|
|
119
|
-
moduleFederationCssAssets
|
|
114
|
+
nestedRoutesJson
|
|
120
115
|
};
|
|
121
116
|
}
|
|
122
117
|
function injectServerManifest(pwd, routes, manifestPromise) {
|
|
@@ -48,6 +48,8 @@ const external_path_namespaceObject = require("path");
|
|
|
48
48
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
49
49
|
const index_js_namespaceObject = require("../../../utils/index.js");
|
|
50
50
|
const publicDir_js_namespaceObject = require("../../../utils/publicDir.js");
|
|
51
|
+
const external_staticModuleFederation_js_namespaceObject = require("./staticModuleFederation.js");
|
|
52
|
+
const external_staticPrecompressed_js_namespaceObject = require("./staticPrecompressed.js");
|
|
51
53
|
const serverStaticPlugin = ()=>({
|
|
52
54
|
name: '@modern-js/plugin-server-static',
|
|
53
55
|
setup (api) {
|
|
@@ -68,98 +70,13 @@ const serverStaticPlugin = ()=>({
|
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
72
|
});
|
|
71
|
-
const PRE_COMPRESSED_ASSET_EXTENSIONS = {
|
|
72
|
-
br: '.br',
|
|
73
|
-
gzip: '.gz'
|
|
74
|
-
};
|
|
75
|
-
const PRE_COMPRESSED_SUPPORTED_ENCODINGS = [
|
|
76
|
-
'br',
|
|
77
|
-
'gzip'
|
|
78
|
-
];
|
|
79
|
-
const parseAcceptEncoding = (value)=>value.split(',').map((item)=>item.trim()).filter(Boolean).map((item)=>{
|
|
80
|
-
const [rawName, ...params] = item.split(';');
|
|
81
|
-
const name = rawName.trim().toLowerCase();
|
|
82
|
-
let q = 1;
|
|
83
|
-
for (const param of params){
|
|
84
|
-
const [key, rawValue] = param.split('=').map((v)=>v.trim());
|
|
85
|
-
if ('q' !== key.toLowerCase() || null == rawValue) continue;
|
|
86
|
-
const parsedQ = Number(rawValue);
|
|
87
|
-
if (!Number.isNaN(parsedQ)) q = Math.max(0, Math.min(parsedQ, 1));
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
name,
|
|
91
|
-
q
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
const getAcceptedEncodings = (value)=>{
|
|
95
|
-
if (!value) return [];
|
|
96
|
-
const parsed = parseAcceptEncoding(value);
|
|
97
|
-
const qualityByEncoding = new Map();
|
|
98
|
-
let wildcardQuality;
|
|
99
|
-
for (const { name, q } of parsed){
|
|
100
|
-
if ('*' === name) {
|
|
101
|
-
wildcardQuality = q;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
qualityByEncoding.set(name, q);
|
|
105
|
-
}
|
|
106
|
-
const getQuality = (encoding)=>{
|
|
107
|
-
const explicit = qualityByEncoding.get(encoding);
|
|
108
|
-
if (void 0 !== explicit) return explicit;
|
|
109
|
-
return wildcardQuality ?? 0;
|
|
110
|
-
};
|
|
111
|
-
return PRE_COMPRESSED_SUPPORTED_ENCODINGS.map((encoding)=>({
|
|
112
|
-
encoding,
|
|
113
|
-
quality: getQuality(encoding)
|
|
114
|
-
})).filter((item)=>item.quality > 0).sort((a, b)=>b.quality - a.quality).map((item)=>item.encoding);
|
|
115
|
-
};
|
|
116
|
-
const appendVaryHeader = (c, value)=>{
|
|
117
|
-
const current = c.res.headers.get('Vary');
|
|
118
|
-
if (!current) return void c.header('Vary', value);
|
|
119
|
-
const values = current.split(',').map((item)=>item.trim().toLowerCase()).filter(Boolean);
|
|
120
|
-
if (!values.includes(value.toLowerCase())) c.header('Vary', `${current}, ${value}`);
|
|
121
|
-
};
|
|
122
|
-
const resolvePreCompressedAsset = async (c, filepath)=>{
|
|
123
|
-
const brPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.br}`;
|
|
124
|
-
const gzipPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.gzip}`;
|
|
125
|
-
const [hasBr, hasGzip] = await Promise.all([
|
|
126
|
-
utils_namespaceObject.fs.pathExists(brPath),
|
|
127
|
-
utils_namespaceObject.fs.pathExists(gzipPath)
|
|
128
|
-
]);
|
|
129
|
-
const hasVariant = hasBr || hasGzip;
|
|
130
|
-
if (!hasVariant) return {
|
|
131
|
-
selected: null,
|
|
132
|
-
hasVariant: false
|
|
133
|
-
};
|
|
134
|
-
const acceptedEncodings = getAcceptedEncodings(c.req.header('accept-encoding'));
|
|
135
|
-
for (const encoding of acceptedEncodings){
|
|
136
|
-
if ('br' === encoding && hasBr) return {
|
|
137
|
-
selected: {
|
|
138
|
-
filepath: brPath,
|
|
139
|
-
encoding
|
|
140
|
-
},
|
|
141
|
-
hasVariant: true
|
|
142
|
-
};
|
|
143
|
-
if ('gzip' === encoding && hasGzip) return {
|
|
144
|
-
selected: {
|
|
145
|
-
filepath: gzipPath,
|
|
146
|
-
encoding
|
|
147
|
-
},
|
|
148
|
-
hasVariant: true
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
selected: null,
|
|
153
|
-
hasVariant: true
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
73
|
function createPublicMiddleware({ pwd, routes }) {
|
|
157
74
|
return async (c, next)=>{
|
|
158
75
|
const route = matchPublicRoute(c.req, routes);
|
|
159
76
|
if (route) {
|
|
160
77
|
const { entryPath } = route;
|
|
161
78
|
const originFilename = external_path_default().join(pwd, entryPath);
|
|
162
|
-
const preCompressedAsset = await resolvePreCompressedAsset(c, originFilename);
|
|
79
|
+
const preCompressedAsset = await (0, external_staticPrecompressed_js_namespaceObject.resolvePreCompressedAsset)(c, originFilename);
|
|
163
80
|
const filename = preCompressedAsset.selected?.filepath ?? originFilename;
|
|
164
81
|
const data = await fileReader_namespaceObject.fileReader.readFile(filename, 'buffer');
|
|
165
82
|
const mimeType = (0, mime_namespaceObject.getMimeType)(originFilename);
|
|
@@ -169,8 +86,7 @@ function createPublicMiddleware({ pwd, routes }) {
|
|
|
169
86
|
Object.entries(route.responseHeaders || {}).forEach(([k, v])=>{
|
|
170
87
|
c.header(k, v);
|
|
171
88
|
});
|
|
172
|
-
|
|
173
|
-
if (preCompressedAsset.selected) c.header('Content-Encoding', preCompressedAsset.selected.encoding);
|
|
89
|
+
(0, external_staticPrecompressed_js_namespaceObject.applyPreCompressedAssetHeaders)(c, preCompressedAsset);
|
|
174
90
|
c.header('Content-Length', String(data.byteLength));
|
|
175
91
|
return c.body(body, 200);
|
|
176
92
|
}
|
|
@@ -190,91 +106,6 @@ const extractPathname = (url)=>{
|
|
|
190
106
|
return url;
|
|
191
107
|
}
|
|
192
108
|
};
|
|
193
|
-
const MODULE_FEDERATION_MANIFEST_FILE = 'mf-manifest.json';
|
|
194
|
-
const MODULE_FEDERATION_OPTIONAL_FILES = [
|
|
195
|
-
'mf-stats.json'
|
|
196
|
-
];
|
|
197
|
-
const trimLeadingSlash = (value)=>value.replace(/^\/+/, '');
|
|
198
|
-
const joinModuleFederationAssetPath = (assetPath, assetName)=>{
|
|
199
|
-
if (!assetName) return '';
|
|
200
|
-
return trimLeadingSlash(external_path_default().posix.join(assetPath || '', assetName));
|
|
201
|
-
};
|
|
202
|
-
const appendModuleFederationAsset = (set, assetPath)=>{
|
|
203
|
-
if (!assetPath) return;
|
|
204
|
-
set.add(trimLeadingSlash(assetPath));
|
|
205
|
-
};
|
|
206
|
-
const appendModuleFederationAssets = (set, assets)=>{
|
|
207
|
-
assets?.js?.sync?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
208
|
-
assets?.js?.async?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
209
|
-
assets?.css?.sync?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
210
|
-
assets?.css?.async?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
211
|
-
};
|
|
212
|
-
const hasAbsoluteProtocol = (value)=>/^https?:\/\//i.test(value) || value.startsWith('//');
|
|
213
|
-
const ensureLeadingSlash = (value)=>{
|
|
214
|
-
if ('' === value) return '/';
|
|
215
|
-
return value.startsWith('/') ? value : `/${value}`;
|
|
216
|
-
};
|
|
217
|
-
const ensureTrailingSlash = (value)=>value.endsWith('/') ? value : `${value}/`;
|
|
218
|
-
const patchModuleFederationManifestPublicPath = (c, manifestBuffer, pathPrefix)=>{
|
|
219
|
-
try {
|
|
220
|
-
const manifest = JSON.parse(manifestBuffer.toString('utf-8'));
|
|
221
|
-
const publicPath = manifest.metaData?.publicPath;
|
|
222
|
-
if (!publicPath || hasAbsoluteProtocol(publicPath)) return manifestBuffer;
|
|
223
|
-
const requestURL = new URL(c.req.url);
|
|
224
|
-
const prefixPath = ensureTrailingSlash(ensureLeadingSlash(pathPrefix || '/'));
|
|
225
|
-
manifest.metaData = {
|
|
226
|
-
...manifest.metaData,
|
|
227
|
-
publicPath: `${requestURL.origin}${prefixPath}`
|
|
228
|
-
};
|
|
229
|
-
return Buffer.from(JSON.stringify(manifest), 'utf-8');
|
|
230
|
-
} catch {
|
|
231
|
-
return manifestBuffer;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
const patchModuleFederationRemoteEntryPublicPath = (c, remoteEntryBuffer, pathPrefix)=>{
|
|
235
|
-
const requestURL = new URL(c.req.url);
|
|
236
|
-
const prefixPath = ensureTrailingSlash(ensureLeadingSlash(pathPrefix || '/'));
|
|
237
|
-
const publicPath = `${requestURL.origin}${prefixPath}`;
|
|
238
|
-
const source = remoteEntryBuffer.toString('utf-8');
|
|
239
|
-
const patched = source.replace(/__webpack_require__\.p\s*=\s*(['"`])[^'"`]*\1;/, `__webpack_require__.p = ${JSON.stringify(publicPath)};`).replace(/__rspack_require__\.p\s*=\s*(['"`])[^'"`]*\1;/, `__rspack_require__.p = ${JSON.stringify(publicPath)};`);
|
|
240
|
-
if (patched === source) return remoteEntryBuffer;
|
|
241
|
-
return Buffer.from(patched, 'utf-8');
|
|
242
|
-
};
|
|
243
|
-
const getModuleFederationAssetList = async (pwd)=>{
|
|
244
|
-
const assets = new Set();
|
|
245
|
-
const manifestPath = external_path_default().join(pwd, MODULE_FEDERATION_MANIFEST_FILE);
|
|
246
|
-
if (!await utils_namespaceObject.fs.pathExists(manifestPath)) return {
|
|
247
|
-
assets,
|
|
248
|
-
remoteEntry: null
|
|
249
|
-
};
|
|
250
|
-
assets.add(MODULE_FEDERATION_MANIFEST_FILE);
|
|
251
|
-
const manifestBuffer = await fileReader_namespaceObject.fileReader.readFileFromSystem(manifestPath, 'buffer');
|
|
252
|
-
if (null === manifestBuffer) return {
|
|
253
|
-
assets,
|
|
254
|
-
remoteEntry: null
|
|
255
|
-
};
|
|
256
|
-
for (const filename of MODULE_FEDERATION_OPTIONAL_FILES)if (await utils_namespaceObject.fs.pathExists(external_path_default().join(pwd, filename))) assets.add(filename);
|
|
257
|
-
let remoteEntryFile = null;
|
|
258
|
-
try {
|
|
259
|
-
const manifest = JSON.parse(manifestBuffer.toString('utf-8'));
|
|
260
|
-
const remoteEntry = joinModuleFederationAssetPath(manifest.metaData?.remoteEntry?.path, manifest.metaData?.remoteEntry?.name);
|
|
261
|
-
const dtsZip = joinModuleFederationAssetPath(manifest.metaData?.types?.path, manifest.metaData?.types?.zip);
|
|
262
|
-
const dtsApi = joinModuleFederationAssetPath(manifest.metaData?.types?.path, manifest.metaData?.types?.api);
|
|
263
|
-
if (remoteEntry) {
|
|
264
|
-
assets.add(remoteEntry);
|
|
265
|
-
remoteEntryFile = remoteEntry;
|
|
266
|
-
}
|
|
267
|
-
if (dtsZip) assets.add(dtsZip);
|
|
268
|
-
if (dtsApi) assets.add(dtsApi);
|
|
269
|
-
manifest.shared?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
270
|
-
manifest.remotes?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
271
|
-
manifest.exposes?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
272
|
-
} catch {}
|
|
273
|
-
return {
|
|
274
|
-
assets,
|
|
275
|
-
remoteEntry: remoteEntryFile
|
|
276
|
-
};
|
|
277
|
-
};
|
|
278
109
|
function createStaticMiddleware(options) {
|
|
279
110
|
const { pwd, routes } = options;
|
|
280
111
|
const prefix = options.output.assetPrefix || '/';
|
|
@@ -311,30 +142,25 @@ function createStaticMiddleware(options) {
|
|
|
311
142
|
});
|
|
312
143
|
let moduleFederationAssetsPromise = null;
|
|
313
144
|
const getModuleFederationAssets = async ()=>{
|
|
314
|
-
if (!moduleFederationAssetsPromise) moduleFederationAssetsPromise = getModuleFederationAssetList(pwd);
|
|
145
|
+
if (!moduleFederationAssetsPromise) moduleFederationAssetsPromise = (0, external_staticModuleFederation_js_namespaceObject.getModuleFederationAssetList)(pwd);
|
|
315
146
|
return moduleFederationAssetsPromise;
|
|
316
147
|
};
|
|
317
148
|
const serveFile = async (c, filepath, moduleFederationAsset = false, moduleFederationRemoteEntry = false, requestPath = '')=>{
|
|
318
|
-
if (moduleFederationAsset)
|
|
319
|
-
c.header('Access-Control-Allow-Origin', '*');
|
|
320
|
-
c.header('Access-Control-Allow-Headers', '*');
|
|
321
|
-
c.header('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS');
|
|
322
|
-
}
|
|
149
|
+
if (moduleFederationAsset) (0, external_staticModuleFederation_js_namespaceObject.applyModuleFederationAssetHeaders)(c);
|
|
323
150
|
const mimeType = (0, mime_namespaceObject.getMimeType)(filepath);
|
|
324
151
|
if (mimeType) c.header('Content-Type', mimeType);
|
|
325
|
-
const shouldPatchManifest = moduleFederationAsset && requestPath
|
|
152
|
+
const shouldPatchManifest = moduleFederationAsset && (0, external_staticModuleFederation_js_namespaceObject.isModuleFederationManifestRequest)(requestPath);
|
|
326
153
|
const shouldPatchRemoteEntry = moduleFederationRemoteEntry;
|
|
327
154
|
const canUsePreCompressed = !shouldPatchManifest && !shouldPatchRemoteEntry;
|
|
328
|
-
const preCompressedAsset = canUsePreCompressed ? await resolvePreCompressedAsset(c, filepath) : {
|
|
155
|
+
const preCompressedAsset = canUsePreCompressed ? await (0, external_staticPrecompressed_js_namespaceObject.resolvePreCompressedAsset)(c, filepath) : {
|
|
329
156
|
selected: null,
|
|
330
157
|
hasVariant: false
|
|
331
158
|
};
|
|
332
159
|
const targetFilepath = preCompressedAsset.selected?.filepath ?? filepath;
|
|
333
160
|
const chunk = await fileReader_namespaceObject.fileReader.readFileFromSystem(targetFilepath, 'buffer');
|
|
334
161
|
if (null === chunk) return null;
|
|
335
|
-
const responseChunk = shouldPatchManifest ? patchModuleFederationManifestPublicPath(c, chunk, pathPrefix) : shouldPatchRemoteEntry ? patchModuleFederationRemoteEntryPublicPath(c, chunk, pathPrefix) : chunk;
|
|
336
|
-
|
|
337
|
-
if (preCompressedAsset.selected) c.header('Content-Encoding', preCompressedAsset.selected.encoding);
|
|
162
|
+
const responseChunk = shouldPatchManifest ? (0, external_staticModuleFederation_js_namespaceObject.patchModuleFederationManifestPublicPath)(c, chunk, pathPrefix) : shouldPatchRemoteEntry ? (0, external_staticModuleFederation_js_namespaceObject.patchModuleFederationRemoteEntryPublicPath)(c, chunk, pathPrefix) : chunk;
|
|
163
|
+
(0, external_staticPrecompressed_js_namespaceObject.applyPreCompressedAssetHeaders)(c, preCompressedAsset);
|
|
338
164
|
c.header('Content-Length', String(responseChunk.byteLength));
|
|
339
165
|
const body = new Uint8Array(responseChunk.buffer, responseChunk.byteOffset, responseChunk.byteLength);
|
|
340
166
|
return c.body(body, 200);
|
|
@@ -344,7 +170,7 @@ function createStaticMiddleware(options) {
|
|
|
344
170
|
const pathname = c.req.path;
|
|
345
171
|
if (pageRoute && '' === external_path_default().extname(pathname)) return next();
|
|
346
172
|
const hit = staticPathRegExp.test(pathname);
|
|
347
|
-
const requestPath =
|
|
173
|
+
const requestPath = (0, external_staticModuleFederation_js_namespaceObject.getModuleFederationRequestPath)(pathname, pathPrefix);
|
|
348
174
|
if (requestPath.includes('..')) return next();
|
|
349
175
|
const moduleFederationAssetMeta = await getModuleFederationAssets();
|
|
350
176
|
const isModuleFederationAsset = moduleFederationAssetMeta.assets.has(requestPath);
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
MODULE_FEDERATION_MANIFEST_FILE: ()=>MODULE_FEDERATION_MANIFEST_FILE,
|
|
41
|
+
applyModuleFederationAssetHeaders: ()=>applyModuleFederationAssetHeaders,
|
|
42
|
+
getModuleFederationAssetList: ()=>getModuleFederationAssetList,
|
|
43
|
+
getModuleFederationRequestPath: ()=>getModuleFederationRequestPath,
|
|
44
|
+
isModuleFederationManifestRequest: ()=>isModuleFederationManifestRequest,
|
|
45
|
+
patchModuleFederationManifestPublicPath: ()=>patchModuleFederationManifestPublicPath,
|
|
46
|
+
patchModuleFederationRemoteEntryPublicPath: ()=>patchModuleFederationRemoteEntryPublicPath,
|
|
47
|
+
trimLeadingSlash: ()=>trimLeadingSlash
|
|
48
|
+
});
|
|
49
|
+
const fileReader_namespaceObject = require("@modern-js/runtime-utils/fileReader");
|
|
50
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
51
|
+
const external_path_namespaceObject = require("path");
|
|
52
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
53
|
+
const MODULE_FEDERATION_MANIFEST_FILE = 'mf-manifest.json';
|
|
54
|
+
const MODULE_FEDERATION_OPTIONAL_FILES = [
|
|
55
|
+
'mf-stats.json'
|
|
56
|
+
];
|
|
57
|
+
const trimLeadingSlash = (value)=>value.replace(/^\/+/, '');
|
|
58
|
+
const getModuleFederationRequestPath = (pathname, pathPrefix)=>trimLeadingSlash(pathname.replace(pathPrefix, ()=>''));
|
|
59
|
+
const isModuleFederationManifestRequest = (requestPath)=>requestPath === MODULE_FEDERATION_MANIFEST_FILE;
|
|
60
|
+
const applyModuleFederationAssetHeaders = (c)=>{
|
|
61
|
+
c.header('Access-Control-Allow-Origin', '*');
|
|
62
|
+
c.header('Access-Control-Allow-Headers', '*');
|
|
63
|
+
c.header('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS');
|
|
64
|
+
};
|
|
65
|
+
const joinModuleFederationAssetPath = (assetPath, assetName)=>{
|
|
66
|
+
if (!assetName) return '';
|
|
67
|
+
return trimLeadingSlash(external_path_default().posix.join(assetPath || '', assetName));
|
|
68
|
+
};
|
|
69
|
+
const appendModuleFederationAsset = (set, assetPath)=>{
|
|
70
|
+
if (!assetPath) return;
|
|
71
|
+
set.add(trimLeadingSlash(assetPath));
|
|
72
|
+
};
|
|
73
|
+
const appendModuleFederationAssets = (set, assets)=>{
|
|
74
|
+
assets?.js?.sync?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
75
|
+
assets?.js?.async?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
76
|
+
assets?.css?.sync?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
77
|
+
assets?.css?.async?.forEach((asset)=>appendModuleFederationAsset(set, asset));
|
|
78
|
+
};
|
|
79
|
+
const hasAbsoluteProtocol = (value)=>/^https?:\/\//i.test(value) || value.startsWith('//');
|
|
80
|
+
const ensureLeadingSlash = (value)=>{
|
|
81
|
+
if ('' === value) return '/';
|
|
82
|
+
return value.startsWith('/') ? value : `/${value}`;
|
|
83
|
+
};
|
|
84
|
+
const ensureTrailingSlash = (value)=>value.endsWith('/') ? value : `${value}/`;
|
|
85
|
+
const patchModuleFederationManifestPublicPath = (c, manifestBuffer, pathPrefix)=>{
|
|
86
|
+
try {
|
|
87
|
+
const manifest = JSON.parse(manifestBuffer.toString('utf-8'));
|
|
88
|
+
const publicPath = manifest.metaData?.publicPath;
|
|
89
|
+
if (!publicPath || hasAbsoluteProtocol(publicPath)) return manifestBuffer;
|
|
90
|
+
const requestURL = new URL(c.req.url);
|
|
91
|
+
const prefixPath = ensureTrailingSlash(ensureLeadingSlash(pathPrefix || '/'));
|
|
92
|
+
manifest.metaData = {
|
|
93
|
+
...manifest.metaData,
|
|
94
|
+
publicPath: `${requestURL.origin}${prefixPath}`
|
|
95
|
+
};
|
|
96
|
+
return Buffer.from(JSON.stringify(manifest), 'utf-8');
|
|
97
|
+
} catch {
|
|
98
|
+
return manifestBuffer;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const patchModuleFederationRemoteEntryPublicPath = (c, remoteEntryBuffer, pathPrefix)=>{
|
|
102
|
+
const requestURL = new URL(c.req.url);
|
|
103
|
+
const prefixPath = ensureTrailingSlash(ensureLeadingSlash(pathPrefix || '/'));
|
|
104
|
+
const publicPath = `${requestURL.origin}${prefixPath}`;
|
|
105
|
+
const source = remoteEntryBuffer.toString('utf-8');
|
|
106
|
+
const patched = source.replace(/__webpack_require__\.p\s*=\s*(['"`])[^'"`]*\1;/, `__webpack_require__.p = ${JSON.stringify(publicPath)};`).replace(/__rspack_require__\.p\s*=\s*(['"`])[^'"`]*\1;/, `__rspack_require__.p = ${JSON.stringify(publicPath)};`);
|
|
107
|
+
if (patched === source) return remoteEntryBuffer;
|
|
108
|
+
return Buffer.from(patched, 'utf-8');
|
|
109
|
+
};
|
|
110
|
+
const getModuleFederationAssetList = async (pwd)=>{
|
|
111
|
+
const assets = new Set();
|
|
112
|
+
const manifestPath = external_path_default().join(pwd, MODULE_FEDERATION_MANIFEST_FILE);
|
|
113
|
+
if (!await utils_namespaceObject.fs.pathExists(manifestPath)) return {
|
|
114
|
+
assets,
|
|
115
|
+
remoteEntry: null
|
|
116
|
+
};
|
|
117
|
+
assets.add(MODULE_FEDERATION_MANIFEST_FILE);
|
|
118
|
+
const manifestBuffer = await fileReader_namespaceObject.fileReader.readFileFromSystem(manifestPath, 'buffer');
|
|
119
|
+
if (null === manifestBuffer) return {
|
|
120
|
+
assets,
|
|
121
|
+
remoteEntry: null
|
|
122
|
+
};
|
|
123
|
+
for (const filename of MODULE_FEDERATION_OPTIONAL_FILES)if (await utils_namespaceObject.fs.pathExists(external_path_default().join(pwd, filename))) assets.add(filename);
|
|
124
|
+
let remoteEntryFile = null;
|
|
125
|
+
try {
|
|
126
|
+
const manifest = JSON.parse(manifestBuffer.toString('utf-8'));
|
|
127
|
+
const remoteEntry = joinModuleFederationAssetPath(manifest.metaData?.remoteEntry?.path, manifest.metaData?.remoteEntry?.name);
|
|
128
|
+
const dtsZip = joinModuleFederationAssetPath(manifest.metaData?.types?.path, manifest.metaData?.types?.zip);
|
|
129
|
+
const dtsApi = joinModuleFederationAssetPath(manifest.metaData?.types?.path, manifest.metaData?.types?.api);
|
|
130
|
+
if (remoteEntry) {
|
|
131
|
+
assets.add(remoteEntry);
|
|
132
|
+
remoteEntryFile = remoteEntry;
|
|
133
|
+
}
|
|
134
|
+
if (dtsZip) assets.add(dtsZip);
|
|
135
|
+
if (dtsApi) assets.add(dtsApi);
|
|
136
|
+
manifest.shared?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
137
|
+
manifest.remotes?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
138
|
+
manifest.exposes?.forEach((item)=>appendModuleFederationAssets(assets, item.assets));
|
|
139
|
+
} catch {}
|
|
140
|
+
return {
|
|
141
|
+
assets,
|
|
142
|
+
remoteEntry: remoteEntryFile
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
exports.MODULE_FEDERATION_MANIFEST_FILE = __webpack_exports__.MODULE_FEDERATION_MANIFEST_FILE;
|
|
146
|
+
exports.applyModuleFederationAssetHeaders = __webpack_exports__.applyModuleFederationAssetHeaders;
|
|
147
|
+
exports.getModuleFederationAssetList = __webpack_exports__.getModuleFederationAssetList;
|
|
148
|
+
exports.getModuleFederationRequestPath = __webpack_exports__.getModuleFederationRequestPath;
|
|
149
|
+
exports.isModuleFederationManifestRequest = __webpack_exports__.isModuleFederationManifestRequest;
|
|
150
|
+
exports.patchModuleFederationManifestPublicPath = __webpack_exports__.patchModuleFederationManifestPublicPath;
|
|
151
|
+
exports.patchModuleFederationRemoteEntryPublicPath = __webpack_exports__.patchModuleFederationRemoteEntryPublicPath;
|
|
152
|
+
exports.trimLeadingSlash = __webpack_exports__.trimLeadingSlash;
|
|
153
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
154
|
+
"MODULE_FEDERATION_MANIFEST_FILE",
|
|
155
|
+
"applyModuleFederationAssetHeaders",
|
|
156
|
+
"getModuleFederationAssetList",
|
|
157
|
+
"getModuleFederationRequestPath",
|
|
158
|
+
"isModuleFederationManifestRequest",
|
|
159
|
+
"patchModuleFederationManifestPublicPath",
|
|
160
|
+
"patchModuleFederationRemoteEntryPublicPath",
|
|
161
|
+
"trimLeadingSlash"
|
|
162
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
163
|
+
Object.defineProperty(exports, '__esModule', {
|
|
164
|
+
value: true
|
|
165
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
appendVaryHeader: ()=>appendVaryHeader,
|
|
32
|
+
applyPreCompressedAssetHeaders: ()=>applyPreCompressedAssetHeaders,
|
|
33
|
+
resolvePreCompressedAsset: ()=>resolvePreCompressedAsset
|
|
34
|
+
});
|
|
35
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
36
|
+
const PRE_COMPRESSED_ASSET_EXTENSIONS = {
|
|
37
|
+
br: '.br',
|
|
38
|
+
gzip: '.gz'
|
|
39
|
+
};
|
|
40
|
+
const PRE_COMPRESSED_SUPPORTED_ENCODINGS = [
|
|
41
|
+
'br',
|
|
42
|
+
'gzip'
|
|
43
|
+
];
|
|
44
|
+
const parseAcceptEncoding = (value)=>value.split(',').map((item)=>item.trim()).filter(Boolean).map((item)=>{
|
|
45
|
+
const [rawName, ...params] = item.split(';');
|
|
46
|
+
const name = rawName.trim().toLowerCase();
|
|
47
|
+
let q = 1;
|
|
48
|
+
for (const param of params){
|
|
49
|
+
const [key, rawValue] = param.split('=').map((v)=>v.trim());
|
|
50
|
+
if ('q' !== key.toLowerCase() || null == rawValue) continue;
|
|
51
|
+
const parsedQ = Number(rawValue);
|
|
52
|
+
if (!Number.isNaN(parsedQ)) q = Math.max(0, Math.min(parsedQ, 1));
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
name,
|
|
56
|
+
q
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
const getAcceptedEncodings = (value)=>{
|
|
60
|
+
if (!value) return [];
|
|
61
|
+
const parsed = parseAcceptEncoding(value);
|
|
62
|
+
const qualityByEncoding = new Map();
|
|
63
|
+
let wildcardQuality;
|
|
64
|
+
for (const { name, q } of parsed){
|
|
65
|
+
if ('*' === name) {
|
|
66
|
+
wildcardQuality = q;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
qualityByEncoding.set(name, q);
|
|
70
|
+
}
|
|
71
|
+
const getQuality = (encoding)=>{
|
|
72
|
+
const explicit = qualityByEncoding.get(encoding);
|
|
73
|
+
if (void 0 !== explicit) return explicit;
|
|
74
|
+
return wildcardQuality ?? 0;
|
|
75
|
+
};
|
|
76
|
+
return PRE_COMPRESSED_SUPPORTED_ENCODINGS.map((encoding)=>({
|
|
77
|
+
encoding,
|
|
78
|
+
quality: getQuality(encoding)
|
|
79
|
+
})).filter((item)=>item.quality > 0).sort((a, b)=>b.quality - a.quality).map((item)=>item.encoding);
|
|
80
|
+
};
|
|
81
|
+
const appendVaryHeader = (c, value)=>{
|
|
82
|
+
const current = c.res.headers.get('Vary');
|
|
83
|
+
if (!current) return void c.header('Vary', value);
|
|
84
|
+
const values = current.split(',').map((item)=>item.trim().toLowerCase()).filter(Boolean);
|
|
85
|
+
if (!values.includes(value.toLowerCase())) c.header('Vary', `${current}, ${value}`);
|
|
86
|
+
};
|
|
87
|
+
const resolvePreCompressedAsset = async (c, filepath)=>{
|
|
88
|
+
const brPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.br}`;
|
|
89
|
+
const gzipPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.gzip}`;
|
|
90
|
+
const [hasBr, hasGzip] = await Promise.all([
|
|
91
|
+
utils_namespaceObject.fs.pathExists(brPath),
|
|
92
|
+
utils_namespaceObject.fs.pathExists(gzipPath)
|
|
93
|
+
]);
|
|
94
|
+
const hasVariant = hasBr || hasGzip;
|
|
95
|
+
if (!hasVariant) return {
|
|
96
|
+
selected: null,
|
|
97
|
+
hasVariant: false
|
|
98
|
+
};
|
|
99
|
+
const acceptedEncodings = getAcceptedEncodings(c.req.header('accept-encoding'));
|
|
100
|
+
for (const encoding of acceptedEncodings){
|
|
101
|
+
if ('br' === encoding && hasBr) return {
|
|
102
|
+
selected: {
|
|
103
|
+
filepath: brPath,
|
|
104
|
+
encoding
|
|
105
|
+
},
|
|
106
|
+
hasVariant: true
|
|
107
|
+
};
|
|
108
|
+
if ('gzip' === encoding && hasGzip) return {
|
|
109
|
+
selected: {
|
|
110
|
+
filepath: gzipPath,
|
|
111
|
+
encoding
|
|
112
|
+
},
|
|
113
|
+
hasVariant: true
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
selected: null,
|
|
118
|
+
hasVariant: true
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const applyPreCompressedAssetHeaders = (c, preCompressedAsset)=>{
|
|
122
|
+
if (preCompressedAsset.hasVariant) appendVaryHeader(c, 'Accept-Encoding');
|
|
123
|
+
if (preCompressedAsset.selected) c.header('Content-Encoding', preCompressedAsset.selected.encoding);
|
|
124
|
+
};
|
|
125
|
+
exports.appendVaryHeader = __webpack_exports__.appendVaryHeader;
|
|
126
|
+
exports.applyPreCompressedAssetHeaders = __webpack_exports__.applyPreCompressedAssetHeaders;
|
|
127
|
+
exports.resolvePreCompressedAsset = __webpack_exports__.resolvePreCompressedAsset;
|
|
128
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
129
|
+
"appendVaryHeader",
|
|
130
|
+
"applyPreCompressedAssetHeaders",
|
|
131
|
+
"resolvePreCompressedAsset"
|
|
132
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
133
|
+
Object.defineProperty(exports, '__esModule', {
|
|
134
|
+
value: true
|
|
135
|
+
});
|