@stacksjs/build 0.70.258 → 0.70.260

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 +14 -7
package/dist/index.js CHANGED
@@ -219,4 +219,4 @@ ${Y}`);else K.debug(`[no changes] ${S}`)}catch{K.info(`[new file] ${Pe(r.cwd,S)}
219
219
  `);if(r.failOnUnresolvedReExport)throw Error(T);K.warn(T),K.warn('Generated .d.ts files reference modules that were not emitted \u2014 consumers will see "has no exported member" errors.')}}if(r.bundle&&(o.filesGenerated>0||a>0)&&f.length>0)try{K.debug("Bundling declarations...");let $=new Map,O=async(S)=>{let W=$.get(S);if(W!==void 0)return W;return W=await ct(S),$.set(S,W),W};for(let S of c)await O(S);let T=f.length===1&&!!r.bundleOutput;for(let S of f){let W=await Zi([S],{includeImports:!0}),b=new Set;for(let X of W.reachable){if(X.endsWith(".d.ts"))continue;if(X.includes("node_modules"))continue;b.add(X)}let L=c.filter((X)=>b.has(X));if(!L.includes(S))L.push(S);let re=new Map;for(let X of L){let se=$.get(X)??await O(X);re.set(X,se)}let F=await bo(L,re,r),J=T?tt(r.cwd,r.outdir,r.bundleOutput):Or(S,r);if(r.dryRun)K.info(`[dry-run] Would bundle ${F.files.length} files to: ${Pe(r.cwd,J)}`);else await cs(Er(J),{recursive:!0}),await vr(J,F.content,r.lineEnding),K.info(`Bundled ${F.files.length} files to: ${Pe(r.cwd,J)}`);if(T)break}}catch($){let O=$ instanceof Error?$.message:String($);K.error(`Bundle failed: ${O}`)}if(o.durationMs=Date.now()-t,r.stats)if(r.outputFormat==="json")console.log(JSON.stringify(o,null,2));else{if(K.info(`
220
220
  --- Generation Statistics ---`),K.info(`Files processed: ${o.filesProcessed}`),K.info(`Files generated: ${o.filesGenerated}`),a>0)K.info(`Files cached: ${a}`);if(o.filesFailed>0)K.info(`Files failed: ${o.filesFailed}`);if(K.info(`Declarations found: ${o.declarationsFound}`),K.info(`Imports processed: ${o.importsProcessed}`),K.info(`Exports processed: ${o.exportsProcessed}`),o.filesValidated>0){if(K.info(`Files validated: ${o.filesValidated}`),o.validationErrors>0)K.info(`Validation errors: ${o.validationErrors}`)}if(K.info(`Duration: ${o.durationMs}ms`),o.errors.length>0){K.info(`
221
221
  Errors:`);for(let $ of o.errors){let O=` - ${$.file}`;if($.location)O+=`:${$.location.line}:${$.location.column}`;if($.code)O+=` [${$.code}]`;if(O+=`: ${$.message}`,K.info(O),$.suggestion)K.info(` Suggestion: ${$.suggestion}`)}}K.info(`-----------------------------
222
- `)}if(r.plugins&&r.plugins.length>0)await n.runOnEnd(o);return K.debug("DTS generation complete!"),o}async function Dl(e){try{return await jd(e)}catch{return tt(e)}}async function Gd(e){let t=tt(e.cwd,e.outdir);if(e.bundle&&e.bundleOutput){if(ds(e.bundleOutput))throw Error("bundleOutput must be relative to outdir");let i=tt(t,e.bundleOutput);if(!Di(i,t))throw Error("bundleOutput must stay within outdir")}if(!e.clean||e.dryRun)return;if(t===Hd(t).root)throw Error("Refusing to clean declarations from the filesystem root");let[r,n]=await Promise.all([Dl(t),Dl(tt(e.cwd,e.root))]);if(Di(n,r))throw Error("Refusing to clean an outdir that contains the source root")}function Vd(e){let t=xr.get(e);if(!t){if(t=new Ml(e),xr.set(e,t),xr.size>Yd){let r=xr.keys().next().value;if(r!==void 0)xr.delete(r)}}return t}async function Zd(e){let t=tt(e.cwd,e.outdir);async function r(n){let i;try{i=await Ld(n,{withFileTypes:!0})}catch{return}await Promise.all(i.map(async(s)=>{let o=tt(n,s.name);if(s.isDirectory()){await r(o);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 _d(o,{force:!0})}))}await r(t)}function us(e,t,r){if(!t||t.length===0)return!1;let n=Pe(r,e);for(let i of t){let s=Vd(i);if(s.match(n)||s.match(e))return!0}return!1}async function qd(e){let t=[],r=tt(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(!Di(s,r)&&e.outputStructure!=="flat")K.warn(`Skipping entrypoint outside root: ${Pe(e.cwd,s)}`);else if(!us(s,n,r))t.push(s)}}else{let o=new Ml(s);for await(let a of o.scan({cwd:r,absolute:!0,onlyFiles:!0}))if(hs(a)&&!a.includes("node_modules")){if(!us(a,n,r))t.push(a)}}return[...new Set(t)].sort()}function Di(e,t){let r=Pe(t,e);return r!==".."&&!r.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!ds(r)}function Ud(e,t){let r=new Map;for(let n of e){let i=Or(n,t),s=r.get(i);if(s&&s!==n)throw Error(`Output path collision: ${Pe(t.cwd,s)} and ${Pe(t.cwd,n)} both emit ${Pe(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 Or(e,t){let r=tt(t.cwd,t.root),n=Pe(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 tt(t.cwd,t.outdir,n);else{let i=n.split("/").pop();return tt(t.cwd,t.outdir,i)}}function Xd(e,t,r=""){let n=Pe(Er(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 zd(e,t,r){let n=Or(t,r),i=(s)=>{let o=Nr(s,t);if(!o.isRelative||!o.resolved)return s;if(/\.d\.(?:ts|mts|cts)$/.test(o.resolved))return s;let a=s.match(/[?#].*$/)?.[0]??"",f=a?s.slice(0,-a.length):s,c=Kd(f),u=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(c)?c:"";return Xd(n,Or(o.resolved,r),u)+a};return e.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,o,a,f)=>{return`${o}${a}${i(f)}${a}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,o,a,f)=>{return`${o}${a}${i(f)}${a}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,o,a,f)=>{return`${o}${a}${i(f)}${a}`})}async function Qd(e,t,r,n,i){let s=t;if(n)s=await n.runOnBeforeFile(e,t);let o=Gr(s,e,r.keepComments,r.isolatedDeclarations??!1);if(n)o=await n.runOnDeclarations(e,s,o);let a=0,f=0;for(let u=0;u<o.length;u++){let l=o[u];if(l.kind==="import")a++;if(l.kind==="export"||l.isExported)f++}let c=Vo(o,{filePath:e,sourceCode:s,declarations:o},r.keepComments,r.importOrder);if(c=zd(c,e,r),i)c=No(c,i,{filePath:e});if(r.normalizeOutput===!0||r.declarationOrder)c=Ds(c,{lineEnding:"lf",declarationOrder:r.declarationOrder,indent:{style:r.indentStyle??"spaces",size:r.indentSize??2}});if(n)c=await n.runOnAfterFile(e,s,c);return{content:c,declarationCount:o.length,importCount:a,exportCount:f}}var Ml,Yd=50,xr;var Bl=de(()=>{Ns();Ms();Is();vo();To();Fo();Do();Bo();Zo();pn();Co();Fl();Rr();Al();zo();({Glob:Ml}=globalThis.Bun);xr=new Map});var Ll=de(()=>{Bl()});var Gl={};lf(Gl,{dtsWatch:()=>cm,dtsCheck:()=>um,dts:()=>gs,default:()=>dm,clearCache:()=>hm,PluginErrorCodes:()=>am,DtsxPluginError:()=>sr});import{createHash as tm}from"crypto";import{existsSync as rm,readFileSync as im,writeFileSync as nm}from"fs";import{dirname as sm,join as om,relative as jl,resolve as nr,sep as Ii}from"path";import Jl from"process";class Kl{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=om(e,"manifest.json"),this.manifest=this.loadManifest(t)}loadManifest(e){try{if(rm(this.manifestPath)){let t=JSON.parse(im(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}=em("fs");e(this.cacheDir,{recursive:!0}),nm(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 lm(e){let t={root:e.root,outdir:e.outdir,entrypoints:e.entrypoints,clean:e.clean,tsconfigPath:e.tsconfigPath};return tm("md5").update(JSON.stringify(t)).digest("hex")}function gs(e={}){let{onSuccess:t,onError:r,failOnError:n=!0,incremental:i=!1,cacheDir:s=".dtsx-cache",on:o,timeout:a=60000,continueOnError:f=!1,verbose:c=!1,...u}=e,l=new Kl;if(o){for(let[p,h]of Object.entries(o))if(h)l.on(p,h)}return{name:"bun-plugin-dtsx",async setup(p){let h=Date.now(),w=null,A=0;try{let $=Yl(u,p),O=lm($);if($.clean){let b=nr($.cwd??Jl.cwd(),$.outdir??"./dist");if(_l.has(b))$.clean=!1;else _l.add(b)}if(i)w=new ms(nr(s),O);if(await l.emit("start",{type:"start",files:$.entrypoints||[],config:$}),c){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),i)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let S=await(async()=>{return new Promise((b,L)=>{let re=setTimeout(()=>{L(new sr(`Generation timed out after ${a}ms`,"TIMEOUT_ERROR",{timeout:a}))},a);Mi($).then((F)=>{clearTimeout(re),b(F)}).catch((F)=>{clearTimeout(re),L(F)})})})(),W=Date.now()-h;if(w)w.save();if(await l.emit("complete",{type:"complete",stats:S,duration:W,fromCache:A}),c){if(console.log(`[bun-plugin-dtsx] Generation complete in ${W}ms`),A>0)console.log(`[bun-plugin-dtsx] ${A} files served from cache`)}if(t)await t(S)}catch($){let O=Hl($);if(await l.emit("error",{type:"error",error:O}),r)await r(O);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${O.code}`),console.error(` Message: ${O.message}`),O.context)console.error(` Context: ${JSON.stringify(O.context)}`);if(c&&O.stack)console.error(` Stack: ${O.stack}`)}if(n&&!f)throw O}}}}function Hl(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 fm(e){let t=e.map((n)=>sm(n).split(Ii)),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(Ii)||Ii}function Yl(e,t){let r=e.cwd||Jl.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 a=fm(n.map((f)=>nr(r,f)));s=jl(r,a)||"."}s=s||"./src";let o=e.entrypoints;if(!o)if(n?.length){let a=nr(r,s),f=[];for(let c of n){let u=nr(r,c);if(u===a||u.startsWith(a+Ii))f.push(jl(a,u));else console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${s}": ${c}`)}o=f.length?f:["index.ts"]}else o=["index.ts"];return{...e,cwd:r,root:s,entrypoints:o,outdir:i,clean:e.clean??!0,tsconfigPath:e.tsconfigPath}}function cm(e={}){return gs({...e,incremental:!0,verbose:e.verbose??!0})}function um(e){return{name:"bun-plugin-dtsx-check",async setup(t){let r=Yl({...e,outdir:""},t);try{await Mi({...r,clean:!1})}catch(n){let i=Hl(n);if(e.onError)await e.onError(i);if(e.failOnError!==!1)throw i}}}}function hm(e=".dtsx-cache"){new ms(nr(e),"").clear()}var em,am,sr,_l,dm;var Vl=de(()=>{Ll();em=import.meta.require,am={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}}};_l=new Set;dm=gs});import{mkdir as mm,stat as gm}from"fs/promises";import{bold as ps,dim as ys,green as pm,italic as Zl,log as ym}from"@stacksjs/cli";import{path as st}from"@stacksjs/path";import{glob as ql}from"@stacksjs/storage";async function $m(e){let t=await ql([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 o0(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 $m(e.dir);let i=await ql([st.resolve(e.dir,"dist","**/*")],{absolute:!0});for(let s of i){let o=await gm(s),a;if(o.size<1048576)a=`${(o.size/1024).toFixed(2)}kb`;else a=`${(o.size/1024/1024).toFixed(2)}mb`;let f=st.relative(e.dir,s).replace("dist/","");console.log(`${ps(ys(`[${a}]`))} ${ys("dist/")}${f}`)}console.log(`${ps(ys(`[${r}ms]`))} Built ${Zl(ps(pm(n)))}`)}async function a0(e){let t=e.pkgName??`@stacksjs/${st.basename(e.dir)}`;if(e.styled===!1)console.log(`Building ${t}...`);else ym.info(`Building ${Zl(t)}...`);return{startTime:Date.now()}}async function l0(e){let{dts:t}=await Promise.resolve().then(() => (Vl(),Gl)),r=st.resolve(e.dir,"src"),n=st.resolve(e.dir,"dist"),i=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:r}))).filter((o)=>!o.endsWith(".d.ts"));await Bun.build({entrypoints:i.map((o)=>st.resolve(r,o)),outdir:n,root:r,target:"bun",format:"esm",splitting:!1,external:e.external??wm(),plugins:[t({root:r,outdir:n})]});let s=new Bun.Transpiler({loader:"ts",target:"bun"});for(let o of i){let a=s.transformSync(await Bun.file(st.resolve(r,o)).text());a=a.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let f=st.resolve(n,o.replace(/\.ts$/,".js"));await mm(st.dirname(f),{recursive:!0}),await Bun.write(f,a)}}function wm(e=[]){let t=[];try{let r=Ze("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{$m as validateDeclarations,l0 as transpilePackage,o0 as outro,a0 as intro,wm as frameworkExternal};
222
+ `)}if(r.plugins&&r.plugins.length>0)await n.runOnEnd(o);return K.debug("DTS generation complete!"),o}async function Dl(e){try{return await jd(e)}catch{return tt(e)}}async function Gd(e){let t=tt(e.cwd,e.outdir);if(e.bundle&&e.bundleOutput){if(ds(e.bundleOutput))throw Error("bundleOutput must be relative to outdir");let i=tt(t,e.bundleOutput);if(!Di(i,t))throw Error("bundleOutput must stay within outdir")}if(!e.clean||e.dryRun)return;if(t===Hd(t).root)throw Error("Refusing to clean declarations from the filesystem root");let[r,n]=await Promise.all([Dl(t),Dl(tt(e.cwd,e.root))]);if(Di(n,r))throw Error("Refusing to clean an outdir that contains the source root")}function Vd(e){let t=xr.get(e);if(!t){if(t=new Ml(e),xr.set(e,t),xr.size>Yd){let r=xr.keys().next().value;if(r!==void 0)xr.delete(r)}}return t}async function Zd(e){let t=tt(e.cwd,e.outdir);async function r(n){let i;try{i=await Ld(n,{withFileTypes:!0})}catch{return}await Promise.all(i.map(async(s)=>{let o=tt(n,s.name);if(s.isDirectory()){await r(o);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 _d(o,{force:!0})}))}await r(t)}function us(e,t,r){if(!t||t.length===0)return!1;let n=Pe(r,e);for(let i of t){let s=Vd(i);if(s.match(n)||s.match(e))return!0}return!1}async function qd(e){let t=[],r=tt(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(!Di(s,r)&&e.outputStructure!=="flat")K.warn(`Skipping entrypoint outside root: ${Pe(e.cwd,s)}`);else if(!us(s,n,r))t.push(s)}}else{let o=new Ml(s);for await(let a of o.scan({cwd:r,absolute:!0,onlyFiles:!0}))if(hs(a)&&!a.includes("node_modules")){if(!us(a,n,r))t.push(a)}}return[...new Set(t)].sort()}function Di(e,t){let r=Pe(t,e);return r!==".."&&!r.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!ds(r)}function Ud(e,t){let r=new Map;for(let n of e){let i=Or(n,t),s=r.get(i);if(s&&s!==n)throw Error(`Output path collision: ${Pe(t.cwd,s)} and ${Pe(t.cwd,n)} both emit ${Pe(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 Or(e,t){let r=tt(t.cwd,t.root),n=Pe(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 tt(t.cwd,t.outdir,n);else{let i=n.split("/").pop();return tt(t.cwd,t.outdir,i)}}function Xd(e,t,r=""){let n=Pe(Er(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 zd(e,t,r){let n=Or(t,r),i=(s)=>{let o=Nr(s,t);if(!o.isRelative||!o.resolved)return s;if(/\.d\.(?:ts|mts|cts)$/.test(o.resolved))return s;let a=s.match(/[?#].*$/)?.[0]??"",f=a?s.slice(0,-a.length):s,c=Kd(f),u=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(c)?c:"";return Xd(n,Or(o.resolved,r),u)+a};return e.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,o,a,f)=>{return`${o}${a}${i(f)}${a}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,o,a,f)=>{return`${o}${a}${i(f)}${a}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(s,o,a,f)=>{return`${o}${a}${i(f)}${a}`})}async function Qd(e,t,r,n,i){let s=t;if(n)s=await n.runOnBeforeFile(e,t);let o=Gr(s,e,r.keepComments,r.isolatedDeclarations??!1);if(n)o=await n.runOnDeclarations(e,s,o);let a=0,f=0;for(let u=0;u<o.length;u++){let l=o[u];if(l.kind==="import")a++;if(l.kind==="export"||l.isExported)f++}let c=Vo(o,{filePath:e,sourceCode:s,declarations:o},r.keepComments,r.importOrder);if(c=zd(c,e,r),i)c=No(c,i,{filePath:e});if(r.normalizeOutput===!0||r.declarationOrder)c=Ds(c,{lineEnding:"lf",declarationOrder:r.declarationOrder,indent:{style:r.indentStyle??"spaces",size:r.indentSize??2}});if(n)c=await n.runOnAfterFile(e,s,c);return{content:c,declarationCount:o.length,importCount:a,exportCount:f}}var Ml,Yd=50,xr;var Bl=de(()=>{Ns();Ms();Is();vo();To();Fo();Do();Bo();Zo();pn();Co();Fl();Rr();Al();zo();({Glob:Ml}=globalThis.Bun);xr=new Map});var Ll=de(()=>{Bl()});var Gl={};lf(Gl,{dtsWatch:()=>cm,dtsCheck:()=>um,dts:()=>gs,default:()=>dm,clearCache:()=>hm,PluginErrorCodes:()=>am,DtsxPluginError:()=>sr});import{createHash as tm}from"crypto";import{existsSync as rm,readFileSync as im,writeFileSync as nm}from"fs";import{dirname as sm,join as om,relative as jl,resolve as nr,sep as Ii}from"path";import Jl from"process";class Kl{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=om(e,"manifest.json"),this.manifest=this.loadManifest(t)}loadManifest(e){try{if(rm(this.manifestPath)){let t=JSON.parse(im(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}=em("fs");e(this.cacheDir,{recursive:!0}),nm(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 lm(e){let t={root:e.root,outdir:e.outdir,entrypoints:e.entrypoints,clean:e.clean,tsconfigPath:e.tsconfigPath};return tm("md5").update(JSON.stringify(t)).digest("hex")}function gs(e={}){let{onSuccess:t,onError:r,failOnError:n=!0,incremental:i=!1,cacheDir:s=".dtsx-cache",on:o,timeout:a=60000,continueOnError:f=!1,verbose:c=!1,...u}=e,l=new Kl;if(o){for(let[p,h]of Object.entries(o))if(h)l.on(p,h)}return{name:"bun-plugin-dtsx",async setup(p){let h=Date.now(),w=null,A=0;try{let $=Yl(u,p),O=lm($);if($.clean){let b=nr($.cwd??Jl.cwd(),$.outdir??"./dist");if(_l.has(b))$.clean=!1;else _l.add(b)}if(i)w=new ms(nr(s),O);if(await l.emit("start",{type:"start",files:$.entrypoints||[],config:$}),c){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),i)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let S=await(async()=>{return new Promise((b,L)=>{let re=setTimeout(()=>{L(new sr(`Generation timed out after ${a}ms`,"TIMEOUT_ERROR",{timeout:a}))},a);Mi($).then((F)=>{clearTimeout(re),b(F)}).catch((F)=>{clearTimeout(re),L(F)})})})(),W=Date.now()-h;if(w)w.save();if(await l.emit("complete",{type:"complete",stats:S,duration:W,fromCache:A}),c){if(console.log(`[bun-plugin-dtsx] Generation complete in ${W}ms`),A>0)console.log(`[bun-plugin-dtsx] ${A} files served from cache`)}if(t)await t(S)}catch($){let O=Hl($);if(await l.emit("error",{type:"error",error:O}),r)await r(O);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${O.code}`),console.error(` Message: ${O.message}`),O.context)console.error(` Context: ${JSON.stringify(O.context)}`);if(c&&O.stack)console.error(` Stack: ${O.stack}`)}if(n&&!f)throw O}}}}function Hl(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 fm(e){let t=e.map((n)=>sm(n).split(Ii)),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(Ii)||Ii}function Yl(e,t){let r=e.cwd||Jl.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 a=fm(n.map((f)=>nr(r,f)));s=jl(r,a)||"."}s=s||"./src";let o=e.entrypoints;if(!o)if(n?.length){let a=nr(r,s),f=[];for(let c of n){let u=nr(r,c);if(u===a||u.startsWith(a+Ii))f.push(jl(a,u));else console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${s}": ${c}`)}o=f.length?f:["index.ts"]}else o=["index.ts"];return{...e,cwd:r,root:s,entrypoints:o,outdir:i,clean:e.clean??!0,tsconfigPath:e.tsconfigPath}}function cm(e={}){return gs({...e,incremental:!0,verbose:e.verbose??!0})}function um(e){return{name:"bun-plugin-dtsx-check",async setup(t){let r=Yl({...e,outdir:""},t);try{await Mi({...r,clean:!1})}catch(n){let i=Hl(n);if(e.onError)await e.onError(i);if(e.failOnError!==!1)throw i}}}}function hm(e=".dtsx-cache"){new ms(nr(e),"").clear()}var em,am,sr,_l,dm;var Vl=de(()=>{Ll();em=import.meta.require,am={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}}};_l=new Set;dm=gs});import{mkdir as mm,stat as gm}from"fs/promises";import{bold as ps,dim as ys,green as pm,italic as Zl,log as ym}from"@stacksjs/cli";import{path as st}from"@stacksjs/path";import{glob as ql}from"@stacksjs/storage";async function $m(e){let t=await ql([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 o0(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 $m(e.dir);let i=await ql([st.resolve(e.dir,"dist","**/*")],{absolute:!0});for(let s of i){let o=await gm(s),a;if(o.size<1048576)a=`${(o.size/1024).toFixed(2)}kb`;else a=`${(o.size/1024/1024).toFixed(2)}mb`;let f=st.relative(e.dir,s).replace("dist/","");console.log(`${ps(ys(`[${a}]`))} ${ys("dist/")}${f}`)}console.log(`${ps(ys(`[${r}ms]`))} Built ${Zl(ps(pm(n)))}`)}async function a0(e){let t=e.pkgName??`@stacksjs/${st.basename(e.dir)}`;if(e.styled===!1)console.log(`Building ${t}...`);else ym.info(`Building ${Zl(t)}...`);return{startTime:Date.now()}}async function l0(e){let{dts:t}=await Promise.resolve().then(() => (Vl(),Gl)),r=st.resolve(e.dir,"src"),n=st.resolve(e.dir,"dist"),i=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:r}))).filter((o)=>!o.endsWith(".d.ts"));await Bun.build({entrypoints:i.map((o)=>st.resolve(r,o)),outdir:n,root:r,target:"bun",format:"esm",splitting:!1,external:e.external??wm(),plugins:[t({root:r,outdir:n})]});let s=new Bun.Transpiler({loader:"ts",target:"bun",minifyWhitespace:!0});for(let o of i){let a=s.transformSync(await Bun.file(st.resolve(r,o)).text());a=a.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let f=st.resolve(n,o.replace(/\.ts$/,".js"));await mm(st.dirname(f),{recursive:!0}),await Bun.write(f,a)}}function wm(e=[]){let t=[];try{let r=Ze("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{$m as validateDeclarations,l0 as transpilePackage,o0 as outro,a0 as intro,wm 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.258",
5
+ "version": "0.70.260",
6
6
  "description": "The Stacks framework build tools and configurations.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -34,9 +34,16 @@
34
34
  "default": "./dist/index.js"
35
35
  },
36
36
  "./*": {
37
- "bun": "./dist/*",
38
- "import": "./dist/*",
39
- "default": "./dist/*"
37
+ "types": "./dist/*.d.ts",
38
+ "bun": "./dist/*.js",
39
+ "import": "./dist/*.js",
40
+ "default": "./dist/*.js"
41
+ },
42
+ "./*.js": {
43
+ "types": "./dist/*.d.ts",
44
+ "bun": "./dist/*.js",
45
+ "import": "./dist/*.js",
46
+ "default": "./dist/*.js"
40
47
  }
41
48
  },
42
49
  "module": "dist/index.js",
@@ -52,9 +59,9 @@
52
59
  },
53
60
  "dependencies": {},
54
61
  "devDependencies": {
55
- "@stacksjs/cli": "0.70.258",
62
+ "@stacksjs/cli": "0.70.260",
56
63
  "better-dx": "^0.2.17",
57
- "@stacksjs/path": "0.70.258",
58
- "@stacksjs/storage": "0.70.258"
64
+ "@stacksjs/path": "0.70.260",
65
+ "@stacksjs/storage": "0.70.260"
59
66
  }
60
67
  }