bun-plugin-stx 0.2.140 → 0.2.141
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 +4 -0
- package/dist/serve.js +44 -11
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
|
@@ -114,6 +114,10 @@ export declare interface ServeOptions {
|
|
|
114
114
|
componentsDir?: string
|
|
115
115
|
layoutsDir?: string
|
|
116
116
|
partialsDir?: string
|
|
117
|
+
watchDirs?: string[]
|
|
118
|
+
renderCache?: boolean
|
|
119
|
+
renderCacheVary?: 'request' | 'source'
|
|
120
|
+
prewarmRenderCache?: boolean | number
|
|
117
121
|
publicDir?: string
|
|
118
122
|
quiet?: boolean
|
|
119
123
|
autoIncrementPort?: boolean | number
|
package/dist/serve.js
CHANGED
|
@@ -8995,7 +8995,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
8995
8995
|
let discoveredPagePaths = null;
|
|
8996
8996
|
let assetsInitialized = false;
|
|
8997
8997
|
const htmlCache = new Map;
|
|
8998
|
-
const ENABLE_HTML_CACHE =
|
|
8998
|
+
const ENABLE_HTML_CACHE = options.renderCache === true;
|
|
8999
|
+
const RENDER_CACHE_VARY = options.renderCacheVary ?? "request";
|
|
8999
9000
|
const crosswindCssCache = new Map;
|
|
9000
9001
|
const hmrClients = new Set;
|
|
9001
9002
|
const hmrEncoder = new TextEncoder;
|
|
@@ -9031,12 +9032,15 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9031
9032
|
return;
|
|
9032
9033
|
const f = String(filename);
|
|
9033
9034
|
const isStxLike = f.endsWith(".stx") || f.endsWith(".md") || f.endsWith(".html");
|
|
9035
|
+
const isCode = f.endsWith(".js") || f.endsWith(".ts") || f.endsWith(".tsx") || f.endsWith(".mts") || f.endsWith(".cts");
|
|
9036
|
+
const isData = f.endsWith(".json");
|
|
9034
9037
|
const isCss = f.endsWith(".css");
|
|
9035
|
-
const isAsset = isCss ||
|
|
9036
|
-
if (!isStxLike && !isAsset)
|
|
9038
|
+
const isAsset = isCss || isCode || f.endsWith(".jpg") || f.endsWith(".jpeg") || f.endsWith(".png") || f.endsWith(".gif") || f.endsWith(".svg") || f.endsWith(".webp") || f.endsWith(".avif") || f.endsWith(".woff") || f.endsWith(".woff2") || f.endsWith(".ttf") || f.endsWith(".otf");
|
|
9039
|
+
if (!isStxLike && !isAsset && !isData)
|
|
9037
9040
|
return;
|
|
9038
|
-
if (isStxLike) {
|
|
9039
|
-
|
|
9041
|
+
if (isStxLike || isCode || isData) {
|
|
9042
|
+
if (isStxLike)
|
|
9043
|
+
sourceFiles = null;
|
|
9040
9044
|
routes.clear();
|
|
9041
9045
|
htmlCache.clear();
|
|
9042
9046
|
crosswindCssCache.clear();
|
|
@@ -9053,7 +9057,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9053
9057
|
layoutsDir,
|
|
9054
9058
|
partialsDir,
|
|
9055
9059
|
publicDir,
|
|
9056
|
-
"resources/assets"
|
|
9060
|
+
"resources/assets",
|
|
9061
|
+
...options.watchDirs ?? []
|
|
9057
9062
|
]) {
|
|
9058
9063
|
if (!dir)
|
|
9059
9064
|
continue;
|
|
@@ -9209,14 +9214,24 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9209
9214
|
context.__stxServeContext = full;
|
|
9210
9215
|
globalThis.__stxServeContext = full;
|
|
9211
9216
|
}
|
|
9212
|
-
function htmlCacheKey(filePath) {
|
|
9217
|
+
function htmlCacheKey(filePath, reqCtx) {
|
|
9218
|
+
if (RENDER_CACHE_VARY === "source")
|
|
9219
|
+
return filePath;
|
|
9220
|
+
if (reqCtx) {
|
|
9221
|
+
try {
|
|
9222
|
+
return `${filePath}\x00${JSON.stringify(reqCtx)}`;
|
|
9223
|
+
} catch {
|
|
9224
|
+
return `${filePath}\x00uncacheable:${crypto.randomUUID()}`;
|
|
9225
|
+
}
|
|
9226
|
+
}
|
|
9213
9227
|
const loc = i18nConfig ? activeServeLocale ?? i18nConfig.defaultLocale : "";
|
|
9214
9228
|
const search = activeServeSearch || "";
|
|
9215
9229
|
const host = activeServeHost || "";
|
|
9216
9230
|
const cookies = activeServeCookieHeader;
|
|
9217
|
-
|
|
9231
|
+
const ip = activeServeIp;
|
|
9232
|
+
if (!loc && !search && !host && !cookies && !ip)
|
|
9218
9233
|
return filePath;
|
|
9219
|
-
return `${filePath}\x00${loc}\x00${search}\x00${host}\x00${cookies}`;
|
|
9234
|
+
return `${filePath}\x00${loc}\x00${search}\x00${host}\x00${cookies}\x00${ip}`;
|
|
9220
9235
|
}
|
|
9221
9236
|
const builtInMiddleware = authConfig === null ? {} : {
|
|
9222
9237
|
auth: (_req, ctx) => {
|
|
@@ -9517,7 +9532,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9517
9532
|
reqCtx.responseStatus = extractPageResponseStatus(content) ?? 200;
|
|
9518
9533
|
const skipCacheHint = /(?:^|[^\w$])__stx_skip_cache\s*=\s*true/.test(content);
|
|
9519
9534
|
if (ENABLE_HTML_CACHE && !skipCacheHint) {
|
|
9520
|
-
const cacheKey = htmlCacheKey(filePath);
|
|
9535
|
+
const cacheKey = htmlCacheKey(filePath, reqCtx);
|
|
9521
9536
|
const cachedEntry = htmlCache.get(cacheKey);
|
|
9522
9537
|
if (cachedEntry && await templateSignatureFresh(cachedEntry.signature))
|
|
9523
9538
|
return cachedEntry.html;
|
|
@@ -9584,7 +9599,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9584
9599
|
}
|
|
9585
9600
|
if (ENABLE_HTML_CACHE && !context.__stx_skip_cache && !skipCacheHint) {
|
|
9586
9601
|
const signature = await buildTemplateSignature(filePath, dependencies);
|
|
9587
|
-
htmlCache.set(htmlCacheKey(filePath), { html: output, signature });
|
|
9602
|
+
htmlCache.set(htmlCacheKey(filePath, reqCtx), { html: output, signature });
|
|
9588
9603
|
}
|
|
9589
9604
|
return output;
|
|
9590
9605
|
}
|
|
@@ -10472,6 +10487,24 @@ ${trailingPageScripts.join(`
|
|
|
10472
10487
|
if (actualPort !== port && !options.quiet) {
|
|
10473
10488
|
console.warn(`\x1B[33m[stx]\x1B[0m port ${port} in use \u2014 using \x1B[1m${actualPort}\x1B[0m instead`);
|
|
10474
10489
|
}
|
|
10490
|
+
if (ENABLE_HTML_CACHE && options.prewarmRenderCache) {
|
|
10491
|
+
const requestedConcurrency = typeof options.prewarmRenderCache === "number" ? Math.floor(options.prewarmRenderCache) : 4;
|
|
10492
|
+
const concurrency = Math.max(1, requestedConcurrency);
|
|
10493
|
+
(async () => {
|
|
10494
|
+
const files = await discoverFiles();
|
|
10495
|
+
const pending = [...new Set(files.map(stxViewFileToRoutePath).filter((routePath) => routePath !== null))];
|
|
10496
|
+
let nextIndex = 0;
|
|
10497
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, pending.length) }, async () => {
|
|
10498
|
+
while (nextIndex < pending.length) {
|
|
10499
|
+
const routePath = pending[nextIndex++];
|
|
10500
|
+
try {
|
|
10501
|
+
const response = await fetch(`http://127.0.0.1:${actualPort}${routePath}`);
|
|
10502
|
+
await response.arrayBuffer();
|
|
10503
|
+
} catch {}
|
|
10504
|
+
}
|
|
10505
|
+
}));
|
|
10506
|
+
})().catch(() => {});
|
|
10507
|
+
}
|
|
10475
10508
|
if (options.reusePort) {
|
|
10476
10509
|
const graceMs = Number(process19.env.SHUTDOWN_GRACE_MS) || 15000;
|
|
10477
10510
|
process19.once("SIGTERM", () => {
|
package/package.json
CHANGED