bun-plugin-stx 0.2.198 → 0.2.199
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 +17 -0
- package/dist/serve.js +36 -6
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
|
@@ -116,6 +116,22 @@ export declare function render404Page(opts: {
|
|
|
116
116
|
routes?: string[]
|
|
117
117
|
isProduction: boolean
|
|
118
118
|
}): string;
|
|
119
|
+
/**
|
|
120
|
+
* A cache that forgets its coldest entry rather than growing forever.
|
|
121
|
+
*
|
|
122
|
+
* A plain `Map` iterates in insertion order, so deleting and re-inserting a key
|
|
123
|
+
* on every read moves it to the end - which makes the first key the least
|
|
124
|
+
* recently used one, and the whole of an LRU three lines long.
|
|
125
|
+
*
|
|
126
|
+
* Exported because the behaviour is worth testing without standing a server
|
|
127
|
+
* up, the same reason `isRenderableCacheCandidate` is.
|
|
128
|
+
*/
|
|
129
|
+
export declare function boundedCache<T>(limit: number): {
|
|
130
|
+
read: (key: string) => T | undefined
|
|
131
|
+
remember: (key: string, value: T) => T
|
|
132
|
+
clear: () => void
|
|
133
|
+
readonly size: number
|
|
134
|
+
};
|
|
119
135
|
export declare function resolveServeOpenUrl(port: number, openPath?: string): string;
|
|
120
136
|
/**
|
|
121
137
|
* Did rendering fail?
|
|
@@ -205,6 +221,7 @@ export declare interface ServeOptions {
|
|
|
205
221
|
watchDirs?: string[]
|
|
206
222
|
renderCache?: boolean
|
|
207
223
|
renderCacheVary?: 'request' | 'source'
|
|
224
|
+
crosswindCacheLimit?: number
|
|
208
225
|
prewarmRenderCache?: boolean | number
|
|
209
226
|
publicDir?: string
|
|
210
227
|
quiet?: boolean
|
package/dist/serve.js
CHANGED
|
@@ -8940,6 +8940,37 @@ function render404Page(opts) {
|
|
|
8940
8940
|
</body>
|
|
8941
8941
|
</html>`;
|
|
8942
8942
|
}
|
|
8943
|
+
function boundedCache(limit) {
|
|
8944
|
+
const entries = new Map;
|
|
8945
|
+
const ceiling = Math.max(1, Math.floor(limit));
|
|
8946
|
+
return {
|
|
8947
|
+
read(key) {
|
|
8948
|
+
const hit = entries.get(key);
|
|
8949
|
+
if (hit === undefined)
|
|
8950
|
+
return;
|
|
8951
|
+
entries.delete(key);
|
|
8952
|
+
entries.set(key, hit);
|
|
8953
|
+
return hit;
|
|
8954
|
+
},
|
|
8955
|
+
remember(key, value) {
|
|
8956
|
+
entries.delete(key);
|
|
8957
|
+
entries.set(key, value);
|
|
8958
|
+
while (entries.size > ceiling) {
|
|
8959
|
+
const coldest = entries.keys().next().value;
|
|
8960
|
+
if (coldest === undefined)
|
|
8961
|
+
break;
|
|
8962
|
+
entries.delete(coldest);
|
|
8963
|
+
}
|
|
8964
|
+
return value;
|
|
8965
|
+
},
|
|
8966
|
+
clear() {
|
|
8967
|
+
entries.clear();
|
|
8968
|
+
},
|
|
8969
|
+
get size() {
|
|
8970
|
+
return entries.size;
|
|
8971
|
+
}
|
|
8972
|
+
};
|
|
8973
|
+
}
|
|
8943
8974
|
function resolveServeOpenUrl(port, openPath = "/") {
|
|
8944
8975
|
const baseUrl = `http://localhost:${port}`;
|
|
8945
8976
|
try {
|
|
@@ -9020,7 +9051,7 @@ async function bundleBrowserAsset(entrypoint) {
|
|
|
9020
9051
|
const result = await Bun.build({
|
|
9021
9052
|
entrypoints: [entrypoint],
|
|
9022
9053
|
format: "esm",
|
|
9023
|
-
minify:
|
|
9054
|
+
minify: true,
|
|
9024
9055
|
packages: "bundle",
|
|
9025
9056
|
sourcemap: "inline",
|
|
9026
9057
|
target: "browser"
|
|
@@ -9103,7 +9134,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9103
9134
|
const htmlCache = new Map;
|
|
9104
9135
|
const ENABLE_HTML_CACHE = options.renderCache === true;
|
|
9105
9136
|
const RENDER_CACHE_VARY = options.renderCacheVary ?? "request";
|
|
9106
|
-
const crosswindCssCache =
|
|
9137
|
+
const crosswindCssCache = boundedCache(options.crosswindCacheLimit ?? 512);
|
|
9107
9138
|
const hmrClients = new Set;
|
|
9108
9139
|
const hmrEncoder = new TextEncoder;
|
|
9109
9140
|
function broadcastHmr(event) {
|
|
@@ -9682,7 +9713,7 @@ function __stxOverlay(errs){
|
|
|
9682
9713
|
for (const cls of merged.safelist)
|
|
9683
9714
|
classes.add(cls);
|
|
9684
9715
|
const cacheKey = [...classes].sort().join(" ");
|
|
9685
|
-
const cached = crosswindCssCache.
|
|
9716
|
+
const cached = crosswindCssCache.read(cacheKey);
|
|
9686
9717
|
if (cached !== undefined)
|
|
9687
9718
|
return cached;
|
|
9688
9719
|
const generator = new cw.CSSGenerator(generatorConfig);
|
|
@@ -9725,9 +9756,7 @@ function __stxOverlay(errs){
|
|
|
9725
9756
|
shortcutCSS += `@media (prefers-color-scheme: dark) { .dark .${name} { ${darkDecls.join(" ")} } }
|
|
9726
9757
|
`;
|
|
9727
9758
|
}
|
|
9728
|
-
|
|
9729
|
-
crosswindCssCache.set(cacheKey, finalCss);
|
|
9730
|
-
return finalCss;
|
|
9759
|
+
return crosswindCssCache.remember(cacheKey, tokenCSS + baseCss + shortcutCSS);
|
|
9731
9760
|
} catch (error) {
|
|
9732
9761
|
console.warn("Failed to generate Crosswind CSS:", error);
|
|
9733
9762
|
return "";
|
|
@@ -10895,5 +10924,6 @@ export {
|
|
|
10895
10924
|
csrfCookieHeader,
|
|
10896
10925
|
bundleBrowserAsset,
|
|
10897
10926
|
buildDynamicRouteRegexes,
|
|
10927
|
+
boundedCache,
|
|
10898
10928
|
CSRF_COOKIE
|
|
10899
10929
|
};
|
package/package.json
CHANGED