bunup 0.3.88 → 0.3.90

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/README.md CHANGED
@@ -24,7 +24,7 @@ To run the benchmarks yourself, clone this repo and run `pnpm benchmark` and che
24
24
 
25
25
  - 🔥 **Bytecode Generation**: Faster startups by compiling to Bun bytecode—perfect for CLIs.
26
26
 
27
- - 📦 **Workspace Support**: Build multiple packages with `defineWorkspace()` in one config file and command.
27
+ - 📦 **Workspace Support**: Build multiple packages with [defineWorkspace()](https://bunup.arshadyaseen.com/#workspaces) in one config file and command.
28
28
 
29
29
  - 🎯 **Bun Targeting**: Optimize for Bun runtime with `--target bun` for native features.
30
30
 
package/build/cli.mjs CHANGED
@@ -1,27 +1,27 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
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
- \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")},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({dtsInput:!0})],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(`
3
+ import{build as qe}from"rolldown";import{dts as Ve}from"rolldown-plugin-dts";class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class d extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class g extends E{constructor(e){super(e);this.name="BunupCLIError"}}class v extends E{constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ne=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],q=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof d)s="DTS ERROR";else if(e instanceof g)s="CLI ERROR";else if(e instanceof v)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";console.error(`\x1B[31m${s}\x1B[0m ${r}${n}`);let o=Ne.find((i)=>i.pattern.test(n)&&(i.errorType===s||!i.errorType));if(o)console.error(`
4
+ \x1B[90mA solution for this error is available at: \x1B[36m${o.link}\x1B[0m
5
+ `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},Z=(e,t)=>{q(e,t),process.exit(1)};import z from"node:fs/promises";import ke from"node:path";function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function J(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function ee(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function te(e){return Array.isArray(e)?e:[e]}function ne(e,t){switch(e){case"esm":return".mjs";case"cjs":return L(t)?".cjs":".js";case"iife":return".global.js"}}function re(e,t){switch(e){case"esm":return".d.mts";case"cjs":return L(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(e){return e==="module"}function S(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function se(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ie(e,t){return e===void 0?t==="esm":e}function G(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function b(e,t=3){return e.split("/").slice(-t).join("/")}async function oe(e,t){let n=ke.join(e,t);try{await z.rm(n,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await z.mkdir(n,{recursive:!0})}function ae(e,t){return t==="cjs"?e:void 0}function le(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${V(t)}($|\\/|\\\\)`):t)}function A(e,t){return le(e.external||[]).concat(se(t).map((n)=>new RegExp(`^${V(n)}($|\\/|\\\\)`)))}function I(e){return le(e.noExternal||[])}import Fe from"node:path";import{ResolverFactory as He}from"oxc-resolver";import R from"node:path";var T="\x00dts:",ce=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(X(r))return r;if(!s||!X(s))return null;let o=await M(r,t,n,B(s));if(!o)return null;let i=C(o);if(e.has(i))return D(i);return null},load(r){if(r.startsWith(T)){let s=B(r),o=e.get(s);if(o)return $.add(s),o}return null}}};function ue(e){return e.tsconfig?.compilerOptions}function C(e){return e.replace(/\.tsx?$/,".d.ts")}function Y(e){let t=R.dirname(e.path||""),n=ue(e);return n?.baseUrl?R.resolve(t,n.baseUrl):t}function fe(e){let t=new Map,n=ue(e)?.paths;if(!n)return t;let r=Y(e);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");t.set(`^${i}$`,R.join(r,a))}return t}function We(e,t,n){for(let[r,s]of t){let o=new RegExp(r),i=e.match(o);if(i)return s.replace("$1",i[1]||"")}return n?R.join(n,e):null}async function je(e){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function M(e,t,n,r){let s=e.startsWith(".")?R.resolve(R.dirname(r||""),e):We(e,t,n);if(!s)return Promise.resolve(null);return je(s)}function X(e){return e.startsWith(T)}function B(e){return e.replace(T,"")}function D(e){return`${T}${e}`}var me;function pe(e){return{name:"bunup:types-resolve",buildStart(){me||=new He({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?B(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let s=r?Fe.dirname(r):process.cwd(),{path:o}=await me.async(s,t);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function de(e,t,n,r,s,o){let i=C(e),a=D(i),l=A(n,r),c=I(n);try{let{output:m}=await qe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;p(f)},plugins:[ce(t,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&pe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ve({dtsInput:!0})],external:(f)=>l.some((p)=>p.test(f))&&!c.some((p)=>p.test(f))});if(!m[0]?.code)throw new d("Generated bundle is empty");return m[0].code}catch(m){throw new d(`DTS bundling failed: ${h(m)}`)}}var ge=!1;function U(e){ge=e??!1}class O{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!O.instance)O.instance=new O;return O.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...m]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${c}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${m.join(" ")}${p}`}let l=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${l}`}output(e,t={},n=console.log){if(ge)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let s=String(e),o=this.colors.default,i,a,l={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,l=n;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){o=f;break}let c=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:l.muted});this.output(c,l)}}var u=O.getInstance();var Ge=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Xe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ye=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ke=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qe=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ze=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Je(e){let t=new Set,n=[Ge,Xe,Ye,Ke,Qe,Ze,ze];for(let r of n){let s=e.matchAll(r);for(let o of s)if(o[1])t.add(o[1])}return t}async function he(e,t,n){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=Je(i);for(let l of a){let c=await M(l,t,n,o);if(!c)continue;if(!r.has(c))r.add(c),s.push(c)}}catch(i){u.warn(`Error processing ${o}: ${h(i)}`)}}return r}import{isolatedDeclaration as et}from"oxc-transform";async function xe(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=C(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=et(n,o);if(i)t.set(r,i)}catch(r){u.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import be from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as tt}from"oxc-transform";async function ye(e,t){let n=K.resolve(e),r=K.resolve(n,t);if(!await be.exists(n))throw new d(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(K.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function we(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:o}=tt(r,s);for(let i of o){if(!t)console.log(`
6
+ `);let a=i.labels[0],l=a?nt(s,a.start):"",m=`${b(r)}${l}: ${rt(i.message)}`;u.warn(m),t=!0}}catch{}})),t)u.info(`
7
7
  You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
8
- `)}function 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.
8
+ `)}function nt(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
9
+ `),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function rt(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Ee(e,t,n,r,s){let{absoluteEntry:o}=await ye(e,t),i=fe(r),a=Y(r),l=await he(o,i,a),c=await xe(l);return de(o,c,n,s,i,a)}function _(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function P(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let l=J(),c=`${i}_${l}`;if(t)u.warn(`Output name conflict: "${i}" is used by multiple files.
10
10
  Bunup uses filenames without extensions as output names by default.
11
11
 
12
- ${r[s]} -> ${s}.js
13
- ${o} -> ${l}.js (auto-renamed to avoid conflict)
12
+ ${s[i]} -> ${i}.js
13
+ ${a} -> ${c}.js (auto-renamed to avoid conflict)
14
14
 
15
15
  To fix this, use named entries in your configuration:
16
16
  {
17
17
  entry: {
18
- custom_name: "${r[s]}",
19
- another_name: "${o}"
18
+ custom_name: "${s[i]}",
19
+ another_name: "${a}"
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=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.88";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(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=_(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=_(e);o(i,e)}return n}function Ce(e,t){return`[dir]/${e}${t}`}import{loadConfig as $e}from"coffi";async function Re(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:ee(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Oe(e){let{config:t,filepath:n}=await $e({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Be(e,t){let{config:n,filepath:r}=await $e({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var Te={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Pe(e,t){return{outdir:`${t}/${e.outDir}`,minify:st(e),target:e.target,splitting:e.splitting,sourcemap:e.sourcemap,define:e.define,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer}}function st(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function ve(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var $=new Set;async function N(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)oe(t,e.outDir);U(e.silent);let{packageJson:n,path:r}=await Oe(t);if(n&&r)u.cli(`Using package.json: ${b(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let s=P(e.entry),o=n?.type,i=A(e,n),a=I(e);if(!e.dtsOnly){let l=[ve(i,a)],c=Pe(e,t),m=e.format.flatMap((f)=>s.map((p)=>{return it(e,t,p,f,o,l,c)}));await Promise.all(m)}if(e.dts||e.dtsOnly){let l=await Be(t,e.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${b(l.path,2)}`,{muted:!0,identifier:e.name,once:`${l.path}:${e.name}`});let c=e.format.filter((f)=>{if(f==="iife"&&!L(o)&&e.format.includes("cjs"))return!1;return!0}),m=typeof e.dts==="object"&&e.dts.entry?P(e.dts.entry):s;try{await Promise.all(m.map(async(f)=>{let p=await Ee(t,f.path,e,l,n);await Promise.all(c.map(async(F)=>{let Ue=re(F,o),H=`${t}/${e.outDir}/${f.name}${Ue}`;await Bun.write(H,p);let _e=Bun.file(H).size||0;u.progress("DTS",b(H),G(_e),e.name)}))}))}catch(f){throw new d(h(f))}}}async function it(e,t,n,r,s,o,i){let a=ne(r,s),l=await Bun.build({...i,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ce(n.name,a)},splitting:ie(e.splitting,r),bytecode:ae(e.bytecode,r),plugins:o,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${n.name}${a}`,m=Bun.file(c).size||0;u.progress(r.toUpperCase(),b(c),G(m),e.name)}var k="0.3.90";var Le="https://bun.sh/docs/installation",Se="https://bunup.arshadyaseen.com/#cli-options";function x(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new g(`Option --${e} requires a string value`)}}function Ae(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new g(`Option --${e} requires a string value`)}}function at(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
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};
26
+ `),process.exit(0)}function lt(){console.log(k),process.exit(0)}var Ie={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(e,t)=>{if(typeof e==="string")t.format=e.split(",");else throw new g("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:Ae("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:Ae("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:y("config")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new g(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=_(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>at()},version:{flags:["v","version"],handler:()=>lt()}},W={};for(let e of Object.values(Ie))for(let t of e.flags)W[t]=e.handler;function Me(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),l=W[i];if(l)l(o,t,a);else throw new g(`Unknown option: --${s}`)}else{let i=W[s];if(i)i(o,t);else throw new g(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=W[s];if(a)a(i,t);else throw new g(`Unknown option: -${s}`)}else Ie.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new g(`Bunup requires Bun to run.
27
+ To install Bun, visit ${Le}`)})();import{loadConfig as ut}from"coffi";import j from"node:path";import ct from"chokidar";async function De(e,t){let n=new Set,r=P(e.entry);for(let a of r){let l=j.resolve(t,a.path),c=j.dirname(l);n.add(c)}let s=ct.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,j.join(t,e.outDir)]}),o=!1,i=async(a=!1)=>{if(o)return;o=!0;try{let l=performance.now();if(await N({...e,entry:r.map((c)=>c.path),clean:!1},t),e.onBuildSuccess?.(),!a)u.cli(`\uD83D\uDCE6 Rebuild finished in ${S(performance.now()-l)}`);await Q()}catch(l){q(l)}finally{o=!1}};s.on("change",(a)=>{let l=j.relative(t,a);u.cli(`File changed: ${l}`,{muted:!0}),i()}),s.on("error",(a)=>{throw new v(`Watcher error: ${h(a)}`)}),await i(!0)}async function ft(e=Bun.argv.slice(2)){let t=Me(e);U(t.silent);let n=process.cwd(),{config:r,filepath:s}=await ut({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Re(r,n);if(u.cli(`Using bunup v${k} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${b(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:c,rootDir:m})=>{return te(c).map(async(p)=>{let F={...Te,...p,...t};return mt(F,m)})}));let a=performance.now()-i,l=S(a);if(u.cli(`\u26A1\uFE0F Build completed in ${l}`),await Q(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Q(){if($.size>0)await we($),$.clear()}async function mt(e,t){if(e.watch)await De(e,t);else await N(e,t),e.onBuildSuccess?.()}ft().catch((e)=>Z(e));export{Q as validateDtsFiles,ft as main};
package/build/index.d.mts CHANGED
@@ -1,221 +1,13 @@
1
1
  import _Bun from "bun";
2
2
 
3
3
  //#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
4
- /**
5
- * Entry point files for TypeScript declaration file generation
6
- *
7
- * This can be:
8
- * - A string path to a file
9
- * - An array of file paths
10
- * - An object where keys are output names and values are input file paths
11
- *
12
- * The key names are used for the generated declaration files.
13
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
14
- *
15
- * If not specified, the main entry points will be used for declaration file generation.
16
- *
17
- * If it's a string or an array of strings, the file name (without extension)
18
- * will be used as the name for the output declaration file.
19
- *
20
- * @example
21
- * // Using a string path
22
- * entry: 'src/index.ts' // Generates index.d.ts
23
- *
24
- * // Using string paths in an array
25
- * entry: ['src/index.ts'] // Generates index.d.ts
26
- *
27
- * // Using named outputs as an object
28
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
29
- */
30
4
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
31
- /**
32
- * Entry point files for TypeScript declaration file generation
33
- *
34
- * This can be:
35
- * - A string path to a file
36
- * - An array of file paths
37
- * - An object where keys are output names and values are input file paths
38
- *
39
- * The key names are used for the generated declaration files.
40
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
41
- *
42
- * If not specified, the main entry points will be used for declaration file generation.
43
- *
44
- * If it's a string or an array of strings, the file name (without extension)
45
- * will be used as the name for the output declaration file.
46
- *
47
- * @example
48
- * // Using a string path
49
- * entry: 'src/index.ts' // Generates index.d.ts
50
- *
51
- * // Using string paths in an array
52
- * entry: ['src/index.ts'] // Generates index.d.ts
53
- *
54
- * // Using named outputs as an object
55
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
56
- */
57
5
  type Define = BunBuildOptions["define"];
58
- /**
59
- * Entry point files for TypeScript declaration file generation
60
- *
61
- * This can be:
62
- * - A string path to a file
63
- * - An array of file paths
64
- * - An object where keys are output names and values are input file paths
65
- *
66
- * The key names are used for the generated declaration files.
67
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
68
- *
69
- * If not specified, the main entry points will be used for declaration file generation.
70
- *
71
- * If it's a string or an array of strings, the file name (without extension)
72
- * will be used as the name for the output declaration file.
73
- *
74
- * @example
75
- * // Using a string path
76
- * entry: 'src/index.ts' // Generates index.d.ts
77
- *
78
- * // Using string paths in an array
79
- * entry: ['src/index.ts'] // Generates index.d.ts
80
- *
81
- * // Using named outputs as an object
82
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
83
- */
84
6
  type Sourcemap = BunBuildOptions["sourcemap"];
85
- /**
86
- * Entry point files for TypeScript declaration file generation
87
- *
88
- * This can be:
89
- * - A string path to a file
90
- * - An array of file paths
91
- * - An object where keys are output names and values are input file paths
92
- *
93
- * The key names are used for the generated declaration files.
94
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
95
- *
96
- * If not specified, the main entry points will be used for declaration file generation.
97
- *
98
- * If it's a string or an array of strings, the file name (without extension)
99
- * will be used as the name for the output declaration file.
100
- *
101
- * @example
102
- * // Using a string path
103
- * entry: 'src/index.ts' // Generates index.d.ts
104
- *
105
- * // Using string paths in an array
106
- * entry: ['src/index.ts'] // Generates index.d.ts
107
- *
108
- * // Using named outputs as an object
109
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
110
- */
111
7
  type Format = Exclude<BunBuildOptions["format"], undefined>;
112
- /**
113
- * Entry point files for TypeScript declaration file generation
114
- *
115
- * This can be:
116
- * - A string path to a file
117
- * - An array of file paths
118
- * - An object where keys are output names and values are input file paths
119
- *
120
- * The key names are used for the generated declaration files.
121
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
122
- *
123
- * If not specified, the main entry points will be used for declaration file generation.
124
- *
125
- * If it's a string or an array of strings, the file name (without extension)
126
- * will be used as the name for the output declaration file.
127
- *
128
- * @example
129
- * // Using a string path
130
- * entry: 'src/index.ts' // Generates index.d.ts
131
- *
132
- * // Using string paths in an array
133
- * entry: ['src/index.ts'] // Generates index.d.ts
134
- *
135
- * // Using named outputs as an object
136
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
137
- */
138
8
  type Target = BunBuildOptions["target"];
139
- /**
140
- * Entry point files for TypeScript declaration file generation
141
- *
142
- * This can be:
143
- * - A string path to a file
144
- * - An array of file paths
145
- * - An object where keys are output names and values are input file paths
146
- *
147
- * The key names are used for the generated declaration files.
148
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
149
- *
150
- * If not specified, the main entry points will be used for declaration file generation.
151
- *
152
- * If it's a string or an array of strings, the file name (without extension)
153
- * will be used as the name for the output declaration file.
154
- *
155
- * @example
156
- * // Using a string path
157
- * entry: 'src/index.ts' // Generates index.d.ts
158
- *
159
- * // Using string paths in an array
160
- * entry: ['src/index.ts'] // Generates index.d.ts
161
- *
162
- * // Using named outputs as an object
163
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
164
- */
165
9
  type External = (string | RegExp)[];
166
- /**
167
- * Entry point files for TypeScript declaration file generation
168
- *
169
- * This can be:
170
- * - A string path to a file
171
- * - An array of file paths
172
- * - An object where keys are output names and values are input file paths
173
- *
174
- * The key names are used for the generated declaration files.
175
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
176
- *
177
- * If not specified, the main entry points will be used for declaration file generation.
178
- *
179
- * If it's a string or an array of strings, the file name (without extension)
180
- * will be used as the name for the output declaration file.
181
- *
182
- * @example
183
- * // Using a string path
184
- * entry: 'src/index.ts' // Generates index.d.ts
185
- *
186
- * // Using string paths in an array
187
- * entry: ['src/index.ts'] // Generates index.d.ts
188
- *
189
- * // Using named outputs as an object
190
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
191
- */
192
10
  type Entry = Arrayable<string> | Record<string, string>;
193
- /**
194
- * Entry point files for TypeScript declaration file generation
195
- *
196
- * This can be:
197
- * - A string path to a file
198
- * - An array of file paths
199
- * - An object where keys are output names and values are input file paths
200
- *
201
- * The key names are used for the generated declaration files.
202
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
203
- *
204
- * If not specified, the main entry points will be used for declaration file generation.
205
- *
206
- * If it's a string or an array of strings, the file name (without extension)
207
- * will be used as the name for the output declaration file.
208
- *
209
- * @example
210
- * // Using a string path
211
- * entry: 'src/index.ts' // Generates index.d.ts
212
- *
213
- * // Using string paths in an array
214
- * entry: ['src/index.ts'] // Generates index.d.ts
215
- *
216
- * // Using named outputs as an object
217
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
218
- */
219
11
  type DtsOptions = {
220
12
  /**
221
13
  * Entry point files for TypeScript declaration file generation
@@ -249,11 +41,7 @@ type DtsOptions = {
249
41
  */
250
42
  resolve?: boolean | (string | RegExp)[]
251
43
  };
252
- /**
253
- * Name of the build configuration
254
- * Used for logging and identification purposes
255
- */
256
- interface BunupOptions {
44
+ interface BuildOptions {
257
45
  /**
258
46
  * Name of the build configuration
259
47
  * Used for logging and identification purposes
@@ -331,6 +119,21 @@ interface BunupOptions {
331
119
  */
332
120
  dts?: boolean | DtsOptions;
333
121
  /**
122
+ * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
123
+ * When set to true, bunup will skip the JavaScript bundling process entirely
124
+ * and only generate declaration files for the specified entry points
125
+ *
126
+ * This is useful when you want to use bunup's fast declaration file generation
127
+ * but handle the JavaScript bundling separately or not at all.
128
+ *
129
+ * Note: When this option is true, the `dts` option is implicitly set to true
130
+ * and other bundling-related options are ignored.
131
+ *
132
+ * @example
133
+ * dtsOnly: true
134
+ */
135
+ dtsOnly?: boolean;
136
+ /**
334
137
  * Path to a preferred tsconfig.json file to use for declaration generation
335
138
  *
336
139
  * If not specified, the tsconfig.json in the project root will be used.
@@ -447,6 +250,12 @@ interface BunupOptions {
447
250
  * @default false
448
251
  */
449
252
  bytecode?: boolean;
253
+ /**
254
+ * Disable logging during the build process. When set to true, no logs will be printed to the console.
255
+ *
256
+ * @default false
257
+ */
258
+ silent?: boolean;
450
259
  }
451
260
 
452
261
  //#endregion
@@ -459,21 +268,21 @@ type WithOptional<
459
268
  type Arrayable<T> = T | T[];
460
269
  type Bun = typeof _Bun;
461
270
  type BunBuildOptions = Parameters<Bun["build"]>[0];
462
- type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
463
- type DefineWorkspaceEntry = {
271
+ type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
272
+ type DefineWorkspaceItem = {
464
273
  name: string
465
274
  root: string
466
- config: DefineConfigEntry | DefineConfigEntry[]
275
+ config: DefineConfigItem | DefineConfigItem[]
467
276
  };
468
277
 
469
278
  //#endregion
470
279
  //#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
471
- declare function defineConfig(options: Arrayable<DefineConfigEntry>): Arrayable<DefineConfigEntry>;
472
- declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
280
+ declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
281
+ declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
473
282
 
474
283
  //#endregion
475
284
  //#region \0dts:/home/runner/work/bunup/bunup/src/build.d.ts
476
- declare function build(options: BunupOptions, rootDir: string): Promise<void>;
285
+ declare function build(options: BuildOptions, rootDir: string): Promise<void>;
477
286
 
478
287
  //#endregion
479
- export { DefineConfigEntry, DefineWorkspaceEntry, build, defineConfig, defineWorkspace };
288
+ export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, build, defineConfig, defineWorkspace };
package/build/index.d.ts CHANGED
@@ -1,221 +1,13 @@
1
1
  import _Bun from "bun";
2
2
 
3
3
  //#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
4
- /**
5
- * Entry point files for TypeScript declaration file generation
6
- *
7
- * This can be:
8
- * - A string path to a file
9
- * - An array of file paths
10
- * - An object where keys are output names and values are input file paths
11
- *
12
- * The key names are used for the generated declaration files.
13
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
14
- *
15
- * If not specified, the main entry points will be used for declaration file generation.
16
- *
17
- * If it's a string or an array of strings, the file name (without extension)
18
- * will be used as the name for the output declaration file.
19
- *
20
- * @example
21
- * // Using a string path
22
- * entry: 'src/index.ts' // Generates index.d.ts
23
- *
24
- * // Using string paths in an array
25
- * entry: ['src/index.ts'] // Generates index.d.ts
26
- *
27
- * // Using named outputs as an object
28
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
29
- */
30
4
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
31
- /**
32
- * Entry point files for TypeScript declaration file generation
33
- *
34
- * This can be:
35
- * - A string path to a file
36
- * - An array of file paths
37
- * - An object where keys are output names and values are input file paths
38
- *
39
- * The key names are used for the generated declaration files.
40
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
41
- *
42
- * If not specified, the main entry points will be used for declaration file generation.
43
- *
44
- * If it's a string or an array of strings, the file name (without extension)
45
- * will be used as the name for the output declaration file.
46
- *
47
- * @example
48
- * // Using a string path
49
- * entry: 'src/index.ts' // Generates index.d.ts
50
- *
51
- * // Using string paths in an array
52
- * entry: ['src/index.ts'] // Generates index.d.ts
53
- *
54
- * // Using named outputs as an object
55
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
56
- */
57
5
  type Define = BunBuildOptions["define"];
58
- /**
59
- * Entry point files for TypeScript declaration file generation
60
- *
61
- * This can be:
62
- * - A string path to a file
63
- * - An array of file paths
64
- * - An object where keys are output names and values are input file paths
65
- *
66
- * The key names are used for the generated declaration files.
67
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
68
- *
69
- * If not specified, the main entry points will be used for declaration file generation.
70
- *
71
- * If it's a string or an array of strings, the file name (without extension)
72
- * will be used as the name for the output declaration file.
73
- *
74
- * @example
75
- * // Using a string path
76
- * entry: 'src/index.ts' // Generates index.d.ts
77
- *
78
- * // Using string paths in an array
79
- * entry: ['src/index.ts'] // Generates index.d.ts
80
- *
81
- * // Using named outputs as an object
82
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
83
- */
84
6
  type Sourcemap = BunBuildOptions["sourcemap"];
85
- /**
86
- * Entry point files for TypeScript declaration file generation
87
- *
88
- * This can be:
89
- * - A string path to a file
90
- * - An array of file paths
91
- * - An object where keys are output names and values are input file paths
92
- *
93
- * The key names are used for the generated declaration files.
94
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
95
- *
96
- * If not specified, the main entry points will be used for declaration file generation.
97
- *
98
- * If it's a string or an array of strings, the file name (without extension)
99
- * will be used as the name for the output declaration file.
100
- *
101
- * @example
102
- * // Using a string path
103
- * entry: 'src/index.ts' // Generates index.d.ts
104
- *
105
- * // Using string paths in an array
106
- * entry: ['src/index.ts'] // Generates index.d.ts
107
- *
108
- * // Using named outputs as an object
109
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
110
- */
111
7
  type Format = Exclude<BunBuildOptions["format"], undefined>;
112
- /**
113
- * Entry point files for TypeScript declaration file generation
114
- *
115
- * This can be:
116
- * - A string path to a file
117
- * - An array of file paths
118
- * - An object where keys are output names and values are input file paths
119
- *
120
- * The key names are used for the generated declaration files.
121
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
122
- *
123
- * If not specified, the main entry points will be used for declaration file generation.
124
- *
125
- * If it's a string or an array of strings, the file name (without extension)
126
- * will be used as the name for the output declaration file.
127
- *
128
- * @example
129
- * // Using a string path
130
- * entry: 'src/index.ts' // Generates index.d.ts
131
- *
132
- * // Using string paths in an array
133
- * entry: ['src/index.ts'] // Generates index.d.ts
134
- *
135
- * // Using named outputs as an object
136
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
137
- */
138
8
  type Target = BunBuildOptions["target"];
139
- /**
140
- * Entry point files for TypeScript declaration file generation
141
- *
142
- * This can be:
143
- * - A string path to a file
144
- * - An array of file paths
145
- * - An object where keys are output names and values are input file paths
146
- *
147
- * The key names are used for the generated declaration files.
148
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
149
- *
150
- * If not specified, the main entry points will be used for declaration file generation.
151
- *
152
- * If it's a string or an array of strings, the file name (without extension)
153
- * will be used as the name for the output declaration file.
154
- *
155
- * @example
156
- * // Using a string path
157
- * entry: 'src/index.ts' // Generates index.d.ts
158
- *
159
- * // Using string paths in an array
160
- * entry: ['src/index.ts'] // Generates index.d.ts
161
- *
162
- * // Using named outputs as an object
163
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
164
- */
165
9
  type External = (string | RegExp)[];
166
- /**
167
- * Entry point files for TypeScript declaration file generation
168
- *
169
- * This can be:
170
- * - A string path to a file
171
- * - An array of file paths
172
- * - An object where keys are output names and values are input file paths
173
- *
174
- * The key names are used for the generated declaration files.
175
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
176
- *
177
- * If not specified, the main entry points will be used for declaration file generation.
178
- *
179
- * If it's a string or an array of strings, the file name (without extension)
180
- * will be used as the name for the output declaration file.
181
- *
182
- * @example
183
- * // Using a string path
184
- * entry: 'src/index.ts' // Generates index.d.ts
185
- *
186
- * // Using string paths in an array
187
- * entry: ['src/index.ts'] // Generates index.d.ts
188
- *
189
- * // Using named outputs as an object
190
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
191
- */
192
10
  type Entry = Arrayable<string> | Record<string, string>;
193
- /**
194
- * Entry point files for TypeScript declaration file generation
195
- *
196
- * This can be:
197
- * - A string path to a file
198
- * - An array of file paths
199
- * - An object where keys are output names and values are input file paths
200
- *
201
- * The key names are used for the generated declaration files.
202
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
203
- *
204
- * If not specified, the main entry points will be used for declaration file generation.
205
- *
206
- * If it's a string or an array of strings, the file name (without extension)
207
- * will be used as the name for the output declaration file.
208
- *
209
- * @example
210
- * // Using a string path
211
- * entry: 'src/index.ts' // Generates index.d.ts
212
- *
213
- * // Using string paths in an array
214
- * entry: ['src/index.ts'] // Generates index.d.ts
215
- *
216
- * // Using named outputs as an object
217
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
218
- */
219
11
  type DtsOptions = {
220
12
  /**
221
13
  * Entry point files for TypeScript declaration file generation
@@ -249,11 +41,7 @@ type DtsOptions = {
249
41
  */
250
42
  resolve?: boolean | (string | RegExp)[]
251
43
  };
252
- /**
253
- * Name of the build configuration
254
- * Used for logging and identification purposes
255
- */
256
- interface BunupOptions {
44
+ interface BuildOptions {
257
45
  /**
258
46
  * Name of the build configuration
259
47
  * Used for logging and identification purposes
@@ -331,6 +119,21 @@ interface BunupOptions {
331
119
  */
332
120
  dts?: boolean | DtsOptions;
333
121
  /**
122
+ * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
123
+ * When set to true, bunup will skip the JavaScript bundling process entirely
124
+ * and only generate declaration files for the specified entry points
125
+ *
126
+ * This is useful when you want to use bunup's fast declaration file generation
127
+ * but handle the JavaScript bundling separately or not at all.
128
+ *
129
+ * Note: When this option is true, the `dts` option is implicitly set to true
130
+ * and other bundling-related options are ignored.
131
+ *
132
+ * @example
133
+ * dtsOnly: true
134
+ */
135
+ dtsOnly?: boolean;
136
+ /**
334
137
  * Path to a preferred tsconfig.json file to use for declaration generation
335
138
  *
336
139
  * If not specified, the tsconfig.json in the project root will be used.
@@ -447,6 +250,12 @@ interface BunupOptions {
447
250
  * @default false
448
251
  */
449
252
  bytecode?: boolean;
253
+ /**
254
+ * Disable logging during the build process. When set to true, no logs will be printed to the console.
255
+ *
256
+ * @default false
257
+ */
258
+ silent?: boolean;
450
259
  }
451
260
 
452
261
  //#endregion
@@ -459,21 +268,21 @@ type WithOptional<
459
268
  type Arrayable<T> = T | T[];
460
269
  type Bun = typeof _Bun;
461
270
  type BunBuildOptions = Parameters<Bun["build"]>[0];
462
- type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
463
- type DefineWorkspaceEntry = {
271
+ type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
272
+ type DefineWorkspaceItem = {
464
273
  name: string
465
274
  root: string
466
- config: DefineConfigEntry | DefineConfigEntry[]
275
+ config: DefineConfigItem | DefineConfigItem[]
467
276
  };
468
277
 
469
278
  //#endregion
470
279
  //#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
471
- declare function defineConfig(options: Arrayable<DefineConfigEntry>): Arrayable<DefineConfigEntry>;
472
- declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
280
+ declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
281
+ declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
473
282
 
474
283
  //#endregion
475
284
  //#region \0dts:/home/runner/work/bunup/bunup/src/build.d.ts
476
- declare function build(options: BunupOptions, rootDir: string): Promise<void>;
285
+ declare function build(options: BuildOptions, rootDir: string): Promise<void>;
477
286
 
478
287
  //#endregion
479
- export { DefineConfigEntry, DefineWorkspaceEntry, build, defineConfig, defineWorkspace };
288
+ export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, build, defineConfig, defineWorkspace };
package/build/index.js CHANGED
@@ -1,15 +1,15 @@
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({dtsInput:!0})],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.
1
+ var Ot=require("node:module");var Bt=Object.create;var{getPrototypeOf:It,defineProperty:$,getOwnPropertyNames:j,getOwnPropertyDescriptor:Lt}=Object,G=Object.prototype.hasOwnProperty;var h=(t,e,n)=>{n=t!=null?Bt(It(t)):{};let r=e||!t||!t.__esModule?$(n,"default",{value:t,enumerable:!0}):n;for(let s of j(t))if(!G.call(r,s))$(r,s,{get:()=>t[s],enumerable:!0});return r},V=new WeakMap,St=(t)=>{var e=V.get(t),n;if(e)return e;if(e=$({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((r)=>!G.call(e,r)&&$(e,r,{get:()=>t[r],enumerable:!(n=Lt(t,r))||n.enumerable}));return V.set(t,e),e};var At=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Kt={};At(Kt,{defineWorkspace:()=>X,defineConfig:()=>q,build:()=>Pt});module.exports=St(Kt);function q(t){return t}function X(t){return t}var lt=require("rolldown"),ut=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends S{constructor(t){super(t);this.name="BunupBuildError"}}class d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};var A=h(require("node:fs/promises")),H=h(require("node:path"));function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function K(t,e){switch(t){case"esm":return".mjs";case"cjs":return P(e)?".cjs":".js";case"iife":return".global.js"}}function Y(t,e){switch(t){case"esm":return".d.mts";case"cjs":return P(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function P(t){return t==="module"}function Q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Z(t,e){return t===void 0?e==="esm":t}function _(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function E(t,e=3){return t.split("/").slice(-e).join("/")}async function z(t,e){let n=H.default.join(t,e);try{await A.default.rm(n,{recursive:!0,force:!0})}catch(r){throw new b(`Failed to clean output directory: ${r}`)}await A.default.mkdir(n,{recursive:!0})}function J(t,e){return e==="cjs"?t:void 0}function tt(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function D(t,e){return tt(t.external||[]).concat(Q(e).map((n)=>new RegExp(`^${O(n)}($|\\/|\\\\)`)))}function M(t){return tt(t.noExternal||[])}var ot=h(require("node:path")),at=require("oxc-resolver");var x=h(require("node:path"));var C="\x00dts:",et=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(N(r))return r;if(!s||!N(s))return null;let o=await T(r,e,n,y(s));if(!o)return null;let i=w(o);if(t.has(i))return B(i);return null},load(r){if(r.startsWith(C)){let s=y(r),o=t.get(s);if(o)return nt.add(s),o}return null}}};function rt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function W(t){let e=x.default.dirname(t.path||""),n=rt(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function st(t){let e=new Map,n=rt(t)?.paths;if(!n)return e;let r=W(t);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");e.set(`^${i}$`,x.default.join(r,a))}return e}function _t(t,e,n){for(let[r,s]of e){let o=new RegExp(r),i=t.match(o);if(i)return s.replace("$1",i[1]||"")}return n?x.default.join(n,t):null}async function Nt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function T(t,e,n,r){let s=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):_t(t,e,n);if(!s)return Promise.resolve(null);return Nt(s)}function N(t){return t.startsWith(C)}function y(t){return t.replace(C,"")}function B(t){return`${C}${t}`}var it;function ct(t){return{name:"bunup:types-resolve",buildStart(){it||=new at.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?y(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let s=r?ot.default.dirname(r):process.cwd(),{path:o}=await it.async(s,e);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function ft(t,e,n,r,s,o){let i=w(t),a=B(i),c=D(n,r),u=M(n);try{let{output:f}=await lt.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[et(e,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&ct(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ut.dts({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${p(f)}`)}}var gt=!1;function mt(t){gt=t??!1}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!R.instance)R.instance=new R;return R.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:e,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...f]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${a}${c}`}output(t,e={},n=console.log){if(gt)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let s=String(t),o=this.colors.default,i,a,c={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,c=n;for(let[f,l]of Object.entries(this.colors.progress))if(s.includes(f)){o=l;break}let u=this.formatMessage({colorCode:o,label:s,message:e,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var g=R.getInstance();var Wt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ut=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Vt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function qt(t){let e=new Set,n=[Wt,Ut,vt,Ft,Vt,jt,Gt];for(let r of n){let s=t.matchAll(r);for(let o of s)if(o[1])e.add(o[1])}return e}async function dt(t,e,n){let r=new Set([t]),s=[t];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=qt(i);for(let c of a){let u=await T(c,e,n,o);if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){g.warn(`Error processing ${o}: ${p(i)}`)}}return r}var pt=require("oxc-transform");async function xt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=w(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=pt.isolatedDeclaration(n,o);if(i)e.set(r,i)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}var U=h(require("node:fs/promises")),I=h(require("node:path")),Xt=require("oxc-transform");async function ht(t,e){let n=I.default.resolve(t),r=I.default.resolve(n,e);if(!await U.default.exists(n))throw new d(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(I.default.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function bt(t,e,n,r,s){let{absoluteEntry:o}=await ht(t,e),i=st(r),a=W(r),c=await dt(o,i,a),u=await xt(c);return ft(o,u,n,s,i,a)}function Et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=k(),u=`${i}_${c}`;if(e)g.warn(`Output name conflict: "${i}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
- ${r[s]} -> ${s}.js
5
- ${o} -> ${c}.js (auto-renamed to avoid conflict)
4
+ ${s[i]} -> ${i}.js
5
+ ${a} -> ${u}.js (auto-renamed to avoid conflict)
6
6
 
7
7
  To fix this, use named entries in your configuration:
8
8
  {
9
9
  entry: {
10
- custom_name: "${r[s]}",
11
- another_name: "${o}"
10
+ custom_name: "${s[i]}",
11
+ another_name: "${a}"
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}),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)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(t))for(let i of t){let a=Et(i);o(a,i)}else if(typeof t==="object")for(let[i,a]of Object.entries(t))o(i,a);else{let i=Et(t);o(i,t)}return n}function wt(t,e){return`[dir]/${t}${e}`}var F=require("coffi");async function Rt(t){let{config:e,filepath:n}=await F.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function $t(t,e){let{config:n,filepath:r}=await F.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function yt(t,e){return{outdir:`${e}/${t.outDir}`,minify:Ht(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function Ht(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Ct(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(t.some((i)=>i.test(s))&&!e.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var nt=new Set;async function Pt(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)z(e,t.outDir);mt(t.silent);let{packageJson:n,path:r}=await Rt(e);if(n&&r)g.cli(`Using package.json: ${E(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let s=v(t.entry),o=n?.type,i=D(t,n),a=M(t);if(!t.dtsOnly){let c=[Ct(i,a)],u=yt(t,e),f=t.format.flatMap((l)=>s.map((m)=>{return kt(t,e,m,l,o,c,u)}));await Promise.all(f)}if(t.dts||t.dtsOnly){let c=await $t(e,t.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,identifier:t.name,once:`${c.path}:${t.name}`});let u=t.format.filter((l)=>{if(l==="iife"&&!P(o)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?v(t.dts.entry):s;try{await Promise.all(f.map(async(l)=>{let m=await bt(e,l.path,t,c,n);await Promise.all(u.map(async(Dt)=>{let Mt=Y(Dt,o),L=`${e}/${t.outDir}/${l.name}${Mt}`;await Bun.write(L,m);let Tt=Bun.file(L).size||0;g.progress("DTS",E(L),_(Tt),t.name)}))}))}catch(l){throw new d(p(l))}}}async function kt(t,e,n,r,s,o,i){let a=K(r,s),c=await Bun.build({...i,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:wt(n.name,a)},splitting:Z(t.splitting,r),bytecode:J(t.bytecode,r),plugins:o,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new b(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(u).size||0;g.progress(r.toUpperCase(),E(u),_(f),t.name)}
package/build/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- function 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({dtsInput:!0})],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.
1
+ function pt(t){return t}function xt(t){return t}import{build as $t}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class B extends Error{constructor(t){super(t);this.name="BunupError"}}class x extends B{constructor(t){super(t);this.name="BunupBuildError"}}class d extends B{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import N from"node:fs/promises";import ht from"node:path";function I(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function U(t,e){switch(t){case"esm":return".mjs";case"cjs":return y(e)?".cjs":".js";case"iife":return".global.js"}}function v(t,e){switch(t){case"esm":return".d.mts";case"cjs":return y(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function y(t){return t==="module"}function F(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,e){return t===void 0?e==="esm":t}function L(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function h(t,e=3){return t.split("/").slice(-e).join("/")}async function j(t,e){let n=ht.join(t,e);try{await N.rm(n,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await N.mkdir(n,{recursive:!0})}function G(t,e){return e==="cjs"?t:void 0}function q(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${I(e)}($|\\/|\\\\)`):e)}function C(t,e){return q(t.external||[]).concat(F(e).map((n)=>new RegExp(`^${I(n)}($|\\/|\\\\)`)))}function P(t){return q(t.noExternal||[])}import wt from"node:path";import{ResolverFactory as Rt}from"oxc-resolver";import E from"node:path";var $="\x00dts:",X=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,o){if(S(r))return r;if(!o||!S(o))return null;let i=await D(r,e,n,R(o));if(!i)return null;let s=b(i);if(t.has(s))return M(s);return null},load(r){if(r.startsWith($)){let o=R(r),i=t.get(o);if(i)return H.add(o),i}return null}}};function k(t){return t.tsconfig?.compilerOptions}function b(t){return t.replace(/\.tsx?$/,".d.ts")}function A(t){let e=E.dirname(t.path||""),n=k(t);return n?.baseUrl?E.resolve(e,n.baseUrl):e}function K(t){let e=new Map,n=k(t)?.paths;if(!n)return e;let r=A(t);for(let[o,i]of Object.entries(n))if(Array.isArray(i)&&i.length){let s=o.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");e.set(`^${s}$`,E.join(r,a))}return e}function bt(t,e,n){for(let[r,o]of e){let i=new RegExp(r),s=t.match(i);if(s)return o.replace("$1",s[1]||"")}return n?E.join(n,t):null}async function Et(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function D(t,e,n,r){let o=t.startsWith(".")?E.resolve(E.dirname(r||""),t):bt(t,e,n);if(!o)return Promise.resolve(null);return Et(o)}function S(t){return t.startsWith($)}function R(t){return t.replace($,"")}function M(t){return`${$}${t}`}var Y;function Q(t){return{name:"bunup:types-resolve",buildStart(){Y||=new Rt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?R(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let o=r?wt.dirname(r):process.cwd(),{path:i}=await Y.async(o,e);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function Z(t,e,n,r,o,i){let s=b(t),a=M(s),c=C(n,r),u=P(n);try{let{output:f}=await $t({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[X(e,o,i),typeof n.dts==="object"&&"resolve"in n.dts&&Q(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),yt({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${p(f)}`)}}var z=!1;function J(t){z=t??!1}class w{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!w.instance)w.instance=new w;return w.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:e,message:n,size:r,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=i?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...f]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},n=console.log){if(z)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let o=String(t),i=this.colors.default,s,a,c={};if(typeof n==="string")s=n,a=r;else if(n)s=n.size,a=n.identifier,c=n;for(let[f,l]of Object.entries(this.colors.progress))if(o.includes(f)){i=l;break}let u=this.formatMessage({colorCode:i,label:o,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var g=w.getInstance();var Ct=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Pt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Dt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Tt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,It=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Lt(t){let e=new Set,n=[Ct,Pt,Dt,Mt,Tt,Bt,It];for(let r of n){let o=t.matchAll(r);for(let i of o)if(i[1])e.add(i[1])}return e}async function tt(t,e,n){let r=new Set([t]),o=[t];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=Lt(s);for(let c of a){let u=await D(c,e,n,i);if(!u)continue;if(!r.has(u))r.add(u),o.push(u)}}catch(s){g.warn(`Error processing ${i}: ${p(s)}`)}}return r}import{isolatedDeclaration as St}from"oxc-transform";async function et(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=b(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:s}=St(n,i);if(s)e.set(r,s)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}import nt from"node:fs/promises";import O from"node:path";import{isolatedDeclaration as Re}from"oxc-transform";async function rt(t,e){let n=O.resolve(t),r=O.resolve(n,e);if(!await nt.exists(n))throw new d(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(O.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function st(t,e,n,r,o){let{absoluteEntry:i}=await rt(t,e),s=K(r),a=A(r),c=await tt(i,s,a),u=await et(c);return Z(i,u,n,o,s,a)}function it(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function _(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,o={};function i(s,a){if(r.has(s)){let c=W(),u=`${s}_${c}`;if(e)g.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
- ${r[s]} -> ${s}.js
5
- ${o} -> ${c}.js (auto-renamed to avoid conflict)
4
+ ${o[s]} -> ${s}.js
5
+ ${a} -> ${u}.js (auto-renamed to avoid conflict)
6
6
 
7
7
  To fix this, use named entries in your configuration:
8
8
  {
9
9
  entry: {
10
- custom_name: "${r[s]}",
11
- another_name: "${o}"
10
+ custom_name: "${o[s]}",
11
+ another_name: "${a}"
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}),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};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:u,path:a})}else n.push({name:s,path:a}),r.add(s),o[s]=a}if(Array.isArray(t))for(let s of t){let a=it(s);i(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))i(s,a);else{let s=it(t);i(s,t)}return n}function ot(t,e){return`[dir]/${t}${e}`}import{loadConfig as at}from"coffi";async function ct(t){let{config:e,filepath:n}=await at({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function lt(t,e){let{config:n,filepath:r}=await at({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function ut(t,e){return{outdir:`${e}/${t.outDir}`,minify:At(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function At(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:o}=t,i=e===!0;return{whitespace:n??i,identifiers:r??i,syntax:o??i}}function ft(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let o=r.path;if(t.some((s)=>s.test(o))&&!e.some((s)=>s.test(o)))return{path:o,external:!0};return null})}}}var H=new Set;async function Ot(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)j(e,t.outDir);J(t.silent);let{packageJson:n,path:r}=await ct(e);if(n&&r)g.cli(`Using package.json: ${h(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let o=_(t.entry),i=n?.type,s=C(t,n),a=P(t);if(!t.dtsOnly){let c=[ft(s,a)],u=ut(t,e),f=t.format.flatMap((l)=>o.map((m)=>{return _t(t,e,m,l,i,c,u)}));await Promise.all(f)}if(t.dts||t.dtsOnly){let c=await lt(e,t.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${h(c.path,2)}`,{muted:!0,identifier:t.name,once:`${c.path}:${t.name}`});let u=t.format.filter((l)=>{if(l==="iife"&&!y(i)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?_(t.dts.entry):o;try{await Promise.all(f.map(async(l)=>{let m=await st(e,l.path,t,c,n);await Promise.all(u.map(async(gt)=>{let mt=v(gt,i),T=`${e}/${t.outDir}/${l.name}${mt}`;await Bun.write(T,m);let dt=Bun.file(T).size||0;g.progress("DTS",h(T),L(dt),t.name)}))}))}catch(l){throw new d(p(l))}}}async function _t(t,e,n,r,o,i,s){let a=U(r,o),c=await Bun.build({...s,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:ot(n.name,a)},splitting:V(t.splitting,r),bytecode:G(t.bytecode,r),plugins:i,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new x(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(u).size||0;g.progress(r.toUpperCase(),h(u),L(f),t.name)}export{xt as defineWorkspace,pt as defineConfig,Ot as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.88",
3
+ "version": "0.3.90",
4
4
  "description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -17,11 +17,10 @@
17
17
  "@commitlint/config-conventional": "^19.5.0",
18
18
  "@types/bun": "^1.2.5",
19
19
  "bumpp": "^10.1.0",
20
- "bunup": "^0.3.73",
20
+ "bunup": "^0.3.89",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "vitest": "^2.1.9",
24
- "create-bunup": "0.3.88"
23
+ "create-bunup": "0.3.90"
25
24
  },
26
25
  "peerDependencies": {
27
26
  "typescript": ">=4.5.0"
@@ -65,7 +64,7 @@
65
64
  "create-bunup": "create-bunup",
66
65
  "dev:docs": "pnpm -C docs dev",
67
66
  "test-build": "pnpm -C tests build",
68
- "test": "vitest run",
67
+ "test": "bun test",
69
68
  "lint": "biome check .",
70
69
  "lint:fix": "biome check --write .",
71
70
  "format": "biome format .",