bunup 0.5.11 → 0.5.13

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