@bleedingdev/modern-js-server-runtime-extensions 3.11.3-ultramodern.1 → 3.11.3-ultramodern.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/cjs/backend-federation-security/index.js +7 -8
- package/dist/cjs/backend-federation-security/node.js +1 -1
- package/dist/cjs/bff-policy/operationIdentity.js +2 -3
- package/dist/cjs/env.js +5 -1
- package/dist/cjs/mfCache.js +6 -7
- package/dist/cjs/module-federation-css/plugin.js +7 -3
- package/dist/cjs/render-resources/channels.js +55 -0
- package/dist/cjs/render-resources/index.js +47 -0
- package/dist/cjs/render-resources/plugin.js +82 -0
- package/dist/cjs/runtime-fallback-signal/model.js +9 -10
- package/dist/cjs/serverPlugin.js +2 -0
- package/dist/cjs/static-serving/immutableAssetStat.js +64 -0
- package/dist/cjs/static-serving/plugin.js +2 -1
- package/dist/cjs/static-serving/responders.js +13 -8
- package/dist/cjs/static-serving/staticPrecompressed.js +6 -3
- package/dist/cjs/telemetry/envelope.js +9 -9
- package/dist/cjs/telemetry/exporters.js +4 -4
- package/dist/cjs/telemetry/registryTypes.js +2 -2
- package/dist/esm/env.mjs +5 -1
- package/dist/esm/module-federation-css/plugin.mjs +7 -3
- package/dist/esm/serverPlugin.mjs +2 -0
- package/dist/esm-node/env.mjs +5 -1
- package/dist/esm-node/module-federation-css/plugin.mjs +7 -3
- package/dist/esm-node/render-resources/channels.mjs +5 -0
- package/dist/esm-node/render-resources/index.mjs +3 -0
- package/dist/esm-node/render-resources/plugin.mjs +43 -0
- package/dist/esm-node/serverPlugin.mjs +2 -0
- package/dist/esm-node/static-serving/immutableAssetStat.mjs +24 -0
- package/dist/esm-node/static-serving/plugin.mjs +2 -1
- package/dist/esm-node/static-serving/responders.mjs +13 -8
- package/dist/esm-node/static-serving/staticPrecompressed.mjs +6 -3
- package/dist/types/env.d.ts +15 -0
- package/dist/types/module-federation-css/plugin.d.ts +3 -2
- package/dist/types/render-resources/channels.d.ts +27 -0
- package/dist/types/render-resources/index.d.ts +2 -0
- package/dist/types/render-resources/plugin.d.ts +3 -0
- package/dist/types/static-serving/immutableAssetStat.d.ts +8 -0
- package/dist/types/static-serving/responders.d.ts +7 -1
- package/dist/types/static-serving/staticPrecompressed.d.ts +1 -1
- package/dist/types-esm/env.d.mts +15 -0
- package/dist/types-esm/module-federation-css/plugin.d.mts +3 -2
- package/dist/types-esm/render-resources/channels.d.mts +27 -0
- package/dist/types-esm/render-resources/index.d.mts +2 -0
- package/dist/types-esm/render-resources/plugin.d.mts +3 -0
- package/dist/types-esm/static-serving/immutableAssetStat.d.mts +8 -0
- package/dist/types-esm/static-serving/responders.d.mts +7 -1
- package/dist/types-esm/static-serving/staticPrecompressed.d.mts +1 -1
- package/package.json +31 -14
- package/src/env.ts +25 -0
- package/src/module-federation-css/plugin.ts +21 -5
- package/src/render-resources/channels.ts +37 -0
- package/src/render-resources/index.ts +7 -0
- package/src/render-resources/plugin.ts +56 -0
- package/src/serverPlugin.ts +2 -0
- package/src/static-serving/immutableAssetStat.ts +41 -0
- package/src/static-serving/plugin.ts +4 -1
- package/src/static-serving/responders.ts +30 -6
- package/src/static-serving/staticPrecompressed.ts +5 -4
|
@@ -3,6 +3,7 @@ import { injectErrorResponsePlugin } from "./errorResponsePlugin.mjs";
|
|
|
3
3
|
import { injectLocalisedLoaderPlugin } from "./localisedLoaderPlugin.mjs";
|
|
4
4
|
import { injectMfAssetCacheHeadersPlugin } from "./mfCache.mjs";
|
|
5
5
|
import { injectModuleFederationCssPlugin } from "./module-federation-css/plugin.mjs";
|
|
6
|
+
import { injectRenderResourcesPlugin } from "./render-resources/plugin.mjs";
|
|
6
7
|
import { disposeServerRuntime } from "./runtimeLifecycle.mjs";
|
|
7
8
|
import { injectStaticServingPlugin } from "./static-serving/plugin.mjs";
|
|
8
9
|
import { injectTelemetryPlugin } from "./telemetry/plugin.mjs";
|
|
@@ -15,6 +16,7 @@ const ultramodernServerPlugin = ()=>({
|
|
|
15
16
|
injectModuleFederationCssPlugin(),
|
|
16
17
|
injectMfAssetCacheHeadersPlugin(),
|
|
17
18
|
injectStaticServingPlugin(),
|
|
19
|
+
injectRenderResourcesPlugin(),
|
|
18
20
|
{
|
|
19
21
|
name: '@modern-js/server-runtime-lifecycle',
|
|
20
22
|
pre: [
|
package/dist/esm-node/env.mjs
CHANGED
|
@@ -8,11 +8,15 @@ const readString = (value)=>{
|
|
|
8
8
|
const parseServerRuntimeExtensionsEnv = (env = process.env)=>{
|
|
9
9
|
const modernEnv = readString(env.MODERN_ENV);
|
|
10
10
|
const nodeEnv = readString(env.NODE_ENV);
|
|
11
|
+
const production = 'production' === nodeEnv;
|
|
11
12
|
return {
|
|
12
13
|
modernEnv,
|
|
13
14
|
nodeEnv,
|
|
14
15
|
environmentName: modernEnv || nodeEnv || DEFAULT_ENVIRONMENT_NAME,
|
|
15
|
-
contractGatesFile: readString(env.MODERN_CONTRACT_GATES_FILE)
|
|
16
|
+
contractGatesFile: readString(env.MODERN_CONTRACT_GATES_FILE),
|
|
17
|
+
renderResources: 'lazy' === readString(env.MODERN_SERVER_RENDER_RESOURCES) ? 'lazy' : 'eager',
|
|
18
|
+
immutableAssets: production && 'true' === readString(env.MODERN_SERVER_IMMUTABLE_ASSETS),
|
|
19
|
+
precompressedAssets: !production || 'false' !== readString(env.MODERN_SERVER_PRECOMPRESSED_ASSETS)
|
|
16
20
|
};
|
|
17
21
|
};
|
|
18
22
|
export { DEFAULT_ENVIRONMENT_NAME, parseServerRuntimeExtensionsEnv };
|
|
@@ -11,7 +11,7 @@ const injectModuleFederationCssPlugin = (options = {})=>({
|
|
|
11
11
|
],
|
|
12
12
|
setup (api) {
|
|
13
13
|
api.onPrepare(()=>{
|
|
14
|
-
const { middlewares, distDirectory: pwd } = api.getServerContext();
|
|
14
|
+
const { middlewares, renderMiddlewares, renderResources, distDirectory: pwd } = api.getServerContext();
|
|
15
15
|
if (!pwd) return;
|
|
16
16
|
const ttlMs = Math.max(0, options.remoteCssCacheTtlMs ?? (isProd() ? DEFAULT_REMOTE_CSS_CACHE_TTL_MS : 0));
|
|
17
17
|
const collector = createModuleFederationCssCollector(pwd, {
|
|
@@ -30,10 +30,14 @@ const injectModuleFederationCssPlugin = (options = {})=>({
|
|
|
30
30
|
}
|
|
31
31
|
await next();
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
const middleware = {
|
|
34
34
|
name: 'inject-module-federation-css',
|
|
35
35
|
handler
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
|
+
if (isProd() && renderResources?.loading === 'lazy') {
|
|
38
|
+
const templates = renderMiddlewares.findIndex((middleware)=>'inject-html' === middleware.name);
|
|
39
|
+
renderMiddlewares.splice(templates + 1, 0, middleware);
|
|
40
|
+
} else middlewares.push(middleware);
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
43
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_diagnostics_channel from "node:diagnostics_channel";
|
|
3
|
+
const renderBundleLoadChannel = node_diagnostics_channel.channel('modern-js:server:render-bundle-load');
|
|
4
|
+
const serverRequestChannel = node_diagnostics_channel.tracingChannel('modern-js:server:request');
|
|
5
|
+
export { renderBundleLoadChannel, serverRequestChannel };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
3
|
+
import { parseServerRuntimeExtensionsEnv } from "../env.mjs";
|
|
4
|
+
import { renderBundleLoadChannel, serverRequestChannel } from "./channels.mjs";
|
|
5
|
+
function injectRenderResourcesPlugin() {
|
|
6
|
+
return {
|
|
7
|
+
name: '@modern-js/server-render-resources',
|
|
8
|
+
setup (api) {
|
|
9
|
+
const distDirectory = api.getServerContext().distDirectory;
|
|
10
|
+
api.updateServerContext({
|
|
11
|
+
renderResources: {
|
|
12
|
+
loading: parseServerRuntimeExtensionsEnv().renderResources,
|
|
13
|
+
onBundleLoad ({ filepath, requestPath }) {
|
|
14
|
+
if (!renderBundleLoadChannel.hasSubscribers) return;
|
|
15
|
+
const started = performance.now();
|
|
16
|
+
return (outcome)=>{
|
|
17
|
+
renderBundleLoadChannel.publish({
|
|
18
|
+
distDirectory,
|
|
19
|
+
filepath,
|
|
20
|
+
durationMs: performance.now() - started,
|
|
21
|
+
outcome,
|
|
22
|
+
triggerPath: requestPath ?? '<startup>'
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
api.onPrepare(()=>{
|
|
29
|
+
const handler = (c, next)=>serverRequestChannel.tracePromise(next, {
|
|
30
|
+
distDirectory,
|
|
31
|
+
path: c.req.path
|
|
32
|
+
});
|
|
33
|
+
api.getServerContext().middlewares.unshift({
|
|
34
|
+
name: 'trace-server-request',
|
|
35
|
+
handler
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const render_resources_plugin = injectRenderResourcesPlugin;
|
|
42
|
+
export default render_resources_plugin;
|
|
43
|
+
export { injectRenderResourcesPlugin };
|
|
@@ -4,6 +4,7 @@ import { injectErrorResponsePlugin } from "./errorResponsePlugin.mjs";
|
|
|
4
4
|
import { injectLocalisedLoaderPlugin } from "./localisedLoaderPlugin.mjs";
|
|
5
5
|
import { injectMfAssetCacheHeadersPlugin } from "./mfCache.mjs";
|
|
6
6
|
import { injectModuleFederationCssPlugin } from "./module-federation-css/plugin.mjs";
|
|
7
|
+
import { injectRenderResourcesPlugin } from "./render-resources/plugin.mjs";
|
|
7
8
|
import { disposeServerRuntime } from "./runtimeLifecycle.mjs";
|
|
8
9
|
import { injectStaticServingPlugin } from "./static-serving/plugin.mjs";
|
|
9
10
|
import { injectTelemetryPlugin } from "./telemetry/plugin.mjs";
|
|
@@ -16,6 +17,7 @@ const ultramodernServerPlugin = ()=>({
|
|
|
16
17
|
injectModuleFederationCssPlugin(),
|
|
17
18
|
injectMfAssetCacheHeadersPlugin(),
|
|
18
19
|
injectStaticServingPlugin(),
|
|
20
|
+
injectRenderResourcesPlugin(),
|
|
19
21
|
{
|
|
20
22
|
name: '@modern-js/server-runtime-lifecycle',
|
|
21
23
|
pre: [
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
const IMMUTABLE_ASSET_STAT_LIMIT = 8192;
|
|
4
|
+
function createImmutableAssetStat() {
|
|
5
|
+
const stats = new Map();
|
|
6
|
+
const forget = (filename, pending)=>{
|
|
7
|
+
if (stats.get(filename) === pending) stats.delete(filename);
|
|
8
|
+
};
|
|
9
|
+
return (filename)=>{
|
|
10
|
+
const cached = stats.get(filename);
|
|
11
|
+
if (cached) return cached;
|
|
12
|
+
const pending = fs.stat(filename).then((stat)=>{
|
|
13
|
+
if (!stat.isFile()) forget(filename, pending);
|
|
14
|
+
return stat;
|
|
15
|
+
}, ()=>{
|
|
16
|
+
forget(filename, pending);
|
|
17
|
+
return null;
|
|
18
|
+
});
|
|
19
|
+
if (stats.size >= IMMUTABLE_ASSET_STAT_LIMIT) stats.delete(stats.keys().next().value);
|
|
20
|
+
stats.set(filename, pending);
|
|
21
|
+
return pending;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { IMMUTABLE_ASSET_STAT_LIMIT, createImmutableAssetStat };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { parseServerRuntimeExtensionsEnv } from "../env.mjs";
|
|
2
3
|
import { createStaticExtensionResponders } from "./responders.mjs";
|
|
3
4
|
function injectStaticServingPlugin() {
|
|
4
5
|
return {
|
|
@@ -8,7 +9,7 @@ function injectStaticServingPlugin() {
|
|
|
8
9
|
],
|
|
9
10
|
setup (api) {
|
|
10
11
|
api.updateServerContext({
|
|
11
|
-
staticAssetResponders: createStaticExtensionResponders()
|
|
12
|
+
staticAssetResponders: createStaticExtensionResponders(parseServerRuntimeExtensionsEnv())
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import node_path from "node:path";
|
|
3
3
|
import { serveStaticAsset } from "@modern-js/server-core/node";
|
|
4
|
+
import { createImmutableAssetStat } from "./immutableAssetStat.mjs";
|
|
4
5
|
import { applyModuleFederationAssetHeaders, getModuleFederationAssetList, getModuleFederationRequestPath, isBackendModuleFederationManifestRequest, isModuleFederationManifestRequest, patchModuleFederationManifestPublicPath, patchModuleFederationRemoteEntryPublicPath } from "./staticModuleFederation.mjs";
|
|
5
6
|
import { applyPreCompressedAssetHeaders, resolvePreCompressedAsset } from "./staticPrecompressed.mjs";
|
|
6
|
-
async function respondPrecompressedAsset(context, asset, serve) {
|
|
7
|
-
const selected = await resolvePreCompressedAsset(context, asset.filename);
|
|
7
|
+
async function respondPrecompressedAsset(context, asset, serve, precompressedAssets) {
|
|
8
|
+
const selected = await resolvePreCompressedAsset(context, asset.filename, precompressedAssets);
|
|
8
9
|
const response = selected.acceptable ? await serve({
|
|
9
10
|
filename: selected.selected?.filepath,
|
|
10
11
|
contentLength: true
|
|
@@ -17,7 +18,9 @@ async function respondPrecompressedAsset(context, asset, serve) {
|
|
|
17
18
|
if ('.cjs' === node_path.extname(asset.filename).toLowerCase()) context.res.headers.set('Content-Type', "text/javascript; charset=UTF-8");
|
|
18
19
|
return context.res;
|
|
19
20
|
}
|
|
20
|
-
function createStaticExtensionResponders() {
|
|
21
|
+
function createStaticExtensionResponders({ immutableAssets, precompressedAssets }) {
|
|
22
|
+
const stat = immutableAssets ? createImmutableAssetStat() : void 0;
|
|
23
|
+
const respondPrecompressed = (context, asset, serve)=>respondPrecompressedAsset(context, asset, serve, precompressedAssets);
|
|
21
24
|
const caches = new Map();
|
|
22
25
|
const getAssets = (root)=>{
|
|
23
26
|
let cache = caches.get(root);
|
|
@@ -34,7 +37,7 @@ function createStaticExtensionResponders() {
|
|
|
34
37
|
const current = cache;
|
|
35
38
|
const pending = getModuleFederationAssetList(root).then((assets)=>{
|
|
36
39
|
current.assets = assets;
|
|
37
|
-
current.expires = Date.now() + 1000;
|
|
40
|
+
current.expires = immutableAssets ? 1 / 0 : Date.now() + 1000;
|
|
38
41
|
return assets;
|
|
39
42
|
}).finally(()=>{
|
|
40
43
|
current.pending = null;
|
|
@@ -45,7 +48,7 @@ function createStaticExtensionResponders() {
|
|
|
45
48
|
async function serveFederated(context, asset, serve, requestPath, pathPrefix, remoteEntry) {
|
|
46
49
|
applyModuleFederationAssetHeaders(context);
|
|
47
50
|
const patchManifest = isModuleFederationManifestRequest(requestPath) && !isBackendModuleFederationManifestRequest(requestPath);
|
|
48
|
-
if (!patchManifest && !remoteEntry) return
|
|
51
|
+
if (!patchManifest && !remoteEntry) return respondPrecompressed(context, asset, serve);
|
|
49
52
|
const response = await serve({
|
|
50
53
|
contentLength: true,
|
|
51
54
|
revalidate: false
|
|
@@ -80,7 +83,7 @@ function createStaticExtensionResponders() {
|
|
|
80
83
|
kind: 'static',
|
|
81
84
|
root: publicRoot,
|
|
82
85
|
realpath: true
|
|
83
|
-
}, (asset, serve)=>
|
|
86
|
+
}, (asset, serve)=>respondPrecompressed(context, asset, serve));
|
|
84
87
|
if (response && 'HEAD' === context.req.raw.method.toUpperCase()) return new Response(null, {
|
|
85
88
|
status: response.status,
|
|
86
89
|
headers: response.headers
|
|
@@ -88,12 +91,13 @@ function createStaticExtensionResponders() {
|
|
|
88
91
|
return response;
|
|
89
92
|
}
|
|
90
93
|
return {
|
|
94
|
+
stat,
|
|
91
95
|
async respondAsset (context, asset, serve, { root, pathPrefix }) {
|
|
92
96
|
const requestPath = getModuleFederationRequestPath(context.req.path, pathPrefix);
|
|
93
97
|
if (requestPath.includes('..')) return null;
|
|
94
98
|
const assets = await getAssets(root);
|
|
95
99
|
if ('static' === asset.kind && assets.assets.has(requestPath)) return serveFederated(context, asset, serve, requestPath, pathPrefix, assets.remoteEntries.has(requestPath));
|
|
96
|
-
return
|
|
100
|
+
return respondPrecompressed(context, asset, serve);
|
|
97
101
|
},
|
|
98
102
|
async respondPublicFallback (context, respondPublic, { root, pathPrefix }) {
|
|
99
103
|
const requestPath = getModuleFederationRequestPath(context.req.path, pathPrefix);
|
|
@@ -103,7 +107,8 @@ function createStaticExtensionResponders() {
|
|
|
103
107
|
const response = await serveStaticAsset(context, {
|
|
104
108
|
filename: node_path.join(root, requestPath),
|
|
105
109
|
kind: 'static',
|
|
106
|
-
root
|
|
110
|
+
root,
|
|
111
|
+
stat
|
|
107
112
|
}, (asset, serve)=>serveFederated(context, asset, serve, requestPath, pathPrefix, assets.remoteEntries.has(requestPath)));
|
|
108
113
|
if (null !== response) return response;
|
|
109
114
|
}
|
|
@@ -67,13 +67,16 @@ const appendVaryHeader = (c, value)=>{
|
|
|
67
67
|
const values = current.split(',').map((item)=>item.trim().toLowerCase()).filter(Boolean);
|
|
68
68
|
if (!values.includes(value.toLowerCase())) c.header('Vary', `${current}, ${value}`);
|
|
69
69
|
};
|
|
70
|
-
const resolvePreCompressedAsset = async (c, filepath)=>{
|
|
70
|
+
const resolvePreCompressedAsset = async (c, filepath, probeVariants)=>{
|
|
71
71
|
const brPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.br}`;
|
|
72
72
|
const gzipPath = `${filepath}${PRE_COMPRESSED_ASSET_EXTENSIONS.gzip}`;
|
|
73
|
-
const [hasBr, hasGzip] = await Promise.all([
|
|
73
|
+
const [hasBr, hasGzip] = probeVariants ? await Promise.all([
|
|
74
74
|
fs.pathExists(brPath),
|
|
75
75
|
fs.pathExists(gzipPath)
|
|
76
|
-
])
|
|
76
|
+
]) : [
|
|
77
|
+
false,
|
|
78
|
+
false
|
|
79
|
+
];
|
|
77
80
|
const hasVariant = hasBr || hasGzip;
|
|
78
81
|
const acceptedRepresentations = getAcceptedRepresentations(c.req.header('accept-encoding'));
|
|
79
82
|
for (const encoding of acceptedRepresentations){
|
package/dist/types/env.d.ts
CHANGED
|
@@ -30,6 +30,21 @@ export interface ServerRuntimeExtensionsEnv {
|
|
|
30
30
|
* (absolute, or relative to the app directory). Undefined when unset.
|
|
31
31
|
*/
|
|
32
32
|
contractGatesFile?: string;
|
|
33
|
+
/**
|
|
34
|
+
* `MODERN_SERVER_RENDER_RESOURCES` — `lazy` defers production server bundle
|
|
35
|
+
* imports to the first render request; anything else keeps eager warmup.
|
|
36
|
+
*/
|
|
37
|
+
renderResources: 'eager' | 'lazy';
|
|
38
|
+
/**
|
|
39
|
+
* Production with `MODERN_SERVER_IMMUTABLE_ASSETS=true`: release files never
|
|
40
|
+
* change while serving, so found files and the federation inventory are kept.
|
|
41
|
+
*/
|
|
42
|
+
immutableAssets: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* False only in production with `MODERN_SERVER_PRECOMPRESSED_ASSETS=false`:
|
|
45
|
+
* no `.br`/`.gz` variants are probed or served.
|
|
46
|
+
*/
|
|
47
|
+
precompressedAssets: boolean;
|
|
33
48
|
}
|
|
34
49
|
/**
|
|
35
50
|
* Parse the statically-known environment variables consumed by this package
|
|
@@ -16,7 +16,8 @@ export type ModuleFederationCssPluginOptions = {
|
|
|
16
16
|
* being pinned at boot: remote manifests change on every remote redeploy, and
|
|
17
17
|
* fetch failures must not pin an empty/partial list for the process lifetime.
|
|
18
18
|
*
|
|
19
|
-
* Existing plugin ordering places this after the native resource plugin
|
|
20
|
-
*
|
|
19
|
+
* Existing plugin ordering places this after the native resource plugin.
|
|
20
|
+
* Lazy loading keeps enrichment in the page-only resource prefix, before
|
|
21
|
+
* configured render middleware.
|
|
21
22
|
*/
|
|
22
23
|
export declare const injectModuleFederationCssPlugin: (options?: ModuleFederationCssPluginOptions) => ServerPlugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import type { ServerContext } from '@modern-js/server-core';
|
|
3
|
+
/** One server bundle import, published after it settles. */
|
|
4
|
+
export interface RenderBundleLoadEvent {
|
|
5
|
+
/** The serving application's output directory, when configured. */
|
|
6
|
+
readonly distDirectory: ServerContext['distDirectory'];
|
|
7
|
+
readonly filepath: string;
|
|
8
|
+
readonly durationMs: number;
|
|
9
|
+
readonly outcome: 'loaded' | 'failed';
|
|
10
|
+
/** The request path that triggered the import, or `<startup>` for warmup. */
|
|
11
|
+
readonly triggerPath: string;
|
|
12
|
+
}
|
|
13
|
+
/** One request through the server middlewares, traced from start to settle. */
|
|
14
|
+
export interface ServerRequestTrace {
|
|
15
|
+
/** The serving application's output directory, when configured. */
|
|
16
|
+
readonly distDirectory: ServerContext['distDirectory'];
|
|
17
|
+
/** The request path, without its query. */
|
|
18
|
+
readonly path: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Process-wide, so every server in a process publishes here regardless of
|
|
22
|
+
* which module format loaded this package. Node reports a subscriber's
|
|
23
|
+
* exception as an uncaught exception.
|
|
24
|
+
*/
|
|
25
|
+
export declare const renderBundleLoadChannel: diagnosticsChannel.Channel<RenderBundleLoadEvent, RenderBundleLoadEvent>;
|
|
26
|
+
/** Publishes `start` when a request enters and `asyncEnd` when it settles. */
|
|
27
|
+
export declare const serverRequestChannel: diagnosticsChannel.TracingChannel<ServerRequestTrace, ServerRequestTrace>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StaticAssetStat } from '@modern-js/server-core/node';
|
|
2
|
+
export declare const IMMUTABLE_ASSET_STAT_LIMIT = 8192;
|
|
3
|
+
/**
|
|
4
|
+
* File metadata for immutable releases. Only found regular files are kept, so
|
|
5
|
+
* a missing path is looked up again by the next request. The oldest entry is
|
|
6
|
+
* dropped once the limit is reached.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createImmutableAssetStat(): StaticAssetStat;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { type ServerStaticPluginOptions } from '@modern-js/server-core/node';
|
|
2
|
-
export
|
|
2
|
+
export type StaticExtensionPolicy = {
|
|
3
|
+
/** Release files never change while serving: keep found files and the federation inventory. */
|
|
4
|
+
immutableAssets: boolean;
|
|
5
|
+
/** Probe and serve `.br`/`.gz` variants. */
|
|
6
|
+
precompressedAssets: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function createStaticExtensionResponders({ immutableAssets, precompressedAssets, }: StaticExtensionPolicy): ServerStaticPluginOptions;
|
|
@@ -8,6 +8,6 @@ type ResolvePreCompressedAssetResult = {
|
|
|
8
8
|
hasVariant: boolean;
|
|
9
9
|
acceptable: boolean;
|
|
10
10
|
};
|
|
11
|
-
export declare const resolvePreCompressedAsset: (c: Parameters<Middleware>[0], filepath: string) => Promise<ResolvePreCompressedAssetResult>;
|
|
11
|
+
export declare const resolvePreCompressedAsset: (c: Parameters<Middleware>[0], filepath: string, probeVariants: boolean) => Promise<ResolvePreCompressedAssetResult>;
|
|
12
12
|
export declare const applyPreCompressedAssetHeaders: (c: Parameters<Middleware>[0], preCompressedAsset: ResolvePreCompressedAssetResult) => void;
|
|
13
13
|
export {};
|
package/dist/types-esm/env.d.mts
CHANGED
|
@@ -30,6 +30,21 @@ export interface ServerRuntimeExtensionsEnv {
|
|
|
30
30
|
* (absolute, or relative to the app directory). Undefined when unset.
|
|
31
31
|
*/
|
|
32
32
|
contractGatesFile?: string;
|
|
33
|
+
/**
|
|
34
|
+
* `MODERN_SERVER_RENDER_RESOURCES` — `lazy` defers production server bundle
|
|
35
|
+
* imports to the first render request; anything else keeps eager warmup.
|
|
36
|
+
*/
|
|
37
|
+
renderResources: 'eager' | 'lazy';
|
|
38
|
+
/**
|
|
39
|
+
* Production with `MODERN_SERVER_IMMUTABLE_ASSETS=true`: release files never
|
|
40
|
+
* change while serving, so found files and the federation inventory are kept.
|
|
41
|
+
*/
|
|
42
|
+
immutableAssets: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* False only in production with `MODERN_SERVER_PRECOMPRESSED_ASSETS=false`:
|
|
45
|
+
* no `.br`/`.gz` variants are probed or served.
|
|
46
|
+
*/
|
|
47
|
+
precompressedAssets: boolean;
|
|
33
48
|
}
|
|
34
49
|
/**
|
|
35
50
|
* Parse the statically-known environment variables consumed by this package
|
|
@@ -16,7 +16,8 @@ export type ModuleFederationCssPluginOptions = {
|
|
|
16
16
|
* being pinned at boot: remote manifests change on every remote redeploy, and
|
|
17
17
|
* fetch failures must not pin an empty/partial list for the process lifetime.
|
|
18
18
|
*
|
|
19
|
-
* Existing plugin ordering places this after the native resource plugin
|
|
20
|
-
*
|
|
19
|
+
* Existing plugin ordering places this after the native resource plugin.
|
|
20
|
+
* Lazy loading keeps enrichment in the page-only resource prefix, before
|
|
21
|
+
* configured render middleware.
|
|
21
22
|
*/
|
|
22
23
|
export declare const injectModuleFederationCssPlugin: (options?: ModuleFederationCssPluginOptions) => ServerPlugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import type { ServerContext } from '@modern-js/server-core';
|
|
3
|
+
/** One server bundle import, published after it settles. */
|
|
4
|
+
export interface RenderBundleLoadEvent {
|
|
5
|
+
/** The serving application's output directory, when configured. */
|
|
6
|
+
readonly distDirectory: ServerContext['distDirectory'];
|
|
7
|
+
readonly filepath: string;
|
|
8
|
+
readonly durationMs: number;
|
|
9
|
+
readonly outcome: 'loaded' | 'failed';
|
|
10
|
+
/** The request path that triggered the import, or `<startup>` for warmup. */
|
|
11
|
+
readonly triggerPath: string;
|
|
12
|
+
}
|
|
13
|
+
/** One request through the server middlewares, traced from start to settle. */
|
|
14
|
+
export interface ServerRequestTrace {
|
|
15
|
+
/** The serving application's output directory, when configured. */
|
|
16
|
+
readonly distDirectory: ServerContext['distDirectory'];
|
|
17
|
+
/** The request path, without its query. */
|
|
18
|
+
readonly path: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Process-wide, so every server in a process publishes here regardless of
|
|
22
|
+
* which module format loaded this package. Node reports a subscriber's
|
|
23
|
+
* exception as an uncaught exception.
|
|
24
|
+
*/
|
|
25
|
+
export declare const renderBundleLoadChannel: diagnosticsChannel.Channel<RenderBundleLoadEvent, RenderBundleLoadEvent>;
|
|
26
|
+
/** Publishes `start` when a request enters and `asyncEnd` when it settles. */
|
|
27
|
+
export declare const serverRequestChannel: diagnosticsChannel.TracingChannel<ServerRequestTrace, ServerRequestTrace>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StaticAssetStat } from '@modern-js/server-core/node';
|
|
2
|
+
export declare const IMMUTABLE_ASSET_STAT_LIMIT = 8192;
|
|
3
|
+
/**
|
|
4
|
+
* File metadata for immutable releases. Only found regular files are kept, so
|
|
5
|
+
* a missing path is looked up again by the next request. The oldest entry is
|
|
6
|
+
* dropped once the limit is reached.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createImmutableAssetStat(): StaticAssetStat;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { type ServerStaticPluginOptions } from '@modern-js/server-core/node';
|
|
2
|
-
export
|
|
2
|
+
export type StaticExtensionPolicy = {
|
|
3
|
+
/** Release files never change while serving: keep found files and the federation inventory. */
|
|
4
|
+
immutableAssets: boolean;
|
|
5
|
+
/** Probe and serve `.br`/`.gz` variants. */
|
|
6
|
+
precompressedAssets: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function createStaticExtensionResponders({ immutableAssets, precompressedAssets, }: StaticExtensionPolicy): ServerStaticPluginOptions;
|
|
@@ -8,6 +8,6 @@ type ResolvePreCompressedAssetResult = {
|
|
|
8
8
|
hasVariant: boolean;
|
|
9
9
|
acceptable: boolean;
|
|
10
10
|
};
|
|
11
|
-
export declare const resolvePreCompressedAsset: (c: Parameters<Middleware>[0], filepath: string) => Promise<ResolvePreCompressedAssetResult>;
|
|
11
|
+
export declare const resolvePreCompressedAsset: (c: Parameters<Middleware>[0], filepath: string, probeVariants: boolean) => Promise<ResolvePreCompressedAssetResult>;
|
|
12
12
|
export declare const applyPreCompressedAssetHeaders: (c: Parameters<Middleware>[0], preCompressedAsset: ResolvePreCompressedAssetResult) => void;
|
|
13
13
|
export {};
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.11.3-ultramodern.
|
|
20
|
+
"version": "3.11.3-ultramodern.11",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -116,6 +116,19 @@
|
|
|
116
116
|
},
|
|
117
117
|
"types": "./dist/types/static-serving/plugin.d.ts"
|
|
118
118
|
},
|
|
119
|
+
"./render-resources": {
|
|
120
|
+
"node": {
|
|
121
|
+
"import": {
|
|
122
|
+
"types": "./dist/types-esm/render-resources/index.d.mts",
|
|
123
|
+
"default": "./dist/esm-node/render-resources/index.mjs"
|
|
124
|
+
},
|
|
125
|
+
"require": {
|
|
126
|
+
"types": "./dist/types/render-resources/index.d.ts",
|
|
127
|
+
"default": "./dist/cjs/render-resources/index.js"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"types": "./dist/types/render-resources/index.d.ts"
|
|
131
|
+
},
|
|
119
132
|
"./server-plugin": {
|
|
120
133
|
"node": {
|
|
121
134
|
"import": {
|
|
@@ -197,6 +210,10 @@
|
|
|
197
210
|
"./dist/types/static-serving/plugin.d.ts",
|
|
198
211
|
"./src/static-serving/plugin.ts"
|
|
199
212
|
],
|
|
213
|
+
"render-resources": [
|
|
214
|
+
"./dist/types/render-resources/index.d.ts",
|
|
215
|
+
"./src/render-resources/index.ts"
|
|
216
|
+
],
|
|
200
217
|
"server-plugin": [
|
|
201
218
|
"./dist/types/serverPlugin.d.ts",
|
|
202
219
|
"./src/serverPlugin.ts"
|
|
@@ -216,25 +233,25 @@
|
|
|
216
233
|
}
|
|
217
234
|
},
|
|
218
235
|
"engines": {
|
|
219
|
-
"node": ">=26.
|
|
236
|
+
"node": ">=26.13.1"
|
|
220
237
|
},
|
|
221
238
|
"dependencies": {
|
|
222
|
-
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.11.3-ultramodern.
|
|
223
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.11.3-ultramodern.
|
|
224
|
-
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.11.3-ultramodern.
|
|
225
|
-
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.11.3-ultramodern.
|
|
226
|
-
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.11.3-ultramodern.
|
|
227
|
-
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.11.3-ultramodern.
|
|
228
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.11.3-ultramodern.
|
|
229
|
-
"@swc/helpers": "^0.5.
|
|
239
|
+
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.11.3-ultramodern.11",
|
|
240
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.11.3-ultramodern.11",
|
|
241
|
+
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.11.3-ultramodern.11",
|
|
242
|
+
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.11.3-ultramodern.11",
|
|
243
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.11.3-ultramodern.11",
|
|
244
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.11.3-ultramodern.11",
|
|
245
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.11.3-ultramodern.11",
|
|
246
|
+
"@swc/helpers": "^0.5.24",
|
|
230
247
|
"reflect-metadata": "^0.2.2"
|
|
231
248
|
},
|
|
232
249
|
"devDependencies": {
|
|
233
|
-
"@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.11.3-ultramodern.
|
|
234
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.11.3-ultramodern.
|
|
235
|
-
"@rslib/core": "1.0.
|
|
250
|
+
"@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.11.3-ultramodern.11",
|
|
251
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.11.3-ultramodern.11",
|
|
252
|
+
"@rslib/core": "1.0.7",
|
|
236
253
|
"@scripts/rstest-config": "2.66.7",
|
|
237
|
-
"@types/node": "^26.6.
|
|
254
|
+
"@types/node": "^26.6.6",
|
|
238
255
|
"esbuild": "^0.28.2",
|
|
239
256
|
"zod": "^4.6.7"
|
|
240
257
|
},
|
package/src/env.ts
CHANGED
|
@@ -32,6 +32,21 @@ export interface ServerRuntimeExtensionsEnv {
|
|
|
32
32
|
* (absolute, or relative to the app directory). Undefined when unset.
|
|
33
33
|
*/
|
|
34
34
|
contractGatesFile?: string;
|
|
35
|
+
/**
|
|
36
|
+
* `MODERN_SERVER_RENDER_RESOURCES` — `lazy` defers production server bundle
|
|
37
|
+
* imports to the first render request; anything else keeps eager warmup.
|
|
38
|
+
*/
|
|
39
|
+
renderResources: 'eager' | 'lazy';
|
|
40
|
+
/**
|
|
41
|
+
* Production with `MODERN_SERVER_IMMUTABLE_ASSETS=true`: release files never
|
|
42
|
+
* change while serving, so found files and the federation inventory are kept.
|
|
43
|
+
*/
|
|
44
|
+
immutableAssets: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* False only in production with `MODERN_SERVER_PRECOMPRESSED_ASSETS=false`:
|
|
47
|
+
* no `.br`/`.gz` variants are probed or served.
|
|
48
|
+
*/
|
|
49
|
+
precompressedAssets: boolean;
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
const readString = (value: string | undefined): string | undefined => {
|
|
@@ -53,11 +68,21 @@ export const parseServerRuntimeExtensionsEnv = (
|
|
|
53
68
|
): ServerRuntimeExtensionsEnv => {
|
|
54
69
|
const modernEnv = readString(env.MODERN_ENV);
|
|
55
70
|
const nodeEnv = readString(env.NODE_ENV);
|
|
71
|
+
const production = nodeEnv === 'production';
|
|
56
72
|
|
|
57
73
|
return {
|
|
58
74
|
modernEnv,
|
|
59
75
|
nodeEnv,
|
|
60
76
|
environmentName: modernEnv || nodeEnv || DEFAULT_ENVIRONMENT_NAME,
|
|
61
77
|
contractGatesFile: readString(env.MODERN_CONTRACT_GATES_FILE),
|
|
78
|
+
renderResources:
|
|
79
|
+
readString(env.MODERN_SERVER_RENDER_RESOURCES) === 'lazy'
|
|
80
|
+
? 'lazy'
|
|
81
|
+
: 'eager',
|
|
82
|
+
immutableAssets:
|
|
83
|
+
production && readString(env.MODERN_SERVER_IMMUTABLE_ASSETS) === 'true',
|
|
84
|
+
precompressedAssets:
|
|
85
|
+
!production ||
|
|
86
|
+
readString(env.MODERN_SERVER_PRECOMPRESSED_ASSETS) !== 'false',
|
|
62
87
|
};
|
|
63
88
|
};
|