bun-plugin-stx 0.2.140 → 0.2.142
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 +5 -0
- package/dist/serve.js +49 -12
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ export declare function render404Page(opts: {
|
|
|
65
65
|
routes?: string[]
|
|
66
66
|
isProduction: boolean
|
|
67
67
|
}): string;
|
|
68
|
+
export declare function isRenderableCacheCandidate(html: string): boolean;
|
|
68
69
|
export declare function bundleBrowserAsset(entrypoint: string): Promise<Response>;
|
|
69
70
|
/**
|
|
70
71
|
* Start the STX development server
|
|
@@ -114,6 +115,10 @@ export declare interface ServeOptions {
|
|
|
114
115
|
componentsDir?: string
|
|
115
116
|
layoutsDir?: string
|
|
116
117
|
partialsDir?: string
|
|
118
|
+
watchDirs?: string[]
|
|
119
|
+
renderCache?: boolean
|
|
120
|
+
renderCacheVary?: 'request' | 'source'
|
|
121
|
+
prewarmRenderCache?: boolean | number
|
|
117
122
|
publicDir?: string
|
|
118
123
|
quiet?: boolean
|
|
119
124
|
autoIncrementPort?: boolean | number
|
package/dist/serve.js
CHANGED
|
@@ -8860,6 +8860,9 @@ function render404Page(opts) {
|
|
|
8860
8860
|
</body>
|
|
8861
8861
|
</html>`;
|
|
8862
8862
|
}
|
|
8863
|
+
function isRenderableCacheCandidate(html) {
|
|
8864
|
+
return !html.includes("<!-- Template Processing failed:") && !html.includes("<!-- stx rendering error -->");
|
|
8865
|
+
}
|
|
8863
8866
|
var defaultStxConfig = {
|
|
8864
8867
|
partialsDir: "partials",
|
|
8865
8868
|
componentsDir: "components",
|
|
@@ -8995,7 +8998,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
8995
8998
|
let discoveredPagePaths = null;
|
|
8996
8999
|
let assetsInitialized = false;
|
|
8997
9000
|
const htmlCache = new Map;
|
|
8998
|
-
const ENABLE_HTML_CACHE =
|
|
9001
|
+
const ENABLE_HTML_CACHE = options.renderCache === true;
|
|
9002
|
+
const RENDER_CACHE_VARY = options.renderCacheVary ?? "request";
|
|
8999
9003
|
const crosswindCssCache = new Map;
|
|
9000
9004
|
const hmrClients = new Set;
|
|
9001
9005
|
const hmrEncoder = new TextEncoder;
|
|
@@ -9031,12 +9035,15 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9031
9035
|
return;
|
|
9032
9036
|
const f = String(filename);
|
|
9033
9037
|
const isStxLike = f.endsWith(".stx") || f.endsWith(".md") || f.endsWith(".html");
|
|
9038
|
+
const isCode = f.endsWith(".js") || f.endsWith(".ts") || f.endsWith(".tsx") || f.endsWith(".mts") || f.endsWith(".cts");
|
|
9039
|
+
const isData = f.endsWith(".json");
|
|
9034
9040
|
const isCss = f.endsWith(".css");
|
|
9035
|
-
const isAsset = isCss ||
|
|
9036
|
-
if (!isStxLike && !isAsset)
|
|
9041
|
+
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");
|
|
9042
|
+
if (!isStxLike && !isAsset && !isData)
|
|
9037
9043
|
return;
|
|
9038
|
-
if (isStxLike) {
|
|
9039
|
-
|
|
9044
|
+
if (isStxLike || isCode || isData) {
|
|
9045
|
+
if (isStxLike)
|
|
9046
|
+
sourceFiles = null;
|
|
9040
9047
|
routes.clear();
|
|
9041
9048
|
htmlCache.clear();
|
|
9042
9049
|
crosswindCssCache.clear();
|
|
@@ -9053,7 +9060,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9053
9060
|
layoutsDir,
|
|
9054
9061
|
partialsDir,
|
|
9055
9062
|
publicDir,
|
|
9056
|
-
"resources/assets"
|
|
9063
|
+
"resources/assets",
|
|
9064
|
+
...options.watchDirs ?? []
|
|
9057
9065
|
]) {
|
|
9058
9066
|
if (!dir)
|
|
9059
9067
|
continue;
|
|
@@ -9209,14 +9217,24 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9209
9217
|
context.__stxServeContext = full;
|
|
9210
9218
|
globalThis.__stxServeContext = full;
|
|
9211
9219
|
}
|
|
9212
|
-
function htmlCacheKey(filePath) {
|
|
9220
|
+
function htmlCacheKey(filePath, reqCtx) {
|
|
9221
|
+
if (RENDER_CACHE_VARY === "source")
|
|
9222
|
+
return filePath;
|
|
9223
|
+
if (reqCtx) {
|
|
9224
|
+
try {
|
|
9225
|
+
return `${filePath}\x00${JSON.stringify(reqCtx)}`;
|
|
9226
|
+
} catch {
|
|
9227
|
+
return `${filePath}\x00uncacheable:${crypto.randomUUID()}`;
|
|
9228
|
+
}
|
|
9229
|
+
}
|
|
9213
9230
|
const loc = i18nConfig ? activeServeLocale ?? i18nConfig.defaultLocale : "";
|
|
9214
9231
|
const search = activeServeSearch || "";
|
|
9215
9232
|
const host = activeServeHost || "";
|
|
9216
9233
|
const cookies = activeServeCookieHeader;
|
|
9217
|
-
|
|
9234
|
+
const ip = activeServeIp;
|
|
9235
|
+
if (!loc && !search && !host && !cookies && !ip)
|
|
9218
9236
|
return filePath;
|
|
9219
|
-
return `${filePath}\x00${loc}\x00${search}\x00${host}\x00${cookies}`;
|
|
9237
|
+
return `${filePath}\x00${loc}\x00${search}\x00${host}\x00${cookies}\x00${ip}`;
|
|
9220
9238
|
}
|
|
9221
9239
|
const builtInMiddleware = authConfig === null ? {} : {
|
|
9222
9240
|
auth: (_req, ctx) => {
|
|
@@ -9517,7 +9535,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9517
9535
|
reqCtx.responseStatus = extractPageResponseStatus(content) ?? 200;
|
|
9518
9536
|
const skipCacheHint = /(?:^|[^\w$])__stx_skip_cache\s*=\s*true/.test(content);
|
|
9519
9537
|
if (ENABLE_HTML_CACHE && !skipCacheHint) {
|
|
9520
|
-
const cacheKey = htmlCacheKey(filePath);
|
|
9538
|
+
const cacheKey = htmlCacheKey(filePath, reqCtx);
|
|
9521
9539
|
const cachedEntry = htmlCache.get(cacheKey);
|
|
9522
9540
|
if (cachedEntry && await templateSignatureFresh(cachedEntry.signature))
|
|
9523
9541
|
return cachedEntry.html;
|
|
@@ -9582,9 +9600,9 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9582
9600
|
} else {
|
|
9583
9601
|
output = output.replace(/<template[^>]*>/gi, "").replace(/<\/template>/gi, "");
|
|
9584
9602
|
}
|
|
9585
|
-
if (ENABLE_HTML_CACHE && !context.__stx_skip_cache && !skipCacheHint) {
|
|
9603
|
+
if (ENABLE_HTML_CACHE && !context.__stx_skip_cache && !skipCacheHint && isRenderableCacheCandidate(output)) {
|
|
9586
9604
|
const signature = await buildTemplateSignature(filePath, dependencies);
|
|
9587
|
-
htmlCache.set(htmlCacheKey(filePath), { html: output, signature });
|
|
9605
|
+
htmlCache.set(htmlCacheKey(filePath, reqCtx), { html: output, signature });
|
|
9588
9606
|
}
|
|
9589
9607
|
return output;
|
|
9590
9608
|
}
|
|
@@ -10472,6 +10490,24 @@ ${trailingPageScripts.join(`
|
|
|
10472
10490
|
if (actualPort !== port && !options.quiet) {
|
|
10473
10491
|
console.warn(`\x1B[33m[stx]\x1B[0m port ${port} in use \u2014 using \x1B[1m${actualPort}\x1B[0m instead`);
|
|
10474
10492
|
}
|
|
10493
|
+
if (ENABLE_HTML_CACHE && options.prewarmRenderCache) {
|
|
10494
|
+
const requestedConcurrency = typeof options.prewarmRenderCache === "number" ? Math.floor(options.prewarmRenderCache) : 4;
|
|
10495
|
+
const concurrency = Math.max(1, requestedConcurrency);
|
|
10496
|
+
(async () => {
|
|
10497
|
+
const files = await discoverFiles();
|
|
10498
|
+
const pending = [...new Set(files.map(stxViewFileToRoutePath).filter((routePath) => routePath !== null))];
|
|
10499
|
+
let nextIndex = 0;
|
|
10500
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, pending.length) }, async () => {
|
|
10501
|
+
while (nextIndex < pending.length) {
|
|
10502
|
+
const routePath = pending[nextIndex++];
|
|
10503
|
+
try {
|
|
10504
|
+
const response = await fetch(`http://127.0.0.1:${actualPort}${routePath}`);
|
|
10505
|
+
await response.arrayBuffer();
|
|
10506
|
+
} catch {}
|
|
10507
|
+
}
|
|
10508
|
+
}));
|
|
10509
|
+
})().catch(() => {});
|
|
10510
|
+
}
|
|
10475
10511
|
if (options.reusePort) {
|
|
10476
10512
|
const graceMs = Number(process19.env.SHUTDOWN_GRACE_MS) || 15000;
|
|
10477
10513
|
process19.once("SIGTERM", () => {
|
|
@@ -10528,6 +10564,7 @@ export {
|
|
|
10528
10564
|
staticCacheControl,
|
|
10529
10565
|
serve,
|
|
10530
10566
|
render404Page,
|
|
10567
|
+
isRenderableCacheCandidate,
|
|
10531
10568
|
isProductionServe,
|
|
10532
10569
|
extractServerScriptsFromTemplate,
|
|
10533
10570
|
bundleBrowserAsset,
|
package/package.json
CHANGED