bunup 0.3.14 → 0.3.16

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
@@ -7,10 +7,10 @@ An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by [
7
7
 
8
8
  | Bundler | Format | Build Time | Build Time (with dts) |
9
9
  | ------- | -------- | -------------- | --------------------- |
10
- | bunup | esm, cjs | **0.86ms ⚡️** | **7.54ms ⚡️** |
11
- | tsdown | esm, cjs | 3.57ms | 15.73ms |
12
- | unbuild | esm, cjs | 12.79ms | 252.01ms |
13
- | tsup | esm, cjs | 10.53ms | 665.55ms |
10
+ | bunup | esm, cjs | **0.86ms ⚡️** | **5.44ms ⚡️** |
11
+ | tsdown | esm, cjs | 3.85ms | 11.03ms |
12
+ | unbuild | esm, cjs | 12.90ms | 252.92ms |
13
+ | tsup | esm, cjs | 10.99ms | 671.39ms |
14
14
 
15
15
  _Lower build time is better. Benchmark run on the same code with identical output formats._
16
16
 
package/build/cli.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{rollup as Dn}from"rollup";import Hn from"rollup-plugin-dts";import I from"typescript";class C extends Error{constructor(n){super(n);this.name="BunupError"}}class y extends C{constructor(n){super(n);this.name="BunupBuildError"}}class d extends C{constructor(n){super(n);this.name="BunupDTSBuildError"}}class h extends C{constructor(n){super(n);this.name="BunupCLIError"}}class j extends C{constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},Tn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof y)s="BUILD ERROR";else if(n instanceof d)s="DTS ERROR";else if(n instanceof h)s="CLI ERROR";else if(n instanceof j)s="WATCH ERROR";else if(n instanceof C)s="BUNUP ERROR";if(console.error(`\x1B[31m${s}\x1B[0m ${r}${e}`),n instanceof Error&&n.stack)console.error("\x1B[2m"+n.stack.split(`
3
+ import{rolldown as Ln}from"rolldown";import{dts as Hn}from"rolldown-plugin-dts";class $ extends Error{constructor(n){super(n);this.name="BunupError"}}class x extends ${constructor(n){super(n);this.name="BunupBuildError"}}class d extends ${constructor(n){super(n);this.name="BunupDTSBuildError"}}class h extends ${constructor(n){super(n);this.name="BunupCLIError"}}class j extends ${constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},Sn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof x)s="BUILD ERROR";else if(n instanceof d)s="DTS ERROR";else if(n instanceof h)s="CLI ERROR";else if(n instanceof j)s="WATCH ERROR";else if(n instanceof $)s="BUNUP ERROR";if(console.error(`\x1B[31m${s}\x1B[0m ${r}${e}`),n instanceof Error&&n.stack)console.error("\x1B[2m"+n.stack.split(`
4
4
  `).slice(1).join(`
5
- `)+"\x1B[0m")},Z=(n,t)=>{Tn(n,t),process.exit(1)};import _ from"node:fs/promises";import Mn from"node:path";var E={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function z(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function Nn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function q(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X(n=8){return Math.random().toString(36).substring(2,2+n)}function F(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function V(n,t){switch(n){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function M(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function nn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function tn(n,t){return n===void 0?t==="esm":n}function P(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function w(n,t=3){return n.split("/").slice(-t).join("/")}async function J(n,t){let e=Mn.join(n,t);if(await _.exists(e))try{await _.rm(e,{recursive:!0})}catch(s){throw new y(`Failed to clean output directory: ${s}`)}await _.mkdir(e,{recursive:!0})}function Y(n){return n||E.outDir}function en(n){return n===void 0?E.clean:n}function rn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${q(t)}($|\\/|\\\\)`):t)}function k(n,t){return rn(n.external||[]).concat(nn(t).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function L(n){return rn(n.noExternal||[])}import kn from"node:path";import{ResolverFactory as Ln}from"oxc-resolver";import B from"path";var g="\x00virtual:",sn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(g))return t;if(!e?.startsWith(g)||!t.startsWith("."))return null;let r=e.slice(g.length),s=B.resolve(B.dirname(r),t);if(t==="."){let o=B.join(B.dirname(r),"index.d.ts");if(n.has(o))return`${g}${o}`;s=B.dirname(r)}if(n.has(s))return`${g}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${g}${i}`;if(t.startsWith(".")){let o=B.join(s,"index.d.ts");if(n.has(o))return`${g}${o}`}return null},load(t){if(t.startsWith(g)){let e=t.slice(g.length),r=n.get(e);if(r)return v.add(e),r}return null}}};var on;function an(n){return{name:"bunup:types-resolve",buildStart(){on||=new Ln({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?.replace(g,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?kn.dirname(e):process.cwd(),{path:s}=await on.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return s}}}async function cn(n,t,e,r,s){let i=n.replace(/\.tsx?$/,".d.ts"),o=`${g}${i}`,a=r.data?.compilerOptions,c=k(e,s),u=L(e),p;try{p=await Dn({input:o,onwarn(x,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;$(x)},plugins:[sn(t),typeof e.dts==="object"&&"resolve"in e.dts&&an(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Hn({tsconfig:r.path,compilerOptions:{...a?I.parseJsonConfigFileContent({compilerOptions:a},I.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:I.ScriptTarget.ESNext}})],external:(x)=>c.some(($)=>$.test(x))&&!u.some(($)=>$.test(x))});let{output:f}=await p.generate({});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${m(f)}`)}finally{if(p)await p.close()}}import R from"node:path";var l={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"},formatMessage({colorCode:n,label:t,message:e,size:r,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),x=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${x}`}let c=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`},output(n,t={},e=console.log){if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")},cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)},info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)},warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)},error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)},progress(n,t,e,r){let s=String(n),i=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[p,f]of Object.entries(this.colors.progress))if(s.includes(p)){i=f;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}};var Un=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Wn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ln(n,t){let e=new Set([n]),r=[n],s=qn(t),i=fn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await Bun.file(o).text(),c=Gn(a);for(let u of c){let p=u.startsWith(".")?R.resolve(R.dirname(o),u):Pn(u,s,i);if(!p)continue;let f=await _n(p);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return e}function Gn(n){let t=new Set;for(let e of[Un,Wn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}async function _n(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function fn(n){let t=R.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?R.resolve(t,n.data.compilerOptions.baseUrl):t}function qn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=fn(n);for(let[s,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");t.set(`^${o}$`,R.join(r,a))}return t}function Pn(n,t,e){for(let[r,s]of t){let i=new RegExp(r),o=n.match(i);if(o)return s.replace("$1",o[1]||"")}return e?R.join(e,n):null}import{isolatedDeclaration as Jn}from"oxc-transform";async function un(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Jn(e,i);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import mn from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as Yn}from"oxc-transform";async function pn(n,t){let e=K.resolve(n),r=K.resolve(e,t);if(!await mn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(K.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function gn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:i}=Yn(r,s);i.forEach((o)=>{if(!t)console.log(`
6
- `);let a=o.labels[0],c=a?In(s,a.start):"",p=`${w(r)}${c}: ${Kn(o.message)}`;l.warn(p),t=!0})}catch{}})),t)l.info(`
5
+ `)+"\x1B[0m")},z=(n,t)=>{Sn(n,t),process.exit(1)};import G from"node:fs/promises";import Tn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function K(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function Nn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function _(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(n=8){return Math.random().toString(36).substring(2,2+n)}function Z(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function X(n,t){switch(n){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function T(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function F(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function V(n,t){return n===void 0?t==="esm":n}function q(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function w(n,t=3){return n.split("/").slice(-t).join("/")}async function P(n,t){let e=Tn.join(n,t);if(await G.exists(e))try{await G.rm(e,{recursive:!0})}catch(s){throw new x(`Failed to clean output directory: ${s}`)}await G.mkdir(e,{recursive:!0})}function Y(n){return n||O.outDir}function nn(n){return n===void 0?O.clean:n}function tn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${_(t)}($|\\/|\\\\)`):t)}function M(n,t){return tn(n.external||[]).concat(F(t).map((e)=>new RegExp(`^${_(e)}($|\\/|\\\\)`)))}function k(n){return tn(n.noExternal||[])}import Mn from"node:path";import{ResolverFactory as kn}from"oxc-resolver";import C from"path";var p="\x00virtual:",en=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(p))return t;if(!e?.startsWith(p)||!t.startsWith("."))return null;let r=e.slice(p.length),s=C.resolve(C.dirname(r),t);if(t==="."){let o=C.join(C.dirname(r),"index.d.ts");if(n.has(o))return`${p}${o}`;s=C.dirname(r)}if(n.has(s))return`${p}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${p}${i}`;if(t.startsWith(".")){let o=C.join(s,"index.d.ts");if(n.has(o))return`${p}${o}`}return null},load(t){if(t.startsWith(p)){let e=t.slice(p.length),r=n.get(e);if(r)return B.add(e),r}return null}}};var rn;function sn(n){return{name:"bunup:types-resolve",buildStart(){rn||=new kn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?.replace(p,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?Mn.dirname(e):process.cwd(),{path:s}=await rn.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return s}}}async function on(n,t,e,r){let s=n.replace(/\.tsx?$/,".d.ts"),i=`${p}${s}`,o=M(e,r),a=k(e),c;try{c=await Ln({input:i,onwarn(g,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;f(g)},plugins:[en(t),typeof e.dts==="object"&&"resolve"in e.dts&&sn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Hn()],external:(g)=>o.some((f)=>f.test(g))&&!a.some((f)=>f.test(g))});let{output:u}=await c.generate({});if(!u[0]?.code)throw new d("Generated bundle is empty");return u[0].code}catch(u){throw new d(`DTS bundling failed: ${m(u)}`)}finally{if(c)await c.close()}}import E from"node:path";var l={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"},formatMessage({colorCode:n,label:t,message:e,size:r,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),R=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${R}`}let c=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`},output(n,t={},e=console.log){if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")},cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)},info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)},warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)},error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)},progress(n,t,e,r){let s=String(n),i=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,f]of Object.entries(this.colors.progress))if(s.includes(g)){i=f;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}};var Un=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Dn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function an(n,t){let e=new Set([n]),r=[n],s=_n(t),i=cn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await Bun.file(o).text(),c=Wn(a);for(let u of c){let g=u.startsWith(".")?E.resolve(E.dirname(o),u):qn(u,s,i);if(!g)continue;let f=await Gn(g);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return e}function Wn(n){let t=new Set;for(let e of[Un,Dn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}async function Gn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function cn(n){let t=E.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?E.resolve(t,n.data.compilerOptions.baseUrl):t}function _n(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=cn(n);for(let[s,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");t.set(`^${o}$`,E.join(r,a))}return t}function qn(n,t,e){for(let[r,s]of t){let i=new RegExp(r),o=n.match(i);if(o)return s.replace("$1",o[1]||"")}return e?E.join(e,n):null}import{isolatedDeclaration as Pn}from"oxc-transform";async function ln(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Pn(e,i);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import fn from"node:fs/promises";import I from"node:path";import{isolatedDeclaration as Yn}from"oxc-transform";async function un(n,t){let e=I.resolve(n),r=I.resolve(e,t);if(!await fn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(I.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function mn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:i}=Yn(r,s);i.forEach((o)=>{if(!t)console.log(`
6
+ `);let a=o.labels[0],c=a?In(s,a.start):"",g=`${w(r)}${c}: ${Jn(o.message)}`;l.warn(g),t=!0})}catch{}})),t)l.info(`
7
7
  You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
8
8
  `)}function In(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
9
- `),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function Kn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function dn(n,t,e,r,s){let{absoluteEntry:i}=await pn(n,t),o=await ln(i,r),a=await un(o);return cn(i,a,e,r,s)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function T(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=X(),c=`${i}_${a}`;l.warn(`Output name conflict: "${i}" is used by multiple files.
9
+ `),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function Jn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function gn(n,t,e,r,s){let{absoluteEntry:i}=await un(n,t),o=await an(i,r),a=await ln(o);return on(i,a,e,s)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function S(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=Q(),c=`${i}_${a}`;l.warn(`Output name conflict: "${i}" is used by multiple files.
10
10
  Bunup uses filenames without extensions as output names by default.
11
11
 
12
12
  ${r[i]} -> ${i}.js
@@ -20,8 +20,8 @@ To fix this, use named entries in your configuration:
20
20
  }
21
21
  }
22
22
 
23
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function hn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Qn}from"load-tsconfig";function xn(n){try{return Qn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import Q from"node:path";async function yn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Q.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Zn(r,e);if(!i)continue;return{configs:Fn(i,n),configFilePath:r}}catch(s){throw new y(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Zn(n,t){if(t===".json"||t===".jsonc")return zn(n);return Xn(n)}async function zn(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Xn(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${m(t)}`)}}function Fn(n,t){let e=[];if(Vn(n))nt(n,t,e);else if(Array.isArray(n))tt(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function Vn(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function nt(n,t,e){for(let r of n){let s=Q.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function tt(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function wn(n){let t=Q.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),{packageJson:null,path:t}}}function bn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var v=new Set;async function D(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await wn(t);if(e)l.cli(`Using package.json: ${w(r,2)}`,{muted:!0});let s=e?.type,i=k(n,e),o=L(n),a=[bn(i,o)],c=T(n.entry),u=z(n,t),p=n.format.flatMap((f)=>c.map((x)=>{return et(n,t,x,f,s,a,u)}));if(await Promise.all(p),n.dts){let f=xn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path,2)}`,{muted:!0});let x=n.format.filter((O)=>{if(O==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),$=typeof n.dts==="object"&&n.dts.entry?T(n.dts.entry):c;try{await Promise.all($.map(async(O)=>{let Rn=await dn(t,O.path,n,f,e);await Promise.all(x.map(async(Sn)=>{let jn=V(Sn,s),G=`${t}/${n.outDir}/${O.name}${jn}`;await Bun.write(G,Rn);let An=Bun.file(G).size||0;l.progress("DTS",w(G),P(An),n.name)}))}))}catch(O){throw new d(m(O))}}}async function et(n,t,e,r,s,i,o){let a=F(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:hn(e.name,a)},splitting:tn(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new y(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,p=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),P(p),n.name)}var H="0.3.14";var $n="https://bun.sh/docs/installation",On="https://bunup.arshadyaseen.com/#cli-options";function b(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function S(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function Cn(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function st(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function pn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as zn}from"load-tsconfig";function dn(n){try{return zn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import J from"node:path";async function hn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=J.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Kn(r,e);if(!i)continue;return{configs:Xn(i,n),configFilePath:r}}catch(s){throw new x(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Kn(n,t){if(t===".json"||t===".jsonc")return Qn(n);return Zn(n)}async function Qn(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Zn(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${m(t)}`)}}function Xn(n,t){let e=[];if(Fn(n))Vn(n,t,e);else if(Array.isArray(n))nt(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function Fn(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function Vn(n,t,e){for(let r of n){let s=J.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function nt(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function xn(n){let t=J.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),{packageJson:null,path:t}}}function wn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var B=new Set;async function L(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await xn(t);if(e)l.cli(`Using package.json: ${w(r,2)}`,{muted:!0});let s=e?.type,i=M(n,e),o=k(n),a=[wn(i,o)],c=S(n.entry),u=K(n,t),g=n.format.flatMap((f)=>c.map((R)=>{return tt(n,t,R,f,s,a,u)}));if(await Promise.all(g),n.dts){let f=dn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path,2)}`,{muted:!0});let R=n.format.filter((b)=>{if(b==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),En=typeof n.dts==="object"&&n.dts.entry?S(n.dts.entry):c;try{await Promise.all(En.map(async(b)=>{let vn=await gn(t,b.path,n,f,e);await Promise.all(R.map(async(Rn)=>{let jn=X(Rn,s),W=`${t}/${n.outDir}/${b.name}${jn}`;await Bun.write(W,vn);let An=Bun.file(W).size||0;l.progress("DTS",w(W),q(An),n.name)}))}))}catch(b){throw new d(m(b))}}}async function tt(n,t,e,r,s,i,o){let a=Z(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:pn(e.name,a)},splitting:V(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),q(g),n.name)}var H="0.3.16";var yn="https://bun.sh/docs/installation",bn="https://bunup.arshadyaseen.com/#cli-options";function y(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function v(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function $n(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function rt(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
- `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${On}\x1B[0m
26
- `),process.exit(0)}function it(){console.log(H),process.exit(0)}var ot={name:{flags:["n","name"],handler:S("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:S("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:S("banner")},footer:{flags:["f","footer"],handler:S("footer")},external:{flags:["e","external"],handler:Cn("external")},sourcemap:{flags:["sm","sourcemap"],handler:S("sourcemap")},target:{flags:["t","target"],handler:S("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:Cn("noExternal")}},at={help:{flags:["h","help"],handler:()=>st()},version:{flags:["v","version"],handler:()=>it()}},U={};for(let n of Object.values(ot))if(n)for(let t of n.flags)U[t]=n.handler;for(let n of Object.values(at))for(let t of n.flags)U[t]=n.handler;function En(n){let t={},e={},r=0;while(r<n.length){let s=n[r];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(i==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=U[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=U[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=A(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
27
- To install Bun, visit `+$n)})();import W from"node:path";import ct from"chokidar";async function Bn(n,t){let e=new Set,r=T(n.entry);r.forEach((a)=>{let c=W.resolve(t,a.path),u=W.dirname(c);e.add(u)});let s=ct.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(t,n.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await D({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${M(performance.now()-c)}`)}catch(c){throw new j(`Build failed: ${m(c)}`)}finally{i=!1}};s.on("change",(a)=>{let c=W.relative(t,a);l.cli(`File changed: ${c}`),o()}),s.on("error",(a)=>{throw new j(`Watcher error: ${m(a)}`)}),await o(!0)}async function lt(n=Bun.argv.slice(2)){let t=En(n),{configs:e,configFilePath:r}=await yn(process.cwd());if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${w(r,2)}`,{muted:!0});let s=performance.now();if(l.cli("Build started"),e.length===0){let a={...E,...t},c=process.cwd();if(a.clean)J(c,Y(a.outDir));await vn(a,c)}else{for(let{options:a,rootDir:c}of e)if(en(a.clean))J(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...E,...a,...t};await vn(u,c)}))}let i=performance.now()-s,o=M(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),v.size>0)await gn(v),v.clear();if(t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function vn(n,t){if(n.watch)await Bn(n,t);else await D(n,t),n.onBuildSuccess?.()}lt().catch((n)=>Z(n));export{lt as main};
25
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${bn}\x1B[0m
26
+ `),process.exit(0)}function st(){console.log(H),process.exit(0)}var it={name:{flags:["n","name"],handler:v("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:v("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},banner:{flags:["b","banner"],handler:v("banner")},footer:{flags:["f","footer"],handler:v("footer")},external:{flags:["e","external"],handler:$n("external")},sourcemap:{flags:["sm","sourcemap"],handler:v("sourcemap")},target:{flags:["t","target"],handler:v("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:y("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:y("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:y("minifySyntax")},clean:{flags:["c","clean"],handler:y("clean")},splitting:{flags:["s","splitting"],handler:y("splitting")},noExternal:{flags:["ne","no-external"],handler:$n("noExternal")}},ot={help:{flags:["h","help"],handler:()=>rt()},version:{flags:["v","version"],handler:()=>st()}},U={};for(let n of Object.values(it))if(n)for(let t of n.flags)U[t]=n.handler;for(let n of Object.values(ot))for(let t of n.flags)U[t]=n.handler;function On(n){let t={},e={},r=0;while(r<n.length){let s=n[r];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(i==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=U[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=U[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=A(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
27
+ To install Bun, visit `+yn)})();import D from"node:path";import at from"chokidar";async function Cn(n,t){let e=new Set,r=S(n.entry);r.forEach((a)=>{let c=D.resolve(t,a.path),u=D.dirname(c);e.add(u)});let s=at.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,D.join(t,n.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await L({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${T(performance.now()-c)}`)}catch(c){throw new j(`Build failed: ${m(c)}`)}finally{i=!1}};s.on("change",(a)=>{let c=D.relative(t,a);l.cli(`File changed: ${c}`),o()}),s.on("error",(a)=>{throw new j(`Watcher error: ${m(a)}`)}),await o(!0)}async function ct(n=Bun.argv.slice(2)){let t=On(n),{configs:e,configFilePath:r}=await hn(process.cwd());if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${w(r,2)}`,{muted:!0});let s=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...t},c=process.cwd();if(a.clean)P(c,Y(a.outDir));await Bn(a,c)}else{for(let{options:a,rootDir:c}of e)if(nn(a.clean))P(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...O,...a,...t};await Bn(u,c)}))}let i=performance.now()-s,o=T(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),B.size>0)await mn(B),B.clear();if(t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Bn(n,t){if(n.watch)await Cn(n,t);else await L(n,t),n.onBuildSuccess?.()}ct().catch((n)=>z(n));export{ct as main};
package/build/index.d.mts CHANGED
@@ -1,12 +1,220 @@
1
- import * as bun from 'bun';
2
1
 
2
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/options.d.ts
3
+ /**
4
+ * Entry point files for TypeScript declaration file generation
5
+ *
6
+ * This can be:
7
+ * - A string path to a file
8
+ * - An array of file paths
9
+ * - An object where keys are output names and values are input file paths
10
+ *
11
+ * The key names are used for the generated declaration files.
12
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
13
+ *
14
+ * If not specified, the main entry points will be used for declaration file generation.
15
+ *
16
+ * If it's a string or an array of strings, the file name (without extension)
17
+ * will be used as the name for the output declaration file.
18
+ *
19
+ * @example
20
+ * // Using a string path
21
+ * entry: 'src/index.ts' // Generates index.d.ts
22
+ *
23
+ * // Using string paths in an array
24
+ * entry: ['src/index.ts'] // Generates index.d.ts
25
+ *
26
+ * // Using named outputs as an object
27
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
28
+ */
3
29
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
30
+ /**
31
+ * Entry point files for TypeScript declaration file generation
32
+ *
33
+ * This can be:
34
+ * - A string path to a file
35
+ * - An array of file paths
36
+ * - An object where keys are output names and values are input file paths
37
+ *
38
+ * The key names are used for the generated declaration files.
39
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
40
+ *
41
+ * If not specified, the main entry points will be used for declaration file generation.
42
+ *
43
+ * If it's a string or an array of strings, the file name (without extension)
44
+ * will be used as the name for the output declaration file.
45
+ *
46
+ * @example
47
+ * // Using a string path
48
+ * entry: 'src/index.ts' // Generates index.d.ts
49
+ *
50
+ * // Using string paths in an array
51
+ * entry: ['src/index.ts'] // Generates index.d.ts
52
+ *
53
+ * // Using named outputs as an object
54
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
55
+ */
4
56
  type Define = BunBuildOptions["define"];
57
+ /**
58
+ * Entry point files for TypeScript declaration file generation
59
+ *
60
+ * This can be:
61
+ * - A string path to a file
62
+ * - An array of file paths
63
+ * - An object where keys are output names and values are input file paths
64
+ *
65
+ * The key names are used for the generated declaration files.
66
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
67
+ *
68
+ * If not specified, the main entry points will be used for declaration file generation.
69
+ *
70
+ * If it's a string or an array of strings, the file name (without extension)
71
+ * will be used as the name for the output declaration file.
72
+ *
73
+ * @example
74
+ * // Using a string path
75
+ * entry: 'src/index.ts' // Generates index.d.ts
76
+ *
77
+ * // Using string paths in an array
78
+ * entry: ['src/index.ts'] // Generates index.d.ts
79
+ *
80
+ * // Using named outputs as an object
81
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
82
+ */
5
83
  type Sourcemap = BunBuildOptions["sourcemap"];
84
+ /**
85
+ * Entry point files for TypeScript declaration file generation
86
+ *
87
+ * This can be:
88
+ * - A string path to a file
89
+ * - An array of file paths
90
+ * - An object where keys are output names and values are input file paths
91
+ *
92
+ * The key names are used for the generated declaration files.
93
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
94
+ *
95
+ * If not specified, the main entry points will be used for declaration file generation.
96
+ *
97
+ * If it's a string or an array of strings, the file name (without extension)
98
+ * will be used as the name for the output declaration file.
99
+ *
100
+ * @example
101
+ * // Using a string path
102
+ * entry: 'src/index.ts' // Generates index.d.ts
103
+ *
104
+ * // Using string paths in an array
105
+ * entry: ['src/index.ts'] // Generates index.d.ts
106
+ *
107
+ * // Using named outputs as an object
108
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
109
+ */
6
110
  type Format = Exclude<BunBuildOptions["format"], undefined>;
111
+ /**
112
+ * Entry point files for TypeScript declaration file generation
113
+ *
114
+ * This can be:
115
+ * - A string path to a file
116
+ * - An array of file paths
117
+ * - An object where keys are output names and values are input file paths
118
+ *
119
+ * The key names are used for the generated declaration files.
120
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
121
+ *
122
+ * If not specified, the main entry points will be used for declaration file generation.
123
+ *
124
+ * If it's a string or an array of strings, the file name (without extension)
125
+ * will be used as the name for the output declaration file.
126
+ *
127
+ * @example
128
+ * // Using a string path
129
+ * entry: 'src/index.ts' // Generates index.d.ts
130
+ *
131
+ * // Using string paths in an array
132
+ * entry: ['src/index.ts'] // Generates index.d.ts
133
+ *
134
+ * // Using named outputs as an object
135
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
136
+ */
7
137
  type Target = BunBuildOptions["target"];
138
+ /**
139
+ * Entry point files for TypeScript declaration file generation
140
+ *
141
+ * This can be:
142
+ * - A string path to a file
143
+ * - An array of file paths
144
+ * - An object where keys are output names and values are input file paths
145
+ *
146
+ * The key names are used for the generated declaration files.
147
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
148
+ *
149
+ * If not specified, the main entry points will be used for declaration file generation.
150
+ *
151
+ * If it's a string or an array of strings, the file name (without extension)
152
+ * will be used as the name for the output declaration file.
153
+ *
154
+ * @example
155
+ * // Using a string path
156
+ * entry: 'src/index.ts' // Generates index.d.ts
157
+ *
158
+ * // Using string paths in an array
159
+ * entry: ['src/index.ts'] // Generates index.d.ts
160
+ *
161
+ * // Using named outputs as an object
162
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
163
+ */
8
164
  type External = (string | RegExp)[];
165
+ /**
166
+ * Entry point files for TypeScript declaration file generation
167
+ *
168
+ * This can be:
169
+ * - A string path to a file
170
+ * - An array of file paths
171
+ * - An object where keys are output names and values are input file paths
172
+ *
173
+ * The key names are used for the generated declaration files.
174
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
175
+ *
176
+ * If not specified, the main entry points will be used for declaration file generation.
177
+ *
178
+ * If it's a string or an array of strings, the file name (without extension)
179
+ * will be used as the name for the output declaration file.
180
+ *
181
+ * @example
182
+ * // Using a string path
183
+ * entry: 'src/index.ts' // Generates index.d.ts
184
+ *
185
+ * // Using string paths in an array
186
+ * entry: ['src/index.ts'] // Generates index.d.ts
187
+ *
188
+ * // Using named outputs as an object
189
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
190
+ */
9
191
  type Entry = Arrayable<string> | Record<string, string>;
192
+ /**
193
+ * Entry point files for TypeScript declaration file generation
194
+ *
195
+ * This can be:
196
+ * - A string path to a file
197
+ * - An array of file paths
198
+ * - An object where keys are output names and values are input file paths
199
+ *
200
+ * The key names are used for the generated declaration files.
201
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
202
+ *
203
+ * If not specified, the main entry points will be used for declaration file generation.
204
+ *
205
+ * If it's a string or an array of strings, the file name (without extension)
206
+ * will be used as the name for the output declaration file.
207
+ *
208
+ * @example
209
+ * // Using a string path
210
+ * entry: 'src/index.ts' // Generates index.d.ts
211
+ *
212
+ * // Using string paths in an array
213
+ * entry: ['src/index.ts'] // Generates index.d.ts
214
+ *
215
+ * // Using named outputs as an object
216
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
217
+ */
10
218
  type DtsOptions = {
11
219
  /**
12
220
  * Entry point files for TypeScript declaration file generation
@@ -40,6 +248,10 @@ type DtsOptions = {
40
248
  */
41
249
  resolve?: boolean | (string | RegExp)[]
42
250
  };
251
+ /**
252
+ * Name of the build configuration
253
+ * Used for logging and identification purposes
254
+ */
43
255
  interface BunupOptions {
44
256
  /**
45
257
  * Name of the build configuration
@@ -224,13 +436,15 @@ interface BunupOptions {
224
436
  loader?: Record<string, Loader>;
225
437
  }
226
438
 
439
+ //#endregion
440
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/types.d.ts
227
441
  type PromiseOr<T> = Promise<T> | T;
228
442
  type WithOptional<
229
443
  T,
230
444
  K extends keyof T
231
445
  > = Omit<T, K> & Partial<Pick<T, K>>;
232
446
  type Arrayable<T> = T | T[];
233
- type Bun = typeof bun;
447
+ type Bun = typeof import("bun");
234
448
  type BunBuildOptions = Parameters<Bun["build"]>[0];
235
449
  type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
236
450
  type DefineWorkspaceEntry = {
@@ -239,10 +453,14 @@ type DefineWorkspaceEntry = {
239
453
  config: DefineConfigEntry | DefineConfigEntry[]
240
454
  };
241
455
 
456
+ //#endregion
457
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/define.d.ts
242
458
  declare function defineConfig(options: DefineConfigEntry | DefineConfigEntry[]): DefineConfigEntry | DefineConfigEntry[];
243
459
  declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
244
460
 
461
+ //#endregion
462
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/build.d.ts
245
463
  declare function build(options: BunupOptions, rootDir: string): Promise<void>;
246
464
 
247
- export { build, defineConfig, defineWorkspace };
248
- export type { DefineConfigEntry, DefineWorkspaceEntry };
465
+ //#endregion
466
+ export { DefineConfigEntry, DefineWorkspaceEntry, build, defineConfig, defineWorkspace };
package/build/index.d.ts CHANGED
@@ -1,12 +1,220 @@
1
- import * as bun from 'bun';
2
1
 
2
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/options.d.ts
3
+ /**
4
+ * Entry point files for TypeScript declaration file generation
5
+ *
6
+ * This can be:
7
+ * - A string path to a file
8
+ * - An array of file paths
9
+ * - An object where keys are output names and values are input file paths
10
+ *
11
+ * The key names are used for the generated declaration files.
12
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
13
+ *
14
+ * If not specified, the main entry points will be used for declaration file generation.
15
+ *
16
+ * If it's a string or an array of strings, the file name (without extension)
17
+ * will be used as the name for the output declaration file.
18
+ *
19
+ * @example
20
+ * // Using a string path
21
+ * entry: 'src/index.ts' // Generates index.d.ts
22
+ *
23
+ * // Using string paths in an array
24
+ * entry: ['src/index.ts'] // Generates index.d.ts
25
+ *
26
+ * // Using named outputs as an object
27
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
28
+ */
3
29
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
30
+ /**
31
+ * Entry point files for TypeScript declaration file generation
32
+ *
33
+ * This can be:
34
+ * - A string path to a file
35
+ * - An array of file paths
36
+ * - An object where keys are output names and values are input file paths
37
+ *
38
+ * The key names are used for the generated declaration files.
39
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
40
+ *
41
+ * If not specified, the main entry points will be used for declaration file generation.
42
+ *
43
+ * If it's a string or an array of strings, the file name (without extension)
44
+ * will be used as the name for the output declaration file.
45
+ *
46
+ * @example
47
+ * // Using a string path
48
+ * entry: 'src/index.ts' // Generates index.d.ts
49
+ *
50
+ * // Using string paths in an array
51
+ * entry: ['src/index.ts'] // Generates index.d.ts
52
+ *
53
+ * // Using named outputs as an object
54
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
55
+ */
4
56
  type Define = BunBuildOptions["define"];
57
+ /**
58
+ * Entry point files for TypeScript declaration file generation
59
+ *
60
+ * This can be:
61
+ * - A string path to a file
62
+ * - An array of file paths
63
+ * - An object where keys are output names and values are input file paths
64
+ *
65
+ * The key names are used for the generated declaration files.
66
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
67
+ *
68
+ * If not specified, the main entry points will be used for declaration file generation.
69
+ *
70
+ * If it's a string or an array of strings, the file name (without extension)
71
+ * will be used as the name for the output declaration file.
72
+ *
73
+ * @example
74
+ * // Using a string path
75
+ * entry: 'src/index.ts' // Generates index.d.ts
76
+ *
77
+ * // Using string paths in an array
78
+ * entry: ['src/index.ts'] // Generates index.d.ts
79
+ *
80
+ * // Using named outputs as an object
81
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
82
+ */
5
83
  type Sourcemap = BunBuildOptions["sourcemap"];
84
+ /**
85
+ * Entry point files for TypeScript declaration file generation
86
+ *
87
+ * This can be:
88
+ * - A string path to a file
89
+ * - An array of file paths
90
+ * - An object where keys are output names and values are input file paths
91
+ *
92
+ * The key names are used for the generated declaration files.
93
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
94
+ *
95
+ * If not specified, the main entry points will be used for declaration file generation.
96
+ *
97
+ * If it's a string or an array of strings, the file name (without extension)
98
+ * will be used as the name for the output declaration file.
99
+ *
100
+ * @example
101
+ * // Using a string path
102
+ * entry: 'src/index.ts' // Generates index.d.ts
103
+ *
104
+ * // Using string paths in an array
105
+ * entry: ['src/index.ts'] // Generates index.d.ts
106
+ *
107
+ * // Using named outputs as an object
108
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
109
+ */
6
110
  type Format = Exclude<BunBuildOptions["format"], undefined>;
111
+ /**
112
+ * Entry point files for TypeScript declaration file generation
113
+ *
114
+ * This can be:
115
+ * - A string path to a file
116
+ * - An array of file paths
117
+ * - An object where keys are output names and values are input file paths
118
+ *
119
+ * The key names are used for the generated declaration files.
120
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
121
+ *
122
+ * If not specified, the main entry points will be used for declaration file generation.
123
+ *
124
+ * If it's a string or an array of strings, the file name (without extension)
125
+ * will be used as the name for the output declaration file.
126
+ *
127
+ * @example
128
+ * // Using a string path
129
+ * entry: 'src/index.ts' // Generates index.d.ts
130
+ *
131
+ * // Using string paths in an array
132
+ * entry: ['src/index.ts'] // Generates index.d.ts
133
+ *
134
+ * // Using named outputs as an object
135
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
136
+ */
7
137
  type Target = BunBuildOptions["target"];
138
+ /**
139
+ * Entry point files for TypeScript declaration file generation
140
+ *
141
+ * This can be:
142
+ * - A string path to a file
143
+ * - An array of file paths
144
+ * - An object where keys are output names and values are input file paths
145
+ *
146
+ * The key names are used for the generated declaration files.
147
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
148
+ *
149
+ * If not specified, the main entry points will be used for declaration file generation.
150
+ *
151
+ * If it's a string or an array of strings, the file name (without extension)
152
+ * will be used as the name for the output declaration file.
153
+ *
154
+ * @example
155
+ * // Using a string path
156
+ * entry: 'src/index.ts' // Generates index.d.ts
157
+ *
158
+ * // Using string paths in an array
159
+ * entry: ['src/index.ts'] // Generates index.d.ts
160
+ *
161
+ * // Using named outputs as an object
162
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
163
+ */
8
164
  type External = (string | RegExp)[];
165
+ /**
166
+ * Entry point files for TypeScript declaration file generation
167
+ *
168
+ * This can be:
169
+ * - A string path to a file
170
+ * - An array of file paths
171
+ * - An object where keys are output names and values are input file paths
172
+ *
173
+ * The key names are used for the generated declaration files.
174
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
175
+ *
176
+ * If not specified, the main entry points will be used for declaration file generation.
177
+ *
178
+ * If it's a string or an array of strings, the file name (without extension)
179
+ * will be used as the name for the output declaration file.
180
+ *
181
+ * @example
182
+ * // Using a string path
183
+ * entry: 'src/index.ts' // Generates index.d.ts
184
+ *
185
+ * // Using string paths in an array
186
+ * entry: ['src/index.ts'] // Generates index.d.ts
187
+ *
188
+ * // Using named outputs as an object
189
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
190
+ */
9
191
  type Entry = Arrayable<string> | Record<string, string>;
192
+ /**
193
+ * Entry point files for TypeScript declaration file generation
194
+ *
195
+ * This can be:
196
+ * - A string path to a file
197
+ * - An array of file paths
198
+ * - An object where keys are output names and values are input file paths
199
+ *
200
+ * The key names are used for the generated declaration files.
201
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
202
+ *
203
+ * If not specified, the main entry points will be used for declaration file generation.
204
+ *
205
+ * If it's a string or an array of strings, the file name (without extension)
206
+ * will be used as the name for the output declaration file.
207
+ *
208
+ * @example
209
+ * // Using a string path
210
+ * entry: 'src/index.ts' // Generates index.d.ts
211
+ *
212
+ * // Using string paths in an array
213
+ * entry: ['src/index.ts'] // Generates index.d.ts
214
+ *
215
+ * // Using named outputs as an object
216
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
217
+ */
10
218
  type DtsOptions = {
11
219
  /**
12
220
  * Entry point files for TypeScript declaration file generation
@@ -40,6 +248,10 @@ type DtsOptions = {
40
248
  */
41
249
  resolve?: boolean | (string | RegExp)[]
42
250
  };
251
+ /**
252
+ * Name of the build configuration
253
+ * Used for logging and identification purposes
254
+ */
43
255
  interface BunupOptions {
44
256
  /**
45
257
  * Name of the build configuration
@@ -224,13 +436,15 @@ interface BunupOptions {
224
436
  loader?: Record<string, Loader>;
225
437
  }
226
438
 
439
+ //#endregion
440
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/types.d.ts
227
441
  type PromiseOr<T> = Promise<T> | T;
228
442
  type WithOptional<
229
443
  T,
230
444
  K extends keyof T
231
445
  > = Omit<T, K> & Partial<Pick<T, K>>;
232
446
  type Arrayable<T> = T | T[];
233
- type Bun = typeof bun;
447
+ type Bun = typeof import("bun");
234
448
  type BunBuildOptions = Parameters<Bun["build"]>[0];
235
449
  type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
236
450
  type DefineWorkspaceEntry = {
@@ -239,10 +453,14 @@ type DefineWorkspaceEntry = {
239
453
  config: DefineConfigEntry | DefineConfigEntry[]
240
454
  };
241
455
 
456
+ //#endregion
457
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/define.d.ts
242
458
  declare function defineConfig(options: DefineConfigEntry | DefineConfigEntry[]): DefineConfigEntry | DefineConfigEntry[];
243
459
  declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
244
460
 
461
+ //#endregion
462
+ //#region \0virtual:/home/runner/work/bunup/bunup/src/build.d.ts
245
463
  declare function build(options: BunupOptions, rootDir: string): Promise<void>;
246
464
 
247
- export { build, defineConfig, defineWorkspace };
248
- export type { DefineConfigEntry, DefineWorkspaceEntry };
465
+ //#endregion
466
+ export { DefineConfigEntry, DefineWorkspaceEntry, build, defineConfig, defineWorkspace };
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var jn=require("node:module");var hn=Object.create;var{getPrototypeOf:bn,defineProperty:R,getOwnPropertyNames:G,getOwnPropertyDescriptor:Rn}=Object,H=Object.prototype.hasOwnProperty;var w=(n,t,r)=>{r=n!=null?hn(bn(n)):{};let e=t||!n||!n.__esModule?R(r,"default",{value:n,enumerable:!0}):r;for(let i of G(n))if(!H.call(e,i))R(e,i,{get:()=>n[i],enumerable:!0});return e},k=new WeakMap,Bn=(n)=>{var t=k.get(n),r;if(t)return t;if(t=R({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")G(n).map((e)=>!H.call(t,e)&&R(t,e,{get:()=>n[e],enumerable:!(r=Rn(n,e))||r.enumerable}));return k.set(n,t),t};var On=(n,t)=>{for(var r in t)R(n,r,{get:t[r],enumerable:!0,configurable:!0,set:(e)=>t[r]=()=>e})};var Ln={};On(Ln,{defineWorkspace:()=>J,defineConfig:()=>L,build:()=>wn});module.exports=Bn(Ln);function L(n){return n}function J(n){return n}var nn=require("rollup"),tn=w(require("rollup-plugin-dts")),M=w(require("typescript"));class A extends Error{constructor(n){super(n);this.name="BunupError"}}class h extends A{constructor(n){super(n);this.name="BunupBuildError"}}class d extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)};var Nn=w(require("node:fs/promises")),Sn=w(require("node:path"));function Y(n,t){return{outdir:`${t}/${n.outDir}`,minify:Mn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function Mn(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function D(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(n=8){return Math.random().toString(36).substring(2,2+n)}function K(n,t){switch(n){case"esm":return".mjs";case"cjs":return B(t)?".cjs":".js";case"iife":return".global.js"}}function Q(n,t){switch(n){case"esm":return".d.mts";case"cjs":return B(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function B(n){return n==="module"}function Z(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function U(n,t){return n===void 0?t==="esm":n}function T(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function b(n,t=3){return n.split("/").slice(-t).join("/")}function P(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${D(t)}($|\\/|\\\\)`):t)}function O(n,t){return P(n.external||[]).concat(Z(t).map((r)=>new RegExp(`^${D(r)}($|\\/|\\\\)`)))}function j(n){return P(n.noExternal||[])}var I=w(require("node:path")),V=require("oxc-resolver");var $=w(require("path"));var m="\x00virtual:",_=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=$.default.resolve($.default.dirname(e),t);if(t==="."){let o=$.default.join($.default.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=$.default.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=$.default.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return z.add(r),e}return null}}};var X;function F(n){return{name:"bunup:types-resolve",buildStart(){X||=new V.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?I.default.dirname(r):process.cwd(),{path:i}=await X.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function rn(n,t,r,e,i){let s=n.replace(/\.tsx?$/,".d.ts"),o=`${m}${s}`,c=e.data?.compilerOptions,f=O(r,i),g=j(r),l;try{l=await nn.rollup({input:o,onwarn(x,E){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;E(x)},plugins:[_(t),typeof r.dts==="object"&&"resolve"in r.dts&&F(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),tn.default({tsconfig:e.path,compilerOptions:{...c?M.default.parseJsonConfigFileContent({compilerOptions:c},M.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:M.default.ScriptTarget.ESNext}})],external:(x)=>f.some((E)=>E.test(x))&&!g.some((E)=>E.test(x))});let{output:a}=await l.generate({});if(!a[0]?.code)throw new d("Generated bundle is empty");return a[0].code}catch(a){throw new d(`DTS bundling failed: ${p(a)}`)}finally{if(l)await l.close()}}var y=w(require("node:path"));var u={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[g,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),x=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${g}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${x}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let g=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(g,f)}};var An=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Dn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function en(n,t){let r=new Set([n]),e=[n],i=vn(t),s=sn(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=Tn(c);for(let g of f){let l=g.startsWith(".")?y.default.resolve(y.default.dirname(o),g):kn(g,i,s);if(!l)continue;let a=await Wn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${o}: ${p(c)}`)}}return r}function Tn(n){let t=new Set;for(let r of[An,Dn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function Wn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function sn(n){let t=y.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?y.default.resolve(t,n.data.compilerOptions.baseUrl):t}function vn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=sn(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,y.default.join(e,c))}return t}function kn(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?y.default.join(r,n):null}var on=require("oxc-transform");async function cn(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=on.isolatedDeclaration(r,s);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),t}var W=w(require("node:fs/promises")),N=w(require("node:path")),Gn=require("oxc-transform");async function an(n,t){let r=N.default.resolve(n),e=N.default.resolve(r,t);if(!await W.default.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(N.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function fn(n,t,r,e,i){let{absoluteEntry:s}=await an(n,t),o=await en(s,e),c=await cn(o);return rn(s,c,r,e,i)}function un(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=q(),f=`${s}_${c}`;u.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ var jn=require("node:module");var Cn=Object.create;var{getPrototypeOf:hn,defineProperty:b,getOwnPropertyNames:v,getOwnPropertyDescriptor:bn}=Object,G=Object.prototype.hasOwnProperty;var d=(n,t,r)=>{r=n!=null?Cn(hn(n)):{};let e=t||!n||!n.__esModule?b(r,"default",{value:n,enumerable:!0}):r;for(let i of v(n))if(!G.call(e,i))b(e,i,{get:()=>n[i],enumerable:!0});return e},T=new WeakMap,Rn=(n)=>{var t=T.get(n),r;if(t)return t;if(t=b({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")v(n).map((e)=>!G.call(t,e)&&b(t,e,{get:()=>n[e],enumerable:!(r=bn(n,e))||r.enumerable}));return T.set(n,t),t};var Bn=(n,t)=>{for(var r in t)b(n,r,{get:t[r],enumerable:!0,configurable:!0,set:(e)=>t[r]=()=>e})};var Hn={};Bn(Hn,{defineWorkspace:()=>H,defineConfig:()=>k,build:()=>pn});module.exports=Rn(Hn);function k(n){return n}function H(n){return n}var V=require("rolldown"),F=require("rolldown-plugin-dts");class A extends Error{constructor(n){super(n);this.name="BunupError"}}class y extends A{constructor(n){super(n);this.name="BunupBuildError"}}class p extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var x=(n)=>{if(n instanceof Error)return n.message;return String(n)};var Mn=d(require("node:fs/promises")),An=d(require("node:path"));function L(n,t){return{outdir:`${t}/${n.outDir}`,minify:On(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function On(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function N(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(n=8){return Math.random().toString(36).substring(2,2+n)}function J(n,t){switch(n){case"esm":return".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function q(n,t){switch(n){case"esm":return".d.mts";case"cjs":return R(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(n){return n==="module"}function K(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function Q(n,t){return n===void 0?t==="esm":n}function S(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function C(n,t=3){return n.split("/").slice(-t).join("/")}function Z(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${N(t)}($|\\/|\\\\)`):t)}function B(n,t){return Z(n.external||[]).concat(K(t).map((r)=>new RegExp(`^${N(r)}($|\\/|\\\\)`)))}function j(n){return Z(n.noExternal||[])}var P=d(require("node:path")),X=require("oxc-resolver");var w=d(require("path"));var m="\x00virtual:",U=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=w.default.resolve(w.default.dirname(e),t);if(t==="."){let o=w.default.join(w.default.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=w.default.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=w.default.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return _.add(r),e}return null}}};var z;function I(n){return{name:"bunup:types-resolve",buildStart(){z||=new X.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?P.default.dirname(r):process.cwd(),{path:i}=await z.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function nn(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${m}${i}`,o=B(r,e),c=j(r),f;try{f=await V.rolldown({input:s,onwarn(l,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;a(l)},plugins:[U(t),typeof r.dts==="object"&&"resolve"in r.dts&&I(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),F.dts()],external:(l)=>o.some((a)=>a.test(l))&&!c.some((a)=>a.test(l))});let{output:u}=await f.generate({});if(!u[0]?.code)throw new p("Generated bundle is empty");return u[0].code}catch(u){throw new p(`DTS bundling failed: ${x(u)}`)}finally{if(f)await f.close()}}var E=d(require("node:path"));var g={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[u,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${h}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(u,f)}};var Nn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Sn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function tn(n,t){let r=new Set([n]),e=[n],i=Tn(t),s=rn(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=Dn(c);for(let u of f){let l=u.startsWith(".")?E.default.resolve(E.default.dirname(o),u):vn(u,i,s);if(!l)continue;let a=await Wn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){g.warn(`Error processing ${o}: ${x(c)}`)}}return r}function Dn(n){let t=new Set;for(let r of[Nn,Sn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function Wn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function rn(n){let t=E.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?E.default.resolve(t,n.data.compilerOptions.baseUrl):t}function Tn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=rn(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,E.default.join(e,c))}return t}function vn(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?E.default.join(r,n):null}var en=require("oxc-transform");async function sn(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=en.isolatedDeclaration(r,s);if(o)t.set(e,o)}catch(e){g.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),t}var D=d(require("node:fs/promises")),O=d(require("node:path")),Gn=require("oxc-transform");async function on(n,t){let r=O.default.resolve(n),e=O.default.resolve(r,t);if(!await D.default.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(O.default.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function cn(n,t,r,e,i){let{absoluteEntry:s}=await on(n,t),o=await tn(s,e),c=await sn(o);return nn(s,c,r,i)}function an(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=Y(),f=`${s}_${c}`;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
4
  ${e[s]} -> ${s}.js
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=un(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=un(n);i(s,n)}return t}function gn(n,t){return`[dir]/${n}${t}`}var ln=require("load-tsconfig");function mn(n){try{return ln.loadTsConfig(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}var pn=w(require("node:path"));async function xn(n){let t=pn.default.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return u.warn(`Failed to load package.json at ${t}: ${p(r)}`),{packageJson:null,path:t}}}function dn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var z=new Set;async function wn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await xn(t);if(r)u.cli(`Using package.json: ${b(e,2)}`,{muted:!0});let i=r?.type,s=O(n,r),o=j(n),c=[dn(s,o)],f=v(n.entry),g=Y(n,t),l=n.format.flatMap((a)=>f.map((x)=>{return Hn(n,t,x,a,i,c,g)}));if(await Promise.all(l),n.dts){let a=mn(n.preferredTsconfigPath);if(a.path)u.cli(`Using tsconfig: ${b(a.path,2)}`,{muted:!0});let x=n.format.filter((C)=>{if(C==="iife"&&!B(i)&&n.format.includes("cjs"))return!1;return!0}),E=typeof n.dts==="object"&&n.dts.entry?v(n.dts.entry):f;try{await Promise.all(E.map(async(C)=>{let En=await fn(t,C.path,n,a,r);await Promise.all(x.map(async($n)=>{let yn=Q($n,i),S=`${t}/${n.outDir}/${C.name}${yn}`;await Bun.write(S,En);let Cn=Bun.file(S).size||0;u.progress("DTS",b(S),T(Cn),n.name)}))}))}catch(C){throw new d(p(C))}}}async function Hn(n,t,r,e,i,s,o){let c=K(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:gn(r.name,c)},splitting:U(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new h(a.message);else if(a.level==="warning")u.warn(a.message);else if(a.level==="info")u.info(a.message)});let g=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(g).size||0;u.progress(e.toUpperCase(),b(g),T(l),n.name)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=an(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=an(n);i(s,n)}return t}function fn(n,t){return`[dir]/${n}${t}`}var un=require("load-tsconfig");function gn(n){try{return un.loadTsConfig(".",n)}catch(t){return g.warn(`Failed to load tsconfig: ${x(t)}`),{path:n,data:{},files:[]}}}var ln=d(require("node:path"));async function mn(n){let t=ln.default.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return g.warn(`Failed to load package.json at ${t}: ${x(r)}`),{packageJson:null,path:t}}}function xn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var _=new Set;async function pn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await mn(t);if(r)g.cli(`Using package.json: ${C(e,2)}`,{muted:!0});let i=r?.type,s=B(n,r),o=j(n),c=[xn(s,o)],f=W(n.entry),u=L(n,t),l=n.format.flatMap((a)=>f.map((h)=>{return kn(n,t,h,a,i,c,u)}));if(await Promise.all(l),n.dts){let a=gn(n.preferredTsconfigPath);if(a.path)g.cli(`Using tsconfig: ${C(a.path,2)}`,{muted:!0});let h=n.format.filter(($)=>{if($==="iife"&&!R(i)&&n.format.includes("cjs"))return!1;return!0}),dn=typeof n.dts==="object"&&n.dts.entry?W(n.dts.entry):f;try{await Promise.all(dn.map(async($)=>{let wn=await cn(t,$.path,n,a,r);await Promise.all(h.map(async(En)=>{let $n=q(En,i),M=`${t}/${n.outDir}/${$.name}${$n}`;await Bun.write(M,wn);let yn=Bun.file(M).size||0;g.progress("DTS",C(M),S(yn),n.name)}))}))}catch($){throw new p(x($))}}}async function kn(n,t,r,e,i,s,o){let c=J(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:fn(r.name,c)},splitting:Q(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new y(a.message);else if(a.level==="warning")g.warn(a.message);else if(a.level==="info")g.info(a.message)});let u=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(u).size||0;g.progress(e.toUpperCase(),C(u),S(l),n.name)}
package/build/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- function cn(n){return n}function an(n){return n}import{rollup as ln}from"rollup";import mn from"rollup-plugin-dts";import S from"typescript";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class $ extends j{constructor(n){super(n);this.name="BunupBuildError"}}class d extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)};import Sn from"node:fs/promises";import Dn from"node:path";function T(n,t){return{outdir:`${t}/${n.outDir}`,minify:fn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function fn(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function M(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(n=8){return Math.random().toString(36).substring(2,2+n)}function v(n,t){switch(n){case"esm":return".mjs";case"cjs":return b(t)?".cjs":".js";case"iife":return".global.js"}}function k(n,t){switch(n){case"esm":return".d.mts";case"cjs":return b(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function b(n){return n==="module"}function G(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function H(n,t){return n===void 0?t==="esm":n}function N(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function y(n,t=3){return n.split("/").slice(-t).join("/")}function L(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${M(t)}($|\\/|\\\\)`):t)}function R(n,t){return L(n.external||[]).concat(G(t).map((r)=>new RegExp(`^${M(r)}($|\\/|\\\\)`)))}function B(n){return L(n.noExternal||[])}import un from"node:path";import{ResolverFactory as gn}from"oxc-resolver";import C from"path";var m="\x00virtual:",J=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=C.resolve(C.dirname(e),t);if(t==="."){let o=C.join(C.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=C.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=C.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return Y.add(r),e}return null}}};var q;function K(n){return{name:"bunup:types-resolve",buildStart(){q||=new gn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?un.dirname(r):process.cwd(),{path:i}=await q.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function Q(n,t,r,e,i){let s=n.replace(/\.tsx?$/,".d.ts"),o=`${m}${s}`,c=e.data?.compilerOptions,f=R(r,i),g=B(r),l;try{l=await ln({input:o,onwarn(x,w){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;w(x)},plugins:[J(t),typeof r.dts==="object"&&"resolve"in r.dts&&K(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),mn({tsconfig:e.path,compilerOptions:{...c?S.parseJsonConfigFileContent({compilerOptions:c},S.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:S.ScriptTarget.ESNext}})],external:(x)=>f.some((w)=>w.test(x))&&!g.some((w)=>w.test(x))});let{output:a}=await l.generate({});if(!a[0]?.code)throw new d("Generated bundle is empty");return a[0].code}catch(a){throw new d(`DTS bundling failed: ${p(a)}`)}finally{if(l)await l.close()}}import h from"node:path";var u={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[g,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),x=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${g}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${x}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let g=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(g,f)}};var pn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,xn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Z(n,t){let r=new Set([n]),e=[n],i=En(t),s=U(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=dn(c);for(let g of f){let l=g.startsWith(".")?h.resolve(h.dirname(o),g):$n(g,i,s);if(!l)continue;let a=await wn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${o}: ${p(c)}`)}}return r}function dn(n){let t=new Set;for(let r of[pn,xn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function wn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function U(n){let t=h.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?h.resolve(t,n.data.compilerOptions.baseUrl):t}function En(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=U(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,h.join(e,c))}return t}function $n(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?h.join(r,n):null}import{isolatedDeclaration as yn}from"oxc-transform";async function P(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=yn(r,s);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),t}import _ from"node:fs/promises";import A from"node:path";import{isolatedDeclaration as mt}from"oxc-transform";async function z(n,t){let r=A.resolve(n),e=A.resolve(r,t);if(!await _.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function X(n,t,r,e,i){let{absoluteEntry:s}=await z(n,t),o=await Z(s,e),c=await P(o);return Q(s,c,r,e,i)}function I(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function D(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=W(),f=`${s}_${c}`;u.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function on(n){return n}function cn(n){return n}import{rolldown as gn}from"rolldown";import{dts as ln}from"rolldown-plugin-dts";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends j{constructor(n){super(n);this.name="BunupBuildError"}}class p extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var x=(n)=>{if(n instanceof Error)return n.message;return String(n)};import An from"node:fs/promises";import Sn from"node:path";function S(n,t){return{outdir:`${t}/${n.outDir}`,minify:an(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function an(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function O(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(n=8){return Math.random().toString(36).substring(2,2+n)}function W(n,t){switch(n){case"esm":return".mjs";case"cjs":return h(t)?".cjs":".js";case"iife":return".global.js"}}function T(n,t){switch(n){case"esm":return".d.mts";case"cjs":return h(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function h(n){return n==="module"}function v(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function G(n,t){return n===void 0?t==="esm":n}function M(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function E(n,t=3){return n.split("/").slice(-t).join("/")}function k(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${O(t)}($|\\/|\\\\)`):t)}function b(n,t){return k(n.external||[]).concat(v(t).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function R(n){return k(n.noExternal||[])}import fn from"node:path";import{ResolverFactory as un}from"oxc-resolver";import $ from"path";var m="\x00virtual:",H=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=$.resolve($.dirname(e),t);if(t==="."){let o=$.join($.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=$.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=$.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return L.add(r),e}return null}}};var Y;function J(n){return{name:"bunup:types-resolve",buildStart(){Y||=new un({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?fn.dirname(r):process.cwd(),{path:i}=await Y.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function q(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${m}${i}`,o=b(r,e),c=R(r),f;try{f=await gn({input:s,onwarn(l,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;a(l)},plugins:[H(t),typeof r.dts==="object"&&"resolve"in r.dts&&J(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),ln()],external:(l)=>o.some((a)=>a.test(l))&&!c.some((a)=>a.test(l))});let{output:u}=await f.generate({});if(!u[0]?.code)throw new p("Generated bundle is empty");return u[0].code}catch(u){throw new p(`DTS bundling failed: ${x(u)}`)}finally{if(f)await f.close()}}import y from"node:path";var g={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[u,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),C=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${C}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(u,f)}};var mn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,xn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function K(n,t){let r=new Set([n]),e=[n],i=wn(t),s=Q(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=pn(c);for(let u of f){let l=u.startsWith(".")?y.resolve(y.dirname(o),u):En(u,i,s);if(!l)continue;let a=await dn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){g.warn(`Error processing ${o}: ${x(c)}`)}}return r}function pn(n){let t=new Set;for(let r of[mn,xn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function dn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function Q(n){let t=y.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?y.resolve(t,n.data.compilerOptions.baseUrl):t}function wn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=Q(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,y.join(e,c))}return t}function En(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?y.join(r,n):null}import{isolatedDeclaration as $n}from"oxc-transform";async function Z(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=$n(r,s);if(o)t.set(e,o)}catch(e){g.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),t}import U from"node:fs/promises";import A from"node:path";import{isolatedDeclaration as gt}from"oxc-transform";async function _(n,t){let r=A.resolve(n),e=A.resolve(r,t);if(!await U.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function z(n,t,r,e,i){let{absoluteEntry:s}=await _(n,t),o=await K(s,e),c=await Z(o);return q(s,c,r,i)}function P(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=D(),f=`${s}_${c}`;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
4
  ${e[s]} -> ${s}.js
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=I(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=I(n);i(s,n)}return t}function V(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Cn}from"load-tsconfig";function F(n){try{return Cn(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import hn from"node:path";async function nn(n){let t=hn.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return u.warn(`Failed to load package.json at ${t}: ${p(r)}`),{packageJson:null,path:t}}}function tn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var Y=new Set;async function bn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new $("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await nn(t);if(r)u.cli(`Using package.json: ${y(e,2)}`,{muted:!0});let i=r?.type,s=R(n,r),o=B(n),c=[tn(s,o)],f=D(n.entry),g=T(n,t),l=n.format.flatMap((a)=>f.map((x)=>{return Rn(n,t,x,a,i,c,g)}));if(await Promise.all(l),n.dts){let a=F(n.preferredTsconfigPath);if(a.path)u.cli(`Using tsconfig: ${y(a.path,2)}`,{muted:!0});let x=n.format.filter((E)=>{if(E==="iife"&&!b(i)&&n.format.includes("cjs"))return!1;return!0}),w=typeof n.dts==="object"&&n.dts.entry?D(n.dts.entry):f;try{await Promise.all(w.map(async(E)=>{let rn=await X(t,E.path,n,a,r);await Promise.all(x.map(async(en)=>{let sn=k(en,i),O=`${t}/${n.outDir}/${E.name}${sn}`;await Bun.write(O,rn);let on=Bun.file(O).size||0;u.progress("DTS",y(O),N(on),n.name)}))}))}catch(E){throw new d(p(E))}}}async function Rn(n,t,r,e,i,s,o){let c=v(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:V(r.name,c)},splitting:H(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new $(a.message);else if(a.level==="warning")u.warn(a.message);else if(a.level==="info")u.info(a.message)});let g=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(g).size||0;u.progress(e.toUpperCase(),y(g),N(l),n.name)}export{an as defineWorkspace,cn as defineConfig,bn as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=P(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=P(n);i(s,n)}return t}function X(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as yn}from"load-tsconfig";function I(n){try{return yn(".",n)}catch(t){return g.warn(`Failed to load tsconfig: ${x(t)}`),{path:n,data:{},files:[]}}}import Cn from"node:path";async function V(n){let t=Cn.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return g.warn(`Failed to load package.json at ${t}: ${x(r)}`),{packageJson:null,path:t}}}function F(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var L=new Set;async function hn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await V(t);if(r)g.cli(`Using package.json: ${E(e,2)}`,{muted:!0});let i=r?.type,s=b(n,r),o=R(n),c=[F(s,o)],f=N(n.entry),u=S(n,t),l=n.format.flatMap((a)=>f.map((C)=>{return bn(n,t,C,a,i,c,u)}));if(await Promise.all(l),n.dts){let a=I(n.preferredTsconfigPath);if(a.path)g.cli(`Using tsconfig: ${E(a.path,2)}`,{muted:!0});let C=n.format.filter((d)=>{if(d==="iife"&&!h(i)&&n.format.includes("cjs"))return!1;return!0}),nn=typeof n.dts==="object"&&n.dts.entry?N(n.dts.entry):f;try{await Promise.all(nn.map(async(d)=>{let tn=await z(t,d.path,n,a,r);await Promise.all(C.map(async(rn)=>{let en=T(rn,i),B=`${t}/${n.outDir}/${d.name}${en}`;await Bun.write(B,tn);let sn=Bun.file(B).size||0;g.progress("DTS",E(B),M(sn),n.name)}))}))}catch(d){throw new p(x(d))}}}async function bn(n,t,r,e,i,s,o){let c=W(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:X(r.name,c)},splitting:G(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new w(a.message);else if(a.level==="warning")g.warn(a.message);else if(a.level==="info")g.info(a.message)});let u=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(u).size||0;g.progress(e.toUpperCase(),E(u),M(l),n.name)}export{cn as defineWorkspace,on as defineConfig,hn as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "@types/bun": "^1.2.5",
19
19
  "@typescript-eslint/eslint-plugin": "^7.3.1",
20
20
  "bumpp": "^10.1.0",
21
- "bunup": "^0.3.7",
21
+ "bunup": "^0.3.15",
22
22
  "eslint": "^8.57.1",
23
23
  "husky": "^9.1.7",
24
24
  "prettier": "^3.5.3",
@@ -57,8 +57,8 @@
57
57
  "load-tsconfig": "^0.2.5",
58
58
  "oxc-resolver": "^5.0.1",
59
59
  "oxc-transform": "^0.58.1",
60
- "rollup": "^4.35.0",
61
- "rollup-plugin-dts": "^6.1.1"
60
+ "rolldown": "1.0.0-beta.7",
61
+ "rolldown-plugin-dts": "https://pkg.pr.new/sxzz/rolldown-plugin-dts@main"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "bunup",