@stacksjs/stx 0.2.233 → 0.2.235
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/{chunk-pn2rzzcj.js → chunk-0e4xfaxn.js} +1 -1
- package/dist/{chunk-9za99vpf.js → chunk-1z4dvqqv.js} +1 -1
- package/dist/{chunk-bbymgcwp.js → chunk-3w2k2ma8.js} +1 -1
- package/dist/{chunk-qv9azqvb.js → chunk-4regf51y.js} +1 -1
- package/dist/{chunk-nepsmxy4.js → chunk-67az313z.js} +1 -1
- package/dist/{chunk-5wwjte8y.js → chunk-7b9tak12.js} +1 -1
- package/dist/{chunk-70rk9she.js → chunk-85frtq6r.js} +1 -1
- package/dist/{chunk-q52bc070.js → chunk-8srw2ck7.js} +1 -1
- package/dist/{chunk-jpjqp4r8.js → chunk-9sg8p36m.js} +1 -1
- package/dist/chunk-ae1pb4a7.js +13 -0
- package/dist/{chunk-ct19gbs6.js → chunk-am6ee3yg.js} +1 -1
- package/dist/{chunk-6k6batqy.js → chunk-ba75f8qh.js} +1 -1
- package/dist/{chunk-9qj7yjse.js → chunk-c0hd0jtr.js} +1 -1
- package/dist/{chunk-dnspts0e.js → chunk-c8sh51p7.js} +1 -1
- package/dist/{chunk-a9cje0vm.js → chunk-ccbgys65.js} +1 -1
- package/dist/{chunk-5dc1twg4.js → chunk-cnayba7d.js} +16 -16
- package/dist/{chunk-a9s60kwx.js → chunk-dhcdsfga.js} +1 -1
- package/dist/{chunk-fphzcf76.js → chunk-e4ta7mkk.js} +1 -1
- package/dist/{chunk-wz81m0kv.js → chunk-fj497e24.js} +1 -1
- package/dist/{chunk-633f58jf.js → chunk-fsr7j01j.js} +1 -1
- package/dist/{chunk-esasjpwa.js → chunk-fwrhkhhz.js} +1 -1
- package/dist/{chunk-kkk5ey50.js → chunk-h9e1mhhk.js} +1 -1
- package/dist/{chunk-ct8xjs8k.js → chunk-haeynd7x.js} +2 -2
- package/dist/{chunk-0xpq63re.js → chunk-jqefbg40.js} +1 -1
- package/dist/{chunk-tdjdf9v9.js → chunk-kp0g4ckk.js} +1 -1
- package/dist/{chunk-qymakqm4.js → chunk-kq3erhfz.js} +105 -105
- package/dist/{chunk-ajt3k1hf.js → chunk-nb7rbydx.js} +1 -1
- package/dist/{chunk-td24v6qk.js → chunk-pwn4hxjb.js} +1 -1
- package/dist/{chunk-g26seq16.js → chunk-q7e9d2m9.js} +1 -1
- package/dist/{chunk-2m730367.js → chunk-q7pafzst.js} +1 -1
- package/dist/{chunk-f74xtehm.js → chunk-qpbywzvg.js} +2 -2
- package/dist/{chunk-7es64y8d.js → chunk-r3vb8c9k.js} +1 -1
- package/dist/{chunk-09rpa9sg.js → chunk-rcv6w99y.js} +1 -1
- package/dist/{chunk-rrwx8e79.js → chunk-savq2gjy.js} +1 -1
- package/dist/{chunk-1mnhkme7.js → chunk-t4e1wqa0.js} +1 -1
- package/dist/{chunk-2j1frpgy.js → chunk-te108yc3.js} +1 -1
- package/dist/{chunk-wwkzy8tz.js → chunk-tyeb73qy.js} +1 -1
- package/dist/{chunk-wm6n9mkk.js → chunk-wmwjbk2g.js} +1 -1
- package/dist/{chunk-xhkyf0s6.js → chunk-www2w0mc.js} +1 -1
- package/dist/{chunk-9se575h1.js → chunk-wx8pg3dw.js} +1 -1
- package/dist/{chunk-9sv8944b.js → chunk-x3tvmc58.js} +1 -1
- package/dist/{chunk-vfnv1r93.js → chunk-yzceabbm.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/client-script-bundler.js +16 -2
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/pwa.js +1 -1
- package/dist/site-builder/seo.js +8 -1
- package/dist/ssg.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-b9ehjbbx.js +0 -13
package/dist/site-builder/seo.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
function absoluteImage(image, origin) {
|
|
2
|
+
if (!image)
|
|
3
|
+
return image;
|
|
4
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(image) || image.startsWith("//"))
|
|
5
|
+
return image;
|
|
6
|
+
return `${origin}${image.startsWith("/") ? "" : "/"}${image}`;
|
|
7
|
+
}
|
|
1
8
|
export function injectSeo(html, site, page = {}, pagePath = "/") {
|
|
2
|
-
const seo = site.seo ?? {}, title = page.title ?? seo.title ?? site.name, description = page.description ?? seo.description ?? site.description ?? "",
|
|
9
|
+
const seo = site.seo ?? {}, title = page.title ?? seo.title ?? site.name, description = page.description ?? seo.description ?? site.description ?? "", origin = site.url.replace(/\/$/, ""), url = `${origin}${pagePath}`, image = absoluteImage(page.image ?? seo.image, origin), siteName = seo.siteName ?? site.name, ogType = seo.type ?? "website", locale = seo.locale ?? "en_US", tags = [];
|
|
3
10
|
if (seo.favicon) {
|
|
4
11
|
const ext = seo.favicon.toLowerCase().split(".").pop(), mime = ext === "svg" ? "image/svg+xml" : ext === "ico" ? "image/x-icon" : ext === "png" ? "image/png" : ext === "jpg" || ext === "jpeg" ? "image/jpeg" : "";
|
|
5
12
|
tags.push(`<link rel="icon"${mime ? ` type="${mime}"` : ""} href="${escapeAttr(seo.favicon)}">`);
|
package/dist/ssg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ck as Tq,xk as Bq,yk as Hq}from"./chunk-3zdkcdvf.js";import{Dk as Uq,Ek as Iq,Fk as Eq}from"./chunk-frp9fc7j.js";import{$k as Nq,al as _q}from"./chunk-
|
|
2
|
+
import{Ck as Tq,xk as Bq,yk as Hq}from"./chunk-3zdkcdvf.js";import{Dk as Uq,Ek as Iq,Fk as Eq}from"./chunk-frp9fc7j.js";import{$k as Nq,al as _q}from"./chunk-ae1pb4a7.js";import"./chunk-r84h7wxw.js";import{Dq as y,Hm as Aq,Rp as Oq,Zo as c,ap as Xq,as as l}from"./chunk-cnayba7d.js";import"./chunk-4awxsp8f.js";import"./chunk-hk8j3eps.js";import"./chunk-mxva4zmq.js";import"./chunk-1kg9sz9a.js";import{Ys as zq}from"./chunk-rcv6w99y.js";import"./chunk-74r77tz1.js";import{it as f}from"./chunk-xgtcq9bj.js";import"./chunk-2fspj91j.js";import"./chunk-evv58hf5.js";import"./chunk-xaqjtned.js";import{lu as Wq,mu as Yq,nu as Vq,ou as jq,pu as Gq,qu as Lq}from"./chunk-7kpfk426.js";import"./chunk-2tew0h6f.js";import{Gu as k}from"./chunk-yx8vftp0.js";import B from"fs";import j from"path";import{createHash as wq}from"crypto";function Sq(q){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(q).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return q}}var vq=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function xq(q){return Bun.hash(q).toString(16)}function Jq(q,Z={}){if(!q.includes('type="stx/island"'))return{html:q,chunks:[]};let $=new Map,Q=q.replace(vq,(J,W,z,X)=>{let N=X.trim();if(!N)return J;if(/\bdata-stx-src=/.test(z))return J;if(Z.minify)N=Sq(N);let O=xq(N);if(!$.has(O))$.set(O,N);let H=Z.integrity?` data-stx-integrity="sha384-${wq("sha384").update(N).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${W}" data-stx-src="/_stx/islands/${O}.js"${H}${z}></script>`}),K=Array.from($,([J,W])=>({hash:J,code:W}));return{html:Q,chunks:K}}var yq=new Set(["visible","idle"]);function Qq(q){if(!q.includes("data-stx-src="))return q;let Z=new Map,$=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,Q;while((Q=$.exec(q))!==null)Z.set(Q[1],Q[2]);let K=new Set,J=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,W;while((W=J.exec(q))!==null)if(yq.has(Z.get(W[1])||""))K.add(W[2]);let z=q.lastIndexOf("</head>");if(K.size===0||z===-1)return q;let X=Array.from(K).filter((N)=>!q.includes(`rel="prefetch" href="${N}"`)).map((N)=>`<link rel="prefetch" href="${N}" as="script">`).join("");if(!X)return q;return q.slice(0,z)+X+q.slice(z)}var Pq=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function u(q){let Z=q.trim();if(!Z)return null;let $=/^https?:\/\//i.test(Z)?Z:`https://${Z}`;try{return new URL($).origin+new URL($).pathname.replace(/\/$/,"")}catch{return null}}function Cq(q){for(let Z of Pq){let $=q[Z];if(!$)continue;let Q=u($);if(Q)return{url:Q,source:"env",via:Z}}return null}function Zq(q){if(!q||typeof q!=="object")return null;let Z=q,$=Z.site?.url??Z.url??Z.app?.url;return typeof $==="string"?u($):null}async function gq(q){let{existsSync:Z}=await import("fs"),$=await import("path");for(let Q of["site.config.ts","site.config.js",".config/site.config.ts"]){let K=$.resolve(q,Q);if(!Z(K))continue;try{let J=await import(K),W=Zq(J.default??J);if(W)return W}catch{}}return null}async function $q(q={}){let Z=q.cwd??process.cwd(),$=q.env??process.env;if(q.explicit){let W=u(q.explicit);if(W)return{url:W,source:"option"}}let Q=Zq(q.stxConfig);if(Q)return{url:Q,source:"stx.config",via:"site.url"};let K=await gq(Z);if(K)return{url:K,source:"site.config",via:"url"};let J=Cq($);if(J)return J;return{url:"http://localhost",source:"fallback"}}function Kq(){return["No site URL configured \u2014 sitemap.xml and robots.txt will point at http://localhost."," Set one in stx.config.ts (site: { url: 'https://example.com' }), in site.config.ts,"," via --domain, or with SITE_URL in the build environment."].join(`
|
|
3
3
|
`)}class Dq{cacheDir;cache=new Map;loaded=!1;salt;constructor(q,Z=""){this.cacheDir=q,this.salt=Z}async load(){if(this.loaded)return;let q=j.join(this.cacheDir,"build-cache.json");if(await Bun.file(q).exists())try{let Z=JSON.parse(await Bun.file(q).text());for(let[$,Q]of Object.entries(Z))this.cache.set($,Q)}catch{}this.loaded=!0}async save(){await B.promises.mkdir(this.cacheDir,{recursive:!0});let q=j.join(this.cacheDir,"build-cache.json"),Z={};for(let[$,Q]of this.cache)Z[$]=Q;await Bun.write(q,JSON.stringify(Z))}getHash(q,Z){let $=B.statSync(q),Q=`${this.salt}|${q}:${$.mtimeMs}`;for(let J of Z)if(B.existsSync(J)){let W=B.statSync(J);Q+=`:${J}:${W.mtimeMs}`}let K=0;for(let J=0;J<Q.length;J++){let W=Q.charCodeAt(J);K=(K<<5)-K+W,K=K&K}return Math.abs(K).toString(36)}get(q,Z){let $=this.cache.get(q);if(!$)return null;let Q=this.getHash(Z,$.dependencies??[]);if($.hash!==Q)return this.cache.delete(q),null;return $.html}set(q,Z,$,Q){let K=this.getHash(Z,$);this.cache.set(q,{hash:K,html:Q,generatedAt:Date.now(),dependencies:$})}}class Fq{cacheDir;constructor(q){this.cacheDir=q}getFilePath(q){let Z=q.replace(/[^a-zA-Z0-9]/g,"_")+".json";return j.join(this.cacheDir,"isr",Z)}async get(q){let Z=this.getFilePath(q);if(!await Bun.file(Z).exists())return null;try{return JSON.parse(await Bun.file(Z).text())}catch{return null}}async set(q,Z){let $=this.getFilePath(q);await B.promises.mkdir(j.dirname($),{recursive:!0}),await Bun.write($,JSON.stringify(Z))}async invalidate(q){let Z=this.getFilePath(q);if(await Bun.file(Z).exists())await B.promises.unlink(Z)}async invalidatePattern(q){let Z=j.join(this.cacheDir,"isr");if(!B.existsSync(Z))return;let $=await B.promises.readdir(Z);for(let Q of $){let K=Q.replace(/_/g,"/").replace(".json","");if(q.test(K))await B.promises.unlink(j.join(Z,Q))}}async needsRevalidation(q){let Z=await this.get(q);if(!Z)return!0;return Date.now()>Z.revalidateAfter}}async function fq(q){try{let $=(await Bun.file(q).text()).match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!$)return null;let Q=$[1];if(!Q.includes("getStaticPaths"))return null;let K=Q.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticPaths\s*\([^)]*\)\s*\{([\s\S]*?)\n[\t ]*\}/);if(!K)return null;return await Function(`
|
|
4
4
|
return (async function getStaticPaths() {
|
|
5
5
|
${K[1]}
|
|
@@ -41,7 +41,7 @@ ${q.map((Q)=>{let K=new URL(Q.loc,Z).href,J=` <url>
|
|
|
41
41
|
${$.join(`
|
|
42
42
|
`)}
|
|
43
43
|
</channel>
|
|
44
|
-
</rss>`}async function sq(q={}){let Z=Date.now();_q();let $=await l(process.cwd()),Q=$.build||{},K=await $q({explicit:q.domain||Q.domain,stxConfig:$});if(K.source==="fallback"&&(q.sitemap??Q.sitemap??!0))console.warn(Kq());let J={pagesDir:q.pagesDir||Q.pagesDir||"pages",outputDir:q.outputDir||Q.outputDir||"dist",baseUrl:q.baseUrl||Q.baseUrl||"/",domain:K.url,revalidate:q.revalidate??Q.revalidate??!1,sitemap:q.sitemap??Q.sitemap??!0,sitemapExclude:q.sitemapExclude||Q.sitemapExclude||[],robots:q.robots??Q.robots??!0,rss:q.rss??Q.rss??!1,concurrency:q.concurrency||Q.concurrency||10,cache:q.cache??Q.cache??!0,cacheDir:q.cacheDir||Q.cacheDir||f(process.cwd(),"ssg-cache"),contentLoaders:q.contentLoaders||[],hooks:q.hooks||{},minify:q.minify??Q.minify??!0,generate404:q.generate404??Q.generate404??!0,publicDir:q.publicDir||Q.publicDir||"public",trailingSlash:q.trailingSlash??Q.trailingSlash??!1,cleanOutput:q.cleanOutput??Q.cleanOutput??!0,cacheSalt:q.cacheSalt??"",partialsDir:q.partialsDir||$?.partialsDir||"",componentsDir:q.componentsDir||$?.componentsDir||"",failOnIncludeError:q.failOnIncludeError??!0,chunkIslands:q.chunkIslands===!0,prefetchIslands:q.prefetchIslands===!0,integrityIslands:q.integrityIslands===!0},W={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},z=new Set,X=0,N={},O={};await J.hooks.onBuildStart?.();try{if(J.cleanOutput&&B.existsSync(J.outputDir))await B.promises.rm(J.outputDir,{recursive:!0});await B.promises.mkdir(J.outputDir,{recursive:!0});let _=J.cacheSalt;if(!_){let{resolveUserCrosswindConfig:Y,fingerprintConfig:G}=await import("./chunk-
|
|
44
|
+
</rss>`}async function sq(q={}){let Z=Date.now();_q();let $=await l(process.cwd()),Q=$.build||{},K=await $q({explicit:q.domain||Q.domain,stxConfig:$});if(K.source==="fallback"&&(q.sitemap??Q.sitemap??!0))console.warn(Kq());let J={pagesDir:q.pagesDir||Q.pagesDir||"pages",outputDir:q.outputDir||Q.outputDir||"dist",baseUrl:q.baseUrl||Q.baseUrl||"/",domain:K.url,revalidate:q.revalidate??Q.revalidate??!1,sitemap:q.sitemap??Q.sitemap??!0,sitemapExclude:q.sitemapExclude||Q.sitemapExclude||[],robots:q.robots??Q.robots??!0,rss:q.rss??Q.rss??!1,concurrency:q.concurrency||Q.concurrency||10,cache:q.cache??Q.cache??!0,cacheDir:q.cacheDir||Q.cacheDir||f(process.cwd(),"ssg-cache"),contentLoaders:q.contentLoaders||[],hooks:q.hooks||{},minify:q.minify??Q.minify??!0,generate404:q.generate404??Q.generate404??!0,publicDir:q.publicDir||Q.publicDir||"public",trailingSlash:q.trailingSlash??Q.trailingSlash??!1,cleanOutput:q.cleanOutput??Q.cleanOutput??!0,cacheSalt:q.cacheSalt??"",partialsDir:q.partialsDir||$?.partialsDir||"",componentsDir:q.componentsDir||$?.componentsDir||"",failOnIncludeError:q.failOnIncludeError??!0,chunkIslands:q.chunkIslands===!0,prefetchIslands:q.prefetchIslands===!0,integrityIslands:q.integrityIslands===!0},W={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},z=new Set,X=0,N={},O={};await J.hooks.onBuildStart?.();try{if(J.cleanOutput&&B.existsSync(J.outputDir))await B.promises.rm(J.outputDir,{recursive:!0});await B.promises.mkdir(J.outputDir,{recursive:!0});let _=J.cacheSalt;if(!_){let{resolveUserCrosswindConfig:Y,fingerprintConfig:G}=await import("./chunk-wx8pg3dw.js");try{_=G(await Y(process.cwd()))}catch{}}let L=new Dq(J.cacheDir,_);if(J.cache)await L.load();try{let{generateCrosswindCSS:Y}=await import("./chunk-wx8pg3dw.js");await Y('<div class="bg-black"></div>')}catch{}Wq();let m=$?.routeMiddleware?.dir||"middleware";await Vq(process.cwd(),m);let p=Yq();if(p.length>0)console.log(`Loaded ${p.length} middleware: ${p.join(", ")}`);let Mq=$?.routeMiddleware?.global||[];Tq($?.layoutsDir,f(process.cwd()));let n=c(".",{pagesDir:J.pagesDir});console.log(`Found ${n.length} routes`);let P=[];for(let Y of n){let G=await mq(Y);for(let A of G)P.push({route:Y,url:A.url,params:A.params,props:A.props,revalidate:A.revalidate??J.revalidate})}W.totalPages=P.length;try{let{warmImagePlaceholders:Y}=await import("./chunk-jd90twtr.js"),{stateDir:G}=await import("./chunk-3j404s9z.js"),A=await Y(J.publicDir,{cachePath:G(process.cwd(),"image-placeholders.json")});if(A>0)console.log(`Derived ${A} image placeholder(s)`)}catch{}console.log(`Generating ${W.totalPages} pages...`);let w=[],i=[];for(let Y=0;Y<P.length;Y+=J.concurrency)i.push(P.slice(Y,Y+J.concurrency));for(let Y of i)await Promise.all(Y.map(async(G)=>{let{route:A,url:V,params:S,props:bq,revalidate:a}=G;try{await J.hooks.onPageStart?.(V);let F=await Bun.file(A.filePath).text(),R=tq(F),kq=R?.middleware?Array.isArray(R.middleware)?R.middleware:[R.middleware]:[],r=[...Mq,...kq];if(r.length>0){let D=jq(V,S,R||{}),M=Gq(D,null,void 0,{isServer:!0}),E=await Lq(r,M);if(E.redirect){let U=typeof E.redirect==="string"?E.redirect:E.redirect.path||E.redirect,x=eq(String(U),V),b=qJ(V,J);await B.promises.mkdir(j.dirname(b),{recursive:!0}),await Bun.write(b,x),W.successCount++,W.pages.push({route:V,outputPath:b,size:Buffer.byteLength(x),cached:!1}),w.push({loc:V,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${V} \u2192 redirect to ${U}`);return}if(E.abort){let U=typeof E.abort==="string"?E.abort:E.abort?.error?.message||"aborted";console.warn(` \u21B3 ${V} \u2014 middleware aborted: ${U}`);return}}let t=F.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(t)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${t[1]};
|
|
46
46
|
return validate(route);
|
|
47
47
|
`)({params:S})){console.warn(`Validation failed for ${V}, skipping...`);return}}catch{}let I=null,e=!1;if(J.cache){if(I=L.get(V,A.filePath),I)e=!0,W.cachedCount++}if(!I){let D=await Rq(A,S,bq,J,$);if(I=D.html,J.failOnIncludeError&&D.includeFailures.length>0)throw Error(`${D.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.235",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -117,12 +117,12 @@
|
|
|
117
117
|
"dependencies": {
|
|
118
118
|
"@cwcss/crosswind": "^0.2.14",
|
|
119
119
|
"@stacksjs/clapp": "^0.2.0",
|
|
120
|
-
"@stacksjs/desktop": "0.2.
|
|
121
|
-
"@stacksjs/sanitizer": "0.2.
|
|
120
|
+
"@stacksjs/desktop": "0.2.235",
|
|
121
|
+
"@stacksjs/sanitizer": "0.2.235",
|
|
122
122
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
123
|
-
"bun-plugin-stx": "0.2.
|
|
123
|
+
"bun-plugin-stx": "0.2.235",
|
|
124
124
|
"bunfig": "^0.15.17",
|
|
125
|
-
"stx-router": "0.2.
|
|
125
|
+
"stx-router": "0.2.235",
|
|
126
126
|
"ts-broadcasting": "^0.0.9",
|
|
127
127
|
"ts-images": "^0.2.11",
|
|
128
128
|
"ts-syntax-highlighter": "^0.2.1"
|
package/dist/chunk-b9ehjbbx.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{gl as _,hl as h}from"./chunk-r84h7wxw.js";import{Pl as g,bs as p}from"./chunk-5dc1twg4.js";import{it as N}from"./chunk-xgtcq9bj.js";import W from"path";import q from"fs";var l=5,u=1;function t(J=process.env){return J.STX_DEBUG==="true"||J.STX_DEBUG==="1"}function L(...J){if(t())console.log("[stx:bundler]",...J)}var D=[];function v(J,K,$){D.push({filePath:J||"<inline>",message:K,details:$})}function Yz(){return D.slice()}function Zz(){D.length=0}var F;function $z(J){F=J}function b(){if(F)return F;try{let J=p.strict;return typeof J==="object"&&J!==null?J.bundlerFallback??"warn":"warn"}catch{return"warn"}}var f=[/^stx$/,/^@stacksjs\/stx$/,/^@stores$/,/^stx\/stores$/,/^@composables$/];function wz(J){let K=/^[ \t]*import[ \t]+(?!type(?:[ \t]|{))[\s\S]*?\s+from\s+['"]([^'"]+)['"][ \t]*;?/gm,$;while(($=K.exec(J))!==null){let M=$[1];if(!f.some((z)=>z.test(M)))return L("detected user import:",M),!0}let Q=/^[ \t]*import[ \t]+['"]([^'"]+)['"]/gm;while(($=Q.exec(J))!==null){let M=$[1];if(/\.css(?:\?.*)?$/.test(M))continue;if(!f.some((z)=>z.test(M)))return L("detected side-effect import:",M),!0}return!1}function i(J,K,$,Q){let M=(Z,z)=>{let G=Z===$?K:W.dirname(Z),Y=W.resolve(G,z),H=[Y,`${Y}.ts`,`${Y}.tsx`,`${Y}.js`,`${Y}.mjs`,`${Y}.jsx`,W.join(Y,"index.ts"),W.join(Y,"index.tsx"),W.join(Y,"index.js"),W.join(Y,"index.mjs")];for(let j of H)try{if(q.existsSync(j)&&q.statSync(j,{throwIfNoEntry:!1})?.isFile())return j}catch{}return Y};return{name:"stx-client-bundle",setup(Z){Z.onResolve({filter:/^(stx|@stacksjs\/stx)$/},(z)=>({path:z.path,external:!0})),Z.onResolve({filter:/^(@stores|@composables|stx\/stores)$/},(z)=>({path:z.path,external:!0})),Z.onResolve({filter:/^\//},(z)=>{if(q.existsSync(z.path))return{path:z.path};return{path:z.path,external:!0}}),Z.onResolve({filter:/^\.\.?\//},(z)=>{let G=M(z.importer,z.path);return Q.add(G),{path:G}}),Z.onResolve({filter:/^[@~]\//},(z)=>{let G=W.resolve(J,z.path.slice(2)),Y=[G,`${G}.ts`,`${G}.tsx`,`${G}.js`,`${G}.mjs`,`${G}.jsx`,W.join(G,"index.ts"),W.join(G,"index.tsx"),W.join(G,"index.js"),W.join(G,"index.mjs")];for(let H of Y)if(q.existsSync(H)&&q.statSync(H,{throwIfNoEntry:!1})?.isFile())return L(`resolved ${z.path[0]}/ import:`,z.path,"\u2192",H),Q.add(H),{path:H};return console.warn(`[stx:bundler] could not resolve ${z.path[0]}/ import:`,z.path),{path:G}}),Z.onLoad({filter:/\.(?:[cm]?[jt]sx?|json)$/},(z)=>{let G=W.extname(z.path).toLowerCase(),Y=G===".json"?"json":G===".tsx"?"tsx":G===".jsx"?"jsx":G===".ts"||G===".mts"||G===".cts"?"ts":"js";if(z.path!==$)Q.add(z.path);return{contents:q.readFileSync(z.path,"utf8"),loader:Y}})}}}var R=new Map,m=Symbol.for("stx.client-bundle-build-queue");function s(J){let K=globalThis,Q=(K[m]??Promise.resolve()).then(J,J);return K[m]=Q.then(()=>{return},()=>{return}),Q}async function Qz(J,K,$={}){let Q=$.projectRoot||process.cwd(),M=$.minify??!1,Z=$.cacheDir||N(Q,"bundle-cache"),z=new Bun.CryptoHasher("md5");z.update(`${l}\x00${J}\x00${K}`);let G=z.digest("hex").slice(0,12),Y=W.join(Z,`${G}.js`),H=W.join(Z,`${G}.deps.json`),j=Bun.file(Y);if(await j.exists()){let V=Bun.file(H),k=!0;if(await V.exists())try{let T=JSON.parse(await V.text());if(T.metadataVersion!==u||!Array.isArray(T.files))k=!1;for(let S of Array.isArray(T.files)?T.files:[])try{if(q.statSync(S.path).mtimeMs!==S.mtimeMs){k=!1;break}}catch{k=!1;break}}catch{k=!1}if(k)return L("cache hit:",G),await j.text();L("cache invalidated by dep change:",G)}let y=R.get(G);if(y)return await y;let x=s(()=>a(J,K,{projectRoot:Q,minify:M,cacheDir:Z,hash:G,cachePath:Y,depsPath:H}));R.set(G,x);try{return await x}finally{R.delete(G)}}async function a(J,K,$){let{projectRoot:Q,minify:M,cacheDir:Z,hash:z,cachePath:G,depsPath:Y}=$,H=N(Q,"bundle-tmp"),j=W.join(H,`${z}.ts`),y=W.join(H,"out",z);q.mkdirSync(H,{recursive:!0}),q.mkdirSync(y,{recursive:!0});let x=W.dirname(K),V=[],k=/^(export\s+)?(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))/gm,T=/^(export\s+)?(?:async\s+)?function\s+(\w+)/gm,S;while((S=k.exec(J))!==null){if(S[1])continue;if(S[2])S[2].split(",").forEach((I)=>{let X=I.split(":")[0].trim();if(X)V.push(X)});else if(S[3])V.push(S[3])}while((S=T.exec(J))!==null){if(S[1])continue;V.push(S[2])}let B=V.length>0?`
|
|
3
|
-
export { ${V.join(", ")} }`:"";await Bun.write(j,J+B),L("bundling:",z,"from:",W.basename(K));let P=new Set;try{let I=await Bun.build({entrypoints:[j],outdir:y,target:"browser",format:"esm",minify:M,plugins:[i(Q,x,j,P)],define:{"process.env.NODE_ENV":M?'"production"':'"development"',...g()},root:Q});if(!I.success){let U=I.logs.filter((C)=>C.level==="error").map((C)=>C.message).join(", ")||`Unable to bundle ${W.basename(K)}`,A=_(I.logs,K||void 0);if(console.warn("[stx:bundler] build failed:",U),v(K||"",U,A),b()==="error")throw Error(U);return J}let X="";for(let w of I.outputs){X=await w.text();break}let O=[];for(let w of X.matchAll(/^\s*export\s*\{([^}]*)\}\s*;?\s*$/gm))for(let U of w[1].split(",")){let A=U.trim().match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);if(A){O.push([A[2],A[1]]);continue}let C=U.trim();if(/^[A-Za-z_$][\w$]*$/.test(C))O.push([C,C])}let c=X.match(/^\s*import\s+[^;]+;?\s*$/gm)||[];X=X.replace(/^\s*import\s+[^;]+;?\s*$/gm,"").replace(/^\s*export\s*\{[^}]*\}\s*;?\s*$/gm,"").replace(/^\s*export\s+default\s+.*$/gm,"").trim();let E=`__stxBundle_${z}`,n=O.map(([w,U])=>`${JSON.stringify(w)}: ${U}`).join(", "),o=O.map(([w])=>`var ${w} = undefined;`).join(`
|
|
4
|
-
`),r=O.map(([w])=>`${w} = ${E}[${JSON.stringify(w)}];`).join(`
|
|
5
|
-
`);if(X=`${c.join(`
|
|
6
|
-
`)}
|
|
7
|
-
${o}
|
|
8
|
-
var ${E} = (function() {
|
|
9
|
-
${X}
|
|
10
|
-
return { ${n} };
|
|
11
|
-
})();
|
|
12
|
-
${r}`.trim(),L("bundled:",z,"output:",X.length,"bytes"),V.length>0&&O.length===0)return console.warn(`[stx:bundler] dropped every binding for ${W.basename(K)} (${z}); serving the unbundled source and not caching this result`),J;q.mkdirSync(Z,{recursive:!0}),await Bun.write(G,X);let d=Array.from(P).map((w)=>{try{return{path:w,mtimeMs:q.statSync(w).mtimeMs}}catch{return null}}).filter((w)=>w!==null);return await Bun.write(Y,JSON.stringify({metadataVersion:u,files:d})),X}catch(I){let X=_(I,K||void 0),O=h(I,K||void 0);if(console.warn(`[stx:bundler] error: ${O}`),v(K||"",O,X),b()==="error")throw I;return J}finally{try{q.rmSync(j,{force:!0}),q.rmSync(y,{recursive:!0,force:!0})}catch{}}}
|
|
13
|
-
export{t as Zk,v as _k,Yz as $k,Zz as al,$z as bl,b as cl,wz as dl,s as el,Qz as fl};
|