bunup 0.3.49 → 0.3.51

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