bun-plugin-stx 0.2.176 → 0.2.178
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 +1 -0
- package/dist/serve.js +24 -14
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
package/dist/serve.js
CHANGED
|
@@ -8721,7 +8721,7 @@ var defaultGeneratedDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "src/gener
|
|
|
8721
8721
|
import { BUILD_ID_HEADER, extractPageResponseStatus, findContainerRegion, getBuildId, mergeCrosswindConfig, stateDir, stateDirName } from "@stacksjs/stx";
|
|
8722
8722
|
import { buildCodeFrame, locateFailureLine } from "@stacksjs/stx/build-message";
|
|
8723
8723
|
import { clearBundleFailures, getBundleFailures } from "@stacksjs/stx/client-script-bundler";
|
|
8724
|
-
import { compressResponse, runPageAction as sharedRunPageAction } from "@stacksjs/stx";
|
|
8724
|
+
import { actionRedirectResponse, compressResponse, runPageAction as sharedRunPageAction } from "@stacksjs/stx";
|
|
8725
8725
|
var defaultStxModule = import("@stacksjs/stx");
|
|
8726
8726
|
var REACTIVE_TEMPLATE_DIRECTIVE_RE = /@for|:for|@if|:if|@else|:else|x-for|x-if|x-else/;
|
|
8727
8727
|
function extractServerScriptsFromTemplate(content) {
|
|
@@ -9051,6 +9051,7 @@ async function serve(options) {
|
|
|
9051
9051
|
checkEnv: false,
|
|
9052
9052
|
verbose: false
|
|
9053
9053
|
});
|
|
9054
|
+
const production = isProductionServe();
|
|
9054
9055
|
try {
|
|
9055
9056
|
const stxMod = options.stxModule ? options.stxModule : await defaultStxModule;
|
|
9056
9057
|
if (stxMod && typeof stxMod.resolveStxDirectories === "function")
|
|
@@ -9152,7 +9153,7 @@ function __stxOverlay(errs){
|
|
|
9152
9153
|
`;
|
|
9153
9154
|
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=new EventSource('/_stx/hmr');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()})}es.onmessage=function(e){try{var m=JSON.parse(e.data);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(_){}};es.onerror=function(){if(es.readyState===2){setTimeout(function(){location.reload()},400)}}})()</script>`;
|
|
9154
9155
|
function injectHmrClient(html) {
|
|
9155
|
-
if (!html)
|
|
9156
|
+
if (!html || production)
|
|
9156
9157
|
return html;
|
|
9157
9158
|
refreshBuildErrors();
|
|
9158
9159
|
const closeBody = html.lastIndexOf("</body>");
|
|
@@ -9195,6 +9196,8 @@ function __stxOverlay(errs){
|
|
|
9195
9196
|
}
|
|
9196
9197
|
const watchersStarted = new Set;
|
|
9197
9198
|
const startWatcher = (dir) => {
|
|
9199
|
+
if (production)
|
|
9200
|
+
return;
|
|
9198
9201
|
if (watchersStarted.has(dir))
|
|
9199
9202
|
return;
|
|
9200
9203
|
try {
|
|
@@ -9667,7 +9670,7 @@ function __stxOverlay(errs){
|
|
|
9667
9670
|
const userConfig = await crosswindUserConfigPromise;
|
|
9668
9671
|
const merged = mergeCrosswindConfig(cw.config, userConfig);
|
|
9669
9672
|
const generatorConfig = merged.config;
|
|
9670
|
-
const { includePreflight, minify } = merged;
|
|
9673
|
+
const { includePreflight, minify, tokenCSS } = merged;
|
|
9671
9674
|
for (const cls of merged.safelist)
|
|
9672
9675
|
classes.add(cls);
|
|
9673
9676
|
const cacheKey = [...classes].sort().join(" ");
|
|
@@ -9714,7 +9717,7 @@ function __stxOverlay(errs){
|
|
|
9714
9717
|
shortcutCSS += `@media (prefers-color-scheme: dark) { .dark .${name} { ${darkDecls.join(" ")} } }
|
|
9715
9718
|
`;
|
|
9716
9719
|
}
|
|
9717
|
-
const finalCss = baseCss + shortcutCSS;
|
|
9720
|
+
const finalCss = tokenCSS + baseCss + shortcutCSS;
|
|
9718
9721
|
crosswindCssCache.set(cacheKey, finalCss);
|
|
9719
9722
|
return finalCss;
|
|
9720
9723
|
} catch (error) {
|
|
@@ -9733,6 +9736,8 @@ function __stxOverlay(errs){
|
|
|
9733
9736
|
});
|
|
9734
9737
|
if (result.redirect)
|
|
9735
9738
|
reqCtx.actionRedirect = result.redirect;
|
|
9739
|
+
if (result.cookies && result.cookies.length > 0)
|
|
9740
|
+
reqCtx.actionCookies = result.cookies;
|
|
9736
9741
|
}
|
|
9737
9742
|
async function processTemplate(filePath, reqCtx) {
|
|
9738
9743
|
const content = await Bun.file(filePath).text();
|
|
@@ -10116,7 +10121,7 @@ ${html}`;
|
|
|
10116
10121
|
_server = bunServe({
|
|
10117
10122
|
port: actualPort,
|
|
10118
10123
|
reusePort: options.reusePort ?? false,
|
|
10119
|
-
idleTimeout: 0,
|
|
10124
|
+
idleTimeout: production ? 30 : 0,
|
|
10120
10125
|
async fetch(req, server) {
|
|
10121
10126
|
return compressResponse(req, await (async () => {
|
|
10122
10127
|
const url = new URL(req.url);
|
|
@@ -10192,6 +10197,8 @@ ${html}`;
|
|
|
10192
10197
|
return new Response(null, { headers: corsHeaders });
|
|
10193
10198
|
}
|
|
10194
10199
|
if (path === "/_stx/hmr") {
|
|
10200
|
+
if (production)
|
|
10201
|
+
return new Response("Not Found", { status: 404, headers: { "Cache-Control": "no-store" } });
|
|
10195
10202
|
let controller;
|
|
10196
10203
|
let keepalive;
|
|
10197
10204
|
const stream = new ReadableStream({
|
|
@@ -10437,10 +10444,10 @@ ${html}`;
|
|
|
10437
10444
|
}
|
|
10438
10445
|
const content = await getRoute(path, reqCtx);
|
|
10439
10446
|
if (reqCtx.actionRedirect) {
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
headers
|
|
10443
|
-
|
|
10447
|
+
const redirectResponse = actionRedirectResponse(reqCtx.actionRedirect, reqCtx.actionCookies);
|
|
10448
|
+
for (const [key, value] of Object.entries(corsHeaders))
|
|
10449
|
+
redirectResponse.headers.set(key, value);
|
|
10450
|
+
return redirectResponse;
|
|
10444
10451
|
}
|
|
10445
10452
|
if (content) {
|
|
10446
10453
|
const responseStatus = reqCtx.responseStatus ?? 200;
|
|
@@ -10591,13 +10598,16 @@ ${trailingPageScripts.join(`
|
|
|
10591
10598
|
} catch {}
|
|
10592
10599
|
}
|
|
10593
10600
|
}
|
|
10601
|
+
const pageHeaders = new Headers({
|
|
10602
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
10603
|
+
"Cache-Control": "no-store",
|
|
10604
|
+
...corsHeaders
|
|
10605
|
+
});
|
|
10606
|
+
for (const cookie of reqCtx.actionCookies ?? [])
|
|
10607
|
+
pageHeaders.append("Set-Cookie", cookie);
|
|
10594
10608
|
return new Response(injectHmrClient(cleaned), {
|
|
10595
10609
|
status: pageRenderFailed ? 500 : responseStatus,
|
|
10596
|
-
headers:
|
|
10597
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
10598
|
-
"Cache-Control": "no-store",
|
|
10599
|
-
...corsHeaders
|
|
10600
|
-
}
|
|
10610
|
+
headers: pageHeaders
|
|
10601
10611
|
});
|
|
10602
10612
|
}
|
|
10603
10613
|
if (!isStaticAssetPath(path)) {
|
package/package.json
CHANGED