bun-plugin-stx 0.2.319 → 0.2.321
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/serve.d.ts +14 -0
- package/dist/serve.js +37 -2
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
|
@@ -227,6 +227,17 @@ export declare function isRenderableCacheCandidate(html: string): boolean;
|
|
|
227
227
|
*/
|
|
228
228
|
export declare function usableErrorPage(rendered: string | null): string | null;
|
|
229
229
|
export declare function bundleBrowserAsset(entrypoint: string): Promise<Response>;
|
|
230
|
+
/**
|
|
231
|
+
* The bind budget from an option or config value. Anything that is not a
|
|
232
|
+
* finite, non-negative number falls back to the default rather than to
|
|
233
|
+
* "forever", since an unbounded wait is the failure the budget exists to stop.
|
|
234
|
+
*/
|
|
235
|
+
export declare function resolveImageWarmupBindBudget(value: unknown): number;
|
|
236
|
+
/**
|
|
237
|
+
* Whether `promise` settles within `ms`. It is not cancelled either way: the
|
|
238
|
+
* caller decides what to do with work that is still running.
|
|
239
|
+
*/
|
|
240
|
+
export declare function settleWithin(promise: Promise<unknown>, ms: number): Promise<boolean>;
|
|
230
241
|
/**
|
|
231
242
|
* Start the STX development server
|
|
232
243
|
* @param options Server options with patterns and port
|
|
@@ -256,6 +267,8 @@ export declare const ROUTE_PARAMS_PLACEHOLDER: '__STX_ROUTE_PARAMS__';
|
|
|
256
267
|
export declare const CSRF_COOKIE: 'X-CSRF-Token';
|
|
257
268
|
/** `/_stx/runtime.js`, `/_stx/router.<16 hex>.js`, … — the shared client scripts. */
|
|
258
269
|
export declare const SHARED_SCRIPT_PATH: unknown;
|
|
270
|
+
/** Default for `imageWarmupBindBudgetMs`: well inside ts-cloud's 180s bind window. */
|
|
271
|
+
export declare const DEFAULT_IMAGE_WARMUP_BIND_BUDGET_MS: unknown;
|
|
259
272
|
/**
|
|
260
273
|
* Build the candidate regexes for a dynamic route file (stacksjs/stx#1927).
|
|
261
274
|
*
|
|
@@ -314,6 +327,7 @@ export declare interface ServeOptions {
|
|
|
314
327
|
cssCacheLimit?: number
|
|
315
328
|
prewarmRenderCache?: boolean | number
|
|
316
329
|
imageWarmupGraceMs?: number
|
|
330
|
+
imageWarmupBindBudgetMs?: number
|
|
317
331
|
imageWarmup?: boolean | 'auto'
|
|
318
332
|
publicDir?: string
|
|
319
333
|
quiet?: boolean
|
package/dist/serve.js
CHANGED
|
@@ -9216,6 +9216,28 @@ async function bundleBrowserAsset(entrypoint) {
|
|
|
9216
9216
|
}
|
|
9217
9217
|
});
|
|
9218
9218
|
}
|
|
9219
|
+
var DEFAULT_IMAGE_WARMUP_BIND_BUDGET_MS = 45000;
|
|
9220
|
+
function resolveImageWarmupBindBudget(value) {
|
|
9221
|
+
const ms = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
|
|
9222
|
+
return typeof ms === "number" && Number.isFinite(ms) && ms >= 0 ? ms : DEFAULT_IMAGE_WARMUP_BIND_BUDGET_MS;
|
|
9223
|
+
}
|
|
9224
|
+
async function settleWithin(promise, ms) {
|
|
9225
|
+
let timer;
|
|
9226
|
+
const settled = promise.then(() => true, () => true);
|
|
9227
|
+
try {
|
|
9228
|
+
return await Promise.race([
|
|
9229
|
+
settled,
|
|
9230
|
+
new Promise((resolve13) => {
|
|
9231
|
+
timer = setTimeout(resolve13, ms, false);
|
|
9232
|
+
})
|
|
9233
|
+
]);
|
|
9234
|
+
} finally {
|
|
9235
|
+
clearTimeout(timer);
|
|
9236
|
+
}
|
|
9237
|
+
}
|
|
9238
|
+
function formatSeconds(ms) {
|
|
9239
|
+
return `${(ms / 1000).toFixed(ms < 1e4 ? 1 : 0)}s`;
|
|
9240
|
+
}
|
|
9219
9241
|
async function serve(options) {
|
|
9220
9242
|
const stxConfig = await loadConfig6({
|
|
9221
9243
|
name: "stx",
|
|
@@ -9260,6 +9282,7 @@ async function serve(options) {
|
|
|
9260
9282
|
let placeholdersAreReady = false;
|
|
9261
9283
|
const imageWarmupSetting = options.imageWarmup ?? stxConfig.imageWarmup ?? "auto";
|
|
9262
9284
|
const imageWarmupGraceMs = Math.max(0, options.imageWarmupGraceMs ?? 1000);
|
|
9285
|
+
const imageWarmupBindBudgetMs = resolveImageWarmupBindBudget(options.imageWarmupBindBudgetMs ?? stxConfig.imageWarmupBindBudgetMs);
|
|
9263
9286
|
function awaitImageWarmup() {
|
|
9264
9287
|
if (placeholdersAreReady || imageWarmupGraceMs === 0)
|
|
9265
9288
|
return;
|
|
@@ -10387,8 +10410,17 @@ ${block}`;
|
|
|
10387
10410
|
markPlaceholdersReady();
|
|
10388
10411
|
}
|
|
10389
10412
|
}
|
|
10390
|
-
if (production)
|
|
10391
|
-
|
|
10413
|
+
if (production) {
|
|
10414
|
+
const warmupStartedAt = performance.now();
|
|
10415
|
+
const warmup = runImageWarmup();
|
|
10416
|
+
const bound = await settleWithin(warmup, imageWarmupBindBudgetMs);
|
|
10417
|
+
if (!bound) {
|
|
10418
|
+
console.warn(`[stx] image warm-up still running after ${formatSeconds(imageWarmupBindBudgetMs)}; binding now and finishing it in the background. Images fall back to the original files until it completes. A cold image cache (first deploy, a cleared STX_IMAGE_CACHE_DIR, an encoder upgrade) is the usual cause; the next start reuses what this one encodes.`);
|
|
10419
|
+
warmup.then(() => {
|
|
10420
|
+
console.log(`[stx] image warm-up finished after ${formatSeconds(performance.now() - warmupStartedAt)}`);
|
|
10421
|
+
});
|
|
10422
|
+
}
|
|
10423
|
+
}
|
|
10392
10424
|
const portAutoIncrement = options.autoIncrementPort ?? true;
|
|
10393
10425
|
const maxPortAttempts = portAutoIncrement === false ? 1 : typeof portAutoIncrement === "number" ? Math.max(1, portAutoIncrement) : 10;
|
|
10394
10426
|
let actualPort = port;
|
|
@@ -11216,12 +11248,14 @@ export {
|
|
|
11216
11248
|
usableErrorPage,
|
|
11217
11249
|
staticCacheControl,
|
|
11218
11250
|
sharedScriptCacheControl,
|
|
11251
|
+
settleWithin,
|
|
11219
11252
|
serverScriptsReadParams,
|
|
11220
11253
|
serve,
|
|
11221
11254
|
serializeRouteParams,
|
|
11222
11255
|
routeSpecificity,
|
|
11223
11256
|
responseTakesCsrfCookie,
|
|
11224
11257
|
resolveServeOpenUrl,
|
|
11258
|
+
resolveImageWarmupBindBudget,
|
|
11225
11259
|
render404Page,
|
|
11226
11260
|
publicFileExists,
|
|
11227
11261
|
projectUsesImageBuiltins,
|
|
@@ -11241,5 +11275,6 @@ export {
|
|
|
11241
11275
|
boundedCache,
|
|
11242
11276
|
SHARED_SCRIPT_PATH,
|
|
11243
11277
|
ROUTE_PARAMS_PLACEHOLDER,
|
|
11278
|
+
DEFAULT_IMAGE_WARMUP_BIND_BUDGET_MS,
|
|
11244
11279
|
CSRF_COOKIE
|
|
11245
11280
|
};
|
package/package.json
CHANGED