bun-plugin-stx 0.2.308 → 0.2.309
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 +9 -1
- package/dist/serve.js +39 -3
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
|
@@ -191,6 +191,14 @@ export declare function bundleBrowserAsset(entrypoint: string): Promise<Response
|
|
|
191
191
|
* @param options Server options with patterns and port
|
|
192
192
|
*/
|
|
193
193
|
export declare function serve(options: ServeOptions): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Whether any `.stx` template under `root` uses `<StxImage>` or `@image`.
|
|
196
|
+
*
|
|
197
|
+
* Stops at the first hit. Skips dependencies, build output and hidden
|
|
198
|
+
* directories (the stx state directory among them), so it reads the project's
|
|
199
|
+
* own templates, including a framework's templates vendored into it.
|
|
200
|
+
*/
|
|
201
|
+
export declare function projectUsesImageBuiltins(root: string): Promise<boolean>;
|
|
194
202
|
/**
|
|
195
203
|
* The cookie name a double-submit CSRF check reads.
|
|
196
204
|
*
|
|
@@ -258,7 +266,7 @@ export declare interface ServeOptions {
|
|
|
258
266
|
cssCacheLimit?: number
|
|
259
267
|
prewarmRenderCache?: boolean | number
|
|
260
268
|
imageWarmupGraceMs?: number
|
|
261
|
-
imageWarmup?: boolean
|
|
269
|
+
imageWarmup?: boolean | 'auto'
|
|
262
270
|
publicDir?: string
|
|
263
271
|
quiet?: boolean
|
|
264
272
|
autoIncrementPort?: boolean | number
|
package/dist/serve.js
CHANGED
|
@@ -9216,7 +9216,7 @@ async function serve(options) {
|
|
|
9216
9216
|
markPlaceholdersReady = resolve13;
|
|
9217
9217
|
});
|
|
9218
9218
|
let placeholdersAreReady = false;
|
|
9219
|
-
const
|
|
9219
|
+
const imageWarmupSetting = options.imageWarmup ?? stxConfig.imageWarmup ?? "auto";
|
|
9220
9220
|
const imageWarmupGraceMs = Math.max(0, options.imageWarmupGraceMs ?? 1000);
|
|
9221
9221
|
function awaitImageWarmup() {
|
|
9222
9222
|
if (placeholdersAreReady || imageWarmupGraceMs === 0)
|
|
@@ -9231,7 +9231,9 @@ async function serve(options) {
|
|
|
9231
9231
|
});
|
|
9232
9232
|
}
|
|
9233
9233
|
const stxModule = options.stxModule ? Promise.resolve(options.stxModule) : defaultStxModule;
|
|
9234
|
-
const
|
|
9234
|
+
const imageCacheDir = process19.env.STX_IMAGE_CACHE_DIR?.trim();
|
|
9235
|
+
const imageDeliveryOutputDir = imageCacheDir ? nodePath.resolve(imageCacheDir, "image-delivery") : stateDir(process19.cwd(), "image-delivery");
|
|
9236
|
+
const imagePlaceholderCachePath = imageCacheDir ? nodePath.resolve(imageCacheDir, "image-placeholders.json") : stateDir(process19.cwd(), "image-placeholders.json");
|
|
9235
9237
|
const imageDeliveryRoot = nodePath.join(imageDeliveryOutputDir, "_stx", "images");
|
|
9236
9238
|
let resolvedStxModule = null;
|
|
9237
9239
|
Promise.resolve(stxModule).then((m) => {
|
|
@@ -10292,6 +10294,7 @@ ${block}`;
|
|
|
10292
10294
|
});
|
|
10293
10295
|
}
|
|
10294
10296
|
async function runImageWarmup() {
|
|
10297
|
+
const imageWarmupEnabled = imageWarmupSetting === "auto" ? await projectUsesImageBuiltins(process19.cwd()) : imageWarmupSetting !== false;
|
|
10295
10298
|
if (!imageWarmupEnabled) {
|
|
10296
10299
|
placeholdersAreReady = true;
|
|
10297
10300
|
markPlaceholdersReady();
|
|
@@ -10302,7 +10305,7 @@ ${block}`;
|
|
|
10302
10305
|
const publicRoot = nodePath.resolve(process19.cwd(), publicDir);
|
|
10303
10306
|
const [placeholderResult, deliveryResult] = await Promise.allSettled([
|
|
10304
10307
|
stx.warmImagePlaceholders(publicRoot, {
|
|
10305
|
-
cachePath:
|
|
10308
|
+
cachePath: imagePlaceholderCachePath
|
|
10306
10309
|
}),
|
|
10307
10310
|
stx.prepareImageDelivery(publicRoot, imageDeliveryOutputDir)
|
|
10308
10311
|
]);
|
|
@@ -11109,6 +11112,38 @@ async function main() {
|
|
|
11109
11112
|
if (import.meta.main) {
|
|
11110
11113
|
main().catch(console.error);
|
|
11111
11114
|
}
|
|
11115
|
+
var IMAGE_BUILTIN_PATTERN = /<(?:StxImage|Image|stx-image|stx-img)[\s/>]|@image\s*\(/;
|
|
11116
|
+
var TEMPLATE_SCAN_SKIP = new Set(["node_modules", "dist", "build", "coverage", "vendor"]);
|
|
11117
|
+
async function projectUsesImageBuiltins(root) {
|
|
11118
|
+
const { readdir: readdir4, readFile } = await import("fs/promises");
|
|
11119
|
+
const pending = [root];
|
|
11120
|
+
while (pending.length > 0) {
|
|
11121
|
+
const dir = pending.pop();
|
|
11122
|
+
let entries;
|
|
11123
|
+
try {
|
|
11124
|
+
entries = await readdir4(dir, { withFileTypes: true });
|
|
11125
|
+
} catch {
|
|
11126
|
+
continue;
|
|
11127
|
+
}
|
|
11128
|
+
for (const entry of entries) {
|
|
11129
|
+
if (entry.name.startsWith("."))
|
|
11130
|
+
continue;
|
|
11131
|
+
const full = nodePath.join(dir, entry.name);
|
|
11132
|
+
if (entry.isDirectory()) {
|
|
11133
|
+
if (!TEMPLATE_SCAN_SKIP.has(entry.name))
|
|
11134
|
+
pending.push(full);
|
|
11135
|
+
continue;
|
|
11136
|
+
}
|
|
11137
|
+
if (!entry.isFile() || !entry.name.endsWith(".stx"))
|
|
11138
|
+
continue;
|
|
11139
|
+
try {
|
|
11140
|
+
if (IMAGE_BUILTIN_PATTERN.test(await readFile(full, "utf8")))
|
|
11141
|
+
return true;
|
|
11142
|
+
} catch {}
|
|
11143
|
+
}
|
|
11144
|
+
}
|
|
11145
|
+
return false;
|
|
11146
|
+
}
|
|
11112
11147
|
export {
|
|
11113
11148
|
usableErrorPage,
|
|
11114
11149
|
staticCacheControl,
|
|
@@ -11119,6 +11154,7 @@ export {
|
|
|
11119
11154
|
resolveServeOpenUrl,
|
|
11120
11155
|
render404Page,
|
|
11121
11156
|
publicFileExists,
|
|
11157
|
+
projectUsesImageBuiltins,
|
|
11122
11158
|
isStaticAssetPath,
|
|
11123
11159
|
isRenderableCacheCandidate,
|
|
11124
11160
|
isRenderFailure,
|
package/package.json
CHANGED