@stacksjs/build 0.70.59 → 0.70.61
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 +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -680,4 +680,4 @@ ${Sh}`);else C8.debug(`[no changes] ${Wf}`)}catch{C8.info(`[new file] ${ej(g.cwd
|
|
|
680
680
|
`);if(g.failOnUnresolvedReExport)throw Error(N0);C8.warn(N0),C8.warn('Generated .d.ts files reference modules that were not emitted \u2014 consumers will see "has no exported member" errors.')}}if(g.bundle&&(F.filesGenerated>0||O>0)&&G.length>0)try{C8.debug("Bundling declarations...");let J0=new Map,Rf=async(Wf)=>{let Uf=J0.get(Wf);if(Uf!==void 0)return Uf;return Uf=await tH(Wf),J0.set(Wf,Uf),Uf};for(let Wf of B)await Rf(Wf);let N0=G.length===1&&!!g.bundleOutput;for(let Wf of G){let Uf=await Phf([Wf],{includeImports:!0}),p0=new Set;for(let I4 of Uf.reachable){if(I4.endsWith(".d.ts"))continue;if(I4.includes("node_modules"))continue;p0.add(I4)}let Vf=B.filter((I4)=>p0.has(I4));if(!Vf.includes(Wf))Vf.push(Wf);let Vu=new Map;for(let I4 of Vf){let Sh=J0.get(I4)??await Rf(I4);Vu.set(I4,Sh)}let dt=await khf(Vf,Vu,g),Mt=N0?eI(g.cwd,g.outdir,g.bundleOutput):Et0(Wf,g);if(await KU0(Y_(Mt),{recursive:!0}),await f$(Mt,dt.content),C8.info(`Bundled ${dt.files.length} files to: ${ej(g.cwd,Mt)}`),N0)break}}catch(J0){let Rf=J0 instanceof Error?J0.message:String(J0);C8.error(`Bundle failed: ${Rf}`)}if(F.durationMs=Date.now()-r,g.stats)if(g.outputFormat==="json")console.log(JSON.stringify(F,null,2));else{if(C8.info(`
|
|
681
681
|
--- Generation Statistics ---`),C8.info(`Files processed: ${F.filesProcessed}`),C8.info(`Files generated: ${F.filesGenerated}`),O>0)C8.info(`Files cached: ${O}`);if(F.filesFailed>0)C8.info(`Files failed: ${F.filesFailed}`);if(C8.info(`Declarations found: ${F.declarationsFound}`),C8.info(`Imports processed: ${F.importsProcessed}`),C8.info(`Exports processed: ${F.exportsProcessed}`),F.filesValidated>0){if(C8.info(`Files validated: ${F.filesValidated}`),F.validationErrors>0)C8.info(`Validation errors: ${F.validationErrors}`)}if(C8.info(`Duration: ${F.durationMs}ms`),F.errors.length>0){C8.info(`
|
|
682
682
|
Errors:`);for(let J0 of F.errors){let Rf=` - ${J0.file}`;if(J0.location)Rf+=`:${J0.location.line}:${J0.location.column}`;if(J0.code)Rf+=` [${J0.code}]`;if(Rf+=`: ${J0.message}`,C8.info(Rf),J0.suggestion)C8.info(` Suggestion: ${J0.suggestion}`)}}C8.info(`-----------------------------
|
|
683
|
-
`)}if(g.plugins&&g.plugins.length>0)await m.runOnEnd(F);return C8.debug("DTS generation complete!"),F}function Wfu(u){let r=J_.get(u);if(!r){if(r=new Nhf(u),J_.set(u,r),J_.size>Efu){let g=J_.keys().next().value;if(g!==void 0)J_.delete(g)}}return r}async function nfu(u){let r=eI(u.cwd,u.outdir);async function g(m){let w;try{w=await lfu(m,{withFileTypes:!0})}catch{return}await Promise.all(w.map(async(F)=>{let O=eI(m,F.name);if(F.isDirectory()){await g(O);return}if(F.name.endsWith(".d.ts")||F.name.endsWith(".d.mts")||F.name.endsWith(".d.cts")||F.name.endsWith(".d.ts.map")||F.name.endsWith(".d.mts.map")||F.name.endsWith(".d.cts.map"))await cfu(O,{force:!0})}))}await g(r)}function tA0(u,r,g){if(!r||r.length===0)return!1;let m=ej(g,u);for(let w of r){let F=Wfu(w);if(F.match(m)||F.match(u))return!0}return!1}async function Zfu(u){let r=[],g=eI(u.cwd,u.root),m=u.exclude||[];for(let w of u.entrypoints)if(w.startsWith("/")&&w.endsWith(".ts")){if(!w.endsWith(".d.ts")&&!w.includes("node_modules")){if(!tA0(w,m,g))r.push(w)}}else{let F=new Nhf(w);for await(let O of F.scan({cwd:g,absolute:!0,onlyFiles:!0}))if(Vhf(O)&&!O.includes("node_modules")){if(!tA0(O,m,g))r.push(O)}}return[...new Set(r)]}function Vhf(u){return/\.(m?tsx?|cts|jsx?|mjs|cjs)$/.test(u)&&!u.endsWith(".d.ts")}function Et0(u,r){let g=eI(r.cwd,r.root),m=ej(g,u).replace(/\.(m?tsx?|cts)$/,(w)=>{if(w===".mts")return".d.mts";if(w===".cts")return".d.cts";return".d.ts"});if(r.outputStructure==="mirror")return eI(r.cwd,r.outdir,m);else{let w=m.split("/").pop();return eI(r.cwd,r.outdir,w)}}function pfu(u,r){let g=ej(Y_(u),r).replace(/\\/g,"/");if(g=g.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),!g.startsWith("."))g=`./${g}`;return g}function zfu(u,r,g){let m=Et0(r,g),w=(F)=>{let O=rA0(F,r);if(!O.isRelative||!O.resolved)return F;return pfu(m,Et0(O.resolved,g))};return u.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(F,O,G,B)=>{return`${O}${G}${w(B)}${G}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(F,O,G,B)=>{return`${O}${G}${w(B)}${G}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(F,O,G,B)=>{return`${O}${G}${w(B)}${G}`})}async function _fu(u,r,g,m){let w=r;if(m)w=await m.runOnBeforeFile(u,r);let F=Ys(w,u,g.keepComments,g.isolatedDeclarations??!1);if(m)F=await m.runOnDeclarations(u,w,F);let O=0,G=0;for(let W=0;W<F.length;W++){let K=F[W];if(K.kind==="import")O++;if(K.kind==="export"||K.isExported)G++}let B=z_(F,{filePath:u,sourceCode:w,declarations:F},g.keepComments,g.importOrder);if(B=zfu(B,u,g),m)B=await m.runOnAfterFile(u,w,B);return{content:B,declarationCount:F.length,importCount:O,exportCount:G}}var Nhf,XU0=1,iA0=".dtsx-cache",vfu="manifest.json",Wt0,Ffu,mQ,Dt0=null,$I=null,Chf,Mhf,vhf,xfu,bfu,X_,Efu=50,J_;var lA0=W3(()=>{eD();zD();W_();__();oU0();fH();by();({Glob:Nhf}=globalThis.Bun);Wt0=typeof globalThis.Bun<"u",Ffu=!Wt0&&typeof process<"u"&&!!process.versions?.node;mQ={PARSE_ERROR:"PARSE_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",FILE_NOT_FOUND:"FILE_NOT_FOUND",FILE_READ_ERROR:"FILE_READ_ERROR",FILE_WRITE_ERROR:"FILE_WRITE_ERROR",TYPE_INFERENCE_ERROR:"TYPE_INFERENCE_ERROR",UNRESOLVED_TYPE:"UNRESOLVED_TYPE",EXTRACTION_ERROR:"EXTRACTION_ERROR",PROCESSING_ERROR:"PROCESSING_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",INVALID_DECLARATION:"INVALID_DECLARATION",CONFIG_ERROR:"CONFIG_ERROR",INVALID_ENTRYPOINT:"INVALID_ENTRYPOINT",CIRCULAR_DEPENDENCY:"CIRCULAR_DEPENDENCY",TIMEOUT_ERROR:"TIMEOUT_ERROR",NOT_SUPPORTED:"NOT_SUPPORTED",UNKNOWN_ERROR:"UNKNOWN_ERROR"};Chf=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".d.ts"];Mhf=/(?:^|[\n;{}])\s*export\s+(type\s+)?(?:\*(?:\s+as\s+\w+)?|\{[^}]*\})\s+from\s+(['"])([^'"]+)\2/g,vhf=/(?:^|[\n;{}])\s*import\s+(type\s+)?(?:[^'";\n]+\s+from\s+)?(['"])([^'"]+)\2/g;xfu=new nt0;bfu=gA0({name:"strip-internal",version:"1.0.0",description:"Removes declarations marked with @internal",onDeclarations:(u)=>{return u.declarations.filter((r)=>{if(r.leadingComments){if(r.leadingComments.some((g)=>g.includes("@internal")))return u.log.debug(`Stripping internal declaration: ${r.name}`),!1}return!0})}}),X_=HM(BM(),1);J_=new Map});var Dhf=W3(()=>{lA0();fH();by()});var Qhf,Ehf,Whf,nhf;var Zhf=W3(()=>{eD();__();((u)=>{u[u.Error=1]="Error",u[u.Warning=2]="Warning",u[u.Information=3]="Information",u[u.Hint=4]="Hint"})(Qhf||={});((u)=>{u[u.File=1]="File",u[u.Module=2]="Module",u[u.Namespace=3]="Namespace",u[u.Package=4]="Package",u[u.Class=5]="Class",u[u.Method=6]="Method",u[u.Property=7]="Property",u[u.Field=8]="Field",u[u.Constructor=9]="Constructor",u[u.Enum=10]="Enum",u[u.Interface=11]="Interface",u[u.Function=12]="Function",u[u.Variable=13]="Variable",u[u.Constant=14]="Constant",u[u.String=15]="String",u[u.Number=16]="Number",u[u.Boolean=17]="Boolean",u[u.Array=18]="Array",u[u.Object=19]="Object",u[u.Key=20]="Key",u[u.Null=21]="Null",u[u.EnumMember=22]="EnumMember",u[u.Struct=23]="Struct",u[u.Event=24]="Event",u[u.Operator=25]="Operator",u[u.TypeParameter=26]="TypeParameter"})(Ehf||={});((u)=>{u[u.Text=1]="Text",u[u.Method=2]="Method",u[u.Function=3]="Function",u[u.Constructor=4]="Constructor",u[u.Field=5]="Field",u[u.Variable=6]="Variable",u[u.Class=7]="Class",u[u.Interface=8]="Interface",u[u.Module=9]="Module",u[u.Property=10]="Property",u[u.Unit=11]="Unit",u[u.Value=12]="Value",u[u.Enum=13]="Enum",u[u.Keyword=14]="Keyword",u[u.Snippet=15]="Snippet",u[u.Color=16]="Color",u[u.File=17]="File",u[u.Reference=18]="Reference",u[u.Folder=19]="Folder",u[u.EnumMember=20]="EnumMember",u[u.Constant=21]="Constant",u[u.Struct=22]="Struct",u[u.Event=23]="Event",u[u.Operator=24]="Operator",u[u.TypeParameter=25]="TypeParameter"})(Whf||={});((u)=>{u[u.Text=1]="Text",u[u.Read=2]="Read",u[u.Write=3]="Write"})(nhf||={})});var VRu;var phf=W3(()=>{zD();by();VRu=HM(BM(),1)});var zhf=()=>{};var nRu;var _hf=W3(()=>{zD();by();nRu=HM(BM(),1)});var $hf=W3(()=>{fH()});var ehf=W3(()=>{W_();du0();__()});class $fu{declarations=new Map;registry=new FinalizationRegistry((u)=>{this.declarations.delete(u)});maxSize;constructor(u=1e4){this.maxSize=u}add(u,r){if(this.declarations.size>=this.maxSize)this.evictOldest();let g=new WeakRef(r);this.declarations.set(u,g),this.registry.register(r,u)}get(u){return this.declarations.get(u)?.deref()}has(u){return this.declarations.get(u)?.deref()!==void 0}delete(u){this.declarations.delete(u)}clear(){this.declarations.clear()}get size(){return this.declarations.size}evictOldest(){let u=Math.ceil(this.maxSize*0.2),r=Array.from(this.declarations.keys());for(let g=0;g<u&&g<r.length;g++)this.declarations.delete(r[g])}}function efu(u,r,g,m={}){return{kind:u,name:r,text:g,isExported:m.isExported??!1,...m}}function dfu(u){if(typeof structuredClone==="function")return structuredClone(u);return JSON.parse(JSON.stringify(u))}async function ofu(u,r,g){let m=[],w=u.length;for(let F=0;F<u.length;F++){let O=u[F],G={...g,index:F,total:w,allDeclarations:u},B=await r(O,G);if(B===null)continue;else if(B===void 0)m.push(O);else if(Array.isArray(B))m.push(...B);else m.push(B)}return m}function cA0(u,r){let g=new Set(Array.isArray(u)?u:[u]);return async(m,w)=>{if(g.has(m.kind))return r(m,w);return}}function mA0(u){let r={createDeclaration:efu,cloneDeclaration:dfu,modifyText:(g,m)=>({...g,text:m}),addModifier:(g,m)=>({...g,modifiers:[...g.modifiers||[],m]}),removeModifier:(g,m)=>({...g,modifiers:(g.modifiers||[]).filter((w)=>w!==m)})};return gA0({name:u.name,version:u.version,description:u.description,onBeforeFile:u.beforeParse?async(g)=>{return u.beforeParse(g.content,{filePath:g.filePath,phase:"before"})}:void 0,onDeclarations:u.transform?async(g)=>{return ofu(g.declarations,u.transform,{filePath:g.filePath,sourceCode:g.sourceCode,...r})}:void 0,onAfterFile:u.afterGenerate?async(g)=>{return u.afterGenerate(g.content,{filePath:g.filePath,phase:"after"})}:void 0})}function Kfu(u){let r=typeof u==="function"?u:(g)=>{return(typeof u==="string"?new RegExp(u):u).test(g.name)};return(g)=>{if(r(g))return null;return}}function Xfu(u,r){return(g)=>{if(r&&!r(g))return;if(g.modifiers?.includes(u))return;let m=[...g.modifiers||[],u],w=g.text;if(!w.includes(u)){let F=["function","class","interface","type","enum","const","let","var"];for(let O of F){let G=w.indexOf(O);if(G>=0){w=`${w.slice(0,G)}${u} ${w.slice(G)}`;break}}}return{...g,modifiers:m,text:w}}}function tiu(u){switch(u){case"strict":return fiu;case"readonly":return iiu;case"simplified":return uiu;case"nullable":return[{pattern:/^(.+)\s*\|\s*undefined$/,replacement:"$1 | undefined",priority:5}];case"branded":return[{pattern:/^string$/,replacement:"string",condition:(r)=>r.declarationKind==="variable"&&(r.declarationName?.includes("path")??!1),priority:5}];default:return[]}}class ohf{rules;compiled=[];cache=new Map;constructor(u={rules:[]}){if(this.rules=[],u.includeDefaults!==!1)this.rules.push(...Yfu);if(u.presets)for(let r of u.presets)this.rules.push(...tiu(r));this.rules.push(...u.rules),this.rules.sort((r,g)=>(g.priority||0)-(r.priority||0)),this.recompile()}recompile(){let u=Array(this.rules.length);for(let r=0;r<this.rules.length;r++){let g=this.rules[r],m=typeof g.pattern==="string"?new RegExp(g.pattern.replace(hiu,"\\$&"),g.global?"g":""):g.pattern;u[r]={rule:g,regex:m}}this.compiled=u}map(u,r={}){let g=!r.declarationName&&!r.declarationKind&&!r.filePath&&!r.isReturnType&&!r.isParameterType&&!r.isPropertyType?u:`${u}\x00${r.declarationName??""}\x00${r.declarationKind??""}\x00${r.filePath??""}\x00${r.isReturnType?"r":""}${r.isParameterType?"p":""}${r.isPropertyType?"P":""}`,m=this.cache.get(g);if(m!==void 0)return m;let w=u,F=null;for(let O=0;O<this.compiled.length;O++){let{rule:G,regex:B}=this.compiled[O];if(G.condition){if(!F)F={type:u,...r};if(!G.condition(F))continue}if(B.test(w)){if(w=w.replace(B,G.replacement),!G.global)break}}if(this.cache.size>=dhf){let O=Math.ceil(dhf*0.1),G=0;for(let B of this.cache.keys()){if(G++>=O)break;this.cache.delete(B)}}return this.cache.set(g,w),w}mapAll(u,r={}){return u.map((g)=>this.map(g,{...r,type:g}))}addRule(u){this.rules.push(u),this.rules.sort((r,g)=>(g.priority||0)-(r.priority||0)),this.recompile(),this.cache.clear()}removeRules(u){let r=this.rules.length;return this.rules=this.rules.filter((g)=>{let m=typeof g.pattern==="string"?g.pattern:g.pattern.source;return typeof u==="string"?m!==u:!u.test(m)}),this.recompile(),this.cache.clear(),r-this.rules.length}clearCache(){this.cache.clear()}getRules(){return this.rules}}function Khf(u={rules:[]}){return new ohf(u)}var _Mu,$Mu,Jfu,eMu,dMu,oMu,KMu,XMu,Yfu,fiu,iiu,uiu,hiu,dhf=2048,JMu,YMu;var Xhf=W3(()=>{Atf();Itf();Dhf();Zhf();phf();zhf();_hf();$hf();lA0();eD();zD();ehf();W_();du0();__();Xu0();oU0();fH();by();_Mu=HM(BM(),1),$Mu={rootDir:process.cwd(),maxFileSize:10485760,maxTotalSize:104857600,timeout:30000,followSymlinks:!1,maxFiles:1e4,blockedPatterns:["**/.git/**","**/node_modules/**","**/.env*","**/secrets/**","**/*.key","**/*.pem"]};Jfu=cA0(["interface","type"],(u)=>{let r=u.text.replace(/(\n\s*)(\w+)(\??:\s)/g,"$1readonly $2$3");if(r===u.text)return;return{...u,text:r}}),eMu=cA0(["interface","type"],(u)=>{let r=u.text.replace(/(\w+)\?:/g,"$1:");if(r===u.text)return;return{...u,text:r}}),dMu=cA0(["interface","type"],(u)=>{let r=u.text.replace(/(\w+)(?<!\?):/g,"$1?:");if(r===u.text)return;return{...u,text:r}}),oMu=mA0({name:"readonly",version:"1.0.0",description:"Makes all interface properties readonly",transform:Jfu}),KMu=mA0({name:"strip-private",version:"1.0.0",description:"Strips @internal, @private, and @hidden declarations",transform:Kfu((u)=>{if(!u.leadingComments)return!1;return u.leadingComments.some((r)=>/@(internal|private|hidden)\b/.test(r))})}),XMu=mA0({name:"declare",version:"1.0.0",description:"Adds declare keyword to all declarations",transform:Xfu("declare",(u)=>u.kind!=="import")}),Yfu=[{pattern:/^Promise<void>$/,replacement:"Promise<void>",priority:-1},{pattern:/^Record<string,\s*any>$/,replacement:"Record<string, unknown>",priority:0},{pattern:/^Array<([^<>]+)>$/,replacement:"$1[]",priority:0}],fiu=[{pattern:/\bany\b/,replacement:"unknown",global:!0,priority:10},{pattern:/^object$/,replacement:"Record<string, unknown>",priority:10},{pattern:/^Function$/,replacement:"(...args: unknown[]) => unknown",priority:10}],iiu=[{pattern:/^(\w+)\[\]$/,replacement:"readonly $1[]",priority:5},{pattern:/^Array<(.+)>$/,replacement:"ReadonlyArray<$1>",priority:5},{pattern:/^Map<(.+),\s*(.+)>$/,replacement:"ReadonlyMap<$1, $2>",priority:5},{pattern:/^Set<(.+)>$/,replacement:"ReadonlySet<$1>",priority:5}],uiu=[{pattern:/^Partial<Partial<(.+)>>$/,replacement:"Partial<$1>",priority:5},{pattern:/^Required<Required<(.+)>>$/,replacement:"Required<$1>",priority:5},{pattern:/^Pick<Omit<(.+),\s*(.+)>,\s*(.+)>$/,replacement:"Pick<$1, $3>",priority:5}];hiu=/[.*+?^${}()|[\]\\]/g;JMu=Khf({rules:[]}),YMu=Khf({rules:[],presets:["strict"]})});var urf={};Fbf(urf,{dtsWatch:()=>Miu,dtsCheck:()=>viu,dts:()=>RA0,default:()=>jiu,clearCache:()=>Piu,PluginErrorCodes:()=>wiu,DtsxPluginError:()=>hH});import{createHash as giu}from"crypto";import{existsSync as liu,readFileSync as ciu,writeFileSync as miu}from"fs";import{basename as Siu,join as Riu,resolve as Zt0}from"path";import Jhf from"process";class Yhf{listeners=new Map;on(u,r){let g=this.listeners.get(u)||[];g.push(r),this.listeners.set(u,g)}async emit(u,r){let g={type:u,timestamp:Date.now(),data:r},m=this.listeners.get(u)||[];for(let w of m)await w(g)}}class SA0{manifest;cacheDir;manifestPath;constructor(u,r){this.cacheDir=u,this.manifestPath=Riu(u,"manifest.json"),this.manifest=this.loadManifest(r)}loadManifest(u){try{if(liu(this.manifestPath)){let r=JSON.parse(ciu(this.manifestPath,"utf-8"));if(r.configHash===u&&r.version==="1.0")return r}}catch{}return{version:"1.0",configHash:u,entries:{}}}save(){try{let{mkdirSync:u}=riu("fs");u(this.cacheDir,{recursive:!0}),miu(this.manifestPath,JSON.stringify(this.manifest,null,2))}catch{}}getEntry(u){return this.manifest.entries[u]}setEntry(u,r){this.manifest.entries[u]=r}isValid(u,r){return this.getEntry(u)?.hash===r}clear(){this.manifest.entries={},this.save()}}function Ciu(u){let r={root:u.root,outdir:u.outdir,entrypoints:u.entrypoints,clean:u.clean,tsconfigPath:u.tsconfigPath};return giu("md5").update(JSON.stringify(r)).digest("hex")}function RA0(u={}){let{onSuccess:r,onError:g,failOnError:m=!0,incremental:w=!1,cacheDir:F=".dtsx-cache",on:O,timeout:G=60000,continueOnError:B=!1,verbose:W=!1,...K}=u,z=new Yhf;if(O){for(let[G0,a0]of Object.entries(O))if(a0)z.on(G0,a0)}return{name:"bun-plugin-dtsx",async setup(G0){let a0=Date.now(),uf=null,J0=0;try{let Rf=irf(K,G0),N0=Ciu(Rf);if(w)uf=new SA0(Zt0(F),N0);if(await z.emit("start",{type:"start",files:Rf.entrypoints||[],config:Rf}),W){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),w)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let Uf=await(async()=>{return new Promise((Vf,Vu)=>{let dt=setTimeout(()=>{Vu(new hH(`Generation timed out after ${G}ms`,"TIMEOUT_ERROR",{timeout:G}))},G);i$(Rf).then((Mt)=>{clearTimeout(dt),Vf(Mt)}).catch((Mt)=>{clearTimeout(dt),Vu(Mt)})})})(),p0=Date.now()-a0;if(uf)uf.save();if(await z.emit("complete",{type:"complete",stats:Uf,duration:p0,fromCache:J0}),W){if(console.log(`[bun-plugin-dtsx] Generation complete in ${p0}ms`),J0>0)console.log(`[bun-plugin-dtsx] ${J0} files served from cache`)}if(r)await r(Uf)}catch(Rf){let N0=frf(Rf);if(await z.emit("error",{type:"error",error:N0}),g)await g(N0);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${N0.code}`),console.error(` Message: ${N0.message}`),N0.context)console.error(` Context: ${JSON.stringify(N0.context)}`);if(W&&N0.stack)console.error(` Stack: ${N0.stack}`)}if(m&&!B)throw N0}}}}function frf(u){if(u instanceof hH)return u;if(u instanceof Error){let r="GENERATION_ERROR";if(u.message.includes("config")||u.message.includes("Config"))r="CONFIG_ERROR";else if(u.message.includes("file")||u.message.includes("File")||u.message.includes("ENOENT"))r="FILE_ERROR";return new hH(u.message,r,{originalError:u.name},u)}return new hH(String(u),"GENERATION_ERROR")}function irf(u,r){let g=u.root||u.build?.config.root||r?.config.root||"./src",m=u.outdir||u.build?.config.outdir||r?.config.outdir||"./dist";if(!g)throw new hH("Root directory is required","CONFIG_ERROR",{providedRoot:g});let w=u.entrypoints;if(!w){let F=r?.config?.entrypoints;if(F?.length){let O=Zt0(u.cwd||Jhf.cwd(),g);w=F.map((G)=>{let B=Zt0(G);return B.startsWith(O)?B.slice(O.length+1):Siu(B)})}else w=["index.ts"]}return{...u,cwd:u.cwd||Jhf.cwd(),root:g,entrypoints:w,outdir:m,clean:u.clean??!0,tsconfigPath:u.tsconfigPath}}function Miu(u={}){return RA0({...u,incremental:!0,verbose:u.verbose??!0})}function viu(u){return{name:"bun-plugin-dtsx-check",async setup(r){let g=irf({...u,outdir:""},r);try{await i$({...g,clean:!1})}catch(m){let w=frf(m);if(u.onError)await u.onError(w);if(u.failOnError!==!1)throw w}}}}function Piu(u=".dtsx-cache"){new SA0(Zt0(u),"").clear()}var riu,wiu,hH,jiu;var trf=W3(()=>{Xhf();riu=import.meta.require,wiu={CONFIG_ERROR:"CONFIG_ERROR",GENERATION_ERROR:"GENERATION_ERROR",FILE_ERROR:"FILE_ERROR",CACHE_ERROR:"CACHE_ERROR",TIMEOUT_ERROR:"TIMEOUT_ERROR"};hH=class hH extends Error{code;context;cause;constructor(u,r,g,m){super(u);if(this.name="DtsxPluginError",this.code=r,this.context=g,this.cause=m,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}};jiu=RA0});import{mkdir as Fiu,stat as Niu}from"fs/promises";import{bold as wA0,dim as CA0,green as kiu,italic as hrf,log as aiu}from"@stacksjs/cli";import{path as Xa}from"@stacksjs/path";import{glob as Uiu}from"@stacksjs/storage";var i1i=_j0(oX0(),1),u1i=_j0(ZJ0(),1),t1i=_j0(sD(),1);async function Svu(u){let g=Date.now()-u.startTime,m=u.pkgName??`@stacksjs/${Xa.basename(u.dir)}`;if(u.result.errors&&u.result.errors.length>0)throw console.error("Build errors:",u.result.errors),Error(`Build failed with errors: ${JSON.stringify(u.result.errors)}`);else if(u.result.success!==void 0&&!u.result.success){let F=u.result.logs?.[0]||"Unknown build error";throw console.log(F),Error(`Build failed: ${F}`)}let w=await Uiu([Xa.resolve(u.dir,"dist","**/*")],{absolute:!0});for(let F of w){let O=await Niu(F),G;if(O.size<1048576)G=`${(O.size/1024).toFixed(2)}kb`;else G=`${(O.size/1024/1024).toFixed(2)}mb`;let B=Xa.relative(u.dir,F).replace("dist/","");console.log(`${wA0(CA0(`[${G}]`))} ${CA0("dist/")}${B}`)}console.log(`${wA0(CA0(`[${g}ms]`))} Built ${hrf(wA0(kiu(m)))}`)}async function Rvu(u){let r=u.pkgName??`@stacksjs/${Xa.basename(u.dir)}`;if(u.styled===!1)console.log(`Building ${r}...`);else aiu.info(`Building ${hrf(r)}...`);return{startTime:Date.now()}}async function wvu(u){let{dts:r}=await Promise.resolve().then(() => (trf(),urf)),g=Xa.resolve(u.dir,"src"),m=Xa.resolve(u.dir,"dist"),w=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:g}))).filter((O)=>!O.endsWith(".d.ts"));await Bun.build({entrypoints:w.map((O)=>Xa.resolve(g,O)),outdir:m,root:g,target:"bun",format:"esm",splitting:!1,external:u.external??Aiu(),plugins:[r({root:g,outdir:m})]});let F=new Bun.Transpiler({loader:"ts",target:"bun"});for(let O of w){let G=F.transformSync(await Bun.file(Xa.resolve(g,O)).text()),B=Xa.resolve(m,O.replace(/\.ts$/,".js"));await Fiu(Xa.dirname(B),{recursive:!0}),await Bun.write(B,G)}}function Aiu(u=[]){let r=[];try{let g=kw("fs"),m=JSON.parse(g.readFileSync(`${process.cwd()}/package.json`,"utf8"));r=[...Object.keys(m.dependencies??{}),...Object.keys(m.peerDependencies??{}),...Object.keys(m.optionalDependencies??{})]}catch{}return["@stacksjs/*",...r,"bun-queue","ioredis","localtunnels","localtunnels/*","@craft-native/ts","ts-md","meilisearch","algoliasearch","@opensearch-project/opensearch","*.yaml","*.yml",...u]}var export_traverse=t1i.default;var export_parser=u1i.default;var export_generator=i1i.default;export{export_traverse as traverse,wvu as transpilePackage,export_parser as parser,Svu as outro,Rvu as intro,export_generator as generator,Aiu as frameworkExternal};
|
|
683
|
+
`)}if(g.plugins&&g.plugins.length>0)await m.runOnEnd(F);return C8.debug("DTS generation complete!"),F}function Wfu(u){let r=J_.get(u);if(!r){if(r=new Nhf(u),J_.set(u,r),J_.size>Efu){let g=J_.keys().next().value;if(g!==void 0)J_.delete(g)}}return r}async function nfu(u){let r=eI(u.cwd,u.outdir);async function g(m){let w;try{w=await lfu(m,{withFileTypes:!0})}catch{return}await Promise.all(w.map(async(F)=>{let O=eI(m,F.name);if(F.isDirectory()){await g(O);return}if(F.name.endsWith(".d.ts")||F.name.endsWith(".d.mts")||F.name.endsWith(".d.cts")||F.name.endsWith(".d.ts.map")||F.name.endsWith(".d.mts.map")||F.name.endsWith(".d.cts.map"))await cfu(O,{force:!0})}))}await g(r)}function tA0(u,r,g){if(!r||r.length===0)return!1;let m=ej(g,u);for(let w of r){let F=Wfu(w);if(F.match(m)||F.match(u))return!0}return!1}async function Zfu(u){let r=[],g=eI(u.cwd,u.root),m=u.exclude||[];for(let w of u.entrypoints)if(w.startsWith("/")&&w.endsWith(".ts")){if(!w.endsWith(".d.ts")&&!w.includes("node_modules")){if(!tA0(w,m,g))r.push(w)}}else{let F=new Nhf(w);for await(let O of F.scan({cwd:g,absolute:!0,onlyFiles:!0}))if(Vhf(O)&&!O.includes("node_modules")){if(!tA0(O,m,g))r.push(O)}}return[...new Set(r)]}function Vhf(u){return/\.(m?tsx?|cts|jsx?|mjs|cjs)$/.test(u)&&!u.endsWith(".d.ts")}function Et0(u,r){let g=eI(r.cwd,r.root),m=ej(g,u).replace(/\.(m?tsx?|cts)$/,(w)=>{if(w===".mts")return".d.mts";if(w===".cts")return".d.cts";return".d.ts"});if(r.outputStructure==="mirror")return eI(r.cwd,r.outdir,m);else{let w=m.split("/").pop();return eI(r.cwd,r.outdir,w)}}function pfu(u,r){let g=ej(Y_(u),r).replace(/\\/g,"/");if(g=g.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),!g.startsWith("."))g=`./${g}`;return g}function zfu(u,r,g){let m=Et0(r,g),w=(F)=>{let O=rA0(F,r);if(!O.isRelative||!O.resolved)return F;return pfu(m,Et0(O.resolved,g))};return u.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(F,O,G,B)=>{return`${O}${G}${w(B)}${G}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(F,O,G,B)=>{return`${O}${G}${w(B)}${G}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(F,O,G,B)=>{return`${O}${G}${w(B)}${G}`})}async function _fu(u,r,g,m){let w=r;if(m)w=await m.runOnBeforeFile(u,r);let F=Ys(w,u,g.keepComments,g.isolatedDeclarations??!1);if(m)F=await m.runOnDeclarations(u,w,F);let O=0,G=0;for(let W=0;W<F.length;W++){let K=F[W];if(K.kind==="import")O++;if(K.kind==="export"||K.isExported)G++}let B=z_(F,{filePath:u,sourceCode:w,declarations:F},g.keepComments,g.importOrder);if(B=zfu(B,u,g),m)B=await m.runOnAfterFile(u,w,B);return{content:B,declarationCount:F.length,importCount:O,exportCount:G}}var Nhf,XU0=1,iA0=".dtsx-cache",vfu="manifest.json",Wt0,Ffu,mQ,Dt0=null,$I=null,Chf,Mhf,vhf,xfu,bfu,X_,Efu=50,J_;var lA0=W3(()=>{eD();zD();W_();__();oU0();fH();by();({Glob:Nhf}=globalThis.Bun);Wt0=typeof globalThis.Bun<"u",Ffu=!Wt0&&typeof process<"u"&&!!process.versions?.node;mQ={PARSE_ERROR:"PARSE_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",FILE_NOT_FOUND:"FILE_NOT_FOUND",FILE_READ_ERROR:"FILE_READ_ERROR",FILE_WRITE_ERROR:"FILE_WRITE_ERROR",TYPE_INFERENCE_ERROR:"TYPE_INFERENCE_ERROR",UNRESOLVED_TYPE:"UNRESOLVED_TYPE",EXTRACTION_ERROR:"EXTRACTION_ERROR",PROCESSING_ERROR:"PROCESSING_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",INVALID_DECLARATION:"INVALID_DECLARATION",CONFIG_ERROR:"CONFIG_ERROR",INVALID_ENTRYPOINT:"INVALID_ENTRYPOINT",CIRCULAR_DEPENDENCY:"CIRCULAR_DEPENDENCY",TIMEOUT_ERROR:"TIMEOUT_ERROR",NOT_SUPPORTED:"NOT_SUPPORTED",UNKNOWN_ERROR:"UNKNOWN_ERROR"};Chf=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".d.ts"];Mhf=/(?:^|[\n;{}])\s*export\s+(type\s+)?(?:\*(?:\s+as\s+\w+)?|\{[^}]*\})\s+from\s+(['"])([^'"]+)\2/g,vhf=/(?:^|[\n;{}])\s*import\s+(type\s+)?(?:[^'";\n]+\s+from\s+)?(['"])([^'"]+)\2/g;xfu=new nt0;bfu=gA0({name:"strip-internal",version:"1.0.0",description:"Removes declarations marked with @internal",onDeclarations:(u)=>{return u.declarations.filter((r)=>{if(r.leadingComments){if(r.leadingComments.some((g)=>g.includes("@internal")))return u.log.debug(`Stripping internal declaration: ${r.name}`),!1}return!0})}}),X_=HM(BM(),1);J_=new Map});var Dhf=W3(()=>{lA0();fH();by()});var Qhf,Ehf,Whf,nhf;var Zhf=W3(()=>{eD();__();((u)=>{u[u.Error=1]="Error",u[u.Warning=2]="Warning",u[u.Information=3]="Information",u[u.Hint=4]="Hint"})(Qhf||={});((u)=>{u[u.File=1]="File",u[u.Module=2]="Module",u[u.Namespace=3]="Namespace",u[u.Package=4]="Package",u[u.Class=5]="Class",u[u.Method=6]="Method",u[u.Property=7]="Property",u[u.Field=8]="Field",u[u.Constructor=9]="Constructor",u[u.Enum=10]="Enum",u[u.Interface=11]="Interface",u[u.Function=12]="Function",u[u.Variable=13]="Variable",u[u.Constant=14]="Constant",u[u.String=15]="String",u[u.Number=16]="Number",u[u.Boolean=17]="Boolean",u[u.Array=18]="Array",u[u.Object=19]="Object",u[u.Key=20]="Key",u[u.Null=21]="Null",u[u.EnumMember=22]="EnumMember",u[u.Struct=23]="Struct",u[u.Event=24]="Event",u[u.Operator=25]="Operator",u[u.TypeParameter=26]="TypeParameter"})(Ehf||={});((u)=>{u[u.Text=1]="Text",u[u.Method=2]="Method",u[u.Function=3]="Function",u[u.Constructor=4]="Constructor",u[u.Field=5]="Field",u[u.Variable=6]="Variable",u[u.Class=7]="Class",u[u.Interface=8]="Interface",u[u.Module=9]="Module",u[u.Property=10]="Property",u[u.Unit=11]="Unit",u[u.Value=12]="Value",u[u.Enum=13]="Enum",u[u.Keyword=14]="Keyword",u[u.Snippet=15]="Snippet",u[u.Color=16]="Color",u[u.File=17]="File",u[u.Reference=18]="Reference",u[u.Folder=19]="Folder",u[u.EnumMember=20]="EnumMember",u[u.Constant=21]="Constant",u[u.Struct=22]="Struct",u[u.Event=23]="Event",u[u.Operator=24]="Operator",u[u.TypeParameter=25]="TypeParameter"})(Whf||={});((u)=>{u[u.Text=1]="Text",u[u.Read=2]="Read",u[u.Write=3]="Write"})(nhf||={})});var VRu;var phf=W3(()=>{zD();by();VRu=HM(BM(),1)});var zhf=()=>{};var nRu;var _hf=W3(()=>{zD();by();nRu=HM(BM(),1)});var $hf=W3(()=>{fH()});var ehf=W3(()=>{W_();du0();__()});class $fu{declarations=new Map;registry=new FinalizationRegistry((u)=>{this.declarations.delete(u)});maxSize;constructor(u=1e4){this.maxSize=u}add(u,r){if(this.declarations.size>=this.maxSize)this.evictOldest();let g=new WeakRef(r);this.declarations.set(u,g),this.registry.register(r,u)}get(u){return this.declarations.get(u)?.deref()}has(u){return this.declarations.get(u)?.deref()!==void 0}delete(u){this.declarations.delete(u)}clear(){this.declarations.clear()}get size(){return this.declarations.size}evictOldest(){let u=Math.ceil(this.maxSize*0.2),r=Array.from(this.declarations.keys());for(let g=0;g<u&&g<r.length;g++)this.declarations.delete(r[g])}}function efu(u,r,g,m={}){return{kind:u,name:r,text:g,isExported:m.isExported??!1,...m}}function dfu(u){if(typeof structuredClone==="function")return structuredClone(u);return JSON.parse(JSON.stringify(u))}async function ofu(u,r,g){let m=[],w=u.length;for(let F=0;F<u.length;F++){let O=u[F],G={...g,index:F,total:w,allDeclarations:u},B=await r(O,G);if(B===null)continue;else if(B===void 0)m.push(O);else if(Array.isArray(B))m.push(...B);else m.push(B)}return m}function cA0(u,r){let g=new Set(Array.isArray(u)?u:[u]);return async(m,w)=>{if(g.has(m.kind))return r(m,w);return}}function mA0(u){let r={createDeclaration:efu,cloneDeclaration:dfu,modifyText:(g,m)=>({...g,text:m}),addModifier:(g,m)=>({...g,modifiers:[...g.modifiers||[],m]}),removeModifier:(g,m)=>({...g,modifiers:(g.modifiers||[]).filter((w)=>w!==m)})};return gA0({name:u.name,version:u.version,description:u.description,onBeforeFile:u.beforeParse?async(g)=>{return u.beforeParse(g.content,{filePath:g.filePath,phase:"before"})}:void 0,onDeclarations:u.transform?async(g)=>{return ofu(g.declarations,u.transform,{filePath:g.filePath,sourceCode:g.sourceCode,...r})}:void 0,onAfterFile:u.afterGenerate?async(g)=>{return u.afterGenerate(g.content,{filePath:g.filePath,phase:"after"})}:void 0})}function Kfu(u){let r=typeof u==="function"?u:(g)=>{return(typeof u==="string"?new RegExp(u):u).test(g.name)};return(g)=>{if(r(g))return null;return}}function Xfu(u,r){return(g)=>{if(r&&!r(g))return;if(g.modifiers?.includes(u))return;let m=[...g.modifiers||[],u],w=g.text;if(!w.includes(u)){let F=["function","class","interface","type","enum","const","let","var"];for(let O of F){let G=w.indexOf(O);if(G>=0){w=`${w.slice(0,G)}${u} ${w.slice(G)}`;break}}}return{...g,modifiers:m,text:w}}}function tiu(u){switch(u){case"strict":return fiu;case"readonly":return iiu;case"simplified":return uiu;case"nullable":return[{pattern:/^(.+)\s*\|\s*undefined$/,replacement:"$1 | undefined",priority:5}];case"branded":return[{pattern:/^string$/,replacement:"string",condition:(r)=>r.declarationKind==="variable"&&(r.declarationName?.includes("path")??!1),priority:5}];default:return[]}}class ohf{rules;compiled=[];cache=new Map;constructor(u={rules:[]}){if(this.rules=[],u.includeDefaults!==!1)this.rules.push(...Yfu);if(u.presets)for(let r of u.presets)this.rules.push(...tiu(r));this.rules.push(...u.rules),this.rules.sort((r,g)=>(g.priority||0)-(r.priority||0)),this.recompile()}recompile(){let u=Array(this.rules.length);for(let r=0;r<this.rules.length;r++){let g=this.rules[r],m=typeof g.pattern==="string"?new RegExp(g.pattern.replace(hiu,"\\$&"),g.global?"g":""):g.pattern;u[r]={rule:g,regex:m}}this.compiled=u}map(u,r={}){let g=!r.declarationName&&!r.declarationKind&&!r.filePath&&!r.isReturnType&&!r.isParameterType&&!r.isPropertyType?u:`${u}\x00${r.declarationName??""}\x00${r.declarationKind??""}\x00${r.filePath??""}\x00${r.isReturnType?"r":""}${r.isParameterType?"p":""}${r.isPropertyType?"P":""}`,m=this.cache.get(g);if(m!==void 0)return m;let w=u,F=null;for(let O=0;O<this.compiled.length;O++){let{rule:G,regex:B}=this.compiled[O];if(G.condition){if(!F)F={type:u,...r};if(!G.condition(F))continue}if(B.test(w)){if(w=w.replace(B,G.replacement),!G.global)break}}if(this.cache.size>=dhf){let O=Math.ceil(dhf*0.1),G=0;for(let B of this.cache.keys()){if(G++>=O)break;this.cache.delete(B)}}return this.cache.set(g,w),w}mapAll(u,r={}){return u.map((g)=>this.map(g,{...r,type:g}))}addRule(u){this.rules.push(u),this.rules.sort((r,g)=>(g.priority||0)-(r.priority||0)),this.recompile(),this.cache.clear()}removeRules(u){let r=this.rules.length;return this.rules=this.rules.filter((g)=>{let m=typeof g.pattern==="string"?g.pattern:g.pattern.source;return typeof u==="string"?m!==u:!u.test(m)}),this.recompile(),this.cache.clear(),r-this.rules.length}clearCache(){this.cache.clear()}getRules(){return this.rules}}function Khf(u={rules:[]}){return new ohf(u)}var _Mu,$Mu,Jfu,eMu,dMu,oMu,KMu,XMu,Yfu,fiu,iiu,uiu,hiu,dhf=2048,JMu,YMu;var Xhf=W3(()=>{Atf();Itf();Dhf();Zhf();phf();zhf();_hf();$hf();lA0();eD();zD();ehf();W_();du0();__();Xu0();oU0();fH();by();_Mu=HM(BM(),1),$Mu={rootDir:process.cwd(),maxFileSize:10485760,maxTotalSize:104857600,timeout:30000,followSymlinks:!1,maxFiles:1e4,blockedPatterns:["**/.git/**","**/node_modules/**","**/.env*","**/secrets/**","**/*.key","**/*.pem"]};Jfu=cA0(["interface","type"],(u)=>{let r=u.text.replace(/(\n\s*)(\w+)(\??:\s)/g,"$1readonly $2$3");if(r===u.text)return;return{...u,text:r}}),eMu=cA0(["interface","type"],(u)=>{let r=u.text.replace(/(\w+)\?:/g,"$1:");if(r===u.text)return;return{...u,text:r}}),dMu=cA0(["interface","type"],(u)=>{let r=u.text.replace(/(\w+)(?<!\?):/g,"$1?:");if(r===u.text)return;return{...u,text:r}}),oMu=mA0({name:"readonly",version:"1.0.0",description:"Makes all interface properties readonly",transform:Jfu}),KMu=mA0({name:"strip-private",version:"1.0.0",description:"Strips @internal, @private, and @hidden declarations",transform:Kfu((u)=>{if(!u.leadingComments)return!1;return u.leadingComments.some((r)=>/@(internal|private|hidden)\b/.test(r))})}),XMu=mA0({name:"declare",version:"1.0.0",description:"Adds declare keyword to all declarations",transform:Xfu("declare",(u)=>u.kind!=="import")}),Yfu=[{pattern:/^Promise<void>$/,replacement:"Promise<void>",priority:-1},{pattern:/^Record<string,\s*any>$/,replacement:"Record<string, unknown>",priority:0},{pattern:/^Array<([^<>]+)>$/,replacement:"$1[]",priority:0}],fiu=[{pattern:/\bany\b/,replacement:"unknown",global:!0,priority:10},{pattern:/^object$/,replacement:"Record<string, unknown>",priority:10},{pattern:/^Function$/,replacement:"(...args: unknown[]) => unknown",priority:10}],iiu=[{pattern:/^(\w+)\[\]$/,replacement:"readonly $1[]",priority:5},{pattern:/^Array<(.+)>$/,replacement:"ReadonlyArray<$1>",priority:5},{pattern:/^Map<(.+),\s*(.+)>$/,replacement:"ReadonlyMap<$1, $2>",priority:5},{pattern:/^Set<(.+)>$/,replacement:"ReadonlySet<$1>",priority:5}],uiu=[{pattern:/^Partial<Partial<(.+)>>$/,replacement:"Partial<$1>",priority:5},{pattern:/^Required<Required<(.+)>>$/,replacement:"Required<$1>",priority:5},{pattern:/^Pick<Omit<(.+),\s*(.+)>,\s*(.+)>$/,replacement:"Pick<$1, $3>",priority:5}];hiu=/[.*+?^${}()|[\]\\]/g;JMu=Khf({rules:[]}),YMu=Khf({rules:[],presets:["strict"]})});var urf={};Fbf(urf,{dtsWatch:()=>Miu,dtsCheck:()=>viu,dts:()=>RA0,default:()=>jiu,clearCache:()=>Piu,PluginErrorCodes:()=>wiu,DtsxPluginError:()=>hH});import{createHash as giu}from"crypto";import{existsSync as liu,readFileSync as ciu,writeFileSync as miu}from"fs";import{basename as Siu,join as Riu,resolve as Zt0}from"path";import Jhf from"process";class Yhf{listeners=new Map;on(u,r){let g=this.listeners.get(u)||[];g.push(r),this.listeners.set(u,g)}async emit(u,r){let g={type:u,timestamp:Date.now(),data:r},m=this.listeners.get(u)||[];for(let w of m)await w(g)}}class SA0{manifest;cacheDir;manifestPath;constructor(u,r){this.cacheDir=u,this.manifestPath=Riu(u,"manifest.json"),this.manifest=this.loadManifest(r)}loadManifest(u){try{if(liu(this.manifestPath)){let r=JSON.parse(ciu(this.manifestPath,"utf-8"));if(r.configHash===u&&r.version==="1.0")return r}}catch{}return{version:"1.0",configHash:u,entries:{}}}save(){try{let{mkdirSync:u}=riu("fs");u(this.cacheDir,{recursive:!0}),miu(this.manifestPath,JSON.stringify(this.manifest,null,2))}catch{}}getEntry(u){return this.manifest.entries[u]}setEntry(u,r){this.manifest.entries[u]=r}isValid(u,r){return this.getEntry(u)?.hash===r}clear(){this.manifest.entries={},this.save()}}function Ciu(u){let r={root:u.root,outdir:u.outdir,entrypoints:u.entrypoints,clean:u.clean,tsconfigPath:u.tsconfigPath};return giu("md5").update(JSON.stringify(r)).digest("hex")}function RA0(u={}){let{onSuccess:r,onError:g,failOnError:m=!0,incremental:w=!1,cacheDir:F=".dtsx-cache",on:O,timeout:G=60000,continueOnError:B=!1,verbose:W=!1,...K}=u,z=new Yhf;if(O){for(let[G0,a0]of Object.entries(O))if(a0)z.on(G0,a0)}return{name:"bun-plugin-dtsx",async setup(G0){let a0=Date.now(),uf=null,J0=0;try{let Rf=irf(K,G0),N0=Ciu(Rf);if(w)uf=new SA0(Zt0(F),N0);if(await z.emit("start",{type:"start",files:Rf.entrypoints||[],config:Rf}),W){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),w)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let Uf=await(async()=>{return new Promise((Vf,Vu)=>{let dt=setTimeout(()=>{Vu(new hH(`Generation timed out after ${G}ms`,"TIMEOUT_ERROR",{timeout:G}))},G);i$(Rf).then((Mt)=>{clearTimeout(dt),Vf(Mt)}).catch((Mt)=>{clearTimeout(dt),Vu(Mt)})})})(),p0=Date.now()-a0;if(uf)uf.save();if(await z.emit("complete",{type:"complete",stats:Uf,duration:p0,fromCache:J0}),W){if(console.log(`[bun-plugin-dtsx] Generation complete in ${p0}ms`),J0>0)console.log(`[bun-plugin-dtsx] ${J0} files served from cache`)}if(r)await r(Uf)}catch(Rf){let N0=frf(Rf);if(await z.emit("error",{type:"error",error:N0}),g)await g(N0);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${N0.code}`),console.error(` Message: ${N0.message}`),N0.context)console.error(` Context: ${JSON.stringify(N0.context)}`);if(W&&N0.stack)console.error(` Stack: ${N0.stack}`)}if(m&&!B)throw N0}}}}function frf(u){if(u instanceof hH)return u;if(u instanceof Error){let r="GENERATION_ERROR";if(u.message.includes("config")||u.message.includes("Config"))r="CONFIG_ERROR";else if(u.message.includes("file")||u.message.includes("File")||u.message.includes("ENOENT"))r="FILE_ERROR";return new hH(u.message,r,{originalError:u.name},u)}return new hH(String(u),"GENERATION_ERROR")}function irf(u,r){let g=u.root||u.build?.config.root||r?.config.root||"./src",m=u.outdir||u.build?.config.outdir||r?.config.outdir||"./dist";if(!g)throw new hH("Root directory is required","CONFIG_ERROR",{providedRoot:g});let w=u.entrypoints;if(!w){let F=r?.config?.entrypoints;if(F?.length){let O=Zt0(u.cwd||Jhf.cwd(),g);w=F.map((G)=>{let B=Zt0(G);return B.startsWith(O)?B.slice(O.length+1):Siu(B)})}else w=["index.ts"]}return{...u,cwd:u.cwd||Jhf.cwd(),root:g,entrypoints:w,outdir:m,clean:u.clean??!0,tsconfigPath:u.tsconfigPath}}function Miu(u={}){return RA0({...u,incremental:!0,verbose:u.verbose??!0})}function viu(u){return{name:"bun-plugin-dtsx-check",async setup(r){let g=irf({...u,outdir:""},r);try{await i$({...g,clean:!1})}catch(m){let w=frf(m);if(u.onError)await u.onError(w);if(u.failOnError!==!1)throw w}}}}function Piu(u=".dtsx-cache"){new SA0(Zt0(u),"").clear()}var riu,wiu,hH,jiu;var trf=W3(()=>{Xhf();riu=import.meta.require,wiu={CONFIG_ERROR:"CONFIG_ERROR",GENERATION_ERROR:"GENERATION_ERROR",FILE_ERROR:"FILE_ERROR",CACHE_ERROR:"CACHE_ERROR",TIMEOUT_ERROR:"TIMEOUT_ERROR"};hH=class hH extends Error{code;context;cause;constructor(u,r,g,m){super(u);if(this.name="DtsxPluginError",this.code=r,this.context=g,this.cause=m,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}};jiu=RA0});import{mkdir as Fiu,stat as Niu}from"fs/promises";import{bold as wA0,dim as CA0,green as kiu,italic as hrf,log as aiu}from"@stacksjs/cli";import{path as Xa}from"@stacksjs/path";import{glob as Uiu}from"@stacksjs/storage";var i1i=_j0(oX0(),1),u1i=_j0(ZJ0(),1),t1i=_j0(sD(),1);async function Svu(u){let g=Date.now()-u.startTime,m=u.pkgName??`@stacksjs/${Xa.basename(u.dir)}`;if(u.result.errors&&u.result.errors.length>0)throw console.error("Build errors:",u.result.errors),Error(`Build failed with errors: ${JSON.stringify(u.result.errors)}`);else if(u.result.success!==void 0&&!u.result.success){let F=u.result.logs?.[0]||"Unknown build error";throw console.log(F),Error(`Build failed: ${F}`)}let w=await Uiu([Xa.resolve(u.dir,"dist","**/*")],{absolute:!0});for(let F of w){let O=await Niu(F),G;if(O.size<1048576)G=`${(O.size/1024).toFixed(2)}kb`;else G=`${(O.size/1024/1024).toFixed(2)}mb`;let B=Xa.relative(u.dir,F).replace("dist/","");console.log(`${wA0(CA0(`[${G}]`))} ${CA0("dist/")}${B}`)}console.log(`${wA0(CA0(`[${g}ms]`))} Built ${hrf(wA0(kiu(m)))}`)}async function Rvu(u){let r=u.pkgName??`@stacksjs/${Xa.basename(u.dir)}`;if(u.styled===!1)console.log(`Building ${r}...`);else aiu.info(`Building ${hrf(r)}...`);return{startTime:Date.now()}}async function wvu(u){let{dts:r}=await Promise.resolve().then(() => (trf(),urf)),g=Xa.resolve(u.dir,"src"),m=Xa.resolve(u.dir,"dist"),w=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:g}))).filter((O)=>!O.endsWith(".d.ts"));await Bun.build({entrypoints:w.map((O)=>Xa.resolve(g,O)),outdir:m,root:g,target:"bun",format:"esm",splitting:!1,external:u.external??Aiu(),plugins:[r({root:g,outdir:m})]});let F=new Bun.Transpiler({loader:"ts",target:"bun"});for(let O of w){let G=F.transformSync(await Bun.file(Xa.resolve(g,O)).text());G=G.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let B=Xa.resolve(m,O.replace(/\.ts$/,".js"));await Fiu(Xa.dirname(B),{recursive:!0}),await Bun.write(B,G)}}function Aiu(u=[]){let r=[];try{let g=kw("fs"),m=JSON.parse(g.readFileSync(`${process.cwd()}/package.json`,"utf8"));r=[...Object.keys(m.dependencies??{}),...Object.keys(m.peerDependencies??{}),...Object.keys(m.optionalDependencies??{})]}catch{}return["@stacksjs/*",...r,"bun-queue","ioredis","localtunnels","localtunnels/*","@craft-native/ts","ts-md","meilisearch","algoliasearch","@opensearch-project/opensearch","*.yaml","*.yml",...u]}var export_traverse=t1i.default;var export_parser=u1i.default;var export_generator=i1i.default;export{export_traverse as traverse,wvu as transpilePackage,export_parser as parser,Svu as outro,Rvu as intro,export_generator as generator,Aiu as frameworkExternal};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/build",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.61",
|
|
5
5
|
"description": "The Stacks framework build tools and configurations.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"@babel/traverse": "^7.29.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@stacksjs/cli": "0.70.
|
|
59
|
+
"@stacksjs/cli": "0.70.61",
|
|
60
60
|
"better-dx": "^0.2.12",
|
|
61
|
-
"@stacksjs/path": "0.70.
|
|
62
|
-
"@stacksjs/storage": "0.70.
|
|
61
|
+
"@stacksjs/path": "0.70.61",
|
|
62
|
+
"@stacksjs/storage": "0.70.61"
|
|
63
63
|
}
|
|
64
64
|
}
|