bunup 0.4.52 → 0.4.62

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.
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{exec as On}from"tinyexec";import{build as Ve}from"rolldown";import{dts as Je}from"rolldown-plugin-dts";var re=!1;function R(e){re=e??!1}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!$.instance)$.instance=new $;return $.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:n,message:t,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=o?`\x1B[38;5;${this.colors.muted}m${t}\x1B[0m`:t;if(r){let[u,...m]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${n}\x1B[0m ${i}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${m.join(" ")}${p}`}let c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${n}\x1B[0m ${i}${a}${c}`}output(e,n={},t=console.log){if(re)return;if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(t(e),n.verticalSpace)console.log("")}cli(e,n={}){let t=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(e,n={}){let t=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(e,n={}){let t=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(e,n={}){let t=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}progress(e,n,t,r){let s=String(e),o=this.colors.default,i,a,c={};if(typeof t==="string")i=t,a=r;else if(t)i=t.size,a=t.identifier,c=t;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){o=f;break}let u=this.formatMessage({colorCode:o,label:s,message:n,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var l=$.getInstance();class O extends Error{constructor(e){super(e);this.name="BunupError"}}class C extends O{constructor(e){super(e);this.name="BunupBuildError"}}class g extends O{constructor(e){super(e);this.name="BunupDTSBuildError"}}class h extends O{constructor(e){super(e);this.name="BunupCLIError"}}class M extends O{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},ze=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],G=(e,n)=>{let t=b(e),r=n?`[${n}] `:"",s="ERROR";if(e instanceof C)s="BUILD ERROR";else if(e instanceof g)s="DTS ERROR";else if(e instanceof h)s="CLI ERROR";else if(e instanceof M)s="WATCH ERROR";else if(e instanceof O)s="BUNUP ERROR";let o=ze.find((i)=>i.pattern.test(t)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${r}${t}`);if(o)console.log(`
3
+ import{exec as Sn}from"tinyexec";import{build as Ve}from"rolldown";import{dts as Je}from"rolldown-plugin-dts";var re=!1;function R(e){re=e??!1}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!$.instance)$.instance=new $;return $.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:n,message:t,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=o?`\x1B[38;5;${this.colors.muted}m${t}\x1B[0m`:t;if(r){let[u,...m]=a.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),f=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${n}\x1B[0m ${i}${u}${p} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${m.join(" ")}${f}`}let c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${n}\x1B[0m ${i}${a}${c}`}output(e,n={},t=console.log){if(re)return;if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(t(e),n.verticalSpace)console.log("")}cli(e,n={}){let t=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(e,n={}){let t=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(e,n={}){let t=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(e,n={}){let t=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}progress(e,n,t,r){let s=String(e),o=this.colors.default,i,a,c={};if(typeof t==="string")i=t,a=r;else if(t)i=t.size,a=t.identifier,c=t;for(let[m,p]of Object.entries(this.colors.progress))if(s.includes(m)){o=p;break}let u=this.formatMessage({colorCode:o,label:s,message:n,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var l=$.getInstance();class O extends Error{constructor(e){super(e);this.name="BunupError"}}class C extends O{constructor(e){super(e);this.name="BunupBuildError"}}class g extends O{constructor(e){super(e);this.name="BunupDTSBuildError"}}class h extends O{constructor(e){super(e);this.name="BunupCLIError"}}class M extends O{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},ze=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],G=(e,n)=>{let t=b(e),r=n?`[${n}] `:"",s="ERROR";if(e instanceof C)s="BUILD ERROR";else if(e instanceof g)s="DTS ERROR";else if(e instanceof h)s="CLI ERROR";else if(e instanceof M)s="WATCH ERROR";else if(e instanceof O)s="BUNUP ERROR";let o=ze.find((i)=>i.pattern.test(t)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${r}${t}`);if(o)console.log(`
4
4
  `),o.logSolution(t),console.log(`
5
- `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},se=(e,n)=>{G(e,n),process.exit(1)};import ie from"node:fs/promises";import Qe from"node:path";function K(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e=8){let n="";while(n.length<e)n+=Math.random().toString(36).substring(2);return n.substring(0,e)}function ae(e,n,t){return Array.isArray(e)?e.map((r)=>({...r,[n]:t})):{...e,[n]:t}}function ce(e){return Array.isArray(e)?e:[e]}function ue(e,n){switch(e){case"esm":return B(n)?".js":".mjs";case"cjs":return B(n)?".cjs":".js";case"iife":return".global.js"}}function le(e,n){switch(e){case"esm":return B(n)?".d.ts":".d.mts";case"cjs":return B(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function Y(e){return e==="node"||e==="bun"}function B(e){return e==="module"}function j(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function me(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function z(e){if(e===0)return"0 B";let n=["B","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(1024));if(t===0)return`${e} ${n[t]}`;return`${(e/1024**t).toFixed(2)} ${n[t]}`}function y(e,n=3){return e.split("/").slice(-n).join("/")}async function pe(e,n){let t=Qe.join(e,n);try{await ie.rm(t,{recursive:!0,force:!0})}catch(r){throw new C(`Failed to clean output directory: ${r}`)}await ie.mkdir(t,{recursive:!0})}function k(e){return[".ts",".mts",".cts",".tsx"].some((n)=>e.endsWith(n))}function fe(e){return e.map((n)=>typeof n==="string"?new RegExp(`^${K(n)}($|\\/|\\\\)`):n)}function I(e,n){return fe(e.external||[]).concat(me(n).map((t)=>new RegExp(`^${K(t)}($|\\/|\\\\)`)))}function _(e){return fe(e.noExternal||[])}import xe from"node:path";import{ResolverFactory as Xe}from"oxc-resolver";import{resolveTsImportPath as Ze}from"ts-import-resolver";var L="\x00dts:",de=(e,n,t)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(Q(r))return r;if(!s||!Q(s))return null;let o=n.tsconfig?Ze({path:r,importer:E(s),tsconfig:n.tsconfig,rootDir:t}):null;if(!o)return null;let i=w(o);if(e.has(i))return N(i);return null},load(r){if(r.startsWith(L)){let s=E(r),o=e.get(s);if(o)return S.add(s),o}return null}}};var Z=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function ge(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function X(e){return Z.test(e)&&!ge(e)}function w(e){if(ge(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(Z.test(e))return e.replace(Z,".d.ts");return`${e}.d.ts`}function be(e){if(X(e))return e;if(e.endsWith(".d.mts"))return`${e.slice(0,-6)}.mts`;if(e.endsWith(".d.cts"))return`${e.slice(0,-6)}.cts`;if(e.endsWith(".d.ts"))return`${e.slice(0,-5)}.ts`;return e}function Q(e){return e.startsWith(L)}function E(e){return e.replace(L,"")}function N(e){return`${L}${e}`}function he(e,n,t,r){if(typeof r==="boolean"&&r)return!1;if(Array.isArray(r)){for(let s of r)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return n.some((s)=>s.test(e))&&!t.some((s)=>s.test(e))}var V;function ye(e,n){return{name:"bunup:types-resolve",buildStart(){V||=new Xe({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(n===!1)return;if(t==="bun")return;let s=r?E(r):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((c)=>typeof c==="string"?c===t:c.test(t)))return}let o=s?xe.dirname(s):process.cwd(),{path:i}=await V.async(o,t);if(!i)return;if(X(i)){let a=w(i);try{let{path:c}=await V.async(xe.dirname(i),a);if(c)return c}catch(c){}return}return i}}}async function we(e,n,t,r,s,o){let i=w(e),a=N(i),c=I(t,r),u=_(t),m=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:f}=await Ve({input:a,output:{dir:t.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(p,T){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;T(p)},plugins:[de(n,s,o),m&&ye(s,m),Je({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>he(p,c,u,m)});if(!f[0]?.code)return l.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new g(`DTS bundling failed for entry "${e}": ${b(f)}`)}}import{resolveTsImportPath as Pe}from"ts-import-resolver";var en=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,nn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,tn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,rn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,sn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,on=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,an=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function cn(e){let n=new Set,t=[en,nn,tn,rn,sn,on,an];for(let r of t){let s=e.matchAll(r);for(let o of s)if(o[1])n.add(o[1])}return n}async function Ce(e,n,t){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=cn(i);for(let c of a){let u=n.tsconfig?Pe({path:c,importer:o,tsconfig:n.tsconfig,rootDir:t}):null;if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){l.warn(`Error processing ${o}: ${b(i)}`)}}return r}import{isolatedDeclaration as un}from"oxc-transform";async function $e(e){let n=new Map;return await Promise.all([...e].map(async(t)=>{try{let r=w(t);if(!await Bun.file(t).exists())return;let o=await Bun.file(t).text(),{code:i}=un(t,o);if(i)n.set(r,i)}catch(r){l.warn(`Failed to generate declaration for ${t}: ${b(r)}`)}})),n}import Oe from"node:fs/promises";import J from"node:path";import{isolatedDeclaration as ln}from"oxc-transform";async function Be(e,n){let t=J.resolve(e),r=J.resolve(t,n);if(!await Oe.exists(t))throw new g(`Root directory does not exist: ${t}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!k(r))throw new g(`Entry file must be a TypeScript file: ${r}`);if(J.relative(t,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:t,absoluteEntry:r}}async function Se(e){let n=!1;if(await Promise.all([...e].map(async(t)=>{try{let r=be(t),s=await Bun.file(r).text(),{errors:o}=ln(r,s);for(let i of o){if(!n)console.log(`
6
- `);let a=i.labels[0],c=a?mn(s,a.start):"",m=`${y(r)}${c}: ${pn(i.message)}`;l.warn(m),n=!0}}catch{}})),n)l.info(`You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.`,{muted:!0,verticalSpace:!0})}function mn(e,n){if(n===void 0)return"";let t=e.slice(0,n).split(`
7
- `),r=t.length,s=t[t.length-1].length+1;return` (${r}:${s})`}function pn(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,n,t,r,s){let{absoluteEntry:o}=await Be(e,n),i=await Ce(o,r,e),a=await $e(i);return we(o,a,t,s,r,e)}function U(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(e,{warnOnConflict:n=!0}={}){let t=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=oe(),u=`${i}_${c}`;if(n)l.warn(`Output name conflict: "${i}" is used by multiple files.
5
+ `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},se=(e,n)=>{G(e,n),process.exit(1)};import ie from"node:fs/promises";import Qe from"node:path";function K(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e=8){let n="";while(n.length<e)n+=Math.random().toString(36).substring(2);return n.substring(0,e)}function ae(e,n,t){return Array.isArray(e)?e.map((r)=>({...r,[n]:t})):{...e,[n]:t}}function ce(e){return Array.isArray(e)?e:[e]}function ue(e,n){switch(e){case"esm":return B(n)?".js":".mjs";case"cjs":return B(n)?".cjs":".js";case"iife":return".global.js"}}function le(e,n){switch(e){case"esm":return B(n)?".d.ts":".d.mts";case"cjs":return B(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function Y(e){return e==="node"||e==="bun"}function B(e){return e==="module"}function j(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function me(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function z(e){if(e===0)return"0 B";let n=["B","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(1024));if(t===0)return`${e} ${n[t]}`;return`${(e/1024**t).toFixed(2)} ${n[t]}`}function y(e,n=3){return e.split("/").slice(-n).join("/")}async function fe(e,n){let t=Qe.join(e,n);try{await ie.rm(t,{recursive:!0,force:!0})}catch(r){throw new C(`Failed to clean output directory: ${r}`)}await ie.mkdir(t,{recursive:!0})}function k(e){return[".ts",".mts",".cts",".tsx"].some((n)=>e.endsWith(n))}function pe(e){return e.map((n)=>typeof n==="string"?new RegExp(`^${K(n)}($|\\/|\\\\)`):n)}function I(e,n){return pe(e.external||[]).concat(me(n).map((t)=>new RegExp(`^${K(t)}($|\\/|\\\\)`)))}function _(e){return pe(e.noExternal||[])}import xe from"node:path";import{ResolverFactory as Xe}from"oxc-resolver";import{resolveTsImportPath as Ze}from"ts-import-resolver";var L="\x00dts:",de=(e,n,t)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(Q(r))return r;if(!s||!Q(s))return null;let o=n.tsconfig?Ze({path:r,importer:E(s),tsconfig:n.tsconfig,rootDir:t}):null;if(!o)return null;let i=w(o);if(e.has(i))return N(i);return null},load(r){if(r.startsWith(L)){let s=E(r),o=e.get(s);if(o)return S.add(s),o}return null}}};var Z=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function ge(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function X(e){return Z.test(e)&&!ge(e)}function w(e){if(ge(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(Z.test(e))return e.replace(Z,".d.ts");return`${e}.d.ts`}function be(e){if(X(e))return e;if(e.endsWith(".d.mts"))return`${e.slice(0,-6)}.mts`;if(e.endsWith(".d.cts"))return`${e.slice(0,-6)}.cts`;if(e.endsWith(".d.ts"))return`${e.slice(0,-5)}.ts`;return e}function Q(e){return e.startsWith(L)}function E(e){return e.replace(L,"")}function N(e){return`${L}${e}`}function he(e,n,t,r){if(typeof r==="boolean"&&r)return!1;if(Array.isArray(r)){for(let s of r)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return n.some((s)=>s.test(e))&&!t.some((s)=>s.test(e))}var V;function ye(e,n){return{name:"bunup:types-resolve",buildStart(){V||=new Xe({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(n===!1)return;if(t==="bun")return;let s=r?E(r):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((c)=>typeof c==="string"?c===t:c.test(t)))return}let o=s?xe.dirname(s):process.cwd(),{path:i}=await V.async(o,t);if(!i)return;if(X(i)){let a=w(i);try{let{path:c}=await V.async(xe.dirname(i),a);if(c)return c}catch(c){}return}return i}}}async function we(e,n,t,r,s,o){let i=w(e),a=N(i),c=I(t,r),u=_(t),m=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:p}=await Ve({input:a,output:{dir:t.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(f,T){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;T(f)},plugins:[de(n,s,o),m&&ye(s,m),Je({dtsInput:!0,emitDtsOnly:!0})],external:(f)=>he(f,c,u,m)});if(!p[0]?.code)return l.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return p[0].code}catch(p){throw new g(`DTS bundling failed for entry "${e}": ${b(p)}`)}}import{resolveTsImportPath as Pe}from"ts-import-resolver";var en=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,nn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,tn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,rn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,sn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,on=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,an=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function cn(e){let n=new Set,t=[en,nn,tn,rn,sn,on,an];for(let r of t){let s=e.matchAll(r);for(let o of s)if(o[1])n.add(o[1])}return n}async function Ce(e,n,t){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=cn(i);for(let c of a){let u=n.tsconfig?Pe({path:c,importer:o,tsconfig:n.tsconfig,rootDir:t}):null;if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){l.warn(`Error processing ${o}: ${b(i)}`)}}return r}import{isolatedDeclaration as un}from"oxc-transform";async function $e(e){let n=new Map;return await Promise.all([...e].map(async(t)=>{try{let r=w(t);if(!await Bun.file(t).exists())return;let o=await Bun.file(t).text(),{code:i}=un(t,o);if(i)n.set(r,i)}catch(r){l.warn(`Failed to generate declaration for ${t}: ${b(r)}`)}})),n}import Oe from"node:fs/promises";import J from"node:path";import{isolatedDeclaration as ln}from"oxc-transform";async function Be(e,n){let t=J.resolve(e),r=J.resolve(t,n);if(!await Oe.exists(t))throw new g(`Root directory does not exist: ${t}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!k(r))throw new g(`Entry file must be a TypeScript file: ${r}`);if(J.relative(t,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:t,absoluteEntry:r}}async function Se(e){let n=!1;if(await Promise.all([...e].map(async(t)=>{try{let r=be(t),s=await Bun.file(r).text(),{errors:o}=ln(r,s);for(let i of o){if(!n)console.log(`
6
+ `);let a=i.labels[0],c=a?mn(s,a.start):"",m=`${y(r)}${c}: ${fn(i.message)}`;l.warn(m),n=!0}}catch{}})),n)l.info(`You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.`,{muted:!0,verticalSpace:!0})}function mn(e,n){if(n===void 0)return"";let t=e.slice(0,n).split(`
7
+ `),r=t.length,s=t[t.length-1].length+1;return` (${r}:${s})`}function fn(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,n,t,r,s){let{absoluteEntry:o}=await Be(e,n),i=await Ce(o,r,e),a=await $e(i);return we(o,a,t,s,r,e)}import{basename as pn,extname as dn}from"node:path";function U(e){let n=pn(e),t=dn(n);return t?n.slice(0,-t.length):n}function A(e,{warnOnConflict:n=!0}={}){let t=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=oe(),u=`${i}_${c}`;if(n)l.warn(`Output name conflict: "${i}" is used by multiple files.
8
8
  Bunup uses filenames without extensions as output names by default.
9
9
 
10
10
  ${s[i]} -> ${i}.js
@@ -18,7 +18,7 @@ To fix this, use named entries in your configuration:
18
18
  }
19
19
  }
20
20
 
21
- See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0});t.push({name:u,path:a})}else t.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=U(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=U(e);o(i,e)}return t}function Ee(e){return e.filter((n)=>k(n.path))}function Le(e,n){return`[dir]/${e}${n}`}import{loadConfig as Ae}from"coffi";async function Re(e,n){return Array.isArray(e)&&"root"in e[0]?e.map((t)=>({rootDir:t.root,options:ae(t.config,"name",t.name)})):[{rootDir:n,options:e}]}async function Me(e){let{config:n,filepath:t}=await Ae({name:"package",cwd:e,extensions:[".json"],maxDepth:3});return{packageJson:n,path:t}}async function je(e,n){let{config:t,filepath:r}=await Ae({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:n,maxDepth:3});return{tsconfig:t,path:r}}var fn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function v(e){return{...fn,...e}}function ke(e){let{minify:n,minifyWhitespace:t,minifyIdentifiers:r,minifySyntax:s}=e,o=n===!0;return{whitespace:t??o,identifiers:r??o,syntax:s??o}}function Ie(e,n){return n==="cjs"?e:void 0}function _e(e,n,t,r){return{...typeof t==="object"&&Object.keys(t).reduce((s,o)=>{let i=JSON.stringify(t[o]);return s[`process.env.${o}`]=i,s[`import.meta.env.${o}`]=i,s},{}),...e,...r==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Ne(e,n){return e===void 0?n==="esm":e}function Ue(e){return typeof e==="string"?e:void 0}function ve(e,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!n.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var dn=/\.(js|ts|jsx|tsx|mts|cts)$/,P={dirnameFilename:{appliesTo:(e,n)=>e==="esm"&&Y(n),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
21
+ See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0});t.push({name:u,path:a})}else t.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=U(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=U(e);o(i,e)}return t}function Ee(e){return e.filter((n)=>k(n.path))}function Le(e,n){return`[dir]/${e}${n}`}import{loadConfig as Ae}from"coffi";async function Re(e,n){return Array.isArray(e)&&"root"in e[0]?e.map((t)=>({rootDir:t.root,options:ae(t.config,"name",t.name)})):[{rootDir:n,options:e}]}async function Me(e){let{config:n,filepath:t}=await Ae({name:"package",cwd:e,extensions:[".json"],maxDepth:3});return{packageJson:n,path:t}}async function je(e,n){let{config:t,filepath:r}=await Ae({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:n,maxDepth:3});return{tsconfig:t,path:r}}var gn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function v(e){return{...gn,...e}}function ke(e){let{minify:n,minifyWhitespace:t,minifyIdentifiers:r,minifySyntax:s}=e,o=n===!0;return{whitespace:t??o,identifiers:r??o,syntax:s??o}}function Ie(e,n){return n==="cjs"?e:void 0}function _e(e,n,t,r){return{...typeof t==="object"&&Object.keys(t).reduce((s,o)=>{let i=JSON.stringify(t[o]);return s[`process.env.${o}`]=i,s[`import.meta.env.${o}`]=i,s},{}),...e,...r==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Ne(e,n){return e===void 0?n==="esm":e}function Ue(e){return typeof e==="string"?e:void 0}function ve(e,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!n.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var bn=/\.(js|ts|jsx|tsx|mts|cts)$/,P={dirnameFilename:{appliesTo:(e,n)=>e==="esm"&&Y(n),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
22
22
  import { dirname } from 'path';
23
23
 
24
24
  const __filename = fileURLToPath(import.meta.url);
@@ -28,8 +28,8 @@ See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0}
28
28
 
29
29
  const importMetaUrl = pathToFileURL(__filename).href;
30
30
 
31
- `}};function De({format:e,target:n,shims:t}){let s=gn(t).map((o)=>P[o]).filter((o)=>o.appliesTo(e,n));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:dn},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((p)=>p.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:m}=bn(a),f=c.map((p)=>p.generateCode()).join("");return{contents:u+f+m}})}}}function gn(e){if(e===!0)return Object.keys(P);if(!e)return[];return Object.entries(e).filter(([n,t])=>t&&(n in P)).map(([n])=>n)}function bn(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let n=e.indexOf(`
32
- `);return n===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,n+1),codeContent:e.slice(n+1)}}function He(e){return e.filter((n)=>n.type==="bun").map((n)=>n.plugin)}var S=new Set;async function D(e,n=process.cwd()){let t=v(e);if(!t.entry||t.entry.length===0||!t.outDir)throw new C("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)pe(n,t.outDir);R(t.silent);let{packageJson:r,path:s}=await Me(n);if(r&&s)l.cli(`Using package.json: ${y(s,2)}`,{muted:!0,identifier:t.name,once:`${s}:${t.name}`});let o=A(t.entry),i=r?.type,a=I(t,r),c=_(t);if(!t.dtsOnly){let u=[ve(a,c),...He(t.plugins??[])],m=t.format.flatMap((f)=>o.map((p)=>{return hn(t,n,p,f,i,u)}));await Promise.all(m)}if(t.dts||t.dtsOnly){let u=await je(n,t.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${y(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let m=t.format.filter((p)=>{if(p==="iife"&&!B(i)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?A(t.dts.entry):Ee(o);try{await Promise.all(f.map(async(p)=>{let T=await Te(n,p.path,t,u,r);await Promise.all(m.map(async(te)=>{let Ke=t.outputExtension?.({format:te,packageType:i,options:t,entry:p}).dts??le(te,i),F=`${n}/${t.outDir}/${p.name}${Ke}`;await Bun.write(F,T);let Ye=Bun.file(F).size||0;l.progress("DTS",y(F),z(Ye),t.name)}))}))}catch(p){throw new g(b(p))}}if(t.onBuildSuccess)await t.onBuildSuccess(t)}async function hn(e,n,t,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:t}).js??ue(r,s),a=await Bun.build({entrypoints:[`${n}/${t.path}`],format:r,naming:{entry:Le(t.name,i)},splitting:Ne(e.splitting,r),bytecode:Ie(e.bytecode,r),define:_e(e.define,e.shims,e.env,r),minify:ke(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:Ue(e.env),plugins:[...o,De({format:r,target:e.target,shims:e.shims})],throw:!1});if(!a.success)for(let m of a.logs){if(m.level==="error")throw new C(m.message);if(m.level==="warning")l.warn(m.message);else if(m.level==="info")l.info(m.message)}let c=`${n}/${e.outDir}/${t.name}${i}`,u=Bun.file(c).size||0;l.progress(r.toUpperCase(),y(c),z(u),e.name)}var H="0.4.52";var We="https://bunup.dev/cli-options";function d(e){return(n,t)=>{t[e]=n===!0||n==="true"}}function x(e){return(n,t)=>{if(typeof n==="string")t[e]=n;else throw new h(`Option --${e} requires a string value`)}}function ee(e){return(n,t)=>{if(typeof n==="string")t[e]=n.split(",");else throw new h(`Option --${e} requires a string value`)}}function yn(e){return(n,t)=>{if(typeof n==="boolean")t[e]=n;else if(typeof n==="string")if(n.toLowerCase()==="true"||n.toLowerCase()==="false")t[e]=n.toLowerCase()==="true";else t[e]=n;else throw new h(`Option --${e} requires a boolean or string value`)}}function wn(){console.log(`
31
+ `}};function De({format:e,target:n,shims:t}){let s=hn(t).map((o)=>P[o]).filter((o)=>o.appliesTo(e,n));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:bn},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((f)=>f.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:m}=xn(a),p=c.map((f)=>f.generateCode()).join("");return{contents:u+p+m}})}}}function hn(e){if(e===!0)return Object.keys(P);if(!e)return[];return Object.entries(e).filter(([n,t])=>t&&(n in P)).map(([n])=>n)}function xn(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let n=e.indexOf(`
32
+ `);return n===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,n+1),codeContent:e.slice(n+1)}}function He(e){return e.filter((n)=>n.type==="bun").map((n)=>n.plugin)}var S=new Set;async function D(e,n=process.cwd()){let t=v(e);if(!t.entry||t.entry.length===0||!t.outDir)throw new C("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)fe(n,t.outDir);R(t.silent);let{packageJson:r,path:s}=await Me(n);if(r&&s)l.cli(`Using package.json: ${y(s,2)}`,{muted:!0,identifier:t.name,once:`${s}:${t.name}`});let o=A(t.entry),i=r?.type,a=I(t,r),c=_(t);if(!t.dtsOnly){let u=[ve(a,c),...He(t.plugins??[])],m=t.format.flatMap((p)=>o.map((f)=>{return yn(t,n,f,p,i,u)}));await Promise.all(m)}if(t.dts||t.dtsOnly){let u=await je(n,t.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${y(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let m=t.format.filter((f)=>{if(f==="iife"&&!B(i)&&t.format.includes("cjs"))return!1;return!0}),p=typeof t.dts==="object"&&t.dts.entry?A(t.dts.entry):Ee(o);try{await Promise.all(p.map(async(f)=>{let T=await Te(n,f.path,t,u,r);await Promise.all(m.map(async(te)=>{let Ke=t.outputExtension?.({format:te,packageType:i,options:t,entry:f}).dts??le(te,i),F=`${n}/${t.outDir}/${f.name}${Ke}`;await Bun.write(F,T);let Ye=Bun.file(F).size||0;l.progress("DTS",y(F),z(Ye),t.name)}))}))}catch(f){throw new g(b(f))}}if(t.onBuildSuccess)await t.onBuildSuccess(t)}async function yn(e,n,t,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:t}).js??ue(r,s),a=await Bun.build({entrypoints:[`${n}/${t.path}`],format:r,naming:{entry:Le(t.name,i)},splitting:Ne(e.splitting,r),bytecode:Ie(e.bytecode,r),define:_e(e.define,e.shims,e.env,r),minify:ke(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:Ue(e.env),plugins:[...o,De({format:r,target:e.target,shims:e.shims})],throw:!1});if(!a.success)for(let m of a.logs){if(m.level==="error")throw new C(m.message);if(m.level==="warning")l.warn(m.message);else if(m.level==="info")l.info(m.message)}let c=`${n}/${e.outDir}/${t.name}${i}`,u=Bun.file(c).size||0;l.progress(r.toUpperCase(),y(c),z(u),e.name)}var H="0.4.62";var We="https://bunup.dev/cli-options";function d(e){return(n,t)=>{t[e]=n===!0||n==="true"}}function x(e){return(n,t)=>{if(typeof n==="string")t[e]=n;else throw new h(`Option --${e} requires a string value`)}}function ee(e){return(n,t)=>{if(typeof n==="string")t[e]=n.split(",");else throw new h(`Option --${e} requires a string value`)}}function Cn(e){return(n,t)=>{if(typeof n==="boolean")t[e]=n;else if(typeof n==="string")if(n.toLowerCase()==="true"||n.toLowerCase()==="false")t[e]=n.toLowerCase()==="true";else t[e]=n;else throw new h(`Option --${e} requires a boolean or string value`)}}function $n(){console.log(`
33
33
  Bunup - A blazing-fast build tool for your libraries built with Bun.
34
34
  `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${We}\x1B[0m
35
- `),process.exit(0)}function Cn(){console.log(H),process.exit(0)}var qe={name:{flags:["n","name"],handler:x("name")},format:{flags:["f","format"],handler:ee("format")},outDir:{flags:["o","out-dir"],handler:x("outDir")},minify:{flags:["m","minify"],handler:d("minify")},watch:{flags:["w","watch"],handler:d("watch")},dts:{flags:["d","dts"],handler:d("dts")},banner:{flags:["bn","banner"],handler:x("banner")},footer:{flags:["ft","footer"],handler:x("footer")},external:{flags:["e","external"],handler:ee("external")},sourcemap:{flags:["sm","sourcemap"],handler:yn("sourcemap")},target:{flags:["t","target"],handler:x("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:d("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:d("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:d("minifySyntax")},clean:{flags:["c","clean"],handler:d("clean")},splitting:{flags:["s","splitting"],handler:d("splitting")},noExternal:{flags:["ne","no-external"],handler:ee("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:x("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:d("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:d("dtsOnly")},silent:{flags:["silent"],handler:d("silent")},config:{flags:["config"],handler:x("config")},publicPath:{flags:["pp","public-path"],handler:x("publicPath")},env:{flags:["env"],handler:x("env")},shims:{flags:["shims"],handler:d("shims")},onSuccess:{flags:["onSuccess"],handler:x("onSuccess")},entry:{flags:["entry"],handler:(e,n,t)=>{if(typeof e!=="string")throw new h(`Entry${t?` --entry.${t}`:""} requires a string value`);let r=n.entry||{};if(t){if(r[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);r[t]=e}else{let s=U(e);if(r[s])l.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}n.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof e==="string")if(e==="true"||e==="false")n.dts.resolve=e==="true";else n.dts.resolve=e.split(",");else n.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>wn()},version:{flags:["v","version"],handler:()=>Cn()}},W={};for(let e of Object.values(qe))for(let n of e.flags)W[n]=e.handler;function Fe(e){let n={};for(let t=0;t<e.length;t++){let r=e[t];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[t+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")t++}if(s.includes(".")){let[i,a]=s.split(".",2),c=W[i];if(c)c(o,n,a);else throw new h(`Unknown option: --${s}`)}else{let i=W[s];if(i)i(o,n);else throw new h(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[t+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")t++;let a=W[s];if(a)a(i,n);else throw new h(`Unknown option: -${s}`)}else qe.entry.handler(r,n,void 0)}return n}import{loadConfig as Bn}from"coffi";import q from"node:path";import $n from"chokidar";async function Ge(e,n){let t=new Set,r=v(e),s=A(r.entry);for(let c of s){let u=q.resolve(n,c.path),m=q.dirname(u);t.add(m)}let o=$n.watch(Array.from(t),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,q.join(n,r.outDir)]}),i=!1,a=async(c=!1)=>{if(i)return;i=!0;try{let u=performance.now();if(await D({...r,entry:s.map((m)=>m.path),clean:!1},n),!c)l.cli(`\uD83D\uDCE6 Rebuild finished in ${j(performance.now()-u)}`);await ne()}catch(u){G(u)}finally{i=!1}};o.on("change",(c)=>{let u=q.relative(n,c);l.cli(`File changed: ${u}`,{muted:!0,once:u}),a()}),o.on("error",(c)=>{throw new M(`Watcher error: ${b(c)}`)}),await a(!0)}async function Sn(e=Bun.argv.slice(2)){let n=Fe(e);R(n.silent);let t=process.cwd(),{config:r,filepath:s}=await Bn({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:n.config,packageJsonProperty:"bunup"}),o=!r?[{rootDir:t,options:n}]:await Re(r,t);if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),s)l.cli(`Using config file: ${y(s,2)}`,{muted:!0});let i=performance.now();l.cli("Build started"),await Promise.all(o.flatMap(({options:u,rootDir:m})=>{return ce(u).map(async(p)=>{let T={...p,...Tn(n)};return En(T,m)})}));let a=performance.now()-i,c=j(a);if(l.cli(`\u26A1\uFE0F Build completed in ${c}`),await ne(),n.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(n.onSuccess)l.cli(`Running command: ${n.onSuccess}`,{muted:!0}),On(n.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!n.watch)process.exit(0)}function Tn(e){return{...e,onSuccess:void 0,config:void 0}}async function ne(){if(S.size>0)await Se(S),S.clear()}async function En(e,n){if(e.watch)await Ge(e,n);else await D(e,n)}Sn().catch((e)=>se(e));export{ne as validateDtsFiles};
35
+ `),process.exit(0)}function On(){console.log(H),process.exit(0)}var qe={name:{flags:["n","name"],handler:x("name")},format:{flags:["f","format"],handler:ee("format")},outDir:{flags:["o","out-dir"],handler:x("outDir")},minify:{flags:["m","minify"],handler:d("minify")},watch:{flags:["w","watch"],handler:d("watch")},dts:{flags:["d","dts"],handler:d("dts")},banner:{flags:["bn","banner"],handler:x("banner")},footer:{flags:["ft","footer"],handler:x("footer")},external:{flags:["e","external"],handler:ee("external")},sourcemap:{flags:["sm","sourcemap"],handler:Cn("sourcemap")},target:{flags:["t","target"],handler:x("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:d("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:d("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:d("minifySyntax")},clean:{flags:["c","clean"],handler:d("clean")},splitting:{flags:["s","splitting"],handler:d("splitting")},noExternal:{flags:["ne","no-external"],handler:ee("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:x("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:d("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:d("dtsOnly")},silent:{flags:["silent"],handler:d("silent")},config:{flags:["config"],handler:x("config")},publicPath:{flags:["pp","public-path"],handler:x("publicPath")},env:{flags:["env"],handler:x("env")},shims:{flags:["shims"],handler:d("shims")},onSuccess:{flags:["onSuccess"],handler:x("onSuccess")},entry:{flags:["entry"],handler:(e,n,t)=>{if(typeof e!=="string")throw new h(`Entry${t?` --entry.${t}`:""} requires a string value`);let r=n.entry||{};if(t){if(r[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);r[t]=e}else{let s=U(e);if(r[s])l.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}n.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof e==="string")if(e==="true"||e==="false")n.dts.resolve=e==="true";else n.dts.resolve=e.split(",");else n.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>$n()},version:{flags:["v","version"],handler:()=>On()}},W={};for(let e of Object.values(qe))for(let n of e.flags)W[n]=e.handler;function Fe(e){let n={};for(let t=0;t<e.length;t++){let r=e[t];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[t+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")t++}if(s.includes(".")){let[i,a]=s.split(".",2),c=W[i];if(c)c(o,n,a);else throw new h(`Unknown option: --${s}`)}else{let i=W[s];if(i)i(o,n);else throw new h(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[t+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")t++;let a=W[s];if(a)a(i,n);else throw new h(`Unknown option: -${s}`)}else qe.entry.handler(r,n,void 0)}return n}import{loadConfig as Tn}from"coffi";import q from"node:path";import Bn from"chokidar";async function Ge(e,n){let t=new Set,r=v(e),s=A(r.entry);for(let c of s){let u=q.resolve(n,c.path),m=q.dirname(u);t.add(m)}let o=Bn.watch(Array.from(t),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,q.join(n,r.outDir)]}),i=!1,a=async(c=!1)=>{if(i)return;i=!0;try{let u=performance.now();if(await D({...r,entry:s.map((m)=>m.path),clean:!1},n),!c)l.cli(`\uD83D\uDCE6 Rebuild finished in ${j(performance.now()-u)}`);await ne()}catch(u){G(u)}finally{i=!1}};o.on("change",(c)=>{let u=q.relative(n,c);l.cli(`File changed: ${u}`,{muted:!0,once:u}),a()}),o.on("error",(c)=>{throw new M(`Watcher error: ${b(c)}`)}),await a(!0)}async function En(e=Bun.argv.slice(2)){let n=Fe(e);R(n.silent);let t=process.cwd(),{config:r,filepath:s}=await Tn({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:n.config,packageJsonProperty:"bunup"}),o=!r?[{rootDir:t,options:n}]:await Re(r,t);if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),s)l.cli(`Using config file: ${y(s,2)}`,{muted:!0});let i=performance.now();l.cli("Build started"),await Promise.all(o.flatMap(({options:u,rootDir:m})=>{return ce(u).map(async(f)=>{let T={...f,...Ln(n)};return An(T,m)})}));let a=performance.now()-i,c=j(a);if(l.cli(`\u26A1\uFE0F Build completed in ${c}`),await ne(),n.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(n.onSuccess)l.cli(`Running command: ${n.onSuccess}`,{muted:!0}),Sn(n.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!n.watch)process.exit(0)}function Ln(e){return{...e,onSuccess:void 0,config:void 0}}async function ne(){if(S.size>0)await Se(S),S.clear()}async function An(e,n){if(e.watch)await Ge(e,n);else await D(e,n)}En().catch((e)=>se(e));export{ne as validateDtsFiles};
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ var Qe=require("node:module");var He=Object.create;var{getPrototypeOf:Fe,defineProperty:C,getOwnPropertyNames:z,getOwnPropertyDescriptor:Ge}=Object,X=Object.prototype.hasOwnProperty;var $=(e,r,n)=>{n=e!=null?He(Fe(e)):{};let t=r||!e||!e.__esModule?C(n,"default",{value:e,enumerable:!0}):n;for(let s of z(e))if(!X.call(t,s))C(t,s,{get:()=>e[s],enumerable:!0});return t},Z=new WeakMap,Ke=(e)=>{var r=Z.get(e),n;if(r)return r;if(r=C({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")z(e).map((t)=>!X.call(r,t)&&C(r,t,{get:()=>e[t],enumerable:!(n=Ge(e,t))||n.enumerable}));return Z.set(e,r),r};var Ye=(e,r)=>{for(var n in r)C(e,n,{get:r[n],enumerable:!0,configurable:!0,set:(t)=>r[n]=()=>t})};var ar={};Ye(ar,{defineWorkspace:()=>J,defineConfig:()=>V,build:()=>ke});module.exports=Ke(ar);function V(e){return e}function J(e){return e}var de=require("rolldown"),xe=require("rolldown-plugin-dts");var v=!1;function P(e){v=e??!1}class b{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!b.instance)b.instance=new b;return b.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:r,message:n,size:t,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length)),a=i?`\x1B[38;5;${this.colors.muted}m${n}\x1B[0m`:n;if(t){let[c,...m]=a.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),g=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${c}${p} \x1B[38;5;${this.colors.size}m${t}\x1B[0m ${m.join(" ")}${g}`}let u=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${a}${u}`}output(e,r={},n=console.log){if(v)return;if(!this.shouldLog(r))return;if(r.verticalSpace)console.log("");if(n(e),r.verticalSpace)console.log("")}cli(e,r={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}info(e,r={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}warn(e,r={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.warn)}error(e,r={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.error)}progress(e,r,n,t){let s=String(e),i=this.colors.default,o,a,u={};if(typeof n==="string")o=n,a=t;else if(n)o=n.size,a=n.identifier,u=n;for(let[m,p]of Object.entries(this.colors.progress))if(s.includes(m)){i=p;break}let c=this.formatMessage({colorCode:i,label:s,message:r,size:o,identifier:a,muted:u.muted});this.output(c,u)}}var f=b.getInstance();class j extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends j{constructor(e){super(e);this.name="BunupBuildError"}}class l extends j{constructor(e){super(e);this.name="BunupDTSBuildError"}}var d=(e)=>{if(e instanceof Error)return e.message;return String(e)};var N=$(require("node:fs/promises")),ee=$(require("node:path"));function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function re(e=8){let r="";while(r.length<e)r+=Math.random().toString(36).substring(2);return r.substring(0,e)}function ne(e,r){switch(e){case"esm":return y(r)?".js":".mjs";case"cjs":return y(r)?".cjs":".js";case"iife":return".global.js"}}function te(e,r){switch(e){case"esm":return y(r)?".d.ts":".d.mts";case"cjs":return y(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function _(e){return e==="node"||e==="bun"}function y(e){return e==="module"}function se(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function W(e){if(e===0)return"0 B";let r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${r[n]}`;return`${(e/1024**n).toFixed(2)} ${r[n]}`}function w(e,r=3){return e.split("/").slice(-r).join("/")}async function oe(e,r){let n=ee.default.join(e,r);try{await N.default.rm(n,{recursive:!0,force:!0})}catch(t){throw new h(`Failed to clean output directory: ${t}`)}await N.default.mkdir(n,{recursive:!0})}function S(e){return[".ts",".mts",".cts",".tsx"].some((r)=>e.endsWith(r))}function ie(e){return e.map((r)=>typeof r==="string"?new RegExp(`^${D(r)}($|\\/|\\\\)`):r)}function T(e,r){return ie(e.external||[]).concat(se(r).map((n)=>new RegExp(`^${D(n)}($|\\/|\\\\)`)))}function R(e){return ie(e.noExternal||[])}var H=$(require("node:path")),pe=require("oxc-resolver");var ae=require("ts-import-resolver");var B="\x00dts:",ue=(e,r,n)=>{return{name:"bunup:virtual-dts",async resolveId(t,s){if(k(t))return t;if(!s||!k(s))return null;let i=r.tsconfig?ae.resolveTsImportPath({path:t,importer:E(s),tsconfig:r.tsconfig,rootDir:n}):null;if(!i)return null;let o=x(i);if(e.has(o))return O(o);return null},load(t){if(t.startsWith(B)){let s=E(t),i=e.get(s);if(i)return ce.add(s),i}return null}}};var U=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function me(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function ge(e){return U.test(e)&&!me(e)}function x(e){if(me(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(U.test(e))return e.replace(U,".d.ts");return`${e}.d.ts`}function k(e){return e.startsWith(B)}function E(e){return e.replace(B,"")}function O(e){return`${B}${e}`}function fe(e,r,n,t){if(typeof t==="boolean"&&t)return!1;if(Array.isArray(t)){for(let s of t)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return r.some((s)=>s.test(e))&&!n.some((s)=>s.test(e))}var q;function le(e,r){return{name:"bunup:types-resolve",buildStart(){q||=new pe.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(n,t){if(r===!1)return;if(n==="bun")return;let s=t?E(t):void 0;if(/\0/.test(n))return;if(Array.isArray(r)){if(!r.some((u)=>typeof u==="string"?u===n:u.test(n)))return}let i=s?H.default.dirname(s):process.cwd(),{path:o}=await q.async(i,n);if(!o)return;if(ge(o)){let a=x(o);try{let{path:u}=await q.async(H.default.dirname(o),a);if(u)return u}catch(u){}return}return o}}}async function be(e,r,n,t,s,i){let o=x(e),a=O(o),u=T(n,t),c=R(n),m=typeof n.dts==="object"&&"resolve"in n.dts?n.dts.resolve:void 0;try{let{output:p}=await de.build({input:a,output:{dir:n.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(g,A){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;A(g)},plugins:[ue(r,s,i),m&&le(s,m),xe.dts({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>fe(g,u,c,m)});if(!p[0]?.code)return f.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return p[0].code}catch(p){throw new l(`DTS bundling failed for entry "${e}": ${d(p)}`)}}var he=require("ts-import-resolver");var Ze=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,ze=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Xe=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ve=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ve=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Pe=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function er(e){let r=new Set,n=[Ze,ze,Xe,Ve,Je,ve,Pe];for(let t of n){let s=e.matchAll(t);for(let i of s)if(i[1])r.add(i[1])}return r}async function ye(e,r,n){let t=new Set([e]),s=[e];while(s.length){let i=s.pop();if(!i)continue;try{let o=await Bun.file(i).text(),a=er(o);for(let u of a){let c=r.tsconfig?he.resolveTsImportPath({path:u,importer:i,tsconfig:r.tsconfig,rootDir:n}):null;if(!c)continue;if(!t.has(c))t.add(c),s.push(c)}}catch(o){f.warn(`Error processing ${i}: ${d(o)}`)}}return t}var we=require("oxc-transform");async function Ce(e){let r=new Map;return await Promise.all([...e].map(async(n)=>{try{let t=x(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:o}=we.isolatedDeclaration(n,i);if(o)r.set(t,o)}catch(t){f.warn(`Failed to generate declaration for ${n}: ${d(t)}`)}})),r}var F=$(require("node:fs/promises")),L=$(require("node:path")),rr=require("oxc-transform");async function $e(e,r){let n=L.default.resolve(e),t=L.default.resolve(n,r);if(!await F.default.exists(n))throw new l(`Root directory does not exist: ${n}`);if(!await Bun.file(t).exists())throw new l(`Entry file does not exist: ${t}`);if(!S(t))throw new l(`Entry file must be a TypeScript file: ${t}`);if(L.default.relative(n,t).startsWith(".."))throw new l(`Entry file must be within rootDir: ${t}`);return{absoluteRootDir:n,absoluteEntry:t}}async function Ee(e,r,n,t,s){let{absoluteEntry:i}=await $e(e,r),o=await ye(i,t,e),a=await Ce(o);return be(i,a,n,s,t,e)}var M=require("node:path");function Be(e){let r=M.basename(e),n=M.extname(r);return n?r.slice(0,-n.length):r}function G(e,{warnOnConflict:r=!0}={}){let n=[],t=new Set,s={};function i(o,a){if(t.has(o)){let u=re(),c=`${o}_${u}`;if(r)f.warn(`Output name conflict: "${o}" is used by multiple files.
2
+ Bunup uses filenames without extensions as output names by default.
3
+
4
+ ${s[o]} -> ${o}.js
5
+ ${a} -> ${c}.js (auto-renamed to avoid conflict)
6
+
7
+ To fix this, use named entries in your configuration:
8
+ {
9
+ entry: {
10
+ custom_name: "${s[o]}",
11
+ another_name: "${a}"
12
+ }
13
+ }
14
+
15
+ See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:o,path:a}),t.add(o),s[o]=a}if(Array.isArray(e))for(let o of e){let a=Be(o);i(a,o)}else if(typeof e==="object")for(let[o,a]of Object.entries(e))i(o,a);else{let o=Be(e);i(o,e)}return n}function Se(e){return e.filter((r)=>S(r.path))}function Te(e,r){return`[dir]/${e}${r}`}var K=require("coffi");async function Re(e){let{config:r,filepath:n}=await K.loadConfig({name:"package",cwd:e,extensions:[".json"],maxDepth:3});return{packageJson:r,path:n}}async function Oe(e,r){let{config:n,filepath:t}=await K.loadConfig({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:r,maxDepth:3});return{tsconfig:n,path:t}}var nr={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Le(e){return{...nr,...e}}function Me(e){let{minify:r,minifyWhitespace:n,minifyIdentifiers:t,minifySyntax:s}=e,i=r===!0;return{whitespace:n??i,identifiers:t??i,syntax:s??i}}function Ae(e,r){return r==="cjs"?e:void 0}function Ie(e,r,n,t){return{...typeof n==="object"&&Object.keys(n).reduce((s,i)=>{let o=JSON.stringify(n[i]);return s[`process.env.${i}`]=o,s[`import.meta.env.${i}`]=o,s},{}),...e,...t==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function je(e,r){return e===void 0?r==="esm":e}function Ne(e){return typeof e==="string"?e:void 0}function De(e,r){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(t)=>{let s=t.path;if(e.some((o)=>o.test(s))&&!r.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var tr=/\.(js|ts|jsx|tsx|mts|cts)$/,Y={dirnameFilename:{appliesTo:(e,r)=>e==="esm"&&_(r),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
16
+ import { dirname } from 'path';
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = dirname(__filename);
20
+
21
+ `},importMetaUrl:{appliesTo:(e,r)=>e==="cjs"&&_(r),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
22
+
23
+ const importMetaUrl = pathToFileURL(__filename).href;
24
+
25
+ `}};function _e({format:e,target:r,shims:n}){let s=sr(n).map((i)=>Y[i]).filter((i)=>i.appliesTo(e,r));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:tr},async({path:o})=>{let a=await Bun.file(o).text(),u=s.filter((g)=>g.isNeededInFile(a));if(u.length===0)return;let{shebangLine:c,codeContent:m}=or(a),p=u.map((g)=>g.generateCode()).join("");return{contents:c+p+m}})}}}function sr(e){if(e===!0)return Object.keys(Y);if(!e)return[];return Object.entries(e).filter(([r,n])=>n&&(r in Y)).map(([r])=>r)}function or(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let r=e.indexOf(`
26
+ `);return r===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,r+1),codeContent:e.slice(r+1)}}function We(e){return e.filter((r)=>r.type==="bun").map((r)=>r.plugin)}var ce=new Set;async function ke(e,r=process.cwd()){let n=Le(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)oe(r,n.outDir);P(n.silent);let{packageJson:t,path:s}=await Re(r);if(t&&s)f.cli(`Using package.json: ${w(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let i=G(n.entry),o=t?.type,a=T(n,t),u=R(n);if(!n.dtsOnly){let c=[De(a,u),...We(n.plugins??[])],m=n.format.flatMap((p)=>i.map((g)=>{return ir(n,r,g,p,o,c)}));await Promise.all(m)}if(n.dts||n.dtsOnly){let c=await Oe(r,n.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let m=n.format.filter((g)=>{if(g==="iife"&&!y(o)&&n.format.includes("cjs"))return!1;return!0}),p=typeof n.dts==="object"&&n.dts.entry?G(n.dts.entry):Se(i);try{await Promise.all(p.map(async(g)=>{let A=await Ee(r,g.path,n,c,t);await Promise.all(m.map(async(Q)=>{let Ue=n.outputExtension?.({format:Q,packageType:o,options:n,entry:g}).dts??te(Q,o),I=`${r}/${n.outDir}/${g.name}${Ue}`;await Bun.write(I,A);let qe=Bun.file(I).size||0;f.progress("DTS",w(I),W(qe),n.name)}))}))}catch(g){throw new l(d(g))}}if(n.onBuildSuccess)await n.onBuildSuccess(n)}async function ir(e,r,n,t,s,i){let o=e.outputExtension?.({format:t,packageType:s,options:e,entry:n}).js??ne(t,s),a=await Bun.build({entrypoints:[`${r}/${n.path}`],format:t,naming:{entry:Te(n.name,o)},splitting:je(e.splitting,t),bytecode:Ae(e.bytecode,t),define:Ie(e.define,e.shims,e.env,t),minify:Me(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:Ne(e.env),plugins:[...i,_e({format:t,target:e.target,shims:e.shims})],throw:!1});if(!a.success)for(let m of a.logs){if(m.level==="error")throw new h(m.message);if(m.level==="warning")f.warn(m.message);else if(m.level==="info")f.info(m.message)}let u=`${r}/${e.outDir}/${n.name}${o}`,c=Bun.file(u).size||0;f.progress(t.toUpperCase(),w(u),W(c),e.name)}
@@ -1,18 +1,18 @@
1
- function Se(e){return e}function Te(e){return e}import{build as Me}from"rolldown";import{dts as Ae}from"rolldown-plugin-dts";var q=!1;function H(e){q=e??!1}class b{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!b.instance)b.instance=new b;return b.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:r,message:n,size:t,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length)),u=i?`\x1B[38;5;${this.colors.muted}m${n}\x1B[0m`:n;if(t){let[c,...m]=u.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),g=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${c}${f} \x1B[38;5;${this.colors.size}m${t}\x1B[0m ${m.join(" ")}${g}`}let a=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${u}${a}`}output(e,r={},n=console.log){if(q)return;if(!this.shouldLog(r))return;if(r.verticalSpace)console.log("");if(n(e),r.verticalSpace)console.log("")}cli(e,r={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}info(e,r={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}warn(e,r={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.warn)}error(e,r={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.error)}progress(e,r,n,t){let s=String(e),i=this.colors.default,o,u,a={};if(typeof n==="string")o=n,u=t;else if(n)o=n.size,u=n.identifier,a=n;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){i=f;break}let c=this.formatMessage({colorCode:i,label:s,message:r,size:o,identifier:u,muted:a.muted});this.output(c,a)}}var p=b.getInstance();class L extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends L{constructor(e){super(e);this.name="BunupBuildError"}}class l extends L{constructor(e){super(e);this.name="BunupDTSBuildError"}}var d=(e)=>{if(e instanceof Error)return e.message;return String(e)};import F from"node:fs/promises";import Re from"node:path";function M(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(e=8){let r="";while(r.length<e)r+=Math.random().toString(36).substring(2);return r.substring(0,e)}function K(e,r){switch(e){case"esm":return y(r)?".js":".mjs";case"cjs":return y(r)?".cjs":".js";case"iife":return".global.js"}}function Y(e,r){switch(e){case"esm":return y(r)?".d.ts":".d.mts";case"cjs":return y(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function A(e){return e==="node"||e==="bun"}function y(e){return e==="module"}function Q(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function j(e){if(e===0)return"0 B";let r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${r[n]}`;return`${(e/1024**n).toFixed(2)} ${r[n]}`}function w(e,r=3){return e.split("/").slice(-r).join("/")}async function Z(e,r){let n=Re.join(e,r);try{await F.rm(n,{recursive:!0,force:!0})}catch(t){throw new h(`Failed to clean output directory: ${t}`)}await F.mkdir(n,{recursive:!0})}function E(e){return[".ts",".mts",".cts",".tsx"].some((r)=>e.endsWith(r))}function z(e){return e.map((r)=>typeof r==="string"?new RegExp(`^${M(r)}($|\\/|\\\\)`):r)}function B(e,r){return z(e.external||[]).concat(Q(r).map((n)=>new RegExp(`^${M(n)}($|\\/|\\\\)`)))}function S(e){return z(e.noExternal||[])}import ee from"node:path";import{ResolverFactory as Le}from"oxc-resolver";import{resolveTsImportPath as Oe}from"ts-import-resolver";var $="\x00dts:",X=(e,r,n)=>{return{name:"bunup:virtual-dts",async resolveId(t,s){if(I(t))return t;if(!s||!I(s))return null;let i=r.tsconfig?Oe({path:t,importer:C(s),tsconfig:r.tsconfig,rootDir:n}):null;if(!i)return null;let o=x(i);if(e.has(o))return T(o);return null},load(t){if(t.startsWith($)){let s=C(t),i=e.get(s);if(i)return V.add(s),i}return null}}};var N=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function J(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function v(e){return N.test(e)&&!J(e)}function x(e){if(J(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(N.test(e))return e.replace(N,".d.ts");return`${e}.d.ts`}function I(e){return e.startsWith($)}function C(e){return e.replace($,"")}function T(e){return`${$}${e}`}function P(e,r,n,t){if(typeof t==="boolean"&&t)return!1;if(Array.isArray(t)){for(let s of t)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return r.some((s)=>s.test(e))&&!n.some((s)=>s.test(e))}var D;function re(e,r){return{name:"bunup:types-resolve",buildStart(){D||=new Le({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(n,t){if(r===!1)return;if(n==="bun")return;let s=t?C(t):void 0;if(/\0/.test(n))return;if(Array.isArray(r)){if(!r.some((a)=>typeof a==="string"?a===n:a.test(n)))return}let i=s?ee.dirname(s):process.cwd(),{path:o}=await D.async(i,n);if(!o)return;if(v(o)){let u=x(o);try{let{path:a}=await D.async(ee.dirname(o),u);if(a)return a}catch(a){}return}return o}}}async function ne(e,r,n,t,s,i){let o=x(e),u=T(o),a=B(n,t),c=S(n),m=typeof n.dts==="object"&&"resolve"in n.dts?n.dts.resolve:void 0;try{let{output:f}=await Me({input:u,output:{dir:n.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(g,R){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;R(g)},plugins:[X(r,s,i),m&&re(s,m),Ae({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>P(g,a,c,m)});if(!f[0]?.code)return p.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new l(`DTS bundling failed for entry "${e}": ${d(f)}`)}}import{resolveTsImportPath as je}from"ts-import-resolver";var Ie=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ne=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,De=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,_e=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,We=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ke=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ue=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function qe(e){let r=new Set,n=[Ie,Ne,De,_e,We,ke,Ue];for(let t of n){let s=e.matchAll(t);for(let i of s)if(i[1])r.add(i[1])}return r}async function te(e,r,n){let t=new Set([e]),s=[e];while(s.length){let i=s.pop();if(!i)continue;try{let o=await Bun.file(i).text(),u=qe(o);for(let a of u){let c=r.tsconfig?je({path:a,importer:i,tsconfig:r.tsconfig,rootDir:n}):null;if(!c)continue;if(!t.has(c))t.add(c),s.push(c)}}catch(o){p.warn(`Error processing ${i}: ${d(o)}`)}}return t}import{isolatedDeclaration as He}from"oxc-transform";async function se(e){let r=new Map;return await Promise.all([...e].map(async(n)=>{try{let t=x(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:o}=He(n,i);if(o)r.set(t,o)}catch(t){p.warn(`Failed to generate declaration for ${n}: ${d(t)}`)}})),r}import oe from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as _r}from"oxc-transform";async function ie(e,r){let n=_.resolve(e),t=_.resolve(n,r);if(!await oe.exists(n))throw new l(`Root directory does not exist: ${n}`);if(!await Bun.file(t).exists())throw new l(`Entry file does not exist: ${t}`);if(!E(t))throw new l(`Entry file must be a TypeScript file: ${t}`);if(_.relative(n,t).startsWith(".."))throw new l(`Entry file must be within rootDir: ${t}`);return{absoluteRootDir:n,absoluteEntry:t}}async function ue(e,r,n,t,s){let{absoluteEntry:i}=await ie(e,r),o=await te(i,t,e),u=await se(o);return ne(i,u,n,s,t,e)}function ae(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(e,{warnOnConflict:r=!0}={}){let n=[],t=new Set,s={};function i(o,u){if(t.has(o)){let a=G(),c=`${o}_${a}`;if(r)p.warn(`Output name conflict: "${o}" is used by multiple files.
1
+ function Se(e){return e}function Te(e){return e}import{build as Me}from"rolldown";import{dts as Ae}from"rolldown-plugin-dts";var q=!1;function H(e){q=e??!1}class b{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!b.instance)b.instance=new b;return b.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:r,message:n,size:t,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length)),a=i?`\x1B[38;5;${this.colors.muted}m${n}\x1B[0m`:n;if(t){let[c,...m]=a.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),g=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${c}${p} \x1B[38;5;${this.colors.size}m${t}\x1B[0m ${m.join(" ")}${g}`}let u=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${a}${u}`}output(e,r={},n=console.log){if(q)return;if(!this.shouldLog(r))return;if(r.verticalSpace)console.log("");if(n(e),r.verticalSpace)console.log("")}cli(e,r={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}info(e,r={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}warn(e,r={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.warn)}error(e,r={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.error)}progress(e,r,n,t){let s=String(e),i=this.colors.default,o,a,u={};if(typeof n==="string")o=n,a=t;else if(n)o=n.size,a=n.identifier,u=n;for(let[m,p]of Object.entries(this.colors.progress))if(s.includes(m)){i=p;break}let c=this.formatMessage({colorCode:i,label:s,message:r,size:o,identifier:a,muted:u.muted});this.output(c,u)}}var f=b.getInstance();class L extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends L{constructor(e){super(e);this.name="BunupBuildError"}}class l extends L{constructor(e){super(e);this.name="BunupDTSBuildError"}}var d=(e)=>{if(e instanceof Error)return e.message;return String(e)};import F from"node:fs/promises";import Re from"node:path";function M(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(e=8){let r="";while(r.length<e)r+=Math.random().toString(36).substring(2);return r.substring(0,e)}function K(e,r){switch(e){case"esm":return y(r)?".js":".mjs";case"cjs":return y(r)?".cjs":".js";case"iife":return".global.js"}}function Y(e,r){switch(e){case"esm":return y(r)?".d.ts":".d.mts";case"cjs":return y(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function A(e){return e==="node"||e==="bun"}function y(e){return e==="module"}function Q(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function I(e){if(e===0)return"0 B";let r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${r[n]}`;return`${(e/1024**n).toFixed(2)} ${r[n]}`}function w(e,r=3){return e.split("/").slice(-r).join("/")}async function Z(e,r){let n=Re.join(e,r);try{await F.rm(n,{recursive:!0,force:!0})}catch(t){throw new h(`Failed to clean output directory: ${t}`)}await F.mkdir(n,{recursive:!0})}function E(e){return[".ts",".mts",".cts",".tsx"].some((r)=>e.endsWith(r))}function z(e){return e.map((r)=>typeof r==="string"?new RegExp(`^${M(r)}($|\\/|\\\\)`):r)}function B(e,r){return z(e.external||[]).concat(Q(r).map((n)=>new RegExp(`^${M(n)}($|\\/|\\\\)`)))}function S(e){return z(e.noExternal||[])}import ee from"node:path";import{ResolverFactory as Le}from"oxc-resolver";import{resolveTsImportPath as Oe}from"ts-import-resolver";var $="\x00dts:",X=(e,r,n)=>{return{name:"bunup:virtual-dts",async resolveId(t,s){if(j(t))return t;if(!s||!j(s))return null;let i=r.tsconfig?Oe({path:t,importer:C(s),tsconfig:r.tsconfig,rootDir:n}):null;if(!i)return null;let o=x(i);if(e.has(o))return T(o);return null},load(t){if(t.startsWith($)){let s=C(t),i=e.get(s);if(i)return V.add(s),i}return null}}};var N=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function J(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function v(e){return N.test(e)&&!J(e)}function x(e){if(J(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(N.test(e))return e.replace(N,".d.ts");return`${e}.d.ts`}function j(e){return e.startsWith($)}function C(e){return e.replace($,"")}function T(e){return`${$}${e}`}function P(e,r,n,t){if(typeof t==="boolean"&&t)return!1;if(Array.isArray(t)){for(let s of t)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return r.some((s)=>s.test(e))&&!n.some((s)=>s.test(e))}var D;function re(e,r){return{name:"bunup:types-resolve",buildStart(){D||=new Le({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(n,t){if(r===!1)return;if(n==="bun")return;let s=t?C(t):void 0;if(/\0/.test(n))return;if(Array.isArray(r)){if(!r.some((u)=>typeof u==="string"?u===n:u.test(n)))return}let i=s?ee.dirname(s):process.cwd(),{path:o}=await D.async(i,n);if(!o)return;if(v(o)){let a=x(o);try{let{path:u}=await D.async(ee.dirname(o),a);if(u)return u}catch(u){}return}return o}}}async function ne(e,r,n,t,s,i){let o=x(e),a=T(o),u=B(n,t),c=S(n),m=typeof n.dts==="object"&&"resolve"in n.dts?n.dts.resolve:void 0;try{let{output:p}=await Me({input:a,output:{dir:n.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(g,R){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;R(g)},plugins:[X(r,s,i),m&&re(s,m),Ae({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>P(g,u,c,m)});if(!p[0]?.code)return f.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return p[0].code}catch(p){throw new l(`DTS bundling failed for entry "${e}": ${d(p)}`)}}import{resolveTsImportPath as Ie}from"ts-import-resolver";var je=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ne=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,De=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,_e=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,We=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ke=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ue=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function qe(e){let r=new Set,n=[je,Ne,De,_e,We,ke,Ue];for(let t of n){let s=e.matchAll(t);for(let i of s)if(i[1])r.add(i[1])}return r}async function te(e,r,n){let t=new Set([e]),s=[e];while(s.length){let i=s.pop();if(!i)continue;try{let o=await Bun.file(i).text(),a=qe(o);for(let u of a){let c=r.tsconfig?Ie({path:u,importer:i,tsconfig:r.tsconfig,rootDir:n}):null;if(!c)continue;if(!t.has(c))t.add(c),s.push(c)}}catch(o){f.warn(`Error processing ${i}: ${d(o)}`)}}return t}import{isolatedDeclaration as He}from"oxc-transform";async function se(e){let r=new Map;return await Promise.all([...e].map(async(n)=>{try{let t=x(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:o}=He(n,i);if(o)r.set(t,o)}catch(t){f.warn(`Failed to generate declaration for ${n}: ${d(t)}`)}})),r}import oe from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as kr}from"oxc-transform";async function ie(e,r){let n=_.resolve(e),t=_.resolve(n,r);if(!await oe.exists(n))throw new l(`Root directory does not exist: ${n}`);if(!await Bun.file(t).exists())throw new l(`Entry file does not exist: ${t}`);if(!E(t))throw new l(`Entry file must be a TypeScript file: ${t}`);if(_.relative(n,t).startsWith(".."))throw new l(`Entry file must be within rootDir: ${t}`);return{absoluteRootDir:n,absoluteEntry:t}}async function ae(e,r,n,t,s){let{absoluteEntry:i}=await ie(e,r),o=await te(i,t,e),a=await se(o);return ne(i,a,n,s,t,e)}import{basename as Fe,extname as Ge}from"node:path";function ue(e){let r=Fe(e),n=Ge(r);return n?r.slice(0,-n.length):r}function W(e,{warnOnConflict:r=!0}={}){let n=[],t=new Set,s={};function i(o,a){if(t.has(o)){let u=G(),c=`${o}_${u}`;if(r)f.warn(`Output name conflict: "${o}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${s[o]} -> ${o}.js
5
- ${u} -> ${c}.js (auto-renamed to avoid conflict)
5
+ ${a} -> ${c}.js (auto-renamed to avoid conflict)
6
6
 
7
7
  To fix this, use named entries in your configuration:
8
8
  {
9
9
  entry: {
10
10
  custom_name: "${s[o]}",
11
- another_name: "${u}"
11
+ another_name: "${a}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:u})}else n.push({name:o,path:u}),t.add(o),s[o]=u}if(Array.isArray(e))for(let o of e){let u=ae(o);i(u,o)}else if(typeof e==="object")for(let[o,u]of Object.entries(e))i(o,u);else{let o=ae(e);i(o,e)}return n}function ce(e){return e.filter((r)=>E(r.path))}function me(e,r){return`[dir]/${e}${r}`}import{loadConfig as ge}from"coffi";async function pe(e){let{config:r,filepath:n}=await ge({name:"package",cwd:e,extensions:[".json"],maxDepth:3});return{packageJson:r,path:n}}async function fe(e,r){let{config:n,filepath:t}=await ge({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:r,maxDepth:3});return{tsconfig:n,path:t}}var Fe={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function le(e){return{...Fe,...e}}function de(e){let{minify:r,minifyWhitespace:n,minifyIdentifiers:t,minifySyntax:s}=e,i=r===!0;return{whitespace:n??i,identifiers:t??i,syntax:s??i}}function xe(e,r){return r==="cjs"?e:void 0}function be(e,r,n,t){return{...typeof n==="object"&&Object.keys(n).reduce((s,i)=>{let o=JSON.stringify(n[i]);return s[`process.env.${i}`]=o,s[`import.meta.env.${i}`]=o,s},{}),...e,...t==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function he(e,r){return e===void 0?r==="esm":e}function ye(e){return typeof e==="string"?e:void 0}function we(e,r){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(t)=>{let s=t.path;if(e.some((o)=>o.test(s))&&!r.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var Ge=/\.(js|ts|jsx|tsx|mts|cts)$/,k={dirnameFilename:{appliesTo:(e,r)=>e==="esm"&&A(r),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
15
+ See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:o,path:a}),t.add(o),s[o]=a}if(Array.isArray(e))for(let o of e){let a=ue(o);i(a,o)}else if(typeof e==="object")for(let[o,a]of Object.entries(e))i(o,a);else{let o=ue(e);i(o,e)}return n}function ce(e){return e.filter((r)=>E(r.path))}function me(e,r){return`[dir]/${e}${r}`}import{loadConfig as ge}from"coffi";async function fe(e){let{config:r,filepath:n}=await ge({name:"package",cwd:e,extensions:[".json"],maxDepth:3});return{packageJson:r,path:n}}async function pe(e,r){let{config:n,filepath:t}=await ge({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:r,maxDepth:3});return{tsconfig:n,path:t}}var Ke={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function le(e){return{...Ke,...e}}function de(e){let{minify:r,minifyWhitespace:n,minifyIdentifiers:t,minifySyntax:s}=e,i=r===!0;return{whitespace:n??i,identifiers:t??i,syntax:s??i}}function xe(e,r){return r==="cjs"?e:void 0}function be(e,r,n,t){return{...typeof n==="object"&&Object.keys(n).reduce((s,i)=>{let o=JSON.stringify(n[i]);return s[`process.env.${i}`]=o,s[`import.meta.env.${i}`]=o,s},{}),...e,...t==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function he(e,r){return e===void 0?r==="esm":e}function ye(e){return typeof e==="string"?e:void 0}function we(e,r){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(t)=>{let s=t.path;if(e.some((o)=>o.test(s))&&!r.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var Ye=/\.(js|ts|jsx|tsx|mts|cts)$/,k={dirnameFilename:{appliesTo:(e,r)=>e==="esm"&&A(r),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
16
16
  import { dirname } from 'path';
17
17
 
18
18
  const __filename = fileURLToPath(import.meta.url);
@@ -22,5 +22,5 @@ See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0}
22
22
 
23
23
  const importMetaUrl = pathToFileURL(__filename).href;
24
24
 
25
- `}};function Ce({format:e,target:r,shims:n}){let s=Ke(n).map((i)=>k[i]).filter((i)=>i.appliesTo(e,r));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Ge},async({path:o})=>{let u=await Bun.file(o).text(),a=s.filter((g)=>g.isNeededInFile(u));if(a.length===0)return;let{shebangLine:c,codeContent:m}=Ye(u),f=a.map((g)=>g.generateCode()).join("");return{contents:c+f+m}})}}}function Ke(e){if(e===!0)return Object.keys(k);if(!e)return[];return Object.entries(e).filter(([r,n])=>n&&(r in k)).map(([r])=>r)}function Ye(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let r=e.indexOf(`
26
- `);return r===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,r+1),codeContent:e.slice(r+1)}}function $e(e){return e.filter((r)=>r.type==="bun").map((r)=>r.plugin)}var V=new Set;async function Qe(e,r=process.cwd()){let n=le(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)Z(r,n.outDir);H(n.silent);let{packageJson:t,path:s}=await pe(r);if(t&&s)p.cli(`Using package.json: ${w(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let i=W(n.entry),o=t?.type,u=B(n,t),a=S(n);if(!n.dtsOnly){let c=[we(u,a),...$e(n.plugins??[])],m=n.format.flatMap((f)=>i.map((g)=>{return Ze(n,r,g,f,o,c)}));await Promise.all(m)}if(n.dts||n.dtsOnly){let c=await fe(r,n.preferredTsconfigPath);if(c.path)p.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let m=n.format.filter((g)=>{if(g==="iife"&&!y(o)&&n.format.includes("cjs"))return!1;return!0}),f=typeof n.dts==="object"&&n.dts.entry?W(n.dts.entry):ce(i);try{await Promise.all(f.map(async(g)=>{let R=await ue(r,g.path,n,c,t);await Promise.all(m.map(async(U)=>{let Ee=n.outputExtension?.({format:U,packageType:o,options:n,entry:g}).dts??Y(U,o),O=`${r}/${n.outDir}/${g.name}${Ee}`;await Bun.write(O,R);let Be=Bun.file(O).size||0;p.progress("DTS",w(O),j(Be),n.name)}))}))}catch(g){throw new l(d(g))}}if(n.onBuildSuccess)await n.onBuildSuccess(n)}async function Ze(e,r,n,t,s,i){let o=e.outputExtension?.({format:t,packageType:s,options:e,entry:n}).js??K(t,s),u=await Bun.build({entrypoints:[`${r}/${n.path}`],format:t,naming:{entry:me(n.name,o)},splitting:he(e.splitting,t),bytecode:xe(e.bytecode,t),define:be(e.define,e.shims,e.env,t),minify:de(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:ye(e.env),plugins:[...i,Ce({format:t,target:e.target,shims:e.shims})],throw:!1});if(!u.success)for(let m of u.logs){if(m.level==="error")throw new h(m.message);if(m.level==="warning")p.warn(m.message);else if(m.level==="info")p.info(m.message)}let a=`${r}/${e.outDir}/${n.name}${o}`,c=Bun.file(a).size||0;p.progress(t.toUpperCase(),w(a),j(c),e.name)}export{Te as defineWorkspace,Se as defineConfig,Qe as build};
25
+ `}};function Ce({format:e,target:r,shims:n}){let s=Qe(n).map((i)=>k[i]).filter((i)=>i.appliesTo(e,r));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Ye},async({path:o})=>{let a=await Bun.file(o).text(),u=s.filter((g)=>g.isNeededInFile(a));if(u.length===0)return;let{shebangLine:c,codeContent:m}=Ze(a),p=u.map((g)=>g.generateCode()).join("");return{contents:c+p+m}})}}}function Qe(e){if(e===!0)return Object.keys(k);if(!e)return[];return Object.entries(e).filter(([r,n])=>n&&(r in k)).map(([r])=>r)}function Ze(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let r=e.indexOf(`
26
+ `);return r===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,r+1),codeContent:e.slice(r+1)}}function $e(e){return e.filter((r)=>r.type==="bun").map((r)=>r.plugin)}var V=new Set;async function ze(e,r=process.cwd()){let n=le(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)Z(r,n.outDir);H(n.silent);let{packageJson:t,path:s}=await fe(r);if(t&&s)f.cli(`Using package.json: ${w(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let i=W(n.entry),o=t?.type,a=B(n,t),u=S(n);if(!n.dtsOnly){let c=[we(a,u),...$e(n.plugins??[])],m=n.format.flatMap((p)=>i.map((g)=>{return Xe(n,r,g,p,o,c)}));await Promise.all(m)}if(n.dts||n.dtsOnly){let c=await pe(r,n.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let m=n.format.filter((g)=>{if(g==="iife"&&!y(o)&&n.format.includes("cjs"))return!1;return!0}),p=typeof n.dts==="object"&&n.dts.entry?W(n.dts.entry):ce(i);try{await Promise.all(p.map(async(g)=>{let R=await ae(r,g.path,n,c,t);await Promise.all(m.map(async(U)=>{let Ee=n.outputExtension?.({format:U,packageType:o,options:n,entry:g}).dts??Y(U,o),O=`${r}/${n.outDir}/${g.name}${Ee}`;await Bun.write(O,R);let Be=Bun.file(O).size||0;f.progress("DTS",w(O),I(Be),n.name)}))}))}catch(g){throw new l(d(g))}}if(n.onBuildSuccess)await n.onBuildSuccess(n)}async function Xe(e,r,n,t,s,i){let o=e.outputExtension?.({format:t,packageType:s,options:e,entry:n}).js??K(t,s),a=await Bun.build({entrypoints:[`${r}/${n.path}`],format:t,naming:{entry:me(n.name,o)},splitting:he(e.splitting,t),bytecode:xe(e.bytecode,t),define:be(e.define,e.shims,e.env,t),minify:de(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:ye(e.env),plugins:[...i,Ce({format:t,target:e.target,shims:e.shims})],throw:!1});if(!a.success)for(let m of a.logs){if(m.level==="error")throw new h(m.message);if(m.level==="warning")f.warn(m.message);else if(m.level==="info")f.info(m.message)}let u=`${r}/${e.outDir}/${n.name}${o}`,c=Bun.file(u).size||0;f.progress(t.toUpperCase(),w(u),I(c),e.name)}export{Te as defineWorkspace,Se as defineConfig,ze as build};
package/package.json CHANGED
@@ -1,82 +1,80 @@
1
1
  {
2
- "name": "bunup",
3
- "version": "0.4.52",
4
- "description": "A blazing-fast build tool for your libraries built with Bun.",
5
- "main": "./build/index.js",
6
- "types": "./build/index.d.ts",
7
- "module": "./build/index.mjs",
8
- "files": [
9
- "build"
10
- ],
11
- "bin": {
12
- "bunup": "./build/cli.mjs"
13
- },
14
- "devDependencies": {
15
- "@biomejs/biome": "^1.9.4",
16
- "@commitlint/cli": "^19.5.0",
17
- "@commitlint/config-conventional": "^19.5.0",
18
- "@types/bun": "^1.2.5",
19
- "bumpp": "^10.1.0",
20
- "bunup": "^0.4.23",
21
- "husky": "^9.1.7",
22
- "typescript": "^5.8.3",
23
- "create-bunup": "0.4.52"
24
- },
25
- "peerDependencies": {
26
- "typescript": ">=4.5.0"
27
- },
28
- "peerDependenciesMeta": {
29
- "typescript": {
30
- "optional": true
2
+ "name": "bunup",
3
+ "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
+ "version": "0.4.62",
5
+ "license": "MIT",
6
+ "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
7
+ "maintainers": [
8
+ {
9
+ "name": "Arshad Yaseen",
10
+ "email": "m@arshadyaseen.com",
11
+ "url": "https://arshadyaseen.com"
12
+ }
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/arshad-yaseen/bunup.git"
17
+ },
18
+ "homepage": "https://bunup.dev",
19
+ "funding": "https://github.com/sponsors/arshad-yaseen",
20
+ "keywords": ["bun", "bunup", "bun-bundler"],
21
+ "types": "./dist/index.d.ts",
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.mjs",
24
+ "files": ["dist"],
25
+ "bin": {
26
+ "bunup": "./dist/cli.mjs"
27
+ },
28
+ "scripts": {
29
+ "build": "bunup",
30
+ "dev": "bunup --watch",
31
+ "build:docs": "bun run --cwd docs build",
32
+ "create-bunup": "create-bunup",
33
+ "dev:docs": "bun run --cwd docs dev",
34
+ "test-build": "bun run --cwd tests build",
35
+ "test": "bun test",
36
+ "lint": "biome check .",
37
+ "lint:fix": "biome check --write .",
38
+ "format": "biome format .",
39
+ "format:fix": "biome format --write .",
40
+ "tsc": "tsc --noEmit",
41
+ "release": "bumpp",
42
+ "npm-publish": "bun publish --access public --no-git-checks",
43
+ "release:ci": "bumpp patch --yes",
44
+ "publish:ci": "bun run npm-publish && bun run --cwd create-bunup npm-publish",
45
+ "benchmark": "bun run --cwd benchmarks benchmark",
46
+ "upgrade-deps": "bunx taze -r -w && bun install && git add . && git commit -m 'chore: upgrade deps' && bun run release:ci",
47
+ "prepare": "husky",
48
+ "fetch-latest-dep-versions": "bun run --cwd create-bunup fetch-latest-dep-versions"
49
+ },
50
+ "workspaces": ["tests", "docs", "benchmarks", "create-bunup"],
51
+ "dependencies": {
52
+ "chokidar": "^4.0.3",
53
+ "coffi": "^0.1.23",
54
+ "oxc-resolver": "^5.0.1",
55
+ "oxc-transform": "^0.58.1",
56
+ "rolldown": "1.0.0-beta.7",
57
+ "rolldown-plugin-dts": "^0.7.0",
58
+ "tinyexec": "^1.0.1",
59
+ "ts-import-resolver": "^0.1.10"
60
+ },
61
+ "peerDependencies": {
62
+ "typescript": ">=4.5.0"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "typescript": {
66
+ "optional": true
67
+ }
68
+ },
69
+ "devDependencies": {
70
+ "@biomejs/biome": "^1.9.4",
71
+ "@commitlint/cli": "^19.5.0",
72
+ "@commitlint/config-conventional": "^19.5.0",
73
+ "@types/bun": "^1.2.5",
74
+ "bumpp": "^10.1.0",
75
+ "bunup": "^0.4.23",
76
+ "create-bunup": "create-bunup",
77
+ "husky": "^9.1.7",
78
+ "typescript": "^5.8.3"
31
79
  }
32
- },
33
- "keywords": [
34
- "bun",
35
- "bunup",
36
- "bun-bundler"
37
- ],
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/arshad-yaseen/bunup.git"
41
- },
42
- "homepage": "https://bunup.dev",
43
- "maintainers": [
44
- {
45
- "name": "Arshad Yaseen",
46
- "email": "m@arshadyaseen.com",
47
- "url": "https://arshadyaseen.com"
48
- }
49
- ],
50
- "license": "MIT",
51
- "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
52
- "dependencies": {
53
- "chokidar": "^4.0.3",
54
- "coffi": "^0.1.23",
55
- "oxc-resolver": "^5.0.1",
56
- "oxc-transform": "^0.58.1",
57
- "rolldown": "1.0.0-beta.7",
58
- "rolldown-plugin-dts": "^0.7.0",
59
- "tinyexec": "^1.0.1",
60
- "ts-import-resolver": "^0.1.10"
61
- },
62
- "scripts": {
63
- "build": "bunup",
64
- "dev": "bunup --watch",
65
- "build:docs": "pnpm -C docs build",
66
- "create-bunup": "create-bunup",
67
- "dev:docs": "pnpm -C docs dev",
68
- "test-build": "pnpm -C tests build",
69
- "test": "bun test",
70
- "lint": "biome check .",
71
- "lint:fix": "biome check --write .",
72
- "format": "biome format .",
73
- "format:fix": "biome format --write .",
74
- "tsc": "tsc --noEmit",
75
- "release": "bumpp -r --commit --push --tag",
76
- "release:ci": "bumpp patch -r --commit --push --tag --yes",
77
- "publish:ci": "pnpm --filter bunup --filter create-bunup publish --access public --no-git-checks",
78
- "benchmark": "pnpm -C benchmarks benchmark",
79
- "upgrade-deps": "pnpx taze -r -w && pnpm install && git add . && git commit -m 'chore: upgrade deps' && pnpm release:ci",
80
- "fetch-latest-dep-versions": "pnpm -C create-bunup fetch-latest-dep-versions"
81
- }
82
- }
80
+ }
package/build/index.js DELETED
@@ -1,26 +0,0 @@
1
- var Ye=require("node:module");var qe=Object.create;var{getPrototypeOf:He,defineProperty:C,getOwnPropertyNames:Z,getOwnPropertyDescriptor:Fe}=Object,z=Object.prototype.hasOwnProperty;var $=(e,r,n)=>{n=e!=null?qe(He(e)):{};let t=r||!e||!e.__esModule?C(n,"default",{value:e,enumerable:!0}):n;for(let s of Z(e))if(!z.call(t,s))C(t,s,{get:()=>e[s],enumerable:!0});return t},Q=new WeakMap,Ge=(e)=>{var r=Q.get(e),n;if(r)return r;if(r=C({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Z(e).map((t)=>!z.call(r,t)&&C(r,t,{get:()=>e[t],enumerable:!(n=Fe(e,t))||n.enumerable}));return Q.set(e,r),r};var Ke=(e,r)=>{for(var n in r)C(e,n,{get:r[n],enumerable:!0,configurable:!0,set:(t)=>r[n]=()=>t})};var ir={};Ke(ir,{defineWorkspace:()=>V,defineConfig:()=>X,build:()=>We});module.exports=Ge(ir);function X(e){return e}function V(e){return e}var le=require("rolldown"),de=require("rolldown-plugin-dts");var J=!1;function v(e){J=e??!1}class b{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!b.instance)b.instance=new b;return b.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:r,message:n,size:t,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length)),u=i?`\x1B[38;5;${this.colors.muted}m${n}\x1B[0m`:n;if(t){let[c,...m]=u.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),g=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${c}${f} \x1B[38;5;${this.colors.size}m${t}\x1B[0m ${m.join(" ")}${g}`}let a=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${r}\x1B[0m ${o}${u}${a}`}output(e,r={},n=console.log){if(J)return;if(!this.shouldLog(r))return;if(r.verticalSpace)console.log("");if(n(e),r.verticalSpace)console.log("")}cli(e,r={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}info(e,r={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r)}warn(e,r={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.warn)}error(e,r={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(n,r,console.error)}progress(e,r,n,t){let s=String(e),i=this.colors.default,o,u,a={};if(typeof n==="string")o=n,u=t;else if(n)o=n.size,u=n.identifier,a=n;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){i=f;break}let c=this.formatMessage({colorCode:i,label:s,message:r,size:o,identifier:u,muted:a.muted});this.output(c,a)}}var p=b.getInstance();class j extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends j{constructor(e){super(e);this.name="BunupBuildError"}}class l extends j{constructor(e){super(e);this.name="BunupDTSBuildError"}}var d=(e)=>{if(e instanceof Error)return e.message;return String(e)};var I=$(require("node:fs/promises")),P=$(require("node:path"));function N(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ee(e=8){let r="";while(r.length<e)r+=Math.random().toString(36).substring(2);return r.substring(0,e)}function re(e,r){switch(e){case"esm":return y(r)?".js":".mjs";case"cjs":return y(r)?".cjs":".js";case"iife":return".global.js"}}function ne(e,r){switch(e){case"esm":return y(r)?".d.ts":".d.mts";case"cjs":return y(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(e){return e==="node"||e==="bun"}function y(e){return e==="module"}function te(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function _(e){if(e===0)return"0 B";let r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${r[n]}`;return`${(e/1024**n).toFixed(2)} ${r[n]}`}function w(e,r=3){return e.split("/").slice(-r).join("/")}async function se(e,r){let n=P.default.join(e,r);try{await I.default.rm(n,{recursive:!0,force:!0})}catch(t){throw new h(`Failed to clean output directory: ${t}`)}await I.default.mkdir(n,{recursive:!0})}function S(e){return[".ts",".mts",".cts",".tsx"].some((r)=>e.endsWith(r))}function oe(e){return e.map((r)=>typeof r==="string"?new RegExp(`^${N(r)}($|\\/|\\\\)`):r)}function T(e,r){return oe(e.external||[]).concat(te(r).map((n)=>new RegExp(`^${N(n)}($|\\/|\\\\)`)))}function R(e){return oe(e.noExternal||[])}var q=$(require("node:path")),pe=require("oxc-resolver");var ie=require("ts-import-resolver");var B="\x00dts:",ue=(e,r,n)=>{return{name:"bunup:virtual-dts",async resolveId(t,s){if(W(t))return t;if(!s||!W(s))return null;let i=r.tsconfig?ie.resolveTsImportPath({path:t,importer:E(s),tsconfig:r.tsconfig,rootDir:n}):null;if(!i)return null;let o=x(i);if(e.has(o))return O(o);return null},load(t){if(t.startsWith(B)){let s=E(t),i=e.get(s);if(i)return ae.add(s),i}return null}}};var k=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function ce(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function me(e){return k.test(e)&&!ce(e)}function x(e){if(ce(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(k.test(e))return e.replace(k,".d.ts");return`${e}.d.ts`}function W(e){return e.startsWith(B)}function E(e){return e.replace(B,"")}function O(e){return`${B}${e}`}function ge(e,r,n,t){if(typeof t==="boolean"&&t)return!1;if(Array.isArray(t)){for(let s of t)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return r.some((s)=>s.test(e))&&!n.some((s)=>s.test(e))}var U;function fe(e,r){return{name:"bunup:types-resolve",buildStart(){U||=new pe.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(n,t){if(r===!1)return;if(n==="bun")return;let s=t?E(t):void 0;if(/\0/.test(n))return;if(Array.isArray(r)){if(!r.some((a)=>typeof a==="string"?a===n:a.test(n)))return}let i=s?q.default.dirname(s):process.cwd(),{path:o}=await U.async(i,n);if(!o)return;if(me(o)){let u=x(o);try{let{path:a}=await U.async(q.default.dirname(o),u);if(a)return a}catch(a){}return}return o}}}async function xe(e,r,n,t,s,i){let o=x(e),u=O(o),a=T(n,t),c=R(n),m=typeof n.dts==="object"&&"resolve"in n.dts?n.dts.resolve:void 0;try{let{output:f}=await le.build({input:u,output:{dir:n.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(g,M){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;M(g)},plugins:[ue(r,s,i),m&&fe(s,m),de.dts({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>ge(g,a,c,m)});if(!f[0]?.code)return p.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new l(`DTS bundling failed for entry "${e}": ${d(f)}`)}}var be=require("ts-import-resolver");var Qe=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ze=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Xe=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ve=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ve=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Pe(e){let r=new Set,n=[Qe,Ze,ze,Xe,Ve,Je,ve];for(let t of n){let s=e.matchAll(t);for(let i of s)if(i[1])r.add(i[1])}return r}async function he(e,r,n){let t=new Set([e]),s=[e];while(s.length){let i=s.pop();if(!i)continue;try{let o=await Bun.file(i).text(),u=Pe(o);for(let a of u){let c=r.tsconfig?be.resolveTsImportPath({path:a,importer:i,tsconfig:r.tsconfig,rootDir:n}):null;if(!c)continue;if(!t.has(c))t.add(c),s.push(c)}}catch(o){p.warn(`Error processing ${i}: ${d(o)}`)}}return t}var ye=require("oxc-transform");async function we(e){let r=new Map;return await Promise.all([...e].map(async(n)=>{try{let t=x(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:o}=ye.isolatedDeclaration(n,i);if(o)r.set(t,o)}catch(t){p.warn(`Failed to generate declaration for ${n}: ${d(t)}`)}})),r}var H=$(require("node:fs/promises")),L=$(require("node:path")),er=require("oxc-transform");async function Ce(e,r){let n=L.default.resolve(e),t=L.default.resolve(n,r);if(!await H.default.exists(n))throw new l(`Root directory does not exist: ${n}`);if(!await Bun.file(t).exists())throw new l(`Entry file does not exist: ${t}`);if(!S(t))throw new l(`Entry file must be a TypeScript file: ${t}`);if(L.default.relative(n,t).startsWith(".."))throw new l(`Entry file must be within rootDir: ${t}`);return{absoluteRootDir:n,absoluteEntry:t}}async function $e(e,r,n,t,s){let{absoluteEntry:i}=await Ce(e,r),o=await he(i,t,e),u=await we(o);return xe(i,u,n,s,t,e)}function Ee(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function F(e,{warnOnConflict:r=!0}={}){let n=[],t=new Set,s={};function i(o,u){if(t.has(o)){let a=ee(),c=`${o}_${a}`;if(r)p.warn(`Output name conflict: "${o}" is used by multiple files.
2
- Bunup uses filenames without extensions as output names by default.
3
-
4
- ${s[o]} -> ${o}.js
5
- ${u} -> ${c}.js (auto-renamed to avoid conflict)
6
-
7
- To fix this, use named entries in your configuration:
8
- {
9
- entry: {
10
- custom_name: "${s[o]}",
11
- another_name: "${u}"
12
- }
13
- }
14
-
15
- See: https://bunup.dev/documentation/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:u})}else n.push({name:o,path:u}),t.add(o),s[o]=u}if(Array.isArray(e))for(let o of e){let u=Ee(o);i(u,o)}else if(typeof e==="object")for(let[o,u]of Object.entries(e))i(o,u);else{let o=Ee(e);i(o,e)}return n}function Be(e){return e.filter((r)=>S(r.path))}function Se(e,r){return`[dir]/${e}${r}`}var G=require("coffi");async function Te(e){let{config:r,filepath:n}=await G.loadConfig({name:"package",cwd:e,extensions:[".json"],maxDepth:3});return{packageJson:r,path:n}}async function Re(e,r){let{config:n,filepath:t}=await G.loadConfig({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:r,maxDepth:3});return{tsconfig:n,path:t}}var rr={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Oe(e){return{...rr,...e}}function Le(e){let{minify:r,minifyWhitespace:n,minifyIdentifiers:t,minifySyntax:s}=e,i=r===!0;return{whitespace:n??i,identifiers:t??i,syntax:s??i}}function Me(e,r){return r==="cjs"?e:void 0}function Ae(e,r,n,t){return{...typeof n==="object"&&Object.keys(n).reduce((s,i)=>{let o=JSON.stringify(n[i]);return s[`process.env.${i}`]=o,s[`import.meta.env.${i}`]=o,s},{}),...e,...t==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function je(e,r){return e===void 0?r==="esm":e}function Ie(e){return typeof e==="string"?e:void 0}function Ne(e,r){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(t)=>{let s=t.path;if(e.some((o)=>o.test(s))&&!r.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var nr=/\.(js|ts|jsx|tsx|mts|cts)$/,K={dirnameFilename:{appliesTo:(e,r)=>e==="esm"&&D(r),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
16
- import { dirname } from 'path';
17
-
18
- const __filename = fileURLToPath(import.meta.url);
19
- const __dirname = dirname(__filename);
20
-
21
- `},importMetaUrl:{appliesTo:(e,r)=>e==="cjs"&&D(r),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
22
-
23
- const importMetaUrl = pathToFileURL(__filename).href;
24
-
25
- `}};function De({format:e,target:r,shims:n}){let s=tr(n).map((i)=>K[i]).filter((i)=>i.appliesTo(e,r));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:nr},async({path:o})=>{let u=await Bun.file(o).text(),a=s.filter((g)=>g.isNeededInFile(u));if(a.length===0)return;let{shebangLine:c,codeContent:m}=sr(u),f=a.map((g)=>g.generateCode()).join("");return{contents:c+f+m}})}}}function tr(e){if(e===!0)return Object.keys(K);if(!e)return[];return Object.entries(e).filter(([r,n])=>n&&(r in K)).map(([r])=>r)}function sr(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let r=e.indexOf(`
26
- `);return r===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,r+1),codeContent:e.slice(r+1)}}function _e(e){return e.filter((r)=>r.type==="bun").map((r)=>r.plugin)}var ae=new Set;async function We(e,r=process.cwd()){let n=Oe(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)se(r,n.outDir);v(n.silent);let{packageJson:t,path:s}=await Te(r);if(t&&s)p.cli(`Using package.json: ${w(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let i=F(n.entry),o=t?.type,u=T(n,t),a=R(n);if(!n.dtsOnly){let c=[Ne(u,a),..._e(n.plugins??[])],m=n.format.flatMap((f)=>i.map((g)=>{return or(n,r,g,f,o,c)}));await Promise.all(m)}if(n.dts||n.dtsOnly){let c=await Re(r,n.preferredTsconfigPath);if(c.path)p.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let m=n.format.filter((g)=>{if(g==="iife"&&!y(o)&&n.format.includes("cjs"))return!1;return!0}),f=typeof n.dts==="object"&&n.dts.entry?F(n.dts.entry):Be(i);try{await Promise.all(f.map(async(g)=>{let M=await $e(r,g.path,n,c,t);await Promise.all(m.map(async(Y)=>{let ke=n.outputExtension?.({format:Y,packageType:o,options:n,entry:g}).dts??ne(Y,o),A=`${r}/${n.outDir}/${g.name}${ke}`;await Bun.write(A,M);let Ue=Bun.file(A).size||0;p.progress("DTS",w(A),_(Ue),n.name)}))}))}catch(g){throw new l(d(g))}}if(n.onBuildSuccess)await n.onBuildSuccess(n)}async function or(e,r,n,t,s,i){let o=e.outputExtension?.({format:t,packageType:s,options:e,entry:n}).js??re(t,s),u=await Bun.build({entrypoints:[`${r}/${n.path}`],format:t,naming:{entry:Se(n.name,o)},splitting:je(e.splitting,t),bytecode:Me(e.bytecode,t),define:Ae(e.define,e.shims,e.env,t),minify:Le(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:Ie(e.env),plugins:[...i,De({format:t,target:e.target,shims:e.shims})],throw:!1});if(!u.success)for(let m of u.logs){if(m.level==="error")throw new h(m.message);if(m.level==="warning")p.warn(m.message);else if(m.level==="info")p.info(m.message)}let a=`${r}/${e.outDir}/${n.name}${o}`,c=Bun.file(a).size||0;p.progress(t.toUpperCase(),w(a),_(c),e.name)}
File without changes
File without changes