bun-plugin-stx 0.2.323 → 0.2.325
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.js +22 -6
- package/package.json +1 -1
package/dist/serve.js
CHANGED
|
@@ -9328,8 +9328,11 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9328
9328
|
const cssCssCache = boundedCache(options.cssCacheLimit ?? 512);
|
|
9329
9329
|
const hmrClients = new Set;
|
|
9330
9330
|
const hmrEncoder = new TextEncoder;
|
|
9331
|
+
let hmrVersion = 0;
|
|
9331
9332
|
function broadcastHmr(event) {
|
|
9332
|
-
|
|
9333
|
+
if (event.type !== "build-error")
|
|
9334
|
+
hmrVersion++;
|
|
9335
|
+
const payload = hmrEncoder.encode(`data: ${JSON.stringify({ ...event, version: hmrVersion })}
|
|
9333
9336
|
|
|
9334
9337
|
`);
|
|
9335
9338
|
for (const c of hmrClients) {
|
|
@@ -9375,16 +9378,17 @@ function __stxOverlay(errs){
|
|
|
9375
9378
|
el.innerHTML=h;
|
|
9376
9379
|
}
|
|
9377
9380
|
`;
|
|
9378
|
-
const HMR_CLIENT_SCRIPT = `<script data-stx-hmr>(()=>{if(window.__stxHmr)return;window.__stxHmr=1;${HMR_OVERLAY_JS}function bust(){var ls=document.querySelectorAll('link[rel="stylesheet"]');for(var i=0;i<ls.length;i++){var l=ls[i];var u=new URL(l.href,location.href);u.searchParams.set('v',Date.now().toString(36));l.href=u.toString()}}var es=
|
|
9381
|
+
const HMR_CLIENT_SCRIPT = `<script data-stx-hmr>(()=>{if(window.__stxHmr)return;window.__stxHmr=1;${HMR_OVERLAY_JS}function bust(){var ls=document.querySelectorAll('link[rel="stylesheet"]');for(var i=0;i<ls.length;i++){var l=ls[i];var u=new URL(l.href,location.href);u.searchParams.set('v',Date.now().toString(36));l.href=u.toString()}}var version=__STX_HMR_VERSION__,es=null;function swapFragment(){var r=window.stxRouter;if(r&&typeof r.refresh==='function'){try{return r.refresh().then(function(ok){if(!ok)location.reload()},function(){location.reload()})}catch(_){location.reload()}}else{location.reload()}}function reloadStores(){var s=window.stx;if(!s||typeof s.__hmrReplaceStores!=='function'){location.reload();return}fetch('/_stx/stores.js',{cache:'no-store'}).then(function(r){return r.ok?r.text():null}).then(function(code){if(code===null){location.reload();return}s.__hmrReplaceStores(code)}).catch(function(){location.reload()})}function connect(){var source=new EventSource('/_stx/hmr');es=source;source.onmessage=function(e){try{var m=JSON.parse(e.data);if(m.type==='connected'){if(typeof m.version==='number'&&m.version!==version)location.reload();return}if(typeof m.version==='number')version=m.version;if(m.type==='reload')location.reload();else if(m.type==='css')bust();else if(m.type==='fragment')swapFragment();else if(m.type==='store')reloadStores();else if(m.type==='build-error')__stxOverlay(m.errors)}catch(_){}};source.onerror=function(){if(es===source&&source.readyState===2){setTimeout(function(){location.reload()},400)}}}connect();addEventListener('pagehide',function(){if(es){es.close();es=null}});addEventListener('pageshow',function(e){if(e.persisted&&!es)connect()})})()</script>`;
|
|
9379
9382
|
function injectHmrClient(html) {
|
|
9380
9383
|
if (!html || production)
|
|
9381
9384
|
return html;
|
|
9382
9385
|
refreshBuildErrors();
|
|
9386
|
+
const client = HMR_CLIENT_SCRIPT.replace("__STX_HMR_VERSION__", String(hmrVersion));
|
|
9383
9387
|
const closeBody = html.lastIndexOf("</body>");
|
|
9384
9388
|
if (closeBody === -1) {
|
|
9385
|
-
return html +
|
|
9389
|
+
return html + client;
|
|
9386
9390
|
}
|
|
9387
|
-
return html.slice(0, closeBody) +
|
|
9391
|
+
return html.slice(0, closeBody) + client + html.slice(closeBody);
|
|
9388
9392
|
}
|
|
9389
9393
|
let currentBuildErrors = [];
|
|
9390
9394
|
async function refreshBuildErrors() {
|
|
@@ -10384,6 +10388,12 @@ ${block}`;
|
|
|
10384
10388
|
headers
|
|
10385
10389
|
});
|
|
10386
10390
|
}
|
|
10391
|
+
function reportImageWarmupFailure(stage, error) {
|
|
10392
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10393
|
+
console.warn(`\x1B[33m[stx]\x1B[0m ${stage} failed during the image warm-up: ${message}. <StxImage> serves the original files without them until a start where the warm-up succeeds.`);
|
|
10394
|
+
if (!production && error instanceof Error && error.stack)
|
|
10395
|
+
console.warn(`\x1B[2m${error.stack}\x1B[0m`);
|
|
10396
|
+
}
|
|
10387
10397
|
async function runImageWarmup() {
|
|
10388
10398
|
const imageWarmupEnabled = imageWarmupSetting === "auto" ? await projectUsesImageBuiltins(process19.cwd()) : imageWarmupSetting !== false;
|
|
10389
10399
|
if (!imageWarmupEnabled) {
|
|
@@ -10401,12 +10411,18 @@ ${block}`;
|
|
|
10401
10411
|
}),
|
|
10402
10412
|
stx.prepareImageDelivery(publicRoot, imageDeliveryOutputDir, { offThread: true })
|
|
10403
10413
|
]);
|
|
10414
|
+
if (placeholderResult.status === "rejected")
|
|
10415
|
+
reportImageWarmupFailure("image placeholders", placeholderResult.reason);
|
|
10416
|
+
if (deliveryResult.status === "rejected")
|
|
10417
|
+
reportImageWarmupFailure("responsive image variants", deliveryResult.reason);
|
|
10404
10418
|
const derived = placeholderResult.status === "fulfilled" ? placeholderResult.value : 0;
|
|
10405
10419
|
if (derived > 0 && !production)
|
|
10406
10420
|
console.log(`[stx] derived ${derived} image placeholder(s)`);
|
|
10407
10421
|
if (deliveryResult.status === "fulfilled" && deliveryResult.value.count > 0 && !production)
|
|
10408
10422
|
console.log(`[stx] optimized ${deliveryResult.value.count} image(s) for responsive delivery`);
|
|
10409
|
-
} catch
|
|
10423
|
+
} catch (error) {
|
|
10424
|
+
reportImageWarmupFailure("image warm-up", error);
|
|
10425
|
+
} finally {
|
|
10410
10426
|
placeholdersAreReady = true;
|
|
10411
10427
|
markPlaceholdersReady();
|
|
10412
10428
|
}
|
|
@@ -10519,7 +10535,7 @@ ${block}`;
|
|
|
10519
10535
|
start(c) {
|
|
10520
10536
|
controller = c;
|
|
10521
10537
|
hmrClients.add(c);
|
|
10522
|
-
c.enqueue(hmrEncoder.encode(`data: {"type":"connected"}
|
|
10538
|
+
c.enqueue(hmrEncoder.encode(`data: {"type":"connected","version":${hmrVersion}}
|
|
10523
10539
|
|
|
10524
10540
|
`));
|
|
10525
10541
|
if (currentBuildErrors.length > 0) {
|
package/package.json
CHANGED