bunup 0.3.61 → 0.3.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{build as Yt}from"rolldown";import{dts as vt}from"rolldown-plugin-dts";class C extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends C{constructor(t){super(t);this.name="BunupBuildError"}}class d extends C{constructor(t){super(t);this.name="BunupDTSBuildError"}}class g extends C{constructor(t){super(t);this.name="BunupCLIError"}}class D extends C{constructor(t){super(t);this.name="BunupWatchError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)},Ut=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",solution:`By default, bunup targets the node environment. To use Bun-specific features, set the target to bun:
3
+ import{build as qt}from"rolldown";import{dts as Gt}from"rolldown-plugin-dts";class O extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends O{constructor(t){super(t);this.name="BunupBuildError"}}class d extends O{constructor(t){super(t);this.name="BunupDTSBuildError"}}class m extends O{constructor(t){super(t);this.name="BunupCLIError"}}class T extends O{constructor(t){super(t);this.name="BunupWatchError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)},Nt=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",solution:`By default, bunup targets the node environment. To use Bun-specific features, set the target to bun:
4
4
 
5
5
  1. In your config file:
6
6
  \`\`\`
@@ -12,30 +12,30 @@ import{build as Yt}from"rolldown";import{dts as vt}from"rolldown-plugin-dts";cla
12
12
  });
13
13
  \`\`\`
14
14
 
15
- 2. Or via CLI: \`bunup src/index.ts --target bun\``}],Y=(t,n)=>{let s=p(t),i=n?`[${n}] `:"",r="ERROR";if(t instanceof h)r="BUILD ERROR";else if(t instanceof d)r="DTS ERROR";else if(t instanceof g)r="CLI ERROR";else if(t instanceof D)r="WATCH ERROR";else if(t instanceof C)r="BUNUP ERROR";console.error(`\x1B[31m${r}\x1B[0m ${i}${s}`);let e=Ut.find((o)=>o.pattern.test(s)&&(o.errorType===r||!o.errorType));if(e)console.error(`
15
+ 2. Or via CLI: \`bunup src/index.ts --target bun\``}],V=(t,n)=>{let e=p(t),s=n?`[${n}] `:"",r="ERROR";if(t instanceof b)r="BUILD ERROR";else if(t instanceof d)r="DTS ERROR";else if(t instanceof m)r="CLI ERROR";else if(t instanceof T)r="WATCH ERROR";else if(t instanceof O)r="BUNUP ERROR";console.error(`\x1B[31m${r}\x1B[0m ${s}${e}`);let i=Nt.find((o)=>o.pattern.test(e)&&(o.errorType===r||!o.errorType));if(i)console.error(`
16
16
  \x1B[33mSolution:\x1B[0m
17
17
 
18
- \x1B[90m${e.solution}\x1B[0m
19
- `);else console.error("\x1B[33mThis error might be addressed in the troubleshooting section: \x1B[0m\x1B[36mhttps://bunup.arshadyaseen.com/#troubleshooting\x1B[0m"),console.error("\x1B[33mIf not, please open an issue at: \x1B[0m\x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},tt=(t,n)=>{Y(t,n),process.exit(1)};import st from"node:fs/promises";import Gt from"node:path";var M={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function nt(t,n){return{outdir:`${n}/${t.outDir}`,minify:Nt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function Nt(t){let{minify:n,minifyWhitespace:s,minifyIdentifiers:i,minifySyntax:r}=t,e=n===!0;return{whitespace:s??e,identifiers:i??e,syntax:r??e}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function it(t=8){return Math.random().toString(36).substring(2,2+t)}function et(t,n){switch(t){case"esm":return".mjs";case"cjs":return S(n)?".cjs":".js";case"iife":return".global.js"}}function rt(t,n){switch(t){case"esm":return".d.mts";case"cjs":return S(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function S(t){return t==="module"}function L(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ot(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function ct(t,n){return t===void 0?n==="esm":t}function J(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],s=Math.floor(Math.log(t)/Math.log(1024));if(s===0)return`${t} ${n[s]}`;return`${(t/Math.pow(1024,s)).toFixed(2)} ${n[s]}`}function x(t,n=3){return t.split("/").slice(-n).join("/")}async function q(t,n){let s=Gt.join(t,n);try{await st.rm(s,{recursive:!0,force:!0})}catch(i){throw new h(`Failed to clean output directory: ${i}`)}await st.mkdir(s,{recursive:!0})}function K(t){return t||M.outDir}function ut(t){return t===void 0?M.clean:t}function at(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function F(t,n){return at(t.external||[]).concat(ot(n).map((s)=>new RegExp(`^${v(s)}($|\\/|\\\\)`)))}function U(t){return at(t.noExternal||[])}import Xt from"node:path";import{ResolverFactory as Wt}from"oxc-resolver";import P from"node:path";var A="\x00dts:",ft=(t,n,s)=>{return{name:"bunup:virtual-dts",async resolveId(i,r){if(Q(i))return i;if(!r||!Q(r))return null;let e=await N(i,n,s,j(r));if(!e)return null;let o=R(e);if(t.has(o))return G(o);return null},load(i){if(i.startsWith(A)){let r=j(i),e=t.get(r);if(e)return E.add(r),e}return null}}};function R(t){return t.replace(/\.tsx?$/,".d.ts")}function Z(t){let n=P.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?P.resolve(n,t.data.compilerOptions.baseUrl):n}function lt(t){let n=new Map,s=t.data?.compilerOptions?.paths;if(!s)return n;let i=Z(t);for(let[r,e]of Object.entries(s))if(Array.isArray(e)&&e.length){let o=r.replace(/\*/g,"(.*)"),c=e[0].replace(/\*/g,"$1");n.set(`^${o}$`,P.join(i,c))}return n}function Bt(t,n,s){for(let[i,r]of n){let e=new RegExp(i),o=t.match(e);if(o)return r.replace("$1",o[1]||"")}return s?P.join(s,t):null}async function Vt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let s of n){let i=`${t}${s}`;if(await Bun.file(i).exists()&&(i.endsWith(".ts")||i.endsWith(".tsx")))return i}return null}function N(t,n,s,i){let r=t.startsWith(".")?P.resolve(P.dirname(i||""),t):Bt(t,n,s);if(!r)return Promise.resolve(null);return Vt(r)}function Q(t){return t.startsWith(A)}function j(t){return t.replace(A,"")}function G(t){return`${A}${t}`}var pt;function mt(t){return{name:"bunup:types-resolve",buildStart(){pt||=new Wt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,s){if(s=s?j(s):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let c=!1;if(typeof o==="string")c=o===n||!!(s&&s.includes(o));else c=o.test(n)||!!(s&&o.test(s));return c}))return}let i=s?Xt.dirname(s):process.cwd(),{path:r}=await pt.async(i,n);if(!r)return;if(/[cm]?jsx?$/.test(r)){let e=r.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(e).exists()?e:void 0}return r}}}async function dt(t,n,s,i,r,e){let o=R(t),c=G(o),u=F(s,i),f=U(s);try{let{output:m}=await Yt({input:c,output:{dir:s.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,b){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;b(l)},plugins:[ft(n,r,e),typeof s.dts==="object"&&"resolve"in s.dts&&mt(typeof s.dts.resolve==="boolean"?void 0:s.dts.resolve),vt()],external:(l)=>u.some((b)=>b.test(l))&&!f.some((b)=>b.test(l))});if(!m[0]?.code)throw new d("Generated bundle is empty");return m[0].code}catch(m){throw new d(`DTS bundling failed: ${p(m)}`)}}class O{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!O.instance)O.instance=new O;return O.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:s,size:i,identifier:r,muted:e}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),c=e?`\x1B[38;5;${this.colors.info}m${s}\x1B[0m`:s;if(i){let[f,...m]=c.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-f.length)),b=r?` \x1B[48;5;${t};38;5;0m ${r} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${f}${l} \x1B[38;5;${this.colors.size}m${i}\x1B[0m ${m.join(" ")}${b}`}let u=r?` \x1B[48;5;${t};38;5;0m ${r} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${c}${u}`}output(t,n={},s=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(s(t),n.verticalSpace)console.log("")}cli(t,n={}){let s=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(s,n)}info(t,n={}){let s=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(s,n)}warn(t,n={}){let s=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(s,n,console.warn)}error(t,n={}){let s=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(s,n,console.error)}progress(t,n,s,i){let r=String(t),e=this.colors.default,o,c,u={};if(typeof s==="string")o=s,c=i;else if(s)o=s.size,c=s.identifier,u=s;for(let[m,l]of Object.entries(this.colors.progress))if(r.includes(m)){e=l;break}let f=this.formatMessage({colorCode:e,label:r,message:n,size:o,identifier:c,muted:u.muted});this.output(f,u)}}var a=O.getInstance();var Jt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,qt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function gt(t,n,s){let i=new Set([t]),r=[t];while(r.length){let e=r.pop();if(!e)continue;try{let o=await Bun.file(e).text(),c=Kt(o);for(let u of c){let f=await N(u,n,s,e);if(!f)continue;if(!i.has(f))i.add(f),r.push(f)}}catch(o){a.warn(`Error processing ${e}: ${p(o)}`)}}return i}function Kt(t){let n=new Set;for(let s of[Jt,qt]){let i;while((i=s.exec(t))!==null)n.add(i[2])}return Array.from(n)}import{isolatedDeclaration as Qt}from"oxc-transform";async function bt(t){let n=new Map;return await Promise.all([...t].map(async(s)=>{try{let i=R(s);if(!await Bun.file(s).exists())return;let e=await Bun.file(s).text(),{code:o}=Qt(s,e);if(o)n.set(i,o)}catch(i){a.warn(`Failed to generate declaration for ${s}: ${p(i)}`)}})),n}import ht from"node:fs/promises";import z from"node:path";import{isolatedDeclaration as Zt}from"oxc-transform";async function xt(t,n){let s=z.resolve(t),i=z.resolve(s,n);if(!await ht.exists(s))throw new d(`Root directory does not exist: ${s}`);if(!await Bun.file(i).exists())throw new d(`Entry file does not exist: ${i}`);if(!i.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${i}`);if(z.relative(s,i).startsWith(".."))throw new d(`Entry file must be within rootDir: ${i}`);return{absoluteRootDir:s,absoluteEntry:i}}async function wt(t){let n=!1;if(await Promise.all([...t].map(async(s)=>{try{let i=s.replace(/\.d\.ts$/,".ts"),r=await Bun.file(i).text(),{errors:e}=Zt(i,r);e.forEach((o)=>{if(!n)console.log(`
20
- `);let c=o.labels[0],u=c?zt(r,c.start):"",m=`${x(i)}${u}: ${Ht(o.message)}`;a.warn(m),n=!0})}catch{}})),n)a.info(`
18
+ \x1B[90m${i.solution}\x1B[0m
19
+ `);else console.error("\x1B[33mThis error might be addressed in the troubleshooting section: \x1B[0m\x1B[36mhttps://bunup.arshadyaseen.com/#troubleshooting\x1B[0m"),console.error("\x1B[33mIf not, please open an issue at: \x1B[0m\x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},tt=(t,n)=>{V(t,n),process.exit(1)};import et from"node:fs/promises";import Ft from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function nt(t,n){return{outdir:`${n}/${t.outDir}`,minify:Ut(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function Ut(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:r}=t,i=n===!0;return{whitespace:e??i,identifiers:s??i,syntax:r??i}}function q(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function st(t=8){return Math.random().toString(36).substring(2,2+t)}function it(t,n){switch(t){case"esm":return".mjs";case"cjs":return L(n)?".cjs":".js";case"iife":return".global.js"}}function rt(t,n){switch(t){case"esm":return".d.mts";case"cjs":return L(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(t){return t==="module"}function j(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ot(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function at(t,n){return t===void 0?n==="esm":t}function G(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function x(t,n=3){return t.split("/").slice(-n).join("/")}async function X(t,n){let e=Ft.join(t,n);try{await et.rm(e,{recursive:!0,force:!0})}catch(s){throw new b(`Failed to clean output directory: ${s}`)}await et.mkdir(e,{recursive:!0})}function Y(t){return t||v.outDir}function ct(t){return t===void 0?v.clean:t}function lt(t,n){return n==="cjs"?t:void 0}function ft(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${q(n)}($|\\/|\\\\)`):n)}function _(t,n){return ft(t.external||[]).concat(ot(n).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function D(t){return ft(t.noExternal||[])}import kt from"node:path";import{ResolverFactory as Vt}from"oxc-resolver";import P from"node:path";var I="\x00dts:",ut=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,r){if(J(s))return s;if(!r||!J(r))return null;let i=await N(s,n,e,A(r));if(!i)return null;let o=C(i);if(t.has(o))return U(o);return null},load(s){if(s.startsWith(I)){let r=A(s),i=t.get(r);if(i)return E.add(r),i}return null}}};function C(t){return t.replace(/\.tsx?$/,".d.ts")}function K(t){let n=P.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?P.resolve(n,t.data.compilerOptions.baseUrl):n}function pt(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=K(t);for(let[r,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=r.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");n.set(`^${o}$`,P.join(s,a))}return n}function Ht(t,n,e){for(let[s,r]of n){let i=new RegExp(s),o=t.match(i);if(o)return r.replace("$1",o[1]||"")}return e?P.join(e,t):null}async function Wt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function N(t,n,e,s){let r=t.startsWith(".")?P.resolve(P.dirname(s||""),t):Ht(t,n,e);if(!r)return Promise.resolve(null);return Wt(r)}function J(t){return t.startsWith(I)}function A(t){return t.replace(I,"")}function U(t){return`${I}${t}`}var gt;function dt(t){return{name:"bunup:types-resolve",buildStart(){gt||=new Vt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?A(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?kt.dirname(e):process.cwd(),{path:r}=await gt.async(s,n);if(!r)return;if(/[cm]?jsx?$/.test(r)){let i=r.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return r}}}async function mt(t,n,e,s,r,i){let o=C(t),a=U(o),c=_(e,s),f=D(e);try{let{output:g}=await qt({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;h(u)},plugins:[ut(n,r,i),typeof e.dts==="object"&&"resolve"in e.dts&&dt(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Gt()],external:(u)=>c.some((h)=>h.test(u))&&!f.some((h)=>h.test(u))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!R.instance)R.instance=new R;return R.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:e,size:s,identifier:r,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[f,...g]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-f.length)),h=r?` \x1B[48;5;${t};38;5;0m ${r} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${f}${u} \x1B[38;5;${this.colors.size}m${s}\x1B[0m ${g.join(" ")}${h}`}let c=r?` \x1B[48;5;${t};38;5;0m ${r} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${c}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let r=String(t),i=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,u]of Object.entries(this.colors.progress))if(r.includes(g)){i=u;break}let f=this.formatMessage({colorCode:i,label:r,message:n,size:o,identifier:a,muted:c.muted});this.output(f,c)}}var l=R.getInstance();var Xt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ht(t,n,e){let s=new Set([t]),r=[t];while(r.length){let i=r.pop();if(!i)continue;try{let o=await Bun.file(i).text(),a=Jt(o);for(let c of a){let f=await N(c,n,e,i);if(!f)continue;if(!s.has(f))s.add(f),r.push(f)}}catch(o){l.warn(`Error processing ${i}: ${p(o)}`)}}return s}function Jt(t){let n=new Set;for(let e of[Xt,Yt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}import{isolatedDeclaration as Kt}from"oxc-transform";async function bt(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=C(e);if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Kt(e,i);if(o)n.set(s,o)}catch(s){l.warn(`Failed to generate declaration for ${e}: ${p(s)}`)}})),n}import xt from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as Qt}from"oxc-transform";async function wt(t,n){let e=Q.resolve(t),s=Q.resolve(e,n);if(!await xt.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new d(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${s}`);if(Q.relative(e,s).startsWith(".."))throw new d(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function yt(t){let n=!1;if(await Promise.all([...t].map(async(e)=>{try{let s=e.replace(/\.d\.ts$/,".ts"),r=await Bun.file(s).text(),{errors:i}=Qt(s,r);i.forEach((o)=>{if(!n)console.log(`
20
+ `);let a=o.labels[0],c=a?Zt(r,a.start):"",g=`${x(s)}${c}: ${zt(o.message)}`;l.warn(g),n=!0})}catch{}})),n)l.info(`
21
21
  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. Other bundlers might not show these warnings because they use different, potentially less precise methods. 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.
22
- `)}function zt(t,n){if(n===void 0)return"";let s=t.slice(0,n).split(`
23
- `),i=s.length,r=s[s.length-1].length+1;return` (${i}:${r})`}function Ht(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $t(t,n,s,i,r){let{absoluteEntry:e}=await xt(t,n),o=lt(i),c=Z(i),u=await gt(e,o,c),f=await bt(u);return dt(e,f,s,r,o,c)}function _(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function I(t){let n=[],s=new Set,i={};function r(e,o){if(s.has(e)){let c=it(),u=`${e}_${c}`;a.warn(`Output name conflict: "${e}" is used by multiple files.
22
+ `)}function Zt(t,n){if(n===void 0)return"";let e=t.slice(0,n).split(`
23
+ `),s=e.length,r=e[e.length-1].length+1;return` (${s}:${r})`}function zt(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $t(t,n,e,s,r){let{absoluteEntry:i}=await wt(t,n),o=pt(s),a=K(s),c=await ht(i,o,a),f=await bt(c);return mt(i,f,e,r,o,a)}function M(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function B(t){let n=[],e=new Set,s={};function r(i,o){if(e.has(i)){let a=st(),c=`${i}_${a}`;l.warn(`Output name conflict: "${i}" is used by multiple files.
24
24
  Bunup uses filenames without extensions as output names by default.
25
25
 
26
- ${i[e]} -> ${e}.js
27
- ${o} -> ${u}.js (auto-renamed to avoid conflict)
26
+ ${s[i]} -> ${i}.js
27
+ ${o} -> ${c}.js (auto-renamed to avoid conflict)
28
28
 
29
29
  To fix this, use named entries in your configuration:
30
30
  {
31
31
  entry: {
32
- custom_name: "${i[e]}",
32
+ custom_name: "${s[i]}",
33
33
  another_name: "${o}"
34
34
  }
35
35
  }
36
36
 
37
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:e,path:o}),s.add(e),i[e]=o}if(Array.isArray(t))for(let e of t){let o=_(e);r(o,e)}else if(typeof t==="object")Object.entries(t).forEach(([e,o])=>{r(e,o)});else{let e=_(t);r(e,t)}return n}function yt(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as kt}from"load-tsconfig";function Ct(t){try{return kt(".",t)}catch(n){return a.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import H from"node:path";async function Mt(t){let n=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let s of n){let i=H.join(t,`bunup.config${s}`);try{if(!await Bun.file(i).exists())continue;let e=await tn(i,s);if(!e)continue;return{configs:en(e,t),configFilePath:i}}catch(r){throw new h(`Failed to load config from ${i}: ${p(r)}`)}}return{configs:[],configFilePath:""}}async function tn(t,n){if(n===".json"||n===".jsonc")return nn(t);return sn(t)}async function nn(t){try{let n=await Bun.file(t).text(),s=JSON.parse(n);return s.bunup||s}catch(n){throw new Error(`Invalid JSON in config file. ${p(n)}`)}}async function sn(t){try{let n=await import(`file://${t}`),s=n.default||n;if(!s)return a.warn(`No export found in ${t}. Make sure you're exporting your configuration.`),{};return s}catch(n){throw new Error(`Failed to import config file. ${p(n)}`)}}function en(t,n){let s=[];if(rn(t))on(t,n,s);else if(Array.isArray(t))cn(t,n,s);else if(t&&typeof t==="object")s.push({options:t,rootDir:n});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return s}function rn(t){return Array.isArray(t)&&t.length>0&&t.every((n)=>typeof n==="object"&&n!==null&&("name"in n)&&("root"in n)&&("config"in n))}function on(t,n,s){for(let i of t){let r=H.resolve(n,i.root);if(Array.isArray(i.config))for(let e of i.config)s.push({options:{name:i.name,...e},rootDir:r});else s.push({options:{name:i.name,...i.config},rootDir:r})}}function cn(t,n,s){for(let i of t){if(!i||typeof i!=="object")throw new Error("Invalid configuration item. Expected an object.");s.push({options:i,rootDir:n})}}async function Rt(t){let n=H.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let i=await Bun.file(n).text();return{packageJson:JSON.parse(i),path:n}}catch(s){return a.warn(`Failed to load package.json at ${n}: ${p(s)}`),{packageJson:null,path:n}}}function Et(t,n){return{name:"bunup:external-plugin",setup(s){s.onResolve({filter:/.*/},(i)=>{let r=i.path;if(t.some((o)=>o.test(r))&&!n.some((o)=>o.test(r)))return{path:r,external:!0};return null})}}}var E=new Set;async function B(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:s,path:i}=await Rt(n);if(s)a.cli(`Using package.json: ${x(i,2)}`,{muted:!0,once:i,identifier:t.name});let r=s?.type,e=F(t,s),o=U(t),c=[Et(e,o)],u=I(t.entry),f=nt(t,n),m=t.format.flatMap((l)=>u.map((b)=>{return un(t,n,b,l,r,c,f)}));if(await Promise.all(m),t.dts){let l=Ct(t.preferredTsconfigPath);if(l.path)a.cli(`Using tsconfig: ${x(l.path,2)}`,{muted:!0,once:l.path,identifier:t.name});let b=t.format.filter((y)=>{if(y==="iife"&&!S(r)&&t.format.includes("cjs"))return!1;return!0}),Tt=typeof t.dts==="object"&&t.dts.entry?I(t.dts.entry):u;try{await Promise.all(Tt.map(async(y)=>{let Dt=await $t(n,y.path,t,l,s);await Promise.all(b.map(async(St)=>{let Lt=rt(St,r),W=`${n}/${t.outDir}/${y.name}${Lt}`;await Bun.write(W,Dt);let Ft=Bun.file(W).size||0;a.progress("DTS",x(W),J(Ft),t.name)}))}))}catch(y){throw new d(p(y))}}}async function un(t,n,s,i,r,e,o){let c=et(i,r),u=await Bun.build({...o,entrypoints:[`${n}/${s.path}`],format:i,naming:{entry:yt(s.name,c)},splitting:ct(t.splitting,i),plugins:e,throw:!1});if(!u.success)u.logs.forEach((l)=>{if(l.level==="error")throw new h(l.message);else if(l.level==="warning")a.warn(l.message);else if(l.level==="info")a.info(l.message)});let f=`${n}/${t.outDir}/${s.name}${c}`,m=Bun.file(f).size||0;a.progress(i.toUpperCase(),x(f),J(m),t.name)}var V="0.3.61";var Pt="https://bun.sh/docs/installation",Ot="https://bunup.arshadyaseen.com/#cli-options";function w(t){return(n,s)=>{s[t]=n===!0?!0:n==="true"}}function $(t){return(n,s)=>{if(typeof n==="string")s[t]=n;else throw new g(`Option --${t} requires a string value`)}}function jt(t){return(n,s)=>{if(typeof n==="string")s[t]=n.split(",");else throw new g(`Option --${t} requires a string value`)}}function fn(){console.log(`
37
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:c,path:o})}else n.push({name:i,path:o}),e.add(i),s[i]=o}if(Array.isArray(t))for(let i of t){let o=M(i);r(o,i)}else if(typeof t==="object")Object.entries(t).forEach(([i,o])=>{r(i,o)});else{let i=M(t);r(i,t)}return n}function Ot(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as tn}from"load-tsconfig";function vt(t){try{return tn(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import Z from"node:path";async function Ct(t){let n=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of n){let s=Z.join(t,`bunup.config${e}`);try{if(!await Bun.file(s).exists())continue;let i=await nn(s,e);if(!i)continue;return{configs:rn(i,t),configFilePath:s}}catch(r){throw new b(`Failed to load config from ${s}: ${p(r)}`)}}return{configs:[],configFilePath:""}}async function nn(t,n){if(n===".json"||n===".jsonc")return en(t);return sn(t)}async function en(t){try{let n=await Bun.file(t).text(),e=JSON.parse(n);return e.bunup||e}catch(n){throw new Error(`Invalid JSON in config file. ${p(n)}`)}}async function sn(t){try{let n=await import(`file://${t}`),e=n.default||n;if(!e)return l.warn(`No export found in ${t}. Make sure you're exporting your configuration.`),{};return e}catch(n){throw new Error(`Failed to import config file. ${p(n)}`)}}function rn(t,n){let e=[];if(on(t))an(t,n,e);else if(Array.isArray(t))cn(t,n,e);else if(t&&typeof t==="object")e.push({options:t,rootDir:n});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function on(t){return Array.isArray(t)&&t.length>0&&t.every((n)=>typeof n==="object"&&n!==null&&("name"in n)&&("root"in n)&&("config"in n))}function an(t,n,e){for(let s of t){let r=Z.resolve(n,s.root);if(Array.isArray(s.config))for(let i of s.config)e.push({options:{name:s.name,...i},rootDir:r});else e.push({options:{name:s.name,...s.config},rootDir:r})}}function cn(t,n,e){for(let s of t){if(!s||typeof s!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:s,rootDir:n})}}async function Et(t){let n=Z.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return l.warn(`Failed to load package.json at ${n}: ${p(e)}`),{packageJson:null,path:n}}}function Pt(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let r=s.path;if(t.some((o)=>o.test(r))&&!n.some((o)=>o.test(r)))return{path:r,external:!0};return null})}}}var E=new Set;async function F(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await Et(n);if(e)l.cli(`Using package.json: ${x(s,2)}`,{muted:!0,once:s,identifier:t.name});let r=e?.type,i=_(t,e),o=D(t),a=[Pt(i,o)],c=B(t.entry),f=nt(t,n),g=t.format.flatMap((u)=>c.map((h)=>{return ln(t,n,h,u,r,a,f)}));if(await Promise.all(g),t.dts){let u=vt(t.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${x(u.path,2)}`,{muted:!0,once:u.path,identifier:t.name});let h=t.format.filter(($)=>{if($==="iife"&&!L(r)&&t.format.includes("cjs"))return!1;return!0}),Tt=typeof t.dts==="object"&&t.dts.entry?B(t.dts.entry):c;try{await Promise.all(Tt.map(async($)=>{let Lt=await $t(n,$.path,t,u,e);await Promise.all(h.map(async(jt)=>{let _t=rt(jt,r),k=`${n}/${t.outDir}/${$.name}${_t}`;await Bun.write(k,Lt);let Dt=Bun.file(k).size||0;l.progress("DTS",x(k),G(Dt),t.name)}))}))}catch($){throw new d(p($))}}}async function ln(t,n,e,s,r,i,o){let a=it(s,r),c=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:Ot(e.name,a)},splitting:at(t.splitting,s),bytecode:lt(t.bytecode,s),plugins:i,throw:!1});if(!c.success)c.logs.forEach((u)=>{if(u.level==="error")throw new b(u.message);else if(u.level==="warning")l.warn(u.message);else if(u.level==="info")l.info(u.message)});let f=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(f).size||0;l.progress(s.toUpperCase(),x(f),G(g),t.name)}var H="0.3.64";var Rt="https://bun.sh/docs/installation",At="https://bunup.arshadyaseen.com/#cli-options";function w(t){return(n,e)=>{e[t]=n===!0?!0:n==="true"}}function y(t){return(n,e)=>{if(typeof n==="string")e[t]=n;else throw new m(`Option --${t} requires a string value`)}}function It(t){return(n,e)=>{if(typeof n==="string")e[t]=n.split(",");else throw new m(`Option --${t} requires a string value`)}}function un(){console.log(`
38
38
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
39
- `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Ot}\x1B[0m
40
- `),process.exit(0)}function ln(){console.log(V),process.exit(0)}var pn={name:{flags:["n","name"],handler:$("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new g("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:$("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["b","banner"],handler:$("banner")},footer:{flags:["f","footer"],handler:$("footer")},external:{flags:["e","external"],handler:jt("external")},sourcemap:{flags:["sm","sourcemap"],handler:$("sourcemap")},target:{flags:["t","target"],handler:$("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:jt("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:$("preferredTsconfigPath")}},mn={resolveDts:{flags:["rd","resolve-dts"],handler:(t,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof t==="string")if(t==="true"||t==="false")n.dts.resolve=t==="true";else n.dts.resolve=t.split(",");else n.dts.resolve=!0}}},dn={help:{flags:["h","help"],handler:()=>fn()},version:{flags:["v","version"],handler:()=>ln()}},T={};for(let t of Object.values(pn))if(t)for(let n of t.flags)T[n]=t.handler;for(let t of Object.values(mn))for(let n of t.flags)T[n]=t.handler;for(let t of Object.values(dn))for(let n of t.flags)T[n]=t.handler;function At(t){let n={},s={},i=0;while(i<t.length){let r=t[i];if(r.startsWith("--")){let e,o;if(r.includes("=")){let[c,u]=r.slice(2).split("=",2);e=c,o=u}else{e=r.slice(2);let c=t[i+1];if(o=c&&!c.startsWith("-")?c:!0,typeof o==="string")i++}if(e==="entry")if(typeof o==="string"){let c=_(o);if(s[c])a.warn(`Duplicate entry name '${c}' derived from '${o}'. Overwriting previous entry.`);s[c]=o}else throw new g("Option --entry requires a string value");else if(e.startsWith("entry.")){let c=e.slice(6);if(typeof o==="string"){if(s[c])a.warn(`Duplicate entry name '${c}' provided via --entry.${c}. Overwriting previous entry.`);s[c]=o}else throw new g(`Option --entry.${c} requires a string value`)}else{let c=T[e];if(c)c(o,n);else throw new g(`Unknown option: --${e}`)}}else if(r.startsWith("-")){let e=r.slice(1),o=t[i+1],c=o&&!o.startsWith("-")?o:!0;if(typeof c==="string")i++;let u=T[e];if(u)u(c,n);else throw new g(`Unknown option: -${e}`)}else{let e=_(r);if(s[e])a.warn(`Duplicate entry name '${e}' derived from positional argument '${r}'. Overwriting previous entry.`);s[e]=r}i++}if(Object.keys(s).length>0)n.entry=s;return n}(()=>{if(typeof Bun==="undefined")throw new g(`Bunup requires Bun to run.
41
- To install Bun, visit `+Pt)})();import X from"node:path";import gn from"chokidar";async function _t(t,n){let s=new Set,i=I(t.entry);i.forEach((c)=>{let u=X.resolve(n,c.path),f=X.dirname(u);s.add(f)});let r=gn.watch(Array.from(s),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,X.join(n,t.outDir)]}),e=!1,o=async(c=!1)=>{if(e)return;e=!0;try{let u=performance.now();if(await B({...t,entry:i.map((f)=>f.path),clean:!1},n),t.onBuildSuccess?.(),!c)a.cli(`\uD83D\uDCE6 Rebuild finished in ${L(performance.now()-u)}`);await k()}catch(u){Y(u)}finally{e=!1}};r.on("change",(c)=>{let u=X.relative(n,c);a.cli(`File changed: ${u}`,{muted:!0}),o()}),r.on("error",(c)=>{throw new D(`Watcher error: ${p(c)}`)}),await o(!0)}async function bn(t=Bun.argv.slice(2)){let n=At(t),{configs:s,configFilePath:i}=await Mt(process.cwd());if(a.cli(`Using bunup v${V} and bun v${Bun.version}`,{muted:!0}),i)a.cli(`Using config file: ${x(i,2)}`,{muted:!0});let r=performance.now();if(a.cli("Build started"),s.length===0){let c={...M,...n},u=process.cwd();if(c.clean)q(u,K(c.outDir));await It(c,u)}else{for(let{options:c,rootDir:u}of s)if(ut(c.clean))q(u,K(c.outDir));await Promise.all(s.map(async({options:c,rootDir:u})=>{let f={...M,...c,...n};await It(f,u)}))}let e=performance.now()-r,o=L(e);if(a.cli(`\u26A1\uFE0F Build completed in ${o}`),await k(),n.watch)a.cli("\uD83D\uDC40 Watching for file changes");if(!n.watch)process.exit(0);a.dispose()}async function k(){if(E.size>0)await wt(E),E.clear()}async function It(t,n){if(t.watch)await _t(t,n);else await B(t,n),t.onBuildSuccess?.()}bn().catch((t)=>tt(t));export{k as validateDtsFiles,bn as main};
39
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${At}\x1B[0m
40
+ `),process.exit(0)}function pn(){console.log(H),process.exit(0)}var gn={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new m("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["b","banner"],handler:y("banner")},footer:{flags:["f","footer"],handler:y("footer")},external:{flags:["e","external"],handler:It("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:It("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")}},dn={resolveDts:{flags:["rd","resolve-dts"],handler:(t,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof t==="string")if(t==="true"||t==="false")n.dts.resolve=t==="true";else n.dts.resolve=t.split(",");else n.dts.resolve=!0}}},mn={help:{flags:["h","help"],handler:()=>un()},version:{flags:["v","version"],handler:()=>pn()}},S={};for(let t of Object.values(gn))if(t)for(let n of t.flags)S[n]=t.handler;for(let t of Object.values(dn))for(let n of t.flags)S[n]=t.handler;for(let t of Object.values(mn))for(let n of t.flags)S[n]=t.handler;function Mt(t){let n={},e={},s=0;while(s<t.length){let r=t[s];if(r.startsWith("--")){let i,o;if(r.includes("=")){let[a,c]=r.slice(2).split("=",2);i=a,o=c}else{i=r.slice(2);let a=t[s+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")s++}if(i==="entry")if(typeof o==="string"){let a=M(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new m("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new m(`Option --entry.${a} requires a string value`)}else{let a=S[i];if(a)a(o,n);else throw new m(`Unknown option: --${i}`)}}else if(r.startsWith("-")){let i=r.slice(1),o=t[s+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")s++;let c=S[i];if(c)c(a,n);else throw new m(`Unknown option: -${i}`)}else{let i=M(r);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${r}'. Overwriting previous entry.`);e[i]=r}s++}if(Object.keys(e).length>0)n.entry=e;return n}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
41
+ To install Bun, visit `+Rt)})();import W from"node:path";import hn from"chokidar";async function Bt(t,n){let e=new Set,s=B(t.entry);s.forEach((a)=>{let c=W.resolve(n,a.path),f=W.dirname(c);e.add(f)});let r=hn.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(n,t.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await F({...t,entry:s.map((f)=>f.path),clean:!1},n),t.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${j(performance.now()-c)}`);await z()}catch(c){V(c)}finally{i=!1}};r.on("change",(a)=>{let c=W.relative(n,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),r.on("error",(a)=>{throw new T(`Watcher error: ${p(a)}`)}),await o(!0)}async function bn(t=Bun.argv.slice(2)){let n=Mt(t),{configs:e,configFilePath:s}=await Ct(process.cwd());if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),s)l.cli(`Using config file: ${x(s,2)}`,{muted:!0});let r=performance.now();if(l.cli("Build started"),e.length===0){let a={...v,...n},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await St(a,c)}else{for(let{options:a,rootDir:c}of e)if(ct(a.clean))X(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let f={...v,...a,...n};await St(f,c)}))}let i=performance.now()-r,o=j(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),n.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!n.watch)process.exit(0);l.dispose()}async function z(){if(E.size>0)await yt(E),E.clear()}async function St(t,n){if(t.watch)await Bt(t,n);else await F(t,n),t.onBuildSuccess?.()}bn().catch((t)=>tt(t));export{z as validateDtsFiles,bn as main};
package/build/index.d.mts CHANGED
@@ -434,6 +434,18 @@ interface BunupOptions {
434
434
  * }
435
435
  */
436
436
  loader?: Record<string, Loader>;
437
+ /**
438
+ * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
439
+ *
440
+ * Bytecode is currently only supported for CommonJS (format: "cjs").
441
+ *
442
+ * Must be target: "bun"
443
+ *
444
+ * @see https://bun.sh/docs/bundler#bytecode
445
+ *
446
+ * @default false
447
+ */
448
+ bytecode?: boolean;
437
449
  }
438
450
 
439
451
  //#endregion
@@ -444,7 +456,7 @@ type WithOptional<
444
456
  K extends keyof T
445
457
  > = Omit<T, K> & Partial<Pick<T, K>>;
446
458
  type Arrayable<T> = T | T[];
447
- type Bun = typeof import("bun");
459
+ type Bun = typeof Bun;
448
460
  type BunBuildOptions = Parameters<Bun["build"]>[0];
449
461
  type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
450
462
  type DefineWorkspaceEntry = {
package/build/index.d.ts CHANGED
@@ -434,6 +434,18 @@ interface BunupOptions {
434
434
  * }
435
435
  */
436
436
  loader?: Record<string, Loader>;
437
+ /**
438
+ * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
439
+ *
440
+ * Bytecode is currently only supported for CommonJS (format: "cjs").
441
+ *
442
+ * Must be target: "bun"
443
+ *
444
+ * @see https://bun.sh/docs/bundler#bytecode
445
+ *
446
+ * @default false
447
+ */
448
+ bytecode?: boolean;
437
449
  }
438
450
 
439
451
  //#endregion
@@ -444,7 +456,7 @@ type WithOptional<
444
456
  K extends keyof T
445
457
  > = Omit<T, K> & Partial<Pick<T, K>>;
446
458
  type Arrayable<T> = T | T[];
447
- type Bun = typeof import("bun");
459
+ type Bun = typeof Bun;
448
460
  type BunBuildOptions = Parameters<Bun["build"]>[0];
449
461
  type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
450
462
  type DefineWorkspaceEntry = {
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var Ot=require("node:module");var Mt=Object.create;var{getPrototypeOf:Dt,defineProperty:C,getOwnPropertyNames:G,getOwnPropertyDescriptor:At}=Object,V=Object.prototype.hasOwnProperty;var x=(t,n,e)=>{e=t!=null?Mt(Dt(t)):{};let s=n||!t||!t.__esModule?C(e,"default",{value:t,enumerable:!0}):e;for(let i of G(t))if(!V.call(s,i))C(s,i,{get:()=>t[i],enumerable:!0});return s},U=new WeakMap,jt=(t)=>{var n=U.get(t),e;if(n)return n;if(n=C({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")G(t).map((s)=>!V.call(n,s)&&C(n,s,{get:()=>t[s],enumerable:!(e=At(t,s))||e.enumerable}));return U.set(t,n),n};var vt=(t,n)=>{for(var e in n)C(t,e,{get:n[e],enumerable:!0,configurable:!0,set:(s)=>n[e]=()=>s})};var Vt={};vt(Vt,{defineWorkspace:()=>B,defineConfig:()=>X,build:()=>$t});module.exports=jt(Vt);function X(t){return t}function B(t){return t}var it=require("rolldown"),ot=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends S{constructor(t){super(t);this.name="BunupBuildError"}}class p extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};var St=x(require("node:fs/promises")),Lt=x(require("node:path"));function H(t,n){return{outdir:`${n}/${t.outDir}`,minify:It(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function It(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:i}=t,r=n===!0;return{whitespace:e??r,identifiers:s??r,syntax:i??r}}function L(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(t=8){return Math.random().toString(36).substring(2,2+t)}function J(t,n){switch(t){case"esm":return".mjs";case"cjs":return M(n)?".cjs":".js";case"iife":return".global.js"}}function q(t,n){switch(t){case"esm":return".d.mts";case"cjs":return M(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(t){return t==="module"}function K(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Q(t,n){return t===void 0?n==="esm":t}function _(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function $(t,n=3){return t.split("/").slice(-n).join("/")}function Z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${L(n)}($|\\/|\\\\)`):n)}function D(t,n){return Z(t.external||[]).concat(K(n).map((e)=>new RegExp(`^${L(e)}($|\\/|\\\\)`)))}function A(t){return Z(t.noExternal||[])}var et=x(require("node:path")),st=require("oxc-resolver");var h=x(require("node:path"));var P="\x00dts:",z=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,i){if(N(s))return s;if(!i||!N(i))return null;let r=await j(s,n,e,R(i));if(!r)return null;let o=y(r);if(t.has(o))return v(o);return null},load(s){if(s.startsWith(P)){let i=R(s),r=t.get(i);if(r)return k.add(i),r}return null}}};function y(t){return t.replace(/\.tsx?$/,".d.ts")}function T(t){let n=h.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?h.default.resolve(n,t.data.compilerOptions.baseUrl):n}function tt(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=T(t);for(let[i,r]of Object.entries(e))if(Array.isArray(r)&&r.length){let o=i.replace(/\*/g,"(.*)"),a=r[0].replace(/\*/g,"$1");n.set(`^${o}$`,h.default.join(s,a))}return n}function _t(t,n,e){for(let[s,i]of n){let r=new RegExp(s),o=t.match(r);if(o)return i.replace("$1",o[1]||"")}return e?h.default.join(e,t):null}async function Nt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function j(t,n,e,s){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(s||""),t):_t(t,n,e);if(!i)return Promise.resolve(null);return Nt(i)}function N(t){return t.startsWith(P)}function R(t){return t.replace(P,"")}function v(t){return`${P}${t}`}var nt;function rt(t){return{name:"bunup:types-resolve",buildStart(){nt||=new st.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?R(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?et.default.dirname(e):process.cwd(),{path:i}=await nt.async(s,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let r=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(r).exists()?r:void 0}return i}}}async function at(t,n,e,s,i,r){let o=y(t),a=v(o),f=D(e,s),l=A(e);try{let{output:g}=await it.build({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[z(n,i,r),typeof e.dts==="object"&&"resolve"in e.dts&&rt(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),ot.dts()],external:(c)=>f.some((d)=>d.test(c))&&!l.some((d)=>d.test(c))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${m(g)}`)}}class E{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!E.instance)E.instance=new E;return E.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:e,size:s,identifier:i,muted:r}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=r?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),d=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${s}\x1B[0m ${g.join(" ")}${d}`}let f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${f}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let i=String(t),r=this.colors.default,o,a,f={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,f=e;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){r=c;break}let l=this.formatMessage({colorCode:r,label:i,message:n,size:o,identifier:a,muted:f.muted});this.output(l,f)}}var u=E.getInstance();var Tt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Ft=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ct(t,n,e){let s=new Set([t]),i=[t];while(i.length){let r=i.pop();if(!r)continue;try{let o=await Bun.file(r).text(),a=Wt(o);for(let f of a){let l=await j(f,n,e,r);if(!l)continue;if(!s.has(l))s.add(l),i.push(l)}}catch(o){u.warn(`Error processing ${r}: ${m(o)}`)}}return s}function Wt(t){let n=new Set;for(let e of[Tt,Ft]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}var ft=require("oxc-transform");async function lt(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=y(e);if(!await Bun.file(e).exists())return;let r=await Bun.file(e).text(),{code:o}=ft.isolatedDeclaration(e,r);if(o)n.set(s,o)}catch(s){u.warn(`Failed to generate declaration for ${e}: ${m(s)}`)}})),n}var F=x(require("node:fs/promises")),O=x(require("node:path")),Ut=require("oxc-transform");async function ut(t,n){let e=O.default.resolve(t),s=O.default.resolve(e,n);if(!await F.default.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new p(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${s}`);if(O.default.relative(e,s).startsWith(".."))throw new p(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function gt(t,n,e,s,i){let{absoluteEntry:r}=await ut(t,n),o=tt(s),a=T(s),f=await ct(r,o,a),l=await lt(f);return at(r,l,e,i,o,a)}function mt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],e=new Set,s={};function i(r,o){if(e.has(r)){let a=Y(),f=`${r}_${a}`;u.warn(`Output name conflict: "${r}" is used by multiple files.
1
+ var It=require("node:module");var At=Object.create;var{getPrototypeOf:Dt,defineProperty:C,getOwnPropertyNames:V,getOwnPropertyDescriptor:Ot}=Object,G=Object.prototype.hasOwnProperty;var x=(t,n,e)=>{e=t!=null?At(Dt(t)):{};let s=n||!t||!t.__esModule?C(e,"default",{value:t,enumerable:!0}):e;for(let i of V(t))if(!G.call(s,i))C(s,i,{get:()=>t[i],enumerable:!0});return s},U=new WeakMap,jt=(t)=>{var n=U.get(t),e;if(n)return n;if(n=C({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")V(t).map((s)=>!G.call(n,s)&&C(n,s,{get:()=>t[s],enumerable:!(e=Ot(t,s))||e.enumerable}));return U.set(t,n),n};var vt=(t,n)=>{for(var e in n)C(t,e,{get:n[e],enumerable:!0,configurable:!0,set:(s)=>n[e]=()=>s})};var Xt={};vt(Xt,{defineWorkspace:()=>B,defineConfig:()=>X,build:()=>Et});module.exports=jt(Xt);function X(t){return t}function B(t){return t}var ot=require("rolldown"),at=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends S{constructor(t){super(t);this.name="BunupBuildError"}}class p extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};var Lt=x(require("node:fs/promises")),_t=x(require("node:path"));function H(t,n){return{outdir:`${n}/${t.outDir}`,minify:St(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function St(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:i}=t,r=n===!0;return{whitespace:e??r,identifiers:s??r,syntax:i??r}}function L(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(t=8){return Math.random().toString(36).substring(2,2+t)}function q(t,n){switch(t){case"esm":return".mjs";case"cjs":return M(n)?".cjs":".js";case"iife":return".global.js"}}function J(t,n){switch(t){case"esm":return".d.mts";case"cjs":return M(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(t){return t==="module"}function K(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Q(t,n){return t===void 0?n==="esm":t}function _(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function $(t,n=3){return t.split("/").slice(-n).join("/")}function Z(t,n){return n==="cjs"?t:void 0}function z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${L(n)}($|\\/|\\\\)`):n)}function A(t,n){return z(t.external||[]).concat(K(n).map((e)=>new RegExp(`^${L(e)}($|\\/|\\\\)`)))}function D(t){return z(t.noExternal||[])}var st=x(require("node:path")),rt=require("oxc-resolver");var h=x(require("node:path"));var P="\x00dts:",k=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,i){if(N(s))return s;if(!i||!N(i))return null;let r=await O(s,n,e,R(i));if(!r)return null;let o=E(r);if(t.has(o))return j(o);return null},load(s){if(s.startsWith(P)){let i=R(s),r=t.get(i);if(r)return tt.add(i),r}return null}}};function E(t){return t.replace(/\.tsx?$/,".d.ts")}function T(t){let n=h.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?h.default.resolve(n,t.data.compilerOptions.baseUrl):n}function nt(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=T(t);for(let[i,r]of Object.entries(e))if(Array.isArray(r)&&r.length){let o=i.replace(/\*/g,"(.*)"),a=r[0].replace(/\*/g,"$1");n.set(`^${o}$`,h.default.join(s,a))}return n}function Nt(t,n,e){for(let[s,i]of n){let r=new RegExp(s),o=t.match(r);if(o)return i.replace("$1",o[1]||"")}return e?h.default.join(e,t):null}async function Tt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function O(t,n,e,s){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(s||""),t):Nt(t,n,e);if(!i)return Promise.resolve(null);return Tt(i)}function N(t){return t.startsWith(P)}function R(t){return t.replace(P,"")}function j(t){return`${P}${t}`}var et;function it(t){return{name:"bunup:types-resolve",buildStart(){et||=new rt.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?R(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?st.default.dirname(e):process.cwd(),{path:i}=await et.async(s,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let r=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(r).exists()?r:void 0}return i}}}async function ct(t,n,e,s,i,r){let o=E(t),a=j(o),f=A(e,s),l=D(e);try{let{output:g}=await ot.build({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[k(n,i,r),typeof e.dts==="object"&&"resolve"in e.dts&&it(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),at.dts()],external:(c)=>f.some((d)=>d.test(c))&&!l.some((d)=>d.test(c))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${m(g)}`)}}class y{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!y.instance)y.instance=new y;return y.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:e,size:s,identifier:i,muted:r}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=r?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),d=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${s}\x1B[0m ${g.join(" ")}${d}`}let f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${f}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let i=String(t),r=this.colors.default,o,a,f={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,f=e;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){r=c;break}let l=this.formatMessage({colorCode:r,label:i,message:n,size:o,identifier:a,muted:f.muted});this.output(l,f)}}var u=y.getInstance();var Ft=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Wt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ft(t,n,e){let s=new Set([t]),i=[t];while(i.length){let r=i.pop();if(!r)continue;try{let o=await Bun.file(r).text(),a=Ut(o);for(let f of a){let l=await O(f,n,e,r);if(!l)continue;if(!s.has(l))s.add(l),i.push(l)}}catch(o){u.warn(`Error processing ${r}: ${m(o)}`)}}return s}function Ut(t){let n=new Set;for(let e of[Ft,Wt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}var lt=require("oxc-transform");async function ut(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=E(e);if(!await Bun.file(e).exists())return;let r=await Bun.file(e).text(),{code:o}=lt.isolatedDeclaration(e,r);if(o)n.set(s,o)}catch(s){u.warn(`Failed to generate declaration for ${e}: ${m(s)}`)}})),n}var F=x(require("node:fs/promises")),v=x(require("node:path")),Vt=require("oxc-transform");async function gt(t,n){let e=v.default.resolve(t),s=v.default.resolve(e,n);if(!await F.default.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new p(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${s}`);if(v.default.relative(e,s).startsWith(".."))throw new p(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function mt(t,n,e,s,i){let{absoluteEntry:r}=await gt(t,n),o=nt(s),a=T(s),f=await ft(r,o,a),l=await ut(f);return ct(r,l,e,i,o,a)}function dt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],e=new Set,s={};function i(r,o){if(e.has(r)){let a=Y(),f=`${r}_${a}`;u.warn(`Output name conflict: "${r}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${s[r]} -> ${r}.js
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=mt(r);i(o,r)}else if(typeof t==="object")Object.entries(t).forEach(([r,o])=>{i(r,o)});else{let r=mt(t);i(r,t)}return n}function dt(t,n){return`[dir]/${t}${n}`}var pt=require("load-tsconfig");function xt(t){try{return pt.loadTsConfig(".",t)}catch(n){return u.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}var ht=x(require("node:path"));async function bt(t){let n=ht.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return u.warn(`Failed to load package.json at ${n}: ${m(e)}`),{packageJson:null,path:n}}}function wt(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let i=s.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var k=new Set;async function $t(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await bt(n);if(e)u.cli(`Using package.json: ${$(s,2)}`,{muted:!0,once:s,identifier:t.name});let i=e?.type,r=D(t,e),o=A(t),a=[wt(r,o)],f=W(t.entry),l=H(t,n),g=t.format.flatMap((c)=>f.map((d)=>{return Gt(t,n,d,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=xt(t.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${$(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let d=t.format.filter((b)=>{if(b==="iife"&&!M(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):f;try{await Promise.all(yt.map(async(b)=>{let Et=await gt(n,b.path,t,c,e);await Promise.all(d.map(async(Ct)=>{let Rt=q(Ct,i),I=`${n}/${t.outDir}/${b.name}${Rt}`;await Bun.write(I,Et);let Pt=Bun.file(I).size||0;u.progress("DTS",$(I),_(Pt),t.name)}))}))}catch(b){throw new p(m(b))}}}async function Gt(t,n,e,s,i,r,o){let a=J(s,i),f=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:dt(e.name,a)},splitting:Q(t.splitting,s),plugins:r,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let l=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(l).size||0;u.progress(s.toUpperCase(),$(l),_(g),t.name)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=dt(r);i(o,r)}else if(typeof t==="object")Object.entries(t).forEach(([r,o])=>{i(r,o)});else{let r=dt(t);i(r,t)}return n}function pt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return u.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}var wt=x(require("node:path"));async function bt(t){let n=wt.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return u.warn(`Failed to load package.json at ${n}: ${m(e)}`),{packageJson:null,path:n}}}function $t(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let i=s.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var tt=new Set;async function Et(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await bt(n);if(e)u.cli(`Using package.json: ${$(s,2)}`,{muted:!0,once:s,identifier:t.name});let i=e?.type,r=A(t,e),o=D(t),a=[$t(r,o)],f=W(t.entry),l=H(t,n),g=t.format.flatMap((c)=>f.map((d)=>{return Gt(t,n,d,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${$(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let d=t.format.filter((w)=>{if(w==="iife"&&!M(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):f;try{await Promise.all(yt.map(async(w)=>{let Ct=await mt(n,w.path,t,c,e);await Promise.all(d.map(async(Rt)=>{let Pt=J(Rt,i),I=`${n}/${t.outDir}/${w.name}${Pt}`;await Bun.write(I,Ct);let Mt=Bun.file(I).size||0;u.progress("DTS",$(I),_(Mt),t.name)}))}))}catch(w){throw new p(m(w))}}}async function Gt(t,n,e,s,i,r,o){let a=q(s,i),f=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:pt(e.name,a)},splitting:Q(t.splitting,s),bytecode:Z(t.bytecode,s),plugins:r,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new b(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let l=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(l).size||0;u.progress(s.toUpperCase(),$(l),_(g),t.name)}
package/build/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- function ut(t){return t}function gt(t){return t}import{build as bt}from"rolldown";import{dts as wt}from"rolldown-plugin-dts";class v extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends v{constructor(t){super(t);this.name="BunupBuildError"}}class p extends v{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};import St from"node:fs/promises";import _t from"node:path";function T(t,n){return{outdir:`${n}/${t.outDir}`,minify:mt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function mt(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:i}=t,r=n===!0;return{whitespace:e??r,identifiers:s??r,syntax:i??r}}function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function F(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function U(t,n){switch(t){case"esm":return".d.mts";case"cjs":return R(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(t){return t==="module"}function G(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function X(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${O(n)}($|\\/|\\\\)`):n)}function P(t,n){return X(t.external||[]).concat(G(n).map((e)=>new RegExp(`^${O(e)}($|\\/|\\\\)`)))}function M(t){return X(t.noExternal||[])}import xt from"node:path";import{ResolverFactory as ht}from"oxc-resolver";import $ from"node:path";var C="\x00dts:",B=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,i){if(S(s))return s;if(!i||!S(i))return null;let r=await D(s,n,e,E(i));if(!r)return null;let o=w(r);if(t.has(o))return A(o);return null},load(s){if(s.startsWith(C)){let i=E(s),r=t.get(i);if(r)return H.add(i),r}return null}}};function w(t){return t.replace(/\.tsx?$/,".d.ts")}function L(t){let n=$.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?$.resolve(n,t.data.compilerOptions.baseUrl):n}function Y(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=L(t);for(let[i,r]of Object.entries(e))if(Array.isArray(r)&&r.length){let o=i.replace(/\*/g,"(.*)"),a=r[0].replace(/\*/g,"$1");n.set(`^${o}$`,$.join(s,a))}return n}function dt(t,n,e){for(let[s,i]of n){let r=new RegExp(s),o=t.match(r);if(o)return i.replace("$1",o[1]||"")}return e?$.join(e,t):null}async function pt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function D(t,n,e,s){let i=t.startsWith(".")?$.resolve($.dirname(s||""),t):dt(t,n,e);if(!i)return Promise.resolve(null);return pt(i)}function S(t){return t.startsWith(C)}function E(t){return t.replace(C,"")}function A(t){return`${C}${t}`}var J;function q(t){return{name:"bunup:types-resolve",buildStart(){J||=new ht({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?E(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?xt.dirname(e):process.cwd(),{path:i}=await J.async(s,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let r=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(r).exists()?r:void 0}return i}}}async function K(t,n,e,s,i,r){let o=w(t),a=A(o),f=P(e,s),l=M(e);try{let{output:g}=await bt({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[B(n,i,r),typeof e.dts==="object"&&"resolve"in e.dts&&q(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),wt()],external:(c)=>f.some((d)=>d.test(c))&&!l.some((d)=>d.test(c))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${m(g)}`)}}class y{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!y.instance)y.instance=new y;return y.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:e,size:s,identifier:i,muted:r}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=r?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),d=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${s}\x1B[0m ${g.join(" ")}${d}`}let f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${f}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let i=String(t),r=this.colors.default,o,a,f={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,f=e;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){r=c;break}let l=this.formatMessage({colorCode:r,label:i,message:n,size:o,identifier:a,muted:f.muted});this.output(l,f)}}var u=y.getInstance();var $t=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Q(t,n,e){let s=new Set([t]),i=[t];while(i.length){let r=i.pop();if(!r)continue;try{let o=await Bun.file(r).text(),a=Et(o);for(let f of a){let l=await D(f,n,e,r);if(!l)continue;if(!s.has(l))s.add(l),i.push(l)}}catch(o){u.warn(`Error processing ${r}: ${m(o)}`)}}return s}function Et(t){let n=new Set;for(let e of[$t,yt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}import{isolatedDeclaration as Ct}from"oxc-transform";async function Z(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=w(e);if(!await Bun.file(e).exists())return;let r=await Bun.file(e).text(),{code:o}=Ct(e,r);if(o)n.set(s,o)}catch(s){u.warn(`Failed to generate declaration for ${e}: ${m(s)}`)}})),n}import z from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as $n}from"oxc-transform";async function k(t,n){let e=_.resolve(t),s=_.resolve(e,n);if(!await z.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new p(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${s}`);if(_.relative(e,s).startsWith(".."))throw new p(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function tt(t,n,e,s,i){let{absoluteEntry:r}=await k(t,n),o=Y(s),a=L(s),f=await Q(r,o,a),l=await Z(f);return K(r,l,e,i,o,a)}function nt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(t){let n=[],e=new Set,s={};function i(r,o){if(e.has(r)){let a=F(),f=`${r}_${a}`;u.warn(`Output name conflict: "${r}" is used by multiple files.
1
+ function gt(t){return t}function mt(t){return t}import{build as bt}from"rolldown";import{dts as $t}from"rolldown-plugin-dts";class j extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends j{constructor(t){super(t);this.name="BunupBuildError"}}class p extends j{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};import Lt from"node:fs/promises";import Nt from"node:path";function T(t,n){return{outdir:`${n}/${t.outDir}`,minify:dt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function dt(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:i}=t,r=n===!0;return{whitespace:e??r,identifiers:s??r,syntax:i??r}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function F(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function U(t,n){switch(t){case"esm":return".d.mts";case"cjs":return R(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(t){return t==="module"}function V(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function G(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function w(t,n=3){return t.split("/").slice(-n).join("/")}function X(t,n){return n==="cjs"?t:void 0}function B(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function P(t,n){return B(t.external||[]).concat(V(n).map((e)=>new RegExp(`^${v(e)}($|\\/|\\\\)`)))}function M(t){return B(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as wt}from"oxc-resolver";import $ from"node:path";var C="\x00dts:",H=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,i){if(S(s))return s;if(!i||!S(i))return null;let r=await A(s,n,e,y(i));if(!r)return null;let o=b(r);if(t.has(o))return D(o);return null},load(s){if(s.startsWith(C)){let i=y(s),r=t.get(i);if(r)return Y.add(i),r}return null}}};function b(t){return t.replace(/\.tsx?$/,".d.ts")}function L(t){let n=$.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?$.resolve(n,t.data.compilerOptions.baseUrl):n}function q(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=L(t);for(let[i,r]of Object.entries(e))if(Array.isArray(r)&&r.length){let o=i.replace(/\*/g,"(.*)"),a=r[0].replace(/\*/g,"$1");n.set(`^${o}$`,$.join(s,a))}return n}function pt(t,n,e){for(let[s,i]of n){let r=new RegExp(s),o=t.match(r);if(o)return i.replace("$1",o[1]||"")}return e?$.join(e,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function A(t,n,e,s){let i=t.startsWith(".")?$.resolve($.dirname(s||""),t):pt(t,n,e);if(!i)return Promise.resolve(null);return xt(i)}function S(t){return t.startsWith(C)}function y(t){return t.replace(C,"")}function D(t){return`${C}${t}`}var J;function K(t){return{name:"bunup:types-resolve",buildStart(){J||=new wt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?y(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?ht.dirname(e):process.cwd(),{path:i}=await J.async(s,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let r=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(r).exists()?r:void 0}return i}}}async function Q(t,n,e,s,i,r){let o=b(t),a=D(o),f=P(e,s),l=M(e);try{let{output:g}=await bt({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[H(n,i,r),typeof e.dts==="object"&&"resolve"in e.dts&&K(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),$t()],external:(c)=>f.some((d)=>d.test(c))&&!l.some((d)=>d.test(c))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${m(g)}`)}}class E{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!E.instance)E.instance=new E;return E.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:e,size:s,identifier:i,muted:r}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=r?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),d=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${s}\x1B[0m ${g.join(" ")}${d}`}let f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${f}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let i=String(t),r=this.colors.default,o,a,f={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,f=e;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){r=c;break}let l=this.formatMessage({colorCode:r,label:i,message:n,size:o,identifier:a,muted:f.muted});this.output(l,f)}}var u=E.getInstance();var Et=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Z(t,n,e){let s=new Set([t]),i=[t];while(i.length){let r=i.pop();if(!r)continue;try{let o=await Bun.file(r).text(),a=Ct(o);for(let f of a){let l=await A(f,n,e,r);if(!l)continue;if(!s.has(l))s.add(l),i.push(l)}}catch(o){u.warn(`Error processing ${r}: ${m(o)}`)}}return s}function Ct(t){let n=new Set;for(let e of[Et,yt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}import{isolatedDeclaration as Rt}from"oxc-transform";async function z(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=b(e);if(!await Bun.file(e).exists())return;let r=await Bun.file(e).text(),{code:o}=Rt(e,r);if(o)n.set(s,o)}catch(s){u.warn(`Failed to generate declaration for ${e}: ${m(s)}`)}})),n}import k from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as En}from"oxc-transform";async function tt(t,n){let e=_.resolve(t),s=_.resolve(e,n);if(!await k.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new p(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${s}`);if(_.relative(e,s).startsWith(".."))throw new p(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function nt(t,n,e,s,i){let{absoluteEntry:r}=await tt(t,n),o=q(s),a=L(s),f=await Z(r,o,a),l=await z(f);return Q(r,l,e,i,o,a)}function et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(t){let n=[],e=new Set,s={};function i(r,o){if(e.has(r)){let a=F(),f=`${r}_${a}`;u.warn(`Output name conflict: "${r}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${s[r]} -> ${r}.js
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=nt(r);i(o,r)}else if(typeof t==="object")Object.entries(t).forEach(([r,o])=>{i(r,o)});else{let r=nt(t);i(r,t)}return n}function et(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Rt}from"load-tsconfig";function st(t){try{return Rt(".",t)}catch(n){return u.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}import Pt from"node:path";async function rt(t){let n=Pt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return u.warn(`Failed to load package.json at ${n}: ${m(e)}`),{packageJson:null,path:n}}}function it(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let i=s.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var H=new Set;async function Mt(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await rt(n);if(e)u.cli(`Using package.json: ${b(s,2)}`,{muted:!0,once:s,identifier:t.name});let i=e?.type,r=P(t,e),o=M(t),a=[it(r,o)],f=N(t.entry),l=T(t,n),g=t.format.flatMap((c)=>f.map((d)=>{return Dt(t,n,d,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=st(t.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${b(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let d=t.format.filter((x)=>{if(x==="iife"&&!R(i)&&t.format.includes("cjs"))return!1;return!0}),ot=typeof t.dts==="object"&&t.dts.entry?N(t.dts.entry):f;try{await Promise.all(ot.map(async(x)=>{let at=await tt(n,x.path,t,c,e);await Promise.all(d.map(async(ct)=>{let ft=U(ct,i),j=`${n}/${t.outDir}/${x.name}${ft}`;await Bun.write(j,at);let lt=Bun.file(j).size||0;u.progress("DTS",b(j),I(lt),t.name)}))}))}catch(x){throw new p(m(x))}}}async function Dt(t,n,e,s,i,r,o){let a=W(s,i),f=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:et(e.name,a)},splitting:V(t.splitting,s),plugins:r,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let l=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(l).size||0;u.progress(s.toUpperCase(),b(l),I(g),t.name)}export{gt as defineWorkspace,ut as defineConfig,Mt as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=et(r);i(o,r)}else if(typeof t==="object")Object.entries(t).forEach(([r,o])=>{i(r,o)});else{let r=et(t);i(r,t)}return n}function st(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Pt}from"load-tsconfig";function rt(t){try{return Pt(".",t)}catch(n){return u.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}import Mt from"node:path";async function it(t){let n=Mt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return u.warn(`Failed to load package.json at ${n}: ${m(e)}`),{packageJson:null,path:n}}}function ot(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let i=s.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var Y=new Set;async function At(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await it(n);if(e)u.cli(`Using package.json: ${w(s,2)}`,{muted:!0,once:s,identifier:t.name});let i=e?.type,r=P(t,e),o=M(t),a=[ot(r,o)],f=N(t.entry),l=T(t,n),g=t.format.flatMap((c)=>f.map((d)=>{return Dt(t,n,d,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=rt(t.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let d=t.format.filter((x)=>{if(x==="iife"&&!R(i)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?N(t.dts.entry):f;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,e);await Promise.all(d.map(async(ft)=>{let lt=U(ft,i),O=`${n}/${t.outDir}/${x.name}${lt}`;await Bun.write(O,ct);let ut=Bun.file(O).size||0;u.progress("DTS",w(O),I(ut),t.name)}))}))}catch(x){throw new p(m(x))}}}async function Dt(t,n,e,s,i,r,o){let a=W(s,i),f=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:st(e.name,a)},splitting:G(t.splitting,s),bytecode:X(t.bytecode,s),plugins:r,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let l=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(l).size||0;u.progress(s.toUpperCase(),w(l),I(g),t.name)}export{mt as defineWorkspace,gt as defineConfig,At as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.61",
3
+ "version": "0.3.64",
4
4
  "description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "prettier": "^3.5.3",
25
25
  "typescript": "^5.8.3",
26
26
  "vitest": "^2.1.9",
27
- "create-bunup": "0.3.61"
27
+ "create-bunup": "0.3.64"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "typescript": ">=4.5.0"