bunup 0.3.89 → 0.3.91

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,27 +1,27 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{build as Ge}from"rolldown";import{dts as Xe}from"rolldown-plugin-dts";class $ extends Error{constructor(e){super(e);this.name="BunupError"}}class y extends ${constructor(e){super(e);this.name="BunupBuildError"}}class d extends ${constructor(e){super(e);this.name="BunupDTSBuildError"}}class g extends ${constructor(e){super(e);this.name="BunupCLIError"}}class A extends ${constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},We=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",i="ERROR";if(e instanceof y)i="BUILD ERROR";else if(e instanceof d)i="DTS ERROR";else if(e instanceof g)i="CLI ERROR";else if(e instanceof A)i="WATCH ERROR";else if(e instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${n}`);let o=We.find((s)=>s.pattern.test(n)&&(s.errorType===i||!s.errorType));if(o)console.error(`
3
+ import{build as qe}from"rolldown";import{dts as Ve}from"rolldown-plugin-dts";class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class d extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class g extends E{constructor(e){super(e);this.name="BunupCLIError"}}class v extends E{constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ne=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],q=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof d)s="DTS ERROR";else if(e instanceof g)s="CLI ERROR";else if(e instanceof v)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";console.error(`\x1B[31m${s}\x1B[0m ${r}${n}`);let o=Ne.find((i)=>i.pattern.test(n)&&(i.errorType===s||!i.errorType));if(o)console.error(`
4
4
  \x1B[90mA solution for this error is available at: \x1B[36m${o.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")},z=(e,t)=>{V(e,t),process.exit(1)};import J from"node:fs/promises";import je from"node:path";function G(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ee(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function te(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function ne(e){return Array.isArray(e)?e:[e]}function re(e,t){switch(e){case"esm":return".mjs";case"cjs":return M(t)?".cjs":".js";case"iife":return".global.js"}}function se(e,t){switch(e){case"esm":return".d.mts";case"cjs":return M(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(e){return e==="module"}function I(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function ie(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function oe(e,t){return e===void 0?t==="esm":e}function X(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function b(e,t=3){return e.split("/").slice(-t).join("/")}async function ae(e,t){let n=je.join(e,t);try{await J.rm(n,{recursive:!0,force:!0})}catch(r){throw new y(`Failed to clean output directory: ${r}`)}await J.mkdir(n,{recursive:!0})}function le(e,t){return t==="cjs"?e:void 0}function ce(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function D(e,t){return ce(e.external||[]).concat(ie(t).map((n)=>new RegExp(`^${G(n)}($|\\/|\\\\)`)))}function U(e){return ce(e.noExternal||[])}import qe from"node:path";import{ResolverFactory as Ve}from"oxc-resolver";import O from"node:path";var T="\x00dts:",ue=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(Y(r))return r;if(!i||!Y(i))return null;let o=await _(r,t,n,v(i));if(!o)return null;let s=C(o);if(e.has(s))return N(s);return null},load(r){if(r.startsWith(T)){let i=v(r),o=e.get(i);if(o)return R.add(i),o}return null}}};function fe(e){return e.tsconfig?.compilerOptions}function C(e){return e.replace(/\.tsx?$/,".d.ts")}function K(e){let t=O.dirname(e.path||""),n=fe(e);return n?.baseUrl?O.resolve(t,n.baseUrl):t}function pe(e){let t=new Map,n=fe(e)?.paths;if(!n)return t;let r=K(e);for(let[i,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let s=i.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");t.set(`^${s}$`,O.join(r,a))}return t}function Fe(e,t,n){for(let[r,i]of t){let o=new RegExp(r),s=e.match(o);if(s)return i.replace("$1",s[1]||"")}return n?O.join(n,e):null}async function He(e){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function _(e,t,n,r){let i=e.startsWith(".")?O.resolve(O.dirname(r||""),e):Fe(e,t,n);if(!i)return Promise.resolve(null);return He(i)}function Y(e){return e.startsWith(T)}function v(e){return e.replace(T,"")}function N(e){return`${T}${e}`}var me;function de(e){return{name:"bunup:types-resolve",buildStart(){me||=new Ve({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?v(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let i=r?qe.dirname(r):process.cwd(),{path:o}=await me.async(i,t);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 ge(e,t,n,r,i,o){let s=C(e),a=N(s),l=D(n,r),u=U(n);try{let{output:p}=await Ge({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;m(f)},plugins:[ue(t,i,o),typeof n.dts==="object"&&"resolve"in n.dts&&de(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Xe({dtsInput:!0})],external:(f)=>l.some((m)=>m.test(f))&&!u.some((m)=>m.test(f))});if(!p[0]?.code)throw new d("Generated bundle is empty");return p[0].code}catch(p){throw new d(`DTS bundling failed: ${h(p)}`)}}var he=!1;function k(e){he=e??!1}class B{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(!B.instance)B.instance=new B;return B.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,size:r,identifier:i,muted:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${s}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${m}`}let l=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${s}${a}${l}`}output(e,t={},n=console.log){if(he)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let i=String(e),o=this.colors.default,s,a,l={};if(typeof n==="string")s=n,a=r;else if(n)s=n.size,a=n.identifier,l=n;for(let[p,f]of Object.entries(this.colors.progress))if(i.includes(p)){o=f;break}let u=this.formatMessage({colorCode:o,label:i,message:t,size:s,identifier:a,muted:l.muted});this.output(u,l)}}var c=B.getInstance();var Ye=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ke=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Qe=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ze=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,et=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function tt(e){let t=new Set,n=[Ye,Ke,Qe,Ze,ze,Je,et];for(let r of n){let i=e.matchAll(r);for(let o of i)if(o[1])t.add(o[1])}return t}async function xe(e,t,n){let r=new Set([e]),i=[e];while(i.length){let o=i.pop();if(!o)continue;try{let s=await Bun.file(o).text(),a=tt(s);for(let l of a){let u=await _(l,t,n,o);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(s){c.warn(`Error processing ${o}: ${h(s)}`)}}return r}import{isolatedDeclaration as nt}from"oxc-transform";async function be(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=C(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:s}=nt(n,o);if(s)t.set(r,s)}catch(r){c.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import ye from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as rt}from"oxc-transform";async function we(e,t){let n=Q.resolve(e),r=Q.resolve(n,t);if(!await ye.exists(n))throw new d(`Root directory does not exist: ${n}`);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(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Ee(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:o}=rt(r,i);for(let s of o){if(!t)console.log(`
6
- `);let a=s.labels[0],l=a?st(i,a.start):"",p=`${b(r)}${l}: ${it(s.message)}`;c.warn(p),t=!0}}catch{}})),t)c.info(`
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")},Z=(e,t)=>{q(e,t),process.exit(1)};import z from"node:fs/promises";import ke from"node:path";function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function J(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function ee(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function te(e){return Array.isArray(e)?e:[e]}function ne(e,t){switch(e){case"esm":return".mjs";case"cjs":return L(t)?".cjs":".js";case"iife":return".global.js"}}function re(e,t){switch(e){case"esm":return".d.mts";case"cjs":return L(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(e){return e==="module"}function S(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function se(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ie(e,t){return e===void 0?t==="esm":e}function G(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function b(e,t=3){return e.split("/").slice(-t).join("/")}async function oe(e,t){let n=ke.join(e,t);try{await z.rm(n,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await z.mkdir(n,{recursive:!0})}function ae(e,t){return t==="cjs"?e:void 0}function le(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${V(t)}($|\\/|\\\\)`):t)}function A(e,t){return le(e.external||[]).concat(se(t).map((n)=>new RegExp(`^${V(n)}($|\\/|\\\\)`)))}function I(e){return le(e.noExternal||[])}import Fe from"node:path";import{ResolverFactory as He}from"oxc-resolver";import R from"node:path";var T="\x00dts:",ce=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(X(r))return r;if(!s||!X(s))return null;let o=await M(r,t,n,B(s));if(!o)return null;let i=C(o);if(e.has(i))return D(i);return null},load(r){if(r.startsWith(T)){let s=B(r),o=e.get(s);if(o)return $.add(s),o}return null}}};function ue(e){return e.tsconfig?.compilerOptions}function C(e){return e.replace(/\.tsx?$/,".d.ts")}function Y(e){let t=R.dirname(e.path||""),n=ue(e);return n?.baseUrl?R.resolve(t,n.baseUrl):t}function fe(e){let t=new Map,n=ue(e)?.paths;if(!n)return t;let r=Y(e);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");t.set(`^${i}$`,R.join(r,a))}return t}function We(e,t,n){for(let[r,s]of t){let o=new RegExp(r),i=e.match(o);if(i)return s.replace("$1",i[1]||"")}return n?R.join(n,e):null}async function je(e){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function M(e,t,n,r){let s=e.startsWith(".")?R.resolve(R.dirname(r||""),e):We(e,t,n);if(!s)return Promise.resolve(null);return je(s)}function X(e){return e.startsWith(T)}function B(e){return e.replace(T,"")}function D(e){return`${T}${e}`}var me;function pe(e){return{name:"bunup:types-resolve",buildStart(){me||=new He({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?B(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let s=r?Fe.dirname(r):process.cwd(),{path:o}=await me.async(s,t);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function de(e,t,n,r,s,o){let i=C(e),a=D(i),l=A(n,r),c=I(n);try{let{output:m}=await qe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;p(f)},plugins:[ce(t,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&pe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ve({dtsInput:!0})],external:(f)=>l.some((p)=>p.test(f))&&!c.some((p)=>p.test(f))});if(!m[0]?.code)throw new d("Generated bundle is empty");return m[0].code}catch(m){throw new d(`DTS bundling failed: ${h(m)}`)}}var ge=!1;function U(e){ge=e??!1}class O{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(!O.instance)O.instance=new O;return O.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...m]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${c}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${m.join(" ")}${p}`}let l=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${l}`}output(e,t={},n=console.log){if(ge)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let s=String(e),o=this.colors.default,i,a,l={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,l=n;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){o=f;break}let c=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:l.muted});this.output(c,l)}}var u=O.getInstance();var Ge=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Xe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ye=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ke=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qe=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ze=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Je(e){let t=new Set,n=[Ge,Xe,Ye,Ke,Qe,Ze,ze];for(let r of n){let s=e.matchAll(r);for(let o of s)if(o[1])t.add(o[1])}return t}async function he(e,t,n){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=Je(i);for(let l of a){let c=await M(l,t,n,o);if(!c)continue;if(!r.has(c))r.add(c),s.push(c)}}catch(i){u.warn(`Error processing ${o}: ${h(i)}`)}}return r}import{isolatedDeclaration as et}from"oxc-transform";async function xe(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=C(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=et(n,o);if(i)t.set(r,i)}catch(r){u.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import be from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as tt}from"oxc-transform";async function ye(e,t){let n=K.resolve(e),r=K.resolve(n,t);if(!await be.exists(n))throw new d(`Root directory does not exist: ${n}`);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(K.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function we(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:o}=tt(r,s);for(let i of o){if(!t)console.log(`
6
+ `);let a=i.labels[0],l=a?nt(s,a.start):"",m=`${b(r)}${l}: ${rt(i.message)}`;u.warn(m),t=!0}}catch{}})),t)u.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 st(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
9
- `),r=n.length,i=n[n.length-1].length+1;return` (${r}:${i})`}function it(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $e(e,t,n,r,i){let{absoluteEntry:o}=await we(e,t),s=pe(r),a=K(r),l=await xe(o,s,a),u=await be(l);return ge(o,u,n,i,s,a)}function P(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function L(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,i={};function o(s,a){if(r.has(s)){let l=ee(),u=`${s}_${l}`;if(t)c.warn(`Output name conflict: "${s}" is used by multiple files.
8
+ `)}function nt(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
9
+ `),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function rt(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Ee(e,t,n,r,s){let{absoluteEntry:o}=await ye(e,t),i=fe(r),a=Y(r),l=await he(o,i,a),c=await xe(l);return de(o,c,n,s,i,a)}function _(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function P(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let l=J(),c=`${i}_${l}`;if(t)u.warn(`Output name conflict: "${i}" is used by multiple files.
10
10
  Bunup uses filenames without extensions as output names by default.
11
11
 
12
- ${i[s]} -> ${s}.js
13
- ${a} -> ${u}.js (auto-renamed to avoid conflict)
12
+ ${s[i]} -> ${i}.js
13
+ ${a} -> ${c}.js (auto-renamed to avoid conflict)
14
14
 
15
15
  To fix this, use named entries in your configuration:
16
16
  {
17
17
  entry: {
18
- custom_name: "${i[s]}",
18
+ custom_name: "${s[i]}",
19
19
  another_name: "${a}"
20
20
  }
21
21
  }
22
22
 
23
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:s,path:a}),r.add(s),i[s]=a}if(Array.isArray(e))for(let s of e){let a=P(s);o(a,s)}else if(typeof e==="object")for(let[s,a]of Object.entries(e))o(s,a);else{let s=P(e);o(s,e)}return n}function Ce(e,t){return`[dir]/${e}${t}`}import{loadConfig as Re}from"coffi";async function Oe(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:te(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Be(e){let{config:t,filepath:n}=await Re({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function ve(e,t){let{config:n,filepath:r}=await Re({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var Te={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Pe(e,t){return{outdir:`${t}/${e.outDir}`,minify:ot(e),target:e.target,splitting:e.splitting,sourcemap:e.sourcemap,define:e.define,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer}}function ot(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:i??o}}function Le(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(e.some((s)=>s.test(i))&&!t.some((s)=>s.test(i)))return{path:i,external:!0};return null})}}}var R=new Set;async function W(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)ae(t,e.outDir);k(e.silent);let{packageJson:n,path:r}=await Be(t);if(n&&r)c.cli(`Using package.json: ${b(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let i=n?.type,o=D(e,n),s=U(e),a=[Le(o,s)],l=L(e.entry),u=Pe(e,t),p=e.format.flatMap((f)=>l.map((m)=>{return at(e,t,m,f,i,a,u)}));if(await Promise.all(p),e.dts){let f=await ve(t,e.preferredTsconfigPath);if(f.path)c.cli(`Using tsconfig: ${b(f.path,2)}`,{muted:!0,identifier:e.name,once:`${f.path}:${e.name}`});let m=e.format.filter((E)=>{if(E==="iife"&&!M(i)&&e.format.includes("cjs"))return!1;return!0}),H=typeof e.dts==="object"&&e.dts.entry?L(e.dts.entry):l;try{await Promise.all(H.map(async(E)=>{let Ue=await $e(t,E.path,e,f,n);await Promise.all(m.map(async(_e)=>{let Ne=se(_e,i),q=`${t}/${e.outDir}/${E.name}${Ne}`;await Bun.write(q,Ue);let ke=Bun.file(q).size||0;c.progress("DTS",b(q),X(ke),e.name)}))}))}catch(E){throw new d(h(E))}}}async function at(e,t,n,r,i,o,s){let a=re(r,i),l=await Bun.build({...s,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ce(n.name,a)},splitting:oe(e.splitting,r),bytecode:le(e.bytecode,r),plugins:o,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new y(f.message);if(f.level==="warning")c.warn(f.message);else if(f.level==="info")c.info(f.message)}let u=`${t}/${e.outDir}/${n.name}${a}`,p=Bun.file(u).size||0;c.progress(r.toUpperCase(),b(u),X(p),e.name)}var j="0.3.89";var Se="https://bun.sh/docs/installation",Ae="https://bunup.arshadyaseen.com/#cli-options";function x(e){return(t,n)=>{n[e]=t===!0?!0:t==="true"}}function w(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new g(`Option --${e} requires a string value`)}}function Me(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new g(`Option --${e} requires a string value`)}}function ct(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=_(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=_(e);o(i,e)}return n}function Ce(e,t){return`[dir]/${e}${t}`}import{loadConfig as $e}from"coffi";async function Re(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:ee(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Oe(e){let{config:t,filepath:n}=await $e({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Be(e,t){let{config:n,filepath:r}=await $e({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var Te={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Pe(e,t){return{outdir:`${t}/${e.outDir}`,minify:st(e),target:e.target,splitting:e.splitting,sourcemap:e.sourcemap,define:e.define,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer}}function st(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function ve(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var $=new Set;async function N(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)oe(t,e.outDir);U(e.silent);let{packageJson:n,path:r}=await Oe(t);if(n&&r)u.cli(`Using package.json: ${b(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let s=P(e.entry),o=n?.type,i=A(e,n),a=I(e);if(!e.dtsOnly){let l=[ve(i,a)],c=Pe(e,t),m=e.format.flatMap((f)=>s.map((p)=>{return it(e,t,p,f,o,l,c)}));await Promise.all(m)}if(e.dts||e.dtsOnly){let l=await Be(t,e.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${b(l.path,2)}`,{muted:!0,identifier:e.name,once:`${l.path}:${e.name}`});let c=e.format.filter((f)=>{if(f==="iife"&&!L(o)&&e.format.includes("cjs"))return!1;return!0}),m=typeof e.dts==="object"&&e.dts.entry?P(e.dts.entry):s;try{await Promise.all(m.map(async(f)=>{let p=await Ee(t,f.path,e,l,n);await Promise.all(c.map(async(F)=>{let Ue=re(F,o),H=`${t}/${e.outDir}/${f.name}${Ue}`;await Bun.write(H,p);let _e=Bun.file(H).size||0;u.progress("DTS",b(H),G(_e),e.name)}))}))}catch(f){throw new d(h(f))}}}async function it(e,t,n,r,s,o,i){let a=ne(r,s),l=await Bun.build({...i,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ce(n.name,a)},splitting:ie(e.splitting,r),bytecode:ae(e.bytecode,r),plugins:o,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${n.name}${a}`,m=Bun.file(c).size||0;u.progress(r.toUpperCase(),b(c),G(m),e.name)}var k="0.3.91";var Le="https://bun.sh/docs/installation",Se="https://bunup.arshadyaseen.com/#cli-options";function x(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new g(`Option --${e} requires a string value`)}}function Ae(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new g(`Option --${e} requires a string value`)}}function at(){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${Ae}\x1B[0m
26
- `),process.exit(0)}function ut(){console.log(j),process.exit(0)}var ft={name:{flags:["n","name"],handler:w("name")},format:{flags:["f","format"],handler:(e,t)=>{if(typeof e==="string")t.format=e.split(",");else throw new g("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:w("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:w("banner")},footer:{flags:["ft","footer"],handler:w("footer")},external:{flags:["e","external"],handler:Me("external")},sourcemap:{flags:["sm","sourcemap"],handler:w("sourcemap")},target:{flags:["t","target"],handler:w("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:Me("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},silent:{flags:["silent"],handler:x("silent")}},pt={resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}}},mt={help:{flags:["h","help"],handler:()=>ct()},version:{flags:["v","version"],handler:()=>ut()}},S={};for(let e of Object.values(ft))if(e)for(let t of e.flags)S[t]=e.handler;for(let e of Object.values(pt))for(let t of e.flags)S[t]=e.handler;for(let e of Object.values(mt))for(let t of e.flags)S[t]=e.handler;function Ie(e){let t={},n={},r=0;while(r<e.length){let i=e[r];if(i.startsWith("--")){let o,s;if(i.includes("=")){let[a,l]=i.slice(2).split("=",2);o=a,s=l}else{o=i.slice(2);let a=e[r+1];if(s=a&&!a.startsWith("-")?a:!0,typeof s==="string")r++}if(o==="entry")if(typeof s==="string"){let a=P(s);if(n[a])c.warn(`Duplicate entry name '${a}' derived from '${s}'. Overwriting previous entry.`);n[a]=s}else throw new g("Option --entry requires a string value");else if(o.startsWith("entry.")){let a=o.slice(6);if(typeof s==="string"){if(n[a])c.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=s}else throw new g(`Option --entry.${a} requires a string value`)}else{let a=S[o];if(a)a(s,t);else throw new g(`Unknown option: --${o}`)}}else if(i.startsWith("-")){let o=i.slice(1),s=e[r+1],a=s&&!s.startsWith("-")?s:!0;if(typeof a==="string")r++;let l=S[o];if(l)l(a,t);else throw new g(`Unknown option: -${o}`)}else{let o=P(i);if(n[o])c.warn(`Duplicate entry name '${o}' derived from positional argument '${i}'. Overwriting previous entry.`);n[o]=i}r++}if(Object.keys(n).length>0)t.entry=n;return t}(()=>{if(typeof Bun==="undefined")throw new g(`Bunup requires Bun to run.
27
- To install Bun, visit ${Se}`)})();import{loadConfig as gt}from"coffi";import F from"node:path";import dt from"chokidar";async function De(e,t){let n=new Set,r=L(e.entry);for(let a of r){let l=F.resolve(t,a.path),u=F.dirname(l);n.add(u)}let i=dt.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,F.join(t,e.outDir)]}),o=!1,s=async(a=!1)=>{if(o)return;o=!0;try{let l=performance.now();if(await W({...e,entry:r.map((u)=>u.path),clean:!1},t),e.onBuildSuccess?.(),!a)c.cli(`\uD83D\uDCE6 Rebuild finished in ${I(performance.now()-l)}`);await Z()}catch(l){V(l)}finally{o=!1}};i.on("change",(a)=>{let l=F.relative(t,a);c.cli(`File changed: ${l}`,{muted:!0}),s()}),i.on("error",(a)=>{throw new A(`Watcher error: ${h(a)}`)}),await s(!0)}async function ht(e=Bun.argv.slice(2)){let t=Ie(e);k(t.silent);let n=process.cwd(),{config:r,filepath:i}=await gt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1}),o=!r?[{rootDir:n,options:t}]:await Oe(r,n);if(c.cli(`Using bunup v${j} and bun v${Bun.version}`,{muted:!0}),i)c.cli(`Using config file: ${b(i,2)}`,{muted:!0});let s=performance.now();c.cli("Build started"),await Promise.all(o.flatMap(({options:u,rootDir:p})=>{return ne(u).map(async(m)=>{let H={...Te,...m,...t};return xt(H,p)})}));let a=performance.now()-s,l=I(a);if(c.cli(`\u26A1\uFE0F Build completed in ${l}`),await Z(),t.watch)c.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Z(){if(R.size>0)await Ee(R),R.clear()}async function xt(e,t){if(e.watch)await De(e,t);else await W(e,t),e.onBuildSuccess?.()}ht().catch((e)=>z(e));export{Z as validateDtsFiles,ht as main};
25
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Se}\x1B[0m
26
+ `),process.exit(0)}function lt(){console.log(k),process.exit(0)}var Ie={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(e,t)=>{if(typeof e==="string")t.format=e.split(",");else throw new g("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:Ae("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:Ae("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:y("config")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new g(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=_(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>at()},version:{flags:["v","version"],handler:()=>lt()}},W={};for(let e of Object.values(Ie))for(let t of e.flags)W[t]=e.handler;function Me(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),l=W[i];if(l)l(o,t,a);else throw new g(`Unknown option: --${s}`)}else{let i=W[s];if(i)i(o,t);else throw new g(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=W[s];if(a)a(i,t);else throw new g(`Unknown option: -${s}`)}else Ie.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new g(`Bunup requires Bun to run.
27
+ To install Bun, visit ${Le}`)})();import{loadConfig as ut}from"coffi";import j from"node:path";import ct from"chokidar";async function De(e,t){let n=new Set,r=P(e.entry);for(let a of r){let l=j.resolve(t,a.path),c=j.dirname(l);n.add(c)}let s=ct.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,j.join(t,e.outDir)]}),o=!1,i=async(a=!1)=>{if(o)return;o=!0;try{let l=performance.now();if(await N({...e,entry:r.map((c)=>c.path),clean:!1},t),e.onBuildSuccess?.(),!a)u.cli(`\uD83D\uDCE6 Rebuild finished in ${S(performance.now()-l)}`);await Q()}catch(l){q(l)}finally{o=!1}};s.on("change",(a)=>{let l=j.relative(t,a);u.cli(`File changed: ${l}`,{muted:!0}),i()}),s.on("error",(a)=>{throw new v(`Watcher error: ${h(a)}`)}),await i(!0)}async function ft(e=Bun.argv.slice(2)){let t=Me(e);U(t.silent);let n=process.cwd(),{config:r,filepath:s}=await ut({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Re(r,n);if(u.cli(`Using bunup v${k} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${b(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:c,rootDir:m})=>{return te(c).map(async(p)=>{let F={...Te,...p,...t};return mt(F,m)})}));let a=performance.now()-i,l=S(a);if(u.cli(`\u26A1\uFE0F Build completed in ${l}`),await Q(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Q(){if($.size>0)await we($),$.clear()}async function mt(e,t){if(e.watch)await De(e,t);else await N(e,t),e.onBuildSuccess?.()}ft().catch((e)=>Z(e));export{Q as validateDtsFiles,ft as main};
package/build/index.d.mts CHANGED
@@ -119,6 +119,21 @@ interface BuildOptions {
119
119
  */
120
120
  dts?: boolean | DtsOptions;
121
121
  /**
122
+ * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
123
+ * When set to true, bunup will skip the JavaScript bundling process entirely
124
+ * and only generate declaration files for the specified entry points
125
+ *
126
+ * This is useful when you want to use bunup's fast declaration file generation
127
+ * but handle the JavaScript bundling separately or not at all.
128
+ *
129
+ * Note: When this option is true, the `dts` option is implicitly set to true
130
+ * and other bundling-related options are ignored.
131
+ *
132
+ * @example
133
+ * dtsOnly: true
134
+ */
135
+ dtsOnly?: boolean;
136
+ /**
122
137
  * Path to a preferred tsconfig.json file to use for declaration generation
123
138
  *
124
139
  * If not specified, the tsconfig.json in the project root will be used.
@@ -119,6 +119,21 @@ interface BuildOptions {
119
119
  */
120
120
  dts?: boolean | DtsOptions;
121
121
  /**
122
+ * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
123
+ * When set to true, bunup will skip the JavaScript bundling process entirely
124
+ * and only generate declaration files for the specified entry points
125
+ *
126
+ * This is useful when you want to use bunup's fast declaration file generation
127
+ * but handle the JavaScript bundling separately or not at all.
128
+ *
129
+ * Note: When this option is true, the `dts` option is implicitly set to true
130
+ * and other bundling-related options are ignored.
131
+ *
132
+ * @example
133
+ * dtsOnly: true
134
+ */
135
+ dtsOnly?: boolean;
136
+ /**
122
137
  * Path to a preferred tsconfig.json file to use for declaration generation
123
138
  *
124
139
  * If not specified, the tsconfig.json in the project root will be used.
package/build/index.js ADDED
@@ -0,0 +1,15 @@
1
+ var Ot=require("node:module");var Bt=Object.create;var{getPrototypeOf:It,defineProperty:$,getOwnPropertyNames:j,getOwnPropertyDescriptor:Lt}=Object,G=Object.prototype.hasOwnProperty;var h=(t,e,n)=>{n=t!=null?Bt(It(t)):{};let r=e||!t||!t.__esModule?$(n,"default",{value:t,enumerable:!0}):n;for(let s of j(t))if(!G.call(r,s))$(r,s,{get:()=>t[s],enumerable:!0});return r},V=new WeakMap,St=(t)=>{var e=V.get(t),n;if(e)return e;if(e=$({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((r)=>!G.call(e,r)&&$(e,r,{get:()=>t[r],enumerable:!(n=Lt(t,r))||n.enumerable}));return V.set(t,e),e};var At=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Kt={};At(Kt,{defineWorkspace:()=>X,defineConfig:()=>q,build:()=>Pt});module.exports=St(Kt);function q(t){return t}function X(t){return t}var lt=require("rolldown"),ut=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class b 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 A=h(require("node:fs/promises")),H=h(require("node:path"));function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function K(t,e){switch(t){case"esm":return".mjs";case"cjs":return P(e)?".cjs":".js";case"iife":return".global.js"}}function Y(t,e){switch(t){case"esm":return".d.mts";case"cjs":return P(e)?".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 Z(t,e){return t===void 0?e==="esm":t}function _(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function E(t,e=3){return t.split("/").slice(-e).join("/")}async function z(t,e){let n=H.default.join(t,e);try{await A.default.rm(n,{recursive:!0,force:!0})}catch(r){throw new b(`Failed to clean output directory: ${r}`)}await A.default.mkdir(n,{recursive:!0})}function J(t,e){return e==="cjs"?t:void 0}function tt(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function D(t,e){return tt(t.external||[]).concat(Q(e).map((n)=>new RegExp(`^${O(n)}($|\\/|\\\\)`)))}function M(t){return tt(t.noExternal||[])}var ot=h(require("node:path")),at=require("oxc-resolver");var x=h(require("node:path"));var C="\x00dts:",et=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(N(r))return r;if(!s||!N(s))return null;let o=await T(r,e,n,y(s));if(!o)return null;let i=w(o);if(t.has(i))return B(i);return null},load(r){if(r.startsWith(C)){let s=y(r),o=t.get(s);if(o)return nt.add(s),o}return null}}};function rt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function W(t){let e=x.default.dirname(t.path||""),n=rt(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function st(t){let e=new Map,n=rt(t)?.paths;if(!n)return e;let r=W(t);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");e.set(`^${i}$`,x.default.join(r,a))}return e}function _t(t,e,n){for(let[r,s]of e){let o=new RegExp(r),i=t.match(o);if(i)return s.replace("$1",i[1]||"")}return n?x.default.join(n,t):null}async function Nt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function T(t,e,n,r){let s=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):_t(t,e,n);if(!s)return Promise.resolve(null);return Nt(s)}function N(t){return t.startsWith(C)}function y(t){return t.replace(C,"")}function B(t){return`${C}${t}`}var it;function ct(t){return{name:"bunup:types-resolve",buildStart(){it||=new at.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?y(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let s=r?ot.default.dirname(r):process.cwd(),{path:o}=await it.async(s,e);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function ft(t,e,n,r,s,o){let i=w(t),a=B(i),c=D(n,r),u=M(n);try{let{output:f}=await lt.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[et(e,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&ct(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ut.dts({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${p(f)}`)}}var gt=!1;function mt(t){gt=t??!1}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:e,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...f]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${a}${c}`}output(t,e={},n=console.log){if(gt)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let s=String(t),o=this.colors.default,i,a,c={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,c=n;for(let[f,l]of Object.entries(this.colors.progress))if(s.includes(f)){o=l;break}let u=this.formatMessage({colorCode:o,label:s,message:e,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var g=R.getInstance();var Wt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ut=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Vt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function qt(t){let e=new Set,n=[Wt,Ut,vt,Ft,Vt,jt,Gt];for(let r of n){let s=t.matchAll(r);for(let o of s)if(o[1])e.add(o[1])}return e}async function dt(t,e,n){let r=new Set([t]),s=[t];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=qt(i);for(let c of a){let u=await T(c,e,n,o);if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){g.warn(`Error processing ${o}: ${p(i)}`)}}return r}var pt=require("oxc-transform");async function xt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=w(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=pt.isolatedDeclaration(n,o);if(i)e.set(r,i)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}var U=h(require("node:fs/promises")),I=h(require("node:path")),Xt=require("oxc-transform");async function ht(t,e){let n=I.default.resolve(t),r=I.default.resolve(n,e);if(!await U.default.exists(n))throw new d(`Root directory does not exist: ${n}`);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(I.default.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function bt(t,e,n,r,s){let{absoluteEntry:o}=await ht(t,e),i=st(r),a=W(r),c=await dt(o,i,a),u=await xt(c);return ft(o,u,n,s,i,a)}function Et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=k(),u=`${i}_${c}`;if(e)g.warn(`Output name conflict: "${i}" is used by multiple files.
2
+ Bunup uses filenames without extensions as output names by default.
3
+
4
+ ${s[i]} -> ${i}.js
5
+ ${a} -> ${u}.js (auto-renamed to avoid conflict)
6
+
7
+ To fix this, use named entries in your configuration:
8
+ {
9
+ entry: {
10
+ custom_name: "${s[i]}",
11
+ another_name: "${a}"
12
+ }
13
+ }
14
+
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(t))for(let i of t){let a=Et(i);o(a,i)}else if(typeof t==="object")for(let[i,a]of Object.entries(t))o(i,a);else{let i=Et(t);o(i,t)}return n}function wt(t,e){return`[dir]/${t}${e}`}var F=require("coffi");async function Rt(t){let{config:e,filepath:n}=await F.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function $t(t,e){let{config:n,filepath:r}=await F.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function yt(t,e){return{outdir:`${e}/${t.outDir}`,minify:Ht(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 Ht(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Ct(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(t.some((i)=>i.test(s))&&!e.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var nt=new Set;async function Pt(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)z(e,t.outDir);mt(t.silent);let{packageJson:n,path:r}=await Rt(e);if(n&&r)g.cli(`Using package.json: ${E(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let s=v(t.entry),o=n?.type,i=D(t,n),a=M(t);if(!t.dtsOnly){let c=[Ct(i,a)],u=yt(t,e),f=t.format.flatMap((l)=>s.map((m)=>{return kt(t,e,m,l,o,c,u)}));await Promise.all(f)}if(t.dts||t.dtsOnly){let c=await $t(e,t.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,identifier:t.name,once:`${c.path}:${t.name}`});let u=t.format.filter((l)=>{if(l==="iife"&&!P(o)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?v(t.dts.entry):s;try{await Promise.all(f.map(async(l)=>{let m=await bt(e,l.path,t,c,n);await Promise.all(u.map(async(Dt)=>{let Mt=Y(Dt,o),L=`${e}/${t.outDir}/${l.name}${Mt}`;await Bun.write(L,m);let Tt=Bun.file(L).size||0;g.progress("DTS",E(L),_(Tt),t.name)}))}))}catch(l){throw new d(p(l))}}}async function kt(t,e,n,r,s,o,i){let a=K(r,s),c=await Bun.build({...i,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:wt(n.name,a)},splitting:Z(t.splitting,r),bytecode:J(t.bytecode,r),plugins:o,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new b(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(u).size||0;g.progress(r.toUpperCase(),E(u),_(f),t.name)}
package/build/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- function bt(t){return t}function Et(t){return t}import{build as Pt}from"rolldown";import{dts as Dt}from"rolldown-plugin-dts";class I extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends I{constructor(t){super(t);this.name="BunupBuildError"}}class p extends I{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import W from"node:fs/promises";import wt from"node:path";function L(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function v(t,e){switch(t){case"esm":return".mjs";case"cjs":return C(e)?".cjs":".js";case"iife":return".global.js"}}function F(t,e){switch(t){case"esm":return".d.mts";case"cjs":return C(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function V(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function j(t,e){return t===void 0?e==="esm":t}function S(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function b(t,e=3){return t.split("/").slice(-e).join("/")}async function G(t,e){let n=wt.join(t,e);try{await W.rm(n,{recursive:!0,force:!0})}catch(r){throw new h(`Failed to clean output directory: ${r}`)}await W.mkdir(n,{recursive:!0})}function q(t,e){return e==="cjs"?t:void 0}function X(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${L(e)}($|\\/|\\\\)`):e)}function P(t,e){return X(t.external||[]).concat(V(e).map((n)=>new RegExp(`^${L(n)}($|\\/|\\\\)`)))}function D(t){return X(t.noExternal||[])}import $t from"node:path";import{ResolverFactory as Ct}from"oxc-resolver";import w from"node:path";var $="\x00dts:",H=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(A(r))return r;if(!i||!A(i))return null;let o=await M(r,e,n,y(i));if(!o)return null;let s=E(o);if(t.has(s))return T(s);return null},load(r){if(r.startsWith($)){let i=y(r),o=t.get(i);if(o)return k.add(i),o}return null}}};function K(t){return t.tsconfig?.compilerOptions}function E(t){return t.replace(/\.tsx?$/,".d.ts")}function O(t){let e=w.dirname(t.path||""),n=K(t);return n?.baseUrl?w.resolve(e,n.baseUrl):e}function Y(t){let e=new Map,n=K(t)?.paths;if(!n)return e;let r=O(t);for(let[i,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let s=i.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");e.set(`^${s}$`,w.join(r,a))}return e}function Rt(t,e,n){for(let[r,i]of e){let o=new RegExp(r),s=t.match(o);if(s)return i.replace("$1",s[1]||"")}return n?w.join(n,t):null}async function yt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function M(t,e,n,r){let i=t.startsWith(".")?w.resolve(w.dirname(r||""),t):Rt(t,e,n);if(!i)return Promise.resolve(null);return yt(i)}function A(t){return t.startsWith($)}function y(t){return t.replace($,"")}function T(t){return`${$}${t}`}var Q;function Z(t){return{name:"bunup:types-resolve",buildStart(){Q||=new Ct({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?y(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let i=r?$t.dirname(r):process.cwd(),{path:o}=await Q.async(i,e);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 z(t,e,n,r,i,o){let s=E(t),a=T(s),c=P(n,r),u=D(n);try{let{output:g}=await Pt({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[H(e,i,o),typeof n.dts==="object"&&"resolve"in n.dts&&Z(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Dt({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${d(g)}`)}}var J=!1;function tt(t){J=t??!1}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:e,message:n,size:r,identifier:i,muted:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...g]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${m}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},n=console.log){if(J)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let i=String(t),o=this.colors.default,s,a,c={};if(typeof n==="string")s=n,a=r;else if(n)s=n.size,a=n.identifier,c=n;for(let[g,l]of Object.entries(this.colors.progress))if(i.includes(g)){o=l;break}let u=this.formatMessage({colorCode:o,label:i,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var f=R.getInstance();var Mt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Tt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Bt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,It=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Lt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,St=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,At=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Ot(t){let e=new Set,n=[Mt,Tt,Bt,It,Lt,St,At];for(let r of n){let i=t.matchAll(r);for(let o of i)if(o[1])e.add(o[1])}return e}async function et(t,e,n){let r=new Set([t]),i=[t];while(i.length){let o=i.pop();if(!o)continue;try{let s=await Bun.file(o).text(),a=Ot(s);for(let c of a){let u=await M(c,e,n,o);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(s){f.warn(`Error processing ${o}: ${d(s)}`)}}return r}import{isolatedDeclaration as _t}from"oxc-transform";async function nt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=E(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:s}=_t(n,o);if(s)e.set(r,s)}catch(r){f.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}import rt from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as Ce}from"oxc-transform";async function st(t,e){let n=_.resolve(t),r=_.resolve(n,e);if(!await rt.exists(n))throw new p(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new p(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${r}`);if(_.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function it(t,e,n,r,i){let{absoluteEntry:o}=await st(t,e),s=Y(r),a=O(r),c=await et(o,s,a),u=await nt(c);return z(o,u,n,i,s,a)}function ot(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,i={};function o(s,a){if(r.has(s)){let c=U(),u=`${s}_${c}`;if(e)f.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function pt(t){return t}function xt(t){return t}import{build as $t}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class B extends Error{constructor(t){super(t);this.name="BunupError"}}class x extends B{constructor(t){super(t);this.name="BunupBuildError"}}class d extends B{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import N from"node:fs/promises";import ht from"node:path";function I(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function U(t,e){switch(t){case"esm":return".mjs";case"cjs":return y(e)?".cjs":".js";case"iife":return".global.js"}}function v(t,e){switch(t){case"esm":return".d.mts";case"cjs":return y(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function y(t){return t==="module"}function F(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,e){return t===void 0?e==="esm":t}function L(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function h(t,e=3){return t.split("/").slice(-e).join("/")}async function j(t,e){let n=ht.join(t,e);try{await N.rm(n,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await N.mkdir(n,{recursive:!0})}function G(t,e){return e==="cjs"?t:void 0}function q(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${I(e)}($|\\/|\\\\)`):e)}function C(t,e){return q(t.external||[]).concat(F(e).map((n)=>new RegExp(`^${I(n)}($|\\/|\\\\)`)))}function P(t){return q(t.noExternal||[])}import wt from"node:path";import{ResolverFactory as Rt}from"oxc-resolver";import E from"node:path";var $="\x00dts:",X=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,o){if(S(r))return r;if(!o||!S(o))return null;let i=await D(r,e,n,R(o));if(!i)return null;let s=b(i);if(t.has(s))return M(s);return null},load(r){if(r.startsWith($)){let o=R(r),i=t.get(o);if(i)return H.add(o),i}return null}}};function k(t){return t.tsconfig?.compilerOptions}function b(t){return t.replace(/\.tsx?$/,".d.ts")}function A(t){let e=E.dirname(t.path||""),n=k(t);return n?.baseUrl?E.resolve(e,n.baseUrl):e}function K(t){let e=new Map,n=k(t)?.paths;if(!n)return e;let r=A(t);for(let[o,i]of Object.entries(n))if(Array.isArray(i)&&i.length){let s=o.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");e.set(`^${s}$`,E.join(r,a))}return e}function bt(t,e,n){for(let[r,o]of e){let i=new RegExp(r),s=t.match(i);if(s)return o.replace("$1",s[1]||"")}return n?E.join(n,t):null}async function Et(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function D(t,e,n,r){let o=t.startsWith(".")?E.resolve(E.dirname(r||""),t):bt(t,e,n);if(!o)return Promise.resolve(null);return Et(o)}function S(t){return t.startsWith($)}function R(t){return t.replace($,"")}function M(t){return`${$}${t}`}var Y;function Q(t){return{name:"bunup:types-resolve",buildStart(){Y||=new Rt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?R(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let o=r?wt.dirname(r):process.cwd(),{path:i}=await Y.async(o,e);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 Z(t,e,n,r,o,i){let s=b(t),a=M(s),c=C(n,r),u=P(n);try{let{output:f}=await $t({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[X(e,o,i),typeof n.dts==="object"&&"resolve"in n.dts&&Q(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),yt({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${p(f)}`)}}var z=!1;function J(t){z=t??!1}class w{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(!w.instance)w.instance=new w;return w.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:e,message:n,size:r,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=i?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...f]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},n=console.log){if(z)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let o=String(t),i=this.colors.default,s,a,c={};if(typeof n==="string")s=n,a=r;else if(n)s=n.size,a=n.identifier,c=n;for(let[f,l]of Object.entries(this.colors.progress))if(o.includes(f)){i=l;break}let u=this.formatMessage({colorCode:i,label:o,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var g=w.getInstance();var Ct=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Pt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Dt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Tt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,It=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Lt(t){let e=new Set,n=[Ct,Pt,Dt,Mt,Tt,Bt,It];for(let r of n){let o=t.matchAll(r);for(let i of o)if(i[1])e.add(i[1])}return e}async function tt(t,e,n){let r=new Set([t]),o=[t];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=Lt(s);for(let c of a){let u=await D(c,e,n,i);if(!u)continue;if(!r.has(u))r.add(u),o.push(u)}}catch(s){g.warn(`Error processing ${i}: ${p(s)}`)}}return r}import{isolatedDeclaration as St}from"oxc-transform";async function et(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=b(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:s}=St(n,i);if(s)e.set(r,s)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}import nt from"node:fs/promises";import O from"node:path";import{isolatedDeclaration as Re}from"oxc-transform";async function rt(t,e){let n=O.resolve(t),r=O.resolve(n,e);if(!await nt.exists(n))throw new d(`Root directory does not exist: ${n}`);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(O.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function st(t,e,n,r,o){let{absoluteEntry:i}=await rt(t,e),s=K(r),a=A(r),c=await tt(i,s,a),u=await et(c);return Z(i,u,n,o,s,a)}function it(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function _(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,o={};function i(s,a){if(r.has(s)){let c=W(),u=`${s}_${c}`;if(e)g.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
- ${i[s]} -> ${s}.js
4
+ ${o[s]} -> ${s}.js
5
5
  ${a} -> ${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
- custom_name: "${i[s]}",
10
+ custom_name: "${o[s]}",
11
11
  another_name: "${a}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:s,path:a}),r.add(s),i[s]=a}if(Array.isArray(t))for(let s of t){let a=ot(s);o(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))o(s,a);else{let s=ot(t);o(s,t)}return n}function at(t,e){return`[dir]/${t}${e}`}import{loadConfig as ct}from"coffi";async function lt(t){let{config:e,filepath:n}=await ct({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function ut(t,e){let{config:n,filepath:r}=await ct({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function ft(t,e){return{outdir:`${e}/${t.outDir}`,minify:Nt(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 Nt(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:i??o}}function gt(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(t.some((s)=>s.test(i))&&!e.some((s)=>s.test(i)))return{path:i,external:!0};return null})}}}var k=new Set;async function Wt(t,e){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.");if(t.clean)G(e,t.outDir);tt(t.silent);let{packageJson:n,path:r}=await lt(e);if(n&&r)f.cli(`Using package.json: ${b(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let i=n?.type,o=P(t,n),s=D(t),a=[gt(o,s)],c=N(t.entry),u=ft(t,e),g=t.format.flatMap((l)=>c.map((m)=>{return Ut(t,e,m,l,i,a,u)}));if(await Promise.all(g),t.dts){let l=await ut(e,t.preferredTsconfigPath);if(l.path)f.cli(`Using tsconfig: ${b(l.path,2)}`,{muted:!0,identifier:t.name,once:`${l.path}:${t.name}`});let m=t.format.filter((x)=>{if(x==="iife"&&!C(i)&&t.format.includes("cjs"))return!1;return!0}),mt=typeof t.dts==="object"&&t.dts.entry?N(t.dts.entry):c;try{await Promise.all(mt.map(async(x)=>{let pt=await it(e,x.path,t,l,n);await Promise.all(m.map(async(dt)=>{let xt=F(dt,i),B=`${e}/${t.outDir}/${x.name}${xt}`;await Bun.write(B,pt);let ht=Bun.file(B).size||0;f.progress("DTS",b(B),S(ht),t.name)}))}))}catch(x){throw new p(d(x))}}}async function Ut(t,e,n,r,i,o,s){let a=v(r,i),c=await Bun.build({...s,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:at(n.name,a)},splitting:j(t.splitting,r),bytecode:q(t.bytecode,r),plugins:o,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new h(l.message);if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,g=Bun.file(u).size||0;f.progress(r.toUpperCase(),b(u),S(g),t.name)}export{Et as defineWorkspace,bt as defineConfig,Wt as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:s,path:a}),r.add(s),o[s]=a}if(Array.isArray(t))for(let s of t){let a=it(s);i(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))i(s,a);else{let s=it(t);i(s,t)}return n}function ot(t,e){return`[dir]/${t}${e}`}import{loadConfig as at}from"coffi";async function ct(t){let{config:e,filepath:n}=await at({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function lt(t,e){let{config:n,filepath:r}=await at({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function ut(t,e){return{outdir:`${e}/${t.outDir}`,minify:At(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 At(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:o}=t,i=e===!0;return{whitespace:n??i,identifiers:r??i,syntax:o??i}}function ft(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let o=r.path;if(t.some((s)=>s.test(o))&&!e.some((s)=>s.test(o)))return{path:o,external:!0};return null})}}}var H=new Set;async function Ot(t,e){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.");if(t.clean)j(e,t.outDir);J(t.silent);let{packageJson:n,path:r}=await ct(e);if(n&&r)g.cli(`Using package.json: ${h(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let o=_(t.entry),i=n?.type,s=C(t,n),a=P(t);if(!t.dtsOnly){let c=[ft(s,a)],u=ut(t,e),f=t.format.flatMap((l)=>o.map((m)=>{return _t(t,e,m,l,i,c,u)}));await Promise.all(f)}if(t.dts||t.dtsOnly){let c=await lt(e,t.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${h(c.path,2)}`,{muted:!0,identifier:t.name,once:`${c.path}:${t.name}`});let u=t.format.filter((l)=>{if(l==="iife"&&!y(i)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?_(t.dts.entry):o;try{await Promise.all(f.map(async(l)=>{let m=await st(e,l.path,t,c,n);await Promise.all(u.map(async(gt)=>{let mt=v(gt,i),T=`${e}/${t.outDir}/${l.name}${mt}`;await Bun.write(T,m);let dt=Bun.file(T).size||0;g.progress("DTS",h(T),L(dt),t.name)}))}))}catch(l){throw new d(p(l))}}}async function _t(t,e,n,r,o,i,s){let a=U(r,o),c=await Bun.build({...s,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:ot(n.name,a)},splitting:V(t.splitting,r),bytecode:G(t.bytecode,r),plugins:i,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new x(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(u).size||0;g.progress(r.toUpperCase(),h(u),L(f),t.name)}export{xt as defineWorkspace,pt as defineConfig,Ot as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.89",
3
+ "version": "0.3.91",
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",
@@ -17,10 +17,10 @@
17
17
  "@commitlint/config-conventional": "^19.5.0",
18
18
  "@types/bun": "^1.2.5",
19
19
  "bumpp": "^10.1.0",
20
- "bunup": "^0.3.88",
20
+ "bunup": "^0.3.90",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "create-bunup": "0.3.89"
23
+ "create-bunup": "0.3.91"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": ">=4.5.0"
@@ -57,7 +57,6 @@
57
57
  "rolldown": "1.0.0-beta.7",
58
58
  "rolldown-plugin-dts": "^0.4.0"
59
59
  },
60
- "type": "module",
61
60
  "scripts": {
62
61
  "build": "bunup",
63
62
  "dev": "bunup --watch",
package/build/index.cjs DELETED
@@ -1,15 +0,0 @@
1
- var Wt=require("node:module");var St=Object.create;var{getPrototypeOf:At,defineProperty:$,getOwnPropertyNames:G,getOwnPropertyDescriptor:Ot}=Object,q=Object.prototype.hasOwnProperty;var b=(t,e,n)=>{n=t!=null?St(At(t)):{};let r=e||!t||!t.__esModule?$(n,"default",{value:t,enumerable:!0}):n;for(let s of G(t))if(!q.call(r,s))$(r,s,{get:()=>t[s],enumerable:!0});return r},j=new WeakMap,_t=(t)=>{var e=j.get(t),n;if(e)return e;if(e=$({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")G(t).map((r)=>!q.call(e,r)&&$(e,r,{get:()=>t[r],enumerable:!(n=Ot(t,r))||n.enumerable}));return j.set(t,e),e};var Nt=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Zt={};Nt(Zt,{defineWorkspace:()=>H,defineConfig:()=>X,build:()=>Dt});module.exports=_t(Zt);function X(t){return t}function H(t){return t}var ut=require("rolldown"),ft=require("rolldown-plugin-dts");class A extends Error{constructor(t){super(t);this.name="BunupError"}}class E extends A{constructor(t){super(t);this.name="BunupBuildError"}}class p extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};var O=b(require("node:fs/promises")),k=b(require("node:path"));function _(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function K(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function Y(t,e){switch(t){case"esm":return".mjs";case"cjs":return D(e)?".cjs":".js";case"iife":return".global.js"}}function Q(t,e){switch(t){case"esm":return".d.mts";case"cjs":return D(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(t){return t==="module"}function Z(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function z(t,e){return t===void 0?e==="esm":t}function N(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function w(t,e=3){return t.split("/").slice(-e).join("/")}async function J(t,e){let n=k.default.join(t,e);try{await O.default.rm(n,{recursive:!0,force:!0})}catch(r){throw new E(`Failed to clean output directory: ${r}`)}await O.default.mkdir(n,{recursive:!0})}function tt(t,e){return e==="cjs"?t:void 0}function et(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${_(e)}($|\\/|\\\\)`):e)}function M(t,e){return et(t.external||[]).concat(Z(e).map((n)=>new RegExp(`^${_(n)}($|\\/|\\\\)`)))}function T(t){return et(t.noExternal||[])}var at=b(require("node:path")),ct=require("oxc-resolver");var x=b(require("node:path"));var P="\x00dts:",nt=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(W(r))return r;if(!s||!W(s))return null;let o=await B(r,e,n,C(s));if(!o)return null;let i=R(o);if(t.has(i))return I(i);return null},load(r){if(r.startsWith(P)){let s=C(r),o=t.get(s);if(o)return rt.add(s),o}return null}}};function st(t){return t.tsconfig?.compilerOptions}function R(t){return t.replace(/\.tsx?$/,".d.ts")}function U(t){let e=x.default.dirname(t.path||""),n=st(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function it(t){let e=new Map,n=st(t)?.paths;if(!n)return e;let r=U(t);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");e.set(`^${i}$`,x.default.join(r,a))}return e}function Ut(t,e,n){for(let[r,s]of e){let o=new RegExp(r),i=t.match(o);if(i)return s.replace("$1",i[1]||"")}return n?x.default.join(n,t):null}async function vt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function B(t,e,n,r){let s=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):Ut(t,e,n);if(!s)return Promise.resolve(null);return vt(s)}function W(t){return t.startsWith(P)}function C(t){return t.replace(P,"")}function I(t){return`${P}${t}`}var ot;function lt(t){return{name:"bunup:types-resolve",buildStart(){ot||=new ct.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?C(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let s=r?at.default.dirname(r):process.cwd(),{path:o}=await ot.async(s,e);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function gt(t,e,n,r,s,o){let i=R(t),a=I(i),c=M(n,r),u=T(n);try{let{output:g}=await ut.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[nt(e,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&lt(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ft.dts({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${d(g)}`)}}var mt=!1;function pt(t){mt=t??!1}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:e,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...g]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${m}`}let c=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${a}${c}`}output(t,e={},n=console.log){if(mt)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let s=String(t),o=this.colors.default,i,a,c={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,c=n;for(let[g,l]of Object.entries(this.colors.progress))if(s.includes(g)){o=l;break}let u=this.formatMessage({colorCode:o,label:s,message:e,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var f=y.getInstance();var Ft=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,jt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Gt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Xt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ht=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function kt(t){let e=new Set,n=[Ft,Vt,jt,Gt,qt,Xt,Ht];for(let r of n){let s=t.matchAll(r);for(let o of s)if(o[1])e.add(o[1])}return e}async function dt(t,e,n){let r=new Set([t]),s=[t];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=kt(i);for(let c of a){let u=await B(c,e,n,o);if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){f.warn(`Error processing ${o}: ${d(i)}`)}}return r}var xt=require("oxc-transform");async function ht(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=R(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=xt.isolatedDeclaration(n,o);if(i)e.set(r,i)}catch(r){f.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}var v=b(require("node:fs/promises")),L=b(require("node:path")),Kt=require("oxc-transform");async function bt(t,e){let n=L.default.resolve(t),r=L.default.resolve(n,e);if(!await v.default.exists(n))throw new p(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new p(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${r}`);if(L.default.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Et(t,e,n,r,s){let{absoluteEntry:o}=await bt(t,e),i=it(r),a=U(r),c=await dt(o,i,a),u=await ht(c);return gt(o,u,n,s,i,a)}function wt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function F(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=K(),u=`${i}_${c}`;if(e)f.warn(`Output name conflict: "${i}" is used by multiple files.
2
- Bunup uses filenames without extensions as output names by default.
3
-
4
- ${s[i]} -> ${i}.js
5
- ${a} -> ${u}.js (auto-renamed to avoid conflict)
6
-
7
- To fix this, use named entries in your configuration:
8
- {
9
- entry: {
10
- custom_name: "${s[i]}",
11
- another_name: "${a}"
12
- }
13
- }
14
-
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(t))for(let i of t){let a=wt(i);o(a,i)}else if(typeof t==="object")for(let[i,a]of Object.entries(t))o(i,a);else{let i=wt(t);o(i,t)}return n}function Rt(t,e){return`[dir]/${t}${e}`}var V=require("coffi");async function yt(t){let{config:e,filepath:n}=await V.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function $t(t,e){let{config:n,filepath:r}=await V.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function Ct(t,e){return{outdir:`${e}/${t.outDir}`,minify:Yt(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 Yt(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Pt(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(t.some((i)=>i.test(s))&&!e.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var rt=new Set;async function Dt(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)J(e,t.outDir);pt(t.silent);let{packageJson:n,path:r}=await yt(e);if(n&&r)f.cli(`Using package.json: ${w(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let s=n?.type,o=M(t,n),i=T(t),a=[Pt(o,i)],c=F(t.entry),u=Ct(t,e),g=t.format.flatMap((l)=>c.map((m)=>{return Qt(t,e,m,l,s,a,u)}));if(await Promise.all(g),t.dts){let l=await $t(e,t.preferredTsconfigPath);if(l.path)f.cli(`Using tsconfig: ${w(l.path,2)}`,{muted:!0,identifier:t.name,once:`${l.path}:${t.name}`});let m=t.format.filter((h)=>{if(h==="iife"&&!D(s)&&t.format.includes("cjs"))return!1;return!0}),Mt=typeof t.dts==="object"&&t.dts.entry?F(t.dts.entry):c;try{await Promise.all(Mt.map(async(h)=>{let Tt=await Et(e,h.path,t,l,n);await Promise.all(m.map(async(Bt)=>{let It=Q(Bt,s),S=`${e}/${t.outDir}/${h.name}${It}`;await Bun.write(S,Tt);let Lt=Bun.file(S).size||0;f.progress("DTS",w(S),N(Lt),t.name)}))}))}catch(h){throw new p(d(h))}}}async function Qt(t,e,n,r,s,o,i){let a=Y(r,s),c=await Bun.build({...i,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:Rt(n.name,a)},splitting:z(t.splitting,r),bytecode:tt(t.bytecode,r),plugins:o,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new E(l.message);if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,g=Bun.file(u).size||0;f.progress(r.toUpperCase(),w(u),N(g),t.name)}