@stacksjs/build 0.70.371 → 0.70.376

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -224,4 +224,4 @@ ${K}`);else H.debug(`[no changes] ${R}`)}catch{H.info(`[new file] ${De(r.cwd,R)}
224
224
  `);if(r.failOnUnresolvedReExport)throw Error(O);H.warn(O),H.warn('Generated .d.ts files reference modules that were not emitted \u2014 consumers will see "has no exported member" errors.')}}if(r.bundle&&(a.filesGenerated>0||o>0)&&c.length>0)try{H.debug("Bundling declarations...");let C=new Map,x=async(R)=>{let k=C.get(R);if(k!==void 0)return k;return k=await ct(R),C.set(R,k),k};for(let R of f)await x(R);let O=c.length===1&&!!r.bundleOutput;for(let R of c){let k=await Yi([R],{includeImports:!0}),E=new Set;for(let X of k.reachable){if(X.endsWith(".d.ts"))continue;if(X.includes("node_modules"))continue;E.add(X)}let G=f.filter((X)=>E.has(X));if(!G.includes(R))G.push(R);let re=new Map;for(let X of G){let se=C.get(X)??await x(X);re.set(X,se)}let I=await $a(G,re,r),_=O?rt(r.cwd,r.outdir,r.bundleOutput):xr(R,r);if(r.dryRun)H.info(`[dry-run] Would bundle ${I.files.length} files to: ${De(r.cwd,_)}`);else await fs(Ar(_),{recursive:!0}),await br(_,I.content,r.lineEnding),H.info(`Bundled ${I.files.length} files to: ${De(r.cwd,_)}`);if(O)break}}catch(C){let x=C instanceof Error?C.message:String(C);H.error(`Bundle failed: ${x}`)}if(a.durationMs=Date.now()-t,r.stats)if(r.outputFormat==="json")console.log(JSON.stringify(a,null,2));else{if(H.info(`
225
225
  --- Generation Statistics ---`),H.info(`Files processed: ${a.filesProcessed}`),H.info(`Files generated: ${a.filesGenerated}`),o>0)H.info(`Files cached: ${o}`);if(a.filesFailed>0)H.info(`Files failed: ${a.filesFailed}`);if(H.info(`Declarations found: ${a.declarationsFound}`),H.info(`Imports processed: ${a.importsProcessed}`),H.info(`Exports processed: ${a.exportsProcessed}`),a.filesValidated>0){if(H.info(`Files validated: ${a.filesValidated}`),a.validationErrors>0)H.info(`Validation errors: ${a.validationErrors}`)}if(H.info(`Duration: ${a.durationMs}ms`),a.errors.length>0){H.info(`
226
226
  Errors:`);for(let C of a.errors){let x=` - ${C.file}`;if(C.location)x+=`:${C.location.line}:${C.location.column}`;if(C.code)x+=` [${C.code}]`;if(x+=`: ${C.message}`,H.info(x),C.suggestion)H.info(` Suggestion: ${C.suggestion}`)}}H.info(`-----------------------------
227
- `)}if(r.plugins&&r.plugins.length>0)await n.runOnEnd(a);return H.debug("DTS generation complete!"),a}async function Bl(e){try{return await Xd(e)}catch{return rt(e)}}async function im(e){let t=rt(e.cwd,e.outdir);if(e.bundle&&e.bundleOutput){if(ds(e.bundleOutput))throw Error("bundleOutput must be relative to outdir");let i=rt(t,e.bundleOutput);if(!Fi(i,t))throw Error("bundleOutput must stay within outdir")}if(!e.clean||e.dryRun)return;if(t===tm(t).root)throw Error("Refusing to clean declarations from the filesystem root");let[r,n]=await Promise.all([Bl(t),Bl(rt(e.cwd,e.root))]);if(Fi(n,r))throw Error("Refusing to clean an outdir that contains the source root")}function nm(e){let t=Sr.get(e);if(!t){if(t=new Vl(e),Sr.set(e,t),Sr.size>rm){let r=Sr.keys().next().value;if(r!==void 0)Sr.delete(r)}}return t}async function sm(e){let t=rt(e.cwd,e.outdir);async function r(n){let i;try{i=await qd(n,{withFileTypes:!0})}catch{return}await Promise.all(i.map(async(s)=>{let a=rt(n,s.name);if(s.isDirectory()){await r(a);return}if(s.name.endsWith(".d.ts")||s.name.endsWith(".d.mts")||s.name.endsWith(".d.cts")||s.name.endsWith(".d.ts.map")||s.name.endsWith(".d.mts.map")||s.name.endsWith(".d.cts.map"))await zd(a,{force:!0})}))}await r(t)}function us(e,t,r){if(!t||t.length===0)return!1;let n=De(r,e);for(let i of t){let s=nm(i);if(s.match(n)||s.match(e))return!0}return!1}async function am(e){let t=[],r=rt(e.cwd,e.root),n=e.exclude||[],i=[...e.entrypoints,...e.include??[]];for(let s of i)if(ds(s)&&hs(s)){if(!s.includes("node_modules")){if(!Fi(s,r)&&e.outputStructure!=="flat")H.warn(`Skipping entrypoint outside root: ${De(e.cwd,s)}`);else if(!us(s,n,r))t.push(s)}}else{let a=new Vl(s);for await(let o of a.scan({cwd:r,absolute:!0,onlyFiles:!0}))if(hs(o)&&!o.includes("node_modules")){if(!us(o,n,r))t.push(o)}}return[...new Set(t)].sort()}function Fi(e,t){let r=De(t,e);return r!==".."&&!r.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!ds(r)}function om(e,t){let r=new Map;for(let n of e){let i=xr(n,t),s=r.get(i);if(s&&s!==n)throw Error(`Output path collision: ${De(t.cwd,s)} and ${De(t.cwd,n)} both emit ${De(t.cwd,i)}`);r.set(i,n)}}function hs(e){return/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/.test(e)&&!/\.d\.(?:ts|mts|cts)$/.test(e)}function xr(e,t){let r=rt(t.cwd,t.root),n=De(r,e).replace(/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/,(i)=>{if(i===".mts"||i===".mjs")return".d.mts";if(i===".cts"||i===".cjs")return".d.cts";return".d.ts"});if(t.outputStructure==="mirror")return rt(t.cwd,t.outdir,n);else{let i=n.split("/").pop();return rt(t.cwd,t.outdir,i)}}function lm(e,t,r=""){let n=De(Ar(e),t).replace(/\\/g,"/");if(n=n.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),r)n+=r;if(!n.startsWith("."))n=`./${n}`;return n}function cm(e,t,r){let n=xr(t,r),i=(s)=>{let a=Ir(s,t);if(!a.isRelative||!a.resolved)return s;if(/\.d\.(?:ts|mts|cts)$/.test(a.resolved))return s;let o=s.match(/[?#].*$/)?.[0]??"",c=o?s.slice(0,-o.length):s,f=em(c),u=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(f)?f:"";return lm(n,xr(a.resolved,r),u)+o};return e.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,a,o,c)=>{return`${a}${o}${i(c)}${o}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,a,o,c)=>{return`${a}${o}${i(c)}${o}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,a,o,c)=>{return`${a}${o}${i(c)}${o}`})}async function fm(e,t,r,n,i){let s=t;if(n)s=await n.runOnBeforeFile(e,t);let a=Jr(s,e,r.keepComments,r.isolatedDeclarations??!1);if(n)a=await n.runOnDeclarations(e,s,a);let o=0,c=0;for(let u=0;u<a.length;u++){let l=a[u];if(l.kind==="import")o++;if(l.kind==="export"||l.isExported)c++}let f=Ja(a,{filePath:e,sourceCode:s,declarations:a},r.keepComments,r.importOrder);if(f=cm(f,e,r),i)f=ka(f,i,{filePath:e});if(r.normalizeOutput===!0||r.declarationOrder)f=Ns(f,{lineEnding:"lf",declarationOrder:r.declarationOrder,indent:{style:r.indentStyle??"spaces",size:r.indentSize??2}});if(n)f=await n.runOnAfterFile(e,s,f);return{content:f,declarationCount:a.length,importCount:o,exportCount:c}}var Vl,rm=50,Sr;var Hl=ae(()=>{Rs();Is();Ls();va();Ra();Ma();Da();La();Ua();gn();wa();Wl();Tl();kr();ro();({Glob:Vl}=globalThis.Bun);Sr=new Map});var jl=ae(()=>{Hl()});var Xl={};hc(Xl,{dtsWatch:()=>Em,dtsCheck:()=>vm,dts:()=>ps,default:()=>Sm,clearCache:()=>bm,PluginErrorCodes:()=>Cm,DtsxPluginError:()=>sr});import{createHash as hm}from"crypto";import{existsSync as dm,readFileSync as mm,writeFileSync as pm}from"fs";import{dirname as gm,join as ym,relative as Kl,resolve as nr,sep as Li}from"path";import Ul from"process";class Yl{listeners=new Map;on(e,t){let r=this.listeners.get(e)||[];r.push(t),this.listeners.set(e,r)}async emit(e,t){let r={type:e,timestamp:Date.now(),data:t},n=this.listeners.get(e)||[];for(let i of n)await i(r)}}class ms{manifest;cacheDir;manifestPath;constructor(e,t){this.cacheDir=e,this.manifestPath=ym(e,"manifest.json"),this.manifest=this.loadManifest(t)}loadManifest(e){try{if(dm(this.manifestPath)){let t=JSON.parse(mm(this.manifestPath,"utf-8"));if(t.configHash===e&&t.version==="1.0")return t}}catch{}return{version:"1.0",configHash:e,entries:{}}}save(){try{let{mkdirSync:e}=um("fs");e(this.cacheDir,{recursive:!0}),pm(this.manifestPath,JSON.stringify(this.manifest,null,2))}catch{}}getEntry(e){return this.manifest.entries[e]}setEntry(e,t){this.manifest.entries[e]=t}isValid(e,t){return this.getEntry(e)?.hash===t}clear(){this.manifest.entries={},this.save()}}function wm(e){let t={root:e.root,outdir:e.outdir,entrypoints:e.entrypoints,clean:e.clean,tsconfigPath:e.tsconfigPath};return hm("md5").update(JSON.stringify(t)).digest("hex")}function ps(e={}){let{onSuccess:t,onError:r,failOnError:n=!0,incremental:i=!1,cacheDir:s=".dtsx-cache",on:a,timeout:o=60000,continueOnError:c=!1,verbose:f=!1,...u}=e,l=new Yl;if(a){for(let[g,h]of Object.entries(a))if(h)l.on(g,h)}return{name:"bun-plugin-dtsx",async setup(g){let h=Date.now(),w=null,v=0;try{let C=ql(u,g),x=wm(C);if(C.clean){let E=nr(C.cwd??Ul.cwd(),C.outdir??"./dist");if(Jl.has(E))C.clean=!1;else Jl.add(E)}if(i)w=new ms(nr(s),x);if(await l.emit("start",{type:"start",files:C.entrypoints||[],config:C}),f){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),i)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let R=await(async()=>{return new Promise((E,G)=>{let re=setTimeout(()=>{G(new sr(`Generation timed out after ${o}ms`,"TIMEOUT_ERROR",{timeout:o}))},o);Ni(C).then((I)=>{clearTimeout(re),E(I)}).catch((I)=>{clearTimeout(re),G(I)})})})(),k=Date.now()-h;if(w)w.save();if(await l.emit("complete",{type:"complete",stats:R,duration:k,fromCache:v}),f){if(console.log(`[bun-plugin-dtsx] Generation complete in ${k}ms`),v>0)console.log(`[bun-plugin-dtsx] ${v} files served from cache`)}if(t)await t(R)}catch(C){let x=Zl(C);if(await l.emit("error",{type:"error",error:x}),r)await r(x);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${x.code}`),console.error(` Message: ${x.message}`),x.context)console.error(` Context: ${JSON.stringify(x.context)}`);if(f&&x.stack)console.error(` Stack: ${x.stack}`)}if(n&&!c)throw x}}}}function Zl(e){if(e instanceof sr)return e;if(e instanceof Error){let t="GENERATION_ERROR";if(e.message.includes("config")||e.message.includes("Config"))t="CONFIG_ERROR";else if(e.message.includes("file")||e.message.includes("File")||e.message.includes("ENOENT"))t="FILE_ERROR";return new sr(e.message,t,{originalError:e.name},e)}return new sr(String(e),"GENERATION_ERROR")}function $m(e){let t=e.map((n)=>gm(n).split(Li)),r=t[0];for(let n of t.slice(1)){let i=0;while(i<r.length&&i<n.length&&r[i]===n[i])i++;r=r.slice(0,i)}return r.join(Li)||Li}function ql(e,t){let r=e.cwd||Ul.cwd(),n=t?.config?.entrypoints,i=e.outdir||e.build?.config.outdir||t?.config.outdir||"./dist",s=e.root||e.build?.config.root||t?.config.root;if(!s&&n?.length){let o=$m(n.map((c)=>nr(r,c)));s=Kl(r,o)||"."}s=s||"./src";let a=e.entrypoints;if(!a)if(n?.length){let o=nr(r,s),c=[];for(let f of n){let u=nr(r,f);if(u===o||u.startsWith(o+Li))c.push(Kl(o,u));else console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${s}": ${f}`)}a=c.length?c:["index.ts"]}else a=["index.ts"];return{...e,cwd:r,root:s,entrypoints:a,outdir:i,clean:e.clean??!0,tsconfigPath:e.tsconfigPath}}function Em(e={}){return ps({...e,incremental:!0,verbose:e.verbose??!0})}function vm(e){return{name:"bun-plugin-dtsx-check",async setup(t){let r=ql({...e,outdir:""},t);try{await Ni({...r,clean:!1})}catch(n){let i=Zl(n);if(e.onError)await e.onError(i);if(e.failOnError!==!1)throw i}}}}function bm(e=".dtsx-cache"){new ms(nr(e),"").clear()}var um,Cm,sr,Jl,Sm;var zl=ae(()=>{jl();um=import.meta.require,Cm={CONFIG_ERROR:"CONFIG_ERROR",GENERATION_ERROR:"GENERATION_ERROR",FILE_ERROR:"FILE_ERROR",CACHE_ERROR:"CACHE_ERROR",TIMEOUT_ERROR:"TIMEOUT_ERROR"};sr=class sr extends Error{code;context;cause;constructor(e,t,r,n){super(e);if(this.name="DtsxPluginError",this.code=t,this.context=r,this.cause=n,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}};Jl=new Set;Sm=ps});import{mkdir as Am,stat as xm}from"fs/promises";import{bold as gs,dim as ys,green as Tm,italic as Ql,log as Rm}from"@stacksjs/cli";import{path as st}from"@stacksjs/path";import{glob as ec}from"@stacksjs/storage";async function Om(e){let t=await ec([st.resolve(e,"dist","**/*.d.ts")],{absolute:!0}),r=new Bun.Transpiler({loader:"ts",target:"bun"});for(let n of t){let i=await Bun.file(n).text();try{r.transformSync(i)}catch(s){throw Error(`Invalid declaration generated at ${n}: ${s instanceof Error?s.message:String(s)}`)}}}async function E0(e){let r=Date.now()-e.startTime,n=e.pkgName??`@stacksjs/${st.basename(e.dir)}`;if(e.result.errors&&e.result.errors.length>0)throw console.error("Build errors:",e.result.errors),Error(`Build failed with errors: ${JSON.stringify(e.result.errors)}`);else if(e.result.success!==void 0&&!e.result.success){let s=e.result.logs?.[0]||"Unknown build error";throw console.log(s),Error(`Build failed: ${s}`)}await Om(e.dir);let i=await ec([st.resolve(e.dir,"dist","**/*")],{absolute:!0});for(let s of i){let a=await xm(s),o;if(a.size<1048576)o=`${(a.size/1024).toFixed(2)}kb`;else o=`${(a.size/1024/1024).toFixed(2)}mb`;let c=st.relative(e.dir,s).replace("dist/","");console.log(`${gs(ys(`[${o}]`))} ${ys("dist/")}${c}`)}console.log(`${gs(ys(`[${r}ms]`))} Built ${Ql(gs(Tm(n)))}`)}async function v0(e){let t=e.pkgName??`@stacksjs/${st.basename(e.dir)}`;if(e.styled===!1)console.log(`Building ${t}...`);else Rm.info(`Building ${Ql(t)}...`);return{startTime:Date.now()}}async function b0(e){let{dts:t}=await Promise.resolve().then(() => (zl(),Xl)),r=st.resolve(e.dir,"src"),n=st.resolve(e.dir,"dist"),i=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:r}))).filter((a)=>!a.endsWith(".d.ts")).filter((a)=>!a.endsWith(".test.ts")&&!a.endsWith(".spec.ts"));await Bun.build({entrypoints:i.map((a)=>st.resolve(r,a)),outdir:n,root:r,target:"bun",format:"esm",splitting:!1,external:e.external??Pm(),plugins:[t({root:r,outdir:n})]});let s=new Bun.Transpiler({loader:"ts",target:"bun",minifyWhitespace:!0});for(let a of i){let o=s.transformSync(await Bun.file(st.resolve(r,a)).text());o=o.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let c=st.resolve(n,a.replace(/\.ts$/,".js"));await Am(st.dirname(c),{recursive:!0}),await Bun.write(c,o)}}function Pm(e=[]){let t=[];try{let r=Ye("fs"),n=JSON.parse(r.readFileSync(`${process.cwd()}/package.json`,"utf8"));t=[...Object.keys(n.dependencies??{}),...Object.keys(n.peerDependencies??{}),...Object.keys(n.optionalDependencies??{})]}catch{}return["@stacksjs/*",...t,"bun-queue","ioredis","localtunnels","localtunnels/*","@craft-native/ts","ts-md","meilisearch","algoliasearch","@opensearch-project/opensearch","*.yaml","*.yml",...e]}export{Om as validateDeclarations,b0 as transpilePackage,E0 as outro,v0 as intro,Pm as frameworkExternal};
227
+ `)}if(r.plugins&&r.plugins.length>0)await n.runOnEnd(a);return H.debug("DTS generation complete!"),a}async function Bl(e){try{return await Xd(e)}catch{return rt(e)}}async function im(e){let t=rt(e.cwd,e.outdir);if(e.bundle&&e.bundleOutput){if(ds(e.bundleOutput))throw Error("bundleOutput must be relative to outdir");let i=rt(t,e.bundleOutput);if(!Fi(i,t))throw Error("bundleOutput must stay within outdir")}if(!e.clean||e.dryRun)return;if(t===tm(t).root)throw Error("Refusing to clean declarations from the filesystem root");let[r,n]=await Promise.all([Bl(t),Bl(rt(e.cwd,e.root))]);if(Fi(n,r))throw Error("Refusing to clean an outdir that contains the source root")}function nm(e){let t=Sr.get(e);if(!t){if(t=new Vl(e),Sr.set(e,t),Sr.size>rm){let r=Sr.keys().next().value;if(r!==void 0)Sr.delete(r)}}return t}async function sm(e){let t=rt(e.cwd,e.outdir);async function r(n){let i;try{i=await qd(n,{withFileTypes:!0})}catch{return}await Promise.all(i.map(async(s)=>{let a=rt(n,s.name);if(s.isDirectory()){await r(a);return}if(s.name.endsWith(".d.ts")||s.name.endsWith(".d.mts")||s.name.endsWith(".d.cts")||s.name.endsWith(".d.ts.map")||s.name.endsWith(".d.mts.map")||s.name.endsWith(".d.cts.map"))await zd(a,{force:!0})}))}await r(t)}function us(e,t,r){if(!t||t.length===0)return!1;let n=De(r,e);for(let i of t){let s=nm(i);if(s.match(n)||s.match(e))return!0}return!1}async function am(e){let t=[],r=rt(e.cwd,e.root),n=e.exclude||[],i=[...e.entrypoints,...e.include??[]];for(let s of i)if(ds(s)&&hs(s)){if(!s.includes("node_modules")){if(!Fi(s,r)&&e.outputStructure!=="flat")H.warn(`Skipping entrypoint outside root: ${De(e.cwd,s)}`);else if(!us(s,n,r))t.push(s)}}else{let a=new Vl(s);for await(let o of a.scan({cwd:r,absolute:!0,onlyFiles:!0}))if(hs(o)&&!o.includes("node_modules")){if(!us(o,n,r))t.push(o)}}return[...new Set(t)].sort()}function Fi(e,t){let r=De(t,e);return r!==".."&&!r.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!ds(r)}function om(e,t){let r=new Map;for(let n of e){let i=xr(n,t),s=r.get(i);if(s&&s!==n)throw Error(`Output path collision: ${De(t.cwd,s)} and ${De(t.cwd,n)} both emit ${De(t.cwd,i)}`);r.set(i,n)}}function hs(e){return/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/.test(e)&&!/\.d\.(?:ts|mts|cts)$/.test(e)}function xr(e,t){let r=rt(t.cwd,t.root),n=De(r,e).replace(/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/,(i)=>{if(i===".mts"||i===".mjs")return".d.mts";if(i===".cts"||i===".cjs")return".d.cts";return".d.ts"});if(t.outputStructure==="mirror")return rt(t.cwd,t.outdir,n);else{let i=n.split("/").pop();return rt(t.cwd,t.outdir,i)}}function lm(e,t,r=""){let n=De(Ar(e),t).replace(/\\/g,"/");if(n=n.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),r)n+=r;if(!n.startsWith("."))n=`./${n}`;return n}function cm(e,t,r){let n=xr(t,r),i=(s)=>{let a=Ir(s,t);if(!a.isRelative||!a.resolved)return s;if(/\.d\.(?:ts|mts|cts)$/.test(a.resolved))return s;let o=s.match(/[?#].*$/)?.[0]??"",c=o?s.slice(0,-o.length):s,f=em(c),u=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(f)?f:"";return lm(n,xr(a.resolved,r),u)+o};return e.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,a,o,c)=>{return`${a}${o}${i(c)}${o}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,a,o,c)=>{return`${a}${o}${i(c)}${o}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,a,o,c)=>{return`${a}${o}${i(c)}${o}`})}async function fm(e,t,r,n,i){let s=t;if(n)s=await n.runOnBeforeFile(e,t);let a=Jr(s,e,r.keepComments,r.isolatedDeclarations??!1);if(n)a=await n.runOnDeclarations(e,s,a);let o=0,c=0;for(let u=0;u<a.length;u++){let l=a[u];if(l.kind==="import")o++;if(l.kind==="export"||l.isExported)c++}let f=Ja(a,{filePath:e,sourceCode:s,declarations:a},r.keepComments,r.importOrder);if(f=cm(f,e,r),i)f=ka(f,i,{filePath:e});if(r.normalizeOutput===!0||r.declarationOrder)f=Ns(f,{lineEnding:"lf",declarationOrder:r.declarationOrder,indent:{style:r.indentStyle??"spaces",size:r.indentSize??2}});if(n)f=await n.runOnAfterFile(e,s,f);return{content:f,declarationCount:a.length,importCount:o,exportCount:c}}var Vl,rm=50,Sr;var Hl=ae(()=>{Rs();Is();Ls();va();Ra();Ma();Da();La();Ua();gn();wa();Wl();Tl();kr();ro();({Glob:Vl}=globalThis.Bun);Sr=new Map});var jl=ae(()=>{Hl()});var Xl={};hc(Xl,{dtsWatch:()=>Em,dtsCheck:()=>vm,dts:()=>ps,default:()=>Sm,clearCache:()=>bm,PluginErrorCodes:()=>Cm,DtsxPluginError:()=>sr});import{createHash as hm}from"crypto";import{existsSync as dm,readFileSync as mm,writeFileSync as pm}from"fs";import{dirname as gm,join as ym,relative as Kl,resolve as nr,sep as Li}from"path";import Ul from"process";class Yl{listeners=new Map;on(e,t){let r=this.listeners.get(e)||[];r.push(t),this.listeners.set(e,r)}async emit(e,t){let r={type:e,timestamp:Date.now(),data:t},n=this.listeners.get(e)||[];for(let i of n)await i(r)}}class ms{manifest;cacheDir;manifestPath;constructor(e,t){this.cacheDir=e,this.manifestPath=ym(e,"manifest.json"),this.manifest=this.loadManifest(t)}loadManifest(e){try{if(dm(this.manifestPath)){let t=JSON.parse(mm(this.manifestPath,"utf-8"));if(t.configHash===e&&t.version==="1.0")return t}}catch{}return{version:"1.0",configHash:e,entries:{}}}save(){try{let{mkdirSync:e}=um("fs");e(this.cacheDir,{recursive:!0}),pm(this.manifestPath,JSON.stringify(this.manifest,null,2))}catch{}}getEntry(e){return this.manifest.entries[e]}setEntry(e,t){this.manifest.entries[e]=t}isValid(e,t){return this.getEntry(e)?.hash===t}clear(){this.manifest.entries={},this.save()}}function wm(e){let t={root:e.root,outdir:e.outdir,entrypoints:e.entrypoints,clean:e.clean,tsconfigPath:e.tsconfigPath};return hm("md5").update(JSON.stringify(t)).digest("hex")}function ps(e={}){let{onSuccess:t,onError:r,failOnError:n=!0,incremental:i=!1,cacheDir:s=".dtsx-cache",on:a,timeout:o=60000,continueOnError:c=!1,verbose:f=!1,...u}=e,l=new Yl;if(a){for(let[g,h]of Object.entries(a))if(h)l.on(g,h)}return{name:"bun-plugin-dtsx",async setup(g){let h=Date.now(),w=null,v=0;try{let C=ql(u,g),x=wm(C);if(C.clean){let E=nr(C.cwd??Ul.cwd(),C.outdir??"./dist");if(Jl.has(E))C.clean=!1;else Jl.add(E)}if(i)w=new ms(nr(s),x);if(await l.emit("start",{type:"start",files:C.entrypoints||[],config:C}),f){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),i)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let R=await(async()=>{return new Promise((E,G)=>{let re=setTimeout(()=>{G(new sr(`Generation timed out after ${o}ms`,"TIMEOUT_ERROR",{timeout:o}))},o);Ni(C).then((I)=>{clearTimeout(re),E(I)}).catch((I)=>{clearTimeout(re),G(I)})})})(),k=Date.now()-h;if(w)w.save();if(await l.emit("complete",{type:"complete",stats:R,duration:k,fromCache:v}),f){if(console.log(`[bun-plugin-dtsx] Generation complete in ${k}ms`),v>0)console.log(`[bun-plugin-dtsx] ${v} files served from cache`)}if(t)await t(R)}catch(C){let x=Zl(C);if(await l.emit("error",{type:"error",error:x}),r)await r(x);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${x.code}`),console.error(` Message: ${x.message}`),x.context)console.error(` Context: ${JSON.stringify(x.context)}`);if(f&&x.stack)console.error(` Stack: ${x.stack}`)}if(n&&!c)throw x}}}}function Zl(e){if(e instanceof sr)return e;if(e instanceof Error){let t="GENERATION_ERROR";if(e.message.includes("config")||e.message.includes("Config"))t="CONFIG_ERROR";else if(e.message.includes("file")||e.message.includes("File")||e.message.includes("ENOENT"))t="FILE_ERROR";return new sr(e.message,t,{originalError:e.name},e)}return new sr(String(e),"GENERATION_ERROR")}function $m(e){let t=e.map((n)=>gm(n).split(Li)),r=t[0];for(let n of t.slice(1)){let i=0;while(i<r.length&&i<n.length&&r[i]===n[i])i++;r=r.slice(0,i)}return r.join(Li)||Li}function ql(e,t){let r=e.cwd||Ul.cwd(),n=t?.config?.entrypoints,i=e.outdir||e.build?.config.outdir||t?.config.outdir||"./dist",s=e.root||e.build?.config.root||t?.config.root;if(!s&&n?.length){let o=$m(n.map((c)=>nr(r,c)));s=Kl(r,o)||"."}s=s||"./src";let a=e.entrypoints;if(!a)if(n?.length){let o=nr(r,s),c=[];for(let f of n){let u=nr(r,f);if(u===o||u.startsWith(o+Li))c.push(Kl(o,u));else console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${s}": ${f}`)}a=c.length?c:["index.ts"]}else a=["index.ts"];return{...e,cwd:r,root:s,entrypoints:a,outdir:i,clean:e.clean??!0,tsconfigPath:e.tsconfigPath}}function Em(e={}){return ps({...e,incremental:!0,verbose:e.verbose??!0})}function vm(e){return{name:"bun-plugin-dtsx-check",async setup(t){let r=ql({...e,outdir:""},t);try{await Ni({...r,clean:!1})}catch(n){let i=Zl(n);if(e.onError)await e.onError(i);if(e.failOnError!==!1)throw i}}}}function bm(e=".dtsx-cache"){new ms(nr(e),"").clear()}var um,Cm,sr,Jl,Sm;var zl=ae(()=>{jl();um=import.meta.require,Cm={CONFIG_ERROR:"CONFIG_ERROR",GENERATION_ERROR:"GENERATION_ERROR",FILE_ERROR:"FILE_ERROR",CACHE_ERROR:"CACHE_ERROR",TIMEOUT_ERROR:"TIMEOUT_ERROR"};sr=class sr extends Error{code;context;cause;constructor(e,t,r,n){super(e);if(this.name="DtsxPluginError",this.code=t,this.context=r,this.cause=n,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}};Jl=new Set;Sm=ps});import{mkdir as Am,stat as xm}from"fs/promises";import{bold as gs,dim as ys,green as Tm,italic as Ql,log as Rm}from"@stacksjs/cli";import{path as st}from"@stacksjs/path";import{glob as ec}from"@stacksjs/storage";async function Om(e){let t=await ec([st.resolve(e,"dist","**/*.d.ts")],{absolute:!0}),r=new Bun.Transpiler({loader:"ts",target:"bun"});for(let n of t){let i=await Bun.file(n).text();try{r.transformSync(i)}catch(s){throw Error(`Invalid declaration generated at ${n}: ${s instanceof Error?s.message:String(s)}`)}}}async function E0(e){let r=Date.now()-e.startTime,n=e.pkgName??`@stacksjs/${st.basename(e.dir)}`;if(e.result.errors&&e.result.errors.length>0)throw console.error("Build errors:",e.result.errors),Error(`Build failed with errors: ${JSON.stringify(e.result.errors)}`);else if(e.result.success!==void 0&&!e.result.success){let s=e.result.logs?.[0]||"Unknown build error";throw console.log(s),Error(`Build failed: ${s}`)}await Om(e.dir);let i=await ec([st.resolve(e.dir,"dist","**/*")],{absolute:!0});for(let s of i){let a=await xm(s),o;if(a.size<1048576)o=`${(a.size/1024).toFixed(2)}kb`;else o=`${(a.size/1024/1024).toFixed(2)}mb`;let c=st.relative(e.dir,s).replace("dist/","");console.log(`${gs(ys(`[${o}]`))} ${ys("dist/")}${c}`)}console.log(`${gs(ys(`[${r}ms]`))} Built ${Ql(gs(Tm(n)))}`)}async function v0(e){let t=e.pkgName??`@stacksjs/${st.basename(e.dir)}`;if(e.styled===!1)console.log(`Building ${t}...`);else Rm.info(`Building ${Ql(t)}...`);return{startTime:Date.now()}}async function b0(e){let{dts:t}=await Promise.resolve().then(() => (zl(),Xl)),r=st.resolve(e.dir,"src"),n=st.resolve(e.dir,"dist"),i=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:r}))).filter((a)=>!a.endsWith(".d.ts")).filter((a)=>!a.endsWith(".test.ts")&&!a.endsWith(".spec.ts"));await Bun.build({entrypoints:i.map((a)=>st.resolve(r,a)),outdir:n,root:r,target:"bun",format:"esm",splitting:!1,external:e.external??Pm(),plugins:[t({root:r,outdir:n})]});let s=new Bun.Transpiler({loader:"ts",target:"bun",minifyWhitespace:!0});for(let a of i){let o=s.transformSync(await Bun.file(st.resolve(r,a)).text());o=o.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let c=st.resolve(n,a.replace(/\.ts$/,".js"));await Am(st.dirname(c),{recursive:!0}),await Bun.write(c,o)}}function Pm(e=[]){let t=[];try{let r=Ye("fs"),n=JSON.parse(r.readFileSync(`${process.cwd()}/package.json`,"utf8"));t=[...Object.keys(n.dependencies??{}),...Object.keys(n.peerDependencies??{}),...Object.keys(n.optionalDependencies??{})]}catch{}return["@stacksjs/*",...t,...t.map((r)=>`${r}/*`),"bun-queue","ioredis","localtunnels","localtunnels/*","@craft-native/ts","ts-md","meilisearch","algoliasearch","@opensearch-project/opensearch","*.yaml","*.yml",...e]}export{Om as validateDeclarations,b0 as transpilePackage,E0 as outro,v0 as intro,Pm as frameworkExternal};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/build",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.371",
5
+ "version": "0.70.376",
6
6
  "description": "The Stacks framework build tools and configurations.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -59,9 +59,9 @@
59
59
  },
60
60
  "dependencies": {},
61
61
  "devDependencies": {
62
- "@stacksjs/cli": "0.70.371",
62
+ "@stacksjs/cli": "0.70.376",
63
63
  "better-dx": "^0.2.17",
64
- "@stacksjs/path": "0.70.371",
65
- "@stacksjs/storage": "0.70.371"
64
+ "@stacksjs/path": "0.70.376",
65
+ "@stacksjs/storage": "0.70.376"
66
66
  }
67
67
  }