bun-plugin-stx 0.1.16 → 0.2.0
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/index.js +10 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{b as E,c as
|
|
2
|
+
import{b as E,c as M,d as F,e as g,f as P,g as N}from"./chunk-mjj2b826.js";import"./chunk-h0s48z3v.js";import u from"path";import q from"fs";import L from"path";var i=new Map;async function b(z,j){try{let Z=L.resolve(j.cachePath),V=L.join(Z,`${w(z)}.html`),K=L.join(Z,`${w(z)}.meta.json`);if(!await M(V)||!await M(K))return null;let _=await Bun.file(K).text(),Q=JSON.parse(_);if(Q.cacheVersion!==j.cacheVersion)return null;if((await q.promises.stat(z)).mtime.getTime()>Q.mtime)return null;for(let J of Q.dependencies)if(await M(J)){if((await q.promises.stat(J)).mtime.getTime()>Q.mtime)return null}else return null;return await Bun.file(V).text()}catch(Z){return console.warn(`Cache error for ${z}:`,Z),null}}async function C(z,j,Z,V){try{let K=L.resolve(V.cachePath);await q.promises.mkdir(K,{recursive:!0});let _=L.join(K,`${w(z)}.html`),Q=L.join(K,`${w(z)}.meta.json`),H=await q.promises.stat(z);await Bun.write(_,j);let J={sourcePath:z,mtime:H.mtime.getTime(),dependencies:Array.from(Z),cacheVersion:V.cacheVersion,generatedAt:Date.now()};await Bun.write(Q,JSON.stringify(J,null,2)),i.set(z,{output:j,mtime:H.mtime.getTime(),dependencies:Z})}catch(K){console.warn(`Failed to cache template ${z}:`,K)}}function w(z){return new Bun.CryptoHasher("sha1").update(z).digest("hex").substring(0,16)}var{serve:n}=globalThis.Bun;import k from"fs";import S from"path";async function r(z={}){let{port:j=3000,root:Z=".",stxOptions:V={},watch:K=!0,onRequest:_,routes:Q={},middleware:H=[],on404:J,onError:W}=z,y=S.resolve(Z),A=new Map;async function T($){let G=k.statSync($),U=`${$}:${G.mtimeMs}`,Y=A.get(U);if(Y)return Y.content;let X=await Bun.file($).text(),B=X.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),m=B?B[1]:"",p=X.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],l=X.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,""),f={__filename:$,__dirname:S.dirname($)};await F(m,f,$);let R=await E(l,f,$,V,new Set),D=[...p];if(D.length>0)if(R.match(/(<\/body>)/i)){let c=D.join(`
|
|
3
3
|
`);R=R.replace(/(<\/body>)/i,`${c}
|
|
4
4
|
$1`)}else R+=`
|
|
5
|
-
${
|
|
6
|
-
`)}`;return
|
|
7
|
-
${X.stack}</pre>`,{status:500,headers:{"Content-Type":"text/html"}})}};for(let Y=
|
|
8
|
-
var content = ${JSON.stringify(
|
|
9
|
-
var data = ${JSON.stringify(
|
|
5
|
+
${D.join(`
|
|
6
|
+
`)}`;return A.set(U,{content:R,mtime:G.mtimeMs}),R}async function O($){let G=k.statSync($),U=`${$}:${G.mtimeMs}`,Y=A.get(U);if(Y)return Y.content;let{content:X}=await N($,V);return A.set(U,{content:X,mtime:G.mtimeMs}),X}function I($){let G=$.startsWith("/")?$.slice(1):$,U=[G,`${G}.stx`,`${G}.md`,`${G}.html`,S.join(G,"index.stx"),S.join(G,"index.md"),S.join(G,"index.html")];for(let Y of U){let X=S.join(y,Y);if(k.existsSync(X)&&k.statSync(X).isFile())return X}return null}async function h($){let G=new URL($.url),U=async()=>{if(Q[G.pathname])return await Q[G.pathname]($);if(_){let X=await _($);if(X)return X}let Y=I(G.pathname);if(!Y){if(J)return await J($);return new Response("Not Found",{status:404})}try{let X,B="text/html";if(Y.endsWith(".stx"))X=await T(Y);else if(Y.endsWith(".md"))X=await O(Y);else if(Y.endsWith(".html"))X=await Bun.file(Y).text();else if(Y.endsWith(".css"))X=await Bun.file(Y).text(),B="text/css";else if(Y.endsWith(".js"))X=await Bun.file(Y).text(),B="text/javascript";else if(Y.endsWith(".json"))X=await Bun.file(Y).text(),B="application/json";else return new Response(Bun.file(Y));return new Response(X,{headers:{"Content-Type":B}})}catch(X){if(W)return await W(X,$);return new Response(`<h1>Error</h1><pre>${X.message}
|
|
7
|
+
${X.stack}</pre>`,{status:500,headers:{"Content-Type":"text/html"}})}};for(let Y=H.length-1;Y>=0;Y--){let X=H[Y],B=U;U=async()=>await X($,B)}return await U()}let x=n({port:j,fetch:h}),v=null;if(K)v=k.watch(y,{recursive:!0},($,G)=>{if(G&&(G.endsWith(".stx")||G.endsWith(".md")||G.endsWith(".html")))A.clear()});return{server:x,url:x.url.toString(),stop(){if(v)v.close();x.stop()}}}function s(z){return z}function o(z){return z}function e(z){return{name:"bun-plugin-stx",async setup(j){let Z={...P,...z},V=new Set,K=Z.webComponents?.enabled?`./${u.relative(u.dirname(j.config?.outdir||"dist"),Z.webComponents.outputDir||"dist/web-components")}`:"/web-components",_=[];if(Z.webComponents?.enabled)try{let Q=await g(Z,V);if(_.push(...Q),Z.debug&&Q.length>0)console.log(`Successfully built ${Q.length} web components`)}catch(Q){console.error("Failed to build web components:",Q)}j.onLoad({filter:/\.md$/},async({path:Q})=>{try{let{content:H,data:J}=await N(Q,Z);return{contents:`// ${Q}
|
|
8
|
+
var content = ${JSON.stringify(H)};
|
|
9
|
+
var data = ${JSON.stringify(J)};
|
|
10
10
|
|
|
11
11
|
export { content, data };
|
|
12
12
|
export { content as default };
|
|
13
|
-
`,loader:"js"}}catch(
|
|
14
|
-
var content = ${JSON.stringify(
|
|
13
|
+
`,loader:"js"}}catch(H){console.error("Markdown Processing Error:",H);let J=`<!DOCTYPE html><html><body><h1>Markdown Error</h1><pre>${H.message||"Unknown error"}</pre></body></html>`;return{contents:`// ${Q}
|
|
14
|
+
var content = ${JSON.stringify(J)};
|
|
15
15
|
var data = {};
|
|
16
16
|
|
|
17
17
|
export { content, data };
|
|
18
18
|
export { content as default };
|
|
19
|
-
`,loader:"js"}}}),
|
|
20
|
-
export{
|
|
19
|
+
`,loader:"js"}}}),j.onLoad({filter:/\.stx$/},async({path:Q})=>{try{let H=new Set;if(Z.cache&&Z.cachePath){let I=await b(Q,Z);if(I){if(Z.debug)console.log(`Using cached version of ${Q}`);return{contents:I,loader:"html"}}}let J=await Bun.file(Q).text(),W=J.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),y=W?W[1]:"",A=J.replace(/<script\b[^>]*>[\s\S]*?<\/script>/i,""),T={__filename:Q,__dirname:u.dirname(Q),__stx:{webComponentsPath:K,builtComponents:_}};await F(y,T,Q);let O=A;if(O=await E(O,T,Q,Z,H),H.forEach((I)=>V.add(I)),Z.cache&&Z.cachePath){if(await C(Q,O,H,Z),Z.debug)console.log(`Cached template ${Q} with ${H.size} dependencies`)}return{contents:O,loader:"html"}}catch(H){return console.error("stx Plugin Error:",H),{contents:`<!DOCTYPE html><html><body><h1>stx Rendering Error</h1><pre>${H.message||String(H)}</pre></body></html>`,loader:"html"}}})}}}var X7=e;export{e as stxPlugin,r as serve,N as readMarkdownFile,X7 as default,o as createRoute,s as createMiddleware};
|
|
20
|
+
export{X7 as a};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"typecheck": "bun tsc --noEmit"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@stacksjs/stx": "0.1.
|
|
70
|
+
"@stacksjs/stx": "0.1.16"
|
|
71
71
|
}
|
|
72
72
|
}
|