@bleedingdev/modern-js-prod-server 3.2.0-ultramodern.99 → 3.4.0-ultramodern.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 (50) hide show
  1. package/dist/cjs/apply.js +14 -8
  2. package/dist/cjs/index.js +17 -13
  3. package/dist/cjs/netlify.js +9 -5
  4. package/dist/esm/apply.mjs +6 -4
  5. package/dist/esm/index.mjs +1 -1
  6. package/dist/esm-node/apply.mjs +6 -4
  7. package/dist/esm-node/index.mjs +1 -1
  8. package/dist/types/index.d.ts +5 -4
  9. package/dist/types/netlify.d.ts +1 -1
  10. package/package.json +11 -10
  11. package/dist/cjs/libs/contractGateAutopilot.js +0 -36
  12. package/dist/cjs/libs/loadConfig.js +0 -72
  13. package/dist/cjs/libs/metrics.js +0 -41
  14. package/dist/cjs/libs/render/index.js +0 -125
  15. package/dist/cjs/libs/render/ssr.js +0 -118
  16. package/dist/cjs/libs/render/utils.js +0 -72
  17. package/dist/cjs/libs/runtimeFallbackWorkerLane.js +0 -167
  18. package/dist/cjs/libs/telemetry.js +0 -87
  19. package/dist/cjs/server/index.js +0 -579
  20. package/dist/cjs/server/modernServer.js +0 -472
  21. package/dist/cjs/server/modernServerSplit.js +0 -38
  22. package/dist/cjs/utils.js +0 -38
  23. package/dist/esm/libs/contractGateAutopilot.mjs +0 -1
  24. package/dist/esm/libs/loadConfig.mjs +0 -22
  25. package/dist/esm/libs/metrics.mjs +0 -7
  26. package/dist/esm/libs/render/index.mjs +0 -81
  27. package/dist/esm/libs/render/ssr.mjs +0 -73
  28. package/dist/esm/libs/render/utils.mjs +0 -35
  29. package/dist/esm/libs/runtimeFallbackWorkerLane.mjs +0 -130
  30. package/dist/esm/libs/telemetry.mjs +0 -1
  31. package/dist/esm/rslib-runtime.mjs +0 -18
  32. package/dist/esm/server/index.mjs +0 -535
  33. package/dist/esm/server/modernServer.mjs +0 -419
  34. package/dist/esm/server/modernServerSplit.mjs +0 -4
  35. package/dist/esm/utils.mjs +0 -4
  36. package/dist/esm-node/libs/contractGateAutopilot.mjs +0 -2
  37. package/dist/esm-node/libs/loadConfig.mjs +0 -23
  38. package/dist/esm-node/libs/metrics.mjs +0 -8
  39. package/dist/esm-node/libs/render/index.mjs +0 -82
  40. package/dist/esm-node/libs/render/ssr.mjs +0 -75
  41. package/dist/esm-node/libs/render/utils.mjs +0 -36
  42. package/dist/esm-node/libs/runtimeFallbackWorkerLane.mjs +0 -131
  43. package/dist/esm-node/libs/telemetry.mjs +0 -2
  44. package/dist/esm-node/rslib-runtime.mjs +0 -19
  45. package/dist/esm-node/server/index.mjs +0 -536
  46. package/dist/esm-node/server/modernServer.mjs +0 -421
  47. package/dist/esm-node/server/modernServerSplit.mjs +0 -5
  48. package/dist/esm-node/utils.mjs +0 -5
  49. package/dist/types/libs/metrics.d.ts +0 -8
  50. package/dist/types/libs/telemetry.d.ts +0 -2
@@ -1,73 +0,0 @@
1
- import { LOADABLE_STATS_FILE, ROUTE_MANIFEST_FILE, SERVER_RENDER_FUNCTION_NAME, fs, mime } from "@modern-js/utils";
2
- import path from "path";
3
- import cache from "./cache";
4
- import { createLogger, createMetrics } from "./measure";
5
- import { injectServerData, injectServerDataStream } from "./utils.mjs";
6
- const render = async (ctx, renderOptions, runner)=>{
7
- const { urlPath, bundle, distDir, template, entryName, staticGenerate, enableUnsafeCtx = false, unsafeHeaders, nonce } = renderOptions;
8
- const bundleJS = path.join(distDir, bundle);
9
- const loadableUri = path.join(distDir, LOADABLE_STATS_FILE);
10
- const loadableStats = fs.existsSync(loadableUri) ? require(loadableUri) : '';
11
- const routesManifestUri = path.join(distDir, ROUTE_MANIFEST_FILE);
12
- const routeManifest = fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
13
- const context = {
14
- request: {
15
- baseUrl: urlPath,
16
- params: ctx.params,
17
- pathname: ctx.path,
18
- host: ctx.host,
19
- query: ctx.query,
20
- url: ctx.href,
21
- headers: ctx.headers
22
- },
23
- response: {
24
- setHeader: (key, value)=>ctx.res.setHeader(key, value),
25
- status: (code)=>{
26
- ctx.res.statusCode = code;
27
- },
28
- locals: ctx.res?.locals || {}
29
- },
30
- redirection: {},
31
- template,
32
- loadableStats,
33
- routeManifest,
34
- entryName,
35
- staticGenerate,
36
- logger: void 0,
37
- metrics: void 0,
38
- reporter: ctx.reporter,
39
- serverTiming: ctx.serverTiming,
40
- req: ctx.req,
41
- res: ctx.res,
42
- enableUnsafeCtx,
43
- unsafeHeaders,
44
- nonce
45
- };
46
- context.logger = createLogger(context, ctx.logger);
47
- context.metrics = createMetrics(context, ctx.metrics);
48
- runner.extendSSRContext(context);
49
- const bundleJSContent = await Promise.resolve(require(bundleJS));
50
- const serverRender = bundleJSContent[SERVER_RENDER_FUNCTION_NAME];
51
- const content = await cache(serverRender, ctx)(context);
52
- const { url, status = 302 } = context.redirection;
53
- if (url) return {
54
- content: url,
55
- contentType: '',
56
- statusCode: status,
57
- redirect: true
58
- };
59
- if ('string' == typeof content) return {
60
- content: injectServerData(content, ctx, {
61
- unsafeHeaders
62
- }),
63
- contentType: mime.contentType('html')
64
- };
65
- return {
66
- content: '',
67
- contentStream: injectServerDataStream(content, ctx, {
68
- unsafeHeaders
69
- }),
70
- contentType: mime.contentType('html')
71
- };
72
- };
73
- export { render };
@@ -1,35 +0,0 @@
1
- import { sanitizeSSRPayload } from "@modern-js/runtime-utils/node";
2
- import { Transform } from "stream";
3
- const SERVER_DATA_MARKUP = (payload)=>`<script type="application/json" id="__MODERN_SERVER_DATA__">${payload}</script>`;
4
- const injectIntoHead = (content, payload)=>{
5
- const scriptTag = SERVER_DATA_MARKUP(payload);
6
- if (content.includes('</head>')) return content.replace('</head>', `${scriptTag}</head>`);
7
- return `${scriptTag}${content}`;
8
- };
9
- const injectServerData = (content, context, options)=>{
10
- const serverData = sanitizeSSRPayload(context.serverData, {
11
- unsafeHeaders: options?.unsafeHeaders,
12
- treatRootAsHeaders: true
13
- }).payload;
14
- return injectIntoHead(content, JSON.stringify(serverData));
15
- };
16
- const injectServerDataStream = (content, context, options)=>{
17
- const serverData = sanitizeSSRPayload(context.serverData, {
18
- unsafeHeaders: options?.unsafeHeaders,
19
- treatRootAsHeaders: true
20
- }).payload;
21
- const payload = JSON.stringify(serverData);
22
- let buffer = '';
23
- const injector = new Transform({
24
- transform (chunk, _encoding, callback) {
25
- buffer += chunk.toString();
26
- callback();
27
- },
28
- flush (callback) {
29
- this.push(injectIntoHead(buffer, payload));
30
- callback();
31
- }
32
- });
33
- return content.pipe(injector);
34
- };
35
- export { injectServerData, injectServerDataStream };
@@ -1,130 +0,0 @@
1
- import { Worker } from "node:worker_threads";
2
- const DEFAULT_RUNTIME_FALLBACK_WORKER_TIMEOUT_MS = 250;
3
- const WORKER_SCRIPT = `
4
- const { parentPort, workerData } = require('node:worker_threads');
5
- const fs = require('node:fs/promises');
6
- const path = require('node:path');
7
-
8
- const isRecord = value => typeof value === 'object' && value !== null && !Array.isArray(value);
9
-
10
- const main = async () => {
11
- const now = Date.now();
12
- const snapshotPath = String(workerData.snapshotPath || '');
13
- const gateName = String(workerData.gateName || 'runtime-mf-fallback-health');
14
- const failureHoldMsRaw = Number(workerData.failureHoldMs);
15
- const failureHoldMs = Number.isFinite(failureHoldMsRaw) && failureHoldMsRaw > 0
16
- ? Math.floor(failureHoldMsRaw)
17
- : 300000;
18
- const schemaVersionRaw = Number(workerData.schemaVersion);
19
- const schemaVersion = Number.isFinite(schemaVersionRaw) ? schemaVersionRaw : 1;
20
- const payload = isRecord(workerData.payload) ? workerData.payload : {};
21
-
22
- let snapshot = {
23
- schemaVersion,
24
- updatedAt: now,
25
- gates: {},
26
- };
27
-
28
- try {
29
- const raw = await fs.readFile(snapshotPath, 'utf8');
30
- const parsed = JSON.parse(raw);
31
- if (isRecord(parsed)) {
32
- snapshot = {
33
- schemaVersion: typeof parsed.schemaVersion === 'number' ? parsed.schemaVersion : schemaVersion,
34
- updatedAt: typeof parsed.updatedAt === 'number' ? parsed.updatedAt : now,
35
- gates: isRecord(parsed.gates) ? parsed.gates : {},
36
- };
37
- }
38
- } catch (_error) {
39
- // start from empty snapshot when file does not exist or cannot be parsed
40
- }
41
-
42
- const reason = typeof payload.reason === 'string' ? payload.reason : 'runtime_fallback';
43
- const phase = typeof payload.phase === 'string' ? payload.phase : 'unknown';
44
- const appName = typeof payload.appName === 'string' ? payload.appName : 'unknown';
45
- const entry = typeof payload.entry === 'string' ? payload.entry : undefined;
46
-
47
- snapshot.schemaVersion = schemaVersion;
48
- snapshot.updatedAt = now;
49
- snapshot.gates = isRecord(snapshot.gates) ? snapshot.gates : {};
50
- snapshot.gates[gateName] = {
51
- passed: false,
52
- reason: \`runtime_fallback:\${reason} phase=\${phase} app=\${appName}\${entry ? \` entry=\${entry}\` : ''}\`,
53
- updatedAt: now,
54
- expiresAt: now + failureHoldMs,
55
- source: 'runtime-mf-fallback-signal',
56
- metadata: payload,
57
- };
58
-
59
- await fs.mkdir(path.dirname(snapshotPath), { recursive: true });
60
- await fs.writeFile(snapshotPath, JSON.stringify(snapshot, null, 2) + '\\n');
61
-
62
- return {
63
- ok: true,
64
- };
65
- };
66
-
67
- main()
68
- .then(result => {
69
- parentPort.postMessage(result);
70
- })
71
- .catch(error => {
72
- parentPort.postMessage({
73
- ok: false,
74
- error: error && error.message ? error.message : String(error),
75
- });
76
- });
77
- `;
78
- const normalizeErrorMessage = (error)=>{
79
- if (error instanceof Error) return error.message;
80
- return String(error);
81
- };
82
- const persistRuntimeFallbackContractGateInWorker = async (payload, config)=>{
83
- if (!config.enabled) return {
84
- ok: false,
85
- error: 'worker_lane_disabled'
86
- };
87
- return new Promise((resolve)=>{
88
- let settled = false;
89
- const worker = new Worker(WORKER_SCRIPT, {
90
- eval: true,
91
- workerData: payload
92
- });
93
- const finish = (result)=>{
94
- if (settled) return;
95
- settled = true;
96
- clearTimeout(timeoutId);
97
- worker.terminate().catch(()=>{});
98
- resolve(result);
99
- };
100
- const timeoutId = setTimeout(()=>{
101
- finish({
102
- ok: false,
103
- error: 'worker_lane_timeout'
104
- });
105
- }, Math.max(25, config.timeoutMs));
106
- worker.once('message', (message)=>{
107
- if (message && 'object' == typeof message && true === message.ok) return void finish({
108
- ok: true
109
- });
110
- finish({
111
- ok: false,
112
- error: message && 'object' == typeof message && 'error' in message ? String(message.error || 'worker_error') : 'worker_error'
113
- });
114
- });
115
- worker.once('error', (error)=>{
116
- finish({
117
- ok: false,
118
- error: normalizeErrorMessage(error)
119
- });
120
- });
121
- worker.once('exit', (code)=>{
122
- if (settled || 0 === code) return;
123
- finish({
124
- ok: false,
125
- error: `worker_lane_exit_${String(code)}`
126
- });
127
- });
128
- });
129
- };
130
- export { DEFAULT_RUNTIME_FALLBACK_WORKER_TIMEOUT_MS, persistRuntimeFallbackContractGateInWorker };
@@ -1 +0,0 @@
1
- export { DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, TelemetryCanaryOrchestrator, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, hasEnabledTelemetryExporters, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, parseRuntimeFallbackSignalPayloadFromRawBody, resolveRuntimeFallbackSignalEndpoint } from "@modern-js/server-core";
@@ -1,18 +0,0 @@
1
- var __webpack_modules__ = {};
2
- var __webpack_module_cache__ = {};
3
- function __webpack_require__(moduleId) {
4
- var cachedModule = __webpack_module_cache__[moduleId];
5
- if (void 0 !== cachedModule) return cachedModule.exports;
6
- var module = __webpack_module_cache__[moduleId] = {
7
- exports: {}
8
- };
9
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
10
- return module.exports;
11
- }
12
- __webpack_require__.m = __webpack_modules__;
13
- (()=>{
14
- __webpack_require__.add = function(modules) {
15
- Object.assign(__webpack_require__.m, modules);
16
- };
17
- })();
18
- export { __webpack_require__ };