bunup 0.3.80 → 0.3.81

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{createRequire as ot}from"node:module";var tt=Object.create;var{getPrototypeOf:nt,defineProperty:ie,getOwnPropertyNames:rt}=Object;var st=Object.prototype.hasOwnProperty;var oe=(e,t,n)=>{n=e!=null?tt(nt(e)):{};let r=t||!e||!e.__esModule?ie(n,"default",{value:e,enumerable:!0}):n;for(let i of rt(e))if(!st.call(r,i))ie(r,i,{get:()=>e[i],enumerable:!0});return r};var it=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var G=ot(import.meta.url);var ne=it((Kn,ke)=>{var Yn=G("node:module"),{defineProperty:ee,getOwnPropertyNames:Pt,getOwnPropertyDescriptor:Tt}=Object,St=Object.prototype.hasOwnProperty,Ie=new WeakMap,Lt=(e)=>{var t=Ie.get(e),n;if(t)return t;if(t=ee({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Pt(e).map((r)=>!St.call(t,r)&&ee(t,r,{get:()=>e[r],enumerable:!(n=Tt(e,r))||n.enumerable}));return Ie.set(e,t),t},At=(e,t)=>{for(var n in t)ee(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(r)=>t[n]=()=>r})},je={};At(je,{loadConfig:()=>Mt});ke.exports=Lt(je);var te=G("node:fs"),Me=G("node:path"),Ne=[".ts",".mts",".cts",".js",".mjs",".cjs",".json"];class P{static instance;constructor(){}static getInstance(){if(!P.instance)P.instance=new P;return P.instance}warn(e){console.log(`\x1B[33mWARNING: ${e}\x1B[0m`)}}var Dt=P.getInstance();function It(e){try{return te.existsSync(e)}catch{return!1}}async function Ue(e){try{if(!It(e))return null;if(e.slice(e.lastIndexOf(".")).toLowerCase()===".json"){let r=te.readFileSync(e,"utf-8");return JSON.parse(r)}let t=await import(e),n=t.default||t;if(typeof n==="function")n=n();if(n instanceof Promise)return n;return n}catch(t){return null}}async function _e(e,t,n,r,i){if(i){let a=await Ue(i);if(a!==null)return{config:a,filepath:i};Dt.warn(`Preferred path "${i}" not found or invalid, searching for ${e} files instead.`)}let s=n,o=0;while(o<r){try{let l=te.readdirSync(s),c=new Set(l);for(let p of t){let u=`${e}${p}`;if(c.has(u)){let m=Me.join(s,u),E=await Ue(m);if(E!==null)return{config:E,filepath:m}}}}catch(l){}let a=Me.dirname(s);if(a===s)break;s=a,o++}return{config:null,filepath:null}}async function Mt(e,t=Ne,n={}){if(typeof e==="string"){let l=e,{cwd:c=process.cwd(),maxDepth:p=10,preferredPath:u}=n;return _e(l,t,c,p,u)}let{name:r,extensions:i=Ne,cwd:s=process.cwd(),maxDepth:o=10,preferredPath:a}=e;return _e(r,i,s,o,a)}});import{build as gt}from"rolldown";import{dts as dt}from"rolldown-plugin-dts";class C extends Error{constructor(e){super(e);this.name="BunupError"}}class b extends C{constructor(e){super(e);this.name="BunupBuildError"}}class g extends C{constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends C{constructor(e){super(e);this.name="BunupCLIError"}}class M extends C{constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},at=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],X=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",i="ERROR";if(e instanceof b)i="BUILD ERROR";else if(e instanceof g)i="DTS ERROR";else if(e instanceof d)i="CLI ERROR";else if(e instanceof M)i="WATCH ERROR";else if(e instanceof C)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${n}`);let s=at.find((o)=>o.pattern.test(n)&&(o.errorType===i||!o.errorType));if(s)console.error(`
3
+ import{build as Xe}from"rolldown";import{dts as Ye}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 g extends ${constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends ${constructor(e){super(e);this.name="BunupCLIError"}}class D 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 g)i="DTS ERROR";else if(e instanceof d)i="CLI ERROR";else if(e instanceof D)i="WATCH ERROR";else if(e instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${n}`);let s=We.find((o)=>o.pattern.test(n)&&(o.errorType===i||!o.errorType));if(s)console.error(`
4
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")},ae=(e,t)=>{X(e,t),process.exit(1)};import ce from"node:fs/promises";import ct from"node:path";var T={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function le(e,t){return{outdir:`${t}/${e.outDir}`,minify:lt(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 lt(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,s=t===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function Y(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ue(e=8){return Math.random().toString(36).substring(2,2+e)}function fe(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function K(e){return Array.isArray(e)?e:[e]}function pe(e,t){switch(e){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function me(e,t){switch(e){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(e){return e==="module"}function U(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function ge(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function de(e,t){return e===void 0?t==="esm":e}function Q(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 x(e,t=3){return e.split("/").slice(-t).join("/")}async function he(e,t){let n=ct.join(e,t);try{await ce.rm(n,{recursive:!0,force:!0})}catch(r){throw new b(`Failed to clean output directory: ${r}`)}await ce.mkdir(n,{recursive:!0})}function xe(e){return e||T.outDir}function ye(e){return e===void 0?T.clean:e}function be(e,t){return t==="cjs"?e:void 0}function we(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${Y(t)}($|\\/|\\\\)`):t)}function _(e,t){return we(e.external||[]).concat(ge(t).map((n)=>new RegExp(`^${Y(n)}($|\\/|\\\\)`)))}function j(e){return we(e.noExternal||[])}import pt from"node:path";import{ResolverFactory as mt}from"oxc-resolver";import v from"node:path";var L="\x00dts:",Ee=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(Z(r))return r;if(!i||!Z(i))return null;let s=await k(r,t,n,S(i));if(!s)return null;let o=R(s);if(e.has(o))return W(o);return null},load(r){if(r.startsWith(L)){let i=S(r),s=e.get(i);if(s)return O.add(i),s}return null}}};function $e(e){return e.tsconfig?.compilerOptions}function R(e){return e.replace(/\.tsx?$/,".d.ts")}function z(e){let t=v.dirname(e.path||""),n=$e(e);return n?.baseUrl?v.resolve(t,n.baseUrl):t}function Ce(e){let t=new Map,n=$e(e)?.paths;if(!n)return t;let r=z(e);for(let[i,s]of Object.entries(n))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,v.join(r,a))}return t}function ut(e,t,n){for(let[r,i]of t){let s=new RegExp(r),o=e.match(s);if(o)return i.replace("$1",o[1]||"")}return n?v.join(n,e):null}async function ft(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 k(e,t,n,r){let i=e.startsWith(".")?v.resolve(v.dirname(r||""),e):ut(e,t,n);if(!i)return Promise.resolve(null);return ft(i)}function Z(e){return e.startsWith(L)}function S(e){return e.replace(L,"")}function W(e){return`${L}${e}`}var Re;function Oe(e){return{name:"bunup:types-resolve",buildStart(){Re||=new mt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?S(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?pt.dirname(r):process.cwd(),{path:s}=await Re.async(i,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function ve(e,t,n,r,i,s){let o=R(e),a=W(o),l=_(n,r),c=j(n);try{let{output:p}=await gt({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[Ee(t,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&Oe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),dt()],external:(u)=>l.some((m)=>m.test(u))&&!c.some((m)=>m.test(u))});if(!p[0]?.code)throw new g("Generated bundle is empty");return p[0].code}catch(p){throw new g(`DTS bundling failed: ${h(p)}`)}}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:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...p]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),m=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${c}${u} \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 ${o}${a}${l}`}output(e,t={},n=console.log){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),s=this.colors.default,o,a,l={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,l=n;for(let[p,u]of Object.entries(this.colors.progress))if(i.includes(p)){s=u;break}let c=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:l.muted});this.output(c,l)}}var f=B.getInstance();var ht=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,xt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,yt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,bt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,wt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,$t=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Ct(e){let t=new Set,n=[ht,xt,yt,bt,wt,Et,$t];for(let r of n){let i=e.matchAll(r);for(let s of i)if(s[1])t.add(s[1])}return t}async function Be(e,t,n){let r=new Set([e]),i=[e];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Ct(o);for(let l of a){let c=await k(l,t,n,s);if(!c)continue;if(!r.has(c))r.add(c),i.push(c)}}catch(o){f.warn(`Error processing ${s}: ${h(o)}`)}}return r}import{isolatedDeclaration as Rt}from"oxc-transform";async function Pe(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=R(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=Rt(n,s);if(o)t.set(r,o)}catch(r){f.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import Te from"node:fs/promises";import J from"node:path";import{isolatedDeclaration as Ot}from"oxc-transform";async function Se(e,t){let n=J.resolve(e),r=J.resolve(n,t);if(!await Te.exists(n))throw new g(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${r}`);if(J.relative(n,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Le(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:s}=Ot(r,i);for(let o of s){if(!t)console.log(`
6
- `);let a=o.labels[0],l=a?vt(i,a.start):"",p=`${x(r)}${l}: ${Bt(o.message)}`;f.warn(p),t=!0}}catch{}})),t)f.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")},J=(e,t)=>{V(e,t),process.exit(1)};import te from"node:fs/promises";import He from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function ee(e,t){return{outdir:`${t}/${e.outDir}`,minify:je(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 je(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,s=t===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function G(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e=8){return Math.random().toString(36).substring(2,2+e)}function re(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function X(e){return Array.isArray(e)?e:[e]}function se(e,t){switch(e){case"esm":return".mjs";case"cjs":return M(t)?".cjs":".js";case"iife":return".global.js"}}function ie(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 oe(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ae(e,t){return e===void 0?t==="esm":e}function Y(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 x(e,t=3){return e.split("/").slice(-t).join("/")}async function le(e,t){let n=He.join(e,t);try{await te.rm(n,{recursive:!0,force:!0})}catch(r){throw new y(`Failed to clean output directory: ${r}`)}await te.mkdir(n,{recursive:!0})}function ce(e){return e||v.outDir}function ue(e){return e===void 0?v.clean:e}function fe(e,t){return t==="cjs"?e:void 0}function pe(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function U(e,t){return pe(e.external||[]).concat(oe(t).map((n)=>new RegExp(`^${G(n)}($|\\/|\\\\)`)))}function _(e){return pe(e.noExternal||[])}import Ve from"node:path";import{ResolverFactory as Ge}from"oxc-resolver";import O from"node:path";var T="\x00dts:",me=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(K(r))return r;if(!i||!K(i))return null;let s=await N(r,t,n,P(i));if(!s)return null;let o=R(s);if(e.has(o))return k(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=e.get(i);if(s)return C.add(i),s}return null}}};function ge(e){return e.tsconfig?.compilerOptions}function R(e){return e.replace(/\.tsx?$/,".d.ts")}function Q(e){let t=O.dirname(e.path||""),n=ge(e);return n?.baseUrl?O.resolve(t,n.baseUrl):t}function de(e){let t=new Map,n=ge(e)?.paths;if(!n)return t;let r=Q(e);for(let[i,s]of Object.entries(n))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,O.join(r,a))}return t}function Fe(e,t,n){for(let[r,i]of t){let s=new RegExp(r),o=e.match(s);if(o)return i.replace("$1",o[1]||"")}return n?O.join(n,e):null}async function qe(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 N(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 qe(i)}function K(e){return e.startsWith(T)}function P(e){return e.replace(T,"")}function k(e){return`${T}${e}`}var he;function xe(e){return{name:"bunup:types-resolve",buildStart(){he||=new Ge({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?P(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?Ve.dirname(r):process.cwd(),{path:s}=await he.async(i,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function be(e,t,n,r,i,s){let o=R(e),a=k(o),l=U(n,r),u=_(n);try{let{output:p}=await Xe({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:[me(t,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&xe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ye()],external:(f)=>l.some((m)=>m.test(f))&&!u.some((m)=>m.test(f))});if(!p[0]?.code)throw new g("Generated bundle is empty");return p[0].code}catch(p){throw new g(`DTS bundling failed: ${h(p)}`)}}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:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\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 ${o}${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 ${o}${a}${l}`}output(e,t={},n=console.log){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),s=this.colors.default,o,a,l={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,l=n;for(let[p,f]of Object.entries(this.colors.progress))if(i.includes(p)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:l.muted});this.output(u,l)}}var c=B.getInstance();var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Qe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ze=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function nt(e){let t=new Set,n=[Ke,Qe,Ze,ze,Je,et,tt];for(let r of n){let i=e.matchAll(r);for(let s of i)if(s[1])t.add(s[1])}return t}async function ye(e,t,n){let r=new Set([e]),i=[e];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=nt(o);for(let l of a){let u=await N(l,t,n,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){c.warn(`Error processing ${s}: ${h(o)}`)}}return r}import{isolatedDeclaration as rt}from"oxc-transform";async function we(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=R(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=rt(n,s);if(o)t.set(r,o)}catch(r){c.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import Ee from"node:fs/promises";import Z from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function $e(e,t){let n=Z.resolve(e),r=Z.resolve(n,t);if(!await Ee.exists(n))throw new g(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${r}`);if(Z.relative(n,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Re(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:s}=st(r,i);for(let o of s){if(!t)console.log(`
6
+ `);let a=o.labels[0],l=a?it(i,a.start):"",p=`${x(r)}${l}: ${ot(o.message)}`;c.warn(p),t=!0}}catch{}})),t)c.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 vt(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 Bt(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Ae(e,t,n,r,i){let{absoluteEntry:s}=await Se(e,t),o=Ce(r),a=z(r),l=await Be(s,o,a),c=await Pe(l);return ve(s,c,n,i,o,a)}function A(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function D(e){let t=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=ue(),l=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
8
+ `)}function it(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 ot(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Ce(e,t,n,r,i){let{absoluteEntry:s}=await $e(e,t),o=de(r),a=Q(r),l=await ye(s,o,a),u=await we(l);return be(s,u,n,i,o,a)}function L(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(e){let t=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=ne(),l=`${s}_${a}`;c.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}),t.push({name:l,path:o})}else t.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(e))for(let s of e){let o=A(s);i(o,s)}else if(typeof e==="object")for(let[s,o]of Object.entries(e))i(s,o);else{let s=A(e);i(s,e)}return t}function De(e,t){return`[dir]/${e}${t}`}var re=oe(ne(),1);async function We(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:fe(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function He(e){let{config:t,filepath:n}=await re.loadConfig({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Fe(e,t){let{config:n,filepath:r}=await re.loadConfig({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}function qe(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(e.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var O=new Set;async function H(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await He(t);if(n&&r)f.cli(`Using package.json: ${x(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let i=n?.type,s=_(e,n),o=j(e),a=[qe(s,o)],l=D(e.entry),c=le(e,t),p=e.format.flatMap((u)=>l.map((m)=>{return Nt(e,t,m,u,i,a,c)}));if(await Promise.all(p),e.dts){let u=await Fe(t,e.preferredTsconfigPath);if(u.path)f.cli(`Using tsconfig: ${x(u.path,2)}`,{muted:!0,identifier:e.name,once:`${u.path}:${e.name}`});let m=e.format.filter(($)=>{if($==="iife"&&!N(i)&&e.format.includes("cjs"))return!1;return!0}),E=typeof e.dts==="object"&&e.dts.entry?D(e.dts.entry):l;try{await Promise.all(E.map(async($)=>{let Ze=await Ae(t,$.path,e,u,n);await Promise.all(m.map(async(ze)=>{let Je=me(ze,i),V=`${t}/${e.outDir}/${$.name}${Je}`;await Bun.write(V,Ze);let et=Bun.file(V).size||0;f.progress("DTS",x(V),Q(et),e.name)}))}))}catch($){throw new g(h($))}}}async function Nt(e,t,n,r,i,s,o){let a=pe(r,i),l=await Bun.build({...o,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:De(n.name,a)},splitting:de(e.splitting,r),bytecode:be(e.bytecode,r),plugins:s,throw:!1});if(!l.success)for(let u of l.logs){if(u.level==="error")throw new b(u.message);if(u.level==="warning")f.warn(u.message);else if(u.level==="info")f.info(u.message)}let c=`${t}/${e.outDir}/${n.name}${a}`,p=Bun.file(c).size||0;f.progress(r.toUpperCase(),x(c),Q(p),e.name)}var F="0.3.80";var Ve="https://bun.sh/docs/installation",Ge="https://bunup.arshadyaseen.com/#cli-options";function y(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 d(`Option --${e} requires a string value`)}}function Xe(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function _t(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:l,path:o})}else t.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(e))for(let s of e){let o=L(s);i(o,s)}else if(typeof e==="object")for(let[s,o]of Object.entries(e))i(s,o);else{let s=L(e);i(s,e)}return t}function Oe(e,t){return`[dir]/${e}${t}`}import{loadConfig as Be}from"coffi";async function ve(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:re(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Pe(e){let{config:t,filepath:n}=await Be({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Te(e,t){let{config:n,filepath:r}=await Be({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}function Le(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(e.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var C=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.");let{packageJson:n,path:r}=await Pe(t);if(n&&r)c.cli(`Using package.json: ${x(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let i=n?.type,s=U(e,n),o=_(e),a=[Le(s,o)],l=A(e.entry),u=ee(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 Te(t,e.preferredTsconfigPath);if(f.path)c.cli(`Using tsconfig: ${x(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}),F=typeof e.dts==="object"&&e.dts.entry?A(e.dts.entry):l;try{await Promise.all(F.map(async(E)=>{let Ue=await Ce(t,E.path,e,f,n);await Promise.all(m.map(async(_e)=>{let Ne=ie(_e,i),q=`${t}/${e.outDir}/${E.name}${Ne}`;await Bun.write(q,Ue);let ke=Bun.file(q).size||0;c.progress("DTS",x(q),Y(ke),e.name)}))}))}catch(E){throw new g(h(E))}}}async function at(e,t,n,r,i,s,o){let a=se(r,i),l=await Bun.build({...o,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Oe(n.name,a)},splitting:ae(e.splitting,r),bytecode:fe(e.bytecode,r),plugins:s,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(),x(u),Y(p),e.name)}var j="0.3.81";var Ae="https://bun.sh/docs/installation",Se="https://bunup.arshadyaseen.com/#cli-options";function b(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 d(`Option --${e} requires a string value`)}}function De(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function ct(){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${Ge}\x1B[0m
26
- `),process.exit(0)}function jt(){console.log(F),process.exit(0)}var kt={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 d("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:w("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},banner:{flags:["b","banner"],handler:w("banner")},footer:{flags:["f","footer"],handler:w("footer")},external:{flags:["e","external"],handler:Xe("external")},sourcemap:{flags:["sm","sourcemap"],handler:w("sourcemap")},target:{flags:["t","target"],handler:w("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:y("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:y("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:y("minifySyntax")},clean:{flags:["c","clean"],handler:y("clean")},splitting:{flags:["s","splitting"],handler:y("splitting")},noExternal:{flags:["ne","no-external"],handler:Xe("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:y("bytecode")}},Wt={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}}},Ht={help:{flags:["h","help"],handler:()=>_t()},version:{flags:["v","version"],handler:()=>jt()}},I={};for(let e of Object.values(kt))if(e)for(let t of e.flags)I[t]=e.handler;for(let e of Object.values(Wt))for(let t of e.flags)I[t]=e.handler;for(let e of Object.values(Ht))for(let t of e.flags)I[t]=e.handler;function Ye(e){let t={},n={},r=0;while(r<e.length){let i=e[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,l]=i.slice(2).split("=",2);s=a,o=l}else{s=i.slice(2);let a=e[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(n[a])f.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);n[a]=o}else throw new d("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(n[a])f.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=o}else throw new d(`Option --entry.${a} requires a string value`)}else{let a=I[s];if(a)a(o,t);else throw new d(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=e[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let l=I[s];if(l)l(a,t);else throw new d(`Unknown option: -${s}`)}else{let s=A(i);if(n[s])f.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);n[s]=i}r++}if(Object.keys(n).length>0)t.entry=n;return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
27
- To install Bun, visit ${Ve}`)})();var Qe=oe(ne(),1);import q from"node:path";import Ft from"chokidar";async function Ke(e,t){let n=new Set,r=D(e.entry);for(let a of r){let l=q.resolve(t,a.path),c=q.dirname(l);n.add(c)}let i=Ft.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,q.join(t,e.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let l=performance.now();if(await H({...e,entry:r.map((c)=>c.path),clean:!1},t),e.onBuildSuccess?.(),!a)f.cli(`\uD83D\uDCE6 Rebuild finished in ${U(performance.now()-l)}`);await se()}catch(l){X(l)}finally{s=!1}};i.on("change",(a)=>{let l=q.relative(t,a);f.cli(`File changed: ${l}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new M(`Watcher error: ${h(a)}`)}),await o(!0)}async function qt(e=Bun.argv.slice(2)){let t=Ye(e),n=process.cwd(),{config:r,filepath:i}=await Qe.loadConfig({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1}),s=!r?[{rootDir:n,options:t}]:await We(r,n);if(f.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),i)f.cli(`Using config file: ${x(i,2)}`,{muted:!0});let o=performance.now();f.cli("Build started");for(let{options:c,rootDir:p}of s){let u=K(c);await Promise.all(u.map((m)=>{if(ye(m.clean))he(p,xe(m.outDir))}))}await Promise.all(s.flatMap(({options:c,rootDir:p})=>{return K(c).map(async(m)=>{let E={...T,...m,...t};return Vt(E,p)})}));let a=performance.now()-o,l=U(a);if(f.cli(`\u26A1\uFE0F Build completed in ${l}`),await se(),t.watch)f.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function se(){if(O.size>0)await Le(O),O.clear()}async function Vt(e,t){if(e.watch)await Ke(e,t);else await H(e,t),e.onBuildSuccess?.()}qt().catch((e)=>ae(e));export{se as validateDtsFiles,qt 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 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 d("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:w("outDir")},minify:{flags:["m","minify"],handler:b("minify")},watch:{flags:["w","watch"],handler:b("watch")},dts:{flags:["d","dts"],handler:b("dts")},banner:{flags:["b","banner"],handler:w("banner")},footer:{flags:["f","footer"],handler:w("footer")},external:{flags:["e","external"],handler:De("external")},sourcemap:{flags:["sm","sourcemap"],handler:w("sourcemap")},target:{flags:["t","target"],handler:w("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:b("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:b("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:b("minifySyntax")},clean:{flags:["c","clean"],handler:b("clean")},splitting:{flags:["s","splitting"],handler:b("splitting")},noExternal:{flags:["ne","no-external"],handler:De("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:b("bytecode")}},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 Me(e){let t={},n={},r=0;while(r<e.length){let i=e[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,l]=i.slice(2).split("=",2);s=a,o=l}else{s=i.slice(2);let a=e[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=L(o);if(n[a])c.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);n[a]=o}else throw new d("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(n[a])c.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=o}else throw new d(`Option --entry.${a} requires a string value`)}else{let a=S[s];if(a)a(o,t);else throw new d(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=e[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let l=S[s];if(l)l(a,t);else throw new d(`Unknown option: -${s}`)}else{let s=L(i);if(n[s])c.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);n[s]=i}r++}if(Object.keys(n).length>0)t.entry=n;return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
27
+ To install Bun, visit ${Ae}`)})();import{loadConfig as dt}from"coffi";import H from"node:path";import gt from"chokidar";async function Ie(e,t){let n=new Set,r=A(e.entry);for(let a of r){let l=H.resolve(t,a.path),u=H.dirname(l);n.add(u)}let i=gt.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,H.join(t,e.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!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{s=!1}};i.on("change",(a)=>{let l=H.relative(t,a);c.cli(`File changed: ${l}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new D(`Watcher error: ${h(a)}`)}),await o(!0)}async function ht(e=Bun.argv.slice(2)){let t=Me(e),n=process.cwd(),{config:r,filepath:i}=await dt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1}),s=!r?[{rootDir:n,options:t}]:await ve(r,n);if(c.cli(`Using bunup v${j} and bun v${Bun.version}`,{muted:!0}),i)c.cli(`Using config file: ${x(i,2)}`,{muted:!0});let o=performance.now();c.cli("Build started");for(let{options:u,rootDir:p}of s){let f=X(u);await Promise.all(f.map((m)=>{if(ue(m.clean))le(p,ce(m.outDir))}))}await Promise.all(s.flatMap(({options:u,rootDir:p})=>{return X(u).map(async(m)=>{let F={...v,...m,...t};return xt(F,p)})}));let a=performance.now()-o,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(C.size>0)await Re(C),C.clear()}async function xt(e,t){if(e.watch)await Ie(e,t);else await W(e,t),e.onBuildSuccess?.()}ht().catch((e)=>J(e));export{z as validateDtsFiles,ht as main};
package/build/index.js CHANGED
@@ -1,15 +1,15 @@
1
- var Gt=require("node:module");var _t=Object.create;var{getPrototypeOf:jt,defineProperty:$,getOwnPropertyNames:k,getOwnPropertyDescriptor:Ut}=Object,H=Object.prototype.hasOwnProperty;var x=(t,e,r)=>{r=t!=null?_t(jt(t)):{};let n=e||!t||!t.__esModule?$(r,"default",{value:t,enumerable:!0}):r;for(let i of k(t))if(!H.call(n,i))$(n,i,{get:()=>t[i],enumerable:!0});return n},X=new WeakMap,qt=(t)=>{var e=X.get(t),r;if(e)return e;if(e=$({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")k(t).map((n)=>!H.call(e,n)&&$(e,n,{get:()=>t[n],enumerable:!(r=Ut(t,n))||r.enumerable}));return X.set(t,e),e},Ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Vt=(t,e)=>{for(var r in e)$(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})};var St=Ft((ar,Bt)=>{var or=require("node:module"),{defineProperty:F,getOwnPropertyNames:ie,getOwnPropertyDescriptor:oe}=Object,ae=Object.prototype.hasOwnProperty,Rt=new WeakMap,ce=(t)=>{var e=Rt.get(t),r;if(e)return e;if(e=F({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")ie(t).map((n)=>!ae.call(e,n)&&F(e,n,{get:()=>t[n],enumerable:!(r=oe(t,n))||r.enumerable}));return Rt.set(t,e),e},ue=(t,e)=>{for(var r in e)F(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})},Mt={};ue(Mt,{loadConfig:()=>ge});Bt.exports=ce(Mt);var V=require("node:fs"),$t=require("node:path"),Ct=[".ts",".mts",".cts",".js",".mjs",".cjs",".json"];class R{static instance;constructor(){}static getInstance(){if(!R.instance)R.instance=new R;return R.instance}warn(t){console.log(`\x1B[33mWARNING: ${t}\x1B[0m`)}}var le=R.getInstance();function fe(t){try{return V.existsSync(t)}catch{return!1}}async function Pt(t){try{if(!fe(t))return null;if(t.slice(t.lastIndexOf(".")).toLowerCase()===".json"){let n=V.readFileSync(t,"utf-8");return JSON.parse(n)}let e=await import(t),r=e.default||e;if(typeof r==="function")r=r();if(r instanceof Promise)return r;return r}catch(e){return null}}async function Dt(t,e,r,n,i){if(i){let a=await Pt(i);if(a!==null)return{config:a,filepath:i};le.warn(`Preferred path "${i}" not found or invalid, searching for ${t} files instead.`)}let s=r,o=0;while(o<n){try{let c=V.readdirSync(s),l=new Set(c);for(let f of e){let u=`${t}${f}`;if(l.has(u)){let g=$t.join(s,u),M=await Pt(g);if(M!==null)return{config:M,filepath:g}}}}catch(c){}let a=$t.dirname(s);if(a===s)break;s=a,o++}return{config:null,filepath:null}}async function ge(t,e=Ct,r={}){if(typeof t==="string"){let c=t,{cwd:l=process.cwd(),maxDepth:f=10,preferredPath:u}=r;return Dt(c,e,l,f,u)}let{name:n,extensions:i=Ct,cwd:s=process.cwd(),maxDepth:o=10,preferredPath:a}=t;return Dt(n,i,s,o,a)}});var me={};Vt(me,{defineWorkspace:()=>Y,defineConfig:()=>K,build:()=>Ot});module.exports=qt(me);function K(t){return t}function Y(t){return t}var gt=require("rolldown"),pt=require("rolldown-plugin-dts");class v extends Error{constructor(t){super(t);this.name="BunupError"}}class C extends v{constructor(t){super(t);this.name="BunupBuildError"}}class m extends v{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};var kt=x(require("node:fs/promises")),Ht=x(require("node:path"));function Q(t,e){return{outdir:`${e}/${t.outDir}`,minify:Xt(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 Xt(t){let{minify:e,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:i}=t,s=e===!0;return{whitespace:r??s,identifiers:n??s,syntax:i??s}}function N(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Z(t=8){return Math.random().toString(36).substring(2,2+t)}function z(t,e){switch(t){case"esm":return".mjs";case"cjs":return B(e)?".cjs":".js";case"iife":return".global.js"}}function J(t,e){switch(t){case"esm":return".d.mts";case"cjs":return B(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function B(t){return t==="module"}function tt(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function et(t,e){return t===void 0?e==="esm":t}function W(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${e[r]}`;return`${(t/1024**r).toFixed(2)} ${e[r]}`}function E(t,e=3){return t.split("/").slice(-e).join("/")}function rt(t,e){return e==="cjs"?t:void 0}function nt(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${N(e)}($|\\/|\\\\)`):e)}function S(t,e){return nt(t.external||[]).concat(tt(e).map((r)=>new RegExp(`^${N(r)}($|\\/|\\\\)`)))}function L(t){return nt(t.noExternal||[])}var ut=x(require("node:path")),lt=require("oxc-resolver");var h=x(require("node:path"));var D="\x00dts:",st=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,i){if(_(n))return n;if(!i||!_(i))return null;let s=await T(n,e,r,P(i));if(!s)return null;let o=b(s);if(t.has(o))return A(o);return null},load(n){if(n.startsWith(D)){let i=P(n),s=t.get(i);if(s)return it.add(i),s}return null}}};function ot(t){return t.tsconfig?.compilerOptions}function b(t){return t.replace(/\.tsx?$/,".d.ts")}function j(t){let e=h.default.dirname(t.path||""),r=ot(t);return r?.baseUrl?h.default.resolve(e,r.baseUrl):e}function at(t){let e=new Map,r=ot(t)?.paths;if(!r)return e;let n=j(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");e.set(`^${o}$`,h.default.join(n,a))}return e}function Kt(t,e,r){for(let[n,i]of e){let s=new RegExp(n),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?h.default.join(r,t):null}async function Yt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of e){let n=`${t}${r}`;if(await Bun.file(n).exists()&&(n.endsWith(".ts")||n.endsWith(".tsx")))return n}return null}function T(t,e,r,n){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(n||""),t):Kt(t,e,r);if(!i)return Promise.resolve(null);return Yt(i)}function _(t){return t.startsWith(D)}function P(t){return t.replace(D,"")}function A(t){return`${D}${t}`}var ct;function ft(t){return{name:"bunup:types-resolve",buildStart(){ct||=new lt.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,r){let n=r?P(r):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!n?.includes(a);else c=a.test(e)||!!(n&&a.test(n));return c}))return}let i=n?ut.default.dirname(n):process.cwd(),{path:s}=await ct.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function mt(t,e,r,n,i,s){let o=b(t),a=A(o),c=S(r,n),l=L(r);try{let{output:f}=await gt.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,g){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;g(u)},plugins:[st(e,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&ft(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),pt.dts()],external:(u)=>c.some((g)=>g.test(u))&&!l.some((g)=>g.test(u))});if(!f[0]?.code)throw new m("Generated bundle is empty");return f[0].code}catch(f){throw new m(`DTS bundling failed: ${d(f)}`)}}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:r,size:n,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[l,...f]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),g=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${f.join(" ")}${g}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${a}${c}`}output(t,e={},r=console.log){if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(r(t),e.verticalSpace)console.log("")}cli(t,e={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}info(t,e={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}warn(t,e={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.warn)}error(t,e={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.error)}progress(t,e,r,n){let i=String(t),s=this.colors.default,o,a,c={};if(typeof r==="string")o=r,a=n;else if(r)o=r.size,a=r.identifier,c=r;for(let[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var p=y.getInstance();var Qt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Zt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,zt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Jt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,te=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ee=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,re=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function ne(t){let e=new Set,r=[Qt,Zt,zt,Jt,te,ee,re];for(let n of r){let i=t.matchAll(n);for(let s of i)if(s[1])e.add(s[1])}return e}async function dt(t,e,r){let n=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=ne(o);for(let c of a){let l=await T(c,e,r,s);if(!l)continue;if(!n.has(l))n.add(l),i.push(l)}}catch(o){p.warn(`Error processing ${s}: ${d(o)}`)}}return n}var xt=require("oxc-transform");async function ht(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=b(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=xt.isolatedDeclaration(r,s);if(o)e.set(n,o)}catch(n){p.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}var U=x(require("node:fs/promises")),O=x(require("node:path")),se=require("oxc-transform");async function wt(t,e){let r=O.default.resolve(t),n=O.default.resolve(r,e);if(!await U.default.exists(r))throw new m(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new m(`Entry file does not exist: ${n}`);if(!n.endsWith(".ts"))throw new m(`Entry file must be a TypeScript file (.ts): ${n}`);if(O.default.relative(r,n).startsWith(".."))throw new m(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function Et(t,e,r,n,i){let{absoluteEntry:s}=await wt(t,e),o=at(n),a=j(n),c=await dt(s,o,a),l=await ht(c);return mt(s,l,r,i,o,a)}function bt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function q(t){let e=[],r=new Set,n={};function i(s,o){if(r.has(s)){let a=Z(),c=`${s}_${a}`;p.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ var St=require("node:module");var Mt=Object.create;var{getPrototypeOf:Bt,defineProperty:y,getOwnPropertyNames:j,getOwnPropertyDescriptor:Tt}=Object,q=Object.prototype.hasOwnProperty;var E=(t,e,n)=>{n=t!=null?Mt(Bt(t)):{};let r=e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n;for(let i of j(t))if(!q.call(r,i))y(r,i,{get:()=>t[i],enumerable:!0});return r},F=new WeakMap,Lt=(t)=>{var e=F.get(t),n;if(e)return e;if(e=y({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((r)=>!q.call(e,r)&&y(e,r,{get:()=>t[r],enumerable:!(n=Tt(t,r))||n.enumerable}));return F.set(t,e),e};var At=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Kt={};At(Kt,{defineWorkspace:()=>X,defineConfig:()=>G,build:()=>Rt});module.exports=Lt(Kt);function G(t){return t}function X(t){return t}var ct=require("rolldown"),ut=require("rolldown-plugin-dts");class I extends Error{constructor(t){super(t);this.name="BunupError"}}class $ 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)};var Ot=E(require("node:fs/promises")),Wt=E(require("node:path"));function H(t,e){return{outdir:`${e}/${t.outDir}`,minify:It(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 It(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,s=e===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){return Math.random().toString(36).substring(2,2+t)}function K(t,e){switch(t){case"esm":return".mjs";case"cjs":return D(e)?".cjs":".js";case"iife":return".global.js"}}function Y(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 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 W(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("/")}function z(t,e){return e==="cjs"?t:void 0}function J(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function M(t,e){return J(t.external||[]).concat(Q(e).map((n)=>new RegExp(`^${O(n)}($|\\/|\\\\)`)))}function B(t){return J(t.noExternal||[])}var it=E(require("node:path")),ot=require("oxc-resolver");var x=E(require("node:path"));var P="\x00dts:",tt=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(_(r))return r;if(!i||!_(i))return null;let s=await T(r,e,n,C(i));if(!s)return null;let o=w(s);if(t.has(o))return L(o);return null},load(r){if(r.startsWith(P)){let i=C(r),s=t.get(i);if(s)return et.add(i),s}return null}}};function nt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function N(t){let e=x.default.dirname(t.path||""),n=nt(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function rt(t){let e=new Map,n=nt(t)?.paths;if(!n)return e;let r=N(t);for(let[i,s]of Object.entries(n))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");e.set(`^${o}$`,x.default.join(r,a))}return e}function _t(t,e,n){for(let[r,i]of e){let s=new RegExp(r),o=t.match(s);if(o)return i.replace("$1",o[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 i=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):_t(t,e,n);if(!i)return Promise.resolve(null);return Nt(i)}function _(t){return t.startsWith(P)}function C(t){return t.replace(P,"")}function L(t){return`${P}${t}`}var st;function at(t){return{name:"bunup:types-resolve",buildStart(){st||=new ot.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 i=r?it.default.dirname(r):process.cwd(),{path:s}=await st.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function lt(t,e,n,r,i,s){let o=w(t),a=L(o),c=M(n,r),l=B(n);try{let{output:f}=await ct.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[tt(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&at(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ut.dts()],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!f[0]?.code)throw new p("Generated bundle is empty");return f[0].code}catch(f){throw new p(`DTS bundling failed: ${d(f)}`)}}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:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=s?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[l,...f]=a.split(" "),u=" ".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${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${a}${c}`}output(t,e={},n=console.log){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),s=this.colors.default,o,a,c={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,c=n;for(let[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var g=R.getInstance();var Ut=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Xt(t){let e=new Set,n=[Ut,vt,Vt,Ft,jt,qt,Gt];for(let r of n){let i=t.matchAll(r);for(let s of i)if(s[1])e.add(s[1])}return e}async function gt(t,e,n){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=Xt(o);for(let c of a){let l=await T(c,e,n,s);if(!l)continue;if(!r.has(l))r.add(l),i.push(l)}}catch(o){g.warn(`Error processing ${s}: ${d(o)}`)}}return r}var ft=require("oxc-transform");async function mt(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 s=await Bun.file(n).text(),{code:o}=ft.isolatedDeclaration(n,s);if(o)e.set(r,o)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}var U=E(require("node:fs/promises")),A=E(require("node:path")),Ht=require("oxc-transform");async function pt(t,e){let n=A.default.resolve(t),r=A.default.resolve(n,e);if(!await U.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(A.default.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function dt(t,e,n,r,i){let{absoluteEntry:s}=await pt(t,e),o=rt(r),a=N(r),c=await gt(s,o,a),l=await mt(c);return lt(s,l,n,i,o,a)}function xt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=k(),c=`${s}_${a}`;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
- ${n[s]} -> ${s}.js
4
+ ${r[s]} -> ${s}.js
5
5
  ${o} -> ${c}.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: "${n[s]}",
10
+ custom_name: "${r[s]}",
11
11
  another_name: "${o}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),e.push({name:c,path:o})}else e.push({name:s,path:o}),r.add(s),n[s]=o}if(Array.isArray(t))for(let s of t){let o=bt(s);i(o,s)}else if(typeof t==="object")for(let[s,o]of Object.entries(t))i(s,o);else{let s=bt(t);i(s,t)}return e}function yt(t,e){return`[dir]/${t}${e}`}var G=x(St());async function Lt(t){let{config:e,filepath:r}=await G.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:r}}async function Tt(t,e){let{config:r,filepath:n}=await G.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:r,path:n}}function At(t,e){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let i=n.path;if(t.some((o)=>o.test(i))&&!e.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var it=new Set;async function Ot(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new C("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:n}=await Lt(e);if(r&&n)p.cli(`Using package.json: ${E(n,2)}`,{muted:!0,identifier:t.name,once:`${n}:${t.name}`});let i=r?.type,s=S(t,r),o=L(t),a=[At(s,o)],c=q(t.entry),l=Q(t,e),f=t.format.flatMap((u)=>c.map((g)=>{return pe(t,e,g,u,i,a,l)}));if(await Promise.all(f),t.dts){let u=await Tt(e,t.preferredTsconfigPath);if(u.path)p.cli(`Using tsconfig: ${E(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let g=t.format.filter((w)=>{if(w==="iife"&&!B(i)&&t.format.includes("cjs"))return!1;return!0}),M=typeof t.dts==="object"&&t.dts.entry?q(t.dts.entry):c;try{await Promise.all(M.map(async(w)=>{let It=await Et(e,w.path,t,u,r);await Promise.all(g.map(async(vt)=>{let Nt=J(vt,i),I=`${e}/${t.outDir}/${w.name}${Nt}`;await Bun.write(I,It);let Wt=Bun.file(I).size||0;p.progress("DTS",E(I),W(Wt),t.name)}))}))}catch(w){throw new m(d(w))}}}async function pe(t,e,r,n,i,s,o){let a=z(n,i),c=await Bun.build({...o,entrypoints:[`${e}/${r.path}`],format:n,naming:{entry:yt(r.name,a)},splitting:et(t.splitting,n),bytecode:rt(t.bytecode,n),plugins:s,throw:!1});if(!c.success)for(let u of c.logs){if(u.level==="error")throw new C(u.message);if(u.level==="warning")p.warn(u.message);else if(u.level==="info")p.info(u.message)}let l=`${e}/${t.outDir}/${r.name}${a}`,f=Bun.file(l).size||0;p.progress(n.toUpperCase(),E(l),W(f),t.name)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),e.push({name:c,path:o})}else e.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(t))for(let s of t){let o=xt(s);i(o,s)}else if(typeof t==="object")for(let[s,o]of Object.entries(t))i(s,o);else{let s=xt(t);i(s,t)}return e}function ht(t,e){return`[dir]/${t}${e}`}var V=require("coffi");async function Et(t){let{config:e,filepath:n}=await V.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function bt(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 wt(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(t.some((o)=>o.test(i))&&!e.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var et=new Set;async function Rt(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new $("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await Et(e);if(n&&r)g.cli(`Using package.json: ${b(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let i=n?.type,s=M(t,n),o=B(t),a=[wt(s,o)],c=v(t.entry),l=H(t,e),f=t.format.flatMap((u)=>c.map((m)=>{return kt(t,e,m,u,i,a,l)}));if(await Promise.all(f),t.dts){let u=await bt(e,t.preferredTsconfigPath);if(u.path)g.cli(`Using tsconfig: ${b(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let m=t.format.filter((h)=>{if(h==="iife"&&!D(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?v(t.dts.entry):c;try{await Promise.all(yt.map(async(h)=>{let $t=await dt(e,h.path,t,u,n);await Promise.all(m.map(async(Ct)=>{let Pt=Y(Ct,i),S=`${e}/${t.outDir}/${h.name}${Pt}`;await Bun.write(S,$t);let Dt=Bun.file(S).size||0;g.progress("DTS",b(S),W(Dt),t.name)}))}))}catch(h){throw new p(d(h))}}}async function kt(t,e,n,r,i,s,o){let a=K(r,i),c=await Bun.build({...o,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:ht(n.name,a)},splitting:Z(t.splitting,r),bytecode:z(t.bytecode,r),plugins:s,throw:!1});if(!c.success)for(let u of c.logs){if(u.level==="error")throw new $(u.message);if(u.level==="warning")g.warn(u.message);else if(u.level==="info")g.info(u.message)}let l=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(l).size||0;g.progress(r.toUpperCase(),b(l),W(f),t.name)}
package/build/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import{createRequire as Ot}from"node:module";var Mt=Object.create;var{getPrototypeOf:Bt,defineProperty:V,getOwnPropertyNames:St}=Object;var Lt=Object.prototype.hasOwnProperty;var Tt=(t,e,r)=>{r=t!=null?Mt(Bt(t)):{};let n=e||!t||!t.__esModule?V(r,"default",{value:t,enumerable:!0}):r;for(let i of St(t))if(!Lt.call(n,i))V(n,i,{get:()=>t[i],enumerable:!0});return n};var At=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var A=Ot(import.meta.url);var Et=At((dr,wt)=>{var mr=A("node:module"),{defineProperty:U,getOwnPropertyNames:zt,getOwnPropertyDescriptor:Jt}=Object,te=Object.prototype.hasOwnProperty,gt=new WeakMap,ee=(t)=>{var e=gt.get(t),r;if(e)return e;if(e=U({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")zt(t).map((n)=>!te.call(e,n)&&U(e,n,{get:()=>t[n],enumerable:!(r=Jt(t,n))||r.enumerable}));return gt.set(t,e),e},re=(t,e)=>{for(var r in e)U(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})},ht={};re(ht,{loadConfig:()=>ie});wt.exports=ee(ht);var q=A("node:fs"),pt=A("node:path"),mt=[".ts",".mts",".cts",".js",".mjs",".cjs",".json"];class y{static instance;constructor(){}static getInstance(){if(!y.instance)y.instance=new y;return y.instance}warn(t){console.log(`\x1B[33mWARNING: ${t}\x1B[0m`)}}var ne=y.getInstance();function se(t){try{return q.existsSync(t)}catch{return!1}}async function dt(t){try{if(!se(t))return null;if(t.slice(t.lastIndexOf(".")).toLowerCase()===".json"){let n=q.readFileSync(t,"utf-8");return JSON.parse(n)}let e=await import(t),r=e.default||e;if(typeof r==="function")r=r();if(r instanceof Promise)return r;return r}catch(e){return null}}async function xt(t,e,r,n,i){if(i){let a=await dt(i);if(a!==null)return{config:a,filepath:i};ne.warn(`Preferred path "${i}" not found or invalid, searching for ${t} files instead.`)}let s=r,o=0;while(o<n){try{let c=q.readdirSync(s),l=new Set(c);for(let f of e){let u=`${t}${f}`;if(l.has(u)){let g=pt.join(s,u),P=await dt(g);if(P!==null)return{config:P,filepath:g}}}}catch(c){}let a=pt.dirname(s);if(a===s)break;s=a,o++}return{config:null,filepath:null}}async function ie(t,e=mt,r={}){if(typeof t==="string"){let c=t,{cwd:l=process.cwd(),maxDepth:f=10,preferredPath:u}=r;return xt(c,e,l,f,u)}let{name:n,extensions:i=mt,cwd:s=process.cwd(),maxDepth:o=10,preferredPath:a}=t;return xt(n,i,s,o,a)}});function It(t){return t}function vt(t){return t}import{build as qt}from"rolldown";import{dts as Ft}from"rolldown-plugin-dts";class O extends Error{constructor(t){super(t);this.name="BunupError"}}class R extends O{constructor(t){super(t);this.name="BunupBuildError"}}class m extends O{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import de from"node:fs/promises";import he from"node:path";function G(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:r,minifyIdentifiers:n,minifySyntax:i}=t,s=e===!0;return{whitespace:r??s,identifiers:n??s,syntax:i??s}}function I(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X(t=8){return Math.random().toString(36).substring(2,2+t)}function k(t,e){switch(t){case"esm":return".mjs";case"cjs":return D(e)?".cjs":".js";case"iife":return".global.js"}}function H(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 K(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Y(t,e){return t===void 0?e==="esm":t}function v(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${e[r]}`;return`${(t/1024**r).toFixed(2)} ${e[r]}`}function h(t,e=3){return t.split("/").slice(-e).join("/")}function Q(t,e){return e==="cjs"?t:void 0}function Z(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${I(e)}($|\\/|\\\\)`):e)}function M(t,e){return Z(t.external||[]).concat(K(e).map((r)=>new RegExp(`^${I(r)}($|\\/|\\\\)`)))}function B(t){return Z(t.noExternal||[])}import jt from"node:path";import{ResolverFactory as Ut}from"oxc-resolver";import E from"node:path";var C="\x00dts:",z=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,i){if(N(n))return n;if(!i||!N(i))return null;let s=await S(n,e,r,$(i));if(!s)return null;let o=w(s);if(t.has(o))return L(o);return null},load(n){if(n.startsWith(C)){let i=$(n),s=t.get(i);if(s)return J.add(i),s}return null}}};function tt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function W(t){let e=E.dirname(t.path||""),r=tt(t);return r?.baseUrl?E.resolve(e,r.baseUrl):e}function et(t){let e=new Map,r=tt(t)?.paths;if(!r)return e;let n=W(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");e.set(`^${o}$`,E.join(n,a))}return e}function Wt(t,e,r){for(let[n,i]of e){let s=new RegExp(n),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?E.join(r,t):null}async function _t(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of e){let n=`${t}${r}`;if(await Bun.file(n).exists()&&(n.endsWith(".ts")||n.endsWith(".tsx")))return n}return null}function S(t,e,r,n){let i=t.startsWith(".")?E.resolve(E.dirname(n||""),t):Wt(t,e,r);if(!i)return Promise.resolve(null);return _t(i)}function N(t){return t.startsWith(C)}function $(t){return t.replace(C,"")}function L(t){return`${C}${t}`}var rt;function nt(t){return{name:"bunup:types-resolve",buildStart(){rt||=new Ut({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,r){let n=r?$(r):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!n?.includes(a);else c=a.test(e)||!!(n&&a.test(n));return c}))return}let i=n?jt.dirname(n):process.cwd(),{path:s}=await rt.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function st(t,e,r,n,i,s){let o=w(t),a=L(o),c=M(r,n),l=B(r);try{let{output:f}=await qt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,g){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;g(u)},plugins:[z(e,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&nt(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Ft()],external:(u)=>c.some((g)=>g.test(u))&&!l.some((g)=>g.test(u))});if(!f[0]?.code)throw new m("Generated bundle is empty");return f[0].code}catch(f){throw new m(`DTS bundling failed: ${d(f)}`)}}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(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:r,size:n,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[l,...f]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),g=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${f.join(" ")}${g}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${a}${c}`}output(t,e={},r=console.log){if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(r(t),e.verticalSpace)console.log("")}cli(t,e={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}info(t,e={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}warn(t,e={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.warn)}error(t,e={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.error)}progress(t,e,r,n){let i=String(t),s=this.colors.default,o,a,c={};if(typeof r==="string")o=r,a=n;else if(r)o=r.size,a=r.identifier,c=r;for(let[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var p=b.getInstance();var Vt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Gt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Xt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,kt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ht=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Kt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Yt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Qt(t){let e=new Set,r=[Vt,Gt,Xt,kt,Ht,Kt,Yt];for(let n of r){let i=t.matchAll(n);for(let s of i)if(s[1])e.add(s[1])}return e}async function it(t,e,r){let n=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Qt(o);for(let c of a){let l=await S(c,e,r,s);if(!l)continue;if(!n.has(l))n.add(l),i.push(l)}}catch(o){p.warn(`Error processing ${s}: ${d(o)}`)}}return n}import{isolatedDeclaration as Zt}from"oxc-transform";async function ot(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=w(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=Zt(r,s);if(o)e.set(n,o)}catch(n){p.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}import at from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as tr}from"oxc-transform";async function ct(t,e){let r=_.resolve(t),n=_.resolve(r,e);if(!await at.exists(r))throw new m(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new m(`Entry file does not exist: ${n}`);if(!n.endsWith(".ts"))throw new m(`Entry file must be a TypeScript file (.ts): ${n}`);if(_.relative(r,n).startsWith(".."))throw new m(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function ut(t,e,r,n,i){let{absoluteEntry:s}=await ct(t,e),o=et(n),a=W(n),c=await it(s,o,a),l=await ot(c);return st(s,l,r,i,o,a)}function lt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let e=[],r=new Set,n={};function i(s,o){if(r.has(s)){let a=X(),c=`${s}_${a}`;p.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function pt(t){return t}function dt(t){return t}import{build as Rt}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class L extends Error{constructor(t){super(t);this.name="BunupError"}}class R extends L{constructor(t){super(t);this.name="BunupBuildError"}}class p extends L{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import Ft from"node:path";function N(t,e){return{outdir:`${e}/${t.outDir}`,minify:xt(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 xt(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,s=e===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function A(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(t=8){return Math.random().toString(36).substring(2,2+t)}function v(t,e){switch(t){case"esm":return".mjs";case"cjs":return C(e)?".cjs":".js";case"iife":return".global.js"}}function V(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 F(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 h(t,e=3){return t.split("/").slice(-e).join("/")}function q(t,e){return e==="cjs"?t:void 0}function G(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${A(e)}($|\\/|\\\\)`):e)}function P(t,e){return G(t.external||[]).concat(F(e).map((n)=>new RegExp(`^${A(n)}($|\\/|\\\\)`)))}function D(t){return G(t.noExternal||[])}import bt from"node:path";import{ResolverFactory as wt}from"oxc-resolver";import b from"node:path";var $="\x00dts:",X=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(I(r))return r;if(!i||!I(i))return null;let s=await M(r,e,n,y(i));if(!s)return null;let o=E(s);if(t.has(o))return B(o);return null},load(r){if(r.startsWith($)){let i=y(r),s=t.get(i);if(s)return H.add(i),s}return null}}};function k(t){return t.tsconfig?.compilerOptions}function E(t){return t.replace(/\.tsx?$/,".d.ts")}function O(t){let e=b.dirname(t.path||""),n=k(t);return n?.baseUrl?b.resolve(e,n.baseUrl):e}function K(t){let e=new Map,n=k(t)?.paths;if(!n)return e;let r=O(t);for(let[i,s]of Object.entries(n))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");e.set(`^${o}$`,b.join(r,a))}return e}function ht(t,e,n){for(let[r,i]of e){let s=new RegExp(r),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return n?b.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 M(t,e,n,r){let i=t.startsWith(".")?b.resolve(b.dirname(r||""),t):ht(t,e,n);if(!i)return Promise.resolve(null);return Et(i)}function I(t){return t.startsWith($)}function y(t){return t.replace($,"")}function B(t){return`${$}${t}`}var Y;function Q(t){return{name:"bunup:types-resolve",buildStart(){Y||=new wt({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?bt.dirname(r):process.cwd(),{path:s}=await Y.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function Z(t,e,n,r,i,s){let o=E(t),a=B(o),c=P(n,r),l=D(n);try{let{output:f}=await Rt({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[X(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&Q(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),yt()],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!f[0]?.code)throw new p("Generated bundle is empty");return f[0].code}catch(f){throw new p(`DTS bundling failed: ${d(f)}`)}}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:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=s?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[l,...f]=a.split(" "),u=" ".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${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${a}${c}`}output(t,e={},n=console.log){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),s=this.colors.default,o,a,c={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,c=n;for(let[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var g=w.getInstance();var $t=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ct=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Pt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Dt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Lt(t){let e=new Set,n=[$t,Ct,Pt,Dt,Mt,Bt,Tt];for(let r of n){let i=t.matchAll(r);for(let s of i)if(s[1])e.add(s[1])}return e}async function z(t,e,n){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=Lt(o);for(let c of a){let l=await M(c,e,n,s);if(!l)continue;if(!r.has(l))r.add(l),i.push(l)}}catch(o){g.warn(`Error processing ${s}: ${d(o)}`)}}return r}import{isolatedDeclaration as At}from"oxc-transform";async function J(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 s=await Bun.file(n).text(),{code:o}=At(n,s);if(o)e.set(r,o)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}import tt from"node:fs/promises";import W from"node:path";import{isolatedDeclaration as Ce}from"oxc-transform";async function et(t,e){let n=W.resolve(t),r=W.resolve(n,e);if(!await tt.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(W.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function nt(t,e,n,r,i){let{absoluteEntry:s}=await et(t,e),o=K(r),a=O(r),c=await z(s,o,a),l=await J(c);return Z(s,l,n,i,o,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function _(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=U(),c=`${s}_${a}`;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
- ${n[s]} -> ${s}.js
4
+ ${r[s]} -> ${s}.js
5
5
  ${o} -> ${c}.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: "${n[s]}",
10
+ custom_name: "${r[s]}",
11
11
  another_name: "${o}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),e.push({name:c,path:o})}else e.push({name:s,path:o}),r.add(s),n[s]=o}if(Array.isArray(t))for(let s of t){let o=lt(s);i(o,s)}else if(typeof t==="object")for(let[s,o]of Object.entries(t))i(s,o);else{let s=lt(t);i(s,t)}return e}function ft(t,e){return`[dir]/${t}${e}`}var F=Tt(Et(),1);async function bt(t){let{config:e,filepath:r}=await F.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:r}}async function yt(t,e){let{config:r,filepath:n}=await F.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:r,path:n}}function Rt(t,e){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let i=n.path;if(t.some((o)=>o.test(i))&&!e.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var J=new Set;async function oe(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new R("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:n}=await bt(e);if(r&&n)p.cli(`Using package.json: ${h(n,2)}`,{muted:!0,identifier:t.name,once:`${n}:${t.name}`});let i=r?.type,s=M(t,r),o=B(t),a=[Rt(s,o)],c=j(t.entry),l=G(t,e),f=t.format.flatMap((u)=>c.map((g)=>{return ae(t,e,g,u,i,a,l)}));if(await Promise.all(f),t.dts){let u=await yt(e,t.preferredTsconfigPath);if(u.path)p.cli(`Using tsconfig: ${h(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let g=t.format.filter((x)=>{if(x==="iife"&&!D(i)&&t.format.includes("cjs"))return!1;return!0}),P=typeof t.dts==="object"&&t.dts.entry?j(t.dts.entry):c;try{await Promise.all(P.map(async(x)=>{let $t=await ut(e,x.path,t,u,r);await Promise.all(g.map(async(Ct)=>{let Pt=H(Ct,i),T=`${e}/${t.outDir}/${x.name}${Pt}`;await Bun.write(T,$t);let Dt=Bun.file(T).size||0;p.progress("DTS",h(T),v(Dt),t.name)}))}))}catch(x){throw new m(d(x))}}}async function ae(t,e,r,n,i,s,o){let a=k(n,i),c=await Bun.build({...o,entrypoints:[`${e}/${r.path}`],format:n,naming:{entry:ft(r.name,a)},splitting:Y(t.splitting,n),bytecode:Q(t.bytecode,n),plugins:s,throw:!1});if(!c.success)for(let u of c.logs){if(u.level==="error")throw new R(u.message);if(u.level==="warning")p.warn(u.message);else if(u.level==="info")p.info(u.message)}let l=`${e}/${t.outDir}/${r.name}${a}`,f=Bun.file(l).size||0;p.progress(n.toUpperCase(),h(l),v(f),t.name)}export{vt as defineWorkspace,It as defineConfig,oe as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),e.push({name:c,path:o})}else e.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(t))for(let s of t){let o=rt(s);i(o,s)}else if(typeof t==="object")for(let[s,o]of Object.entries(t))i(s,o);else{let s=rt(t);i(s,t)}return e}function st(t,e){return`[dir]/${t}${e}`}import{loadConfig as it}from"coffi";async function ot(t){let{config:e,filepath:n}=await it({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function at(t,e){let{config:n,filepath:r}=await it({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function ct(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(t.some((o)=>o.test(i))&&!e.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var H=new Set;async function St(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new R("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await ot(e);if(n&&r)g.cli(`Using package.json: ${h(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let i=n?.type,s=P(t,n),o=D(t),a=[ct(s,o)],c=_(t.entry),l=N(t,e),f=t.format.flatMap((u)=>c.map((m)=>{return It(t,e,m,u,i,a,l)}));if(await Promise.all(f),t.dts){let u=await at(e,t.preferredTsconfigPath);if(u.path)g.cli(`Using tsconfig: ${h(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let m=t.format.filter((x)=>{if(x==="iife"&&!C(i)&&t.format.includes("cjs"))return!1;return!0}),ut=typeof t.dts==="object"&&t.dts.entry?_(t.dts.entry):c;try{await Promise.all(ut.map(async(x)=>{let lt=await nt(e,x.path,t,u,n);await Promise.all(m.map(async(gt)=>{let ft=V(gt,i),T=`${e}/${t.outDir}/${x.name}${ft}`;await Bun.write(T,lt);let mt=Bun.file(T).size||0;g.progress("DTS",h(T),S(mt),t.name)}))}))}catch(x){throw new p(d(x))}}}async function It(t,e,n,r,i,s,o){let a=v(r,i),c=await Bun.build({...o,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:st(n.name,a)},splitting:j(t.splitting,r),bytecode:q(t.bytecode,r),plugins:s,throw:!1});if(!c.success)for(let u of c.logs){if(u.level==="error")throw new R(u.message);if(u.level==="warning")g.warn(u.message);else if(u.level==="info")g.info(u.message)}let l=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(l).size||0;g.progress(r.toUpperCase(),h(l),S(f),t.name)}export{dt as defineWorkspace,pt as defineConfig,St as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.80",
3
+ "version": "0.3.81",
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",
@@ -18,11 +18,10 @@
18
18
  "@types/bun": "^1.2.5",
19
19
  "bumpp": "^10.1.0",
20
20
  "bunup": "^0.3.73",
21
- "coffi": "^0.1.20",
22
21
  "husky": "^9.1.7",
23
22
  "typescript": "^5.8.3",
24
23
  "vitest": "^2.1.9",
25
- "create-bunup": "0.3.80"
24
+ "create-bunup": "0.3.81"
26
25
  },
27
26
  "peerDependencies": {
28
27
  "typescript": ">=4.5.0"
@@ -53,6 +52,7 @@
53
52
  "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
54
53
  "dependencies": {
55
54
  "chokidar": "^4.0.3",
55
+ "coffi": "^0.1.20",
56
56
  "oxc-resolver": "^5.0.1",
57
57
  "oxc-transform": "^0.58.1",
58
58
  "rolldown": "1.0.0-beta.7",