bunup 0.4.74 → 0.4.87

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/cli.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var Ar=Object.create;var{getPrototypeOf:Er,defineProperty:sn,getOwnPropertyNames:Ur}=Object;var _r=Object.prototype.hasOwnProperty;var v=(n,r,t)=>{t=n!=null?Ar(Er(n)):{};let e=r||!n||!n.__esModule?sn(t,"default",{value:n,enumerable:!0}):t;for(let o of Ur(n))if(!_r.call(e,o))sn(e,o,{get:()=>n[o],enumerable:!0});return e};var Wr=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var Hr=(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 vr=import.meta.require;var q=Wr((je,an)=>{var Z=process||{},kn=Z.argv||[],Q=Z.env||{},qr=!(!!Q.NO_COLOR||kn.includes("--no-color"))&&(!!Q.FORCE_COLOR||kn.includes("--color")||Z.platform==="win32"||(Z.stdout||{}).isTTY&&Q.TERM!=="dumb"||!!Q.CI),Fr=(n,r,t=n)=>(e)=>{let o=""+e,i=o.indexOf(r,n.length);return~i?n+Yr(o,r,t,i)+r:n+o+r},Yr=(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=qr)=>{let r=n?Fr:()=>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){In=n??!1}class E{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(!E.instance)E.instance=new E;return E.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({fgColor:n,bgColor:r,label:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),l=i?this.mutedColor(e):e,a=o?` ${r(d.default.black(` ${o} `))}`:"";return`${n(t)} ${s}${l}${a}`}output(n,r={},t=console.log){if(In||!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,In=!1,m;var L=p(()=>{d=v(q(),1);m=E.getInstance()});function cn(n){return n instanceof N}var b,T,M,C,B,X,N,y=(n)=>{if(n instanceof Error)return n.message;return String(n)},Gr,ln=(n,r)=>{let t=y(n),e=r?`[${r}] `:"",o=cn(n),i="ERROR";if(n instanceof M)i="BUILD ERROR";else if(n instanceof C)i="DTS ERROR";else if(n instanceof B)i="CLI ERROR";else if(n instanceof X)i="WATCH ERROR";else if(o)i="ISOLATED DECL ERROR";else if(n instanceof T)i="BUNUP ERROR";let s=Gr.find((l)=>l.pattern.test(t)&&(l.errorType===i||!l.errorType));if(!s)console.error(`${b.default.red(i)} ${e}${o?b.default.dim(t):t}`);if(s)console.log(`
4
+ `),s.logSolution(t),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")))},jn=(n,r)=>{ln(n,r),process.exit(1)};var O=p(()=>{b=v(q(),1);L();T=class T extends Error{constructor(n){super(n);this.name="BunupError"}};M=class M extends T{constructor(n){super(n);this.name="BunupBuildError"}};C=class C extends T{constructor(n){super(n);this.name="BunupDTSBuildError"}};B=class B extends T{constructor(n){super(n);this.name="BunupCLIError"}};X=class X extends T{constructor(n){super(n);this.name="BunupWatchError"}};N=class N extends T{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};Gr=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{m.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 Kr from"path";function Mn(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function An(n){return Array.isArray(n)?n:[n]}function En(n,r){switch(n){case"esm":return U(r)?".js":".mjs";case"cjs":return U(r)?".cjs":".js";case"iife":return".global.js"}}function Un(n,r){switch(n){case"esm":return U(r)?".d.ts":".d.mts";case"cjs":return U(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function gn(n){return n==="node"||n==="bun"}function U(n){return n==="module"}function z(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function _n(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function A(n,r=3){return n.split("/").slice(-r).join("/")}async function Wn(n,r){let t=Kr.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 $=p(()=>{O()});function Qr(n){return _n(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function Hn(n,r){return typeof r==="string"?r===n:r.test(n)}function D(n,r,t){let o=Qr(t).some((s)=>s.test(n))||r.external?.some((s)=>Hn(n,s)),i=r.noExternal?.some((s)=>Hn(n,s));return o&&!i}var fn=p(()=>{$()});import{resolveTsImportPath as Zr}from"ts-import-resolver";var Y="\x00dts:",vn=(n,r,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(mn(e))return e;if(!o||!mn(o))return null;let i=r.tsconfig?Zr({path:e,importer:F(o),tsconfig:r.tsconfig,rootDir:t}):null;if(!i)return null;let s=I(i);if(n.has(s))return J(s);return null},load(e){if(e.startsWith(Y)){let o=F(e),i=n.get(o);if(i)return i}return null}}};var un=p(()=>{j()});function G(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function qn(n){return dn.test(n)&&!G(n)}function _(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))&&!G(n)}function I(n){if(G(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 mn(n){return n.startsWith(Y)}function F(n){return n.replace(Y,"")}function J(n){return`${Y}${n}`}function Fn(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 D(n,r,t)}var dn;var j=p(()=>{fn();un();dn=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import{basename as Vr,dirname as Xr,extname as Nr}from"path";function P(n){let r=Vr(n),t=Nr(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=Xr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,c;do c=`${o}_${a++}`;while(t.has(c));r.push({fullEntryPath:e,name:c}),t.add(c);continue}let l=!1;for(let a=1;a<=s.length&&!l;a++){let g=`${s.slice(-a).join("/")}/${o}`;if(!t.has(g))r.push({fullEntryPath:e,name:g}),t.add(g),l=!0}if(!l){let a=1,c;do c=`${s.join("/")}/${o}_${a++}`;while(t.has(c));r.push({fullEntryPath:e,name:c}),t.add(c)}}return r}function Gn(n){return n.filter((r)=>_(r.fullEntryPath))}function Kn(n,r){return`[dir]/${n}${r}`}var nn=p(()=>{j()});import{existsSync as Pr,readFileSync as ne,readdirSync as re}from"fs";import{dirname as Nn,join as zn,resolve as ee}from"path";class W{static instance;constructor(){}static getInstance(){if(!W.instance)W.instance=new W;return W.instance}warn(n){console.log(`\x1B[33mWARNING: ${n}\x1B[0m`)}}function Dn(n){try{return Pr(n)}catch{return!1}}async function bn(n){try{if(!Dn(n))return null;if(n.slice(n.lastIndexOf(".")).toLowerCase()===".json"){let e=ne(n,"utf-8");return JSON.parse(e)}let r=await import(n),t=r.default||r;if(typeof t==="function")t=t();if(t instanceof Promise)return t;return t}catch(r){return null}}function oe(n,r){let t=n,e=0;while(e<r){let o=zn(t,"package.json");if(Dn(o))return o;let i=Nn(t);if(i===t)break;t=i,e++}return null}async function Xn(n,r,t,e,o,i){if(i){let a=oe(t,e);if(a){let c=await bn(a);if(c&&typeof c==="object"&&i in c)return{config:c[i],filepath:a}}}if(o){let a=ee(t,o),c=await bn(a);if(c!==null)return{config:c,filepath:a};te.warn(`Preferred path "${o}" not found or invalid, searching for ${n} files instead.`)}let s=t,l=0;while(l<e){try{let c=re(s),g=new Set(c);for(let f of r){let u=`${n}${f}`;if(g.has(u)){let w=zn(s,u),x=await bn(w);if(x!==null)return{config:x,filepath:w}}}}catch(c){}let a=Nn(s);if(a===s)break;s=a,l++}return{config:null,filepath:null}}async function xn(n,r=Vn,t={}){if(typeof n==="string"){let c=n,{cwd:g=process.cwd(),maxDepth:f=10,preferredPath:u,packageJsonProperty:w}=t;return Xn(c,r,g,f,u,w)}let{name:e,extensions:o=Vn,cwd:i=process.cwd(),maxDepth:s=10,preferredPath:l,packageJsonProperty:a}=n;return Xn(e,o,i,s,l,a)}var te,Vn;var Jn=p(()=>{te=W.getInstance(),Vn=[".ts",".mts",".cts",".js",".mjs",".cjs",".json"]});import ie from"path";async function Pn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:ie.resolve(r,e.root),options:Mn(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function nr(n){let{config:r,filepath:t}=await xn({name:"package",cwd:n,extensions:[".json"]});return{packageJson:r,path:t}}async function rr(n,r){let{config:t,filepath:e}=await xn({name:"tsconfig",cwd:n,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:e}}var hn=p(()=>{Jn();$()});import er from"path";import{ResolverFactory as se}from"oxc-resolver";function tr(n,r){return{name:"bunup:types-resolve",buildStart(){wn||=new se({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?F(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?er.dirname(o):process.cwd(),{path:s}=await wn.async(i,t);if(!s)return;if(qn(s)){let l=I(s);try{let{path:a}=await wn.async(er.dirname(s),l);if(a)return a}catch(a){}return}return s}}}var wn;var or=p(()=>{j()});import{build as ae}from"rolldown";import{dts as ce}from"rolldown-plugin-dts";async function ir(n,r,t,e,o,i){let s=I(n),l=J(s),a=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:c}=await ae({input:l,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(g,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;f(g)},plugins:[vn(r,o,i),a&&tr(o,a),ce({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>Yn(g,t,e,a)});if(!c[0]?.code)return m.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return c[0].code}catch(c){throw new C(`DTS bundling failed for entry "${n}": ${y(c)}`)}}var sr=p(()=>{O();L();or();j();un()});import{resolveTsImportPath as le}from"ts-import-resolver";function xe(n){let r=new Set,t=[ge,fe,me,ue,de,pe,be];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 ar(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(),l=xe(s);for(let a of l){let c=r.tsconfig?le({path:a,importer:i,tsconfig:r.tsconfig,rootDir:t}):null;if(!c||!(_(c)||G(c)))continue;if(!e.has(c))e.add(c),o.push(c)}}catch(s){m.warn(`Error processing ${i}: ${y(s)}`)}}return e}var ge,fe,me,ue,de,pe,be;var cr=p(()=>{O();L();j();ge=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,fe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,me=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ue=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,de=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,pe=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,be=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g});import{isolatedDeclaration as he}from"oxc-transform";async function lr(n,r){let t=!1,e=new Map;if(await Promise.all([...n].map(async(o)=>{try{let i=I(o);if(!await Bun.file(o).exists())return;let l=await Bun.file(o).text(),{code:a,errors:c}=he(o,l);if(a)e.set(i,a);for(let g of c){if(!t&&!r)console.log(`
8
+ `);let f=g.labels[0],u=f?Fn(l,f.start):"",x=`${A(o)}${u}: ${we(g.message)}`;m[r?"warn":"error"](x),t=!0}}catch(i){m.warn(`Failed to generate declaration for ${o}: ${y(i)}`)}})),t&&!r)throw console.log(`
9
+ `),new N(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${Cn.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${Cn.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function we(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var Cn;var gr=p(()=>{Cn=v(q(),1);O();L();$();j()});import fr from"fs/promises";import yn from"path";async function mr(n,r){let t=yn.resolve(n),e=yn.resolve(t,r);if(!await fr.exists(t))throw new C(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new C(`Entry file does not exist: ${e}`);if(!_(e))throw new C(`Entry file must be a TypeScript file: ${e}`);if(yn.relative(t,e).startsWith(".."))throw new C(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}var ur=p(()=>{O();j()});async function dr(n,r,t,e,o){let{absoluteEntry:i}=await mr(n,r),s=await ar(i,e,n),l=await lr(s,t.watch);return ir(i,l,t,o,e,n)}var pr=p(()=>{sr();cr();gr();ur()});function tn(n){return{...Ce,...n}}function br(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 xr(n,r){return r==="cjs"?n:void 0}function hr(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 wr(n,r){return n===void 0?r==="esm":n}function Cr(n){return typeof n==="string"?n:void 0}var Ce;var Bn=p(()=>{Ce={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function yr(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(D(o,n,r))return{path:o,external:!0};return null})}}}var Br=p(()=>{fn()});function Or({format:n,target:r,shims:t}){let o=Be(t).map((i)=>On[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:ye},async({path:s})=>{let l=await Bun.file(s).text(),a=o.filter((u)=>u.isNeededInFile(l));if(a.length===0)return;let{shebangLine:c,codeContent:g}=Oe(l),f=a.map((u)=>u.generateCode()).join("");return{contents:c+f+g}})}}}function Be(n){if(n===!0)return Object.keys(On);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in On)).map(([r])=>r)}function Oe(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
10
+ `);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var ye,On;var Sr=p(()=>{$();ye=/\.(js|ts|jsx|tsx|mts|cts)$/,On={dirnameFilename:{appliesTo:(n,r)=>n==="esm"&&gn(r),isNeededInFile:(n)=>/\b__dirname\b/.test(n)||/\b__filename\b/.test(n),generateCode:()=>`import { fileURLToPath } from 'url';
11
+ import { dirname } from 'path';
12
+
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = dirname(__filename);
15
+
16
+ `},importMetaUrl:{appliesTo:(n,r)=>n==="cjs"&&gn(r),isNeededInFile:(n)=>/\bimport\.meta\.url\b/.test(n),generateCode:()=>`import { pathToFileURL } from 'url';
17
+
18
+ const importMetaUrl = pathToFileURL(__filename).href;
19
+
20
+ `}}});function Rr(n){if(!n)return[];return n.filter((r)=>r.type==="bun")}function kr(n){if(!n)return[];return n.filter((r)=>r.type==="bunup")}async function Lr(n,r){if(!n)return;for(let t of n)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(r)}async function $r(n,r,t){if(!n)return;for(let e of n)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:r,output:t})}var Tr={};Hr(Tr,{build:()=>Sn});async function Sn(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)Wn(r,e.outDir);V(e.silent);let{packageJson:o,path:i}=await nr(r);if(o&&i)m.cli(`Using ${A(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=kr(e.plugins);await Lr(s,e);let l=K(e.entry),a=o?.type;if(!e.dtsOnly){let c=[yr(e,o),...Rr(e.plugins).map((f)=>f.plugin)],g=e.format.flatMap((f)=>l.map(async(u)=>{let w=e.outputExtension?.({format:f,packageType:a,options:e,entry:u}).js??En(f,a),x=await Bun.build({entrypoints:[`${r}/${u.fullEntryPath}`],format:f,naming:{entry:Kn(u.name,w)},splitting:wr(e.splitting,f),bytecode:xr(e.bytecode,f),define:hr(e.define,e.shims,e.env,f),minify:br(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:Cr(e.env),plugins:[...c,Or({format:f,target:e.target,shims:e.shims})],throw:!1});if(!x.success)for(let k of x.logs){if(k.level==="error")throw new M(k.message);if(k.level==="warning")m.warn(k.message);else if(k.level==="info")m.info(k.message)}let R=Ir(e.outDir,u.name,w),H=jr(r,R);t.files.push({fullPath:H,relativePathToOutputDir:R}),m.progress(f.toUpperCase(),R,{identifier:e.name})}));await Promise.all(g)}if(e.dts||e.dtsOnly){let c=await rr(r,e.preferredTsconfigPath);if(c.path)m.cli(`Using ${A(c.path,2)}`,{muted:!0,identifier:e.name,once:`${c.path}:${e.name}`});let g=e.format.filter((u)=>{if(u==="iife"&&!U(a)&&e.format.includes("cjs"))return!1;return!0}),f=typeof e.dts==="object"&&e.dts.entry?K(e.dts.entry):Gn(l);try{await Promise.all(f.map(async(u)=>{let w=await dr(r,u.fullEntryPath,e,c,o);await Promise.all(g.map(async(x)=>{let R=e.outputExtension?.({format:x,packageType:a,options:e,entry:u}).dts??Un(x,a),H=Ir(e.outDir,u.name,R),k=jr(r,H);t.files.push({fullPath:k,relativePathToOutputDir:H}),await Bun.write(k,w),m.progress("DTS",H,{identifier:e.name})}))}))}catch(u){if(cn(u))throw u;throw new C(y(u))}}if(await $r(s,e,t),e.onSuccess)await e.onSuccess(e)}function Ir(n,r,t){return`${n}/${r}${t}`}function jr(n,r){return`${n}/${r}`}var Rn=p(()=>{pr();O();nn();hn();L();Bn();Br();Sr();$()});import{exec as Re}from"tinyexec";var pn=v(q(),1);var $n="https://bunup.dev/cli-options";O();nn();L();function h(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function S(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new B(`Option --${n} requires a string value`)}}function rn(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new B(`Option --${n} requires a string value`)}}function zr(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 B(`Option --${n} requires a boolean or string value`)}}function Dr(){console.log(`
21
+ Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
22
+ `),console.log("For more information on available options, visit:"),console.log(`${pn.default.cyan(pn.default.underline($n))}
23
+ `),process.exit(0)}function Jr(){console.log("0.4.74"),process.exit(0)}var Qn={name:{flags:["n","name"],handler:S("name")},format:{flags:["f","format"],handler:rn("format")},outDir:{flags:["o","out-dir"],handler:S("outDir")},minify:{flags:["m","minify"],handler:h("minify")},watch:{flags:["w","watch"],handler:h("watch")},dts:{flags:["d","dts"],handler:h("dts")},banner:{flags:["bn","banner"],handler:S("banner")},footer:{flags:["ft","footer"],handler:S("footer")},external:{flags:["e","external"],handler:rn("external")},sourcemap:{flags:["sm","sourcemap"],handler:zr("sourcemap")},target:{flags:["t","target"],handler:S("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:h("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:h("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:h("minifySyntax")},clean:{flags:["c","clean"],handler:h("clean")},splitting:{flags:["s","splitting"],handler:h("splitting")},noExternal:{flags:["ne","no-external"],handler:rn("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:S("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:h("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:h("dtsOnly")},silent:{flags:["silent"],handler:h("silent")},config:{flags:["config"],handler:S("config")},publicPath:{flags:["pp","public-path"],handler:S("publicPath")},env:{flags:["env"],handler:S("env")},shims:{flags:["shims"],handler:h("shims")},onSuccess:{flags:["onSuccess"],handler:S("onSuccess")},filter:{flags:["filter"],handler:rn("filter")},entry:{flags:["entry"],handler:(n,r,t)=>{if(typeof n!=="string")throw new B(`Entry${t?` --entry.${t}`:""} requires a string value`);let e=r.entry||{};if(t){if(e[t])m.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);e[t]=n}else{let o=P(n);if(e[o])m.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:()=>Dr()},version:{flags:["v","version"],handler:()=>Jr()}},en={};for(let n of Object.values(Qn))for(let r of n.flags)en[r]=n.handler;function Zn(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,l]=e.slice(2).split("=",2);o=s,i=l}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,l]=o.split(".",2),a=en[s];if(a)a(i,r,l);else throw new B(`Unknown option: --${o}`)}else{let s=en[o];if(s)s(i,r);else throw new B(`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 l=en[o];if(l)l(s,r);else throw new B(`Unknown option: -${o}`)}else Qn.entry.handler(e,r,void 0)}return r}O();L();hn();$();Rn();O();nn();L();Bn();$();import on from"path";async function Mr(n,r){let t=new Set,e=tn(n),o=K(e.entry);for(let c of o){let g=on.resolve(r,c.fullEntryPath),f=on.dirname(g);t.add(f)}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)]}),l=!1,a=async(c=!1)=>{if(l)return;l=!0;try{let g=performance.now();if(await Sn({...e,entry:o.map((f)=>f.fullEntryPath),clean:!1},r),!c)m.cli(`\uD83D\uDCE6 Rebuild finished in ${z(performance.now()-g)}`)}catch(g){ln(g)}finally{l=!1}};s.on("change",(c)=>{let g=on.relative(r,c);m.cli(`File changed: ${g}`,{muted:!0,once:g}),a()}),s.on("error",(c)=>{throw new X(`Watcher error: ${y(c)}`)}),await a(!0)}import{loadConfig as ke}from"unconfig";async function Le(n=Bun.argv.slice(2)){let r=Zn(n);V(r.silent);let t=process.cwd(),{config:e,sources:o}=await ke({sources:[{files:r.config||"bunup.config",extensions:["ts","js","mjs","cjs"]},{files:"package.json",extensions:[],rewrite(f){return f?.bunup}}],merge:!1}),i=o?.[0],s=!e?[{rootDir:t,options:r}]:await Pn(e,t,r.filter);if(m.cli(`Using bunup v0.4.74 and bun v${Bun.version}`,{muted:!0}),i)m.cli(`Using ${A(i,2)}`,{muted:!0});let l=performance.now();m.cli("Build started");let{build:a}=await Promise.resolve().then(() => (Rn(),Tr));await Promise.all(s.flatMap(({options:f,rootDir:u})=>{return An(f).map(async(x)=>{let R={...x,...$e(r)};if(R.watch)await Mr(R,u);else await a(R,u)})}));let c=performance.now()-l,g=z(c);if(m.cli(`\u26A1\uFE0F Build completed in ${g}`),r.watch)m.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)m.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await Re(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function $e(n){return{...n,onSuccess:void 0,config:void 0}}Le().catch((n)=>jn(n));
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import _Bun from "bun";
2
2
 
3
- //#region \0dts:/home/runner/work/bunup/bunup/src/helpers/entry.d.ts
3
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/helpers/entry.d.ts
4
4
  type ProcessableEntry = {
5
5
  fullEntryPath: string
6
6
  name: string
7
7
  };
8
8
 
9
9
  //#endregion
10
- //#region \0dts:/home/runner/work/bunup/bunup/src/plugins/types.d.ts
10
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/plugins/types.d.ts
11
11
  /**
12
12
  * Represents a Bun plugin that can be used with Bunup
13
13
  */
@@ -26,7 +26,9 @@ type BuildOutput = {
26
26
  /** Array of generated files with their paths and contents */
27
27
  files: Array<{
28
28
  /** Path to the generated file */
29
- path: string
29
+ fullPath: string
30
+ /** Path to the generated file relative to the output directory */
31
+ relativePathToOutputDir: string
30
32
  }>
31
33
  };
32
34
  /**
@@ -70,7 +72,7 @@ type BunupPlugin = {
70
72
  type Plugin = BunupBunPlugin | BunupPlugin;
71
73
 
72
74
  //#endregion
73
- //#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
75
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/options.d.ts
74
76
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
75
77
  type Define = BunBuildOptions["define"];
76
78
  type Sourcemap = BunBuildOptions["sourcemap"];
@@ -458,7 +460,7 @@ interface BuildOptions {
458
460
  }
459
461
 
460
462
  //#endregion
461
- //#region \0dts:/home/runner/work/bunup/bunup/src/types.d.ts
463
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/types.d.ts
462
464
  type MaybePromise<T> = Promise<T> | T;
463
465
  type WithOptional<
464
466
  T,
@@ -476,12 +478,12 @@ type DefineWorkspaceItem = {
476
478
  };
477
479
 
478
480
  //#endregion
479
- //#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
481
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/define.d.ts
480
482
  declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
481
483
  declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
482
484
 
483
485
  //#endregion
484
- //#region \0dts:/home/runner/work/bunup/bunup/src/build.d.ts
486
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/build.d.ts
485
487
  declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
486
488
 
487
489
  //#endregion
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- // @bun @bun-cjs
2
- (function(exports, require, module, __filename, __dirname) {var Nr=Object.create;var{getPrototypeOf:Jr,defineProperty:I,getOwnPropertyNames:rr,getOwnPropertyDescriptor:vr}=Object,nr=Object.prototype.hasOwnProperty;var d=(r,n,e)=>{e=r!=null?Nr(Jr(r)):{};let t=n||!r||!r.__esModule?I(e,"default",{value:r,enumerable:!0}):e;for(let o of rr(r))if(!nr.call(t,o))I(t,o,{get:()=>r[o],enumerable:!0});return t},P=new WeakMap,Pr=(r)=>{var n=P.get(r),e;if(n)return n;if(n=I({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")rr(r).map((t)=>!nr.call(n,t)&&I(n,t,{get:()=>r[t],enumerable:!(e=vr(r,t))||e.enumerable}));return P.set(r,n),n},rn=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var nn=(r,n)=>{for(var e in n)I(r,e,{get:n[e],enumerable:!0,configurable:!0,set:(t)=>n[e]=()=>t})};var j=rn((Tn,K)=>{var A=process||{},or=A.argv||[],$=A.env||{},tn=!(!!$.NO_COLOR||or.includes("--no-color"))&&(!!$.FORCE_COLOR||or.includes("--color")||A.platform==="win32"||(A.stdout||{}).isTTY&&$.TERM!=="dumb"||!!$.CI),en=(r,n,e=r)=>(t)=>{let o=""+t,i=o.indexOf(n,r.length);return~i?r+on(o,n,e,i)+n:r+o+n},on=(r,n,e,t)=>{let o="",i=0;do o+=r.substring(i,t)+e,i=t+n.length,t=r.indexOf(n,i);while(~t);return o+r.substring(i)},ir=(r=tn)=>{let n=r?en:()=>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")}};K.exports=ir();K.exports.createColors=ir});var hn={};nn(hn,{defineWorkspace:()=>er,defineConfig:()=>tr,build:()=>Xr});module.exports=Pr(hn);function tr(r){return r}function er(r){return r}var Rr=require("rolldown"),Tr=require("rolldown-plugin-dts");var sn=d(j());var c=d(j()),sr=!1;function ur(r){sr=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:e,message:t,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),m=i?this.mutedColor(t):t,u=o?` ${n(c.default.black(` ${o} `))}`:"";return`${r(e)} ${s}${m}${u}`}output(r,n={},e=console.log){if(sr||!this.shouldLog(n))return;if(n.verticalSpace)e("");if(e(r),n.verticalSpace)e("")}cli(r,n={}){let e=this.formatMessage({fgColor:this.cliColor,bgColor:c.default.bgBlue,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(r,n={}){let e=this.formatMessage({fgColor:this.infoColor,bgColor:c.default.bgCyan,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(r,n={}){let e=this.formatMessage({fgColor:this.warnColor,bgColor:c.default.bgYellow,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(r,n={}){let e=this.formatMessage({fgColor:this.errorColor,bgColor:c.default.bgRed,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}getProgressFgColor(r){for(let[n,e]of Object.entries(this.progressFgColorMap))if(r.includes(n))return e;return this.defaultColor}getProgressBgColor(r){for(let[n,e]of Object.entries(this.progressBgColorMap))if(r.includes(n))return e;return c.default.bgWhite}progress(r,n,e={}){let t=this.getProgressFgColor(r),o=this.getProgressBgColor(r),i=this.formatMessage({fgColor:t,bgColor:o,label:r,message:n,identifier:e.identifier,muted:e.muted});this.output(i,e)}}var p=h.getInstance();class D extends Error{constructor(r){super(r);this.name="BunupError"}}class O extends D{constructor(r){super(r);this.name="BunupBuildError"}}class f extends D{constructor(r){super(r);this.name="BunupDTSBuildError"}}class W extends D{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var C=(r)=>{if(r instanceof Error)return r.message;return String(r)};function gr(r){return r instanceof W}var z=d(require("path")),hr=require("oxc-resolver");var q=d(require("fs/promises")),mr=d(require("path"));function cr(r,n){switch(r){case"esm":return R(n)?".js":".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function br(r,n){switch(r){case"esm":return R(n)?".d.ts":".d.mts";case"cjs":return R(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function G(r){return r==="node"||r==="bun"}function R(r){return r==="module"}function ar(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function L(r,n=3){return r.split("/").slice(-n).join("/")}async function xr(r,n){let e=mr.default.join(r,n);try{await q.default.rm(e,{recursive:!0,force:!0})}catch(t){throw new O(`Failed to clean output directory: ${t}`)}await q.default.mkdir(e,{recursive:!0})}function _(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))}function un(r){return ar(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function pr(r,n){return typeof n==="string"?n===r:n.test(r)}function U(r,n,e){let o=un(e).some((s)=>s.test(r))||n.external?.some((s)=>pr(r,s)),i=n.noExternal?.some((s)=>pr(r,s));return o&&!i}var fr=require("ts-import-resolver");var M="\x00dts:",lr=(r,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(t,o){if(H(t))return t;if(!o||!H(o))return null;let i=n.tsconfig?fr.resolveTsImportPath({path:t,importer:k(o),tsconfig:n.tsconfig,rootDir:e}):null;if(!i)return null;let s=B(i);if(r.has(s))return Y(s);return null},load(t){if(t.startsWith(M)){let o=k(t),i=r.get(o);if(i)return i}return null}}};var Q=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function dr(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function Cr(r){return Q.test(r)&&!dr(r)}function B(r){if(dr(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(Q.test(r))return r.replace(Q,".d.ts");return`${r}.d.ts`}function H(r){return r.startsWith(M)}function k(r){return r.replace(M,"")}function Y(r){return`${M}${r}`}function Br(r,n){if(n===void 0)return"";let e=r.slice(0,n).split(`
3
- `),t=e.length,o=e[e.length-1].length+1;return` (${t}:${o})`}function wr(r,n,e,t){if(typeof t==="boolean"&&t)return!1;if(Array.isArray(t)){for(let o of t)if(typeof o==="string"&&r===o)return!1;else if(o instanceof RegExp&&o.test(r))return!1}return U(r,n,e)}var Z;function Or(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(e,t){if(n===!1)return;if(e==="bun")return;let o=t?k(t):void 0;if(/\0/.test(e))return;if(Array.isArray(n)){if(!n.some((u)=>typeof u==="string"?u===e:u.test(e)))return}let i=o?z.default.dirname(o):process.cwd(),{path:s}=await Z.async(i,e);if(!s)return;if(Cr(s)){let m=B(s);try{let{path:u}=await Z.async(z.default.dirname(s),m);if(u)return u}catch(u){}return}return s}}}async function Sr(r,n,e,t,o,i){let s=B(r),m=Y(s),u=typeof e.dts==="object"&&"resolve"in e.dts?e.dts.resolve:void 0;try{let{output:g}=await Rr.build({input:m,output:{dir:e.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(x,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;a(x)},plugins:[lr(n,o,i),u&&Or(o,u),Tr.dts({dtsInput:!0,emitDtsOnly:!0})],external:(x)=>wr(x,e,t,u)});if(!g[0]?.code)return p.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return g[0].code}catch(g){throw new f(`DTS bundling failed for entry "${r}": ${C(g)}`)}}var Ir=require("ts-import-resolver");var gn=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,mn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,cn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,bn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,an=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,xn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,pn=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function fn(r){let n=new Set,e=[gn,mn,cn,bn,an,xn,pn];for(let t of e){let o=r.matchAll(t);for(let i of o)if(i[1])n.add(i[1])}return n}async function Lr(r,n,e){let t=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),m=fn(s);for(let u of m){let g=n.tsconfig?Ir.resolveTsImportPath({path:u,importer:i,tsconfig:n.tsconfig,rootDir:e}):null;if(!g)continue;if(!t.has(g))t.add(g),o.push(g)}}catch(s){p.warn(`Error processing ${i}: ${C(s)}`)}}return t}var kr=require("oxc-transform"),V=d(j());async function Mr(r,n){let e=!1,t=new Map;if(await Promise.all([...r].map(async(o)=>{try{let i=B(o);if(!await Bun.file(o).exists())return;let m=await Bun.file(o).text(),{code:u,errors:g}=kr.isolatedDeclaration(o,m);if(u)t.set(i,u);for(let x of g){if(!e&&!n)console.log(`
4
- `);let a=x.labels[0],b=a?Br(m,a.start):"",w=`${L(o)}${b}: ${ln(x.message)}`;p[n?"warn":"error"](w),e=!0}}catch(i){p.warn(`Failed to generate declaration for ${o}: ${C(i)}`)}})),e&&!n)throw console.log(`
5
- `),new W(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${V.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${V.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return t}function ln(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var X=d(require("fs/promises")),F=d(require("path"));async function Er(r,n){let e=F.default.resolve(r),t=F.default.resolve(e,n);if(!await X.default.exists(e))throw new f(`Root directory does not exist: ${e}`);if(!await Bun.file(t).exists())throw new f(`Entry file does not exist: ${t}`);if(!_(t))throw new f(`Entry file must be a TypeScript file: ${t}`);if(F.default.relative(e,t).startsWith(".."))throw new f(`Entry file must be within rootDir: ${t}`);return{absoluteRootDir:e,absoluteEntry:t}}async function yr(r,n,e,t,o){let{absoluteEntry:i}=await Er(r,n),s=await Lr(i,t,r),m=await Mr(s,e.watch);return Sr(i,m,e,o,t,r)}var T=require("path");function $r(r){let n=T.basename(r),e=T.extname(n);return e?n.slice(0,-e.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(([t,o])=>({fullEntryPath:o,name:t}));let n=[],e=new Set;for(let t of r){let o=$r(t);if(!e.has(o)){n.push({fullEntryPath:t,name:o}),e.add(o);continue}let s=T.dirname(t).split("/").filter((u)=>u!=="."&&u!=="");if(s.length===0){let u=1,g;do g=`${o}_${u++}`;while(e.has(g));n.push({fullEntryPath:t,name:g}),e.add(g);continue}let m=!1;for(let u=1;u<=s.length&&!m;u++){let x=`${s.slice(-u).join("/")}/${o}`;if(!e.has(x))n.push({fullEntryPath:t,name:x}),e.add(x),m=!0}if(!m){let u=1,g;do g=`${s.join("/")}/${o}_${u++}`;while(e.has(g));n.push({fullEntryPath:t,name:g}),e.add(g)}}return n}function Ar(r){return r.filter((n)=>_(n.fullEntryPath))}function jr(r,n){return`[dir]/${r}${n}`}var J=require("coffi");async function Dr(r){let{config:n,filepath:e}=await J.loadConfig({name:"package",cwd:r,extensions:[".json"]});return{packageJson:n,path:e}}async function Wr(r,n){let{config:e,filepath:t}=await J.loadConfig({name:"tsconfig",cwd:r,extensions:[".json"],preferredPath:n});return{tsconfig:e,path:t}}var dn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function _r(r){return{...dn,...r}}function Ur(r){let{minify:n,minifyWhitespace:e,minifyIdentifiers:t,minifySyntax:o}=r,i=n===!0;return{whitespace:e??i,identifiers:t??i,syntax:o??i}}function Yr(r,n){return n==="cjs"?r:void 0}function Fr(r,n,e,t){return{...typeof e==="object"&&Object.keys(e).reduce((o,i)=>{let s=JSON.stringify(e[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...r,...t==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Kr(r,n){return r===void 0?n==="esm":r}function qr(r){return typeof r==="string"?r:void 0}function Gr(r,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(t)=>{let o=t.path;if(U(o,r,n))return{path:o,external:!0};return null})}}}var Cn=/\.(js|ts|jsx|tsx|mts|cts)$/,v={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&G(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
1
+ // @bun
2
+ var Zr=Object.create;var{getPrototypeOf:Hr,defineProperty:J,getOwnPropertyNames:Vr}=Object;var zr=Object.prototype.hasOwnProperty;var Y=(r,n,t)=>{t=r!=null?Zr(Hr(r)):{};let e=n||!r||!r.__esModule?J(t,"default",{value:r,enumerable:!0}):t;for(let o of Vr(r))if(!zr.call(e,o))J(e,o,{get:()=>r[o],enumerable:!0});return e};var Xr=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var $=Xr((_n,G)=>{var A=process||{},v=A.argv||[],E=A.env||{},vr=!(!!E.NO_COLOR||v.includes("--no-color"))&&(!!E.FORCE_COLOR||v.includes("--color")||A.platform==="win32"||(A.stdout||{}).isTTY&&E.TERM!=="dumb"||!!E.CI),Pr=(r,n,t=r)=>(e)=>{let o=""+e,i=o.indexOf(n,r.length);return~i?r+rn(o,n,t,i)+n:r+o+n},rn=(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)},P=(r=vr)=>{let n=r?Pr:()=>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=P();G.exports.createColors=P});function Nr(r){return r}function Jr(r){return r}import{build as gn}from"rolldown";import{dts as cn}from"rolldown-plugin-dts";var nn=Y($(),1);var l=Y($(),1),rr=!1;function nr(r){rr=r??!1}class h{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(!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 g=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),u=i?this.mutedColor(e):e,s=o?` ${n(l.default.black(` ${o} `))}`:"";return`${r(t)} ${g}${u}${s}`}output(r,n={},t=console.log){if(rr||!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:l.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:l.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:l.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:l.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 l.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 p=h.getInstance();class W extends Error{constructor(r){super(r);this.name="BunupError"}}class R extends W{constructor(r){super(r);this.name="BunupBuildError"}}class x extends W{constructor(r){super(r);this.name="BunupDTSBuildError"}}class _ extends W{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var w=(r)=>{if(r instanceof Error)return r.message;return String(r)};function er(r){return r instanceof _}import lr from"path";import{ResolverFactory as sn}from"oxc-resolver";import tr from"fs/promises";import en from"path";function or(r,n){switch(r){case"esm":return y(n)?".js":".mjs";case"cjs":return y(n)?".cjs":".js";case"iife":return".global.js"}}function ir(r,n){switch(r){case"esm":return y(n)?".d.ts":".d.mts";case"cjs":return y(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function K(r){return r==="node"||r==="bun"}function y(r){return r==="module"}function sr(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function j(r,n=3){return r.split("/").slice(-n).join("/")}async function gr(r,n){let t=en.join(r,n);try{await tr.rm(t,{recursive:!0,force:!0})}catch(e){throw new R(`Failed to clean output directory: ${e}`)}await tr.mkdir(t,{recursive:!0})}function tn(r){return sr(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function cr(r,n){return typeof n==="string"?n===r:n.test(r)}function F(r,n,t){let o=tn(t).some((g)=>g.test(r))||n.external?.some((g)=>cr(r,g)),i=n.noExternal?.some((g)=>cr(r,g));return o&&!i}import{resolveTsImportPath as on}from"ts-import-resolver";var O="\x00dts:",ur=(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?on({path:e,importer:M(o),tsconfig:n.tsconfig,rootDir:t}):null;if(!i)return null;let g=B(i);if(r.has(g))return U(g);return null},load(e){if(e.startsWith(O)){let o=M(e),i=r.get(o);if(i)return i}return null}}};var D=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function T(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function ar(r){return D.test(r)&&!T(r)}function S(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))&&!T(r)}function B(r){if(T(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(D.test(r))return r.replace(D,".d.ts");return`${r}.d.ts`}function q(r){return r.startsWith(O)}function M(r){return r.replace(O,"")}function U(r){return`${O}${r}`}function mr(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 fr(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 F(r,n,t)}var Q;function pr(r,n){return{name:"bunup:types-resolve",buildStart(){Q||=new sn({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?M(e):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((s)=>typeof s==="string"?s===t:s.test(t)))return}let i=o?lr.dirname(o):process.cwd(),{path:g}=await Q.async(i,t);if(!g)return;if(ar(g)){let u=B(g);try{let{path:s}=await Q.async(lr.dirname(g),u);if(s)return s}catch(s){}return}return g}}}async function br(r,n,t,e,o,i){let g=B(r),u=U(g),s=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:c}=await gn({input:u,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(f,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;m(f)},plugins:[ur(n,o,i),s&&pr(o,s),cn({dtsInput:!0,emitDtsOnly:!0})],external:(f)=>fr(f,t,e,s)});if(!c[0]?.code)return p.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return c[0].code}catch(c){throw new x(`DTS bundling failed for entry "${r}": ${w(c)}`)}}import{resolveTsImportPath as un}from"ts-import-resolver";var an=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,mn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,fn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ln=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,pn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,bn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,dn=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function xn(r){let n=new Set,t=[an,mn,fn,ln,pn,bn,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 dr(r,n,t){let e=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let g=await Bun.file(i).text(),u=xn(g);for(let s of u){let c=n.tsconfig?un({path:s,importer:i,tsconfig:n.tsconfig,rootDir:t}):null;if(!c||!(S(c)||T(c)))continue;if(!e.has(c))e.add(c),o.push(c)}}catch(g){p.warn(`Error processing ${i}: ${w(g)}`)}}return e}var Z=Y($(),1);import{isolatedDeclaration as Cn}from"oxc-transform";async function xr(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:s,errors:c}=Cn(o,u);if(s)e.set(i,s);for(let f of c){if(!t&&!n)console.log(`
4
+ `);let m=f.labels[0],a=m?mr(u,m.start):"",d=`${j(o)}${a}: ${wn(f.message)}`;p[n?"warn":"error"](d),t=!0}}catch(i){p.warn(`Failed to generate declaration for ${o}: ${w(i)}`)}})),t&&!n)throw console.log(`
5
+ `),new _(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${Z.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${Z.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function wn(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}import Cr from"fs/promises";import H from"path";async function wr(r,n){let t=H.resolve(r),e=H.resolve(t,n);if(!await Cr.exists(t))throw new x(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new x(`Entry file does not exist: ${e}`);if(!S(e))throw new x(`Entry file must be a TypeScript file: ${e}`);if(H.relative(t,e).startsWith(".."))throw new x(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function Br(r,n,t,e,o){let{absoluteEntry:i}=await wr(r,n),g=await dr(i,e,r),u=await xr(g,t.watch);return br(i,u,t,o,e,r)}import{basename as Bn,dirname as hn,extname as Rn}from"path";function hr(r){let n=Bn(r),t=Rn(n);return t?n.slice(0,-t.length):n}function V(r){if(typeof r==="string")return[{fullEntryPath:r,name:hr(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=hr(e);if(!t.has(o)){n.push({fullEntryPath:e,name:o}),t.add(o);continue}let g=hn(e).split("/").filter((s)=>s!=="."&&s!=="");if(g.length===0){let s=1,c;do c=`${o}_${s++}`;while(t.has(c));n.push({fullEntryPath:e,name:c}),t.add(c);continue}let u=!1;for(let s=1;s<=g.length&&!u;s++){let f=`${g.slice(-s).join("/")}/${o}`;if(!t.has(f))n.push({fullEntryPath:e,name:f}),t.add(f),u=!0}if(!u){let s=1,c;do c=`${g.join("/")}/${o}_${s++}`;while(t.has(c));n.push({fullEntryPath:e,name:c}),t.add(c)}}return n}function Rr(r){return r.filter((n)=>S(n.fullEntryPath))}function yr(r,n){return`[dir]/${r}${n}`}import{existsSync as yn,readFileSync as Sn,readdirSync as kn}from"fs";import{dirname as Ir,join as Lr,resolve as In}from"path";class k{static instance;constructor(){}static getInstance(){if(!k.instance)k.instance=new k;return k.instance}warn(r){console.log(`\x1B[33mWARNING: ${r}\x1B[0m`)}}var Ln=k.getInstance(),Sr=[".ts",".mts",".cts",".js",".mjs",".cjs",".json"];function jr(r){try{return yn(r)}catch{return!1}}async function z(r){try{if(!jr(r))return null;if(r.slice(r.lastIndexOf(".")).toLowerCase()===".json"){let e=Sn(r,"utf-8");return JSON.parse(e)}let n=await import(r),t=n.default||n;if(typeof t==="function")t=t();if(t instanceof Promise)return t;return t}catch(n){return null}}function jn(r,n){let t=r,e=0;while(e<n){let o=Lr(t,"package.json");if(jr(o))return o;let i=Ir(t);if(i===t)break;t=i,e++}return null}async function kr(r,n,t,e,o,i){if(i){let s=jn(t,e);if(s){let c=await z(s);if(c&&typeof c==="object"&&i in c)return{config:c[i],filepath:s}}}if(o){let s=In(t,o),c=await z(s);if(c!==null)return{config:c,filepath:s};Ln.warn(`Preferred path "${o}" not found or invalid, searching for ${r} files instead.`)}let g=t,u=0;while(u<e){try{let c=kn(g),f=new Set(c);for(let m of n){let a=`${r}${m}`;if(f.has(a)){let b=Lr(g,a),d=await z(b);if(d!==null)return{config:d,filepath:b}}}}catch(c){}let s=Ir(g);if(s===g)break;g=s,u++}return{config:null,filepath:null}}async function X(r,n=Sr,t={}){if(typeof r==="string"){let c=r,{cwd:f=process.cwd(),maxDepth:m=10,preferredPath:a,packageJsonProperty:b}=t;return kr(c,n,f,m,a,b)}let{name:e,extensions:o=Sr,cwd:i=process.cwd(),maxDepth:g=10,preferredPath:u,packageJsonProperty:s}=r;return kr(e,o,i,g,u,s)}async function Mr(r){let{config:n,filepath:t}=await X({name:"package",cwd:r,extensions:[".json"]});return{packageJson:n,path:t}}async function Or(r,n){let{config:t,filepath:e}=await X({name:"tsconfig",cwd:r,extensions:[".json"],preferredPath:n});return{tsconfig:t,path:e}}var Mn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Tr(r){return{...Mn,...r}}function Er(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 Ar(r,n){return n==="cjs"?r:void 0}function $r(r,n,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((o,i)=>{let g=JSON.stringify(t[i]);return o[`process.env.${i}`]=g,o[`import.meta.env.${i}`]=g,o},{}),...r,...e==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Wr(r,n){return r===void 0?n==="esm":r}function _r(r){return typeof r==="string"?r:void 0}function Fr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(F(o,r,n))return{path:o,external:!0};return null})}}}var On=/\.(js|ts|jsx|tsx|mts|cts)$/,N={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&K(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
6
6
  import { dirname } from 'path';
7
7
 
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = dirname(__filename);
10
10
 
11
- `},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&G(n),isNeededInFile:(r)=>/\bimport\.meta\.url\b/.test(r),generateCode:()=>`import { pathToFileURL } from 'url';
11
+ `},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&K(n),isNeededInFile:(r)=>/\bimport\.meta\.url\b/.test(r),generateCode:()=>`import { pathToFileURL } from 'url';
12
12
 
13
13
  const importMetaUrl = pathToFileURL(__filename).href;
14
14
 
15
- `}};function Hr({format:r,target:n,shims:e}){let o=Bn(e).map((i)=>v[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:Cn},async({path:s})=>{let m=await Bun.file(s).text(),u=o.filter((b)=>b.isNeededInFile(m));if(u.length===0)return;let{shebangLine:g,codeContent:x}=wn(m),a=u.map((b)=>b.generateCode()).join("");return{contents:g+a+x}})}}}function Bn(r){if(r===!0)return Object.keys(v);if(!r)return[];return Object.entries(r).filter(([n,e])=>e&&(n in v)).map(([n])=>n)}function wn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
16
- `);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 e of r)if(e.hooks.onBuildStart)await e.hooks.onBuildStart(n)}async function Vr(r,n,e){if(!r)return;for(let t of r)if(t.hooks.onBuildDone)await t.hooks.onBuildDone({options:n,output:e})}async function Xr(r,n=process.cwd()){let e={files:[]},t=_r(r);if(!t.entry||t.entry.length===0||!t.outDir)throw new O("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)xr(n,t.outDir);ur(t.silent);let{packageJson:o,path:i}=await Dr(n);if(o&&i)p.cli(`Using package.json: ${L(i,2)}`,{muted:!0,identifier:t.name,once:`${i}:${t.name}`});let s=Zr(t.plugins);await zr(s,t);let m=N(t.entry),u=o?.type;if(!t.dtsOnly){let g=[Gr(t,o),...Qr(t.plugins).map((a)=>a.plugin)],x=t.format.flatMap((a)=>m.map(async(b)=>{let S=t.outputExtension?.({format:a,packageType:u,options:t,entry:b}).js??cr(a,u),w=await Bun.build({entrypoints:[`${n}/${b.fullEntryPath}`],format:a,naming:{entry:jr(b.name,S)},splitting:Kr(t.splitting,a),bytecode:Yr(t.bytecode,a),define:Fr(t.define,t.shims,t.env,a),minify:Ur(t),outdir:`${n}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:qr(t.env),plugins:[...g,Hr({format:a,target:t.target,shims:t.shims})],throw:!1});if(!w.success)for(let l of w.logs){if(l.level==="error")throw new O(l.message);if(l.level==="warning")p.warn(l.message);else if(l.level==="info")p.info(l.message)}let E=`${t.outDir}/${b.name}${S}`,y=`${n}/${E}`;e.files.push({path:y}),p.progress(a.toUpperCase(),E,{identifier:t.name})}));await Promise.all(x)}if(t.dts||t.dtsOnly){let g=await Wr(n,t.preferredTsconfigPath);if(g.path)p.cli(`Using tsconfig: ${L(g.path,2)}`,{muted:!0,identifier:t.name,once:`${g.path}:${t.name}`});let x=t.format.filter((b)=>{if(b==="iife"&&!R(u)&&t.format.includes("cjs"))return!1;return!0}),a=typeof t.dts==="object"&&t.dts.entry?N(t.dts.entry):Ar(m);try{await Promise.all(a.map(async(b)=>{let S=await yr(n,b.fullEntryPath,t,g,o);await Promise.all(x.map(async(w)=>{let E=t.outputExtension?.({format:w,packageType:u,options:t,entry:b}).dts??br(w,u),y=`${t.outDir}/${b.name}${E}`,l=`${n}/${y}`;e.files.push({path:l}),await Bun.write(l,S),p.progress("DTS",y,{identifier:t.name})}))}))}catch(b){if(gr(b))throw b;throw new f(C(b))}}if(await Vr(s,t,e),t.onSuccess)await t.onSuccess(t)}})
15
+ `}};function Ur({format:r,target:n,shims:t}){let o=Tn(t).map((i)=>N[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:On},async({path:g})=>{let u=await Bun.file(g).text(),s=o.filter((a)=>a.isNeededInFile(u));if(s.length===0)return;let{shebangLine:c,codeContent:f}=En(u),m=s.map((a)=>a.generateCode()).join("");return{contents:c+m+f}})}}}function Tn(r){if(r===!0)return Object.keys(N);if(!r)return[];return Object.entries(r).filter(([n,t])=>t&&(n in N)).map(([n])=>n)}function En(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
16
+ `);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function Yr(r){if(!r)return[];return r.filter((n)=>n.type==="bun")}function Gr(r){if(!r)return[];return r.filter((n)=>n.type==="bunup")}async function Kr(r,n){if(!r)return;for(let t of r)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(n)}async function qr(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 An(r,n=process.cwd()){let t={files:[]},e=Tr(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)gr(n,e.outDir);nr(e.silent);let{packageJson:o,path:i}=await Mr(n);if(o&&i)p.cli(`Using ${j(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let g=Gr(e.plugins);await Kr(g,e);let u=V(e.entry),s=o?.type;if(!e.dtsOnly){let c=[Fr(e,o),...Yr(e.plugins).map((m)=>m.plugin)],f=e.format.flatMap((m)=>u.map(async(a)=>{let b=e.outputExtension?.({format:m,packageType:s,options:e,entry:a}).js??or(m,s),d=await Bun.build({entrypoints:[`${n}/${a.fullEntryPath}`],format:m,naming:{entry:yr(a.name,b)},splitting:Wr(e.splitting,m),bytecode:Ar(e.bytecode,m),define:$r(e.define,e.shims,e.env,m),minify:Er(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:_r(e.env),plugins:[...c,Ur({format:m,target:e.target,shims:e.shims})],throw:!1});if(!d.success)for(let C of d.logs){if(C.level==="error")throw new R(C.message);if(C.level==="warning")p.warn(C.message);else if(C.level==="info")p.info(C.message)}let I=Dr(e.outDir,a.name,b),L=Qr(n,I);t.files.push({fullPath:L,relativePathToOutputDir:I}),p.progress(m.toUpperCase(),I,{identifier:e.name})}));await Promise.all(f)}if(e.dts||e.dtsOnly){let c=await Or(n,e.preferredTsconfigPath);if(c.path)p.cli(`Using ${j(c.path,2)}`,{muted:!0,identifier:e.name,once:`${c.path}:${e.name}`});let f=e.format.filter((a)=>{if(a==="iife"&&!y(s)&&e.format.includes("cjs"))return!1;return!0}),m=typeof e.dts==="object"&&e.dts.entry?V(e.dts.entry):Rr(u);try{await Promise.all(m.map(async(a)=>{let b=await Br(n,a.fullEntryPath,e,c,o);await Promise.all(f.map(async(d)=>{let I=e.outputExtension?.({format:d,packageType:s,options:e,entry:a}).dts??ir(d,s),L=Dr(e.outDir,a.name,I),C=Qr(n,L);t.files.push({fullPath:C,relativePathToOutputDir:L}),await Bun.write(C,b),p.progress("DTS",L,{identifier:e.name})}))}))}catch(a){if(er(a))throw a;throw new x(w(a))}}if(await qr(g,e,t),e.onSuccess)await e.onSuccess(e)}function Dr(r,n,t){return`${r}/${n}${t}`}function Qr(r,n){return`${r}/${n}`}export{Jr as defineWorkspace,Nr as defineConfig,An as build};
@@ -1,76 +1,21 @@
1
1
  import _Bun from "bun";
2
2
 
3
- //#region \0dts:/home/runner/work/bunup/bunup/src/helpers/entry.d.ts
3
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/helpers/entry.d.ts
4
4
  type ProcessableEntry = {
5
5
  fullEntryPath: string
6
6
  name: string
7
7
  };
8
8
 
9
9
  //#endregion
10
- //#region \0dts:/home/runner/work/bunup/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
- path: string
30
- }>
31
- };
32
- /**
33
- * Context provided to build hooks
34
- */
35
- type BuildContext = {
36
- /** The build options that were used */
37
- options: BuildOptions
38
- /** The output of the build */
39
- output: BuildOutput
40
- };
41
- /**
42
- * Hooks that can be implemented by Bunup plugins
43
- */
44
- type BunupPluginHooks = {
45
- /**
46
- * Called when a build is successfully completed
47
- * @param ctx Build context containing options and output
48
- */
49
- onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
50
- /**
51
- * Called before a build starts
52
- * @param options Build options that will be used
53
- */
54
- onBuildStart?: (options: BuildOptions) => MaybePromise<void>
55
- };
56
- /**
57
- * Represents a Bunup-specific plugin
58
- */
59
- type BunupPlugin = {
60
- /** Identifies this as a Bunup-specific plugin */
61
- type: "bunup"
62
- /** Optional name for the plugin */
63
- name?: string
64
- /** The hooks implemented by this plugin */
65
- hooks: BunupPluginHooks
66
- };
67
- /**
68
- * Union type representing all supported plugin types
69
- */
70
- type Plugin = BunupBunPlugin | BunupPlugin;
10
+ //#region \0dts:/Users/admin/Desktop/Projects/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];
71
16
 
72
17
  //#endregion
73
- //#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
18
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/options.d.ts
74
19
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
75
20
  type Define = BunBuildOptions["define"];
76
21
  type Sourcemap = BunBuildOptions["sourcemap"];
@@ -458,31 +403,90 @@ interface BuildOptions {
458
403
  }
459
404
 
460
405
  //#endregion
461
- //#region \0dts:/home/runner/work/bunup/bunup/src/types.d.ts
462
- type MaybePromise<T> = Promise<T> | T;
463
- type WithOptional<
464
- T,
465
- K extends keyof T
466
- > = Omit<T, K> & Partial<Pick<T, K>>;
467
- type Arrayable<T> = T | T[];
468
- type Bun = typeof _Bun;
469
- type BunBuildOptions = Parameters<Bun["build"]>[0];
470
- type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
471
- type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
472
- type DefineWorkspaceItem = {
473
- name: string
474
- root: string
475
- config: DefineConfigItem | DefineConfigItem[]
406
+ //#region \0dts:/Users/admin/Desktop/Projects/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
476
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;
477
469
 
478
470
  //#endregion
479
- //#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
480
- declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
481
- declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
482
-
483
- //#endregion
484
- //#region \0dts:/home/runner/work/bunup/bunup/src/build.d.ts
485
- declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
471
+ //#region \0dts:/Users/admin/Desktop/Projects/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;
486
490
 
487
491
  //#endregion
488
- export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin, build, defineConfig, defineWorkspace };
492
+ export { report };
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ var D=Object.create;var{getPrototypeOf:F,defineProperty:O,getOwnPropertyNames:P}=Object;var $=Object.prototype.hasOwnProperty;var E=(r,e,t)=>{t=r!=null?D(F(r)):{};let o=e||!r||!r.__esModule?O(t,"default",{value:r,enumerable:!0}):t;for(let i of P(r))if(!$.call(o,i))O(o,i,{get:()=>r[i],enumerable:!0});return o};var j=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var w=j((U,y)=>{var C=process||{},L=C.argv||[],f=C.env||{},A=!(!!f.NO_COLOR||L.includes("--no-color"))&&(!!f.FORCE_COLOR||L.includes("--color")||C.platform==="win32"||(C.stdout||{}).isTTY&&f.TERM!=="dumb"||!!f.CI),S=(r,e,t=r)=>(o)=>{let i=""+o,a=i.indexOf(e,r.length);return~a?r+N(i,e,t,a)+e:r+i+e},N=(r,e,t,o)=>{let i="",a=0;do i+=r.substring(a,o)+t,a=o+e.length,o=r.indexOf(e,a);while(~o);return i+r.substring(a)},T=(r=A)=>{let e=r?S:()=>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")}};y.exports=T();y.exports.createColors=T});var p=E(w(),1);var n=E(w(),1),W=!1;class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=n.default.blue;mutedColor=n.default.dim;infoColor=n.default.cyan;warnColor=n.default.yellow;errorColor=n.default.red;defaultColor=n.default.white;progressFgColorMap={ESM:n.default.yellow,CJS:n.default.green,IIFE:n.default.magenta,DTS:n.default.blue};progressBgColorMap={ESM:n.default.bgYellow,CJS:n.default.bgGreen,IIFE:n.default.bgMagenta,DTS:n.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:o,identifier:i,muted:a}){let b=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),s=a?this.mutedColor(o):o,g=i?` ${e(n.default.black(` ${i} `))}`:"";return`${r(t)} ${b}${s}${g}`}output(r,e={},t=console.log){if(W||!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:n.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:n.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:n.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:n.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 n.default.bgWhite}progress(r,e,t={}){let o=this.getProgressFgColor(r),i=this.getProgressBgColor(r),a=this.formatMessage({fgColor:o,bgColor:i,label:r,message:e,identifier:t.identifier,muted:t.muted});this.output(a,t)}}function k(r,e,t){let o={};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;o[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,o[s.header],s.align)).join(n.default.gray(" | "));console.log(n.default.gray(a));let b=r.map((s)=>"-".repeat(o[s.header])).join(" | ");console.log(n.default.gray(b));for(let s of e){let g=r.map((l)=>{let d=s[l.header]||"",m=i(d,o[l.header],l.align);return l.color?l.color(m):m}).join(n.default.gray(" | "));console.log(g)}if(console.log(n.default.gray(b)),t){let s=r.map((g)=>{let l=t[g.header]||"";return i(l,o[g.header],g.align)}).join(n.default.gray(" | "));console.log(s)}}var _=x.getInstance();var Y=E(w(),1);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 z(r={}){let{maxBundleSize:e,gzip:t=!0}=r;return{type:"bunup",name:"report",hooks:{onBuildDone:async({options:o,output:i})=>{if(o.watch)return;let a=await Promise.all(i.files.map(async(c)=>{let u=c.relativePathToOutputDir,B=Bun.file(c.fullPath).size,R,v;if(t){let I=await Bun.file(c.fullPath).text();R=Bun.gzipSync(I).length,v=h(R)}return{name:u,size:B,formattedSize:h(B),gzipSize:R,formattedGzipSize:v}})),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:p.default.blue},{header:"Size",align:"right",color:p.default.green}];if(t)d.push({header:"Gzip",align:"right",color:p.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}),M={File:"Total",Size:s};if(t&&l)M.Gzip=l;if(console.log(""),k(d,m,M),e&&b>e)console.log(""),console.log(p.default.red(`Your bundle size of ${s} exceeds the configured limit of ${h(e)}`));console.log("")}}}}export{z as report};
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.4.74",
4
+ "version": "0.4.87",
5
5
  "license": "MIT",
6
6
  "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
7
+ "type": "module",
7
8
  "maintainers": [
8
9
  {
9
10
  "name": "Arshad Yaseen",
@@ -18,12 +19,16 @@
18
19
  "homepage": "https://bunup.dev",
19
20
  "funding": "https://github.com/sponsors/arshad-yaseen",
20
21
  "keywords": ["bun", "bunup", "bun-bundler"],
21
- "types": "./dist/index.d.ts",
22
- "main": "./dist/index.js",
23
- "module": "./dist/index.mjs",
24
22
  "files": ["dist"],
25
23
  "bin": {
26
- "bunup": "./dist/cli.mjs"
24
+ "bunup": "./dist/cli.js"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": "./dist/index.js",
31
+ "./plugins": "./dist/plugins.js"
27
32
  },
28
33
  "scripts": {
29
34
  "build": "bunup",
@@ -49,18 +54,18 @@
49
54
  },
50
55
  "lint-staged": {
51
56
  "*": "bun run format --no-errors-on-unmatched",
52
- "src/**/*.(m|c)?(j|t)s|(bump|bunup).config.ts": "bun run tsc"
57
+ "src/**/*.(m|c)?(j|t)s": "bun run tsc"
53
58
  },
54
59
  "workspaces": ["tests", "docs", "benchmarks", "create-bunup"],
55
60
  "dependencies": {
56
61
  "chokidar": "^4.0.3",
57
- "coffi": "^0.1.23",
58
62
  "oxc-resolver": "^5.0.1",
59
63
  "oxc-transform": "^0.58.1",
60
64
  "rolldown": "1.0.0-beta.7",
61
65
  "rolldown-plugin-dts": "^0.7.0",
62
66
  "tinyexec": "^1.0.1",
63
- "ts-import-resolver": "^0.1.10"
67
+ "ts-import-resolver": "^0.1.10",
68
+ "unconfig": "^7.3.2"
64
69
  },
65
70
  "peerDependencies": {
66
71
  "typescript": ">=4.5.0"
@@ -74,8 +79,8 @@
74
79
  "@biomejs/biome": "^1.9.4",
75
80
  "@types/bun": "^1.2.5",
76
81
  "bumpp": "^10.1.0",
77
- "bunup": "^0.4.69",
78
- "create-bunup": "create-bunup",
82
+ "bunup": "^0.4.78",
83
+ "create-bunup": "workspace:create-bunup",
79
84
  "husky": "^9.1.7",
80
85
  "lint-staged": "^15.5.1",
81
86
  "typescript": "^5.8.3"
package/dist/cli.mjs DELETED
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env bun
2
- // @bun
3
- var kr=Object.create;var{getPrototypeOf:Sr,defineProperty:on,getOwnPropertyNames:Tr}=Object;var $r=Object.prototype.hasOwnProperty;var E=(n,r,t)=>{t=n!=null?kr(Sr(n)):{};let e=r||!n||!n.__esModule?on(t,"default",{value:n,enumerable:!0}):t;for(let i of Tr(n))if(!$r.call(e,i))on(e,i,{get:()=>n[i],enumerable:!0});return e};var Lr=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var Rr=(n,r)=>{for(var t in r)on(n,t,{get:r[t],enumerable:!0,configurable:!0,set:(e)=>r[t]=()=>e})};var d=(n,r)=>()=>(n&&(r=n(n=0)),r);var Ir=import.meta.require;var v=Lr((be,sn)=>{var F=process||{},On=F.argv||[],q=F.env||{},Mr=!(!!q.NO_COLOR||On.includes("--no-color"))&&(!!q.FORCE_COLOR||On.includes("--color")||F.platform==="win32"||(F.stdout||{}).isTTY&&q.TERM!=="dumb"||!!q.CI),Ar=(n,r,t=n)=>(e)=>{let i=""+e,o=i.indexOf(r,n.length);return~o?n+jr(i,r,t,o)+r:n+i+r},jr=(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)},kn=(n=Mr)=>{let r=n?Ar:()=>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")}};sn.exports=kn();sn.exports.createColors=kn});function G(n){Tn=n??!1}class A{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=p.default.blue;mutedColor=p.default.dim;infoColor=p.default.cyan;warnColor=p.default.yellow;errorColor=p.default.red;defaultColor=p.default.white;progressFgColorMap={ESM:p.default.yellow,CJS:p.default.green,IIFE:p.default.magenta,DTS:p.default.blue};progressBgColorMap={ESM:p.default.bgYellow,CJS:p.default.bgGreen,IIFE:p.default.bgMagenta,DTS:p.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(p.default.black(` ${i} `))}`:"";return`${n(t)} ${s}${c}${a}`}output(n,r={},t=console.log){if(Tn||!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:p.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:p.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:p.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:p.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 p.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 p,Tn=!1,l;var T=d(()=>{p=E(v(),1);l=A.getInstance()});function an(n){return n instanceof Z}var b,R,I,w,C,Q,Z,y=(n)=>{if(n instanceof Error)return n.message;return String(n)},vr,un=(n,r)=>{let t=y(n),e=r?`[${r}] `:"",i=an(n),o="ERROR";if(n instanceof I)o="BUILD ERROR";else if(n instanceof w)o="DTS ERROR";else if(n instanceof C)o="CLI ERROR";else if(n instanceof Q)o="WATCH ERROR";else if(i)o="ISOLATED DECL ERROR";else if(n instanceof R)o="BUNUP ERROR";let s=vr.find((c)=>c.pattern.test(t)&&(c.errorType===o||!c.errorType));if(!s)console.error(`${b.default.red(o)} ${e}${i?b.default.dim(t):t}`);if(s)console.log(`
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)=>{un(n,r),process.exit(1)};var B=d(()=>{b=E(v(),1);T();R=class R extends Error{constructor(n){super(n);this.name="BunupError"}};I=class I extends R{constructor(n){super(n);this.name="BunupBuildError"}};w=class w extends R{constructor(n){super(n);this.name="BunupDTSBuildError"}};C=class C extends R{constructor(n){super(n);this.name="BunupCLIError"}};Q=class Q extends R{constructor(n){super(n);this.name="BunupWatchError"}};Z=class Z extends R{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};vr=[{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 Ln from"fs/promises";import Ur from"path";function Rn(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function In(n){return Array.isArray(n)?n:[n]}function Mn(n,r){switch(n){case"esm":return j(r)?".js":".mjs";case"cjs":return j(r)?".cjs":".js";case"iife":return".global.js"}}function An(n,r){switch(n){case"esm":return j(r)?".d.ts":".d.mts";case"cjs":return j(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function cn(n){return n==="node"||n==="bun"}function j(n){return n==="module"}function z(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function jn(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 En(n,r){let t=Ur.join(n,r);try{await Ln.rm(t,{recursive:!0,force:!0})}catch(e){throw new I(`Failed to clean output directory: ${e}`)}await Ln.mkdir(t,{recursive:!0})}function V(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))}var O=d(()=>{B()});import{basename as _r,dirname as Hr,extname as Wr}from"path";function X(n){let r=_r(n),t=Wr(r);return t?r.slice(0,-t.length):r}function U(n){if(typeof n==="string")return[{fullEntryPath:n,name:X(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=X(e);if(!t.has(i)){r.push({fullEntryPath:e,name:i}),t.add(i);continue}let s=Hr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,u;do u=`${i}_${a++}`;while(t.has(u));r.push({fullEntryPath:e,name:u}),t.add(u);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,u;do u=`${s.join("/")}/${i}_${a++}`;while(t.has(u));r.push({fullEntryPath:e,name:u}),t.add(u)}}return r}function vn(n){return n.filter((r)=>V(r.fullEntryPath))}function Un(n,r){return`[dir]/${n}${r}`}var N=d(()=>{O()});import Fr from"path";import{loadConfig as Wn}from"coffi";async function Dn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:Fr.resolve(r,e.root),options:Rn(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function Yn(n){let{config:r,filepath:t}=await Wn({name:"package",cwd:n,extensions:[".json"]});return{packageJson:r,path:t}}async function qn(n,r){let{config:t,filepath:e}=await Wn({name:"tsconfig",cwd:n,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:e}}var mn=d(()=>{O()});function Kr(n){return jn(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function Fn(n,r){return typeof r==="string"?r===n:r.test(n)}function nn(n,r,t){let i=Kr(t).some((s)=>s.test(n))||r.external?.some((s)=>Fn(n,s)),o=r.noExternal?.some((s)=>Fn(n,s));return i&&!o}var gn=d(()=>{O()});import{resolveTsImportPath as Gr}from"ts-import-resolver";var H="\x00dts:",Kn=(n,r,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(fn(e))return e;if(!i||!fn(i))return null;let o=r.tsconfig?Gr({path:e,importer:_(i),tsconfig:r.tsconfig,rootDir:t}):null;if(!o)return null;let s=$(o);if(n.has(s))return rn(s);return null},load(e){if(e.startsWith(H)){let i=_(e),o=n.get(i);if(o)return o}return null}}};var pn=d(()=>{W()});function Gn(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function Qn(n){return dn.test(n)&&!Gn(n)}function $(n){if(Gn(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 fn(n){return n.startsWith(H)}function _(n){return n.replace(H,"")}function rn(n){return`${H}${n}`}function Zn(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 zn(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 nn(n,r,t)}var dn;var W=d(()=>{gn();pn();dn=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import Vn from"path";import{ResolverFactory as Qr}from"oxc-resolver";function Xn(n,r){return{name:"bunup:types-resolve",buildStart(){bn||=new Qr({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?_(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?Vn.dirname(i):process.cwd(),{path:s}=await bn.async(o,t);if(!s)return;if(Qn(s)){let c=$(s);try{let{path:a}=await bn.async(Vn.dirname(s),c);if(a)return a}catch(a){}return}return s}}}var bn;var Nn=d(()=>{W()});import{build as Zr}from"rolldown";import{dts as zr}from"rolldown-plugin-dts";async function Jn(n,r,t,e,i,o){let s=$(n),c=rn(s),a=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:u}=await Zr({input:c,output:{dir:t.outDir},write:!1,...i.path&&{resolve:{tsconfigFilename:i.path}},onwarn(m,g){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;g(m)},plugins:[Kn(r,i,o),a&&Xn(i,a),zr({dtsInput:!0,emitDtsOnly:!0})],external:(m)=>zn(m,t,e,a)});if(!u[0]?.code)return l.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return u[0].code}catch(u){throw new w(`DTS bundling failed for entry "${n}": ${y(u)}`)}}var Pn=d(()=>{B();T();Nn();W();pn()});import{resolveTsImportPath as Vr}from"ts-import-resolver";function te(n){let r=new Set,t=[Xr,Nr,Jr,Pr,ne,re,ee];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=te(s);for(let a of c){let u=r.tsconfig?Vr({path:a,importer:o,tsconfig:r.tsconfig,rootDir:t}):null;if(!u)continue;if(!e.has(u))e.add(u),i.push(u)}}catch(s){l.warn(`Error processing ${o}: ${y(s)}`)}}return e}var Xr,Nr,Jr,Pr,ne,re,ee;var rr=d(()=>{B();T();Xr=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Nr=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Jr=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Pr=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ne=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,re=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ee=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g});import{isolatedDeclaration as ie}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=$(i);if(!await Bun.file(i).exists())return;let c=await Bun.file(i).text(),{code:a,errors:u}=ie(i,c);if(a)e.set(o,a);for(let m of u){if(!t&&!r)console.log(`
8
- `);let g=m.labels[0],f=g?Zn(c,g.start):"",h=`${M(i)}${f}: ${oe(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(`
9
- `),new Z(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${xn.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${xn.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function oe(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var xn;var tr=d(()=>{xn=E(v(),1);B();T();O();W()});import ir from"fs/promises";import hn from"path";async function or(n,r){let t=hn.resolve(n),e=hn.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(!V(e))throw new w(`Entry file must be a TypeScript file: ${e}`);if(hn.relative(t,e).startsWith(".."))throw new w(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}var sr=d(()=>{B();O()});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 Jn(o,c,t,i,e,n)}var ur=d(()=>{Pn();rr();tr();sr()});function en(n){return{...se,...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 gr(n,r){return n===void 0?r==="esm":n}function fr(n){return typeof n==="string"?n:void 0}var se;var wn=d(()=>{se={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function pr(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let i=e.path;if(nn(i,n,r))return{path:i,external:!0};return null})}}}var dr=d(()=>{gn()});function br({format:n,target:r,shims:t}){let i=ue(t).map((o)=>yn[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:ae},async({path:s})=>{let c=await Bun.file(s).text(),a=i.filter((f)=>f.isNeededInFile(c));if(a.length===0)return;let{shebangLine:u,codeContent:m}=ce(c),g=a.map((f)=>f.generateCode()).join("");return{contents:u+g+m}})}}}function ue(n){if(n===!0)return Object.keys(yn);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in yn)).map(([r])=>r)}function ce(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
10
- `);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var ae,yn;var xr=d(()=>{O();ae=/\.(js|ts|jsx|tsx|mts|cts)$/,yn={dirnameFilename:{appliesTo:(n,r)=>n==="esm"&&cn(r),isNeededInFile:(n)=>/\b__dirname\b/.test(n)||/\b__filename\b/.test(n),generateCode:()=>`import { fileURLToPath } from 'url';
11
- import { dirname } from 'path';
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
15
-
16
- `},importMetaUrl:{appliesTo:(n,r)=>n==="cjs"&&cn(r),isNeededInFile:(n)=>/\bimport\.meta\.url\b/.test(n),generateCode:()=>`import { pathToFileURL } from 'url';
17
-
18
- const importMetaUrl = pathToFileURL(__filename).href;
19
-
20
- `}}});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 Br={};Rr(Br,{build:()=>Cn});async function Cn(n,r=process.cwd()){let t={files:[]},e=en(n);if(!e.entry||e.entry.length===0||!e.outDir)throw new I("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)En(r,e.outDir);G(e.silent);let{packageJson:i,path:o}=await Yn(r);if(i&&o)l.cli(`Using package.json: ${M(o,2)}`,{muted:!0,identifier:e.name,once:`${o}:${e.name}`});let s=wr(e.plugins);await yr(s,e);let c=U(e.entry),a=i?.type;if(!e.dtsOnly){let u=[pr(e,i),...hr(e.plugins).map((g)=>g.plugin)],m=e.format.flatMap((g)=>c.map(async(f)=>{let L=e.outputExtension?.({format:g,packageType:a,options:e,entry:f}).js??Mn(g,a),h=await Bun.build({entrypoints:[`${r}/${f.fullEntryPath}`],format:g,naming:{entry:Un(f.name,L)},splitting:gr(e.splitting,g),bytecode:lr(e.bytecode,g),define:mr(e.define,e.shims,e.env,g),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:[...u,br({format:g,target:e.target,shims:e.shims})],throw:!1});if(!h.success)for(let S of h.logs){if(S.level==="error")throw new I(S.message);if(S.level==="warning")l.warn(S.message);else if(S.level==="info")l.info(S.message)}let D=`${e.outDir}/${f.name}${L}`,Y=`${r}/${D}`;t.files.push({path:Y}),l.progress(g.toUpperCase(),D,{identifier:e.name})}));await Promise.all(m)}if(e.dts||e.dtsOnly){let u=await qn(r,e.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${M(u.path,2)}`,{muted:!0,identifier:e.name,once:`${u.path}:${e.name}`});let m=e.format.filter((f)=>{if(f==="iife"&&!j(a)&&e.format.includes("cjs"))return!1;return!0}),g=typeof e.dts==="object"&&e.dts.entry?U(e.dts.entry):vn(c);try{await Promise.all(g.map(async(f)=>{let L=await ar(r,f.fullEntryPath,e,u,i);await Promise.all(m.map(async(h)=>{let D=e.outputExtension?.({format:h,packageType:a,options:e,entry:f}).dts??An(h,a),Y=`${e.outDir}/${f.name}${D}`,S=`${r}/${Y}`;t.files.push({path:S}),await Bun.write(S,L),l.progress("DTS",Y,{identifier:e.name})}))}))}catch(f){if(an(f))throw f;throw new w(y(f))}}if(await Cr(s,e,t),e.onSuccess)await e.onSuccess(e)}var Bn=d(()=>{ur();B();N();mn();T();wn();dr();xr();O()});import{exec as me}from"tinyexec";var ln=E(v(),1);var K="0.4.74";var Sn="https://bunup.dev/cli-options";B();N();T();function x(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function k(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new C(`Option --${n} requires a string value`)}}function J(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new C(`Option --${n} requires a string value`)}}function Dr(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 Yr(){console.log(`
21
- Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
22
- `),console.log("For more information on available options, visit:"),console.log(`${ln.default.cyan(ln.default.underline(Sn))}
23
- `),process.exit(0)}function qr(){console.log(K),process.exit(0)}var _n={name:{flags:["n","name"],handler:k("name")},format:{flags:["f","format"],handler:J("format")},outDir:{flags:["o","out-dir"],handler:k("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:k("banner")},footer:{flags:["ft","footer"],handler:k("footer")},external:{flags:["e","external"],handler:J("external")},sourcemap:{flags:["sm","sourcemap"],handler:Dr("sourcemap")},target:{flags:["t","target"],handler:k("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:J("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:k("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:k("config")},publicPath:{flags:["pp","public-path"],handler:k("publicPath")},env:{flags:["env"],handler:k("env")},shims:{flags:["shims"],handler:x("shims")},onSuccess:{flags:["onSuccess"],handler:k("onSuccess")},filter:{flags:["filter"],handler:J("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=X(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:()=>Yr()},version:{flags:["v","version"],handler:()=>qr()}},P={};for(let n of Object.values(_n))for(let r of n.flags)P[r]=n.handler;function Hn(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=P[s];if(a)a(o,r,c);else throw new C(`Unknown option: --${i}`)}else{let s=P[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=P[i];if(c)c(s,r);else throw new C(`Unknown option: -${i}`)}else _n.entry.handler(e,r,void 0)}return r}B();T();import{loadConfig as ge}from"coffi";mn();O();Bn();B();N();T();wn();O();import tn from"path";async function Or(n,r){let t=new Set,e=en(n),i=U(e.entry);for(let u of i){let m=tn.resolve(r,u.fullEntryPath),g=tn.dirname(m);t.add(g)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,tn.join(r,e.outDir)]}),c=!1,a=async(u=!1)=>{if(c)return;c=!0;try{let m=performance.now();if(await Cn({...e,entry:i.map((g)=>g.fullEntryPath),clean:!1},r),!u)l.cli(`\uD83D\uDCE6 Rebuild finished in ${z(performance.now()-m)}`)}catch(m){un(m)}finally{c=!1}};s.on("change",(u)=>{let m=tn.relative(r,u);l.cli(`File changed: ${m}`,{muted:!0,once:m}),a()}),s.on("error",(u)=>{throw new Q(`Watcher error: ${y(u)}`)}),await a(!0)}async function fe(n=Bun.argv.slice(2)){let r=Hn(n);G(r.silent);let t=process.cwd(),{config:e,filepath:i}=await ge({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:r.config,packageJsonProperty:"bunup"}),o=!e?[{rootDir:t,options:r}]:await Dn(e,t,r.filter);if(l.cli(`Using bunup v${K} and bun v${Bun.version}`,{muted:!0}),i)l.cli(`Using config file: ${M(i,2)}`,{muted:!0});let s=performance.now();l.cli("Build started");let{build:c}=await Promise.resolve().then(() => (Bn(),Br));await Promise.all(o.flatMap(({options:m,rootDir:g})=>{return In(m).map(async(L)=>{let h={...L,...pe(r)};if(h.watch)await Or(h,g);else await c(h,g)})}));let a=performance.now()-s,u=z(a);if(l.cli(`\u26A1\uFE0F Build completed in ${u}`),r.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)l.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await me(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function pe(n){return{...n,onSuccess:void 0,config:void 0}}fe().catch((n)=>$n(n));
package/dist/index.mjs DELETED
@@ -1,16 +0,0 @@
1
- // @bun
2
- var Wr=Object.create;var{getPrototypeOf:_r,defineProperty:z,getOwnPropertyNames:Ur}=Object;var Yr=Object.prototype.hasOwnProperty;var _=(r,n,e)=>{e=r!=null?Wr(_r(r)):{};let t=n||!r||!r.__esModule?z(e,"default",{value:r,enumerable:!0}):e;for(let o of Ur(r))if(!Yr.call(t,o))z(t,o,{get:()=>r[o],enumerable:!0});return t};var Fr=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var y=Fr((hn,U)=>{var E=process||{},V=E.argv||[],M=E.env||{},Gr=!(!!M.NO_COLOR||V.includes("--no-color"))&&(!!M.FORCE_COLOR||V.includes("--color")||E.platform==="win32"||(E.stdout||{}).isTTY&&M.TERM!=="dumb"||!!M.CI),Hr=(r,n,e=r)=>(t)=>{let o=""+t,i=o.indexOf(n,r.length);return~i?r+Qr(o,n,e,i)+n:r+o+n},Qr=(r,n,e,t)=>{let o="",i=0;do o+=r.substring(i,t)+e,i=t+n.length,t=r.indexOf(n,i);while(~t);return o+r.substring(i)},X=(r=Gr)=>{let n=r?Hr:()=>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")}};U.exports=X();U.exports.createColors=X});function Kr(r){return r}function qr(r){return r}import{build as Jr}from"rolldown";import{dts as vr}from"rolldown-plugin-dts";var Zr=_(y(),1);var c=_(y(),1),N=!1;function J(r){N=r??!1}class w{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(!w.instance)w.instance=new w;return w.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:e,message:t,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),m=i?this.mutedColor(t):t,u=o?` ${n(c.default.black(` ${o} `))}`:"";return`${r(e)} ${s}${m}${u}`}output(r,n={},e=console.log){if(N||!this.shouldLog(n))return;if(n.verticalSpace)e("");if(e(r),n.verticalSpace)e("")}cli(r,n={}){let e=this.formatMessage({fgColor:this.cliColor,bgColor:c.default.bgBlue,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(r,n={}){let e=this.formatMessage({fgColor:this.infoColor,bgColor:c.default.bgCyan,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(r,n={}){let e=this.formatMessage({fgColor:this.warnColor,bgColor:c.default.bgYellow,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(r,n={}){let e=this.formatMessage({fgColor:this.errorColor,bgColor:c.default.bgRed,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}getProgressFgColor(r){for(let[n,e]of Object.entries(this.progressFgColorMap))if(r.includes(n))return e;return this.defaultColor}getProgressBgColor(r){for(let[n,e]of Object.entries(this.progressBgColorMap))if(r.includes(n))return e;return c.default.bgWhite}progress(r,n,e={}){let t=this.getProgressFgColor(r),o=this.getProgressBgColor(r),i=this.formatMessage({fgColor:t,bgColor:o,label:r,message:n,identifier:e.identifier,muted:e.muted});this.output(i,e)}}var p=w.getInstance();class $ extends Error{constructor(r){super(r);this.name="BunupError"}}class h extends ${constructor(r){super(r);this.name="BunupBuildError"}}class f extends ${constructor(r){super(r);this.name="BunupDTSBuildError"}}class A extends ${constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var d=(r)=>{if(r instanceof Error)return r.message;return String(r)};function v(r){return r instanceof A}import cr from"path";import{ResolverFactory as Nr}from"oxc-resolver";import P from"fs/promises";import zr from"path";function rr(r,n){switch(r){case"esm":return O(n)?".js":".mjs";case"cjs":return O(n)?".cjs":".js";case"iife":return".global.js"}}function nr(r,n){switch(r){case"esm":return O(n)?".d.ts":".d.mts";case"cjs":return O(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function Y(r){return r==="node"||r==="bun"}function O(r){return r==="module"}function tr(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 er(r,n){let e=zr.join(r,n);try{await P.rm(e,{recursive:!0,force:!0})}catch(t){throw new h(`Failed to clean output directory: ${t}`)}await P.mkdir(e,{recursive:!0})}function j(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))}function Vr(r){return tr(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function or(r,n){return typeof n==="string"?n===r:n.test(r)}function D(r,n,e){let o=Vr(e).some((s)=>s.test(r))||n.external?.some((s)=>or(r,s)),i=n.noExternal?.some((s)=>or(r,s));return o&&!i}import{resolveTsImportPath as Xr}from"ts-import-resolver";var I="\x00dts:",ir=(r,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(t,o){if(F(t))return t;if(!o||!F(o))return null;let i=n.tsconfig?Xr({path:t,importer:S(o),tsconfig:n.tsconfig,rootDir:e}):null;if(!i)return null;let s=C(i);if(r.has(s))return W(s);return null},load(t){if(t.startsWith(I)){let o=S(t),i=r.get(o);if(i)return i}return null}}};var K=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function sr(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function ur(r){return K.test(r)&&!sr(r)}function C(r){if(sr(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(K.test(r))return r.replace(K,".d.ts");return`${r}.d.ts`}function F(r){return r.startsWith(I)}function S(r){return r.replace(I,"")}function W(r){return`${I}${r}`}function gr(r,n){if(n===void 0)return"";let e=r.slice(0,n).split(`
3
- `),t=e.length,o=e[e.length-1].length+1;return` (${t}:${o})`}function mr(r,n,e,t){if(typeof t==="boolean"&&t)return!1;if(Array.isArray(t)){for(let o of t)if(typeof o==="string"&&r===o)return!1;else if(o instanceof RegExp&&o.test(r))return!1}return D(r,n,e)}var q;function br(r,n){return{name:"bunup:types-resolve",buildStart(){q||=new Nr({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(e,t){if(n===!1)return;if(e==="bun")return;let o=t?S(t):void 0;if(/\0/.test(e))return;if(Array.isArray(n)){if(!n.some((u)=>typeof u==="string"?u===e:u.test(e)))return}let i=o?cr.dirname(o):process.cwd(),{path:s}=await q.async(i,e);if(!s)return;if(ur(s)){let m=C(s);try{let{path:u}=await q.async(cr.dirname(s),m);if(u)return u}catch(u){}return}return s}}}async function ar(r,n,e,t,o,i){let s=C(r),m=W(s),u=typeof e.dts==="object"&&"resolve"in e.dts?e.dts.resolve:void 0;try{let{output:g}=await Jr({input:m,output:{dir:e.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(x,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;a(x)},plugins:[ir(n,o,i),u&&br(o,u),vr({dtsInput:!0,emitDtsOnly:!0})],external:(x)=>mr(x,e,t,u)});if(!g[0]?.code)return p.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return g[0].code}catch(g){throw new f(`DTS bundling failed for entry "${r}": ${d(g)}`)}}import{resolveTsImportPath as Pr}from"ts-import-resolver";var rn=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,nn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,tn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,en=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,on=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,sn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,un=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function gn(r){let n=new Set,e=[rn,nn,tn,en,on,sn,un];for(let t of e){let o=r.matchAll(t);for(let i of o)if(i[1])n.add(i[1])}return n}async function xr(r,n,e){let t=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),m=gn(s);for(let u of m){let g=n.tsconfig?Pr({path:u,importer:i,tsconfig:n.tsconfig,rootDir:e}):null;if(!g)continue;if(!t.has(g))t.add(g),o.push(g)}}catch(s){p.warn(`Error processing ${i}: ${d(s)}`)}}return t}var G=_(y(),1);import{isolatedDeclaration as mn}from"oxc-transform";async function pr(r,n){let e=!1,t=new Map;if(await Promise.all([...r].map(async(o)=>{try{let i=C(o);if(!await Bun.file(o).exists())return;let m=await Bun.file(o).text(),{code:u,errors:g}=mn(o,m);if(u)t.set(i,u);for(let x of g){if(!e&&!n)console.log(`
4
- `);let a=x.labels[0],b=a?gr(m,a.start):"",B=`${T(o)}${b}: ${cn(x.message)}`;p[n?"warn":"error"](B),e=!0}}catch(i){p.warn(`Failed to generate declaration for ${o}: ${d(i)}`)}})),e&&!n)throw console.log(`
5
- `),new A(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${G.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${G.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return t}function cn(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}import fr from"fs/promises";import H from"path";async function lr(r,n){let e=H.resolve(r),t=H.resolve(e,n);if(!await fr.exists(e))throw new f(`Root directory does not exist: ${e}`);if(!await Bun.file(t).exists())throw new f(`Entry file does not exist: ${t}`);if(!j(t))throw new f(`Entry file must be a TypeScript file: ${t}`);if(H.relative(e,t).startsWith(".."))throw new f(`Entry file must be within rootDir: ${t}`);return{absoluteRootDir:e,absoluteEntry:t}}async function dr(r,n,e,t,o){let{absoluteEntry:i}=await lr(r,n),s=await xr(i,t,r),m=await pr(s,e.watch);return ar(i,m,e,o,t,r)}import{basename as bn,dirname as an,extname as xn}from"path";function Cr(r){let n=bn(r),e=xn(n);return e?n.slice(0,-e.length):n}function Q(r){if(typeof r==="string")return[{fullEntryPath:r,name:Cr(r)}];if(typeof r==="object"&&!Array.isArray(r))return Object.entries(r).map(([t,o])=>({fullEntryPath:o,name:t}));let n=[],e=new Set;for(let t of r){let o=Cr(t);if(!e.has(o)){n.push({fullEntryPath:t,name:o}),e.add(o);continue}let s=an(t).split("/").filter((u)=>u!=="."&&u!=="");if(s.length===0){let u=1,g;do g=`${o}_${u++}`;while(e.has(g));n.push({fullEntryPath:t,name:g}),e.add(g);continue}let m=!1;for(let u=1;u<=s.length&&!m;u++){let x=`${s.slice(-u).join("/")}/${o}`;if(!e.has(x))n.push({fullEntryPath:t,name:x}),e.add(x),m=!0}if(!m){let u=1,g;do g=`${s.join("/")}/${o}_${u++}`;while(e.has(g));n.push({fullEntryPath:t,name:g}),e.add(g)}}return n}function Br(r){return r.filter((n)=>j(n.fullEntryPath))}function wr(r,n){return`[dir]/${r}${n}`}import{loadConfig as hr}from"coffi";async function Or(r){let{config:n,filepath:e}=await hr({name:"package",cwd:r,extensions:[".json"]});return{packageJson:n,path:e}}async function Rr(r,n){let{config:e,filepath:t}=await hr({name:"tsconfig",cwd:r,extensions:[".json"],preferredPath:n});return{tsconfig:e,path:t}}var pn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Tr(r){return{...pn,...r}}function Sr(r){let{minify:n,minifyWhitespace:e,minifyIdentifiers:t,minifySyntax:o}=r,i=n===!0;return{whitespace:e??i,identifiers:t??i,syntax:o??i}}function Ir(r,n){return n==="cjs"?r:void 0}function Lr(r,n,e,t){return{...typeof e==="object"&&Object.keys(e).reduce((o,i)=>{let s=JSON.stringify(e[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...r,...t==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function kr(r,n){return r===void 0?n==="esm":r}function Mr(r){return typeof r==="string"?r:void 0}function Er(r,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(t)=>{let o=t.path;if(D(o,r,n))return{path:o,external:!0};return null})}}}var fn=/\.(js|ts|jsx|tsx|mts|cts)$/,Z={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&Y(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
6
- import { dirname } from 'path';
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = dirname(__filename);
10
-
11
- `},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&Y(n),isNeededInFile:(r)=>/\bimport\.meta\.url\b/.test(r),generateCode:()=>`import { pathToFileURL } from 'url';
12
-
13
- const importMetaUrl = pathToFileURL(__filename).href;
14
-
15
- `}};function yr({format:r,target:n,shims:e}){let o=ln(e).map((i)=>Z[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:fn},async({path:s})=>{let m=await Bun.file(s).text(),u=o.filter((b)=>b.isNeededInFile(m));if(u.length===0)return;let{shebangLine:g,codeContent:x}=dn(m),a=u.map((b)=>b.generateCode()).join("");return{contents:g+a+x}})}}}function ln(r){if(r===!0)return Object.keys(Z);if(!r)return[];return Object.entries(r).filter(([n,e])=>e&&(n in Z)).map(([n])=>n)}function dn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
16
- `);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function $r(r){if(!r)return[];return r.filter((n)=>n.type==="bun")}function Ar(r){if(!r)return[];return r.filter((n)=>n.type==="bunup")}async function jr(r,n){if(!r)return;for(let e of r)if(e.hooks.onBuildStart)await e.hooks.onBuildStart(n)}async function Dr(r,n,e){if(!r)return;for(let t of r)if(t.hooks.onBuildDone)await t.hooks.onBuildDone({options:n,output:e})}async function Cn(r,n=process.cwd()){let e={files:[]},t=Tr(r);if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)er(n,t.outDir);J(t.silent);let{packageJson:o,path:i}=await Or(n);if(o&&i)p.cli(`Using package.json: ${T(i,2)}`,{muted:!0,identifier:t.name,once:`${i}:${t.name}`});let s=Ar(t.plugins);await jr(s,t);let m=Q(t.entry),u=o?.type;if(!t.dtsOnly){let g=[Er(t,o),...$r(t.plugins).map((a)=>a.plugin)],x=t.format.flatMap((a)=>m.map(async(b)=>{let R=t.outputExtension?.({format:a,packageType:u,options:t,entry:b}).js??rr(a,u),B=await Bun.build({entrypoints:[`${n}/${b.fullEntryPath}`],format:a,naming:{entry:wr(b.name,R)},splitting:kr(t.splitting,a),bytecode:Ir(t.bytecode,a),define:Lr(t.define,t.shims,t.env,a),minify:Sr(t),outdir:`${n}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:Mr(t.env),plugins:[...g,yr({format:a,target:t.target,shims:t.shims})],throw:!1});if(!B.success)for(let l of B.logs){if(l.level==="error")throw new h(l.message);if(l.level==="warning")p.warn(l.message);else if(l.level==="info")p.info(l.message)}let L=`${t.outDir}/${b.name}${R}`,k=`${n}/${L}`;e.files.push({path:k}),p.progress(a.toUpperCase(),L,{identifier:t.name})}));await Promise.all(x)}if(t.dts||t.dtsOnly){let g=await Rr(n,t.preferredTsconfigPath);if(g.path)p.cli(`Using tsconfig: ${T(g.path,2)}`,{muted:!0,identifier:t.name,once:`${g.path}:${t.name}`});let x=t.format.filter((b)=>{if(b==="iife"&&!O(u)&&t.format.includes("cjs"))return!1;return!0}),a=typeof t.dts==="object"&&t.dts.entry?Q(t.dts.entry):Br(m);try{await Promise.all(a.map(async(b)=>{let R=await dr(n,b.fullEntryPath,t,g,o);await Promise.all(x.map(async(B)=>{let L=t.outputExtension?.({format:B,packageType:u,options:t,entry:b}).dts??nr(B,u),k=`${t.outDir}/${b.name}${L}`,l=`${n}/${k}`;e.files.push({path:l}),await Bun.write(l,R),p.progress("DTS",k,{identifier:t.name})}))}))}catch(b){if(v(b))throw b;throw new f(d(b))}}if(await Dr(s,t,e),t.onSuccess)await t.onSuccess(t)}export{qr as defineWorkspace,Kr as defineConfig,Cn as build};