bunup 0.3.68 → 0.3.70

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/README.md CHANGED
@@ -7,10 +7,10 @@ An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by [
7
7
 
8
8
  | Bundler | Format | Build Time | Build Time (with dts) |
9
9
  | ------- | -------- | -------------- | --------------------- |
10
- | bunup | esm, cjs | **3.09ms ⚡️** | **19.55ms ⚡️** |
11
- | tsdown | esm, cjs | 5.75ms | 43.89ms |
12
- | unbuild | esm, cjs | 42.26ms | 322.66ms |
13
- | tsup | esm, cjs | 63.81ms | 948.24ms |
10
+ | bunup | esm, cjs | **3.13ms ⚡️** | **20.65ms ⚡️** |
11
+ | tsdown | esm, cjs | 5.89ms | 43.76ms |
12
+ | unbuild | esm, cjs | 43.84ms | 322.65ms |
13
+ | tsup | esm, cjs | 62.07ms | 937.35ms |
14
14
 
15
15
  _Lower build time is better. Benchmark run on the same code with identical output formats._
16
16
 
package/build/cli.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{build as Gn}from"rolldown";import{dts as Xn}from"rolldown-plugin-dts";class $ extends Error{constructor(n){super(n);this.name="BunupError"}}class x extends ${constructor(n){super(n);this.name="BunupBuildError"}}class d extends ${constructor(n){super(n);this.name="BunupDTSBuildError"}}class m extends ${constructor(n){super(n);this.name="BunupCLIError"}}class M extends ${constructor(n){super(n);this.name="BunupWatchError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)},Un=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(n,t)=>{let e=p(n),r=t?`[${t}] `:"",i="ERROR";if(n instanceof x)i="BUILD ERROR";else if(n instanceof d)i="DTS ERROR";else if(n instanceof m)i="CLI ERROR";else if(n instanceof M)i="WATCH ERROR";else if(n instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${e}`);let s=Un.find((o)=>o.pattern.test(e)&&(o.errorType===i||!o.errorType));if(s)console.error(`
3
+ import{build as Vt}from"rolldown";import{dts as Gt}from"rolldown-plugin-dts";class $ extends Error{constructor(t){super(t);this.name="BunupError"}}class x extends ${constructor(t){super(t);this.name="BunupBuildError"}}class d extends ${constructor(t){super(t);this.name="BunupDTSBuildError"}}class m extends ${constructor(t){super(t);this.name="BunupCLIError"}}class M extends ${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",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],q=(t,e)=>{let n=p(t),r=e?`[${e}] `:"",i="ERROR";if(t instanceof x)i="BUILD ERROR";else if(t instanceof d)i="DTS ERROR";else if(t instanceof m)i="CLI ERROR";else if(t instanceof M)i="WATCH ERROR";else if(t instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${n}`);let s=Ut.find((o)=>o.pattern.test(n)&&(o.errorType===i||!o.errorType));if(s)console.error(`
4
4
  \x1B[90mA solution for this error is available at: \x1B[36m${s.link}\x1B[0m
5
- `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},nn=(n,t)=>{V(n,t),process.exit(1)};import en from"node:fs/promises";import Fn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function tn(n,t){return{outdir:`${t}/${n.outDir}`,minify:kn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function kn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:i}=n,s=t===!0;return{whitespace:e??s,identifiers:r??s,syntax:i??s}}function q(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rn(n=8){return Math.random().toString(36).substring(2,2+n)}function sn(n,t){switch(n){case"esm":return".mjs";case"cjs":return L(t)?".cjs":".js";case"iife":return".global.js"}}function on(n,t){switch(n){case"esm":return".d.mts";case"cjs":return L(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(n){return n==="module"}function D(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function an(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function cn(n,t){return n===void 0?t==="esm":n}function G(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function b(n,t=3){return n.split("/").slice(-t).join("/")}async function X(n,t){let e=Fn.join(n,t);try{await en.rm(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await en.mkdir(e,{recursive:!0})}function Y(n){return n||O.outDir}function ln(n){return n===void 0?O.clean:n}function un(n,t){return t==="cjs"?n:void 0}function fn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${q(t)}($|\\/|\\\\)`):t)}function _(n,t){return fn(n.external||[]).concat(an(t).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function j(n){return fn(n.noExternal||[])}import Vn from"node:path";import{ResolverFactory as qn}from"oxc-resolver";import C from"node:path";var T="\x00dts:",pn=(n,t,e)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(J(r))return r;if(!i||!J(i))return null;let s=await N(r,t,e,P(i));if(!s)return null;let o=v(s);if(n.has(o))return U(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=n.get(i);if(s)return B.add(i),s}return null}}};function v(n){return n.replace(/\.tsx?$/,".d.ts")}function K(n){let t=C.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?C.resolve(t,n.data.compilerOptions.baseUrl):t}function gn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=K(n);for(let[i,s]of Object.entries(e))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,C.join(r,a))}return t}function Wn(n,t,e){for(let[r,i]of t){let s=new RegExp(r),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return e?C.join(e,n):null}async function Hn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(n,t,e,r){let i=n.startsWith(".")?C.resolve(C.dirname(r||""),n):Wn(n,t,e);if(!i)return Promise.resolve(null);return Hn(i)}function J(n){return n.startsWith(T)}function P(n){return n.replace(T,"")}function U(n){return`${T}${n}`}var dn;function mn(n){return{name:"bunup:types-resolve",buildStart(){dn||=new qn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?P(e):void 0,/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?Vn.dirname(e):process.cwd(),{path:i}=await dn.async(r,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function hn(n,t,e,r,i,s){let o=v(n),a=U(o),c=_(e,r),u=j(e);try{let{output:g}=await Gn({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;h(f)},plugins:[pn(t,i,s),typeof e.dts==="object"&&"resolve"in e.dts&&mn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Xn()],external:(f)=>c.some((h)=>h.test(f))&&!u.some((h)=>h.test(f))});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(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({colorCode:n,label:t,message:e,size:r,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${h}`}let c=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`}output(n,t={},e=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")}cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)}error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)}progress(n,t,e,r){let i=String(n),s=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,f]of Object.entries(this.colors.progress))if(i.includes(g)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}}var l=R.getInstance();var Yn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Jn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function xn(n,t,e){let r=new Set([n]),i=[n];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Kn(o);for(let c of a){let u=await N(c,t,e,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){l.warn(`Error processing ${s}: ${p(o)}`)}}return r}function Kn(n){let t=new Set;for(let e of[Yn,Jn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}import{isolatedDeclaration as Qn}from"oxc-transform";async function bn(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=v(e);if(!await Bun.file(e).exists())return;let s=await Bun.file(e).text(),{code:o}=Qn(e,s);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${p(r)}`)}})),t}import wn from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as Zn}from"oxc-transform";async function yn(n,t){let e=Q.resolve(n),r=Q.resolve(e,t);if(!await wn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Q.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function En(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=Zn(r,i);s.forEach((o)=>{if(!t)console.log(`
6
- `);let a=o.labels[0],c=a?zn(i,a.start):"",g=`${b(r)}${c}: ${nt(o.message)}`;l.warn(g),t=!0})}catch{}})),t)l.info(`
5
+ `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},tt=(t,e)=>{q(t,e),process.exit(1)};import nt from"node:fs/promises";import kt from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function et(t,e){return{outdir:`${e}/${t.outDir}`,minify:_t(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 _t(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,s=e===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function V(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rt(t=8){return Math.random().toString(36).substring(2,2+t)}function st(t,e){switch(t){case"esm":return".mjs";case"cjs":return L(e)?".cjs":".js";case"iife":return".global.js"}}function it(t,e){switch(t){case"esm":return".d.mts";case"cjs":return L(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(t){return t==="module"}function D(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,e){return t===void 0?e==="esm":t}function G(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/Math.pow(1024,n)).toFixed(2)} ${e[n]}`}function b(t,e=3){return t.split("/").slice(-e).join("/")}async function X(t,e){let n=kt.join(t,e);try{await nt.rm(n,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await nt.mkdir(n,{recursive:!0})}function Y(t){return t||O.outDir}function ct(t){return t===void 0?O.clean:t}function lt(t,e){return e==="cjs"?t:void 0}function ut(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${V(e)}($|\\/|\\\\)`):e)}function j(t,e){return ut(t.external||[]).concat(ot(e).map((n)=>new RegExp(`^${V(n)}($|\\/|\\\\)`)))}function N(t){return ut(t.noExternal||[])}import Ht from"node:path";import{ResolverFactory as qt}from"oxc-resolver";import B from"node:path";var T="\x00dts:",ft=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(J(r))return r;if(!i||!J(i))return null;let s=await U(r,e,n,P(i));if(!s)return null;let o=v(s);if(t.has(o))return _(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=t.get(i);if(s)return R.add(i),s}return null}}};function v(t){return t.replace(/\.tsx?$/,".d.ts")}function K(t){let e=B.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?B.resolve(e,t.data.compilerOptions.baseUrl):e}function pt(t){let e=new Map,n=t.data?.compilerOptions?.paths;if(!n)return e;let r=K(t);for(let[i,s]of Object.entries(n))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");e.set(`^${o}$`,B.join(r,a))}return e}function Ft(t,e,n){for(let[r,i]of e){let s=new RegExp(r),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return n?B.join(n,t):null}async function Wt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function U(t,e,n,r){let i=t.startsWith(".")?B.resolve(B.dirname(r||""),t):Ft(t,e,n);if(!i)return Promise.resolve(null);return Wt(i)}function J(t){return t.startsWith(T)}function P(t){return t.replace(T,"")}function _(t){return`${T}${t}`}var gt;function dt(t){return{name:"bunup:types-resolve",buildStart(){gt||=new qt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){if(n=n?P(n):void 0,/\0/.test(e))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===e||!!(n&&n.includes(o));else a=o.test(e)||!!(n&&o.test(n));return a}))return}let r=n?Ht.dirname(n):process.cwd(),{path:i}=await gt.async(r,e);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function mt(t,e,n,r,i,s){let o=v(t),a=_(o),c=j(n,r),u=N(n);try{let{output:g}=await Vt({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;h(f)},plugins:[ft(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&dt(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Gt()],external:(f)=>c.some((h)=>h.test(f))&&!u.some((h)=>h.test(f))});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 C{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(!C.instance)C.instance=new C;return C.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:e,message:n,size:r,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=s?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${h}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${o}${a}${c}`}output(t,e={},n=console.log){if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let i=String(t),s=this.colors.default,o,a,c={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,c=n;for(let[g,f]of Object.entries(this.colors.progress))if(i.includes(g)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(u,c)}}var l=C.getInstance();var Xt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Yt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Jt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Kt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Zt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,zt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function te(t){let e=new Set,n=[Xt,Yt,Jt,Kt,Qt,Zt,zt];for(let r of n){let i=t.matchAll(r);for(let s of i)if(s[1])e.add(s[1])}return e}async function ht(t,e,n){let r=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=te(o);for(let c of a){let u=await U(c,e,n,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){l.warn(`Error processing ${s}: ${p(o)}`)}}return r}import{isolatedDeclaration as ee}from"oxc-transform";async function xt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=v(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=ee(n,s);if(o)e.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}import bt from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as ne}from"oxc-transform";async function yt(t,e){let n=Q.resolve(t),r=Q.resolve(n,e);if(!await bt.exists(n))throw new d(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Q.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function wt(t){let e=!1;if(await Promise.all([...t].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=ne(r,i);s.forEach((o)=>{if(!e)console.log(`
6
+ `);let a=o.labels[0],c=a?re(i,a.start):"",g=`${b(r)}${c}: ${se(o.message)}`;l.warn(g),e=!0})}catch{}})),e)l.info(`
7
7
  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.
8
- `)}function zn(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
9
- `),r=e.length,i=e[e.length-1].length+1;return` (${r}:${i})`}function nt(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $n(n,t,e,r,i){let{absoluteEntry:s}=await yn(n,t),o=gn(r),a=K(r),c=await xn(s,o,a),u=await bn(c);return hn(s,u,e,i,o,a)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function I(n){let t=[],e=new Set,r={};function i(s,o){if(e.has(s)){let a=rn(),c=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
8
+ `)}function re(t,e){if(e===void 0)return"";let n=t.slice(0,e).split(`
9
+ `),r=n.length,i=n[n.length-1].length+1;return` (${r}:${i})`}function se(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Et(t,e,n,r,i){let{absoluteEntry:s}=await yt(t,e),o=pt(r),a=K(r),c=await ht(s,o,a),u=await xt(c);return mt(s,u,n,i,o,a)}function S(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=rt(),c=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
10
10
  Bunup uses filenames without extensions as output names by default.
11
11
 
12
12
  ${r[s]} -> ${s}.js
@@ -20,8 +20,8 @@ To fix this, use named entries in your configuration:
20
20
  }
21
21
  }
22
22
 
23
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:s,path:o}),e.add(s),r[s]=o}if(Array.isArray(n))for(let s of n){let o=A(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=A(n);i(s,n)}return t}function On(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as tt}from"load-tsconfig";function vn(n){try{return tt(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import Z from"node:path";async function Bn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Z.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let s=await et(r,e);if(!s)continue;return{configs:it(s,n),configFilePath:r}}catch(i){throw new x(`Failed to load config from ${r}: ${p(i)}`)}}return{configs:[],configFilePath:""}}async function et(n,t){if(t===".json"||t===".jsonc")return rt(n);return st(n)}async function rt(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${p(t)}`)}}async function st(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${p(t)}`)}}function it(n,t){let e=[];if(ot(n))at(n,t,e);else if(Array.isArray(n))ct(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function ot(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function at(n,t,e){for(let r of n){let i=Z.resolve(t,r.root);if(Array.isArray(r.config))for(let s of r.config)e.push({options:{name:r.name,...s},rootDir:i});else e.push({options:{name:r.name,...r.config},rootDir:i})}}function ct(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function Cn(n){let t=Z.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${p(e)}`),{packageJson:null,path:t}}}function Rn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let i=r.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var B=new Set;async function k(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await Cn(t);if(e)l.cli(`Using package.json: ${b(r,2)}`,{muted:!0,once:r,identifier:n.name});let i=e?.type,s=_(n,e),o=j(n),a=[Rn(s,o)],c=I(n.entry),u=tn(n,t),g=n.format.flatMap((f)=>c.map((h)=>{return lt(n,t,h,f,i,a,u)}));if(await Promise.all(g),n.dts){let f=vn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${b(f.path,2)}`,{muted:!0,once:f.path,identifier:n.name});let h=n.format.filter((E)=>{if(E==="iife"&&!L(i)&&n.format.includes("cjs"))return!1;return!0}),Ln=typeof n.dts==="object"&&n.dts.entry?I(n.dts.entry):c;try{await Promise.all(Ln.map(async(E)=>{let Dn=await $n(t,E.path,n,f,e);await Promise.all(h.map(async(_n)=>{let jn=on(_n,i),H=`${t}/${n.outDir}/${E.name}${jn}`;await Bun.write(H,Dn);let Nn=Bun.file(H).size||0;l.progress("DTS",b(H),G(Nn),n.name)}))}))}catch(E){throw new d(p(E))}}}async function lt(n,t,e,r,i,s,o){let a=sn(r,i),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:On(e.name,a)},splitting:cn(n.splitting,r),bytecode:un(n.bytecode,r),plugins:s,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),b(u),G(g),n.name)}var F="0.3.68";var Pn="https://bun.sh/docs/installation",Tn="https://bunup.arshadyaseen.com/#cli-options";function w(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function y(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new m(`Option --${n} requires a string value`)}}function An(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new m(`Option --${n} requires a string value`)}}function ft(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),e.push({name:c,path:o})}else e.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(t))for(let s of t){let o=S(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=S(t);i(s,t)}return e}function $t(t,e){return`[dir]/${t}${e}`}import{loadTsConfig as ie}from"load-tsconfig";function Ot(t){try{return ie(".",t)}catch(e){return l.warn(`Failed to load tsconfig: ${p(e)}`),{path:t,data:{},files:[]}}}import Z from"node:path";async function vt(t){let e=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let n of e){let r=Z.join(t,`bunup.config${n}`);try{if(!await Bun.file(r).exists())continue;let s=await oe(r,n);if(!s)continue;return{configs:le(s,t),configFilePath:r}}catch(i){throw new x(`Failed to load config from ${r}: ${p(i)}`)}}return{configs:[],configFilePath:""}}async function oe(t,e){if(e===".json"||e===".jsonc")return ae(t);return ce(t)}async function ae(t){try{let e=await Bun.file(t).text(),n=JSON.parse(e);return n.bunup||n}catch(e){throw new Error(`Invalid JSON in config file. ${p(e)}`)}}async function ce(t){try{let e=await import(`file://${t}`),n=e.default||e;if(!n)return l.warn(`No export found in ${t}. Make sure you're exporting your configuration.`),{};return n}catch(e){throw new Error(`Failed to import config file. ${p(e)}`)}}function le(t,e){let n=[];if(ue(t))fe(t,e,n);else if(Array.isArray(t))pe(t,e,n);else if(t&&typeof t==="object")n.push({options:t,rootDir:e});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return n}function ue(t){return Array.isArray(t)&&t.length>0&&t.every((e)=>typeof e==="object"&&e!==null&&("name"in e)&&("root"in e)&&("config"in e))}function fe(t,e,n){for(let r of t){let i=Z.resolve(e,r.root);if(Array.isArray(r.config))for(let s of r.config)n.push({options:{name:r.name,...s},rootDir:i});else n.push({options:{name:r.name,...r.config},rootDir:i})}}function pe(t,e,n){for(let r of t){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");n.push({options:r,rootDir:e})}}async function Rt(t){let e=Z.join(t,"package.json");try{if(!await Bun.file(e).exists())return{packageJson:null,path:e};let r=await Bun.file(e).text();return{packageJson:JSON.parse(r),path:e}}catch(n){return l.warn(`Failed to load package.json at ${e}: ${p(n)}`),{packageJson:null,path:e}}}function Bt(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(t.some((o)=>o.test(i))&&!e.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var R=new Set;async function k(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await Rt(e);if(n)l.cli(`Using package.json: ${b(r,2)}`,{muted:!0,once:r,identifier:t.name});let i=n?.type,s=j(t,n),o=N(t),a=[Bt(s,o)],c=A(t.entry),u=et(t,e),g=t.format.flatMap((f)=>c.map((h)=>{return ge(t,e,h,f,i,a,u)}));if(await Promise.all(g),t.dts){let f=Ot(t.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${b(f.path,2)}`,{muted:!0,once:f.path,identifier:t.name});let h=t.format.filter((E)=>{if(E==="iife"&&!L(i)&&t.format.includes("cjs"))return!1;return!0}),Mt=typeof t.dts==="object"&&t.dts.entry?A(t.dts.entry):c;try{await Promise.all(Mt.map(async(E)=>{let Lt=await Et(e,E.path,t,f,n);await Promise.all(h.map(async(Dt)=>{let jt=it(Dt,i),H=`${e}/${t.outDir}/${E.name}${jt}`;await Bun.write(H,Lt);let Nt=Bun.file(H).size||0;l.progress("DTS",b(H),G(Nt),t.name)}))}))}catch(E){throw new d(p(E))}}}async function ge(t,e,n,r,i,s,o){let a=st(r,i),c=await Bun.build({...o,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:$t(n.name,a)},splitting:at(t.splitting,r),bytecode:lt(t.bytecode,r),plugins:s,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${e}/${t.outDir}/${n.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),b(u),G(g),t.name)}var F="0.3.70";var Ct="https://bun.sh/docs/installation",Pt="https://bunup.arshadyaseen.com/#cli-options";function y(t){return(e,n)=>{n[t]=e===!0?!0:e==="true"}}function w(t){return(e,n)=>{if(typeof e==="string")n[t]=e;else throw new m(`Option --${t} requires a string value`)}}function Tt(t){return(e,n)=>{if(typeof e==="string")n[t]=e.split(",");else throw new m(`Option --${t} requires a string value`)}}function me(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
- `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Tn}\x1B[0m
26
- `),process.exit(0)}function pt(){console.log(F),process.exit(0)}var gt={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.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:An("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:An("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")}},dt={resolveDts:{flags:["rd","resolve-dts"],handler:(n,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof n==="string")if(n==="true"||n==="false")t.dts.resolve=n==="true";else t.dts.resolve=n.split(",");else t.dts.resolve=!0}}},mt={help:{flags:["h","help"],handler:()=>ft()},version:{flags:["v","version"],handler:()=>pt()}},S={};for(let n of Object.values(gt))if(n)for(let t of n.flags)S[t]=n.handler;for(let n of Object.values(dt))for(let t of n.flags)S[t]=n.handler;for(let n of Object.values(mt))for(let t of n.flags)S[t]=n.handler;function In(n){let t={},e={},r=0;while(r<n.length){let i=n[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,c]=i.slice(2).split("=",2);s=a,o=c}else{s=i.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=A(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(s.startsWith("entry.")){let a=s.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[s];if(a)a(o,t);else throw new m(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=S[s];if(c)c(a,t);else throw new m(`Unknown option: -${s}`)}else{let s=A(i);if(e[s])l.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);e[s]=i}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
27
- To install Bun, visit `+Pn)})();import W from"node:path";import ht from"chokidar";async function Sn(n,t){let e=new Set,r=I(n.entry);r.forEach((a)=>{let c=W.resolve(t,a.path),u=W.dirname(c);e.add(u)});let i=ht.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(t,n.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let c=performance.now();if(await k({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${D(performance.now()-c)}`);await z()}catch(c){V(c)}finally{s=!1}};i.on("change",(a)=>{let c=W.relative(t,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new M(`Watcher error: ${p(a)}`)}),await o(!0)}async function xt(n=Bun.argv.slice(2)){let t=In(n),{configs:e,configFilePath:r}=await Bn(process.cwd());if(l.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${b(r,2)}`,{muted:!0});let i=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...t},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await Mn(a,c)}else{for(let{options:a,rootDir:c}of e)if(ln(a.clean))X(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...O,...a,...t};await Mn(u,c)}))}let s=performance.now()-i,o=D(s);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0);l.dispose()}async function z(){if(B.size>0)await En(B),B.clear()}async function Mn(n,t){if(n.watch)await Sn(n,t);else await k(n,t),n.onBuildSuccess?.()}xt().catch((n)=>nn(n));export{z as validateDtsFiles,xt as main};
25
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Pt}\x1B[0m
26
+ `),process.exit(0)}function he(){console.log(F),process.exit(0)}var xe={name:{flags:["n","name"],handler:w("name")},format:{flags:["f","format"],handler:(t,e)=>{if(typeof t==="string")e.format=t.split(",");else throw new m("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:w("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},banner:{flags:["b","banner"],handler:w("banner")},footer:{flags:["f","footer"],handler:w("footer")},external:{flags:["e","external"],handler:Tt("external")},sourcemap:{flags:["sm","sourcemap"],handler:w("sourcemap")},target:{flags:["t","target"],handler:w("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:y("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:y("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:y("minifySyntax")},clean:{flags:["c","clean"],handler:y("clean")},splitting:{flags:["s","splitting"],handler:y("splitting")},noExternal:{flags:["ne","no-external"],handler:Tt("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:y("bytecode")}},be={resolveDts:{flags:["rd","resolve-dts"],handler:(t,e)=>{if(!e.dts)e.dts={};if(typeof e.dts==="boolean")e.dts={};if(typeof t==="string")if(t==="true"||t==="false")e.dts.resolve=t==="true";else e.dts.resolve=t.split(",");else e.dts.resolve=!0}}},ye={help:{flags:["h","help"],handler:()=>me()},version:{flags:["v","version"],handler:()=>he()}},I={};for(let t of Object.values(xe))if(t)for(let e of t.flags)I[e]=t.handler;for(let t of Object.values(be))for(let e of t.flags)I[e]=t.handler;for(let t of Object.values(ye))for(let e of t.flags)I[e]=t.handler;function St(t){let e={},n={},r=0;while(r<t.length){let i=t[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,c]=i.slice(2).split("=",2);s=a,o=c}else{s=i.slice(2);let a=t[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=S(o);if(n[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);n[a]=o}else throw new m("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(n[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=o}else throw new m(`Option --entry.${a} requires a string value`)}else{let a=I[s];if(a)a(o,e);else throw new m(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=t[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=I[s];if(c)c(a,e);else throw new m(`Unknown option: -${s}`)}else{let s=S(i);if(n[s])l.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);n[s]=i}r++}if(Object.keys(n).length>0)e.entry=n;return e}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
27
+ To install Bun, visit `+Ct)})();import W from"node:path";import we from"chokidar";async function At(t,e){let n=new Set,r=A(t.entry);r.forEach((a)=>{let c=W.resolve(e,a.path),u=W.dirname(c);n.add(u)});let i=we.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(e,t.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let c=performance.now();if(await k({...t,entry:r.map((u)=>u.path),clean:!1},e),t.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${D(performance.now()-c)}`);await z()}catch(c){q(c)}finally{s=!1}};i.on("change",(a)=>{let c=W.relative(e,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new M(`Watcher error: ${p(a)}`)}),await o(!0)}async function Ee(t=Bun.argv.slice(2)){let e=St(t),{configs:n,configFilePath:r}=await vt(process.cwd());if(l.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${b(r,2)}`,{muted:!0});let i=performance.now();if(l.cli("Build started"),n.length===0){let a={...O,...e},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await It(a,c)}else{for(let{options:a,rootDir:c}of n)if(ct(a.clean))X(c,Y(a.outDir));await Promise.all(n.map(async({options:a,rootDir:c})=>{let u={...O,...a,...e};await It(u,c)}))}let s=performance.now()-i,o=D(s);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),e.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!e.watch)process.exit(0);l.dispose()}async function z(){if(R.size>0)await wt(R),R.clear()}async function It(t,e){if(t.watch)await At(t,e);else await k(t,e),t.onBuildSuccess?.()}Ee().catch((t)=>tt(t));export{z as validateDtsFiles,Ee as main};
package/build/index.js CHANGED
@@ -1,15 +1,15 @@
1
- var It=require("node:module");var Bt=Object.create;var{getPrototypeOf:Dt,defineProperty:R,getOwnPropertyNames:U,getOwnPropertyDescriptor:Ot}=Object,V=Object.prototype.hasOwnProperty;var x=(t,n,r)=>{r=t!=null?Bt(Dt(t)):{};let e=n||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r;for(let i of U(t))if(!V.call(e,i))R(e,i,{get:()=>t[i],enumerable:!0});return e},F=new WeakMap,At=(t)=>{var n=F.get(t),r;if(n)return n;if(n=R({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")U(t).map((e)=>!V.call(n,e)&&R(n,e,{get:()=>t[e],enumerable:!(r=Ot(t,e))||r.enumerable}));return F.set(t,n),n};var Tt=(t,n)=>{for(var r in n)R(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var kt={};Tt(kt,{defineWorkspace:()=>G,defineConfig:()=>k,build:()=>$t});module.exports=At(kt);function k(t){return t}function G(t){return t}var ot=require("rolldown"),at=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 d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};var vt=x(require("node:fs/promises")),Lt=x(require("node:path"));function X(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:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function H(t=8){return Math.random().toString(36).substring(2,2+t)}function Y(t,n){switch(t){case"esm":return".mjs";case"cjs":return P(n)?".cjs":".js";case"iife":return".global.js"}}function K(t,n){switch(t){case"esm":return".d.mts";case"cjs":return P(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function P(t){return t==="module"}function q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function J(t,n){return t===void 0?n==="esm":t}function L(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function Q(t,n){return n==="cjs"?t:void 0}function Z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function B(t,n){return Z(t.external||[]).concat(q(n).map((r)=>new RegExp(`^${v(r)}($|\\/|\\\\)`)))}function D(t){return Z(t.noExternal||[])}var et=x(require("node:path")),st=require("oxc-resolver");var h=x(require("node:path"));var M="\x00dts:",z=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(j(e))return e;if(!i||!j(i))return null;let s=await O(e,n,r,C(i));if(!s)return null;let o=$(s);if(t.has(o))return A(o);return null},load(e){if(e.startsWith(M)){let i=C(e),s=t.get(i);if(s)return tt.add(i),s}return null}}};function $(t){return t.replace(/\.tsx?$/,".d.ts")}function _(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,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=_(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,h.default.join(e,a))}return n}function jt(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?h.default.join(r,t):null}async function _t(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function O(t,n,r,e){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(e||""),t):jt(t,n,r);if(!i)return Promise.resolve(null);return _t(i)}function j(t){return t.startsWith(M)}function C(t){return t.replace(M,"")}function A(t){return`${M}${t}`}var rt;function it(t){return{name:"bunup:types-resolve",buildStart(){rt||=new st.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?C(r):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(r&&r.includes(o));else a=o.test(n)||!!(r&&o.test(r));return a}))return}let e=r?et.default.dirname(r):process.cwd(),{path:i}=await rt.async(e,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function ct(t,n,r,e,i,s){let o=$(t),a=A(o),u=B(r,e),l=D(r);try{let{output:g}=await ot.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[z(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&it(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),at.dts()],external:(c)=>u.some((m)=>m.test(c))&&!l.some((m)=>m.test(c))});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 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:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=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${e}\x1B[0m ${g.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,u={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:u.muted});this.output(l,u)}}var f=y.getInstance();var Nt=/(?: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 ut(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Ft(o);for(let u of a){let l=await O(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${p(o)}`)}}return e}function Ft(t){let n=new Set;for(let r of[Nt,Wt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}var lt=require("oxc-transform");async function ft(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=$(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=lt.isolatedDeclaration(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}var N=x(require("node:fs/promises")),T=x(require("node:path")),Ut=require("oxc-transform");async function gt(t,n){let r=T.default.resolve(t),e=T.default.resolve(r,n);if(!await N.default.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(T.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function pt(t,n,r,e,i){let{absoluteEntry:s}=await gt(t,n),o=nt(e),a=_(e),u=await ut(s,o,a),l=await ft(u);return ct(s,l,r,i,o,a)}function mt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=H(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ var Tt=require("node:module");var Mt=Object.create;var{getPrototypeOf:Dt,defineProperty:R,getOwnPropertyNames:U,getOwnPropertyDescriptor:Ot}=Object,V=Object.prototype.hasOwnProperty;var x=(t,n,r)=>{r=t!=null?Mt(Dt(t)):{};let e=n||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r;for(let o of U(t))if(!V.call(e,o))R(e,o,{get:()=>t[o],enumerable:!0});return e},F=new WeakMap,At=(t)=>{var n=F.get(t),r;if(n)return n;if(n=R({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")U(t).map((e)=>!V.call(n,e)&&R(n,e,{get:()=>t[e],enumerable:!(r=Ot(t,e))||r.enumerable}));return F.set(t,n),n};var St=(t,n)=>{for(var r in n)R(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var Kt={};St(Kt,{defineWorkspace:()=>q,defineConfig:()=>k,build:()=>$t});module.exports=At(Kt);function k(t){return t}function q(t){return t}var it=require("rolldown"),at=require("rolldown-plugin-dts");class v extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends v{constructor(t){super(t);this.name="BunupBuildError"}}class d extends v{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};var It=x(require("node:fs/promises")),Lt=x(require("node:path"));function G(t,n){return{outdir:`${n}/${t.outDir}`,minify:vt(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 vt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:o}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:o??s}}function I(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X(t=8){return Math.random().toString(36).substring(2,2+t)}function H(t,n){switch(t){case"esm":return".mjs";case"cjs":return P(n)?".cjs":".js";case"iife":return".global.js"}}function K(t,n){switch(t){case"esm":return".d.mts";case"cjs":return P(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function P(t){return t==="module"}function Y(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function J(t,n){return t===void 0?n==="esm":t}function L(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function Q(t,n){return n==="cjs"?t:void 0}function Z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${I(n)}($|\\/|\\\\)`):n)}function M(t,n){return Z(t.external||[]).concat(Y(n).map((r)=>new RegExp(`^${I(r)}($|\\/|\\\\)`)))}function D(t){return Z(t.noExternal||[])}var et=x(require("node:path")),st=require("oxc-resolver");var h=x(require("node:path"));var B="\x00dts:",z=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(j(e))return e;if(!o||!j(o))return null;let s=await O(e,n,r,C(o));if(!s)return null;let i=$(s);if(t.has(i))return A(i);return null},load(e){if(e.startsWith(B)){let o=C(e),s=t.get(o);if(s)return tt.add(o),s}return null}}};function $(t){return t.replace(/\.tsx?$/,".d.ts")}function N(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,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=N(t);for(let[o,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let i=o.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${i}$`,h.default.join(e,a))}return n}function jt(t,n,r){for(let[e,o]of n){let s=new RegExp(e),i=t.match(s);if(i)return o.replace("$1",i[1]||"")}return r?h.default.join(r,t):null}async function Nt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function O(t,n,r,e){let o=t.startsWith(".")?h.default.resolve(h.default.dirname(e||""),t):jt(t,n,r);if(!o)return Promise.resolve(null);return Nt(o)}function j(t){return t.startsWith(B)}function C(t){return t.replace(B,"")}function A(t){return`${B}${t}`}var rt;function ot(t){return{name:"bunup:types-resolve",buildStart(){rt||=new st.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?C(r):void 0,/\0/.test(n))return;if(t){if(!t.some((i)=>{let a=!1;if(typeof i==="string")a=i===n||!!(r&&r.includes(i));else a=i.test(n)||!!(r&&i.test(r));return a}))return}let e=r?et.default.dirname(r):process.cwd(),{path:o}=await rt.async(e,n);if(!o)return;if(/[cm]?jsx?$/.test(o)){let s=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return o}}}async function ct(t,n,r,e,o,s){let i=$(t),a=A(i),u=M(r,e),f=D(r);try{let{output:g}=await it.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[z(n,o,s),typeof r.dts==="object"&&"resolve"in r.dts&&ot(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),at.dts()],external:(c)=>u.some((m)=>m.test(c))&&!f.some((m)=>m.test(c))});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 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:r,size:e,identifier:o,muted:s}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[f,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-f.length)),m=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${f}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let u=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let o=String(t),s=this.colors.default,i,a,u={};if(typeof r==="string")i=r,a=e;else if(r)i=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(o.includes(g)){s=c;break}let f=this.formatMessage({colorCode:s,label:o,message:n,size:i,identifier:a,muted:u.muted});this.output(f,u)}}var l=y.getInstance();var _t=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Wt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ft=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ut=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Vt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,kt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,qt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Gt(t){let n=new Set,r=[_t,Wt,Ft,Ut,Vt,kt,qt];for(let e of r){let o=t.matchAll(e);for(let s of o)if(s[1])n.add(s[1])}return n}async function ut(t,n,r){let e=new Set([t]),o=[t];while(o.length){let s=o.pop();if(!s)continue;try{let i=await Bun.file(s).text(),a=Gt(i);for(let u of a){let f=await O(u,n,r,s);if(!f)continue;if(!e.has(f))e.add(f),o.push(f)}}catch(i){l.warn(`Error processing ${s}: ${p(i)}`)}}return e}var ft=require("oxc-transform");async function lt(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=$(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:i}=ft.isolatedDeclaration(r,s);if(i)n.set(e,i)}catch(e){l.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}var _=x(require("node:fs/promises")),S=x(require("node:path")),Xt=require("oxc-transform");async function gt(t,n){let r=S.default.resolve(t),e=S.default.resolve(r,n);if(!await _.default.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(S.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function pt(t,n,r,e,o){let{absoluteEntry:s}=await gt(t,n),i=nt(e),a=N(e),u=await ut(s,i,a),f=await lt(u);return ct(s,f,r,o,i,a)}function mt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],r=new Set,e={};function o(s,i){if(r.has(s)){let a=X(),u=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${e[s]} -> ${s}.js
5
- ${o} -> ${u}.js (auto-renamed to avoid conflict)
5
+ ${i} -> ${u}.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: "${e[s]}",
11
- another_name: "${o}"
11
+ another_name: "${i}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=mt(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=mt(t);i(s,t)}return n}function dt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}var Et=x(require("node:path"));async function wt(t){let n=Et.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function bt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.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 $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:r,path:e}=await wt(n);if(r)f.cli(`Using package.json: ${b(e,2)}`,{muted:!0,once:e,identifier:t.name});let i=r?.type,s=B(t,r),o=D(t),a=[bt(s,o)],u=W(t.entry),l=X(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Vt(t,n,m,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${b(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((E)=>{if(E==="iife"&&!P(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):u;try{await Promise.all(yt.map(async(E)=>{let Rt=await pt(n,E.path,t,c,r);await Promise.all(m.map(async(Ct)=>{let Mt=K(Ct,i),I=`${n}/${t.outDir}/${E.name}${Mt}`;await Bun.write(I,Rt);let Pt=Bun.file(I).size||0;f.progress("DTS",b(I),L(Pt),t.name)}))}))}catch(E){throw new d(p(E))}}}async function Vt(t,n,r,e,i,s,o){let a=Y(e,i),u=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:dt(r.name,a)},splitting:J(t.splitting,e),bytecode:Q(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),b(l),L(g),t.name)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:i})}else n.push({name:s,path:i}),r.add(s),e[s]=i}if(Array.isArray(t))for(let s of t){let i=mt(s);o(i,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,i])=>{o(s,i)});else{let s=mt(t);o(s,t)}return n}function dt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}var Et=x(require("node:path"));async function wt(t){let n=Et.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return l.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function bt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let o=e.path;if(t.some((i)=>i.test(o))&&!n.some((i)=>i.test(o)))return{path:o,external:!0};return null})}}}var tt=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:r,path:e}=await wt(n);if(r)l.cli(`Using package.json: ${b(e,2)}`,{muted:!0,once:e,identifier:t.name});let o=r?.type,s=M(t,r),i=D(t),a=[bt(s,i)],u=W(t.entry),f=G(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Ht(t,n,m,c,o,a,f)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)l.cli(`Using tsconfig: ${b(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((E)=>{if(E==="iife"&&!P(o)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):u;try{await Promise.all(yt.map(async(E)=>{let Rt=await pt(n,E.path,t,c,r);await Promise.all(m.map(async(Ct)=>{let Bt=K(Ct,o),T=`${n}/${t.outDir}/${E.name}${Bt}`;await Bun.write(T,Rt);let Pt=Bun.file(T).size||0;l.progress("DTS",b(T),L(Pt),t.name)}))}))}catch(E){throw new d(p(E))}}}async function Ht(t,n,r,e,o,s,i){let a=H(e,o),u=await Bun.build({...i,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:dt(r.name,a)},splitting:J(t.splitting,e),bytecode:Q(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")l.warn(c.message);else if(c.level==="info")l.info(c.message)});let f=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(f).size||0;l.progress(e.toUpperCase(),b(f),L(g),t.name)}
package/build/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- function gt(t){return t}function pt(t){return t}import{build as wt}from"rolldown";import{dts as bt}from"rolldown-plugin-dts";class A extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends A{constructor(t){super(t);this.name="BunupBuildError"}}class d extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import jt from"node:path";function _(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:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function T(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function F(t,n){switch(t){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function U(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"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function E(t,n=3){return t.split("/").slice(-n).join("/")}function k(t,n){return n==="cjs"?t:void 0}function G(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${T(n)}($|\\/|\\\\)`):n)}function M(t,n){return G(t.external||[]).concat(U(n).map((r)=>new RegExp(`^${T(r)}($|\\/|\\\\)`)))}function P(t){return G(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as Et}from"oxc-resolver";import b from"node:path";var R="\x00dts:",X=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(S(e))return e;if(!i||!S(i))return null;let s=await B(e,n,r,y(i));if(!s)return null;let o=w(s);if(t.has(o))return D(o);return null},load(e){if(e.startsWith(R)){let i=y(e),s=t.get(i);if(s)return H.add(i),s}return null}}};function w(t){return t.replace(/\.tsx?$/,".d.ts")}function v(t){let n=b.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?b.resolve(n,t.data.compilerOptions.baseUrl):n}function Y(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=v(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,b.join(e,a))}return n}function dt(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?b.join(r,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function B(t,n,r,e){let i=t.startsWith(".")?b.resolve(b.dirname(e||""),t):dt(t,n,r);if(!i)return Promise.resolve(null);return xt(i)}function S(t){return t.startsWith(R)}function y(t){return t.replace(R,"")}function D(t){return`${R}${t}`}var K;function q(t){return{name:"bunup:types-resolve",buildStart(){K||=new Et({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?y(r):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(r&&r.includes(o));else a=o.test(n)||!!(r&&o.test(r));return a}))return}let e=r?ht.dirname(r):process.cwd(),{path:i}=await K.async(e,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function J(t,n,r,e,i,s){let o=w(t),a=D(o),u=M(r,e),l=P(r);try{let{output:g}=await wt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[X(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&q(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),bt()],external:(c)=>u.some((m)=>m.test(c))&&!l.some((m)=>m.test(c))});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 ${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(!$.instance)$.instance=new $;return $.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:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=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${e}\x1B[0m ${g.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,u={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:u.muted});this.output(l,u)}}var f=$.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,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Rt(o);for(let u of a){let l=await B(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${p(o)}`)}}return e}function Rt(t){let n=new Set;for(let r of[$t,yt]){let e;while((e=r.exec(t))!==null)n.add(e[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(r)=>{try{let e=w(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=Ct(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}import z from"node:fs/promises";import L from"node:path";import{isolatedDeclaration as $n}from"oxc-transform";async function tt(t,n){let r=L.resolve(t),e=L.resolve(r,n);if(!await z.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(L.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function nt(t,n,r,e,i){let{absoluteEntry:s}=await tt(t,n),o=Y(e),a=v(e),u=await Q(s,o,a),l=await Z(u);return J(s,l,r,i,o,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=N(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function gt(t){return t}function pt(t){return t}import{build as wt}from"rolldown";import{dts as bt}from"rolldown-plugin-dts";class A extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends A{constructor(t){super(t);this.name="BunupBuildError"}}class d extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import Wt from"node:fs/promises";import Ut from"node:path";function N(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:r,minifyIdentifiers:e,minifySyntax:o}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:o??s}}function S(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function F(t,n){switch(t){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function U(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 T(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function E(t,n=3){return t.split("/").slice(-n).join("/")}function k(t,n){return n==="cjs"?t:void 0}function q(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${S(n)}($|\\/|\\\\)`):n)}function B(t,n){return q(t.external||[]).concat(U(n).map((r)=>new RegExp(`^${S(r)}($|\\/|\\\\)`)))}function P(t){return q(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as Et}from"oxc-resolver";import b from"node:path";var R="\x00dts:",G=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(v(e))return e;if(!o||!v(o))return null;let s=await M(e,n,r,y(o));if(!s)return null;let i=w(s);if(t.has(i))return D(i);return null},load(e){if(e.startsWith(R)){let o=y(e),s=t.get(o);if(s)return X.add(o),s}return null}}};function w(t){return t.replace(/\.tsx?$/,".d.ts")}function I(t){let n=b.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?b.resolve(n,t.data.compilerOptions.baseUrl):n}function H(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=I(t);for(let[o,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let i=o.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${i}$`,b.join(e,a))}return n}function dt(t,n,r){for(let[e,o]of n){let s=new RegExp(e),i=t.match(s);if(i)return o.replace("$1",i[1]||"")}return r?b.join(r,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function M(t,n,r,e){let o=t.startsWith(".")?b.resolve(b.dirname(e||""),t):dt(t,n,r);if(!o)return Promise.resolve(null);return xt(o)}function v(t){return t.startsWith(R)}function y(t){return t.replace(R,"")}function D(t){return`${R}${t}`}var K;function Y(t){return{name:"bunup:types-resolve",buildStart(){K||=new Et({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?y(r):void 0,/\0/.test(n))return;if(t){if(!t.some((i)=>{let a=!1;if(typeof i==="string")a=i===n||!!(r&&r.includes(i));else a=i.test(n)||!!(r&&i.test(r));return a}))return}let e=r?ht.dirname(r):process.cwd(),{path:o}=await K.async(e,n);if(!o)return;if(/[cm]?jsx?$/.test(o)){let s=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return o}}}async function J(t,n,r,e,o,s){let i=w(t),a=D(i),u=B(r,e),f=P(r);try{let{output:g}=await wt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[G(n,o,s),typeof r.dts==="object"&&"resolve"in r.dts&&Y(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),bt()],external:(c)=>u.some((m)=>m.test(c))&&!f.some((m)=>m.test(c))});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 ${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(!$.instance)$.instance=new $;return $.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:r,size:e,identifier:o,muted:s}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[f,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-f.length)),m=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${f}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let u=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${i}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let o=String(t),s=this.colors.default,i,a,u={};if(typeof r==="string")i=r,a=e;else if(r)i=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(o.includes(g)){s=c;break}let f=this.formatMessage({colorCode:s,label:o,message:n,size:i,identifier:a,muted:u.muted});this.output(f,u)}}var l=$.getInstance();var $t=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,yt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Rt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ct=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Pt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Mt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Dt(t){let n=new Set,r=[$t,yt,Rt,Ct,Bt,Pt,Mt];for(let e of r){let o=t.matchAll(e);for(let s of o)if(s[1])n.add(s[1])}return n}async function Q(t,n,r){let e=new Set([t]),o=[t];while(o.length){let s=o.pop();if(!s)continue;try{let i=await Bun.file(s).text(),a=Dt(i);for(let u of a){let f=await M(u,n,r,s);if(!f)continue;if(!e.has(f))e.add(f),o.push(f)}}catch(i){l.warn(`Error processing ${s}: ${p(i)}`)}}return e}import{isolatedDeclaration as Ot}from"oxc-transform";async function Z(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=w(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:i}=Ot(r,s);if(i)n.set(e,i)}catch(e){l.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}import z from"node:fs/promises";import L from"node:path";import{isolatedDeclaration as Pn}from"oxc-transform";async function tt(t,n){let r=L.resolve(t),e=L.resolve(r,n);if(!await z.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(L.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function nt(t,n,r,e,o){let{absoluteEntry:s}=await tt(t,n),i=H(e),a=I(e),u=await Q(s,i,a),f=await Z(u);return J(s,f,r,o,i,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set,e={};function o(s,i){if(r.has(s)){let a=_(),u=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${e[s]} -> ${s}.js
5
- ${o} -> ${u}.js (auto-renamed to avoid conflict)
5
+ ${i} -> ${u}.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: "${e[s]}",
11
- another_name: "${o}"
11
+ another_name: "${i}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=rt(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=rt(t);i(s,t)}return n}function et(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Mt}from"load-tsconfig";function st(t){try{return Mt(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import Pt from"node:path";async function it(t){let n=Pt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function ot(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.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 Bt(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:r,path:e}=await it(n);if(r)f.cli(`Using package.json: ${E(e,2)}`,{muted:!0,once:e,identifier:t.name});let i=r?.type,s=M(t,r),o=P(t),a=[ot(s,o)],u=j(t.entry),l=_(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Dt(t,n,m,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=st(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((x)=>{if(x==="iife"&&!C(i)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?j(t.dts.entry):u;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,r);await Promise.all(m.map(async(ut)=>{let lt=F(ut,i),O=`${n}/${t.outDir}/${x.name}${lt}`;await Bun.write(O,ct);let ft=Bun.file(O).size||0;f.progress("DTS",E(O),I(ft),t.name)}))}))}catch(x){throw new d(p(x))}}}async function Dt(t,n,r,e,i,s,o){let a=W(e,i),u=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:et(r.name,a)},splitting:V(t.splitting,e),bytecode:k(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),E(l),I(g),t.name)}export{pt as defineWorkspace,gt as defineConfig,Bt as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:i})}else n.push({name:s,path:i}),r.add(s),e[s]=i}if(Array.isArray(t))for(let s of t){let i=rt(s);o(i,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,i])=>{o(s,i)});else{let s=rt(t);o(s,t)}return n}function et(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as At}from"load-tsconfig";function st(t){try{return At(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import St from"node:path";async function ot(t){let n=St.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return l.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function it(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let o=e.path;if(t.some((i)=>i.test(o))&&!n.some((i)=>i.test(o)))return{path:o,external:!0};return null})}}}var X=new Set;async function Tt(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:r,path:e}=await ot(n);if(r)l.cli(`Using package.json: ${E(e,2)}`,{muted:!0,once:e,identifier:t.name});let o=r?.type,s=B(t,r),i=P(t),a=[it(s,i)],u=j(t.entry),f=N(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return vt(t,n,m,c,o,a,f)}));if(await Promise.all(g),t.dts){let c=st(t.preferredTsconfigPath);if(c.path)l.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((x)=>{if(x==="iife"&&!C(o)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?j(t.dts.entry):u;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,r);await Promise.all(m.map(async(ut)=>{let ft=F(ut,o),O=`${n}/${t.outDir}/${x.name}${ft}`;await Bun.write(O,ct);let lt=Bun.file(O).size||0;l.progress("DTS",E(O),T(lt),t.name)}))}))}catch(x){throw new d(p(x))}}}async function vt(t,n,r,e,o,s,i){let a=W(e,o),u=await Bun.build({...i,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:et(r.name,a)},splitting:V(t.splitting,e),bytecode:k(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")l.warn(c.message);else if(c.level==="info")l.info(c.message)});let f=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(f).size||0;l.progress(e.toUpperCase(),E(f),T(g),t.name)}export{pt as defineWorkspace,gt as defineConfig,Tt as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.68",
3
+ "version": "0.3.70",
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.68"
27
+ "create-bunup": "0.3.70"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "typescript": ">=4.5.0"