bun-plugin-stx 0.2.321 → 0.2.322
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 +11 -3
- package/dist/serve.js +46 -5
- package/package.json +1 -1
package/dist/serve.d.ts
CHANGED
|
@@ -246,9 +246,17 @@ export declare function serve(options: ServeOptions): Promise<void>;
|
|
|
246
246
|
/**
|
|
247
247
|
* Whether any `.stx` template under `root` uses `<StxImage>` or `@image`.
|
|
248
248
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
249
|
+
* Skips dependencies, build output and hidden directories (the stx state
|
|
250
|
+
* directory among them), so it reads the project's own templates, including a
|
|
251
|
+
* framework's templates vendored into it.
|
|
252
|
+
*
|
|
253
|
+
* A component that wraps `<StxImage>` counts only when something renders it.
|
|
254
|
+
* Stacks vendors its `Image.stx` component into every app, twice (the
|
|
255
|
+
* framework defaults and the pantry install tree), so reading a definition as
|
|
256
|
+
* a use turned the pass on for every Stacks app: one that only ever wrote
|
|
257
|
+
* plain `<img>` tags spent over seven minutes of each cold boot encoding
|
|
258
|
+
* 213MB of variants that no page could ask for. A use is followed through
|
|
259
|
+
* wrappers of wrappers, and a page, layout or partial using one counts.
|
|
252
260
|
*/
|
|
253
261
|
export declare function projectUsesImageBuiltins(root: string): Promise<boolean>;
|
|
254
262
|
/**
|
package/dist/serve.js
CHANGED
|
@@ -10396,9 +10396,10 @@ ${block}`;
|
|
|
10396
10396
|
const publicRoot = nodePath.resolve(process19.cwd(), publicDir);
|
|
10397
10397
|
const [placeholderResult, deliveryResult] = await Promise.allSettled([
|
|
10398
10398
|
stx.warmImagePlaceholders(publicRoot, {
|
|
10399
|
-
cachePath: imagePlaceholderCachePath
|
|
10399
|
+
cachePath: imagePlaceholderCachePath,
|
|
10400
|
+
offThread: true
|
|
10400
10401
|
}),
|
|
10401
|
-
stx.prepareImageDelivery(publicRoot, imageDeliveryOutputDir)
|
|
10402
|
+
stx.prepareImageDelivery(publicRoot, imageDeliveryOutputDir, { offThread: true })
|
|
10402
10403
|
]);
|
|
10403
10404
|
const derived = placeholderResult.status === "fulfilled" ? placeholderResult.value : 0;
|
|
10404
10405
|
if (derived > 0 && !production)
|
|
@@ -11214,8 +11215,20 @@ if (import.meta.main) {
|
|
|
11214
11215
|
}
|
|
11215
11216
|
var IMAGE_BUILTIN_PATTERN = /<(?:StxImage|Image|stx-image|stx-img)[\s/>]|@image\s*\(/;
|
|
11216
11217
|
var TEMPLATE_SCAN_SKIP = new Set(["node_modules", "dist", "build", "coverage", "vendor"]);
|
|
11218
|
+
function escapeRegExp(value) {
|
|
11219
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11220
|
+
}
|
|
11221
|
+
function kebabCase(name) {
|
|
11222
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
11223
|
+
}
|
|
11224
|
+
function usesComponent(source, name) {
|
|
11225
|
+
const kebab = kebabCase(name);
|
|
11226
|
+
const spellings = (kebab.includes("-") ? [name, kebab] : [name]).map(escapeRegExp).join("|");
|
|
11227
|
+
return new RegExp(`<(?:${spellings})[\\s/>]|@component\\(\\s*['"](?:${spellings})['"]`).test(source);
|
|
11228
|
+
}
|
|
11217
11229
|
async function projectUsesImageBuiltins(root) {
|
|
11218
11230
|
const { readdir: readdir4, readFile } = await import("fs/promises");
|
|
11231
|
+
const templates = [];
|
|
11219
11232
|
const pending = [root];
|
|
11220
11233
|
while (pending.length > 0) {
|
|
11221
11234
|
const dir = pending.pop();
|
|
@@ -11236,10 +11249,38 @@ async function projectUsesImageBuiltins(root) {
|
|
|
11236
11249
|
}
|
|
11237
11250
|
if (!entry.isFile() || !entry.name.endsWith(".stx"))
|
|
11238
11251
|
continue;
|
|
11252
|
+
let source;
|
|
11239
11253
|
try {
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11254
|
+
source = await readFile(full, "utf8");
|
|
11255
|
+
} catch {
|
|
11256
|
+
continue;
|
|
11257
|
+
}
|
|
11258
|
+
const inComponents = nodePath.relative(root, dir).split(nodePath.sep).includes("components");
|
|
11259
|
+
const component = inComponents ? entry.name.slice(0, -".stx".length) : undefined;
|
|
11260
|
+
if (!component && IMAGE_BUILTIN_PATTERN.test(source))
|
|
11261
|
+
return true;
|
|
11262
|
+
templates.push({ source, component });
|
|
11263
|
+
}
|
|
11264
|
+
}
|
|
11265
|
+
const imageComponents = new Set;
|
|
11266
|
+
const queue = [];
|
|
11267
|
+
for (const template of templates) {
|
|
11268
|
+
if (template.component && IMAGE_BUILTIN_PATTERN.test(template.source) && !imageComponents.has(template.component)) {
|
|
11269
|
+
imageComponents.add(template.component);
|
|
11270
|
+
queue.push(template.component);
|
|
11271
|
+
}
|
|
11272
|
+
}
|
|
11273
|
+
while (queue.length > 0) {
|
|
11274
|
+
const name = queue.shift();
|
|
11275
|
+
for (const template of templates) {
|
|
11276
|
+
if (template.component === name || !usesComponent(template.source, name))
|
|
11277
|
+
continue;
|
|
11278
|
+
if (!template.component)
|
|
11279
|
+
return true;
|
|
11280
|
+
if (!imageComponents.has(template.component)) {
|
|
11281
|
+
imageComponents.add(template.component);
|
|
11282
|
+
queue.push(template.component);
|
|
11283
|
+
}
|
|
11243
11284
|
}
|
|
11244
11285
|
}
|
|
11245
11286
|
return false;
|
package/package.json
CHANGED