bun-plugin-stx 0.2.617 → 0.2.619

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 CHANGED
@@ -239,6 +239,11 @@ export declare function bundleBrowserAsset(entrypoint: string): Promise<Response
239
239
  * "forever", since an unbounded wait is the failure the budget exists to stop.
240
240
  */
241
241
  export declare function resolveImageWarmupBindBudget(value: unknown): number;
242
+ /**
243
+ * Whether something already accepts connections on `port` on this machine:
244
+ * during a zero-downtime deploy, the release this one is replacing.
245
+ */
246
+ export declare function portIsServed(port: number, timeoutMs?: number): Promise<boolean>;
242
247
  /**
243
248
  * `pageWarmup` from an option or config value. Anything unusable falls back to
244
249
  * the default, and a path that is not a same-origin absolute path is dropped:
package/dist/serve.js CHANGED
@@ -9390,6 +9390,23 @@ function resolveImageWarmupBindBudget(value) {
9390
9390
  const ms = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
9391
9391
  return typeof ms === "number" && Number.isFinite(ms) && ms >= 0 ? ms : DEFAULT_IMAGE_WARMUP_BIND_BUDGET_MS;
9392
9392
  }
9393
+ async function portIsServed(port, timeoutMs = 500) {
9394
+ let timer;
9395
+ try {
9396
+ const socket = await Promise.race([
9397
+ Bun.connect({ hostname: "127.0.0.1", port, socket: { data() {}, error() {} } }),
9398
+ new Promise((_, reject) => {
9399
+ timer = setTimeout(() => reject(new Error("connect timed out")), timeoutMs);
9400
+ })
9401
+ ]);
9402
+ socket.end();
9403
+ return true;
9404
+ } catch {
9405
+ return false;
9406
+ } finally {
9407
+ clearTimeout(timer);
9408
+ }
9409
+ }
9393
9410
  var PAGE_WARMUP_HEADER = "x-stx-warmup";
9394
9411
  var DEFAULT_PAGE_WARMUP_BUDGET_MS = 60000;
9395
9412
  function resolvePageWarmup(value) {
@@ -11418,8 +11435,9 @@ ${trailingPageScripts.join(`
11418
11435
  }
11419
11436
  if (production && pageWarmup.enabled) {
11420
11437
  const warmupStartedAt = performance.now();
11438
+ const covered = options.reusePort === true && await portIsServed(port);
11421
11439
  const warming = warmPages();
11422
- const done = await settleWithin(warming, pageWarmup.budgetMs);
11440
+ const done = !covered || await settleWithin(warming, pageWarmup.budgetMs);
11423
11441
  if (!done) {
11424
11442
  console.warn(`[stx] page warm-up still running after ${formatSeconds(pageWarmup.budgetMs)}; binding now and finishing it in the background.`);
11425
11443
  }
@@ -11660,6 +11678,7 @@ export {
11660
11678
  orderDynamicRouteFiles,
11661
11679
  pageExcluder,
11662
11680
  pageRootOf,
11681
+ portIsServed,
11663
11682
  projectUsesImageBuiltins,
11664
11683
  publicFileExists,
11665
11684
  render404Page,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.617",
4
+ "version": "0.2.619",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "typecheck": "bun tsc --noEmit"
75
75
  },
76
76
  "dependencies": {
77
- "@stacksjs/stx": "0.2.617",
78
- "stx-router": "0.2.617"
77
+ "@stacksjs/stx": "0.2.619",
78
+ "stx-router": "0.2.619"
79
79
  }
80
80
  }