bunup 0.3.66 → 0.3.69

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/build/cli.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{build as qt}from"rolldown";import{dts as Gt}from"rolldown-plugin-dts";class $ extends Error{constructor(t){super(t);this.name="BunupError"}}class x extends ${constructor(t){super(t);this.name="BunupBuildError"}}class d extends ${constructor(t){super(t);this.name="BunupDTSBuildError"}}class m extends ${constructor(t){super(t);this.name="BunupCLIError"}}class M extends ${constructor(t){super(t);this.name="BunupWatchError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)},Nt=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(t,n)=>{let e=p(t),r=n?`[${n}] `:"",i="ERROR";if(t instanceof x)i="BUILD ERROR";else if(t instanceof d)i="DTS ERROR";else if(t instanceof m)i="CLI ERROR";else if(t instanceof M)i="WATCH ERROR";else if(t instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${e}`);let s=Nt.find((o)=>o.pattern.test(e)&&(o.errorType===i||!o.errorType));if(s)console.error(`
4
- \x1B[33mA solution for this error is available at: \x1B[36m${s.link}\x1B[0m
5
- `);else console.error("\x1B[33mThis error might be addressed in the troubleshooting section: \x1B[0m\x1B[36mhttps://bunup.arshadyaseen.com/#troubleshooting\x1B[0m"),console.error("\x1B[33mIf not, please open an issue at: \x1B[0m\x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},tt=(t,n)=>{V(t,n),process.exit(1)};import et from"node:fs/promises";import kt from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function nt(t,n){return{outdir:`${n}/${t.outDir}`,minify:Ut(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function Ut(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:i}=t,s=n===!0;return{whitespace:e??s,identifiers:r??s,syntax:i??s}}function q(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rt(t=8){return Math.random().toString(36).substring(2,2+t)}function st(t,n){switch(t){case"esm":return".mjs";case"cjs":return L(n)?".cjs":".js";case"iife":return".global.js"}}function it(t,n){switch(t){case"esm":return".d.mts";case"cjs":return L(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(t){return t==="module"}function D(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ot(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function at(t,n){return t===void 0?n==="esm":t}function G(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}async function X(t,n){let e=kt.join(t,n);try{await et.rm(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await et.mkdir(e,{recursive:!0})}function Y(t){return t||O.outDir}function ct(t){return t===void 0?O.clean:t}function lt(t,n){return n==="cjs"?t:void 0}function ut(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${q(n)}($|\\/|\\\\)`):n)}function _(t,n){return ut(t.external||[]).concat(ot(n).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function j(t){return ut(t.noExternal||[])}import Ht from"node:path";import{ResolverFactory as Vt}from"oxc-resolver";import C from"node:path";var P="\x00dts:",ft=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(J(r))return r;if(!i||!J(i))return null;let s=await N(r,n,e,T(i));if(!s)return null;let o=v(s);if(t.has(o))return U(o);return null},load(r){if(r.startsWith(P)){let i=T(r),s=t.get(i);if(s)return B.add(i),s}return null}}};function v(t){return t.replace(/\.tsx?$/,".d.ts")}function K(t){let n=C.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?C.resolve(n,t.data.compilerOptions.baseUrl):n}function pt(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let r=K(t);for(let[i,s]of Object.entries(e))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,C.join(r,a))}return n}function Ft(t,n,e){for(let[r,i]of n){let s=new RegExp(r),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return e?C.join(e,t):null}async function Wt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let r=`${t}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(t,n,e,r){let i=t.startsWith(".")?C.resolve(C.dirname(r||""),t):Ft(t,n,e);if(!i)return Promise.resolve(null);return Wt(i)}function J(t){return t.startsWith(P)}function T(t){return t.replace(P,"")}function U(t){return`${P}${t}`}var gt;function dt(t){return{name:"bunup:types-resolve",buildStart(){gt||=new Vt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?T(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let r=e?Ht.dirname(e):process.cwd(),{path:i}=await gt.async(r,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function mt(t,n,e,r,i,s){let o=v(t),a=U(o),c=_(e,r),u=j(e);try{let{output:g}=await qt({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;h(f)},plugins:[ft(n,i,s),typeof e.dts==="object"&&"resolve"in e.dts&&dt(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Gt()],external:(f)=>c.some((h)=>h.test(f))&&!u.some((h)=>h.test(f))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!R.instance)R.instance=new R;return R.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:e,size:r,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${h}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${c}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,r){let i=String(t),s=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,f]of Object.entries(this.colors.progress))if(i.includes(g)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:c.muted});this.output(u,c)}}var l=R.getInstance();var Xt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ht(t,n,e){let r=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Jt(o);for(let c of a){let u=await N(c,n,e,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){l.warn(`Error processing ${s}: ${p(o)}`)}}return r}function Jt(t){let n=new Set;for(let e of[Xt,Yt]){let r;while((r=e.exec(t))!==null)n.add(r[2])}return Array.from(n)}import{isolatedDeclaration as Kt}from"oxc-transform";async function xt(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let r=v(e);if(!await Bun.file(e).exists())return;let s=await Bun.file(e).text(),{code:o}=Kt(e,s);if(o)n.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${p(r)}`)}})),n}import bt from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as Qt}from"oxc-transform";async function wt(t,n){let e=Q.resolve(t),r=Q.resolve(e,n);if(!await bt.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Q.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function yt(t){let n=!1;if(await Promise.all([...t].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=Qt(r,i);s.forEach((o)=>{if(!n)console.log(`
6
- `);let a=o.labels[0],c=a?Zt(i,a.start):"",g=`${b(r)}${c}: ${zt(o.message)}`;l.warn(g),n=!0})}catch{}})),n)l.info(`
3
+ import{build as Gn}from"rolldown";import{dts as Xn}from"rolldown-plugin-dts";class $ extends Error{constructor(n){super(n);this.name="BunupError"}}class x extends ${constructor(n){super(n);this.name="BunupBuildError"}}class d extends ${constructor(n){super(n);this.name="BunupDTSBuildError"}}class m extends ${constructor(n){super(n);this.name="BunupCLIError"}}class M extends ${constructor(n){super(n);this.name="BunupWatchError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)},Un=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(n,t)=>{let e=p(n),r=t?`[${t}] `:"",i="ERROR";if(n instanceof x)i="BUILD ERROR";else if(n instanceof d)i="DTS ERROR";else if(n instanceof m)i="CLI ERROR";else if(n instanceof M)i="WATCH ERROR";else if(n instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${e}`);let s=Un.find((o)=>o.pattern.test(e)&&(o.errorType===i||!o.errorType));if(s)console.error(`
4
+ \x1B[90mA solution for this error is available at: \x1B[36m${s.link}\x1B[0m
5
+ `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},nn=(n,t)=>{V(n,t),process.exit(1)};import en from"node:fs/promises";import Fn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function tn(n,t){return{outdir:`${t}/${n.outDir}`,minify:kn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function kn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:i}=n,s=t===!0;return{whitespace:e??s,identifiers:r??s,syntax:i??s}}function q(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rn(n=8){return Math.random().toString(36).substring(2,2+n)}function sn(n,t){switch(n){case"esm":return".mjs";case"cjs":return L(t)?".cjs":".js";case"iife":return".global.js"}}function on(n,t){switch(n){case"esm":return".d.mts";case"cjs":return L(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(n){return n==="module"}function D(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function an(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function cn(n,t){return n===void 0?t==="esm":n}function G(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function b(n,t=3){return n.split("/").slice(-t).join("/")}async function X(n,t){let e=Fn.join(n,t);try{await en.rm(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await en.mkdir(e,{recursive:!0})}function Y(n){return n||O.outDir}function ln(n){return n===void 0?O.clean:n}function un(n,t){return t==="cjs"?n:void 0}function fn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${q(t)}($|\\/|\\\\)`):t)}function _(n,t){return fn(n.external||[]).concat(an(t).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function j(n){return fn(n.noExternal||[])}import Vn from"node:path";import{ResolverFactory as qn}from"oxc-resolver";import C from"node:path";var T="\x00dts:",pn=(n,t,e)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(J(r))return r;if(!i||!J(i))return null;let s=await N(r,t,e,P(i));if(!s)return null;let o=v(s);if(n.has(o))return U(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=n.get(i);if(s)return B.add(i),s}return null}}};function v(n){return n.replace(/\.tsx?$/,".d.ts")}function K(n){let t=C.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?C.resolve(t,n.data.compilerOptions.baseUrl):t}function gn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=K(n);for(let[i,s]of Object.entries(e))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,C.join(r,a))}return t}function Wn(n,t,e){for(let[r,i]of t){let s=new RegExp(r),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return e?C.join(e,n):null}async function Hn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(n,t,e,r){let i=n.startsWith(".")?C.resolve(C.dirname(r||""),n):Wn(n,t,e);if(!i)return Promise.resolve(null);return Hn(i)}function J(n){return n.startsWith(T)}function P(n){return n.replace(T,"")}function U(n){return`${T}${n}`}var dn;function mn(n){return{name:"bunup:types-resolve",buildStart(){dn||=new qn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?P(e):void 0,/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?Vn.dirname(e):process.cwd(),{path:i}=await dn.async(r,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function hn(n,t,e,r,i,s){let o=v(n),a=U(o),c=_(e,r),u=j(e);try{let{output:g}=await Gn({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;h(f)},plugins:[pn(t,i,s),typeof e.dts==="object"&&"resolve"in e.dts&&mn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Xn()],external:(f)=>c.some((h)=>h.test(f))&&!u.some((h)=>h.test(f))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!R.instance)R.instance=new R;return R.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({colorCode:n,label:t,message:e,size:r,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${h}`}let c=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`}output(n,t={},e=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")}cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)}error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)}progress(n,t,e,r){let i=String(n),s=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,f]of Object.entries(this.colors.progress))if(i.includes(g)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}}var l=R.getInstance();var Yn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Jn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function xn(n,t,e){let r=new Set([n]),i=[n];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Kn(o);for(let c of a){let u=await N(c,t,e,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){l.warn(`Error processing ${s}: ${p(o)}`)}}return r}function Kn(n){let t=new Set;for(let e of[Yn,Jn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}import{isolatedDeclaration as Qn}from"oxc-transform";async function bn(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=v(e);if(!await Bun.file(e).exists())return;let s=await Bun.file(e).text(),{code:o}=Qn(e,s);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${p(r)}`)}})),t}import wn from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as Zn}from"oxc-transform";async function yn(n,t){let e=Q.resolve(n),r=Q.resolve(e,t);if(!await wn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Q.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function En(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=Zn(r,i);s.forEach((o)=>{if(!t)console.log(`
6
+ `);let a=o.labels[0],c=a?zn(i,a.start):"",g=`${b(r)}${c}: ${nt(o.message)}`;l.warn(g),t=!0})}catch{}})),t)l.info(`
7
7
  You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
8
- `)}function Zt(t,n){if(n===void 0)return"";let e=t.slice(0,n).split(`
9
- `),r=e.length,i=e[e.length-1].length+1;return` (${r}:${i})`}function zt(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Et(t,n,e,r,i){let{absoluteEntry:s}=await wt(t,n),o=pt(r),a=K(r),c=await ht(s,o,a),u=await xt(c);return mt(s,u,e,i,o,a)}function A(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function I(t){let n=[],e=new Set,r={};function i(s,o){if(e.has(s)){let a=rt(),c=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
8
+ `)}function zn(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
9
+ `),r=e.length,i=e[e.length-1].length+1;return` (${r}:${i})`}function nt(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $n(n,t,e,r,i){let{absoluteEntry:s}=await yn(n,t),o=gn(r),a=K(r),c=await xn(s,o,a),u=await bn(c);return hn(s,u,e,i,o,a)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function I(n){let t=[],e=new Set,r={};function i(s,o){if(e.has(s)){let a=rn(),c=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
10
10
  Bunup uses filenames without extensions as output names by default.
11
11
 
12
12
  ${r[s]} -> ${s}.js
@@ -20,8 +20,8 @@ To fix this, use named entries in your configuration:
20
20
  }
21
21
  }
22
22
 
23
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:c,path:o})}else n.push({name:s,path:o}),e.add(s),r[s]=o}if(Array.isArray(t))for(let s of t){let o=A(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=A(t);i(s,t)}return n}function $t(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as tn}from"load-tsconfig";function Ot(t){try{return tn(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import Z from"node:path";async function vt(t){let n=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of n){let r=Z.join(t,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let s=await nn(r,e);if(!s)continue;return{configs:sn(s,t),configFilePath:r}}catch(i){throw new x(`Failed to load config from ${r}: ${p(i)}`)}}return{configs:[],configFilePath:""}}async function nn(t,n){if(n===".json"||n===".jsonc")return en(t);return rn(t)}async function en(t){try{let n=await Bun.file(t).text(),e=JSON.parse(n);return e.bunup||e}catch(n){throw new Error(`Invalid JSON in config file. ${p(n)}`)}}async function rn(t){try{let n=await import(`file://${t}`),e=n.default||n;if(!e)return l.warn(`No export found in ${t}. Make sure you're exporting your configuration.`),{};return e}catch(n){throw new Error(`Failed to import config file. ${p(n)}`)}}function sn(t,n){let e=[];if(on(t))an(t,n,e);else if(Array.isArray(t))cn(t,n,e);else if(t&&typeof t==="object")e.push({options:t,rootDir:n});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function on(t){return Array.isArray(t)&&t.length>0&&t.every((n)=>typeof n==="object"&&n!==null&&("name"in n)&&("root"in n)&&("config"in n))}function an(t,n,e){for(let r of t){let i=Z.resolve(n,r.root);if(Array.isArray(r.config))for(let s of r.config)e.push({options:{name:r.name,...s},rootDir:i});else e.push({options:{name:r.name,...r.config},rootDir:i})}}function cn(t,n,e){for(let r of t){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:n})}}async function Bt(t){let n=Z.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let r=await Bun.file(n).text();return{packageJson:JSON.parse(r),path:n}}catch(e){return l.warn(`Failed to load package.json at ${n}: ${p(e)}`),{packageJson:null,path:n}}}function Ct(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let i=r.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var B=new Set;async function k(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await Bt(n);if(e)l.cli(`Using package.json: ${b(r,2)}`,{muted:!0,once:r,identifier:t.name});let i=e?.type,s=_(t,e),o=j(t),a=[Ct(s,o)],c=I(t.entry),u=nt(t,n),g=t.format.flatMap((f)=>c.map((h)=>{return ln(t,n,h,f,i,a,u)}));if(await Promise.all(g),t.dts){let f=Ot(t.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${b(f.path,2)}`,{muted:!0,once:f.path,identifier:t.name});let h=t.format.filter((E)=>{if(E==="iife"&&!L(i)&&t.format.includes("cjs"))return!1;return!0}),Mt=typeof t.dts==="object"&&t.dts.entry?I(t.dts.entry):c;try{await Promise.all(Mt.map(async(E)=>{let Lt=await Et(n,E.path,t,f,e);await Promise.all(h.map(async(Dt)=>{let _t=it(Dt,i),H=`${n}/${t.outDir}/${E.name}${_t}`;await Bun.write(H,Lt);let jt=Bun.file(H).size||0;l.progress("DTS",b(H),G(jt),t.name)}))}))}catch(E){throw new d(p(E))}}}async function ln(t,n,e,r,i,s,o){let a=st(r,i),c=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:r,naming:{entry:$t(e.name,a)},splitting:at(t.splitting,r),bytecode:lt(t.bytecode,r),plugins:s,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),b(u),G(g),t.name)}var F="0.3.66";var Rt="https://bun.sh/docs/installation",Tt="https://bunup.arshadyaseen.com/#cli-options";function w(t){return(n,e)=>{e[t]=n===!0?!0:n==="true"}}function y(t){return(n,e)=>{if(typeof n==="string")e[t]=n;else throw new m(`Option --${t} requires a string value`)}}function Pt(t){return(n,e)=>{if(typeof n==="string")e[t]=n.split(",");else throw new m(`Option --${t} requires a string value`)}}function fn(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:s,path:o}),e.add(s),r[s]=o}if(Array.isArray(n))for(let s of n){let o=A(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=A(n);i(s,n)}return t}function On(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as tt}from"load-tsconfig";function vn(n){try{return tt(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import Z from"node:path";async function Bn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Z.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let s=await et(r,e);if(!s)continue;return{configs:it(s,n),configFilePath:r}}catch(i){throw new x(`Failed to load config from ${r}: ${p(i)}`)}}return{configs:[],configFilePath:""}}async function et(n,t){if(t===".json"||t===".jsonc")return rt(n);return st(n)}async function rt(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${p(t)}`)}}async function st(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${p(t)}`)}}function it(n,t){let e=[];if(ot(n))at(n,t,e);else if(Array.isArray(n))ct(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function ot(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function at(n,t,e){for(let r of n){let i=Z.resolve(t,r.root);if(Array.isArray(r.config))for(let s of r.config)e.push({options:{name:r.name,...s},rootDir:i});else e.push({options:{name:r.name,...r.config},rootDir:i})}}function ct(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function Cn(n){let t=Z.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${p(e)}`),{packageJson:null,path:t}}}function Rn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let i=r.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var B=new Set;async function k(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await Cn(t);if(e)l.cli(`Using package.json: ${b(r,2)}`,{muted:!0,once:r,identifier:n.name});let i=e?.type,s=_(n,e),o=j(n),a=[Rn(s,o)],c=I(n.entry),u=tn(n,t),g=n.format.flatMap((f)=>c.map((h)=>{return lt(n,t,h,f,i,a,u)}));if(await Promise.all(g),n.dts){let f=vn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${b(f.path,2)}`,{muted:!0,once:f.path,identifier:n.name});let h=n.format.filter((E)=>{if(E==="iife"&&!L(i)&&n.format.includes("cjs"))return!1;return!0}),Ln=typeof n.dts==="object"&&n.dts.entry?I(n.dts.entry):c;try{await Promise.all(Ln.map(async(E)=>{let Dn=await $n(t,E.path,n,f,e);await Promise.all(h.map(async(_n)=>{let jn=on(_n,i),H=`${t}/${n.outDir}/${E.name}${jn}`;await Bun.write(H,Dn);let Nn=Bun.file(H).size||0;l.progress("DTS",b(H),G(Nn),n.name)}))}))}catch(E){throw new d(p(E))}}}async function lt(n,t,e,r,i,s,o){let a=sn(r,i),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:On(e.name,a)},splitting:cn(n.splitting,r),bytecode:un(n.bytecode,r),plugins:s,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),b(u),G(g),n.name)}var F="0.3.69";var Pn="https://bun.sh/docs/installation",Tn="https://bunup.arshadyaseen.com/#cli-options";function w(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function y(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new m(`Option --${n} requires a string value`)}}function An(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new m(`Option --${n} requires a string value`)}}function ft(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
- `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Tt}\x1B[0m
26
- `),process.exit(0)}function pn(){console.log(F),process.exit(0)}var gn={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new m("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["b","banner"],handler:y("banner")},footer:{flags:["f","footer"],handler:y("footer")},external:{flags:["e","external"],handler:Pt("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:Pt("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")}},dn={resolveDts:{flags:["rd","resolve-dts"],handler:(t,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof t==="string")if(t==="true"||t==="false")n.dts.resolve=t==="true";else n.dts.resolve=t.split(",");else n.dts.resolve=!0}}},mn={help:{flags:["h","help"],handler:()=>fn()},version:{flags:["v","version"],handler:()=>pn()}},S={};for(let t of Object.values(gn))if(t)for(let n of t.flags)S[n]=t.handler;for(let t of Object.values(dn))for(let n of t.flags)S[n]=t.handler;for(let t of Object.values(mn))for(let n of t.flags)S[n]=t.handler;function At(t){let n={},e={},r=0;while(r<t.length){let i=t[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,c]=i.slice(2).split("=",2);s=a,o=c}else{s=i.slice(2);let a=t[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new m("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new m(`Option --entry.${a} requires a string value`)}else{let a=S[s];if(a)a(o,n);else throw new m(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=t[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=S[s];if(c)c(a,n);else throw new m(`Unknown option: -${s}`)}else{let s=A(i);if(e[s])l.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);e[s]=i}r++}if(Object.keys(e).length>0)n.entry=e;return n}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
27
- To install Bun, visit `+Rt)})();import W from"node:path";import hn from"chokidar";async function It(t,n){let e=new Set,r=I(t.entry);r.forEach((a)=>{let c=W.resolve(n,a.path),u=W.dirname(c);e.add(u)});let i=hn.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(n,t.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let c=performance.now();if(await k({...t,entry:r.map((u)=>u.path),clean:!1},n),t.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${D(performance.now()-c)}`);await z()}catch(c){V(c)}finally{s=!1}};i.on("change",(a)=>{let c=W.relative(n,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new M(`Watcher error: ${p(a)}`)}),await o(!0)}async function xn(t=Bun.argv.slice(2)){let n=At(t),{configs:e,configFilePath:r}=await vt(process.cwd());if(l.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${b(r,2)}`,{muted:!0});let i=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...n},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await St(a,c)}else{for(let{options:a,rootDir:c}of e)if(ct(a.clean))X(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...O,...a,...n};await St(u,c)}))}let s=performance.now()-i,o=D(s);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),n.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!n.watch)process.exit(0);l.dispose()}async function z(){if(B.size>0)await yt(B),B.clear()}async function St(t,n){if(t.watch)await It(t,n);else await k(t,n),t.onBuildSuccess?.()}xn().catch((t)=>tt(t));export{z as validateDtsFiles,xn as main};
25
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Tn}\x1B[0m
26
+ `),process.exit(0)}function pt(){console.log(F),process.exit(0)}var gt={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new m("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["b","banner"],handler:y("banner")},footer:{flags:["f","footer"],handler:y("footer")},external:{flags:["e","external"],handler:An("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:An("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")}},dt={resolveDts:{flags:["rd","resolve-dts"],handler:(n,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof n==="string")if(n==="true"||n==="false")t.dts.resolve=n==="true";else t.dts.resolve=n.split(",");else t.dts.resolve=!0}}},mt={help:{flags:["h","help"],handler:()=>ft()},version:{flags:["v","version"],handler:()=>pt()}},S={};for(let n of Object.values(gt))if(n)for(let t of n.flags)S[t]=n.handler;for(let n of Object.values(dt))for(let t of n.flags)S[t]=n.handler;for(let n of Object.values(mt))for(let t of n.flags)S[t]=n.handler;function In(n){let t={},e={},r=0;while(r<n.length){let i=n[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,c]=i.slice(2).split("=",2);s=a,o=c}else{s=i.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new m("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new m(`Option --entry.${a} requires a string value`)}else{let a=S[s];if(a)a(o,t);else throw new m(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=S[s];if(c)c(a,t);else throw new m(`Unknown option: -${s}`)}else{let s=A(i);if(e[s])l.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);e[s]=i}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
27
+ To install Bun, visit `+Pn)})();import W from"node:path";import ht from"chokidar";async function Sn(n,t){let e=new Set,r=I(n.entry);r.forEach((a)=>{let c=W.resolve(t,a.path),u=W.dirname(c);e.add(u)});let i=ht.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(t,n.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let c=performance.now();if(await k({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${D(performance.now()-c)}`);await z()}catch(c){V(c)}finally{s=!1}};i.on("change",(a)=>{let c=W.relative(t,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new M(`Watcher error: ${p(a)}`)}),await o(!0)}async function xt(n=Bun.argv.slice(2)){let t=In(n),{configs:e,configFilePath:r}=await Bn(process.cwd());if(l.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${b(r,2)}`,{muted:!0});let i=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...t},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await Mn(a,c)}else{for(let{options:a,rootDir:c}of e)if(ln(a.clean))X(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...O,...a,...t};await Mn(u,c)}))}let s=performance.now()-i,o=D(s);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0);l.dispose()}async function z(){if(B.size>0)await En(B),B.clear()}async function Mn(n,t){if(n.watch)await Sn(n,t);else await k(n,t),n.onBuildSuccess?.()}xt().catch((n)=>nn(n));export{z as validateDtsFiles,xt as main};
package/build/index.js CHANGED
@@ -1,15 +1,15 @@
1
- var It=require("node:module");var Pt=Object.create;var{getPrototypeOf:Dt,defineProperty:R,getOwnPropertyNames:U,getOwnPropertyDescriptor:Ot}=Object,V=Object.prototype.hasOwnProperty;var x=(t,n,r)=>{r=t!=null?Pt(Dt(t)):{};let e=n||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r;for(let o of U(t))if(!V.call(e,o))R(e,o,{get:()=>t[o],enumerable:!0});return e},F=new WeakMap,Tt=(t)=>{var n=F.get(t),r;if(n)return n;if(n=R({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")U(t).map((e)=>!V.call(n,e)&&R(n,e,{get:()=>t[e],enumerable:!(r=Ot(t,e))||r.enumerable}));return F.set(t,n),n};var At=(t,n)=>{for(var r in n)R(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var Gt={};At(Gt,{defineWorkspace:()=>X,defineConfig:()=>G,build:()=>$t});module.exports=Tt(Gt);function G(t){return t}function X(t){return t}var it=require("rolldown"),at=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends S{constructor(t){super(t);this.name="BunupBuildError"}}class d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};var vt=x(require("node:fs/promises")),Lt=x(require("node:path"));function k(t,n){return{outdir:`${n}/${t.outDir}`,minify:St(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function St(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:o}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:o??s}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function H(t=8){return Math.random().toString(36).substring(2,2+t)}function Y(t,n){switch(t){case"esm":return".mjs";case"cjs":return M(n)?".cjs":".js";case"iife":return".global.js"}}function K(t,n){switch(t){case"esm":return".d.mts";case"cjs":return M(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(t){return t==="module"}function q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function J(t,n){return t===void 0?n==="esm":t}function L(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function Q(t,n){return n==="cjs"?t:void 0}function Z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function P(t,n){return Z(t.external||[]).concat(q(n).map((r)=>new RegExp(`^${v(r)}($|\\/|\\\\)`)))}function D(t){return Z(t.noExternal||[])}var et=x(require("node:path")),st=require("oxc-resolver");var h=x(require("node:path"));var B="\x00dts:",z=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(j(e))return e;if(!o||!j(o))return null;let s=await O(e,n,r,C(o));if(!s)return null;let i=$(s);if(t.has(i))return T(i);return null},load(e){if(e.startsWith(B)){let o=C(e),s=t.get(o);if(s)return tt.add(o),s}return null}}};function $(t){return t.replace(/\.tsx?$/,".d.ts")}function _(t){let n=h.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?h.default.resolve(n,t.data.compilerOptions.baseUrl):n}function nt(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=_(t);for(let[o,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let i=o.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${i}$`,h.default.join(e,a))}return n}function jt(t,n,r){for(let[e,o]of n){let s=new RegExp(e),i=t.match(s);if(i)return o.replace("$1",i[1]||"")}return r?h.default.join(r,t):null}async function _t(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function O(t,n,r,e){let o=t.startsWith(".")?h.default.resolve(h.default.dirname(e||""),t):jt(t,n,r);if(!o)return Promise.resolve(null);return _t(o)}function j(t){return t.startsWith(B)}function C(t){return t.replace(B,"")}function T(t){return`${B}${t}`}var rt;function ot(t){return{name:"bunup:types-resolve",buildStart(){rt||=new st.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?C(r):void 0,/\0/.test(n))return;if(t){if(!t.some((i)=>{let a=!1;if(typeof i==="string")a=i===n||!!(r&&r.includes(i));else a=i.test(n)||!!(r&&i.test(r));return a}))return}let e=r?et.default.dirname(r):process.cwd(),{path:o}=await rt.async(e,n);if(!o)return;if(/[cm]?jsx?$/.test(o)){let s=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return o}}}async function ct(t,n,r,e,o,s){let i=$(t),a=T(i),u=P(r,e),l=D(r);try{let{output:g}=await it.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;p(c)},plugins:[z(n,o,s),typeof r.dts==="object"&&"resolve"in r.dts&&ot(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),at.dts()],external:(c)=>u.some((p)=>p.test(c))&&!l.some((p)=>p.test(c))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${m(g)}`)}}class y{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!y.instance)y.instance=new y;return y.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:o,muted:s}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),p=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${l}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${p}`}let u=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let o=String(t),s=this.colors.default,i,a,u={};if(typeof r==="string")i=r,a=e;else if(r)i=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(o.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:o,message:n,size:i,identifier:a,muted:u.muted});this.output(l,u)}}var f=y.getInstance();var Nt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Wt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ut(t,n,r){let e=new Set([t]),o=[t];while(o.length){let s=o.pop();if(!s)continue;try{let i=await Bun.file(s).text(),a=Ft(i);for(let u of a){let l=await O(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),o.push(l)}}catch(i){f.warn(`Error processing ${s}: ${m(i)}`)}}return e}function Ft(t){let n=new Set;for(let r of[Nt,Wt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}var lt=require("oxc-transform");async function ft(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=$(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:i}=lt.isolatedDeclaration(r,s);if(i)n.set(e,i)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${m(e)}`)}})),n}var N=x(require("node:fs/promises")),A=x(require("node:path")),Ut=require("oxc-transform");async function gt(t,n){let r=A.default.resolve(t),e=A.default.resolve(r,n);if(!await N.default.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function mt(t,n,r,e,o){let{absoluteEntry:s}=await gt(t,n),i=nt(e),a=_(e),u=await ut(s,i,a),l=await ft(u);return ct(s,l,r,o,i,a)}function pt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],r=new Set,e={};function o(s,i){if(r.has(s)){let a=H(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ var It=require("node:module");var Bt=Object.create;var{getPrototypeOf:Dt,defineProperty:R,getOwnPropertyNames:U,getOwnPropertyDescriptor:Ot}=Object,V=Object.prototype.hasOwnProperty;var x=(t,n,r)=>{r=t!=null?Bt(Dt(t)):{};let e=n||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r;for(let i of U(t))if(!V.call(e,i))R(e,i,{get:()=>t[i],enumerable:!0});return e},F=new WeakMap,At=(t)=>{var n=F.get(t),r;if(n)return n;if(n=R({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")U(t).map((e)=>!V.call(n,e)&&R(n,e,{get:()=>t[e],enumerable:!(r=Ot(t,e))||r.enumerable}));return F.set(t,n),n};var Tt=(t,n)=>{for(var r in n)R(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var kt={};Tt(kt,{defineWorkspace:()=>G,defineConfig:()=>k,build:()=>$t});module.exports=At(kt);function k(t){return t}function G(t){return t}var ot=require("rolldown"),at=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends S{constructor(t){super(t);this.name="BunupBuildError"}}class d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};var vt=x(require("node:fs/promises")),Lt=x(require("node:path"));function X(t,n){return{outdir:`${n}/${t.outDir}`,minify:St(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function St(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function H(t=8){return Math.random().toString(36).substring(2,2+t)}function Y(t,n){switch(t){case"esm":return".mjs";case"cjs":return P(n)?".cjs":".js";case"iife":return".global.js"}}function K(t,n){switch(t){case"esm":return".d.mts";case"cjs":return P(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function P(t){return t==="module"}function q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function J(t,n){return t===void 0?n==="esm":t}function L(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function Q(t,n){return n==="cjs"?t:void 0}function Z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function B(t,n){return Z(t.external||[]).concat(q(n).map((r)=>new RegExp(`^${v(r)}($|\\/|\\\\)`)))}function D(t){return Z(t.noExternal||[])}var et=x(require("node:path")),st=require("oxc-resolver");var h=x(require("node:path"));var M="\x00dts:",z=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(j(e))return e;if(!i||!j(i))return null;let s=await O(e,n,r,C(i));if(!s)return null;let o=$(s);if(t.has(o))return A(o);return null},load(e){if(e.startsWith(M)){let i=C(e),s=t.get(i);if(s)return tt.add(i),s}return null}}};function $(t){return t.replace(/\.tsx?$/,".d.ts")}function _(t){let n=h.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?h.default.resolve(n,t.data.compilerOptions.baseUrl):n}function nt(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=_(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,h.default.join(e,a))}return n}function jt(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?h.default.join(r,t):null}async function _t(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function O(t,n,r,e){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(e||""),t):jt(t,n,r);if(!i)return Promise.resolve(null);return _t(i)}function j(t){return t.startsWith(M)}function C(t){return t.replace(M,"")}function A(t){return`${M}${t}`}var rt;function it(t){return{name:"bunup:types-resolve",buildStart(){rt||=new st.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?C(r):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(r&&r.includes(o));else a=o.test(n)||!!(r&&o.test(r));return a}))return}let e=r?et.default.dirname(r):process.cwd(),{path:i}=await rt.async(e,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function ct(t,n,r,e,i,s){let o=$(t),a=A(o),u=B(r,e),l=D(r);try{let{output:g}=await ot.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[z(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&it(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),at.dts()],external:(c)=>u.some((m)=>m.test(c))&&!l.some((m)=>m.test(c))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class y{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!y.instance)y.instance=new y;return y.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,u={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:u.muted});this.output(l,u)}}var f=y.getInstance();var Nt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Wt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ut(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Ft(o);for(let u of a){let l=await O(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${p(o)}`)}}return e}function Ft(t){let n=new Set;for(let r of[Nt,Wt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}var lt=require("oxc-transform");async function ft(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=$(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=lt.isolatedDeclaration(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}var N=x(require("node:fs/promises")),T=x(require("node:path")),Ut=require("oxc-transform");async function gt(t,n){let r=T.default.resolve(t),e=T.default.resolve(r,n);if(!await N.default.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(T.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function pt(t,n,r,e,i){let{absoluteEntry:s}=await gt(t,n),o=nt(e),a=_(e),u=await ut(s,o,a),l=await ft(u);return ct(s,l,r,i,o,a)}function mt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=H(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${e[s]} -> ${s}.js
5
- ${i} -> ${u}.js (auto-renamed to avoid conflict)
5
+ ${o} -> ${u}.js (auto-renamed to avoid conflict)
6
6
 
7
7
  To fix this, use named entries in your configuration:
8
8
  {
9
9
  entry: {
10
10
  custom_name: "${e[s]}",
11
- another_name: "${i}"
11
+ another_name: "${o}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:i})}else n.push({name:s,path:i}),r.add(s),e[s]=i}if(Array.isArray(t))for(let s of t){let i=pt(s);o(i,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,i])=>{o(s,i)});else{let s=pt(t);o(s,t)}return n}function dt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}var Et=x(require("node:path"));async function wt(t){let n=Et.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${m(r)}`),{packageJson:null,path:n}}}function bt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let o=e.path;if(t.some((i)=>i.test(o))&&!n.some((i)=>i.test(o)))return{path:o,external:!0};return null})}}}var tt=new Set;async function $t(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await wt(n);if(r)f.cli(`Using package.json: ${b(e,2)}`,{muted:!0,once:e,identifier:t.name});let o=r?.type,s=P(t,r),i=D(t),a=[bt(s,i)],u=W(t.entry),l=k(t,n),g=t.format.flatMap((c)=>u.map((p)=>{return Vt(t,n,p,c,o,a,l)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${b(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let p=t.format.filter((E)=>{if(E==="iife"&&!M(o)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):u;try{await Promise.all(yt.map(async(E)=>{let Rt=await mt(n,E.path,t,c,r);await Promise.all(p.map(async(Ct)=>{let Bt=K(Ct,o),I=`${n}/${t.outDir}/${E.name}${Bt}`;await Bun.write(I,Rt);let Mt=Bun.file(I).size||0;f.progress("DTS",b(I),L(Mt),t.name)}))}))}catch(E){throw new d(m(E))}}}async function Vt(t,n,r,e,o,s,i){let a=Y(e,o),u=await Bun.build({...i,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:dt(r.name,a)},splitting:J(t.splitting,e),bytecode:Q(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),b(l),L(g),t.name)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=mt(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=mt(t);i(s,t)}return n}function dt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}var Et=x(require("node:path"));async function wt(t){let n=Et.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function bt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var tt=new Set;async function $t(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await wt(n);if(r)f.cli(`Using package.json: ${b(e,2)}`,{muted:!0,once:e,identifier:t.name});let i=r?.type,s=B(t,r),o=D(t),a=[bt(s,o)],u=W(t.entry),l=X(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Vt(t,n,m,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${b(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((E)=>{if(E==="iife"&&!P(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):u;try{await Promise.all(yt.map(async(E)=>{let Rt=await pt(n,E.path,t,c,r);await Promise.all(m.map(async(Ct)=>{let Mt=K(Ct,i),I=`${n}/${t.outDir}/${E.name}${Mt}`;await Bun.write(I,Rt);let Pt=Bun.file(I).size||0;f.progress("DTS",b(I),L(Pt),t.name)}))}))}catch(E){throw new d(p(E))}}}async function Vt(t,n,r,e,i,s,o){let a=Y(e,i),u=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:dt(r.name,a)},splitting:J(t.splitting,e),bytecode:Q(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),b(l),L(g),t.name)}
package/build/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- function gt(t){return t}function mt(t){return t}import{build as wt}from"rolldown";import{dts as bt}from"rolldown-plugin-dts";class T extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends T{constructor(t){super(t);this.name="BunupBuildError"}}class d extends T{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import jt from"node:path";function _(t,n){return{outdir:`${n}/${t.outDir}`,minify:pt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function pt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:o}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:o??s}}function A(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function F(t,n){switch(t){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function U(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function E(t,n=3){return t.split("/").slice(-n).join("/")}function G(t,n){return n==="cjs"?t:void 0}function X(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${A(n)}($|\\/|\\\\)`):n)}function B(t,n){return X(t.external||[]).concat(U(n).map((r)=>new RegExp(`^${A(r)}($|\\/|\\\\)`)))}function M(t){return X(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as Et}from"oxc-resolver";import b from"node:path";var R="\x00dts:",k=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(S(e))return e;if(!o||!S(o))return null;let s=await P(e,n,r,y(o));if(!s)return null;let i=w(s);if(t.has(i))return D(i);return null},load(e){if(e.startsWith(R)){let o=y(e),s=t.get(o);if(s)return H.add(o),s}return null}}};function w(t){return t.replace(/\.tsx?$/,".d.ts")}function v(t){let n=b.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?b.resolve(n,t.data.compilerOptions.baseUrl):n}function Y(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=v(t);for(let[o,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let i=o.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${i}$`,b.join(e,a))}return n}function dt(t,n,r){for(let[e,o]of n){let s=new RegExp(e),i=t.match(s);if(i)return o.replace("$1",i[1]||"")}return r?b.join(r,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function P(t,n,r,e){let o=t.startsWith(".")?b.resolve(b.dirname(e||""),t):dt(t,n,r);if(!o)return Promise.resolve(null);return xt(o)}function S(t){return t.startsWith(R)}function y(t){return t.replace(R,"")}function D(t){return`${R}${t}`}var K;function q(t){return{name:"bunup:types-resolve",buildStart(){K||=new Et({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?y(r):void 0,/\0/.test(n))return;if(t){if(!t.some((i)=>{let a=!1;if(typeof i==="string")a=i===n||!!(r&&r.includes(i));else a=i.test(n)||!!(r&&i.test(r));return a}))return}let e=r?ht.dirname(r):process.cwd(),{path:o}=await K.async(e,n);if(!o)return;if(/[cm]?jsx?$/.test(o)){let s=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return o}}}async function J(t,n,r,e,o,s){let i=w(t),a=D(i),u=B(r,e),l=M(r);try{let{output:g}=await wt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;p(c)},plugins:[k(n,o,s),typeof r.dts==="object"&&"resolve"in r.dts&&q(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),bt()],external:(c)=>u.some((p)=>p.test(c))&&!l.some((p)=>p.test(c))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${m(g)}`)}}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!$.instance)$.instance=new $;return $.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:o,muted:s}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),p=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${l}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${p}`}let u=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let o=String(t),s=this.colors.default,i,a,u={};if(typeof r==="string")i=r,a=e;else if(r)i=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(o.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:o,message:n,size:i,identifier:a,muted:u.muted});this.output(l,u)}}var f=$.getInstance();var $t=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Q(t,n,r){let e=new Set([t]),o=[t];while(o.length){let s=o.pop();if(!s)continue;try{let i=await Bun.file(s).text(),a=Rt(i);for(let u of a){let l=await P(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),o.push(l)}}catch(i){f.warn(`Error processing ${s}: ${m(i)}`)}}return e}function Rt(t){let n=new Set;for(let r of[$t,yt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}import{isolatedDeclaration as Ct}from"oxc-transform";async function Z(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=w(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:i}=Ct(r,s);if(i)n.set(e,i)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${m(e)}`)}})),n}import z from"node:fs/promises";import L from"node:path";import{isolatedDeclaration as $n}from"oxc-transform";async function tt(t,n){let r=L.resolve(t),e=L.resolve(r,n);if(!await z.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(L.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function nt(t,n,r,e,o){let{absoluteEntry:s}=await tt(t,n),i=Y(e),a=v(e),u=await Q(s,i,a),l=await Z(u);return J(s,l,r,o,i,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set,e={};function o(s,i){if(r.has(s)){let a=N(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function gt(t){return t}function pt(t){return t}import{build as wt}from"rolldown";import{dts as bt}from"rolldown-plugin-dts";class A extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends A{constructor(t){super(t);this.name="BunupBuildError"}}class d extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import jt from"node:path";function _(t,n){return{outdir:`${n}/${t.outDir}`,minify:mt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function mt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function T(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function F(t,n){switch(t){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function U(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function E(t,n=3){return t.split("/").slice(-n).join("/")}function k(t,n){return n==="cjs"?t:void 0}function G(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${T(n)}($|\\/|\\\\)`):n)}function M(t,n){return G(t.external||[]).concat(U(n).map((r)=>new RegExp(`^${T(r)}($|\\/|\\\\)`)))}function P(t){return G(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as Et}from"oxc-resolver";import b from"node:path";var R="\x00dts:",X=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(S(e))return e;if(!i||!S(i))return null;let s=await B(e,n,r,y(i));if(!s)return null;let o=w(s);if(t.has(o))return D(o);return null},load(e){if(e.startsWith(R)){let i=y(e),s=t.get(i);if(s)return H.add(i),s}return null}}};function w(t){return t.replace(/\.tsx?$/,".d.ts")}function v(t){let n=b.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?b.resolve(n,t.data.compilerOptions.baseUrl):n}function Y(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=v(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,b.join(e,a))}return n}function dt(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?b.join(r,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function B(t,n,r,e){let i=t.startsWith(".")?b.resolve(b.dirname(e||""),t):dt(t,n,r);if(!i)return Promise.resolve(null);return xt(i)}function S(t){return t.startsWith(R)}function y(t){return t.replace(R,"")}function D(t){return`${R}${t}`}var K;function q(t){return{name:"bunup:types-resolve",buildStart(){K||=new Et({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?y(r):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(r&&r.includes(o));else a=o.test(n)||!!(r&&o.test(r));return a}))return}let e=r?ht.dirname(r):process.cwd(),{path:i}=await K.async(e,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function J(t,n,r,e,i,s){let o=w(t),a=D(o),u=M(r,e),l=P(r);try{let{output:g}=await wt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[X(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&q(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),bt()],external:(c)=>u.some((m)=>m.test(c))&&!l.some((m)=>m.test(c))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!$.instance)$.instance=new $;return $.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,u={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:u.muted});this.output(l,u)}}var f=$.getInstance();var $t=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Q(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Rt(o);for(let u of a){let l=await B(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${p(o)}`)}}return e}function Rt(t){let n=new Set;for(let r of[$t,yt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}import{isolatedDeclaration as Ct}from"oxc-transform";async function Z(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=w(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=Ct(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}import z from"node:fs/promises";import L from"node:path";import{isolatedDeclaration as $n}from"oxc-transform";async function tt(t,n){let r=L.resolve(t),e=L.resolve(r,n);if(!await z.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(L.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function nt(t,n,r,e,i){let{absoluteEntry:s}=await tt(t,n),o=Y(e),a=v(e),u=await Q(s,o,a),l=await Z(u);return J(s,l,r,i,o,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=N(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${e[s]} -> ${s}.js
5
- ${i} -> ${u}.js (auto-renamed to avoid conflict)
5
+ ${o} -> ${u}.js (auto-renamed to avoid conflict)
6
6
 
7
7
  To fix this, use named entries in your configuration:
8
8
  {
9
9
  entry: {
10
10
  custom_name: "${e[s]}",
11
- another_name: "${i}"
11
+ another_name: "${o}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:i})}else n.push({name:s,path:i}),r.add(s),e[s]=i}if(Array.isArray(t))for(let s of t){let i=rt(s);o(i,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,i])=>{o(s,i)});else{let s=rt(t);o(s,t)}return n}function et(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Bt}from"load-tsconfig";function st(t){try{return Bt(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}import Mt from"node:path";async function ot(t){let n=Mt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${m(r)}`),{packageJson:null,path:n}}}function it(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let o=e.path;if(t.some((i)=>i.test(o))&&!n.some((i)=>i.test(o)))return{path:o,external:!0};return null})}}}var H=new Set;async function Pt(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await ot(n);if(r)f.cli(`Using package.json: ${E(e,2)}`,{muted:!0,once:e,identifier:t.name});let o=r?.type,s=B(t,r),i=M(t),a=[it(s,i)],u=j(t.entry),l=_(t,n),g=t.format.flatMap((c)=>u.map((p)=>{return Dt(t,n,p,c,o,a,l)}));if(await Promise.all(g),t.dts){let c=st(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let p=t.format.filter((x)=>{if(x==="iife"&&!C(o)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?j(t.dts.entry):u;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,r);await Promise.all(p.map(async(ut)=>{let lt=F(ut,o),O=`${n}/${t.outDir}/${x.name}${lt}`;await Bun.write(O,ct);let ft=Bun.file(O).size||0;f.progress("DTS",E(O),I(ft),t.name)}))}))}catch(x){throw new d(m(x))}}}async function Dt(t,n,r,e,o,s,i){let a=W(e,o),u=await Bun.build({...i,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:et(r.name,a)},splitting:V(t.splitting,e),bytecode:G(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),E(l),I(g),t.name)}export{mt as defineWorkspace,gt as defineConfig,Pt as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=rt(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=rt(t);i(s,t)}return n}function et(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Mt}from"load-tsconfig";function st(t){try{return Mt(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import Pt from"node:path";async function it(t){let n=Pt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function ot(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var H=new Set;async function Bt(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await it(n);if(r)f.cli(`Using package.json: ${E(e,2)}`,{muted:!0,once:e,identifier:t.name});let i=r?.type,s=M(t,r),o=P(t),a=[ot(s,o)],u=j(t.entry),l=_(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Dt(t,n,m,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=st(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((x)=>{if(x==="iife"&&!C(i)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?j(t.dts.entry):u;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,r);await Promise.all(m.map(async(ut)=>{let lt=F(ut,i),O=`${n}/${t.outDir}/${x.name}${lt}`;await Bun.write(O,ct);let ft=Bun.file(O).size||0;f.progress("DTS",E(O),I(ft),t.name)}))}))}catch(x){throw new d(p(x))}}}async function Dt(t,n,r,e,i,s,o){let a=W(e,i),u=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:et(r.name,a)},splitting:V(t.splitting,e),bytecode:k(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),E(l),I(g),t.name)}export{pt as defineWorkspace,gt as defineConfig,Bt as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.66",
3
+ "version": "0.3.69",
4
4
  "description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "prettier": "^3.5.3",
25
25
  "typescript": "^5.8.3",
26
26
  "vitest": "^2.1.9",
27
- "create-bunup": "0.3.66"
27
+ "create-bunup": "0.3.69"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "typescript": ">=4.5.0"