@hyperframes/producer 0.9.90 → 0.9.92
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 +11 -4
- package/dist/compileWorker.js +3 -3
- package/dist/distributed.js +6 -5
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/index.js +225 -133
- package/dist/public-server.js +227 -133
- package/dist/server.d.ts +7 -2
- package/dist/services/hdrCompositor.d.ts +7 -0
- package/dist/services/renderOrchestrator.d.ts +7 -0
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -3056,6 +3056,7 @@ import {
|
|
|
3056
3056
|
import { readSync as readSync2 } from "fs";
|
|
3057
3057
|
import { join as join7 } from "path";
|
|
3058
3058
|
import {
|
|
3059
|
+
TRANSITIONS,
|
|
3059
3060
|
captureAlphaPng,
|
|
3060
3061
|
applyDomLayerMask,
|
|
3061
3062
|
removeDomLayerMask,
|
|
@@ -3092,6 +3093,31 @@ function isAffineMatrix(m) {
|
|
|
3092
3093
|
function resolveBlitOpacity(opacity) {
|
|
3093
3094
|
return opacity < OPAQUE_ALPHA_THRESHOLD ? opacity : void 0;
|
|
3094
3095
|
}
|
|
3096
|
+
var isTime = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
|
|
3097
|
+
function sanitizeTransitionMeta(raw, warn) {
|
|
3098
|
+
if (!Array.isArray(raw)) return [];
|
|
3099
|
+
const kept = [];
|
|
3100
|
+
for (const [index, entry] of raw.entries()) {
|
|
3101
|
+
if (typeof entry !== "object" || entry === null || !isTime(entry.time) || !isTime(entry.duration) || typeof entry.fromScene !== "string" || typeof entry.toScene !== "string") {
|
|
3102
|
+
warn("[Render] Ignoring malformed shader transition entry", { index });
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
const { shader } = entry;
|
|
3106
|
+
const known = typeof shader === "string" && Object.hasOwn(TRANSITIONS, shader);
|
|
3107
|
+
if (shader !== void 0 && !known) {
|
|
3108
|
+
warn("[Render] Unknown shader transition; using crossfade", { index });
|
|
3109
|
+
}
|
|
3110
|
+
kept.push({
|
|
3111
|
+
time: entry.time,
|
|
3112
|
+
duration: entry.duration,
|
|
3113
|
+
ease: typeof entry.ease === "string" ? entry.ease : "",
|
|
3114
|
+
fromScene: entry.fromScene,
|
|
3115
|
+
toScene: entry.toScene,
|
|
3116
|
+
...known ? { shader } : {}
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
return kept;
|
|
3120
|
+
}
|
|
3095
3121
|
function cropRgb48le(src, srcW, srcH, cropX, cropY, cropW, cropH) {
|
|
3096
3122
|
const dst = Buffer.alloc(cropW * cropH * RGB48_BYTES_PER_PIXEL);
|
|
3097
3123
|
for (let row = 0; row < cropH; row++) {
|
|
@@ -9491,7 +9517,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
9491
9517
|
}
|
|
9492
9518
|
let result = html;
|
|
9493
9519
|
for (const [url, relPath] of urlToRelPath) {
|
|
9494
|
-
result = result.replaceAll(`"${url}"`, `"${relPath}"`).replaceAll(`'${url}'`, `'${relPath}'`);
|
|
9520
|
+
result = result.replaceAll(`"${url}"`, () => `"${relPath}"`).replaceAll(`'${url}'`, () => `'${relPath}'`);
|
|
9495
9521
|
if (extraRewrite) result = extraRewrite(result, url, relPath);
|
|
9496
9522
|
}
|
|
9497
9523
|
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
@@ -9546,7 +9572,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir, assets) {
|
|
|
9546
9572
|
assets,
|
|
9547
9573
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
9548
9574
|
// replaceAll; this handles the unquoted url(https://..) form.
|
|
9549
|
-
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
9575
|
+
(h, url, rel) => h.replaceAll(`url(${url})`, () => `url(${rel})`)
|
|
9550
9576
|
);
|
|
9551
9577
|
}
|
|
9552
9578
|
function isGoogleFontsUrl(href) {
|
|
@@ -9716,7 +9742,7 @@ function localizeFontFaceUrls(html, downloadDir, assets) {
|
|
|
9716
9742
|
style,
|
|
9717
9743
|
css,
|
|
9718
9744
|
"</style>".length,
|
|
9719
|
-
css.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9745
|
+
css.replaceAll(`url(${url})`, () => `url("${relPath}")`)
|
|
9720
9746
|
)
|
|
9721
9747
|
)
|
|
9722
9748
|
);
|
|
@@ -13594,7 +13620,7 @@ function createHdrImageTransferCache(options = {}) {
|
|
|
13594
13620
|
// src/services/render/stages/captureHdrSequentialLoop.ts
|
|
13595
13621
|
import { join as join30 } from "node:path";
|
|
13596
13622
|
import {
|
|
13597
|
-
TRANSITIONS,
|
|
13623
|
+
TRANSITIONS as TRANSITIONS2,
|
|
13598
13624
|
crossfade
|
|
13599
13625
|
} from "@hyperframes/engine";
|
|
13600
13626
|
async function runSequentialLayeredFrameLoop(input) {
|
|
@@ -13692,7 +13718,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13692
13718
|
});
|
|
13693
13719
|
}
|
|
13694
13720
|
const shaderName = activeTransition.shader;
|
|
13695
|
-
const transitionFn = shaderName ?
|
|
13721
|
+
const transitionFn = shaderName ? TRANSITIONS2[shaderName] ?? crossfade : crossfade;
|
|
13696
13722
|
transitionFn(
|
|
13697
13723
|
transitionBuffers.bufferA,
|
|
13698
13724
|
transitionBuffers.bufferB,
|
|
@@ -13751,7 +13777,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13751
13777
|
// src/services/render/stages/captureHdrHybridLoop.ts
|
|
13752
13778
|
import { join as join32 } from "node:path";
|
|
13753
13779
|
import {
|
|
13754
|
-
TRANSITIONS as
|
|
13780
|
+
TRANSITIONS as TRANSITIONS3,
|
|
13755
13781
|
closeCaptureSession as closeCaptureSession6,
|
|
13756
13782
|
createCaptureSession as createCaptureSession6,
|
|
13757
13783
|
createFrameReorderBuffer as createFrameReorderBuffer2,
|
|
@@ -14036,6 +14062,15 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14036
14062
|
const workerRanges = distributeLayeredHybridFrameRanges(totalFrames, activeWorkerCount);
|
|
14037
14063
|
let framesWritten = 0;
|
|
14038
14064
|
const reorderBuffer = createFrameReorderBuffer2(0, totalFrames);
|
|
14065
|
+
let failure = null;
|
|
14066
|
+
const fail = (err) => {
|
|
14067
|
+
if (failure) return;
|
|
14068
|
+
failure = err instanceof Error ? err : new Error(String(err));
|
|
14069
|
+
reorderBuffer.abort(failure);
|
|
14070
|
+
};
|
|
14071
|
+
const throwIfFailed = () => {
|
|
14072
|
+
if (failure) throw failure;
|
|
14073
|
+
};
|
|
14039
14074
|
const writeEncoded = async (frameIdx, buf) => {
|
|
14040
14075
|
await reorderBuffer.waitForFrame(frameIdx);
|
|
14041
14076
|
const writeStart = Date.now();
|
|
@@ -14062,103 +14097,108 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14062
14097
|
if (!session || !canvas || !range) return;
|
|
14063
14098
|
const ringInFlight = ring ? ring.map(() => null) : [];
|
|
14064
14099
|
let nextRingIdx = 0;
|
|
14065
|
-
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
const
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14081
|
-
|
|
14082
|
-
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
|
|
14087
|
-
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
|
|
14101
|
-
|
|
14102
|
-
|
|
14103
|
-
|
|
14104
|
-
|
|
14105
|
-
|
|
14106
|
-
|
|
14107
|
-
|
|
14108
|
-
|
|
14109
|
-
|
|
14110
|
-
|
|
14111
|
-
|
|
14112
|
-
|
|
14113
|
-
|
|
14114
|
-
|
|
14115
|
-
|
|
14116
|
-
|
|
14117
|
-
|
|
14118
|
-
|
|
14119
|
-
|
|
14120
|
-
|
|
14121
|
-
|
|
14100
|
+
try {
|
|
14101
|
+
for (let i = range.start; i < range.end; i++) {
|
|
14102
|
+
throwIfFailed();
|
|
14103
|
+
assertNotAborted();
|
|
14104
|
+
const time = i * job.config.fps.den / job.config.fps.num;
|
|
14105
|
+
const activeTransition = transitionFramesSet.has(i) ? transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame) : void 0;
|
|
14106
|
+
if (activeTransition && ring) {
|
|
14107
|
+
const slot = nextRingIdx;
|
|
14108
|
+
nextRingIdx = (nextRingIdx + 1) % TRANSITION_RING_DEPTH;
|
|
14109
|
+
const prev = ringInFlight[slot];
|
|
14110
|
+
if (prev) await prev;
|
|
14111
|
+
throwIfFailed();
|
|
14112
|
+
const buffers = ring[slot];
|
|
14113
|
+
if (!buffers) continue;
|
|
14114
|
+
await captureTransitionFrameOnWorker({
|
|
14115
|
+
session,
|
|
14116
|
+
frameIdx: i,
|
|
14117
|
+
time,
|
|
14118
|
+
transition: activeTransition,
|
|
14119
|
+
buffers,
|
|
14120
|
+
nativeHdrIds,
|
|
14121
|
+
nativeHdrImageIds,
|
|
14122
|
+
sceneElements,
|
|
14123
|
+
hdrCompositeCtx,
|
|
14124
|
+
width,
|
|
14125
|
+
height,
|
|
14126
|
+
compositeTransfer,
|
|
14127
|
+
hdrTargetTransfer,
|
|
14128
|
+
hdrPerf,
|
|
14129
|
+
log
|
|
14130
|
+
});
|
|
14131
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (i - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
14132
|
+
const frameIdx = i;
|
|
14133
|
+
const shaderName = activeTransition.shader;
|
|
14134
|
+
const dispatch = (async () => {
|
|
14135
|
+
if (poolRef && shaderName) {
|
|
14136
|
+
const blendStart = Date.now();
|
|
14137
|
+
const result = await poolRef.run({
|
|
14138
|
+
shader: shaderName,
|
|
14139
|
+
bufferA: buffers.bufferA,
|
|
14140
|
+
bufferB: buffers.bufferB,
|
|
14141
|
+
output: buffers.output,
|
|
14142
|
+
width,
|
|
14143
|
+
height,
|
|
14144
|
+
progress
|
|
14145
|
+
});
|
|
14146
|
+
buffers.bufferA = result.bufferA;
|
|
14147
|
+
buffers.bufferB = result.bufferB;
|
|
14148
|
+
buffers.output = result.output;
|
|
14149
|
+
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14150
|
+
} else {
|
|
14151
|
+
const transitionFn = shaderName ? TRANSITIONS3[shaderName] ?? crossfade2 : crossfade2;
|
|
14152
|
+
const blendStart = Date.now();
|
|
14153
|
+
transitionFn(
|
|
14154
|
+
buffers.bufferA,
|
|
14155
|
+
buffers.bufferB,
|
|
14156
|
+
buffers.output,
|
|
14157
|
+
width,
|
|
14158
|
+
height,
|
|
14159
|
+
progress
|
|
14160
|
+
);
|
|
14161
|
+
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14162
|
+
}
|
|
14163
|
+
await writeEncoded(frameIdx, buffers.output);
|
|
14164
|
+
})();
|
|
14165
|
+
ringInFlight[slot] = dispatch.then(() => void 0, fail);
|
|
14166
|
+
} else {
|
|
14167
|
+
const stackingInfo = await seekInjectAndQueryStacking(
|
|
14168
|
+
session.page,
|
|
14169
|
+
time,
|
|
14170
|
+
session.onBeforeCapture,
|
|
14171
|
+
nativeHdrIds,
|
|
14172
|
+
hdrPerf,
|
|
14173
|
+
"frameSeekMs",
|
|
14174
|
+
"frameInjectMs",
|
|
14175
|
+
"stackingQueryMs"
|
|
14176
|
+
);
|
|
14177
|
+
canvas.fill(0);
|
|
14178
|
+
const wctx = { ...hdrCompositeCtx, domSession: session };
|
|
14179
|
+
await timeHdrPhaseAsync(
|
|
14180
|
+
hdrPerf,
|
|
14181
|
+
"normalCompositeMs",
|
|
14182
|
+
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
|
|
14183
|
+
);
|
|
14184
|
+
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14185
|
+
writeFileExclusiveSync(
|
|
14186
|
+
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14187
|
+
canvas
|
|
14122
14188
|
);
|
|
14123
|
-
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14124
14189
|
}
|
|
14125
|
-
await writeEncoded(
|
|
14126
|
-
})();
|
|
14127
|
-
ringInFlight[slot] = dispatch.catch((err) => {
|
|
14128
|
-
throw err instanceof Error ? err : new Error(String(err));
|
|
14129
|
-
});
|
|
14130
|
-
} else {
|
|
14131
|
-
const stackingInfo = await seekInjectAndQueryStacking(
|
|
14132
|
-
session.page,
|
|
14133
|
-
time,
|
|
14134
|
-
session.onBeforeCapture,
|
|
14135
|
-
nativeHdrIds,
|
|
14136
|
-
hdrPerf,
|
|
14137
|
-
"frameSeekMs",
|
|
14138
|
-
"frameInjectMs",
|
|
14139
|
-
"stackingQueryMs"
|
|
14140
|
-
);
|
|
14141
|
-
canvas.fill(0);
|
|
14142
|
-
const wctx = { ...hdrCompositeCtx, domSession: session };
|
|
14143
|
-
await timeHdrPhaseAsync(
|
|
14144
|
-
hdrPerf,
|
|
14145
|
-
"normalCompositeMs",
|
|
14146
|
-
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
|
|
14147
|
-
);
|
|
14148
|
-
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14149
|
-
writeFileExclusiveSync(
|
|
14150
|
-
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14151
|
-
canvas
|
|
14152
|
-
);
|
|
14190
|
+
await writeEncoded(i, canvas);
|
|
14153
14191
|
}
|
|
14154
|
-
await writeEncoded(i, canvas);
|
|
14155
14192
|
}
|
|
14193
|
+
} catch (err) {
|
|
14194
|
+
fail(err);
|
|
14195
|
+
} finally {
|
|
14196
|
+
await Promise.all(ringInFlight);
|
|
14156
14197
|
}
|
|
14157
|
-
|
|
14158
|
-
if (pending) await pending;
|
|
14159
|
-
}
|
|
14198
|
+
throwIfFailed();
|
|
14160
14199
|
};
|
|
14161
|
-
await Promise.
|
|
14200
|
+
await Promise.allSettled(sessions.map((_, w) => workerTaskOf(w)));
|
|
14201
|
+
throwIfFailed();
|
|
14162
14202
|
await reorderBuffer.waitForAllDone();
|
|
14163
14203
|
} finally {
|
|
14164
14204
|
for (const s of workerSessions) {
|
|
@@ -14250,23 +14290,27 @@ async function runCaptureHdrStage(input) {
|
|
|
14250
14290
|
assertNotAborted();
|
|
14251
14291
|
lastBrowserConsole = domSession.browserConsoleBuffer;
|
|
14252
14292
|
await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
|
|
14253
|
-
const transitionMeta =
|
|
14254
|
-
|
|
14255
|
-
|
|
14256
|
-
|
|
14257
|
-
|
|
14258
|
-
|
|
14259
|
-
|
|
14260
|
-
|
|
14261
|
-
const
|
|
14262
|
-
const
|
|
14263
|
-
|
|
14264
|
-
|
|
14293
|
+
const transitionMeta = sanitizeTransitionMeta(
|
|
14294
|
+
await domSession.page.evaluate(() => window.__hf?.transitions ?? []),
|
|
14295
|
+
(message, meta) => log.warn(message, meta)
|
|
14296
|
+
);
|
|
14297
|
+
const sceneElements = Object.assign(
|
|
14298
|
+
/* @__PURE__ */ Object.create(null),
|
|
14299
|
+
await domSession.page.evaluate(() => {
|
|
14300
|
+
const scenes = document.querySelectorAll(".scene");
|
|
14301
|
+
const map = {};
|
|
14302
|
+
for (const scene of scenes) {
|
|
14303
|
+
if (!scene.id) continue;
|
|
14304
|
+
const ids = /* @__PURE__ */ new Set([scene.id]);
|
|
14305
|
+
const els = scene.querySelectorAll("[id]");
|
|
14306
|
+
for (const el of els) {
|
|
14307
|
+
if (el.id) ids.add(el.id);
|
|
14308
|
+
}
|
|
14309
|
+
map[scene.id] = Array.from(ids);
|
|
14265
14310
|
}
|
|
14266
|
-
map
|
|
14267
|
-
}
|
|
14268
|
-
|
|
14269
|
-
});
|
|
14311
|
+
return map;
|
|
14312
|
+
})
|
|
14313
|
+
);
|
|
14270
14314
|
const fpsDecimal = fpsToNumber7(job.config.fps);
|
|
14271
14315
|
const transitionRanges = transitionMeta.map((t) => ({
|
|
14272
14316
|
...t,
|
|
@@ -15161,6 +15205,13 @@ var RenderCancelledError = class extends Error {
|
|
|
15161
15205
|
this.reason = reason;
|
|
15162
15206
|
}
|
|
15163
15207
|
};
|
|
15208
|
+
var EscapedRejectionError = class extends Error {
|
|
15209
|
+
constructor(cause) {
|
|
15210
|
+
super(cause.message, { cause });
|
|
15211
|
+
Object.assign(this, cause);
|
|
15212
|
+
this.name = cause.name;
|
|
15213
|
+
}
|
|
15214
|
+
};
|
|
15164
15215
|
function createRenderFileLogger(logPath, base = defaultLogger) {
|
|
15165
15216
|
const write = (prefix, args) => {
|
|
15166
15217
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -18125,11 +18176,12 @@ async function executeRenderPipeline(input) {
|
|
|
18125
18176
|
framesRendered: job.framesRendered ?? 0,
|
|
18126
18177
|
error: caught
|
|
18127
18178
|
});
|
|
18179
|
+
const escapedRejection = executionSignal.reason instanceof EscapedRejectionError ? executionSignal.reason : void 0;
|
|
18128
18180
|
const error = surfaceScriptFailure(
|
|
18129
|
-
tooSlowError ?? audioFailure ?? pageNeverReady ?? caught,
|
|
18181
|
+
tooSlowError ?? audioFailure ?? escapedRejection ?? pageNeverReady ?? caught,
|
|
18130
18182
|
job
|
|
18131
18183
|
);
|
|
18132
|
-
if (!tooSlowError && !audioFailure && (error instanceof RenderCancelledError || executionSignal.aborted)) {
|
|
18184
|
+
if (!tooSlowError && !audioFailure && !escapedRejection && (error instanceof RenderCancelledError || executionSignal.aborted)) {
|
|
18133
18185
|
job.error = error instanceof Error ? error.message : "render_cancelled";
|
|
18134
18186
|
updateJobStatus(job, "cancelled", "Render cancelled", job.progress, onProgress);
|
|
18135
18187
|
await eventPublisher.flush();
|
|
@@ -23254,8 +23306,9 @@ import {
|
|
|
23254
23306
|
rmSync as rmSync20,
|
|
23255
23307
|
createReadStream as createReadStream6
|
|
23256
23308
|
} from "node:fs";
|
|
23309
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23257
23310
|
import { basename as basename9, resolve as resolve13, dirname as dirname22, join as join52 } from "node:path";
|
|
23258
|
-
import { tmpdir as tmpdir6 } from "node:os";
|
|
23311
|
+
import { homedir, tmpdir as tmpdir6 } from "node:os";
|
|
23259
23312
|
import { parseArgs } from "node:util";
|
|
23260
23313
|
import { isIP } from "node:net";
|
|
23261
23314
|
import crypto from "node:crypto";
|
|
@@ -24149,11 +24202,16 @@ function createRenderHandlers(options = {}) {
|
|
|
24149
24202
|
quality: input.quality
|
|
24150
24203
|
});
|
|
24151
24204
|
try {
|
|
24152
|
-
await
|
|
24153
|
-
|
|
24154
|
-
|
|
24155
|
-
|
|
24156
|
-
|
|
24205
|
+
await runInRenderScope(
|
|
24206
|
+
requestId,
|
|
24207
|
+
new AbortController(),
|
|
24208
|
+
(signal) => executeRenderJob(
|
|
24209
|
+
job,
|
|
24210
|
+
input.projectDir,
|
|
24211
|
+
absoluteOutputPath,
|
|
24212
|
+
createBlockingProgressReporter(log, requestId),
|
|
24213
|
+
signal
|
|
24214
|
+
)
|
|
24157
24215
|
);
|
|
24158
24216
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
24159
24217
|
const durationMs = Date.now() - t0;
|
|
@@ -24250,12 +24308,10 @@ function createRenderHandlers(options = {}) {
|
|
|
24250
24308
|
}, SSE_KEEPALIVE_MS);
|
|
24251
24309
|
const release = await renderSemaphore.acquire();
|
|
24252
24310
|
try {
|
|
24253
|
-
await
|
|
24254
|
-
|
|
24255
|
-
|
|
24256
|
-
absoluteOutputPath,
|
|
24257
|
-
reportProgress,
|
|
24258
|
-
abortController.signal
|
|
24311
|
+
await runInRenderScope(
|
|
24312
|
+
requestId,
|
|
24313
|
+
abortController,
|
|
24314
|
+
(signal) => executeRenderJob(job, input.projectDir, absoluteOutputPath, reportProgress, signal)
|
|
24259
24315
|
).finally(release);
|
|
24260
24316
|
clearInterval(keepalive);
|
|
24261
24317
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
@@ -24423,19 +24479,53 @@ function createProducerApp(options = {}) {
|
|
|
24423
24479
|
app.get("/outputs/:token", handlers.outputs);
|
|
24424
24480
|
return app;
|
|
24425
24481
|
}
|
|
24426
|
-
|
|
24427
|
-
|
|
24428
|
-
const
|
|
24429
|
-
|
|
24430
|
-
|
|
24482
|
+
var renderScope = new AsyncLocalStorage();
|
|
24483
|
+
function runInRenderScope(requestId, abortController, run) {
|
|
24484
|
+
const fail = (err) => abortController.abort(new EscapedRejectionError(err));
|
|
24485
|
+
return renderScope.run({ requestId, fail }, () => run(abortController.signal));
|
|
24486
|
+
}
|
|
24487
|
+
function onEscapedRejection(reason, log) {
|
|
24488
|
+
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
24489
|
+
const scope = renderScope.getStore();
|
|
24490
|
+
log.error("Unhandled promise rejection", {
|
|
24491
|
+
requestId: scope?.requestId ?? null,
|
|
24492
|
+
error: err.message,
|
|
24493
|
+
stack: err.stack
|
|
24494
|
+
});
|
|
24495
|
+
scope?.fail(err);
|
|
24496
|
+
}
|
|
24497
|
+
function serverAuth(options, hostname2, port) {
|
|
24498
|
+
const configured = resolveAuthToken(options);
|
|
24499
|
+
if (configured) return { token: configured };
|
|
24500
|
+
if (!isLoopbackHostname(hostname2)) {
|
|
24431
24501
|
throw new Error(
|
|
24432
24502
|
`Refusing to listen on ${hostname2} without an auth token. Set authToken or PRODUCER_AUTH_TOKEN, or listen on a loopback address.`
|
|
24433
24503
|
);
|
|
24434
24504
|
}
|
|
24435
|
-
const
|
|
24505
|
+
const file = resolve13(
|
|
24506
|
+
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join52(homedir(), ".hyperframes", "producer", `${port}.token`)
|
|
24507
|
+
);
|
|
24508
|
+
const token = crypto.randomBytes(32).toString("base64url");
|
|
24509
|
+
mkdirSync21(dirname22(file), { recursive: true, mode: 448 });
|
|
24510
|
+
rmSync20(file, { force: true });
|
|
24511
|
+
writeFileSync13(file, `${token}
|
|
24512
|
+
`, { flag: "wx", mode: 384 });
|
|
24513
|
+
return { token, generatedFile: file };
|
|
24514
|
+
}
|
|
24515
|
+
function startServer(options = {}) {
|
|
24516
|
+
const port = options.port ?? parseInt(process.env.PRODUCER_PORT ?? "9847", 10);
|
|
24517
|
+
const hostname2 = options.hostname || process.env.PRODUCER_HOST || "127.0.0.1";
|
|
24518
|
+
const log = options.logger ?? defaultLogger;
|
|
24519
|
+
const auth = serverAuth(options, hostname2, port);
|
|
24520
|
+
const app = createProducerApp({ ...options, authToken: auth.token });
|
|
24436
24521
|
const server = serve2({ fetch: app.fetch, port, hostname: hostname2 }, (info) => {
|
|
24437
24522
|
const address = info.family === "IPv6" ? `[${info.address}]` : info.address;
|
|
24438
24523
|
log.info(`Listening on http://${address}:${info.port}`);
|
|
24524
|
+
if (auth.generatedFile) {
|
|
24525
|
+
log.info(
|
|
24526
|
+
`No auth token was set, so this run made one: send "Authorization: Bearer <token>" with the token in ${auth.generatedFile}`
|
|
24527
|
+
);
|
|
24528
|
+
}
|
|
24439
24529
|
});
|
|
24440
24530
|
server.setTimeout(0);
|
|
24441
24531
|
server.requestTimeout = 0;
|
|
@@ -24446,6 +24536,7 @@ function startServer(options = {}) {
|
|
|
24446
24536
|
});
|
|
24447
24537
|
async function shutdown(signal) {
|
|
24448
24538
|
log.info(`Received ${signal}, shutting down`);
|
|
24539
|
+
if (auth.generatedFile) rmSync20(auth.generatedFile, { force: true });
|
|
24449
24540
|
const { drainBrowserPool } = await import("@hyperframes/engine");
|
|
24450
24541
|
await drainBrowserPool().catch(() => {
|
|
24451
24542
|
});
|
|
@@ -24467,6 +24558,7 @@ function startServer(options = {}) {
|
|
|
24467
24558
|
}, 3e4).unref();
|
|
24468
24559
|
}
|
|
24469
24560
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
24561
|
+
process.on("unhandledRejection", (reason) => onEscapedRejection(reason, log));
|
|
24470
24562
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
24471
24563
|
return server;
|
|
24472
24564
|
}
|