bunup 0.5.1 → 0.5.6

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
@@ -35,7 +35,7 @@
35
35
 
36
36
  ## 📚 Documentation
37
37
 
38
- To get started, visit the [documentation](https://bunup.dev/documentation).
38
+ To get started, visit the [documentation](https://bunup.dev/docs).
39
39
 
40
40
  ## ❤️ Contributing
41
41
 
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var kr=Object.create;var{getPrototypeOf:Rr,defineProperty:sn,getOwnPropertyNames:$r}=Object;var Tr=Object.prototype.hasOwnProperty;var W=(n,r,t)=>{t=n!=null?kr(Rr(n)):{};let e=r||!n||!n.__esModule?sn(t,"default",{value:n,enumerable:!0}):t;for(let i of $r(n))if(!Tr.call(e,i))sn(e,i,{get:()=>n[i],enumerable:!0});return e};var Ir=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var jr=(n,r)=>{for(var t in r)sn(n,t,{get:r[t],enumerable:!0,configurable:!0,set:(e)=>r[t]=()=>e})};var p=(n,r)=>()=>(n&&(r=n(n=0)),r);var Mr=import.meta.require;var v=Ir((we,an)=>{var Z=process||{},Sn=Z.argv||[],Q=Z.env||{},Er=!(!!Q.NO_COLOR||Sn.includes("--no-color"))&&(!!Q.FORCE_COLOR||Sn.includes("--color")||Z.platform==="win32"||(Z.stdout||{}).isTTY&&Q.TERM!=="dumb"||!!Q.CI),Ur=(n,r,t=n)=>(e)=>{let i=""+e,o=i.indexOf(r,n.length);return~o?n+_r(i,r,t,o)+r:n+i+r},_r=(n,r,t,e)=>{let i="",o=0;do i+=n.substring(o,e)+t,o=e+r.length,e=n.indexOf(r,o);while(~e);return i+n.substring(o)},Ln=(n=Er)=>{let r=n?Ur:()=>String;return{isColorSupported:n,reset:r("\x1B[0m","\x1B[0m"),bold:r("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:r("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:r("\x1B[3m","\x1B[23m"),underline:r("\x1B[4m","\x1B[24m"),inverse:r("\x1B[7m","\x1B[27m"),hidden:r("\x1B[8m","\x1B[28m"),strikethrough:r("\x1B[9m","\x1B[29m"),black:r("\x1B[30m","\x1B[39m"),red:r("\x1B[31m","\x1B[39m"),green:r("\x1B[32m","\x1B[39m"),yellow:r("\x1B[33m","\x1B[39m"),blue:r("\x1B[34m","\x1B[39m"),magenta:r("\x1B[35m","\x1B[39m"),cyan:r("\x1B[36m","\x1B[39m"),white:r("\x1B[37m","\x1B[39m"),gray:r("\x1B[90m","\x1B[39m"),bgBlack:r("\x1B[40m","\x1B[49m"),bgRed:r("\x1B[41m","\x1B[49m"),bgGreen:r("\x1B[42m","\x1B[49m"),bgYellow:r("\x1B[43m","\x1B[49m"),bgBlue:r("\x1B[44m","\x1B[49m"),bgMagenta:r("\x1B[45m","\x1B[49m"),bgCyan:r("\x1B[46m","\x1B[49m"),bgWhite:r("\x1B[47m","\x1B[49m"),blackBright:r("\x1B[90m","\x1B[39m"),redBright:r("\x1B[91m","\x1B[39m"),greenBright:r("\x1B[92m","\x1B[39m"),yellowBright:r("\x1B[93m","\x1B[39m"),blueBright:r("\x1B[94m","\x1B[39m"),magentaBright:r("\x1B[95m","\x1B[39m"),cyanBright:r("\x1B[96m","\x1B[39m"),whiteBright:r("\x1B[97m","\x1B[39m"),bgBlackBright:r("\x1B[100m","\x1B[49m"),bgRedBright:r("\x1B[101m","\x1B[49m"),bgGreenBright:r("\x1B[102m","\x1B[49m"),bgYellowBright:r("\x1B[103m","\x1B[49m"),bgBlueBright:r("\x1B[104m","\x1B[49m"),bgMagentaBright:r("\x1B[105m","\x1B[49m"),bgCyanBright:r("\x1B[106m","\x1B[49m"),bgWhiteBright:r("\x1B[107m","\x1B[49m")}};an.exports=Ln();an.exports.createColors=Ln});function V(n){Rn=n??!1}class A{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=d.default.blue;mutedColor=d.default.dim;infoColor=d.default.cyan;warnColor=d.default.yellow;errorColor=d.default.red;defaultColor=d.default.white;progressFgColorMap={ESM:d.default.yellow,CJS:d.default.green,IIFE:d.default.magenta,DTS:d.default.blue};progressBgColorMap={ESM:d.default.bgYellow,CJS:d.default.bgGreen,IIFE:d.default.bgMagenta,DTS:d.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!A.instance)A.instance=new A;return A.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({fgColor:n,bgColor:r,label:t,message:e,identifier:i,muted:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=o?this.mutedColor(e):e,a=i?` ${r(d.default.black(` ${i} `))}`:"";return`${n(t)} ${s}${c}${a}`}output(n,r={},t=console.log){if(Rn||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(n),r.verticalSpace)t("")}cli(n,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:d.default.bgBlue,label:this.labels.cli,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(n,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:d.default.bgCyan,label:this.labels.info,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(n,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:d.default.bgYellow,label:this.labels.warn,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(n,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:d.default.bgRed,label:this.labels.error,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(n){for(let[r,t]of Object.entries(this.progressFgColorMap))if(n.includes(r))return t;return this.defaultColor}getProgressBgColor(n){for(let[r,t]of Object.entries(this.progressBgColorMap))if(n.includes(r))return t;return d.default.bgWhite}progress(n,r,t={}){let e=this.getProgressFgColor(n),i=this.getProgressBgColor(n),o=this.formatMessage({fgColor:e,bgColor:i,label:n,message:r,identifier:t.identifier,muted:t.muted});this.output(o,t)}}var d,Rn=!1,l;var L=p(()=>{d=W(v(),1);l=A.getInstance()});function gn(n){return n instanceof D}var b,I,j,w,C,z,D,y=(n)=>{if(n instanceof Error)return n.message;return String(n)},Hr,cn=(n,r)=>{let t=y(n),e=r?`[${r}] `:"",i=gn(n),o="ERROR";if(n instanceof j)o="BUILD ERROR";else if(n instanceof w)o="DTS ERROR";else if(n instanceof C)o="CLI ERROR";else if(n instanceof z)o="WATCH ERROR";else if(i)o="ISOLATED DECL ERROR";else if(n instanceof I)o="BUNUP ERROR";let s=Hr.find((c)=>c.pattern.test(t)&&(c.errorType===o||!c.errorType));if(!s&&!i)console.error(`${b.default.red(o)} ${e}${t}`);if(s)console.log(`
3
+ var kr=Object.create;var{getPrototypeOf:Rr,defineProperty:sn,getOwnPropertyNames:$r}=Object;var Tr=Object.prototype.hasOwnProperty;var W=(n,r,t)=>{t=n!=null?kr(Rr(n)):{};let e=r||!n||!n.__esModule?sn(t,"default",{value:n,enumerable:!0}):t;for(let o of $r(n))if(!Tr.call(e,o))sn(e,o,{get:()=>n[o],enumerable:!0});return e};var Ir=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var Mr=(n,r)=>{for(var t in r)sn(n,t,{get:r[t],enumerable:!0,configurable:!0,set:(e)=>r[t]=()=>e})};var p=(n,r)=>()=>(n&&(r=n(n=0)),r);var jr=import.meta.require;var v=Ir((we,an)=>{var Z=process||{},Sn=Z.argv||[],Q=Z.env||{},Er=!(!!Q.NO_COLOR||Sn.includes("--no-color"))&&(!!Q.FORCE_COLOR||Sn.includes("--color")||Z.platform==="win32"||(Z.stdout||{}).isTTY&&Q.TERM!=="dumb"||!!Q.CI),Ur=(n,r,t=n)=>(e)=>{let o=""+e,i=o.indexOf(r,n.length);return~i?n+_r(o,r,t,i)+r:n+o+r},_r=(n,r,t,e)=>{let o="",i=0;do o+=n.substring(i,e)+t,i=e+r.length,e=n.indexOf(r,i);while(~e);return o+n.substring(i)},Ln=(n=Er)=>{let r=n?Ur:()=>String;return{isColorSupported:n,reset:r("\x1B[0m","\x1B[0m"),bold:r("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:r("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:r("\x1B[3m","\x1B[23m"),underline:r("\x1B[4m","\x1B[24m"),inverse:r("\x1B[7m","\x1B[27m"),hidden:r("\x1B[8m","\x1B[28m"),strikethrough:r("\x1B[9m","\x1B[29m"),black:r("\x1B[30m","\x1B[39m"),red:r("\x1B[31m","\x1B[39m"),green:r("\x1B[32m","\x1B[39m"),yellow:r("\x1B[33m","\x1B[39m"),blue:r("\x1B[34m","\x1B[39m"),magenta:r("\x1B[35m","\x1B[39m"),cyan:r("\x1B[36m","\x1B[39m"),white:r("\x1B[37m","\x1B[39m"),gray:r("\x1B[90m","\x1B[39m"),bgBlack:r("\x1B[40m","\x1B[49m"),bgRed:r("\x1B[41m","\x1B[49m"),bgGreen:r("\x1B[42m","\x1B[49m"),bgYellow:r("\x1B[43m","\x1B[49m"),bgBlue:r("\x1B[44m","\x1B[49m"),bgMagenta:r("\x1B[45m","\x1B[49m"),bgCyan:r("\x1B[46m","\x1B[49m"),bgWhite:r("\x1B[47m","\x1B[49m"),blackBright:r("\x1B[90m","\x1B[39m"),redBright:r("\x1B[91m","\x1B[39m"),greenBright:r("\x1B[92m","\x1B[39m"),yellowBright:r("\x1B[93m","\x1B[39m"),blueBright:r("\x1B[94m","\x1B[39m"),magentaBright:r("\x1B[95m","\x1B[39m"),cyanBright:r("\x1B[96m","\x1B[39m"),whiteBright:r("\x1B[97m","\x1B[39m"),bgBlackBright:r("\x1B[100m","\x1B[49m"),bgRedBright:r("\x1B[101m","\x1B[49m"),bgGreenBright:r("\x1B[102m","\x1B[49m"),bgYellowBright:r("\x1B[103m","\x1B[49m"),bgBlueBright:r("\x1B[104m","\x1B[49m"),bgMagentaBright:r("\x1B[105m","\x1B[49m"),bgCyanBright:r("\x1B[106m","\x1B[49m"),bgWhiteBright:r("\x1B[107m","\x1B[49m")}};an.exports=Ln();an.exports.createColors=Ln});function V(n){Rn=n??!1}class A{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=d.default.blue;mutedColor=d.default.dim;infoColor=d.default.cyan;warnColor=d.default.yellow;errorColor=d.default.red;defaultColor=d.default.white;progressFgColorMap={ESM:d.default.yellow,CJS:d.default.green,IIFE:d.default.magenta,DTS:d.default.blue};progressBgColorMap={ESM:d.default.bgYellow,CJS:d.default.bgGreen,IIFE:d.default.bgMagenta,DTS:d.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!A.instance)A.instance=new A;return A.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({fgColor:n,bgColor:r,label:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=i?this.mutedColor(e):e,a=o?` ${r(d.default.black(` ${o} `))}`:"";return`${n(t)} ${s}${c}${a}`}output(n,r={},t=console.log){if(Rn||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(n),r.verticalSpace)t("")}cli(n,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:d.default.bgBlue,label:this.labels.cli,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(n,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:d.default.bgCyan,label:this.labels.info,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(n,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:d.default.bgYellow,label:this.labels.warn,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(n,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:d.default.bgRed,label:this.labels.error,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(n){for(let[r,t]of Object.entries(this.progressFgColorMap))if(n.includes(r))return t;return this.defaultColor}getProgressBgColor(n){for(let[r,t]of Object.entries(this.progressBgColorMap))if(n.includes(r))return t;return d.default.bgWhite}progress(n,r,t={}){let e=this.getProgressFgColor(n),o=this.getProgressBgColor(n),i=this.formatMessage({fgColor:e,bgColor:o,label:n,message:r,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var d,Rn=!1,l;var L=p(()=>{d=W(v(),1);l=A.getInstance()});function gn(n){return n instanceof D}var b,I,M,w,C,z,D,y=(n)=>{if(n instanceof Error)return n.message;return String(n)},Hr,cn=(n,r)=>{let t=y(n),e=r?`[${r}] `:"",o=gn(n),i="ERROR";if(n instanceof M)i="BUILD ERROR";else if(n instanceof w)i="DTS ERROR";else if(n instanceof C)i="CLI ERROR";else if(n instanceof z)i="WATCH ERROR";else if(o)i="ISOLATED DECL ERROR";else if(n instanceof I)i="BUNUP ERROR";let s=Hr.find((c)=>c.pattern.test(t)&&(c.errorType===i||!c.errorType));if(!s&&!o)console.error(`${b.default.red(i)} ${e}${t}`);if(s)console.log(`
4
4
  `),s.logSolution(t),console.log(`
5
- `);else if(!i)console.error(b.default.dim(b.default.white("If you think this is a bug, please open an issue at: ")+b.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$n=(n,r)=>{cn(n,r),process.exit(1)};var B=p(()=>{b=W(v(),1);L();I=class I extends Error{constructor(n){super(n);this.name="BunupError"}};j=class j extends I{constructor(n){super(n);this.name="BunupBuildError"}};w=class w extends I{constructor(n){super(n);this.name="BunupDTSBuildError"}};C=class C extends I{constructor(n){super(n);this.name="BunupCLIError"}};z=class z extends I{constructor(n){super(n);this.name="BunupWatchError"}};D=class D extends I{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};Hr=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.error(b.default.white("You're trying to build a project that uses Bun. ")+b.default.white("Please set the target option to ")+b.default.cyan("`bun`")+b.default.white(`.
6
- `)+b.default.white("Example: ")+b.default.green("`bunup --target bun`")+b.default.white(" or in config: ")+b.default.green("{ target: 'bun' }"))}}]});import Tn from"fs/promises";import Wr from"path";function In(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function jn(n){return Array.isArray(n)?n:[n]}function Mn(n,r){switch(n){case"esm":return E(r)?".js":".mjs";case"cjs":return E(r)?".cjs":".js";case"iife":return".global.js"}}function An(n,r){switch(n){case"esm":return E(r)?".d.ts":".d.mts";case"cjs":return E(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function ln(n){return n==="node"||n==="bun"}function E(n){return n==="module"}function X(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function En(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function M(n,r=3){return n.split("/").slice(-r).join("/")}async function Un(n,r){let t=Wr.join(n,r);try{await Tn.rm(t,{recursive:!0,force:!0})}catch(e){throw new j(`Failed to clean output directory: ${e}`)}await Tn.mkdir(t,{recursive:!0})}var k=p(()=>{B()});function vr(n){return En(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function _n(n,r){return typeof r==="string"?r===n:r.test(n)}function J(n,r,t){let i=vr(t).some((s)=>s.test(n))||r.external?.some((s)=>_n(n,s)),o=r.noExternal?.some((s)=>_n(n,s));return i&&!o}var mn=p(()=>{k()});import{resolveTsImportPath as qr}from"ts-import-resolver";var Y="\x00dts:",Hn=(n,r,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(un(e))return e;if(!i||!un(i))return null;let o=r.tsconfig?qr({path:e,importer:q(i),tsconfig:r.tsconfig,rootDir:t}):null;if(!o)return null;let s=R(o);if(n.has(s))return N(s);return null},load(e){if(e.startsWith(Y)){let i=q(e),o=n.get(i);if(o)return o}return null}}};var fn=p(()=>{$()});function F(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function Wn(n){return dn.test(n)&&!F(n)}function U(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))&&!F(n)}function R(n){if(F(n))return n;if(n.endsWith(".mts"))return`${n.slice(0,-4)}.d.mts`;if(n.endsWith(".cts"))return`${n.slice(0,-4)}.d.cts`;if(dn.test(n))return n.replace(dn,".d.ts");return`${n}.d.ts`}function un(n){return n.startsWith(Y)}function q(n){return n.replace(Y,"")}function N(n){return`${Y}${n}`}function vn(n,r){if(r===void 0)return"";let t=n.slice(0,r).split(`
7
- `),e=t.length,i=t[t.length-1].length+1;return` (${e}:${i})`}function qn(n,r,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let i of e)if(typeof i==="string"&&n===i)return!1;else if(i instanceof RegExp&&i.test(n))return!1}return J(n,r,t)}var dn;var $=p(()=>{mn();fn();dn=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import{basename as Yr,dirname as Fr,extname as Kr}from"path";function P(n){let r=Yr(n),t=Kr(r);return t?r.slice(0,-t.length):r}function K(n){if(typeof n==="string")return[{fullEntryPath:n,name:P(n)}];if(typeof n==="object"&&!Array.isArray(n))return Object.entries(n).map(([e,i])=>({fullEntryPath:i,name:e}));let r=[],t=new Set;for(let e of n){let i=P(e);if(!t.has(i)){r.push({fullEntryPath:e,name:i}),t.add(i);continue}let s=Fr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,g;do g=`${i}_${a++}`;while(t.has(g));r.push({fullEntryPath:e,name:g}),t.add(g);continue}let c=!1;for(let a=1;a<=s.length&&!c;a++){let m=`${s.slice(-a).join("/")}/${i}`;if(!t.has(m))r.push({fullEntryPath:e,name:m}),t.add(m),c=!0}if(!c){let a=1,g;do g=`${s.join("/")}/${i}_${a++}`;while(t.has(g));r.push({fullEntryPath:e,name:g}),t.add(g)}}return r}function Yn(n){return n.filter((r)=>U(r.fullEntryPath))}function Fn(n,r){return`[dir]/${n}${r}`}var nn=p(()=>{$()});import Vr from"path";import{loadConfig as Qn}from"coffi";async function Zn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:Vr.resolve(r,e.root),options:In(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function Vn(n){let{config:r,filepath:t}=await Qn({name:"package",cwd:n,extensions:[".json"]});return{packageJson:r,path:t}}async function zn(n,r){let{config:t,filepath:e}=await Qn({name:"tsconfig",cwd:n,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:e}}var bn=p(()=>{k()});import Dn from"path";import{ResolverFactory as zr}from"oxc-resolver";function Xn(n,r){return{name:"bunup:types-resolve",buildStart(){xn||=new zr({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...n.path&&{tsconfig:{configFile:n.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(r===!1)return;if(t==="bun")return;let i=e?q(e):void 0;if(/\0/.test(t))return;if(Array.isArray(r)){if(!r.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let o=i?Dn.dirname(i):process.cwd(),{path:s}=await xn.async(o,t);if(!s)return;if(Wn(s)){let c=R(s);try{let{path:a}=await xn.async(Dn.dirname(s),c);if(a)return a}catch(a){}return}return s}}}var xn;var Jn=p(()=>{$()});import{build as Dr}from"rolldown";import{dts as Xr}from"rolldown-plugin-dts";async function Nn(n,r,t,e,i,o){let s=R(n),c=N(s),a=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:g}=await Dr({input:c,output:{dir:t.outDir},write:!1,...i.path&&{resolve:{tsconfigFilename:i.path}},onwarn(m,u){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;u(m)},plugins:[Hn(r,i,o),a&&Xn(i,a),Xr({dtsInput:!0,emitDtsOnly:!0})],external:(m)=>qn(m,t,e,a)});if(!g[0]?.code)return l.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return g[0].code}catch(g){throw new w(`DTS bundling failed for entry "${n}": ${y(g)}`)}}var Pn=p(()=>{B();L();Jn();$();fn()});import{resolveTsImportPath as Jr}from"ts-import-resolver";function oe(n){let r=new Set,t=[Nr,Pr,ne,re,ee,te,ie];for(let e of t){let i=n.matchAll(e);for(let o of i)if(o[1])r.add(o[1])}return r}async function nr(n,r,t){let e=new Set([n]),i=[n];while(i.length){let o=i.pop();if(!o)continue;try{let s=await Bun.file(o).text(),c=oe(s);for(let a of c){let g=r.tsconfig?Jr({path:a,importer:o,tsconfig:r.tsconfig,rootDir:t}):null;if(!g||!(U(g)||F(g)))continue;if(!e.has(g))e.add(g),i.push(g)}}catch(s){l.warn(`Error processing ${o}: ${y(s)}`)}}return e}var Nr,Pr,ne,re,ee,te,ie;var rr=p(()=>{B();L();$();Nr=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Pr=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ne=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,re=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ee=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,te=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ie=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g});import{isolatedDeclaration as se}from"oxc-transform";async function er(n,r){let t=!1,e=new Map;if(await Promise.all([...n].map(async(i)=>{try{let o=R(i);if(!await Bun.file(i).exists())return;let c=await Bun.file(i).text(),{code:a,errors:g}=se(i,c);if(a)e.set(o,a);for(let m of g){if(!t&&!r)console.log(`
8
- `);let u=m.labels[0],f=u?vn(c,u.start):"",h=`${M(i)}${f}: ${ae(m.message)}`;l[r?"warn":"error"](h),t=!0}}catch(o){l.warn(`Failed to generate declaration for ${i}: ${y(o)}`)}})),t&&!r)throw console.log(`
5
+ `);else if(!o)console.error(b.default.dim(b.default.white("If you think this is a bug, please open an issue at: ")+b.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$n=(n,r)=>{cn(n,r),process.exit(1)};var B=p(()=>{b=W(v(),1);L();I=class I extends Error{constructor(n){super(n);this.name="BunupError"}};M=class M extends I{constructor(n){super(n);this.name="BunupBuildError"}};w=class w extends I{constructor(n){super(n);this.name="BunupDTSBuildError"}};C=class C extends I{constructor(n){super(n);this.name="BunupCLIError"}};z=class z extends I{constructor(n){super(n);this.name="BunupWatchError"}};D=class D extends I{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};Hr=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.error(b.default.white("You're trying to build a project that uses Bun. ")+b.default.white("Please set the target option to ")+b.default.cyan("`bun`")+b.default.white(`.
6
+ `)+b.default.white("Example: ")+b.default.green("`bunup --target bun`")+b.default.white(" or in config: ")+b.default.green("{ target: 'bun' }"))}}]});import Tn from"fs/promises";import Wr from"path";function In(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function Mn(n){return Array.isArray(n)?n:[n]}function jn(n,r){switch(n){case"esm":return E(r)?".js":".mjs";case"cjs":return E(r)?".cjs":".js";case"iife":return".global.js"}}function An(n,r){switch(n){case"esm":return E(r)?".d.ts":".d.mts";case"cjs":return E(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function ln(n){return n==="node"||n==="bun"}function E(n){return n==="module"}function X(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function En(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function j(n,r=3){return n.split("/").slice(-r).join("/")}async function Un(n,r){let t=Wr.join(n,r);try{await Tn.rm(t,{recursive:!0,force:!0})}catch(e){throw new M(`Failed to clean output directory: ${e}`)}await Tn.mkdir(t,{recursive:!0})}var k=p(()=>{B()});function vr(n){return En(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function _n(n,r){return typeof r==="string"?r===n:r.test(n)}function J(n,r,t){let o=vr(t).some((s)=>s.test(n))||r.external?.some((s)=>_n(n,s)),i=r.noExternal?.some((s)=>_n(n,s));return o&&!i}var mn=p(()=>{k()});import{resolveTsImportPath as Yr}from"ts-import-resolver";var q="\x00dts:",Hn=(n,r,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(un(e))return e;if(!o||!un(o))return null;let i=r.tsconfig?Yr({path:e,importer:Y(o),tsconfig:r.tsconfig,rootDir:t}):null;if(!i)return null;let s=R(i);if(n.has(s))return N(s);return null},load(e){if(e.startsWith(q)){let o=Y(e),i=n.get(o);if(i)return i}return null}}};var fn=p(()=>{$()});function F(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function Wn(n){return dn.test(n)&&!F(n)}function U(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))&&!F(n)}function R(n){if(F(n))return n;if(n.endsWith(".mts"))return`${n.slice(0,-4)}.d.mts`;if(n.endsWith(".cts"))return`${n.slice(0,-4)}.d.cts`;if(dn.test(n))return n.replace(dn,".d.ts");return`${n}.d.ts`}function un(n){return n.startsWith(q)}function Y(n){return n.replace(q,"")}function N(n){return`${q}${n}`}function vn(n,r){if(r===void 0)return"";let t=n.slice(0,r).split(`
7
+ `),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function Yn(n,r,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let o of e)if(typeof o==="string"&&n===o)return!1;else if(o instanceof RegExp&&o.test(n))return!1}return J(n,r,t)}var dn;var $=p(()=>{mn();fn();dn=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import{basename as qr,dirname as Fr,extname as Kr}from"path";function P(n){let r=qr(n),t=Kr(r);return t?r.slice(0,-t.length):r}function K(n){if(typeof n==="string")return[{fullEntryPath:n,name:P(n)}];if(typeof n==="object"&&!Array.isArray(n))return Object.entries(n).map(([e,o])=>({fullEntryPath:o,name:e}));let r=[],t=new Set;for(let e of n){let o=P(e);if(!t.has(o)){r.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=Fr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,g;do g=`${o}_${a++}`;while(t.has(g));r.push({fullEntryPath:e,name:g}),t.add(g);continue}let c=!1;for(let a=1;a<=s.length&&!c;a++){let m=`${s.slice(-a).join("/")}/${o}`;if(!t.has(m))r.push({fullEntryPath:e,name:m}),t.add(m),c=!0}if(!c){let a=1,g;do g=`${s.join("/")}/${o}_${a++}`;while(t.has(g));r.push({fullEntryPath:e,name:g}),t.add(g)}}return r}function qn(n){return n.filter((r)=>U(r.fullEntryPath))}function Fn(n,r){return`[dir]/${n}${r}`}var nn=p(()=>{$()});import Vr from"path";import{loadConfig as Qn}from"coffi";async function Zn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:Vr.resolve(r,e.root),options:In(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function Vn(n){let{config:r,filepath:t}=await Qn({name:"package",cwd:n,extensions:[".json"]});return{packageJson:r,path:t}}async function zn(n,r){let{config:t,filepath:e}=await Qn({name:"tsconfig",cwd:n,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:e}}var bn=p(()=>{k()});import Dn from"path";import{ResolverFactory as zr}from"oxc-resolver";function Xn(n,r){return{name:"bunup:types-resolve",buildStart(){xn||=new zr({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...n.path&&{tsconfig:{configFile:n.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(r===!1)return;if(t==="bun")return;let o=e?Y(e):void 0;if(/\0/.test(t))return;if(Array.isArray(r)){if(!r.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let i=o?Dn.dirname(o):process.cwd(),{path:s}=await xn.async(i,t);if(!s)return;if(Wn(s)){let c=R(s);try{let{path:a}=await xn.async(Dn.dirname(s),c);if(a)return a}catch(a){}return}return s}}}var xn;var Jn=p(()=>{$()});import{build as Dr}from"rolldown";import{dts as Xr}from"rolldown-plugin-dts";async function Nn(n,r,t,e,o,i){let s=R(n),c=N(s),a=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:g}=await Dr({input:c,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(m,u){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;u(m)},plugins:[Hn(r,o,i),a&&Xn(o,a),Xr({dtsInput:!0,emitDtsOnly:!0})],external:(m)=>Yn(m,t,e,a)});if(!g[0]?.code)return l.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return g[0].code}catch(g){throw new w(`DTS bundling failed for entry "${n}": ${y(g)}`)}}var Pn=p(()=>{B();L();Jn();$();fn()});import{resolveTsImportPath as Jr}from"ts-import-resolver";function ie(n){let r=new Set,t=[Nr,Pr,ne,re,ee,te,oe];for(let e of t){let o=n.matchAll(e);for(let i of o)if(i[1])r.add(i[1])}return r}async function nr(n,r,t){let e=new Set([n]),o=[n];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),c=ie(s);for(let a of c){let g=r.tsconfig?Jr({path:a,importer:i,tsconfig:r.tsconfig,rootDir:t}):null;if(!g||!(U(g)||F(g)))continue;if(!e.has(g))e.add(g),o.push(g)}}catch(s){l.warn(`Error processing ${i}: ${y(s)}`)}}return e}var Nr,Pr,ne,re,ee,te,oe;var rr=p(()=>{B();L();$();Nr=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Pr=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ne=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,re=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ee=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,te=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,oe=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g});import{isolatedDeclaration as se}from"oxc-transform";async function er(n,r){let t=!1,e=new Map;if(await Promise.all([...n].map(async(o)=>{try{let i=R(o);if(!await Bun.file(o).exists())return;let c=await Bun.file(o).text(),{code:a,errors:g}=se(o,c);if(a)e.set(i,a);for(let m of g){if(!t&&!r)console.log(`
8
+ `);let u=m.labels[0],f=u?vn(c,u.start):"",h=`${j(o)}${f}: ${ae(m.message)}`;l[r?"warn":"error"](h),t=!0}}catch(i){l.warn(`Failed to generate declaration for ${o}: ${y(i)}`)}})),t&&!r)throw console.log(`
9
9
  `),console.log(hn.default.gray(`See ${hn.default.blue("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")} for details.`)),console.log(`
10
- `),new D;return e}function ae(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var hn;var tr=p(()=>{hn=W(v(),1);B();L();k();$()});import ir from"fs/promises";import wn from"path";async function or(n,r){let t=wn.resolve(n),e=wn.resolve(t,r);if(!await ir.exists(t))throw new w(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new w(`Entry file does not exist: ${e}`);if(!U(e))throw new w(`Entry file must be a TypeScript file: ${e}`);if(wn.relative(t,e).startsWith(".."))throw new w(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}var sr=p(()=>{B();$()});async function ar(n,r,t,e,i){let{absoluteEntry:o}=await or(n,r),s=await nr(o,e,n),c=await er(s,t.watch);return Nn(o,c,t,i,e,n)}var gr=p(()=>{Pn();rr();tr();sr()});function tn(n){return{...ge,...n}}function cr(n){let{minify:r,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:i}=n,o=r===!0;return{whitespace:t??o,identifiers:e??o,syntax:i??o}}function lr(n,r){return r==="cjs"?n:void 0}function mr(n,r,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((i,o)=>{let s=JSON.stringify(t[o]);return i[`process.env.${o}`]=s,i[`import.meta.env.${o}`]=s,i},{}),...n,...e==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function ur(n,r){return n===void 0?r==="esm":n}function fr(n){return typeof n==="string"?n:void 0}var ge;var yn=p(()=>{ge={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function dr(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let i=e.path;if(J(i,n,r))return{path:i,external:!0};return null})}}}var pr=p(()=>{mn()});function br({format:n,target:r,shims:t}){let i=le(t).map((o)=>Cn[o]).filter((o)=>o.appliesTo(n,r));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:ce},async({path:s})=>{let c=await Bun.file(s).text(),a=i.filter((f)=>f.isNeededInFile(c));if(a.length===0)return;let{shebangLine:g,codeContent:m}=me(c),u=a.map((f)=>f.generateCode()).join("");return{contents:g+u+m}})}}}function le(n){if(n===!0)return Object.keys(Cn);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in Cn)).map(([r])=>r)}function me(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
10
+ `),new D;return e}function ae(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var hn;var tr=p(()=>{hn=W(v(),1);B();L();k();$()});import or from"fs/promises";import wn from"path";async function ir(n,r){let t=wn.resolve(n),e=wn.resolve(t,r);if(!await or.exists(t))throw new w(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new w(`Entry file does not exist: ${e}`);if(!U(e))throw new w(`Entry file must be a TypeScript file: ${e}`);if(wn.relative(t,e).startsWith(".."))throw new w(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}var sr=p(()=>{B();$()});async function ar(n,r,t,e,o){let{absoluteEntry:i}=await ir(n,r),s=await nr(i,e,n),c=await er(s,t.watch);return Nn(i,c,t,o,e,n)}var gr=p(()=>{Pn();rr();tr();sr()});function tn(n){return{...ge,...n}}function cr(n){let{minify:r,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=n,i=r===!0;return{whitespace:t??i,identifiers:e??i,syntax:o??i}}function lr(n,r){return r==="cjs"?n:void 0}function mr(n,r,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((o,i)=>{let s=JSON.stringify(t[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...n,...e==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function ur(n,r){return n===void 0?r==="esm":n}function fr(n){return typeof n==="string"?n:void 0}var ge;var yn=p(()=>{ge={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function dr(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(J(o,n,r))return{path:o,external:!0};return null})}}}var pr=p(()=>{mn()});function br({format:n,target:r,shims:t}){let o=le(t).map((i)=>Cn[i]).filter((i)=>i.appliesTo(n,r));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:ce},async({path:s})=>{let c=await Bun.file(s).text(),a=o.filter((f)=>f.isNeededInFile(c));if(a.length===0)return;let{shebangLine:g,codeContent:m}=me(c),u=a.map((f)=>f.generateCode()).join("");return{contents:g+u+m}})}}}function le(n){if(n===!0)return Object.keys(Cn);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in Cn)).map(([r])=>r)}function me(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
11
11
  `);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var ce,Cn;var xr=p(()=>{k();ce=/\.(js|ts|jsx|tsx|mts|cts)$/,Cn={dirnameFilename:{appliesTo:(n,r)=>n==="esm"&&ln(r),isNeededInFile:(n)=>/\b__dirname\b/.test(n)||/\b__filename\b/.test(n),generateCode:()=>`import { fileURLToPath } from 'url';
12
12
  import { dirname } from 'path';
13
13
 
@@ -18,7 +18,7 @@ var kr=Object.create;var{getPrototypeOf:Rr,defineProperty:sn,getOwnPropertyNames
18
18
 
19
19
  const importMetaUrl = pathToFileURL(__filename).href;
20
20
 
21
- `}}});function hr(n){if(!n)return[];return n.filter((r)=>r.type==="bun")}function wr(n){if(!n)return[];return n.filter((r)=>r.type==="bunup")}async function yr(n,r){if(!n)return;for(let t of n)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(r)}async function Cr(n,r,t){if(!n)return;for(let e of n)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:r,output:t})}var Sr={};jr(Sr,{build:()=>Bn});async function Bn(n,r=process.cwd()){let t={files:[]},e=tn(n);if(!e.entry||e.entry.length===0||!e.outDir)throw new j("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)Un(r,e.outDir);V(e.silent);let{packageJson:i,path:o}=await Vn(r);if(i&&o)l.cli(`Using ${M(o,2)}`,{muted:!0,identifier:e.name,once:`${o}:${e.name}`});let s=wr(e.plugins);await yr(s,e);let c=K(e.entry),a=i?.type;if(!e.dtsOnly){let g=[dr(e,i),...hr(e.plugins).map((u)=>u.plugin)],m=e.format.flatMap((u)=>c.map(async(f)=>{let T=e.outputExtension?.({format:u,packageType:a,options:e,entry:f}).js??Mn(u,a),h=await Bun.build({entrypoints:[`${r}/${f.fullEntryPath}`],format:u,naming:{entry:Fn(f.name,T)},splitting:ur(e.splitting,u),bytecode:lr(e.bytecode,u),define:mr(e.define,e.shims,e.env,u),minify:cr(e),outdir:`${r}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:fr(e.env),plugins:[...g,br({format:u,target:e.target,shims:e.shims})],throw:!1});if(!h.success)for(let S of h.logs){if(S.level==="error")throw new j(S.message);if(S.level==="warning")l.warn(S.message);else if(S.level==="info")l.info(S.message)}let _=Br(e.outDir,f.name,T),H=Or(r,_);t.files.push({fullPath:H,relativePathToOutputDir:_}),l.progress(u.toUpperCase(),_,{identifier:e.name})}));await Promise.all(m)}if(e.dts||e.dtsOnly){let g=await zn(r,e.preferredTsconfigPath);if(g.path)l.cli(`Using ${M(g.path,2)}`,{muted:!0,identifier:e.name,once:`${g.path}:${e.name}`});let m=e.format.filter((f)=>{if(f==="iife"&&!E(a)&&e.format.includes("cjs"))return!1;return!0}),u=typeof e.dts==="object"&&e.dts.entry?K(e.dts.entry):Yn(c);try{await Promise.all(u.map(async(f)=>{let T=await ar(r,f.fullEntryPath,e,g,i);await Promise.all(m.map(async(h)=>{let _=e.outputExtension?.({format:h,packageType:a,options:e,entry:f}).dts??An(h,a),H=Br(e.outDir,f.name,_),S=Or(r,H);t.files.push({fullPath:S,relativePathToOutputDir:H}),await Bun.write(S,T),l.progress("DTS",H,{identifier:e.name})}))}))}catch(f){if(gn(f))throw f;throw new w(y(f))}}if(await Cr(s,e,t),e.onSuccess)await e.onSuccess(e)}function Br(n,r,t){return`${n}/${r}${t}`}function Or(n,r){return`${n}/${r}`}var On=p(()=>{gr();B();nn();bn();L();yn();pr();xr();k()});import{exec as fe}from"tinyexec";var G="0.5.1";var pn=W(v(),1);var kn="https://bunup.dev/docs/guide/cli-options";B();nn();L();function x(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function O(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new C(`Option --${n} requires a string value`)}}function rn(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new C(`Option --${n} requires a string value`)}}function Gr(n){return(r,t)=>{if(typeof r==="boolean")t[n]=r;else if(typeof r==="string")if(r.toLowerCase()==="true"||r.toLowerCase()==="false")t[n]=r.toLowerCase()==="true";else t[n]=r;else throw new C(`Option --${n} requires a boolean or string value`)}}function Qr(){console.log(`
21
+ `}}});function hr(n){if(!n)return[];return n.filter((r)=>r.type==="bun")}function wr(n){if(!n)return[];return n.filter((r)=>r.type==="bunup")}async function yr(n,r){if(!n)return;for(let t of n)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(r)}async function Cr(n,r,t){if(!n)return;for(let e of n)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:r,output:t})}var Sr={};Mr(Sr,{build:()=>Bn});async function Bn(n,r=process.cwd()){let t={files:[]},e=tn(n);if(!e.entry||e.entry.length===0||!e.outDir)throw new M("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)Un(r,e.outDir);V(e.silent);let{packageJson:o,path:i}=await Vn(r);if(o&&i)l.cli(`Using ${j(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=wr(e.plugins);await yr(s,e);let c=K(e.entry),a=o?.type;if(!e.dtsOnly){let g=[dr(e,o),...hr(e.plugins).map((u)=>u.plugin)],m=e.format.flatMap((u)=>c.map(async(f)=>{let T=e.outputExtension?.({format:u,packageType:a,options:e,entry:f}).js??jn(u,a),h=await Bun.build({entrypoints:[`${r}/${f.fullEntryPath}`],format:u,naming:{entry:Fn(f.name,T)},splitting:ur(e.splitting,u),bytecode:lr(e.bytecode,u),define:mr(e.define,e.shims,e.env,u),minify:cr(e),outdir:`${r}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:fr(e.env),plugins:[...g,br({format:u,target:e.target,shims:e.shims})],throw:!1});if(!h.success)for(let S of h.logs){if(S.level==="error")throw new M(S.message);if(S.level==="warning")l.warn(S.message);else if(S.level==="info")l.info(S.message)}let _=Br(e.outDir,f.name,T),H=Or(r,_);t.files.push({fullPath:H,relativePathToOutputDir:_}),l.progress(u.toUpperCase(),_,{identifier:e.name})}));await Promise.all(m)}if(e.dts||e.dtsOnly){let g=await zn(r,e.preferredTsconfigPath);if(g.path)l.cli(`Using ${j(g.path,2)}`,{muted:!0,identifier:e.name,once:`${g.path}:${e.name}`});let m=e.format.filter((f)=>{if(f==="iife"&&!E(a)&&e.format.includes("cjs"))return!1;return!0}),u=typeof e.dts==="object"&&e.dts.entry?K(e.dts.entry):qn(c);try{await Promise.all(u.map(async(f)=>{let T=await ar(r,f.fullEntryPath,e,g,o);await Promise.all(m.map(async(h)=>{let _=e.outputExtension?.({format:h,packageType:a,options:e,entry:f}).dts??An(h,a),H=Br(e.outDir,f.name,_),S=Or(r,H);t.files.push({fullPath:S,relativePathToOutputDir:H}),await Bun.write(S,T),l.progress("DTS",H,{identifier:e.name})}))}))}catch(f){if(gn(f))throw f;throw new w(y(f))}}if(await Cr(s,e,t),e.onSuccess)await e.onSuccess(e)}function Br(n,r,t){return`${n}/${r}${t}`}function Or(n,r){return`${n}/${r}`}var On=p(()=>{gr();B();nn();bn();L();yn();pr();xr();k()});import{exec as fe}from"tinyexec";var G="0.5.6";var pn=W(v(),1);var kn="https://bunup.dev/docs/guide/cli-options";B();nn();L();function x(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function O(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new C(`Option --${n} requires a string value`)}}function rn(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new C(`Option --${n} requires a string value`)}}function Gr(n){return(r,t)=>{if(typeof r==="boolean")t[n]=r;else if(typeof r==="string")if(r.toLowerCase()==="true"||r.toLowerCase()==="false")t[n]=r.toLowerCase()==="true";else t[n]=r;else throw new C(`Option --${n} requires a boolean or string value`)}}function Qr(){console.log(`
22
22
  Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
23
23
  `),console.log("For more information on available options, visit:"),console.log(`${pn.default.cyan(pn.default.underline(kn))}
24
- `),process.exit(0)}function Zr(){console.log(G),process.exit(0)}var Kn={name:{flags:["n","name"],handler:O("name")},format:{flags:["f","format"],handler:rn("format")},outDir:{flags:["o","out-dir"],handler:O("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:O("banner")},footer:{flags:["ft","footer"],handler:O("footer")},external:{flags:["e","external"],handler:rn("external")},sourcemap:{flags:["sm","sourcemap"],handler:Gr("sourcemap")},target:{flags:["t","target"],handler:O("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:rn("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:O("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:O("config")},publicPath:{flags:["pp","public-path"],handler:O("publicPath")},env:{flags:["env"],handler:O("env")},shims:{flags:["shims"],handler:x("shims")},onSuccess:{flags:["onSuccess"],handler:O("onSuccess")},filter:{flags:["filter"],handler:rn("filter")},entry:{flags:["entry"],handler:(n,r,t)=>{if(typeof n!=="string")throw new C(`Entry${t?` --entry.${t}`:""} requires a string value`);let e=r.entry||{};if(t){if(e[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);e[t]=n}else{let i=P(n);if(e[i])l.warn(`Duplicate entry name '${i}' derived from '${n}'. Overwriting previous entry.`);e[i]=n}r.entry=e}},resolveDts:{flags:["rd","resolve-dts"],handler:(n,r)=>{if(!r.dts)r.dts={};if(typeof r.dts==="boolean")r.dts={};if(typeof n==="string")if(n==="true"||n==="false")r.dts.resolve=n==="true";else r.dts.resolve=n.split(",");else r.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>Qr()},version:{flags:["v","version"],handler:()=>Zr()}},en={};for(let n of Object.values(Kn))for(let r of n.flags)en[r]=n.handler;function Gn(n){let r={};for(let t=0;t<n.length;t++){let e=n[t];if(e.startsWith("--")){let i,o;if(e.includes("=")){let[s,c]=e.slice(2).split("=",2);i=s,o=c}else{i=e.slice(2);let s=n[t+1];if(o=s&&!s.startsWith("-")?s:!0,typeof o==="string")t++}if(i.includes(".")){let[s,c]=i.split(".",2),a=en[s];if(a)a(o,r,c);else throw new C(`Unknown option: --${i}`)}else{let s=en[i];if(s)s(o,r);else throw new C(`Unknown option: --${i}`)}}else if(e.startsWith("-")){let i=e.slice(1),o=n[t+1],s=o&&!o.startsWith("-")?o:!0;if(typeof s==="string")t++;let c=en[i];if(c)c(s,r);else throw new C(`Unknown option: -${i}`)}else Kn.entry.handler(e,r,void 0)}return r}B();L();bn();k();import{loadConfig as de}from"coffi";On();B();nn();L();yn();k();import on from"path";async function Lr(n,r){let t=new Set,e=tn(n),i=K(e.entry);for(let g of i){let m=on.resolve(r,g.fullEntryPath),u=on.dirname(m);t.add(u)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,on.join(r,e.outDir)]}),c=!1,a=async(g=!1)=>{if(c)return;c=!0;try{let m=performance.now();if(await Bn({...e,entry:i.map((u)=>u.fullEntryPath),clean:!1},r),!g)l.cli(`\uD83D\uDCE6 Rebuild finished in ${X(performance.now()-m)}`)}catch(m){cn(m)}finally{c=!1}};s.on("change",(g)=>{let m=on.relative(r,g);l.cli(`File changed: ${m}`,{muted:!0,once:m}),a()}),s.on("error",(g)=>{throw new z(`Watcher error: ${y(g)}`)}),await a(!0)}async function pe(n=Bun.argv.slice(2)){let r=Gn(n);V(r.silent);let t=process.cwd(),{config:e,filepath:i}=await de({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:r.config,packageJsonProperty:"bunup"}),o=!e?[{rootDir:t,options:r}]:await Zn(e,t,r.filter);if(l.cli(`Using bunup v${G} and bun v${Bun.version}`,{muted:!0}),i)l.cli(`Using ${M(i,2)}`,{muted:!0});let s=performance.now();l.cli("Build started");let{build:c}=await Promise.resolve().then(() => (On(),Sr));await Promise.all(o.flatMap(({options:m,rootDir:u})=>{return jn(m).map(async(T)=>{let h={...T,...be(r)};if(h.watch)await Lr(h,u);else await c(h,u)})}));let a=performance.now()-s,g=X(a);if(l.cli(`\u26A1\uFE0F Build completed in ${g}`),r.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)l.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await fe(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function be(n){return{...n,onSuccess:void 0,config:void 0}}pe().catch((n)=>$n(n));
24
+ `),process.exit(0)}function Zr(){console.log(G),process.exit(0)}var Kn={name:{flags:["n","name"],handler:O("name")},format:{flags:["f","format"],handler:rn("format")},outDir:{flags:["o","out-dir"],handler:O("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:O("banner")},footer:{flags:["ft","footer"],handler:O("footer")},external:{flags:["e","external"],handler:rn("external")},sourcemap:{flags:["sm","sourcemap"],handler:Gr("sourcemap")},target:{flags:["t","target"],handler:O("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:rn("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:O("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:O("config")},publicPath:{flags:["pp","public-path"],handler:O("publicPath")},env:{flags:["env"],handler:O("env")},shims:{flags:["shims"],handler:x("shims")},onSuccess:{flags:["onSuccess"],handler:O("onSuccess")},filter:{flags:["filter"],handler:rn("filter")},entry:{flags:["entry"],handler:(n,r,t)=>{if(typeof n!=="string")throw new C(`Entry${t?` --entry.${t}`:""} requires a string value`);let e=r.entry||{};if(t){if(e[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);e[t]=n}else{let o=P(n);if(e[o])l.warn(`Duplicate entry name '${o}' derived from '${n}'. Overwriting previous entry.`);e[o]=n}r.entry=e}},resolveDts:{flags:["rd","resolve-dts"],handler:(n,r)=>{if(!r.dts)r.dts={};if(typeof r.dts==="boolean")r.dts={};if(typeof n==="string")if(n==="true"||n==="false")r.dts.resolve=n==="true";else r.dts.resolve=n.split(",");else r.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>Qr()},version:{flags:["v","version"],handler:()=>Zr()}},en={};for(let n of Object.values(Kn))for(let r of n.flags)en[r]=n.handler;function Gn(n){let r={};for(let t=0;t<n.length;t++){let e=n[t];if(e.startsWith("--")){let o,i;if(e.includes("=")){let[s,c]=e.slice(2).split("=",2);o=s,i=c}else{o=e.slice(2);let s=n[t+1];if(i=s&&!s.startsWith("-")?s:!0,typeof i==="string")t++}if(o.includes(".")){let[s,c]=o.split(".",2),a=en[s];if(a)a(i,r,c);else throw new C(`Unknown option: --${o}`)}else{let s=en[o];if(s)s(i,r);else throw new C(`Unknown option: --${o}`)}}else if(e.startsWith("-")){let o=e.slice(1),i=n[t+1],s=i&&!i.startsWith("-")?i:!0;if(typeof s==="string")t++;let c=en[o];if(c)c(s,r);else throw new C(`Unknown option: -${o}`)}else Kn.entry.handler(e,r,void 0)}return r}B();L();bn();k();import{loadConfig as de}from"coffi";On();B();nn();L();yn();k();import on from"path";async function Lr(n,r){let t=new Set,e=tn(n),o=K(e.entry);for(let g of o){let m=on.resolve(r,g.fullEntryPath),u=on.dirname(m);t.add(u)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,on.join(r,e.outDir)]}),c=!1,a=async(g=!1)=>{if(c)return;c=!0;try{let m=performance.now();if(await Bn({...e,entry:o.map((u)=>u.fullEntryPath),clean:!1},r),!g)l.cli(`\uD83D\uDCE6 Rebuild finished in ${X(performance.now()-m)}`)}catch(m){cn(m)}finally{c=!1}};s.on("change",(g)=>{let m=on.relative(r,g);l.cli(`File changed: ${m}`,{muted:!0,once:m}),a()}),s.on("error",(g)=>{throw new z(`Watcher error: ${y(g)}`)}),await a(!0)}async function pe(n=Bun.argv.slice(2)){let r=Gn(n);V(r.silent);let t=process.cwd(),{config:e,filepath:o}=await de({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:r.config,packageJsonProperty:"bunup"}),i=!e?[{rootDir:t,options:r}]:await Zn(e,t,r.filter);if(l.cli(`Using bunup v${G} and bun v${Bun.version}`,{muted:!0}),o)l.cli(`Using ${j(o,2)}`,{muted:!0});let s=performance.now();l.cli("Build started");let{build:c}=await Promise.resolve().then(() => (On(),Sr));await Promise.all(i.flatMap(({options:m,rootDir:u})=>{return Mn(m).map(async(T)=>{let h={...T,...be(r)};if(h.watch)await Lr(h,u);else await c(h,u)})}));let a=performance.now()-s,g=X(a);if(l.cli(`\u26A1\uFE0F Build completed in ${g}`),r.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)l.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await fe(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function be(n){return{...n,onSuccess:void 0,config:void 0}}pe().catch((n)=>$n(n));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.5.1",
4
+ "version": "0.5.6",
5
5
  "license": "MIT",
6
6
  "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
7
7
  "maintainers": [
@@ -19,8 +19,6 @@
19
19
  "homepage": "https://bunup.dev",
20
20
  "keywords": ["bun", "bunup", "bun-bundler"],
21
21
  "files": ["dist", "./../../LICENSE"],
22
- "main": "./dist/index.cjs",
23
- "module": "./dist/index.js",
24
22
  "dependencies": {
25
23
  "chokidar": "^4.0.3",
26
24
  "coffi": "^0.1.25",
@@ -34,26 +32,17 @@
34
32
  "peerDependencies": {
35
33
  "typescript": ">=4.5.0"
36
34
  },
35
+ "main": "./dist/index.js",
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
37
38
  "exports": {
38
39
  ".": {
39
- "import": {
40
- "types": "./dist/index.d.ts",
41
- "default": "./dist/index.js"
42
- },
43
- "require": {
44
- "types": "./dist/index.d.cts",
45
- "default": "./dist/index.cjs"
46
- }
40
+ "types": "./dist/index.d.ts",
41
+ "default": "./dist/index.js"
47
42
  },
48
43
  "./plugins": {
49
- "import": {
50
- "types": "./dist/plugins.d.ts",
51
- "default": "./dist/plugins.js"
52
- },
53
- "require": {
54
- "types": "./dist/plugins.d.cts",
55
- "default": "./dist/plugins.cjs"
56
- }
44
+ "types": "./dist/plugins.d.ts",
45
+ "default": "./dist/plugins.js"
57
46
  }
58
47
  },
59
48
  "bin": {
@@ -67,6 +56,5 @@
67
56
  "scripts": {
68
57
  "npm-publish": "bun publish --access public --no-git-checks"
69
58
  },
70
- "type": "module",
71
- "types": "./dist/index.d.ts"
59
+ "type": "module"
72
60
  }
package/dist/index.cjs DELETED
@@ -1,17 +0,0 @@
1
- // @bun @bun-cjs
2
- (function(exports, require, module, __filename, __dirname) {var vr=Object.create;var{getPrototypeOf:Pr,defineProperty:O,getOwnPropertyNames:nr,getOwnPropertyDescriptor:rn}=Object,er=Object.prototype.hasOwnProperty;var l=(r,n,t)=>{t=r!=null?vr(Pr(r)):{};let e=n||!r||!r.__esModule?O(t,"default",{value:r,enumerable:!0}):t;for(let o of nr(r))if(!er.call(e,o))O(e,o,{get:()=>r[o],enumerable:!0});return e},rr=new WeakMap,nn=(r)=>{var n=rr.get(r),t;if(n)return n;if(n=O({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")nr(r).map((e)=>!er.call(n,e)&&O(n,e,{get:()=>r[e],enumerable:!(t=rn(r,e))||t.enumerable}));return rr.set(r,n),n},en=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var tn=(r,n)=>{for(var t in n)O(r,t,{get:n[t],enumerable:!0,configurable:!0,set:(e)=>n[t]=()=>e})};var W=en((yn,G)=>{var _=process||{},ir=_.argv||[],A=_.env||{},on=!(!!A.NO_COLOR||ir.includes("--no-color"))&&(!!A.FORCE_COLOR||ir.includes("--color")||_.platform==="win32"||(_.stdout||{}).isTTY&&A.TERM!=="dumb"||!!A.CI),sn=(r,n,t=r)=>(e)=>{let o=""+e,i=o.indexOf(n,r.length);return~i?r+gn(o,n,t,i)+n:r+o+n},gn=(r,n,t,e)=>{let o="",i=0;do o+=r.substring(i,e)+t,i=e+n.length,e=r.indexOf(n,i);while(~e);return o+r.substring(i)},sr=(r=on)=>{let n=r?sn:()=>String;return{isColorSupported:r,reset:n("\x1B[0m","\x1B[0m"),bold:n("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:n("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:n("\x1B[3m","\x1B[23m"),underline:n("\x1B[4m","\x1B[24m"),inverse:n("\x1B[7m","\x1B[27m"),hidden:n("\x1B[8m","\x1B[28m"),strikethrough:n("\x1B[9m","\x1B[29m"),black:n("\x1B[30m","\x1B[39m"),red:n("\x1B[31m","\x1B[39m"),green:n("\x1B[32m","\x1B[39m"),yellow:n("\x1B[33m","\x1B[39m"),blue:n("\x1B[34m","\x1B[39m"),magenta:n("\x1B[35m","\x1B[39m"),cyan:n("\x1B[36m","\x1B[39m"),white:n("\x1B[37m","\x1B[39m"),gray:n("\x1B[90m","\x1B[39m"),bgBlack:n("\x1B[40m","\x1B[49m"),bgRed:n("\x1B[41m","\x1B[49m"),bgGreen:n("\x1B[42m","\x1B[49m"),bgYellow:n("\x1B[43m","\x1B[49m"),bgBlue:n("\x1B[44m","\x1B[49m"),bgMagenta:n("\x1B[45m","\x1B[49m"),bgCyan:n("\x1B[46m","\x1B[49m"),bgWhite:n("\x1B[47m","\x1B[49m"),blackBright:n("\x1B[90m","\x1B[39m"),redBright:n("\x1B[91m","\x1B[39m"),greenBright:n("\x1B[92m","\x1B[39m"),yellowBright:n("\x1B[93m","\x1B[39m"),blueBright:n("\x1B[94m","\x1B[39m"),magentaBright:n("\x1B[95m","\x1B[39m"),cyanBright:n("\x1B[96m","\x1B[39m"),whiteBright:n("\x1B[97m","\x1B[39m"),bgBlackBright:n("\x1B[100m","\x1B[49m"),bgRedBright:n("\x1B[101m","\x1B[49m"),bgGreenBright:n("\x1B[102m","\x1B[49m"),bgYellowBright:n("\x1B[103m","\x1B[49m"),bgBlueBright:n("\x1B[104m","\x1B[49m"),bgMagentaBright:n("\x1B[105m","\x1B[49m"),bgCyanBright:n("\x1B[106m","\x1B[49m"),bgWhiteBright:n("\x1B[107m","\x1B[49m")}};G.exports=sr();G.exports.createColors=sr});var Sn={};tn(Sn,{defineWorkspace:()=>or,defineConfig:()=>tr,build:()=>Nr});module.exports=nn(Sn);function tr(r){return r}function or(r){return r}var Sr=require("rolldown"),kr=require("rolldown-plugin-dts");var mn=l(W());var c=l(W()),gr=!1;function mr(r){gr=r??!1}class h{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=c.default.blue;mutedColor=c.default.dim;infoColor=c.default.cyan;warnColor=c.default.yellow;errorColor=c.default.red;defaultColor=c.default.white;progressFgColorMap={ESM:c.default.yellow,CJS:c.default.green,IIFE:c.default.magenta,DTS:c.default.blue};progressBgColorMap={ESM:c.default.bgYellow,CJS:c.default.bgGreen,IIFE:c.default.bgMagenta,DTS:c.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!h.instance)h.instance=new h;return h.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:n,label:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),u=i?this.mutedColor(e):e,g=o?` ${n(c.default.black(` ${o} `))}`:"";return`${r(t)} ${s}${u}${g}`}output(r,n={},t=console.log){if(gr||!this.shouldLog(n))return;if(n.verticalSpace)t("");if(t(r),n.verticalSpace)t("")}cli(r,n={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:c.default.bgBlue,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(r,n={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:c.default.bgCyan,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(r,n={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:c.default.bgYellow,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(r,n={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:c.default.bgRed,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}getProgressFgColor(r){for(let[n,t]of Object.entries(this.progressFgColorMap))if(r.includes(n))return t;return this.defaultColor}getProgressBgColor(r){for(let[n,t]of Object.entries(this.progressBgColorMap))if(r.includes(n))return t;return c.default.bgWhite}progress(r,n,t={}){let e=this.getProgressFgColor(r),o=this.getProgressBgColor(r),i=this.formatMessage({fgColor:e,bgColor:o,label:r,message:n,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var x=h.getInstance();class U extends Error{constructor(r){super(r);this.name="BunupError"}}class R extends U{constructor(r){super(r);this.name="BunupBuildError"}}class f extends U{constructor(r){super(r);this.name="BunupDTSBuildError"}}class F extends U{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var C=(r)=>{if(r instanceof Error)return r.message;return String(r)};function ur(r){return r instanceof F}var V=l(require("path")),hr=require("oxc-resolver");var H=l(require("fs/promises")),cr=l(require("path"));function ar(r,n){switch(r){case"esm":return S(n)?".js":".mjs";case"cjs":return S(n)?".cjs":".js";case"iife":return".global.js"}}function br(r,n){switch(r){case"esm":return S(n)?".d.ts":".d.mts";case"cjs":return S(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(r){return r==="node"||r==="bun"}function S(r){return r==="module"}function pr(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function T(r,n=3){return r.split("/").slice(-n).join("/")}async function xr(r,n){let t=cr.default.join(r,n);try{await H.default.rm(t,{recursive:!0,force:!0})}catch(e){throw new R(`Failed to clean output directory: ${e}`)}await H.default.mkdir(t,{recursive:!0})}function un(r){return pr(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function fr(r,n){return typeof n==="string"?n===r:n.test(r)}function Y(r,n,t){let o=un(t).some((s)=>s.test(r))||n.external?.some((s)=>fr(r,s)),i=n.noExternal?.some((s)=>fr(r,s));return o&&!i}var dr=require("ts-import-resolver");var $="\x00dts:",lr=(r,n,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(Q(e))return e;if(!o||!Q(o))return null;let i=n.tsconfig?dr.resolveTsImportPath({path:e,importer:E(o),tsconfig:n.tsconfig,rootDir:t}):null;if(!i)return null;let s=B(i);if(r.has(s))return K(s);return null},load(e){if(e.startsWith($)){let o=E(e),i=r.get(o);if(i)return i}return null}}};var Z=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function j(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function Cr(r){return Z.test(r)&&!j(r)}function k(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))&&!j(r)}function B(r){if(j(r))return r;if(r.endsWith(".mts"))return`${r.slice(0,-4)}.d.mts`;if(r.endsWith(".cts"))return`${r.slice(0,-4)}.d.cts`;if(Z.test(r))return r.replace(Z,".d.ts");return`${r}.d.ts`}function Q(r){return r.startsWith($)}function E(r){return r.replace($,"")}function K(r){return`${$}${r}`}function Br(r,n){if(n===void 0)return"";let t=r.slice(0,n).split(`
3
- `),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function wr(r,n,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let o of e)if(typeof o==="string"&&r===o)return!1;else if(o instanceof RegExp&&o.test(r))return!1}return Y(r,n,t)}var z;function Rr(r,n){return{name:"bunup:types-resolve",buildStart(){z||=new hr.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...r.path&&{tsconfig:{configFile:r.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(n===!1)return;if(t==="bun")return;let o=e?E(e):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((g)=>typeof g==="string"?g===t:g.test(t)))return}let i=o?V.default.dirname(o):process.cwd(),{path:s}=await z.async(i,t);if(!s)return;if(Cr(s)){let u=B(s);try{let{path:g}=await z.async(V.default.dirname(s),u);if(g)return g}catch(g){}return}return s}}}async function Lr(r,n,t,e,o,i){let s=B(r),u=K(s),g=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:m}=await Sr.build({input:u,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(p,b){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;b(p)},plugins:[lr(n,o,i),g&&Rr(o,g),kr.dts({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>wr(p,t,e,g)});if(!m[0]?.code)return x.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return m[0].code}catch(m){throw new f(`DTS bundling failed for entry "${r}": ${C(m)}`)}}var yr=require("ts-import-resolver");var cn=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,an=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,bn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,pn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,xn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,fn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,dn=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function ln(r){let n=new Set,t=[cn,an,bn,pn,xn,fn,dn];for(let e of t){let o=r.matchAll(e);for(let i of o)if(i[1])n.add(i[1])}return n}async function Ir(r,n,t){let e=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),u=ln(s);for(let g of u){let m=n.tsconfig?yr.resolveTsImportPath({path:g,importer:i,tsconfig:n.tsconfig,rootDir:t}):null;if(!m||!(k(m)||j(m)))continue;if(!e.has(m))e.add(m),o.push(m)}}catch(s){x.warn(`Error processing ${i}: ${C(s)}`)}}return e}var Mr=require("oxc-transform"),X=l(W());async function Or(r,n){let t=!1,e=new Map;if(await Promise.all([...r].map(async(o)=>{try{let i=B(o);if(!await Bun.file(o).exists())return;let u=await Bun.file(o).text(),{code:g,errors:m}=Mr.isolatedDeclaration(o,u);if(g)e.set(i,g);for(let p of m){if(!t&&!n)console.log(`
4
- `);let b=p.labels[0],a=b?Br(u,b.start):"",w=`${T(o)}${a}: ${Cn(p.message)}`;x[n?"warn":"error"](w),t=!0}}catch(i){x.warn(`Failed to generate declaration for ${o}: ${C(i)}`)}})),t&&!n)throw console.log(`
5
- `),console.log(X.default.gray(`See ${X.default.blue("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")} for details.`)),console.log(`
6
- `),new F;return e}function Cn(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var J=l(require("fs/promises")),q=l(require("path"));async function Tr(r,n){let t=q.default.resolve(r),e=q.default.resolve(t,n);if(!await J.default.exists(t))throw new f(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new f(`Entry file does not exist: ${e}`);if(!k(e))throw new f(`Entry file must be a TypeScript file: ${e}`);if(q.default.relative(t,e).startsWith(".."))throw new f(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function Er(r,n,t,e,o){let{absoluteEntry:i}=await Tr(r,n),s=await Ir(i,e,r),u=await Or(s,t.watch);return Lr(i,u,t,o,e,r)}var L=require("path");function $r(r){let n=L.basename(r),t=L.extname(n);return t?n.slice(0,-t.length):n}function N(r){if(typeof r==="string")return[{fullEntryPath:r,name:$r(r)}];if(typeof r==="object"&&!Array.isArray(r))return Object.entries(r).map(([e,o])=>({fullEntryPath:o,name:e}));let n=[],t=new Set;for(let e of r){let o=$r(e);if(!t.has(o)){n.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=L.dirname(e).split("/").filter((g)=>g!=="."&&g!=="");if(s.length===0){let g=1,m;do m=`${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m);continue}let u=!1;for(let g=1;g<=s.length&&!u;g++){let p=`${s.slice(-g).join("/")}/${o}`;if(!t.has(p))n.push({fullEntryPath:e,name:p}),t.add(p),u=!0}if(!u){let g=1,m;do m=`${s.join("/")}/${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m)}}return n}function jr(r){return r.filter((n)=>k(n.fullEntryPath))}function Ar(r,n){return`[dir]/${r}${n}`}var v=require("coffi");async function _r(r){let{config:n,filepath:t}=await v.loadConfig({name:"package",cwd:r,extensions:[".json"]});return{packageJson:n,path:t}}async function Wr(r,n){let{config:t,filepath:e}=await v.loadConfig({name:"tsconfig",cwd:r,extensions:[".json"],preferredPath:n});return{tsconfig:t,path:e}}var Bn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Ur(r){return{...Bn,...r}}function Fr(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=r,i=n===!0;return{whitespace:t??i,identifiers:e??i,syntax:o??i}}function Yr(r,n){return n==="cjs"?r:void 0}function Kr(r,n,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((o,i)=>{let s=JSON.stringify(t[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...r,...e==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function qr(r,n){return r===void 0?n==="esm":r}function Gr(r){return typeof r==="string"?r:void 0}function Hr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(Y(o,r,n))return{path:o,external:!0};return null})}}}var wn=/\.(js|ts|jsx|tsx|mts|cts)$/,P={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&D(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
7
- import { dirname } from 'path';
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
-
12
- `},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&D(n),isNeededInFile:(r)=>/\bimport\.meta\.url\b/.test(r),generateCode:()=>`import { pathToFileURL } from 'url';
13
-
14
- const importMetaUrl = pathToFileURL(__filename).href;
15
-
16
- `}};function Dr({format:r,target:n,shims:t}){let o=hn(t).map((i)=>P[i]).filter((i)=>i.appliesTo(r,n));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:wn},async({path:s})=>{let u=await Bun.file(s).text(),g=o.filter((a)=>a.isNeededInFile(u));if(g.length===0)return;let{shebangLine:m,codeContent:p}=Rn(u),b=g.map((a)=>a.generateCode()).join("");return{contents:m+b+p}})}}}function hn(r){if(r===!0)return Object.keys(P);if(!r)return[];return Object.entries(r).filter(([n,t])=>t&&(n in P)).map(([n])=>n)}function Rn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
17
- `);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function Qr(r){if(!r)return[];return r.filter((n)=>n.type==="bun")}function Zr(r){if(!r)return[];return r.filter((n)=>n.type==="bunup")}async function zr(r,n){if(!r)return;for(let t of r)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(n)}async function Vr(r,n,t){if(!r)return;for(let e of r)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:n,output:t})}async function Nr(r,n=process.cwd()){let t={files:[]},e=Ur(r);if(!e.entry||e.entry.length===0||!e.outDir)throw new R("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)xr(n,e.outDir);mr(e.silent);let{packageJson:o,path:i}=await _r(n);if(o&&i)x.cli(`Using ${T(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=Zr(e.plugins);await zr(s,e);let u=N(e.entry),g=o?.type;if(!e.dtsOnly){let m=[Hr(e,o),...Qr(e.plugins).map((b)=>b.plugin)],p=e.format.flatMap((b)=>u.map(async(a)=>{let y=e.outputExtension?.({format:b,packageType:g,options:e,entry:a}).js??ar(b,g),w=await Bun.build({entrypoints:[`${n}/${a.fullEntryPath}`],format:b,naming:{entry:Ar(a.name,y)},splitting:qr(e.splitting,b),bytecode:Yr(e.bytecode,b),define:Kr(e.define,e.shims,e.env,b),minify:Fr(e),outdir:`${n}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Gr(e.env),plugins:[...m,Dr({format:b,target:e.target,shims:e.shims})],throw:!1});if(!w.success)for(let d of w.logs){if(d.level==="error")throw new R(d.message);if(d.level==="warning")x.warn(d.message);else if(d.level==="info")x.info(d.message)}let I=Xr(e.outDir,a.name,y),M=Jr(n,I);t.files.push({fullPath:M,relativePathToOutputDir:I}),x.progress(b.toUpperCase(),I,{identifier:e.name})}));await Promise.all(p)}if(e.dts||e.dtsOnly){let m=await Wr(n,e.preferredTsconfigPath);if(m.path)x.cli(`Using ${T(m.path,2)}`,{muted:!0,identifier:e.name,once:`${m.path}:${e.name}`});let p=e.format.filter((a)=>{if(a==="iife"&&!S(g)&&e.format.includes("cjs"))return!1;return!0}),b=typeof e.dts==="object"&&e.dts.entry?N(e.dts.entry):jr(u);try{await Promise.all(b.map(async(a)=>{let y=await Er(n,a.fullEntryPath,e,m,o);await Promise.all(p.map(async(w)=>{let I=e.outputExtension?.({format:w,packageType:g,options:e,entry:a}).dts??br(w,g),M=Xr(e.outDir,a.name,I),d=Jr(n,M);t.files.push({fullPath:d,relativePathToOutputDir:M}),await Bun.write(d,y),x.progress("DTS",M,{identifier:e.name})}))}))}catch(a){if(ur(a))throw a;throw new f(C(a))}}if(await Vr(s,e,t),e.onSuccess)await e.onSuccess(e)}function Xr(r,n,t){return`${r}/${n}${t}`}function Jr(r,n){return`${r}/${n}`}})
package/dist/index.d.cts DELETED
@@ -1,490 +0,0 @@
1
- import _Bun from "bun";
2
-
3
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/helpers/entry.d.ts
4
- type ProcessableEntry = {
5
- fullEntryPath: string
6
- name: string
7
- };
8
-
9
- //#endregion
10
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/plugins/types.d.ts
11
- /**
12
- * Represents a Bun plugin that can be used with Bunup
13
- */
14
- type BunupBunPlugin = {
15
- /** Identifies this as a native Bun plugin */
16
- type: "bun"
17
- /** Optional name for the plugin */
18
- name?: string
19
- /** The actual Bun plugin implementation */
20
- plugin: BunPlugin
21
- };
22
- /**
23
- * Represents the output of a build operation
24
- */
25
- type BuildOutput = {
26
- /** Array of generated files with their paths and contents */
27
- files: Array<{
28
- /** Path to the generated file */
29
- fullPath: string
30
- /** Path to the generated file relative to the output directory */
31
- relativePathToOutputDir: string
32
- }>
33
- };
34
- /**
35
- * Context provided to build hooks
36
- */
37
- type BuildContext = {
38
- /** The build options that were used */
39
- options: BuildOptions
40
- /** The output of the build */
41
- output: BuildOutput
42
- };
43
- /**
44
- * Hooks that can be implemented by Bunup plugins
45
- */
46
- type BunupPluginHooks = {
47
- /**
48
- * Called when a build is successfully completed
49
- * @param ctx Build context containing options and output
50
- */
51
- onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
52
- /**
53
- * Called before a build starts
54
- * @param options Build options that will be used
55
- */
56
- onBuildStart?: (options: BuildOptions) => MaybePromise<void>
57
- };
58
- /**
59
- * Represents a Bunup-specific plugin
60
- */
61
- type BunupPlugin = {
62
- /** Identifies this as a Bunup-specific plugin */
63
- type: "bunup"
64
- /** Optional name for the plugin */
65
- name?: string
66
- /** The hooks implemented by this plugin */
67
- hooks: BunupPluginHooks
68
- };
69
- /**
70
- * Union type representing all supported plugin types
71
- */
72
- type Plugin = BunupBunPlugin | BunupPlugin;
73
-
74
- //#endregion
75
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/options.d.ts
76
- type Loader = NonNullable<BunBuildOptions["loader"]>[string];
77
- type Define = BunBuildOptions["define"];
78
- type Sourcemap = BunBuildOptions["sourcemap"];
79
- type Format = Exclude<BunBuildOptions["format"], undefined>;
80
- type Target = BunBuildOptions["target"];
81
- type External = (string | RegExp)[];
82
- type Env = BunBuildOptions["env"] | Record<string, string>;
83
- type Entry = Arrayable<string> | Record<string, string>;
84
- type ShimOptions = {
85
- /**
86
- * Adds __dirname and __filename shims for ESM files when used
87
- */
88
- dirnameFilename?: boolean
89
- /**
90
- * Adds import.meta.url shims for CJS files when used
91
- */
92
- importMetaUrl?: boolean
93
- };
94
- type Shims = boolean | ShimOptions;
95
- type DtsResolve = boolean | (string | RegExp)[];
96
- type DtsOptions = {
97
- /**
98
- * Entry point files for TypeScript declaration file generation
99
- *
100
- * This can be:
101
- * - A string path to a file
102
- * - An array of file paths
103
- * - An object where keys are output names and values are input file paths
104
- *
105
- * The key names are used for the generated declaration files.
106
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
107
- *
108
- * If not specified, the main entry points will be used for declaration file generation.
109
- *
110
- * If it's a string or an array of strings, the file name (without extension)
111
- * will be used as the name for the output declaration file.
112
- *
113
- * @example
114
- * // Using a string path
115
- * entry: 'src/index.ts' // Generates index.d.ts
116
- *
117
- * // Using string paths in an array
118
- * entry: ['src/index.ts'] // Generates index.d.ts
119
- *
120
- * // Using named outputs as an object
121
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
122
- *
123
- * // Organizing output with subdirectories
124
- * entry: { "client/index": "src/client/index.ts", "server/index": "src/server/index.ts" } // Generates client/index.d.ts and server/index.d.ts
125
- */
126
- entry?: Entry
127
- /**
128
- * Resolve external types used in dts files from node_modules
129
- */
130
- resolve?: DtsResolve
131
- };
132
- interface BuildOptions {
133
- /**
134
- * Name of the build configuration
135
- * Used for logging and identification purposes
136
- */
137
- name?: string;
138
- /**
139
- * Entry point files for the build
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 output files.
147
- * For example, `{custom: 'src/index.ts'}` will generate `custom.js`
148
- *
149
- * If it's a string or an array of strings, the file name (without extension)
150
- * will be used as the name for the output file.
151
- *
152
- * @example
153
- * // Using a string path
154
- * entry: 'src/index.ts' // Generates index.js
155
- *
156
- * // Using string paths in an array
157
- * entry: ['src/index.ts'] // Generates index.js
158
- *
159
- * // Using named outputs as an object
160
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
161
- */
162
- entry: Entry;
163
- /**
164
- * Output directory for the bundled files
165
- * Defaults to 'dist' if not specified
166
- */
167
- outDir: string;
168
- /**
169
- * Output formats for the bundle
170
- * Can include 'esm', 'cjs', and/or 'iife'
171
- * Defaults to ['cjs'] if not specified
172
- */
173
- format: Format[];
174
- /**
175
- * Whether to enable all minification options
176
- * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
177
- */
178
- minify?: boolean;
179
- /**
180
- * Whether to enable code splitting
181
- * Defaults to true for ESM format, false for CJS format
182
- */
183
- splitting?: boolean;
184
- /**
185
- * Whether to minify whitespace in the output
186
- * Removes unnecessary whitespace to reduce file size
187
- */
188
- minifyWhitespace?: boolean;
189
- /**
190
- * Whether to minify identifiers in the output
191
- * Renames variables and functions to shorter names
192
- */
193
- minifyIdentifiers?: boolean;
194
- /**
195
- * Whether to minify syntax in the output
196
- * Optimizes code structure for smaller file size
197
- */
198
- minifySyntax?: boolean;
199
- /**
200
- * Whether to watch for file changes and rebuild automatically
201
- */
202
- watch?: boolean;
203
- /**
204
- * Whether to generate TypeScript declaration files (.d.ts)
205
- * When set to true, generates declaration files for all entry points
206
- * Can also be configured with DtsOptions for more control
207
- */
208
- dts?: boolean | DtsOptions;
209
- /**
210
- * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
211
- * When set to true, bunup will skip the JavaScript bundling process entirely
212
- * and only generate declaration files for the specified entry points
213
- *
214
- * This is useful when you want to use bunup's fast declaration file generation
215
- * but handle the JavaScript bundling separately or not at all.
216
- *
217
- * Note: When this option is true, the `dts` option is implicitly set to true
218
- * and other bundling-related options are ignored.
219
- *
220
- * @example
221
- * dtsOnly: true
222
- */
223
- dtsOnly?: boolean;
224
- /**
225
- * Path to a preferred tsconfig.json file to use for declaration generation
226
- *
227
- * If not specified, the tsconfig.json in the project root will be used.
228
- * This option allows you to use a different TypeScript configuration
229
- * specifically for declaration file generation.
230
- *
231
- * @example
232
- * preferredTsconfigPath: './tsconfig.build.json'
233
- */
234
- preferredTsconfigPath?: string;
235
- /**
236
- * External packages that should not be bundled
237
- * Useful for dependencies that should be kept as external imports
238
- */
239
- external?: External;
240
- /**
241
- * Packages that should be bundled even if they are in external
242
- * Useful for dependencies that should be included in the bundle
243
- */
244
- noExternal?: External;
245
- /**
246
- * The target environment for the bundle
247
- * Can be 'browser', 'bun', 'node', etc.
248
- * Defaults to 'node' if not specified
249
- */
250
- target?: Target;
251
- /**
252
- * Whether to clean the output directory before building
253
- * When true, removes all files in the outDir before starting a new build
254
- * Defaults to true if not specified
255
- */
256
- clean?: boolean;
257
- /**
258
- * Specifies the type of sourcemap to generate
259
- * Can be 'none', 'linked', 'external', or 'inline'
260
- * Can also be a boolean - when true, it will use 'inline'
261
- *
262
- * @see https://bun.sh/docs/bundler#sourcemap
263
- *
264
- * @default 'none'
265
- *
266
- * @example
267
- * sourcemap: 'linked'
268
- * // or
269
- * sourcemap: true // equivalent to 'inline'
270
- */
271
- sourcemap?: Sourcemap;
272
- /**
273
- * Define global constants for the build
274
- * These values will be replaced at build time
275
- *
276
- * @see https://bun.sh/docs/bundler#define
277
- *
278
- * @example
279
- * define: {
280
- * 'process.env.NODE_ENV': '"production"',
281
- * 'PACKAGE_VERSION': '"1.0.0"'
282
- * }
283
- */
284
- define?: Define;
285
- /**
286
- * A callback function that runs after the build process completes
287
- * This can be used for custom post-build operations like copying files,
288
- * running additional tools, or logging build information
289
- *
290
- * If watch mode is enabled, this callback runs after each rebuild
291
- *
292
- * @param options The build options that were used
293
- */
294
- onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
295
- /**
296
- * A banner to be added to the final bundle, this can be a directive like "use client" for react or a comment block such as a license for the code.
297
- *
298
- * @see https://bun.sh/docs/bundler#banner
299
- *
300
- * @example
301
- * banner: '"use client";'
302
- */
303
- banner?: string;
304
- /**
305
- * A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
306
- *
307
- * @see https://bun.sh/docs/bundler#footer
308
- *
309
- * @example
310
- * footer: '// built with love in SF'
311
- */
312
- footer?: string;
313
- /**
314
- * Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
315
- *
316
- * @see https://bun.sh/docs/bundler#drop
317
- *
318
- * @example
319
- * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
320
- */
321
- drop?: string[];
322
- /**
323
- * A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
324
- *
325
- * @see https://bun.sh/docs/bundler#loader
326
- *
327
- * @example
328
- * loader: {
329
- * ".png": "dataurl",
330
- * ".txt": "file",
331
- * }
332
- */
333
- loader?: Record<string, Loader>;
334
- /**
335
- * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
336
- *
337
- * Bytecode is currently only supported for CommonJS (format: "cjs").
338
- *
339
- * Must be target: "bun"
340
- *
341
- * @see https://bun.sh/docs/bundler#bytecode
342
- *
343
- * @default false
344
- */
345
- bytecode?: boolean;
346
- /**
347
- * Disable logging during the build process. When set to true, no logs will be printed to the console.
348
- *
349
- * @default false
350
- */
351
- silent?: boolean;
352
- /**
353
- * You can specify a prefix to be added to specific import paths in your bundled code
354
- *
355
- * Used for assets, external modules, and chunk files when splitting is enabled
356
- *
357
- * @see https://bunup.dev/docs#public-path for more information
358
- *
359
- * @example
360
- * publicPath: 'https://cdn.example.com/'
361
- */
362
- publicPath?: string;
363
- /**
364
- * Inject Node.js compatibility shims for ESM/CJS interoperability
365
- *
366
- * When set to true, automatically injects all shims when needed
367
- * When set to an object, only injects the specified shims
368
- *
369
- * Available shims:
370
- * - dirnameFilename: Adds __dirname and __filename for ESM files when used
371
- * - importMetaUrl: Adds import.meta.url for CJS files when used
372
- *
373
- * @example
374
- * // Enable all shims
375
- * shims: true
376
- *
377
- * // Enable only specific shims
378
- * shims: { dirnameFilename: true, importMetaUrl: true }
379
- */
380
- shims?: Shims;
381
- /**
382
- * Controls how environment variables are handled during bundling.
383
- *
384
- * Can be one of:
385
- * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
386
- * of those environment variables at the time the build runs.
387
- * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
388
- * - A string ending in `*`: Only inlines environment variables matching the given prefix.
389
- * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
390
- * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
391
- * with the provided values, regardless of the runtime environment.
392
- *
393
- * Note: Values are injected at build time. Secrets or private keys should be excluded
394
- * from inlining when targeting browser environments.
395
- *
396
- * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
397
- *
398
- * @example
399
- * // Inline all environment variables available at build time
400
- * env: "inline"
401
- *
402
- * // Disable all environment variable injection
403
- * env: "disable"
404
- *
405
- * // Only inline environment variables with a specific prefix
406
- * env: "PUBLIC_*"
407
- *
408
- * // Provide specific environment variables manually
409
- * env: { API_URL: "https://api.example.com", DEBUG: "false" }
410
- */
411
- env?: Env;
412
- /**
413
- * Plugins to extend the build process functionality
414
- *
415
- * The Plugin type uses a discriminated union pattern with the 'type' field
416
- * to support different plugin systems. Currently, only "bun" plugins are supported,
417
- * but in the future, this will be extended to include "bunup" plugins as well.
418
- *
419
- * Each plugin type has its own specific plugin implementation:
420
- * - "bun": Uses Bun's native plugin system (BunPlugin)
421
- * - "bunup": Will use bunup's own plugin system (coming in future versions)
422
- *
423
- * This architecture allows for extensibility as more plugin systems are added.
424
- *
425
- * @example
426
- * plugins: [
427
- * {
428
- * type: "bun",
429
- * plugin: myBunPlugin()
430
- * },
431
- * // In the future:
432
- * // {
433
- * // type: "bunup",
434
- * // plugin: myBunupPlugin()
435
- * // }
436
- * ]
437
- */
438
- plugins?: Plugin[];
439
- /**
440
- * Customize the output file extension for each format.
441
- *
442
- * @param options Contains format, packageType, options, and entry information
443
- * @returns Object with js and dts extensions (including the leading dot)
444
- *
445
- * @example
446
- * outputExtension: ({ format, entry }) => ({
447
- * js: entry.name === 'worker' ? '.worker.js' : `.${format}.js`,
448
- * dts: `.${format}.d.ts`
449
- * })
450
- */
451
- outputExtension?: (options: {
452
- format: Format
453
- packageType: string | undefined
454
- options: BuildOptions
455
- entry: ProcessableEntry
456
- }) => {
457
- js: string
458
- dts: string
459
- };
460
- }
461
-
462
- //#endregion
463
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/types.d.ts
464
- type MaybePromise<T> = Promise<T> | T;
465
- type WithOptional<
466
- T,
467
- K extends keyof T
468
- > = Omit<T, K> & Partial<Pick<T, K>>;
469
- type Arrayable<T> = T | T[];
470
- type Bun = typeof _Bun;
471
- type BunBuildOptions = Parameters<Bun["build"]>[0];
472
- type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
473
- type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
474
- type DefineWorkspaceItem = {
475
- name: string
476
- root: string
477
- config: DefineConfigItem | DefineConfigItem[]
478
- };
479
-
480
- //#endregion
481
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/define.d.ts
482
- declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
483
- declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
484
-
485
- //#endregion
486
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/build.d.ts
487
- declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
488
-
489
- //#endregion
490
- export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin, build, defineConfig, defineWorkspace };
package/dist/plugins.cjs DELETED
@@ -1,2 +0,0 @@
1
- // @bun @bun-cjs
2
- (function(exports, require, module, __filename, __dirname) {var $=Object.create;var{getPrototypeOf:j,defineProperty:p,getOwnPropertyNames:T,getOwnPropertyDescriptor:A}=Object,k=Object.prototype.hasOwnProperty;var y=(r,e,t)=>{t=r!=null?$(j(r)):{};let n=e||!r||!r.__esModule?p(t,"default",{value:r,enumerable:!0}):t;for(let i of T(r))if(!k.call(n,i))p(n,i,{get:()=>r[i],enumerable:!0});return n},L=new WeakMap,S=(r)=>{var e=L.get(r),t;if(e)return e;if(e=p({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")T(r).map((n)=>!k.call(e,n)&&p(e,n,{get:()=>r[n],enumerable:!(t=A(r,n))||t.enumerable}));return L.set(r,e),e},N=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var W=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:!0,configurable:!0,set:(n)=>e[t]=()=>n})};var R=N((V,M)=>{var w=process||{},I=w.argv||[],C=w.env||{},_=!(!!C.NO_COLOR||I.includes("--no-color"))&&(!!C.FORCE_COLOR||I.includes("--color")||w.platform==="win32"||(w.stdout||{}).isTTY&&C.TERM!=="dumb"||!!C.CI),Y=(r,e,t=r)=>(n)=>{let i=""+n,a=i.indexOf(e,r.length);return~a?r+K(i,e,t,a)+e:r+i+e},K=(r,e,t,n)=>{let i="",a=0;do i+=r.substring(a,n)+t,a=n+e.length,n=r.indexOf(e,a);while(~n);return i+r.substring(a)},D=(r=_)=>{let e=r?Y:()=>String;return{isColorSupported:r,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};M.exports=D();M.exports.createColors=D});var q={};W(q,{report:()=>J});module.exports=S(q);var f=y(R());var o=y(R()),U=!1;class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=o.default.blue;mutedColor=o.default.dim;infoColor=o.default.cyan;warnColor=o.default.yellow;errorColor=o.default.red;defaultColor=o.default.white;progressFgColorMap={ESM:o.default.yellow,CJS:o.default.green,IIFE:o.default.magenta,DTS:o.default.blue};progressBgColorMap={ESM:o.default.bgYellow,CJS:o.default.bgGreen,IIFE:o.default.bgMagenta,DTS:o.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:e,label:t,message:n,identifier:i,muted:a}){let b=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),s=a?this.mutedColor(n):n,g=i?` ${e(o.default.black(` ${i} `))}`:"";return`${r(t)} ${b}${s}${g}`}output(r,e={},t=console.log){if(U||!this.shouldLog(e))return;if(e.verticalSpace)t("");if(t(r),e.verticalSpace)t("")}cli(r,e={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:o.default.bgBlue,label:this.labels.cli,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e)}info(r,e={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:o.default.bgCyan,label:this.labels.info,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e)}warn(r,e={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:o.default.bgYellow,label:this.labels.warn,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e,console.warn)}error(r,e={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:o.default.bgRed,label:this.labels.error,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e,console.error)}getProgressFgColor(r){for(let[e,t]of Object.entries(this.progressFgColorMap))if(r.includes(e))return t;return this.defaultColor}getProgressBgColor(r){for(let[e,t]of Object.entries(this.progressBgColorMap))if(r.includes(e))return t;return o.default.bgWhite}progress(r,e,t={}){let n=this.getProgressFgColor(r),i=this.getProgressBgColor(r),a=this.formatMessage({fgColor:n,bgColor:i,label:r,message:e,identifier:t.identifier,muted:t.muted});this.output(a,t)}}function F(r,e,t){let n={};for(let s of r){let g=s.header.length,l=e.map((m)=>m[s.header]?.length||0),d=t?t[s.header]?.length||0:0;n[s.header]=Math.max(g,...l,d)}let i=(s,g,l)=>{return l==="left"?s.padEnd(g):s.padStart(g)},a=r.map((s)=>i(s.header,n[s.header],s.align)).join(o.default.gray(" | "));console.log(o.default.gray(a));let b=r.map((s)=>"-".repeat(n[s.header])).join(" | ");console.log(o.default.gray(b));for(let s of e){let g=r.map((l)=>{let d=s[l.header]||"",m=i(d,n[l.header],l.align);return l.color?l.color(m):m}).join(o.default.gray(" | "));console.log(g)}if(console.log(o.default.gray(b)),t){let s=r.map((g)=>{let l=t[g.header]||"";return i(l,n[g.header],g.align)}).join(o.default.gray(" | "));console.log(s)}}var H=x.getInstance();var X=y(R());function h(r){if(r===0)return"0 B";let e=["B","KB","MB","GB"],t=Math.floor(Math.log(r)/Math.log(1024));if(t===0)return`${r} ${e[t]}`;return`${(r/1024**t).toFixed(2)} ${e[t]}`}function J(r={}){let{maxBundleSize:e,gzip:t=!0}=r;return{type:"bunup",name:"report",hooks:{onBuildDone:async({options:n,output:i})=>{if(n.watch)return;let a=await Promise.all(i.files.map(async(c)=>{let u=c.relativePathToOutputDir,v=Bun.file(c.fullPath).size,E,O;if(t){let P=await Bun.file(c.fullPath).text();E=Bun.gzipSync(P).length,O=h(E)}return{name:u,size:v,formattedSize:h(v),gzipSize:E,formattedGzipSize:O}})),b=a.reduce((c,u)=>c+u.size,0),s=h(b),g,l;if(t)g=a.reduce((c,u)=>c+(u.gzipSize||0),0),l=h(g);let d=[{header:"File",align:"left",color:f.default.blue},{header:"Size",align:"right",color:f.default.green}];if(t)d.push({header:"Gzip",align:"right",color:f.default.magenta});let m=a.map((c)=>{let u={File:c.name,Size:c.formattedSize};if(t&&c.formattedGzipSize)u.Gzip=c.formattedGzipSize;return u}),B={File:"Total",Size:s};if(t&&l)B.Gzip=l;if(console.log(""),F(d,m,B),e&&b>e)console.log(""),console.log(f.default.red(`Your bundle size of ${s} exceeds the configured limit of ${h(e)}`));console.log("")}}}}})
@@ -1,492 +0,0 @@
1
- import _Bun from "bun";
2
-
3
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/helpers/entry.d.ts
4
- type ProcessableEntry = {
5
- fullEntryPath: string
6
- name: string
7
- };
8
-
9
- //#endregion
10
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/types.d.ts
11
- type MaybePromise<T> = Promise<T> | T;
12
- type Arrayable<T> = T | T[];
13
- type Bun = typeof _Bun;
14
- type BunBuildOptions = Parameters<Bun["build"]>[0];
15
- type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
16
-
17
- //#endregion
18
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/options.d.ts
19
- type Loader = NonNullable<BunBuildOptions["loader"]>[string];
20
- type Define = BunBuildOptions["define"];
21
- type Sourcemap = BunBuildOptions["sourcemap"];
22
- type Format = Exclude<BunBuildOptions["format"], undefined>;
23
- type Target = BunBuildOptions["target"];
24
- type External = (string | RegExp)[];
25
- type Env = BunBuildOptions["env"] | Record<string, string>;
26
- type Entry = Arrayable<string> | Record<string, string>;
27
- type ShimOptions = {
28
- /**
29
- * Adds __dirname and __filename shims for ESM files when used
30
- */
31
- dirnameFilename?: boolean
32
- /**
33
- * Adds import.meta.url shims for CJS files when used
34
- */
35
- importMetaUrl?: boolean
36
- };
37
- type Shims = boolean | ShimOptions;
38
- type DtsResolve = boolean | (string | RegExp)[];
39
- type DtsOptions = {
40
- /**
41
- * Entry point files for TypeScript declaration file generation
42
- *
43
- * This can be:
44
- * - A string path to a file
45
- * - An array of file paths
46
- * - An object where keys are output names and values are input file paths
47
- *
48
- * The key names are used for the generated declaration files.
49
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
50
- *
51
- * If not specified, the main entry points will be used for declaration file generation.
52
- *
53
- * If it's a string or an array of strings, the file name (without extension)
54
- * will be used as the name for the output declaration file.
55
- *
56
- * @example
57
- * // Using a string path
58
- * entry: 'src/index.ts' // Generates index.d.ts
59
- *
60
- * // Using string paths in an array
61
- * entry: ['src/index.ts'] // Generates index.d.ts
62
- *
63
- * // Using named outputs as an object
64
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
65
- *
66
- * // Organizing output with subdirectories
67
- * entry: { "client/index": "src/client/index.ts", "server/index": "src/server/index.ts" } // Generates client/index.d.ts and server/index.d.ts
68
- */
69
- entry?: Entry
70
- /**
71
- * Resolve external types used in dts files from node_modules
72
- */
73
- resolve?: DtsResolve
74
- };
75
- interface BuildOptions {
76
- /**
77
- * Name of the build configuration
78
- * Used for logging and identification purposes
79
- */
80
- name?: string;
81
- /**
82
- * Entry point files for the build
83
- *
84
- * This can be:
85
- * - A string path to a file
86
- * - An array of file paths
87
- * - An object where keys are output names and values are input file paths
88
- *
89
- * The key names are used for the generated output files.
90
- * For example, `{custom: 'src/index.ts'}` will generate `custom.js`
91
- *
92
- * If it's a string or an array of strings, the file name (without extension)
93
- * will be used as the name for the output file.
94
- *
95
- * @example
96
- * // Using a string path
97
- * entry: 'src/index.ts' // Generates index.js
98
- *
99
- * // Using string paths in an array
100
- * entry: ['src/index.ts'] // Generates index.js
101
- *
102
- * // Using named outputs as an object
103
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
104
- */
105
- entry: Entry;
106
- /**
107
- * Output directory for the bundled files
108
- * Defaults to 'dist' if not specified
109
- */
110
- outDir: string;
111
- /**
112
- * Output formats for the bundle
113
- * Can include 'esm', 'cjs', and/or 'iife'
114
- * Defaults to ['cjs'] if not specified
115
- */
116
- format: Format[];
117
- /**
118
- * Whether to enable all minification options
119
- * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
120
- */
121
- minify?: boolean;
122
- /**
123
- * Whether to enable code splitting
124
- * Defaults to true for ESM format, false for CJS format
125
- */
126
- splitting?: boolean;
127
- /**
128
- * Whether to minify whitespace in the output
129
- * Removes unnecessary whitespace to reduce file size
130
- */
131
- minifyWhitespace?: boolean;
132
- /**
133
- * Whether to minify identifiers in the output
134
- * Renames variables and functions to shorter names
135
- */
136
- minifyIdentifiers?: boolean;
137
- /**
138
- * Whether to minify syntax in the output
139
- * Optimizes code structure for smaller file size
140
- */
141
- minifySyntax?: boolean;
142
- /**
143
- * Whether to watch for file changes and rebuild automatically
144
- */
145
- watch?: boolean;
146
- /**
147
- * Whether to generate TypeScript declaration files (.d.ts)
148
- * When set to true, generates declaration files for all entry points
149
- * Can also be configured with DtsOptions for more control
150
- */
151
- dts?: boolean | DtsOptions;
152
- /**
153
- * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
154
- * When set to true, bunup will skip the JavaScript bundling process entirely
155
- * and only generate declaration files for the specified entry points
156
- *
157
- * This is useful when you want to use bunup's fast declaration file generation
158
- * but handle the JavaScript bundling separately or not at all.
159
- *
160
- * Note: When this option is true, the `dts` option is implicitly set to true
161
- * and other bundling-related options are ignored.
162
- *
163
- * @example
164
- * dtsOnly: true
165
- */
166
- dtsOnly?: boolean;
167
- /**
168
- * Path to a preferred tsconfig.json file to use for declaration generation
169
- *
170
- * If not specified, the tsconfig.json in the project root will be used.
171
- * This option allows you to use a different TypeScript configuration
172
- * specifically for declaration file generation.
173
- *
174
- * @example
175
- * preferredTsconfigPath: './tsconfig.build.json'
176
- */
177
- preferredTsconfigPath?: string;
178
- /**
179
- * External packages that should not be bundled
180
- * Useful for dependencies that should be kept as external imports
181
- */
182
- external?: External;
183
- /**
184
- * Packages that should be bundled even if they are in external
185
- * Useful for dependencies that should be included in the bundle
186
- */
187
- noExternal?: External;
188
- /**
189
- * The target environment for the bundle
190
- * Can be 'browser', 'bun', 'node', etc.
191
- * Defaults to 'node' if not specified
192
- */
193
- target?: Target;
194
- /**
195
- * Whether to clean the output directory before building
196
- * When true, removes all files in the outDir before starting a new build
197
- * Defaults to true if not specified
198
- */
199
- clean?: boolean;
200
- /**
201
- * Specifies the type of sourcemap to generate
202
- * Can be 'none', 'linked', 'external', or 'inline'
203
- * Can also be a boolean - when true, it will use 'inline'
204
- *
205
- * @see https://bun.sh/docs/bundler#sourcemap
206
- *
207
- * @default 'none'
208
- *
209
- * @example
210
- * sourcemap: 'linked'
211
- * // or
212
- * sourcemap: true // equivalent to 'inline'
213
- */
214
- sourcemap?: Sourcemap;
215
- /**
216
- * Define global constants for the build
217
- * These values will be replaced at build time
218
- *
219
- * @see https://bun.sh/docs/bundler#define
220
- *
221
- * @example
222
- * define: {
223
- * 'process.env.NODE_ENV': '"production"',
224
- * 'PACKAGE_VERSION': '"1.0.0"'
225
- * }
226
- */
227
- define?: Define;
228
- /**
229
- * A callback function that runs after the build process completes
230
- * This can be used for custom post-build operations like copying files,
231
- * running additional tools, or logging build information
232
- *
233
- * If watch mode is enabled, this callback runs after each rebuild
234
- *
235
- * @param options The build options that were used
236
- */
237
- onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
238
- /**
239
- * A banner to be added to the final bundle, this can be a directive like "use client" for react or a comment block such as a license for the code.
240
- *
241
- * @see https://bun.sh/docs/bundler#banner
242
- *
243
- * @example
244
- * banner: '"use client";'
245
- */
246
- banner?: string;
247
- /**
248
- * A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
249
- *
250
- * @see https://bun.sh/docs/bundler#footer
251
- *
252
- * @example
253
- * footer: '// built with love in SF'
254
- */
255
- footer?: string;
256
- /**
257
- * Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
258
- *
259
- * @see https://bun.sh/docs/bundler#drop
260
- *
261
- * @example
262
- * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
263
- */
264
- drop?: string[];
265
- /**
266
- * A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
267
- *
268
- * @see https://bun.sh/docs/bundler#loader
269
- *
270
- * @example
271
- * loader: {
272
- * ".png": "dataurl",
273
- * ".txt": "file",
274
- * }
275
- */
276
- loader?: Record<string, Loader>;
277
- /**
278
- * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
279
- *
280
- * Bytecode is currently only supported for CommonJS (format: "cjs").
281
- *
282
- * Must be target: "bun"
283
- *
284
- * @see https://bun.sh/docs/bundler#bytecode
285
- *
286
- * @default false
287
- */
288
- bytecode?: boolean;
289
- /**
290
- * Disable logging during the build process. When set to true, no logs will be printed to the console.
291
- *
292
- * @default false
293
- */
294
- silent?: boolean;
295
- /**
296
- * You can specify a prefix to be added to specific import paths in your bundled code
297
- *
298
- * Used for assets, external modules, and chunk files when splitting is enabled
299
- *
300
- * @see https://bunup.dev/docs#public-path for more information
301
- *
302
- * @example
303
- * publicPath: 'https://cdn.example.com/'
304
- */
305
- publicPath?: string;
306
- /**
307
- * Inject Node.js compatibility shims for ESM/CJS interoperability
308
- *
309
- * When set to true, automatically injects all shims when needed
310
- * When set to an object, only injects the specified shims
311
- *
312
- * Available shims:
313
- * - dirnameFilename: Adds __dirname and __filename for ESM files when used
314
- * - importMetaUrl: Adds import.meta.url for CJS files when used
315
- *
316
- * @example
317
- * // Enable all shims
318
- * shims: true
319
- *
320
- * // Enable only specific shims
321
- * shims: { dirnameFilename: true, importMetaUrl: true }
322
- */
323
- shims?: Shims;
324
- /**
325
- * Controls how environment variables are handled during bundling.
326
- *
327
- * Can be one of:
328
- * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
329
- * of those environment variables at the time the build runs.
330
- * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
331
- * - A string ending in `*`: Only inlines environment variables matching the given prefix.
332
- * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
333
- * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
334
- * with the provided values, regardless of the runtime environment.
335
- *
336
- * Note: Values are injected at build time. Secrets or private keys should be excluded
337
- * from inlining when targeting browser environments.
338
- *
339
- * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
340
- *
341
- * @example
342
- * // Inline all environment variables available at build time
343
- * env: "inline"
344
- *
345
- * // Disable all environment variable injection
346
- * env: "disable"
347
- *
348
- * // Only inline environment variables with a specific prefix
349
- * env: "PUBLIC_*"
350
- *
351
- * // Provide specific environment variables manually
352
- * env: { API_URL: "https://api.example.com", DEBUG: "false" }
353
- */
354
- env?: Env;
355
- /**
356
- * Plugins to extend the build process functionality
357
- *
358
- * The Plugin type uses a discriminated union pattern with the 'type' field
359
- * to support different plugin systems. Currently, only "bun" plugins are supported,
360
- * but in the future, this will be extended to include "bunup" plugins as well.
361
- *
362
- * Each plugin type has its own specific plugin implementation:
363
- * - "bun": Uses Bun's native plugin system (BunPlugin)
364
- * - "bunup": Will use bunup's own plugin system (coming in future versions)
365
- *
366
- * This architecture allows for extensibility as more plugin systems are added.
367
- *
368
- * @example
369
- * plugins: [
370
- * {
371
- * type: "bun",
372
- * plugin: myBunPlugin()
373
- * },
374
- * // In the future:
375
- * // {
376
- * // type: "bunup",
377
- * // plugin: myBunupPlugin()
378
- * // }
379
- * ]
380
- */
381
- plugins?: Plugin[];
382
- /**
383
- * Customize the output file extension for each format.
384
- *
385
- * @param options Contains format, packageType, options, and entry information
386
- * @returns Object with js and dts extensions (including the leading dot)
387
- *
388
- * @example
389
- * outputExtension: ({ format, entry }) => ({
390
- * js: entry.name === 'worker' ? '.worker.js' : `.${format}.js`,
391
- * dts: `.${format}.d.ts`
392
- * })
393
- */
394
- outputExtension?: (options: {
395
- format: Format
396
- packageType: string | undefined
397
- options: BuildOptions
398
- entry: ProcessableEntry
399
- }) => {
400
- js: string
401
- dts: string
402
- };
403
- }
404
-
405
- //#endregion
406
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/plugins/types.d.ts
407
- /**
408
- * Represents a Bun plugin that can be used with Bunup
409
- */
410
- type BunupBunPlugin = {
411
- /** Identifies this as a native Bun plugin */
412
- type: "bun"
413
- /** Optional name for the plugin */
414
- name?: string
415
- /** The actual Bun plugin implementation */
416
- plugin: BunPlugin
417
- };
418
- /**
419
- * Represents the output of a build operation
420
- */
421
- type BuildOutput = {
422
- /** Array of generated files with their paths and contents */
423
- files: Array<{
424
- /** Path to the generated file */
425
- fullPath: string
426
- /** Path to the generated file relative to the output directory */
427
- relativePathToOutputDir: string
428
- }>
429
- };
430
- /**
431
- * Context provided to build hooks
432
- */
433
- type BuildContext = {
434
- /** The build options that were used */
435
- options: BuildOptions
436
- /** The output of the build */
437
- output: BuildOutput
438
- };
439
- /**
440
- * Hooks that can be implemented by Bunup plugins
441
- */
442
- type BunupPluginHooks = {
443
- /**
444
- * Called when a build is successfully completed
445
- * @param ctx Build context containing options and output
446
- */
447
- onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
448
- /**
449
- * Called before a build starts
450
- * @param options Build options that will be used
451
- */
452
- onBuildStart?: (options: BuildOptions) => MaybePromise<void>
453
- };
454
- /**
455
- * Represents a Bunup-specific plugin
456
- */
457
- type BunupPlugin = {
458
- /** Identifies this as a Bunup-specific plugin */
459
- type: "bunup"
460
- /** Optional name for the plugin */
461
- name?: string
462
- /** The hooks implemented by this plugin */
463
- hooks: BunupPluginHooks
464
- };
465
- /**
466
- * Union type representing all supported plugin types
467
- */
468
- type Plugin = BunupBunPlugin | BunupPlugin;
469
-
470
- //#endregion
471
- //#region \0dts:/home/runner/work/bunup/bunup/packages/bunup/src/plugins/built-in/report.d.ts
472
- type ReportPluginOptions = {
473
- /**
474
- * The maximum bundle size in bytes.
475
- * If the bundle size exceeds this limit, a error will be logged without failing the build.
476
- */
477
- maxBundleSize?: number
478
- /**
479
- * Whether to show gzip sizes in the report.
480
- * When enabled, the report will include an additional column with the gzip size of each file.
481
- * @default true
482
- */
483
- gzip?: boolean
484
- };
485
- /**
486
- * A plugin that logs a report of the bundle size.
487
- * @param options - The options for the report plugin.
488
- */
489
- declare function report(options?: ReportPluginOptions): BunupPlugin;
490
-
491
- //#endregion
492
- export { report };