bunup 0.4.87 → 0.4.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,15 @@
1
+ var on=require("node:module");var vr=Object.create;var{getPrototypeOf:Pr,defineProperty:O,getOwnPropertyNames:nr,getOwnPropertyDescriptor:rn}=Object,er=Object.prototype.hasOwnProperty;var l=(r,n,t)=>{t=r!=null?vr(Pr(r)):{};let e=n||!r||!r.__esModule?O(t,"default",{value:r,enumerable:!0}):t;for(let o of nr(r))if(!er.call(e,o))O(e,o,{get:()=>r[o],enumerable:!0});return e},rr=new WeakMap,nn=(r)=>{var n=rr.get(r),t;if(n)return n;if(n=O({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")nr(r).map((e)=>!er.call(n,e)&&O(n,e,{get:()=>r[e],enumerable:!(t=rn(r,e))||t.enumerable}));return rr.set(r,n),n},en=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var tn=(r,n)=>{for(var t in n)O(r,t,{get:n[t],enumerable:!0,configurable:!0,set:(e)=>n[t]=()=>e})};var W=en((Mn,G)=>{var _=process||{},ir=_.argv||[],A=_.env||{},sn=!(!!A.NO_COLOR||ir.includes("--no-color"))&&(!!A.FORCE_COLOR||ir.includes("--color")||_.platform==="win32"||(_.stdout||{}).isTTY&&A.TERM!=="dumb"||!!A.CI),gn=(r,n,t=r)=>(e)=>{let o=""+e,i=o.indexOf(n,r.length);return~i?r+mn(o,n,t,i)+n:r+o+n},mn=(r,n,t,e)=>{let o="",i=0;do o+=r.substring(i,e)+t,i=e+n.length,e=r.indexOf(n,i);while(~e);return o+r.substring(i)},sr=(r=sn)=>{let n=r?gn:()=>String;return{isColorSupported:r,reset:n("\x1B[0m","\x1B[0m"),bold:n("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:n("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:n("\x1B[3m","\x1B[23m"),underline:n("\x1B[4m","\x1B[24m"),inverse:n("\x1B[7m","\x1B[27m"),hidden:n("\x1B[8m","\x1B[28m"),strikethrough:n("\x1B[9m","\x1B[29m"),black:n("\x1B[30m","\x1B[39m"),red:n("\x1B[31m","\x1B[39m"),green:n("\x1B[32m","\x1B[39m"),yellow:n("\x1B[33m","\x1B[39m"),blue:n("\x1B[34m","\x1B[39m"),magenta:n("\x1B[35m","\x1B[39m"),cyan:n("\x1B[36m","\x1B[39m"),white:n("\x1B[37m","\x1B[39m"),gray:n("\x1B[90m","\x1B[39m"),bgBlack:n("\x1B[40m","\x1B[49m"),bgRed:n("\x1B[41m","\x1B[49m"),bgGreen:n("\x1B[42m","\x1B[49m"),bgYellow:n("\x1B[43m","\x1B[49m"),bgBlue:n("\x1B[44m","\x1B[49m"),bgMagenta:n("\x1B[45m","\x1B[49m"),bgCyan:n("\x1B[46m","\x1B[49m"),bgWhite:n("\x1B[47m","\x1B[49m"),blackBright:n("\x1B[90m","\x1B[39m"),redBright:n("\x1B[91m","\x1B[39m"),greenBright:n("\x1B[92m","\x1B[39m"),yellowBright:n("\x1B[93m","\x1B[39m"),blueBright:n("\x1B[94m","\x1B[39m"),magentaBright:n("\x1B[95m","\x1B[39m"),cyanBright:n("\x1B[96m","\x1B[39m"),whiteBright:n("\x1B[97m","\x1B[39m"),bgBlackBright:n("\x1B[100m","\x1B[49m"),bgRedBright:n("\x1B[101m","\x1B[49m"),bgGreenBright:n("\x1B[102m","\x1B[49m"),bgYellowBright:n("\x1B[103m","\x1B[49m"),bgBlueBright:n("\x1B[104m","\x1B[49m"),bgMagentaBright:n("\x1B[105m","\x1B[49m"),bgCyanBright:n("\x1B[106m","\x1B[49m"),bgWhiteBright:n("\x1B[107m","\x1B[49m")}};G.exports=sr();G.exports.createColors=sr});var Ln={};tn(Ln,{defineWorkspace:()=>or,defineConfig:()=>tr,build:()=>Nr});module.exports=nn(Ln);function tr(r){return r}function or(r){return r}var Sr=require("rolldown"),kr=require("rolldown-plugin-dts");var un=l(W());var c=l(W()),gr=!1;function mr(r){gr=r??!1}class h{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=c.default.blue;mutedColor=c.default.dim;infoColor=c.default.cyan;warnColor=c.default.yellow;errorColor=c.default.red;defaultColor=c.default.white;progressFgColorMap={ESM:c.default.yellow,CJS:c.default.green,IIFE:c.default.magenta,DTS:c.default.blue};progressBgColorMap={ESM:c.default.bgYellow,CJS:c.default.bgGreen,IIFE:c.default.bgMagenta,DTS:c.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!h.instance)h.instance=new h;return h.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:n,label:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),u=i?this.mutedColor(e):e,g=o?` ${n(c.default.black(` ${o} `))}`:"";return`${r(t)} ${s}${u}${g}`}output(r,n={},t=console.log){if(gr||!this.shouldLog(n))return;if(n.verticalSpace)t("");if(t(r),n.verticalSpace)t("")}cli(r,n={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:c.default.bgBlue,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(r,n={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:c.default.bgCyan,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(r,n={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:c.default.bgYellow,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(r,n={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:c.default.bgRed,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}getProgressFgColor(r){for(let[n,t]of Object.entries(this.progressFgColorMap))if(r.includes(n))return t;return this.defaultColor}getProgressBgColor(r){for(let[n,t]of Object.entries(this.progressBgColorMap))if(r.includes(n))return t;return c.default.bgWhite}progress(r,n,t={}){let e=this.getProgressFgColor(r),o=this.getProgressBgColor(r),i=this.formatMessage({fgColor:e,bgColor:o,label:r,message:n,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var f=h.getInstance();class U extends Error{constructor(r){super(r);this.name="BunupError"}}class R extends U{constructor(r){super(r);this.name="BunupBuildError"}}class p extends U{constructor(r){super(r);this.name="BunupDTSBuildError"}}class F extends U{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var C=(r)=>{if(r instanceof Error)return r.message;return String(r)};function ur(r){return r instanceof F}var V=l(require("node:path")),hr=require("oxc-resolver");var H=l(require("node:fs/promises")),cr=l(require("node:path"));function ar(r,n){switch(r){case"esm":return S(n)?".js":".mjs";case"cjs":return S(n)?".cjs":".js";case"iife":return".global.js"}}function br(r,n){switch(r){case"esm":return S(n)?".d.ts":".d.mts";case"cjs":return S(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(r){return r==="node"||r==="bun"}function S(r){return r==="module"}function xr(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 fr(r,n){let t=cr.default.join(r,n);try{await H.default.rm(t,{recursive:!0,force:!0})}catch(e){throw new R(`Failed to clean output directory: ${e}`)}await H.default.mkdir(t,{recursive:!0})}function cn(r){return xr(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function pr(r,n){return typeof n==="string"?n===r:n.test(r)}function Y(r,n,t){let o=cn(t).some((s)=>s.test(r))||n.external?.some((s)=>pr(r,s)),i=n.noExternal?.some((s)=>pr(r,s));return o&&!i}var dr=require("ts-import-resolver");var $="\x00dts:",lr=(r,n,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(Q(e))return e;if(!o||!Q(o))return null;let i=n.tsconfig?dr.resolveTsImportPath({path:e,importer:E(o),tsconfig:n.tsconfig,rootDir:t}):null;if(!i)return null;let s=B(i);if(r.has(s))return K(s);return null},load(e){if(e.startsWith($)){let o=E(e),i=r.get(o);if(i)return i}return null}}};var Z=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function j(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function Cr(r){return Z.test(r)&&!j(r)}function k(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))&&!j(r)}function B(r){if(j(r))return r;if(r.endsWith(".mts"))return`${r.slice(0,-4)}.d.mts`;if(r.endsWith(".cts"))return`${r.slice(0,-4)}.d.cts`;if(Z.test(r))return r.replace(Z,".d.ts");return`${r}.d.ts`}function Q(r){return r.startsWith($)}function E(r){return r.replace($,"")}function K(r){return`${$}${r}`}function Br(r,n){if(n===void 0)return"";let t=r.slice(0,n).split(`
2
+ `),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function wr(r,n,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let o of e)if(typeof o==="string"&&r===o)return!1;else if(o instanceof RegExp&&o.test(r))return!1}return Y(r,n,t)}var z;function Rr(r,n){return{name:"bunup:types-resolve",buildStart(){z||=new hr.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...r.path&&{tsconfig:{configFile:r.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(n===!1)return;if(t==="bun")return;let o=e?E(e):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((g)=>typeof g==="string"?g===t:g.test(t)))return}let i=o?V.default.dirname(o):process.cwd(),{path:s}=await z.async(i,t);if(!s)return;if(Cr(s)){let u=B(s);try{let{path:g}=await z.async(V.default.dirname(s),u);if(g)return g}catch(g){}return}return s}}}async function Lr(r,n,t,e,o,i){let s=B(r),u=K(s),g=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:m}=await Sr.build({input:u,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(x,b){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;b(x)},plugins:[lr(n,o,i),g&&Rr(o,g),kr.dts({dtsInput:!0,emitDtsOnly:!0})],external:(x)=>wr(x,t,e,g)});if(!m[0]?.code)return f.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return m[0].code}catch(m){throw new p(`DTS bundling failed for entry "${r}": ${C(m)}`)}}var yr=require("ts-import-resolver");var an=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,bn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,xn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,fn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,pn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,dn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ln=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Cn(r){let n=new Set,t=[an,bn,xn,fn,pn,dn,ln];for(let e of t){let o=r.matchAll(e);for(let i of o)if(i[1])n.add(i[1])}return n}async function Ir(r,n,t){let e=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),u=Cn(s);for(let g of u){let m=n.tsconfig?yr.resolveTsImportPath({path:g,importer:i,tsconfig:n.tsconfig,rootDir:t}):null;if(!m||!(k(m)||j(m)))continue;if(!e.has(m))e.add(m),o.push(m)}}catch(s){f.warn(`Error processing ${i}: ${C(s)}`)}}return e}var Mr=require("oxc-transform"),X=l(W());async function Or(r,n){let t=!1,e=new Map;if(await Promise.all([...r].map(async(o)=>{try{let i=B(o);if(!await Bun.file(o).exists())return;let u=await Bun.file(o).text(),{code:g,errors:m}=Mr.isolatedDeclaration(o,u);if(g)e.set(i,g);for(let x of m){if(!t&&!n)console.log(`
3
+ `);let b=x.labels[0],a=b?Br(u,b.start):"",w=`${T(o)}${a}: ${Bn(x.message)}`;f[n?"warn":"error"](w),t=!0}}catch(i){f.warn(`Failed to generate declaration for ${o}: ${C(i)}`)}})),t&&!n)throw console.log(`
4
+ `),new F(`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 ${X.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${X.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function Bn(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var J=l(require("node:fs/promises")),q=l(require("node:path"));async function Tr(r,n){let t=q.default.resolve(r),e=q.default.resolve(t,n);if(!await J.default.exists(t))throw new p(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!k(e))throw new p(`Entry file must be a TypeScript file: ${e}`);if(q.default.relative(t,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function Er(r,n,t,e,o){let{absoluteEntry:i}=await Tr(r,n),s=await Ir(i,e,r),u=await Or(s,t.watch);return Lr(i,u,t,o,e,r)}var L=require("node:path");function $r(r){let n=L.basename(r),t=L.extname(n);return t?n.slice(0,-t.length):n}function N(r){if(typeof r==="string")return[{fullEntryPath:r,name:$r(r)}];if(typeof r==="object"&&!Array.isArray(r))return Object.entries(r).map(([e,o])=>({fullEntryPath:o,name:e}));let n=[],t=new Set;for(let e of r){let o=$r(e);if(!t.has(o)){n.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=L.dirname(e).split("/").filter((g)=>g!=="."&&g!=="");if(s.length===0){let g=1,m;do m=`${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m);continue}let u=!1;for(let g=1;g<=s.length&&!u;g++){let x=`${s.slice(-g).join("/")}/${o}`;if(!t.has(x))n.push({fullEntryPath:e,name:x}),t.add(x),u=!0}if(!u){let g=1,m;do m=`${s.join("/")}/${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m)}}return n}function jr(r){return r.filter((n)=>k(n.fullEntryPath))}function Ar(r,n){return`[dir]/${r}${n}`}var wn=l(require("node:path"));var v=require("unconfig");async function _r(r){let{config:n,sources:t}=await v.loadConfig({sources:[{files:"package.json",extensions:[]}],cwd:r});return{packageJson:n,path:t?.[0]}}async function Wr(r,n){let{config:t,sources:e}=await v.loadConfig({sources:n?[{files:n,extensions:[]}]:[{files:"tsconfig.json",extensions:[]}],cwd:r});return{tsconfig:t,path:e?.[0]}}var hn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Ur(r){return{...hn,...r}}function Fr(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=r,i=n===!0;return{whitespace:t??i,identifiers:e??i,syntax:o??i}}function Yr(r,n){return n==="cjs"?r:void 0}function Kr(r,n,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((o,i)=>{let s=JSON.stringify(t[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...r,...e==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function qr(r,n){return r===void 0?n==="esm":r}function Gr(r){return typeof r==="string"?r:void 0}function Hr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(Y(o,r,n))return{path:o,external:!0};return null})}}}var Rn=/\.(js|ts|jsx|tsx|mts|cts)$/,P={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&D(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
5
+ import { dirname } from 'path';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+
10
+ `},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&D(n),isNeededInFile:(r)=>/\bimport\.meta\.url\b/.test(r),generateCode:()=>`import { pathToFileURL } from 'url';
11
+
12
+ const importMetaUrl = pathToFileURL(__filename).href;
13
+
14
+ `}};function Dr({format:r,target:n,shims:t}){let o=Sn(t).map((i)=>P[i]).filter((i)=>i.appliesTo(r,n));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Rn},async({path:s})=>{let u=await Bun.file(s).text(),g=o.filter((a)=>a.isNeededInFile(u));if(g.length===0)return;let{shebangLine:m,codeContent:x}=kn(u),b=g.map((a)=>a.generateCode()).join("");return{contents:m+b+x}})}}}function Sn(r){if(r===!0)return Object.keys(P);if(!r)return[];return Object.entries(r).filter(([n,t])=>t&&(n in P)).map(([n])=>n)}function kn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
15
+ `);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function Qr(r){if(!r)return[];return r.filter((n)=>n.type==="bun")}function Zr(r){if(!r)return[];return r.filter((n)=>n.type==="bunup")}async function zr(r,n){if(!r)return;for(let t of r)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(n)}async function Vr(r,n,t){if(!r)return;for(let e of r)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:n,output:t})}async function Nr(r,n=process.cwd()){let t={files:[]},e=Ur(r);if(!e.entry||e.entry.length===0||!e.outDir)throw new R("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)fr(n,e.outDir);mr(e.silent);let{packageJson:o,path:i}=await _r(n);if(o&&i)f.cli(`Using ${T(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=Zr(e.plugins);await zr(s,e);let u=N(e.entry),g=o?.type;if(!e.dtsOnly){let m=[Hr(e,o),...Qr(e.plugins).map((b)=>b.plugin)],x=e.format.flatMap((b)=>u.map(async(a)=>{let y=e.outputExtension?.({format:b,packageType:g,options:e,entry:a}).js??ar(b,g),w=await Bun.build({entrypoints:[`${n}/${a.fullEntryPath}`],format:b,naming:{entry:Ar(a.name,y)},splitting:qr(e.splitting,b),bytecode:Yr(e.bytecode,b),define:Kr(e.define,e.shims,e.env,b),minify:Fr(e),outdir:`${n}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Gr(e.env),plugins:[...m,Dr({format:b,target:e.target,shims:e.shims})],throw:!1});if(!w.success)for(let d of w.logs){if(d.level==="error")throw new R(d.message);if(d.level==="warning")f.warn(d.message);else if(d.level==="info")f.info(d.message)}let I=Xr(e.outDir,a.name,y),M=Jr(n,I);t.files.push({fullPath:M,relativePathToOutputDir:I}),f.progress(b.toUpperCase(),I,{identifier:e.name})}));await Promise.all(x)}if(e.dts||e.dtsOnly){let m=await Wr(n,e.preferredTsconfigPath);if(m.path)f.cli(`Using ${T(m.path,2)}`,{muted:!0,identifier:e.name,once:`${m.path}:${e.name}`});let x=e.format.filter((a)=>{if(a==="iife"&&!S(g)&&e.format.includes("cjs"))return!1;return!0}),b=typeof e.dts==="object"&&e.dts.entry?N(e.dts.entry):jr(u);try{await Promise.all(b.map(async(a)=>{let y=await Er(n,a.fullEntryPath,e,m,o);await Promise.all(x.map(async(w)=>{let I=e.outputExtension?.({format:w,packageType:g,options:e,entry:a}).dts??br(w,g),M=Xr(e.outDir,a.name,I),d=Jr(n,M);t.files.push({fullPath:d,relativePathToOutputDir:M}),await Bun.write(d,y),f.progress("DTS",M,{identifier:e.name})}))}))}catch(a){if(ur(a))throw a;throw new p(C(a))}}if(await Vr(s,e,t),e.onSuccess)await e.onSuccess(e)}function Xr(r,n,t){return`${r}/${n}${t}`}function Jr(r,n){return`${r}/${n}`}
@@ -7,12 +7,69 @@ type ProcessableEntry = {
7
7
  };
8
8
 
9
9
  //#endregion
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];
10
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/plugins/types.d.ts
11
+ /**
12
+ * Represents a Bun plugin that can be used with Bunup
13
+ */
14
+ type BunupBunPlugin = {
15
+ /** Identifies this as a native Bun plugin */
16
+ type: "bun"
17
+ /** Optional name for the plugin */
18
+ name?: string
19
+ /** The actual Bun plugin implementation */
20
+ plugin: BunPlugin
21
+ };
22
+ /**
23
+ * Represents the output of a build operation
24
+ */
25
+ type BuildOutput = {
26
+ /** Array of generated files with their paths and contents */
27
+ files: Array<{
28
+ /** Path to the generated file */
29
+ fullPath: string
30
+ /** Path to the generated file relative to the output directory */
31
+ relativePathToOutputDir: string
32
+ }>
33
+ };
34
+ /**
35
+ * Context provided to build hooks
36
+ */
37
+ type BuildContext = {
38
+ /** The build options that were used */
39
+ options: BuildOptions
40
+ /** The output of the build */
41
+ output: BuildOutput
42
+ };
43
+ /**
44
+ * Hooks that can be implemented by Bunup plugins
45
+ */
46
+ type BunupPluginHooks = {
47
+ /**
48
+ * Called when a build is successfully completed
49
+ * @param ctx Build context containing options and output
50
+ */
51
+ onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
52
+ /**
53
+ * Called before a build starts
54
+ * @param options Build options that will be used
55
+ */
56
+ onBuildStart?: (options: BuildOptions) => MaybePromise<void>
57
+ };
58
+ /**
59
+ * Represents a Bunup-specific plugin
60
+ */
61
+ type BunupPlugin = {
62
+ /** Identifies this as a Bunup-specific plugin */
63
+ type: "bunup"
64
+ /** Optional name for the plugin */
65
+ name?: string
66
+ /** The hooks implemented by this plugin */
67
+ hooks: BunupPluginHooks
68
+ };
69
+ /**
70
+ * Union type representing all supported plugin types
71
+ */
72
+ type Plugin = BunupBunPlugin | BunupPlugin;
16
73
 
17
74
  //#endregion
18
75
  //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/options.d.ts
@@ -403,90 +460,31 @@ interface BuildOptions {
403
460
  }
404
461
 
405
462
  //#endregion
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
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
463
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/types.d.ts
464
+ type MaybePromise<T> = Promise<T> | T;
465
+ type WithOptional<
466
+ T,
467
+ K extends keyof T
468
+ > = Omit<T, K> & Partial<Pick<T, K>>;
469
+ type Arrayable<T> = T | T[];
470
+ type Bun = typeof _Bun;
471
+ type BunBuildOptions = Parameters<Bun["build"]>[0];
472
+ type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
473
+ type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
474
+ type DefineWorkspaceItem = {
475
+ name: string
476
+ root: string
477
+ config: DefineConfigItem | DefineConfigItem[]
464
478
  };
465
- /**
466
- * Union type representing all supported plugin types
467
- */
468
- type Plugin = BunupBunPlugin | BunupPlugin;
469
479
 
470
480
  //#endregion
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;
481
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/define.d.ts
482
+ declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
483
+ declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
484
+
485
+ //#endregion
486
+ //#region \0dts:/Users/admin/Desktop/Projects/bunup/src/build.d.ts
487
+ declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
490
488
 
491
489
  //#endregion
492
- export { report };
490
+ export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin, build, defineConfig, defineWorkspace };
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
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';
1
+ import{createRequire as Rn}from"node:module";var Fr=Object.create;var{getPrototypeOf:Yr,defineProperty:V,getOwnPropertyNames:Kr}=Object;var qr=Object.prototype.hasOwnProperty;var F=(r,n,t)=>{t=r!=null?Fr(Yr(r)):{};let e=n||!r||!r.__esModule?V(t,"default",{value:r,enumerable:!0}):t;for(let o of Kr(r))if(!qr.call(e,o))V(e,o,{get:()=>r[o],enumerable:!0});return e};var Gr=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var j=Gr((Ln,Y)=>{var $=process||{},X=$.argv||[],E=$.env||{},Qr=!(!!E.NO_COLOR||X.includes("--no-color"))&&(!!E.FORCE_COLOR||X.includes("--color")||$.platform==="win32"||($.stdout||{}).isTTY&&E.TERM!=="dumb"||!!E.CI),Zr=(r,n,t=r)=>(e)=>{let o=""+e,i=o.indexOf(n,r.length);return~i?r+zr(o,n,t,i)+n:r+o+n},zr=(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)},J=(r=Qr)=>{let n=r?Zr:()=>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")}};Y.exports=J();Y.exports.createColors=J});function Hr(r){return r}function Dr(r){return r}import{build as Pr}from"rolldown";import{dts as rn}from"rolldown-plugin-dts";var Vr=F(j(),1);var c=F(j(),1),N=!1;function v(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:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),u=i?this.mutedColor(e):e,g=o?` ${n(c.default.black(` ${o} `))}`:"";return`${r(t)} ${s}${u}${g}`}output(r,n={},t=console.log){if(N||!this.shouldLog(n))return;if(n.verticalSpace)t("");if(t(r),n.verticalSpace)t("")}cli(r,n={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:c.default.bgBlue,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(r,n={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:c.default.bgCyan,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(r,n={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:c.default.bgYellow,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(r,n={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:c.default.bgRed,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}getProgressFgColor(r){for(let[n,t]of Object.entries(this.progressFgColorMap))if(r.includes(n))return t;return this.defaultColor}getProgressBgColor(r){for(let[n,t]of Object.entries(this.progressBgColorMap))if(r.includes(n))return t;return c.default.bgWhite}progress(r,n,t={}){let e=this.getProgressFgColor(r),o=this.getProgressBgColor(r),i=this.formatMessage({fgColor:e,bgColor:o,label:r,message:n,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var f=w.getInstance();class A extends Error{constructor(r){super(r);this.name="BunupError"}}class h extends A{constructor(r){super(r);this.name="BunupBuildError"}}class p extends A{constructor(r){super(r);this.name="BunupDTSBuildError"}}class _ extends A{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var l=(r)=>{if(r instanceof Error)return r.message;return String(r)};function P(r){return r instanceof _}import cr from"node:path";import{ResolverFactory as vr}from"oxc-resolver";import rr from"node:fs/promises";import Xr from"node:path";function nr(r,n){switch(r){case"esm":return R(n)?".js":".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function er(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 K(r){return r==="node"||r==="bun"}function R(r){return r==="module"}function tr(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function I(r,n=3){return r.split("/").slice(-n).join("/")}async function or(r,n){let t=Xr.join(r,n);try{await rr.rm(t,{recursive:!0,force:!0})}catch(e){throw new h(`Failed to clean output directory: ${e}`)}await rr.mkdir(t,{recursive:!0})}function Jr(r){return tr(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function ir(r,n){return typeof n==="string"?n===r:n.test(r)}function W(r,n,t){let o=Jr(t).some((s)=>s.test(r))||n.external?.some((s)=>ir(r,s)),i=n.noExternal?.some((s)=>ir(r,s));return o&&!i}import{resolveTsImportPath as Nr}from"ts-import-resolver";var O="\x00dts:",sr=(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?Nr({path:e,importer:M(o),tsconfig:n.tsconfig,rootDir:t}):null;if(!i)return null;let s=C(i);if(r.has(s))return U(s);return null},load(e){if(e.startsWith(O)){let o=M(e),i=r.get(o);if(i)return i}return null}}};var G=/\.(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 gr(r){return G.test(r)&&!T(r)}function S(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))&&!T(r)}function C(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(G.test(r))return r.replace(G,".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(`
2
+ `),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function ur(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 W(r,n,t)}var H;function ar(r,n){return{name:"bunup:types-resolve",buildStart(){H||=new vr({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((g)=>typeof g==="string"?g===t:g.test(t)))return}let i=o?cr.dirname(o):process.cwd(),{path:s}=await H.async(i,t);if(!s)return;if(gr(s)){let u=C(s);try{let{path:g}=await H.async(cr.dirname(s),u);if(g)return g}catch(g){}return}return s}}}async function br(r,n,t,e,o,i){let s=C(r),u=U(s),g=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:m}=await Pr({input:u,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(x,b){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;b(x)},plugins:[sr(n,o,i),g&&ar(o,g),rn({dtsInput:!0,emitDtsOnly:!0})],external:(x)=>ur(x,t,e,g)});if(!m[0]?.code)return f.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return m[0].code}catch(m){throw new p(`DTS bundling failed for entry "${r}": ${l(m)}`)}}import{resolveTsImportPath as nn}from"ts-import-resolver";var en=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,tn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,on=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,sn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,gn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,mn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,un=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function cn(r){let n=new Set,t=[en,tn,on,sn,gn,mn,un];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 xr(r,n,t){let e=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),u=cn(s);for(let g of u){let m=n.tsconfig?nn({path:g,importer:i,tsconfig:n.tsconfig,rootDir:t}):null;if(!m||!(S(m)||T(m)))continue;if(!e.has(m))e.add(m),o.push(m)}}catch(s){f.warn(`Error processing ${i}: ${l(s)}`)}}return e}var D=F(j(),1);import{isolatedDeclaration as an}from"oxc-transform";async function fr(r,n){let t=!1,e=new Map;if(await Promise.all([...r].map(async(o)=>{try{let i=C(o);if(!await Bun.file(o).exists())return;let u=await Bun.file(o).text(),{code:g,errors:m}=an(o,u);if(g)e.set(i,g);for(let x of m){if(!t&&!n)console.log(`
3
+ `);let b=x.labels[0],a=b?mr(u,b.start):"",B=`${I(o)}${a}: ${bn(x.message)}`;f[n?"warn":"error"](B),t=!0}}catch(i){f.warn(`Failed to generate declaration for ${o}: ${l(i)}`)}})),t&&!n)throw console.log(`
4
+ `),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 ${D.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${D.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function bn(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}import pr from"node:fs/promises";import Q from"node:path";async function dr(r,n){let t=Q.resolve(r),e=Q.resolve(t,n);if(!await pr.exists(t))throw new p(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!S(e))throw new p(`Entry file must be a TypeScript file: ${e}`);if(Q.relative(t,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function lr(r,n,t,e,o){let{absoluteEntry:i}=await dr(r,n),s=await xr(i,e,r),u=await fr(s,t.watch);return br(i,u,t,o,e,r)}import{basename as xn,dirname as fn,extname as pn}from"node:path";function Cr(r){let n=xn(r),t=pn(n);return t?n.slice(0,-t.length):n}function Z(r){if(typeof r==="string")return[{fullEntryPath:r,name:Cr(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=Cr(e);if(!t.has(o)){n.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=fn(e).split("/").filter((g)=>g!=="."&&g!=="");if(s.length===0){let g=1,m;do m=`${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m);continue}let u=!1;for(let g=1;g<=s.length&&!u;g++){let x=`${s.slice(-g).join("/")}/${o}`;if(!t.has(x))n.push({fullEntryPath:e,name:x}),t.add(x),u=!0}if(!u){let g=1,m;do m=`${s.join("/")}/${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m)}}return n}function Br(r){return r.filter((n)=>S(n.fullEntryPath))}function wr(r,n){return`[dir]/${r}${n}`}import Le from"node:path";import{loadConfig as hr}from"unconfig";async function Rr(r){let{config:n,sources:t}=await hr({sources:[{files:"package.json",extensions:[]}],cwd:r});return{packageJson:n,path:t?.[0]}}async function Sr(r,n){let{config:t,sources:e}=await hr({sources:n?[{files:n,extensions:[]}]:[{files:"tsconfig.json",extensions:[]}],cwd:r});return{tsconfig:t,path:e?.[0]}}var dn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function kr(r){return{...dn,...r}}function Lr(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=r,i=n===!0;return{whitespace:t??i,identifiers:e??i,syntax:o??i}}function yr(r,n){return n==="cjs"?r:void 0}function Ir(r,n,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((o,i)=>{let s=JSON.stringify(t[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...r,...e==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Mr(r,n){return r===void 0?n==="esm":r}function Or(r){return typeof r==="string"?r:void 0}function Tr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(W(o,r,n))return{path:o,external:!0};return null})}}}var ln=/\.(js|ts|jsx|tsx|mts|cts)$/,z={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
5
  import { dirname } from 'path';
7
6
 
8
7
  const __filename = fileURLToPath(import.meta.url);
@@ -12,5 +11,5 @@ var Zr=Object.create;var{getPrototypeOf:Hr,defineProperty:J,getOwnPropertyNames:
12
11
 
13
12
  const importMetaUrl = pathToFileURL(__filename).href;
14
13
 
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};
14
+ `}};function Er({format:r,target:n,shims:t}){let o=Cn(t).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:ln},async({path:s})=>{let u=await Bun.file(s).text(),g=o.filter((a)=>a.isNeededInFile(u));if(g.length===0)return;let{shebangLine:m,codeContent:x}=Bn(u),b=g.map((a)=>a.generateCode()).join("");return{contents:m+b+x}})}}}function Cn(r){if(r===!0)return Object.keys(z);if(!r)return[];return Object.entries(r).filter(([n,t])=>t&&(n in z)).map(([n])=>n)}function Bn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
15
+ `);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 jr(r){if(!r)return[];return r.filter((n)=>n.type==="bunup")}async function Ar(r,n){if(!r)return;for(let t of r)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(n)}async function _r(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 wn(r,n=process.cwd()){let t={files:[]},e=kr(r);if(!e.entry||e.entry.length===0||!e.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)or(n,e.outDir);v(e.silent);let{packageJson:o,path:i}=await Rr(n);if(o&&i)f.cli(`Using ${I(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=jr(e.plugins);await Ar(s,e);let u=Z(e.entry),g=o?.type;if(!e.dtsOnly){let m=[Tr(e,o),...$r(e.plugins).map((b)=>b.plugin)],x=e.format.flatMap((b)=>u.map(async(a)=>{let k=e.outputExtension?.({format:b,packageType:g,options:e,entry:a}).js??nr(b,g),B=await Bun.build({entrypoints:[`${n}/${a.fullEntryPath}`],format:b,naming:{entry:wr(a.name,k)},splitting:Mr(e.splitting,b),bytecode:yr(e.bytecode,b),define:Ir(e.define,e.shims,e.env,b),minify:Lr(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:Or(e.env),plugins:[...m,Er({format:b,target:e.target,shims:e.shims})],throw:!1});if(!B.success)for(let d of B.logs){if(d.level==="error")throw new h(d.message);if(d.level==="warning")f.warn(d.message);else if(d.level==="info")f.info(d.message)}let L=Wr(e.outDir,a.name,k),y=Ur(n,L);t.files.push({fullPath:y,relativePathToOutputDir:L}),f.progress(b.toUpperCase(),L,{identifier:e.name})}));await Promise.all(x)}if(e.dts||e.dtsOnly){let m=await Sr(n,e.preferredTsconfigPath);if(m.path)f.cli(`Using ${I(m.path,2)}`,{muted:!0,identifier:e.name,once:`${m.path}:${e.name}`});let x=e.format.filter((a)=>{if(a==="iife"&&!R(g)&&e.format.includes("cjs"))return!1;return!0}),b=typeof e.dts==="object"&&e.dts.entry?Z(e.dts.entry):Br(u);try{await Promise.all(b.map(async(a)=>{let k=await lr(n,a.fullEntryPath,e,m,o);await Promise.all(x.map(async(B)=>{let L=e.outputExtension?.({format:B,packageType:g,options:e,entry:a}).dts??er(B,g),y=Wr(e.outDir,a.name,L),d=Ur(n,y);t.files.push({fullPath:d,relativePathToOutputDir:y}),await Bun.write(d,k),f.progress("DTS",y,{identifier:e.name})}))}))}catch(a){if(P(a))throw a;throw new p(l(a))}}if(await _r(s,e,t),e.onSuccess)await e.onSuccess(e)}function Wr(r,n,t){return`${r}/${n}${t}`}function Ur(r,n){return`${r}/${n}`}export{Dr as defineWorkspace,Hr as defineConfig,wn as build};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.4.87",
4
+ "version": "0.4.92",
5
5
  "license": "MIT",
6
6
  "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
7
7
  "type": "module",
@@ -19,16 +19,34 @@
19
19
  "homepage": "https://bunup.dev",
20
20
  "funding": "https://github.com/sponsors/arshad-yaseen",
21
21
  "keywords": ["bun", "bunup", "bun-bundler"],
22
+ "types": "./dist/index.d.ts",
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
22
25
  "files": ["dist"],
23
26
  "bin": {
24
27
  "bunup": "./dist/cli.js"
25
28
  },
26
- "main": "./dist/index.js",
27
- "module": "./dist/index.js",
28
- "types": "./dist/index.d.ts",
29
29
  "exports": {
30
- ".": "./dist/index.js",
31
- "./plugins": "./dist/plugins.js"
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ },
40
+ "./plugins": {
41
+ "import": {
42
+ "types": "./dist/plugins.d.ts",
43
+ "default": "./dist/plugins.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/plugins.d.cts",
47
+ "default": "./dist/plugins.cjs"
48
+ }
49
+ }
32
50
  },
33
51
  "scripts": {
34
52
  "build": "bunup",
@@ -59,13 +77,13 @@
59
77
  "workspaces": ["tests", "docs", "benchmarks", "create-bunup"],
60
78
  "dependencies": {
61
79
  "chokidar": "^4.0.3",
80
+ "coffi": "^0.1.24",
62
81
  "oxc-resolver": "^5.0.1",
63
82
  "oxc-transform": "^0.58.1",
64
83
  "rolldown": "1.0.0-beta.7",
65
84
  "rolldown-plugin-dts": "^0.7.0",
66
85
  "tinyexec": "^1.0.1",
67
- "ts-import-resolver": "^0.1.10",
68
- "unconfig": "^7.3.2"
86
+ "ts-import-resolver": "^0.1.10"
69
87
  },
70
88
  "peerDependencies": {
71
89
  "typescript": ">=4.5.0"
@@ -79,7 +97,7 @@
79
97
  "@biomejs/biome": "^1.9.4",
80
98
  "@types/bun": "^1.2.5",
81
99
  "bumpp": "^10.1.0",
82
- "bunup": "^0.4.78",
100
+ "bunup": "^0.4.90",
83
101
  "create-bunup": "workspace:create-bunup",
84
102
  "husky": "^9.1.7",
85
103
  "lint-staged": "^15.5.1",
package/dist/cli.js DELETED
@@ -1,23 +0,0 @@
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/plugins.js DELETED
@@ -1,2 +0,0 @@
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};