bun-plugin-stx 0.2.177 → 0.2.179

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.
Files changed (2) hide show
  1. package/dist/serve.js +8 -3
  2. package/package.json +1 -1
package/dist/serve.js CHANGED
@@ -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 {
@@ -10118,7 +10121,7 @@ ${html}`;
10118
10121
  _server = bunServe({
10119
10122
  port: actualPort,
10120
10123
  reusePort: options.reusePort ?? false,
10121
- idleTimeout: 0,
10124
+ idleTimeout: production ? 30 : 0,
10122
10125
  async fetch(req, server) {
10123
10126
  return compressResponse(req, await (async () => {
10124
10127
  const url = new URL(req.url);
@@ -10194,6 +10197,8 @@ ${html}`;
10194
10197
  return new Response(null, { headers: corsHeaders });
10195
10198
  }
10196
10199
  if (path === "/_stx/hmr") {
10200
+ if (production)
10201
+ return new Response("Not Found", { status: 404, headers: { "Cache-Control": "no-store" } });
10197
10202
  let controller;
10198
10203
  let keepalive;
10199
10204
  const stream = new ReadableStream({
@@ -10238,7 +10243,7 @@ ${html}`;
10238
10243
  const etag = `"${Bun.hash(content2).toString(16)}"`;
10239
10244
  const headers = {
10240
10245
  "Content-Type": "application/javascript; charset=utf-8",
10241
- "Cache-Control": "public, max-age=0, must-revalidate",
10246
+ "Cache-Control": production ? "public, max-age=3600, stale-while-revalidate=86400" : "public, max-age=0, must-revalidate",
10242
10247
  ETag: etag,
10243
10248
  ...corsHeaders
10244
10249
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.177",
4
+ "version": "0.2.179",
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",