bunup 0.3.81 → 0.3.86

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,16 +7,24 @@ 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.13ms ⚡️** | **19.43ms ⚡️** |
11
- | tsdown | esm, cjs | 5.89ms | 43.76ms |
12
- | unbuild | esm, cjs | 43.84ms | 322.65ms |
13
- | tsup | esm, cjs | 62.07ms | 937.35ms |
10
+ | bunup | esm, cjs | **3.14ms ⚡️** | **19.86ms ⚡️** |
11
+ | tsdown | esm, cjs | 5.60ms | 56.87ms |
12
+ | unbuild | esm, cjs | 41.19ms | 321.09ms |
13
+ | tsup | esm, cjs | 62.59ms | 937.64ms |
14
14
 
15
15
  _Lower build time is better. Benchmark run on the same code with identical output formats._
16
16
 
17
17
  To run the benchmarks yourself, clone this repo and run `pnpm benchmark` and check `results.md` in the benchmarks folder.
18
18
 
19
- ## 🚀 Quick Start
19
+ ## Key Features
20
+
21
+ - 🔄 **Tsup-Compatible CLI & Config**
22
+ - ⚡ **Ultra-Fast Builds Powered by Bun & oxc**
23
+ - 🚀 **Bytecode Generation for Lightning-Fast Startups**
24
+ - 📦 **Workspace/Monorepo Support Out of the Box**
25
+ - 🎯 **Bun-Specific Targeting**
26
+
27
+ ## Quick Start
20
28
 
21
29
  ### Installations
22
30
 
package/build/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
  import{build as Xe}from"rolldown";import{dts as Ye}from"rolldown-plugin-dts";class $ extends Error{constructor(e){super(e);this.name="BunupError"}}class y extends ${constructor(e){super(e);this.name="BunupBuildError"}}class g extends ${constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends ${constructor(e){super(e);this.name="BunupCLIError"}}class D extends ${constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},We=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",i="ERROR";if(e instanceof y)i="BUILD ERROR";else if(e instanceof g)i="DTS ERROR";else if(e instanceof d)i="CLI ERROR";else if(e instanceof D)i="WATCH ERROR";else if(e instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${n}`);let s=We.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")},J=(e,t)=>{V(e,t),process.exit(1)};import te from"node:fs/promises";import He from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function ee(e,t){return{outdir:`${t}/${e.outDir}`,minify:je(e),target:e.target,splitting:e.splitting,sourcemap:e.sourcemap,define:e.define,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer}}function je(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,s=t===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function G(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e=8){return Math.random().toString(36).substring(2,2+e)}function re(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function X(e){return Array.isArray(e)?e:[e]}function se(e,t){switch(e){case"esm":return".mjs";case"cjs":return M(t)?".cjs":".js";case"iife":return".global.js"}}function ie(e,t){switch(e){case"esm":return".d.mts";case"cjs":return M(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(e){return e==="module"}function I(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function oe(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ae(e,t){return e===void 0?t==="esm":e}function Y(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function x(e,t=3){return e.split("/").slice(-t).join("/")}async function le(e,t){let n=He.join(e,t);try{await te.rm(n,{recursive:!0,force:!0})}catch(r){throw new y(`Failed to clean output directory: ${r}`)}await te.mkdir(n,{recursive:!0})}function ce(e){return e||v.outDir}function ue(e){return e===void 0?v.clean:e}function fe(e,t){return t==="cjs"?e:void 0}function pe(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function U(e,t){return pe(e.external||[]).concat(oe(t).map((n)=>new RegExp(`^${G(n)}($|\\/|\\\\)`)))}function _(e){return pe(e.noExternal||[])}import Ve from"node:path";import{ResolverFactory as Ge}from"oxc-resolver";import O from"node:path";var T="\x00dts:",me=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(K(r))return r;if(!i||!K(i))return null;let s=await N(r,t,n,P(i));if(!s)return null;let o=R(s);if(e.has(o))return k(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=e.get(i);if(s)return C.add(i),s}return null}}};function ge(e){return e.tsconfig?.compilerOptions}function R(e){return e.replace(/\.tsx?$/,".d.ts")}function Q(e){let t=O.dirname(e.path||""),n=ge(e);return n?.baseUrl?O.resolve(t,n.baseUrl):t}function de(e){let t=new Map,n=ge(e)?.paths;if(!n)return t;let r=Q(e);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");t.set(`^${o}$`,O.join(r,a))}return t}function Fe(e,t,n){for(let[r,i]of t){let s=new RegExp(r),o=e.match(s);if(o)return i.replace("$1",o[1]||"")}return n?O.join(n,e):null}async function qe(e){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(e,t,n,r){let i=e.startsWith(".")?O.resolve(O.dirname(r||""),e):Fe(e,t,n);if(!i)return Promise.resolve(null);return qe(i)}function K(e){return e.startsWith(T)}function P(e){return e.replace(T,"")}function k(e){return`${T}${e}`}var he;function xe(e){return{name:"bunup:types-resolve",buildStart(){he||=new Ge({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?P(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let i=r?Ve.dirname(r):process.cwd(),{path:s}=await he.async(i,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function be(e,t,n,r,i,s){let o=R(e),a=k(o),l=U(n,r),u=_(n);try{let{output:p}=await Xe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;m(f)},plugins:[me(t,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&xe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ye()],external:(f)=>l.some((m)=>m.test(f))&&!u.some((m)=>m.test(f))});if(!p[0]?.code)throw new g("Generated bundle is empty");return p[0].code}catch(p){throw new g(`DTS bundling failed: ${h(p)}`)}}class B{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(!B.instance)B.instance=new B;return B.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,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${n}\x1B[0m`:n;if(r){let[u,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${m}`}let l=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${a}${l}`}output(e,t={},n=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let i=String(e),s=this.colors.default,o,a,l={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,l=n;for(let[p,f]of Object.entries(this.colors.progress))if(i.includes(p)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:l.muted});this.output(u,l)}}var c=B.getInstance();var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Qe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ze=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function nt(e){let t=new Set,n=[Ke,Qe,Ze,ze,Je,et,tt];for(let r of n){let i=e.matchAll(r);for(let s of i)if(s[1])t.add(s[1])}return t}async function ye(e,t,n){let r=new Set([e]),i=[e];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=nt(o);for(let l of a){let u=await N(l,t,n,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){c.warn(`Error processing ${s}: ${h(o)}`)}}return r}import{isolatedDeclaration as rt}from"oxc-transform";async function we(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=R(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=rt(n,s);if(o)t.set(r,o)}catch(r){c.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import Ee from"node:fs/promises";import Z from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function $e(e,t){let n=Z.resolve(e),r=Z.resolve(n,t);if(!await Ee.exists(n))throw new g(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${r}`);if(Z.relative(n,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Re(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=st(r,i);for(let o of s){if(!t)console.log(`
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")},J=(e,t)=>{V(e,t),process.exit(1)};import te from"node:fs/promises";import He from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function ee(e,t){return{outdir:`${t}/${e.outDir}`,minify:je(e),target:e.target,splitting:e.splitting,sourcemap:e.sourcemap,define:e.define,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer}}function je(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,s=t===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function G(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e=8){return Math.random().toString(36).substring(2,2+e)}function re(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function X(e){return Array.isArray(e)?e:[e]}function se(e,t){switch(e){case"esm":return".mjs";case"cjs":return M(t)?".cjs":".js";case"iife":return".global.js"}}function ie(e,t){switch(e){case"esm":return".d.mts";case"cjs":return M(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(e){return e==="module"}function I(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function oe(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ae(e,t){return e===void 0?t==="esm":e}function Y(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function x(e,t=3){return e.split("/").slice(-t).join("/")}async function le(e,t){let n=He.join(e,t);try{await te.rm(n,{recursive:!0,force:!0})}catch(r){throw new y(`Failed to clean output directory: ${r}`)}await te.mkdir(n,{recursive:!0})}function ce(e){return e||v.outDir}function ue(e){return e===void 0?v.clean:e}function fe(e,t){return t==="cjs"?e:void 0}function pe(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function U(e,t){return pe(e.external||[]).concat(oe(t).map((n)=>new RegExp(`^${G(n)}($|\\/|\\\\)`)))}function _(e){return pe(e.noExternal||[])}import Ve from"node:path";import{ResolverFactory as Ge}from"oxc-resolver";import O from"node:path";var T="\x00dts:",me=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(K(r))return r;if(!i||!K(i))return null;let s=await N(r,t,n,P(i));if(!s)return null;let o=R(s);if(e.has(o))return k(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=e.get(i);if(s)return C.add(i),s}return null}}};function ge(e){return e.tsconfig?.compilerOptions}function R(e){return e.replace(/\.tsx?$/,".d.ts")}function Q(e){let t=O.dirname(e.path||""),n=ge(e);return n?.baseUrl?O.resolve(t,n.baseUrl):t}function de(e){let t=new Map,n=ge(e)?.paths;if(!n)return t;let r=Q(e);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");t.set(`^${o}$`,O.join(r,a))}return t}function Fe(e,t,n){for(let[r,i]of t){let s=new RegExp(r),o=e.match(s);if(o)return i.replace("$1",o[1]||"")}return n?O.join(n,e):null}async function qe(e){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(e,t,n,r){let i=e.startsWith(".")?O.resolve(O.dirname(r||""),e):Fe(e,t,n);if(!i)return Promise.resolve(null);return qe(i)}function K(e){return e.startsWith(T)}function P(e){return e.replace(T,"")}function k(e){return`${T}${e}`}var he;function xe(e){return{name:"bunup:types-resolve",buildStart(){he||=new Ge({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?P(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let i=r?Ve.dirname(r):process.cwd(),{path:s}=await he.async(i,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function be(e,t,n,r,i,s){let o=R(e),a=k(o),l=U(n,r),u=_(n);try{let{output:p}=await Xe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;m(f)},plugins:[me(t,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&xe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ye({dtsInput:!0})],external:(f)=>l.some((m)=>m.test(f))&&!u.some((m)=>m.test(f))});if(!p[0]?.code)throw new g("Generated bundle is empty");return p[0].code}catch(p){throw new g(`DTS bundling failed: ${h(p)}`)}}class B{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(!B.instance)B.instance=new B;return B.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,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${n}\x1B[0m`:n;if(r){let[u,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${m}`}let l=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${a}${l}`}output(e,t={},n=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let i=String(e),s=this.colors.default,o,a,l={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,l=n;for(let[p,f]of Object.entries(this.colors.progress))if(i.includes(p)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:l.muted});this.output(u,l)}}var c=B.getInstance();var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Qe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ze=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function nt(e){let t=new Set,n=[Ke,Qe,Ze,ze,Je,et,tt];for(let r of n){let i=e.matchAll(r);for(let s of i)if(s[1])t.add(s[1])}return t}async function ye(e,t,n){let r=new Set([e]),i=[e];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=nt(o);for(let l of a){let u=await N(l,t,n,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){c.warn(`Error processing ${s}: ${h(o)}`)}}return r}import{isolatedDeclaration as rt}from"oxc-transform";async function we(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=R(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=rt(n,s);if(o)t.set(r,o)}catch(r){c.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import Ee from"node:fs/promises";import Z from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function $e(e,t){let n=Z.resolve(e),r=Z.resolve(n,t);if(!await Ee.exists(n))throw new g(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${r}`);if(Z.relative(n,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Re(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=st(r,i);for(let o of s){if(!t)console.log(`
6
6
  `);let a=o.labels[0],l=a?it(i,a.start):"",p=`${x(r)}${l}: ${ot(o.message)}`;c.warn(p),t=!0}}catch{}})),t)c.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
8
  `)}function it(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
@@ -20,7 +20,7 @@ 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:l,path:o})}else t.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(e))for(let s of e){let o=L(s);i(o,s)}else if(typeof e==="object")for(let[s,o]of Object.entries(e))i(s,o);else{let s=L(e);i(s,e)}return t}function Oe(e,t){return`[dir]/${e}${t}`}import{loadConfig as Be}from"coffi";async function ve(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:re(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Pe(e){let{config:t,filepath:n}=await Be({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Te(e,t){let{config:n,filepath:r}=await Be({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}function Le(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(e.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var C=new Set;async function W(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await Pe(t);if(n&&r)c.cli(`Using package.json: ${x(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let i=n?.type,s=U(e,n),o=_(e),a=[Le(s,o)],l=A(e.entry),u=ee(e,t),p=e.format.flatMap((f)=>l.map((m)=>{return at(e,t,m,f,i,a,u)}));if(await Promise.all(p),e.dts){let f=await Te(t,e.preferredTsconfigPath);if(f.path)c.cli(`Using tsconfig: ${x(f.path,2)}`,{muted:!0,identifier:e.name,once:`${f.path}:${e.name}`});let m=e.format.filter((E)=>{if(E==="iife"&&!M(i)&&e.format.includes("cjs"))return!1;return!0}),F=typeof e.dts==="object"&&e.dts.entry?A(e.dts.entry):l;try{await Promise.all(F.map(async(E)=>{let Ue=await Ce(t,E.path,e,f,n);await Promise.all(m.map(async(_e)=>{let Ne=ie(_e,i),q=`${t}/${e.outDir}/${E.name}${Ne}`;await Bun.write(q,Ue);let ke=Bun.file(q).size||0;c.progress("DTS",x(q),Y(ke),e.name)}))}))}catch(E){throw new g(h(E))}}}async function at(e,t,n,r,i,s,o){let a=se(r,i),l=await Bun.build({...o,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Oe(n.name,a)},splitting:ae(e.splitting,r),bytecode:fe(e.bytecode,r),plugins:s,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new y(f.message);if(f.level==="warning")c.warn(f.message);else if(f.level==="info")c.info(f.message)}let u=`${t}/${e.outDir}/${n.name}${a}`,p=Bun.file(u).size||0;c.progress(r.toUpperCase(),x(u),Y(p),e.name)}var j="0.3.81";var Ae="https://bun.sh/docs/installation",Se="https://bunup.arshadyaseen.com/#cli-options";function b(e){return(t,n)=>{n[e]=t===!0?!0:t==="true"}}function w(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new d(`Option --${e} requires a string value`)}}function De(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function ct(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:l,path:o})}else t.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(e))for(let s of e){let o=L(s);i(o,s)}else if(typeof e==="object")for(let[s,o]of Object.entries(e))i(s,o);else{let s=L(e);i(s,e)}return t}function Oe(e,t){return`[dir]/${e}${t}`}import{loadConfig as Be}from"coffi";async function ve(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:re(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Pe(e){let{config:t,filepath:n}=await Be({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Te(e,t){let{config:n,filepath:r}=await Be({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}function Le(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(e.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var C=new Set;async function W(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await Pe(t);if(n&&r)c.cli(`Using package.json: ${x(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let i=n?.type,s=U(e,n),o=_(e),a=[Le(s,o)],l=A(e.entry),u=ee(e,t),p=e.format.flatMap((f)=>l.map((m)=>{return at(e,t,m,f,i,a,u)}));if(await Promise.all(p),e.dts){let f=await Te(t,e.preferredTsconfigPath);if(f.path)c.cli(`Using tsconfig: ${x(f.path,2)}`,{muted:!0,identifier:e.name,once:`${f.path}:${e.name}`});let m=e.format.filter((E)=>{if(E==="iife"&&!M(i)&&e.format.includes("cjs"))return!1;return!0}),F=typeof e.dts==="object"&&e.dts.entry?A(e.dts.entry):l;try{await Promise.all(F.map(async(E)=>{let Ue=await Ce(t,E.path,e,f,n);await Promise.all(m.map(async(_e)=>{let Ne=ie(_e,i),q=`${t}/${e.outDir}/${E.name}${Ne}`;await Bun.write(q,Ue);let ke=Bun.file(q).size||0;c.progress("DTS",x(q),Y(ke),e.name)}))}))}catch(E){throw new g(h(E))}}}async function at(e,t,n,r,i,s,o){let a=se(r,i),l=await Bun.build({...o,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Oe(n.name,a)},splitting:ae(e.splitting,r),bytecode:fe(e.bytecode,r),plugins:s,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new y(f.message);if(f.level==="warning")c.warn(f.message);else if(f.level==="info")c.info(f.message)}let u=`${t}/${e.outDir}/${n.name}${a}`,p=Bun.file(u).size||0;c.progress(r.toUpperCase(),x(u),Y(p),e.name)}var j="0.3.86";var Ae="https://bun.sh/docs/installation",Se="https://bunup.arshadyaseen.com/#cli-options";function b(e){return(t,n)=>{n[e]=t===!0?!0:t==="true"}}function w(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new d(`Option --${e} requires a string value`)}}function De(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function ct(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
25
  `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Se}\x1B[0m
26
26
  `),process.exit(0)}function ut(){console.log(j),process.exit(0)}var ft={name:{flags:["n","name"],handler:w("name")},format:{flags:["f","format"],handler:(e,t)=>{if(typeof e==="string")t.format=e.split(",");else throw new d("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:w("outDir")},minify:{flags:["m","minify"],handler:b("minify")},watch:{flags:["w","watch"],handler:b("watch")},dts:{flags:["d","dts"],handler:b("dts")},banner:{flags:["b","banner"],handler:w("banner")},footer:{flags:["f","footer"],handler:w("footer")},external:{flags:["e","external"],handler:De("external")},sourcemap:{flags:["sm","sourcemap"],handler:w("sourcemap")},target:{flags:["t","target"],handler:w("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:b("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:b("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:b("minifySyntax")},clean:{flags:["c","clean"],handler:b("clean")},splitting:{flags:["s","splitting"],handler:b("splitting")},noExternal:{flags:["ne","no-external"],handler:De("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:b("bytecode")}},pt={resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}}},mt={help:{flags:["h","help"],handler:()=>ct()},version:{flags:["v","version"],handler:()=>ut()}},S={};for(let e of Object.values(ft))if(e)for(let t of e.flags)S[t]=e.handler;for(let e of Object.values(pt))for(let t of e.flags)S[t]=e.handler;for(let e of Object.values(mt))for(let t of e.flags)S[t]=e.handler;function Me(e){let t={},n={},r=0;while(r<e.length){let i=e[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,l]=i.slice(2).split("=",2);s=a,o=l}else{s=i.slice(2);let a=e[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=L(o);if(n[a])c.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);n[a]=o}else throw new d("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(n[a])c.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=o}else throw new d(`Option --entry.${a} requires a string value`)}else{let a=S[s];if(a)a(o,t);else throw new d(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=e[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let l=S[s];if(l)l(a,t);else throw new d(`Unknown option: -${s}`)}else{let s=L(i);if(n[s])c.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);n[s]=i}r++}if(Object.keys(n).length>0)t.entry=n;return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var St=require("node:module");var Mt=Object.create;var{getPrototypeOf:Bt,defineProperty:y,getOwnPropertyNames:j,getOwnPropertyDescriptor:Tt}=Object,q=Object.prototype.hasOwnProperty;var E=(t,e,n)=>{n=t!=null?Mt(Bt(t)):{};let r=e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n;for(let i of j(t))if(!q.call(r,i))y(r,i,{get:()=>t[i],enumerable:!0});return r},F=new WeakMap,Lt=(t)=>{var e=F.get(t),n;if(e)return e;if(e=y({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((r)=>!q.call(e,r)&&y(e,r,{get:()=>t[r],enumerable:!(n=Tt(t,r))||n.enumerable}));return F.set(t,e),e};var At=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Kt={};At(Kt,{defineWorkspace:()=>X,defineConfig:()=>G,build:()=>Rt});module.exports=Lt(Kt);function G(t){return t}function X(t){return t}var ct=require("rolldown"),ut=require("rolldown-plugin-dts");class I extends Error{constructor(t){super(t);this.name="BunupError"}}class $ extends I{constructor(t){super(t);this.name="BunupBuildError"}}class p extends I{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};var Ot=E(require("node:fs/promises")),Wt=E(require("node:path"));function H(t,e){return{outdir:`${e}/${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:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,s=e===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){return Math.random().toString(36).substring(2,2+t)}function K(t,e){switch(t){case"esm":return".mjs";case"cjs":return D(e)?".cjs":".js";case"iife":return".global.js"}}function Y(t,e){switch(t){case"esm":return".d.mts";case"cjs":return D(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(t){return t==="module"}function Q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Z(t,e){return t===void 0?e==="esm":t}function W(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/1024**n).toFixed(2)} ${e[n]}`}function b(t,e=3){return t.split("/").slice(-e).join("/")}function z(t,e){return e==="cjs"?t:void 0}function J(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function M(t,e){return J(t.external||[]).concat(Q(e).map((n)=>new RegExp(`^${O(n)}($|\\/|\\\\)`)))}function B(t){return J(t.noExternal||[])}var it=E(require("node:path")),ot=require("oxc-resolver");var x=E(require("node:path"));var P="\x00dts:",tt=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(_(r))return r;if(!i||!_(i))return null;let s=await T(r,e,n,C(i));if(!s)return null;let o=w(s);if(t.has(o))return L(o);return null},load(r){if(r.startsWith(P)){let i=C(r),s=t.get(i);if(s)return et.add(i),s}return null}}};function nt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function N(t){let e=x.default.dirname(t.path||""),n=nt(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function rt(t){let e=new Map,n=nt(t)?.paths;if(!n)return e;let r=N(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}$`,x.default.join(r,a))}return e}function _t(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?x.default.join(n,t):null}async function Nt(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 T(t,e,n,r){let i=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):_t(t,e,n);if(!i)return Promise.resolve(null);return Nt(i)}function _(t){return t.startsWith(P)}function C(t){return t.replace(P,"")}function L(t){return`${P}${t}`}var st;function at(t){return{name:"bunup:types-resolve",buildStart(){st||=new ot.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?C(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let i=r?it.default.dirname(r):process.cwd(),{path:s}=await st.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function lt(t,e,n,r,i,s){let o=w(t),a=L(o),c=M(n,r),l=B(n);try{let{output:f}=await ct.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[tt(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&at(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ut.dts()],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!f[0]?.code)throw new p("Generated bundle is empty");return f[0].code}catch(f){throw new p(`DTS bundling failed: ${d(f)}`)}}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: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[l,...f]=a.split(" "),u=" ".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${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}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[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var g=R.getInstance();var Ut=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Xt(t){let e=new Set,n=[Ut,vt,Vt,Ft,jt,qt,Gt];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 gt(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=Xt(o);for(let c of a){let l=await T(c,e,n,s);if(!l)continue;if(!r.has(l))r.add(l),i.push(l)}}catch(o){g.warn(`Error processing ${s}: ${d(o)}`)}}return r}var ft=require("oxc-transform");async function mt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=w(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=ft.isolatedDeclaration(n,s);if(o)e.set(r,o)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}var U=E(require("node:fs/promises")),A=E(require("node:path")),Ht=require("oxc-transform");async function pt(t,e){let n=A.default.resolve(t),r=A.default.resolve(n,e);if(!await U.default.exists(n))throw new p(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new p(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${r}`);if(A.default.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function dt(t,e,n,r,i){let{absoluteEntry:s}=await pt(t,e),o=rt(r),a=N(r),c=await gt(s,o,a),l=await mt(c);return lt(s,l,n,i,o,a)}function xt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=k(),c=`${s}_${a}`;g.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ var St=require("node:module");var Mt=Object.create;var{getPrototypeOf:Bt,defineProperty:y,getOwnPropertyNames:j,getOwnPropertyDescriptor:Tt}=Object,q=Object.prototype.hasOwnProperty;var E=(t,e,n)=>{n=t!=null?Mt(Bt(t)):{};let r=e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n;for(let i of j(t))if(!q.call(r,i))y(r,i,{get:()=>t[i],enumerable:!0});return r},F=new WeakMap,Lt=(t)=>{var e=F.get(t),n;if(e)return e;if(e=y({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((r)=>!q.call(e,r)&&y(e,r,{get:()=>t[r],enumerable:!(n=Tt(t,r))||n.enumerable}));return F.set(t,e),e};var At=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Kt={};At(Kt,{defineWorkspace:()=>X,defineConfig:()=>G,build:()=>Rt});module.exports=Lt(Kt);function G(t){return t}function X(t){return t}var ct=require("rolldown"),ut=require("rolldown-plugin-dts");class I extends Error{constructor(t){super(t);this.name="BunupError"}}class $ extends I{constructor(t){super(t);this.name="BunupBuildError"}}class p extends I{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};var Ot=E(require("node:fs/promises")),Wt=E(require("node:path"));function H(t,e){return{outdir:`${e}/${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:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,s=e===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){return Math.random().toString(36).substring(2,2+t)}function K(t,e){switch(t){case"esm":return".mjs";case"cjs":return D(e)?".cjs":".js";case"iife":return".global.js"}}function Y(t,e){switch(t){case"esm":return".d.mts";case"cjs":return D(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(t){return t==="module"}function Q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Z(t,e){return t===void 0?e==="esm":t}function W(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/1024**n).toFixed(2)} ${e[n]}`}function b(t,e=3){return t.split("/").slice(-e).join("/")}function z(t,e){return e==="cjs"?t:void 0}function J(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function M(t,e){return J(t.external||[]).concat(Q(e).map((n)=>new RegExp(`^${O(n)}($|\\/|\\\\)`)))}function B(t){return J(t.noExternal||[])}var it=E(require("node:path")),ot=require("oxc-resolver");var x=E(require("node:path"));var P="\x00dts:",tt=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(_(r))return r;if(!i||!_(i))return null;let s=await T(r,e,n,C(i));if(!s)return null;let o=w(s);if(t.has(o))return L(o);return null},load(r){if(r.startsWith(P)){let i=C(r),s=t.get(i);if(s)return et.add(i),s}return null}}};function nt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function N(t){let e=x.default.dirname(t.path||""),n=nt(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function rt(t){let e=new Map,n=nt(t)?.paths;if(!n)return e;let r=N(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}$`,x.default.join(r,a))}return e}function _t(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?x.default.join(n,t):null}async function Nt(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 T(t,e,n,r){let i=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):_t(t,e,n);if(!i)return Promise.resolve(null);return Nt(i)}function _(t){return t.startsWith(P)}function C(t){return t.replace(P,"")}function L(t){return`${P}${t}`}var st;function at(t){return{name:"bunup:types-resolve",buildStart(){st||=new ot.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?C(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let i=r?it.default.dirname(r):process.cwd(),{path:s}=await st.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function lt(t,e,n,r,i,s){let o=w(t),a=L(o),c=M(n,r),l=B(n);try{let{output:f}=await ct.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[tt(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&at(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ut.dts({dtsInput:!0})],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!f[0]?.code)throw new p("Generated bundle is empty");return f[0].code}catch(f){throw new p(`DTS bundling failed: ${d(f)}`)}}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: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[l,...f]=a.split(" "),u=" ".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${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}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[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var g=R.getInstance();var Ut=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Xt(t){let e=new Set,n=[Ut,vt,Vt,Ft,jt,qt,Gt];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 gt(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=Xt(o);for(let c of a){let l=await T(c,e,n,s);if(!l)continue;if(!r.has(l))r.add(l),i.push(l)}}catch(o){g.warn(`Error processing ${s}: ${d(o)}`)}}return r}var ft=require("oxc-transform");async function mt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=w(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=ft.isolatedDeclaration(n,s);if(o)e.set(r,o)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}var U=E(require("node:fs/promises")),A=E(require("node:path")),Ht=require("oxc-transform");async function pt(t,e){let n=A.default.resolve(t),r=A.default.resolve(n,e);if(!await U.default.exists(n))throw new p(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new p(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${r}`);if(A.default.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function dt(t,e,n,r,i){let{absoluteEntry:s}=await pt(t,e),o=rt(r),a=N(r),c=await gt(s,o,a),l=await mt(c);return lt(s,l,n,i,o,a)}function xt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=k(),c=`${s}_${a}`;g.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
  ${r[s]} -> ${s}.js
package/build/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- function pt(t){return t}function dt(t){return t}import{build as Rt}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class L extends Error{constructor(t){super(t);this.name="BunupError"}}class R extends L{constructor(t){super(t);this.name="BunupBuildError"}}class p extends L{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import Ft from"node:path";function N(t,e){return{outdir:`${e}/${t.outDir}`,minify:xt(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 xt(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 A(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(t=8){return Math.random().toString(36).substring(2,2+t)}function v(t,e){switch(t){case"esm":return".mjs";case"cjs":return C(e)?".cjs":".js";case"iife":return".global.js"}}function V(t,e){switch(t){case"esm":return".d.mts";case"cjs":return C(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function F(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function j(t,e){return t===void 0?e==="esm":t}function S(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/1024**n).toFixed(2)} ${e[n]}`}function h(t,e=3){return t.split("/").slice(-e).join("/")}function q(t,e){return e==="cjs"?t:void 0}function G(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${A(e)}($|\\/|\\\\)`):e)}function P(t,e){return G(t.external||[]).concat(F(e).map((n)=>new RegExp(`^${A(n)}($|\\/|\\\\)`)))}function D(t){return G(t.noExternal||[])}import bt from"node:path";import{ResolverFactory as wt}from"oxc-resolver";import b from"node:path";var $="\x00dts:",X=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(I(r))return r;if(!i||!I(i))return null;let s=await M(r,e,n,y(i));if(!s)return null;let o=E(s);if(t.has(o))return B(o);return null},load(r){if(r.startsWith($)){let i=y(r),s=t.get(i);if(s)return H.add(i),s}return null}}};function k(t){return t.tsconfig?.compilerOptions}function E(t){return t.replace(/\.tsx?$/,".d.ts")}function O(t){let e=b.dirname(t.path||""),n=k(t);return n?.baseUrl?b.resolve(e,n.baseUrl):e}function K(t){let e=new Map,n=k(t)?.paths;if(!n)return e;let r=O(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 ht(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 Et(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 M(t,e,n,r){let i=t.startsWith(".")?b.resolve(b.dirname(r||""),t):ht(t,e,n);if(!i)return Promise.resolve(null);return Et(i)}function I(t){return t.startsWith($)}function y(t){return t.replace($,"")}function B(t){return`${$}${t}`}var Y;function Q(t){return{name:"bunup:types-resolve",buildStart(){Y||=new wt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?y(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let i=r?bt.dirname(r):process.cwd(),{path:s}=await Y.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function Z(t,e,n,r,i,s){let o=E(t),a=B(o),c=P(n,r),l=D(n);try{let{output:f}=await Rt({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[X(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&Q(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),yt()],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!f[0]?.code)throw new p("Generated bundle is empty");return f[0].code}catch(f){throw new p(`DTS bundling failed: ${d(f)}`)}}class w{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(!w.instance)w.instance=new w;return w.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[l,...f]=a.split(" "),u=" ".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${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}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[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var g=w.getInstance();var $t=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ct=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Pt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Dt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Lt(t){let e=new Set,n=[$t,Ct,Pt,Dt,Mt,Bt,Tt];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 z(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=Lt(o);for(let c of a){let l=await M(c,e,n,s);if(!l)continue;if(!r.has(l))r.add(l),i.push(l)}}catch(o){g.warn(`Error processing ${s}: ${d(o)}`)}}return r}import{isolatedDeclaration as At}from"oxc-transform";async function J(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=E(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=At(n,s);if(o)e.set(r,o)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}import tt from"node:fs/promises";import W from"node:path";import{isolatedDeclaration as Ce}from"oxc-transform";async function et(t,e){let n=W.resolve(t),r=W.resolve(n,e);if(!await tt.exists(n))throw new p(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new p(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${r}`);if(W.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function nt(t,e,n,r,i){let{absoluteEntry:s}=await et(t,e),o=K(r),a=O(r),c=await z(s,o,a),l=await J(c);return Z(s,l,n,i,o,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function _(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=U(),c=`${s}_${a}`;g.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function pt(t){return t}function dt(t){return t}import{build as Rt}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class L extends Error{constructor(t){super(t);this.name="BunupError"}}class R extends L{constructor(t){super(t);this.name="BunupBuildError"}}class p extends L{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import Ft from"node:path";function N(t,e){return{outdir:`${e}/${t.outDir}`,minify:xt(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 xt(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 A(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(t=8){return Math.random().toString(36).substring(2,2+t)}function v(t,e){switch(t){case"esm":return".mjs";case"cjs":return C(e)?".cjs":".js";case"iife":return".global.js"}}function V(t,e){switch(t){case"esm":return".d.mts";case"cjs":return C(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function F(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function j(t,e){return t===void 0?e==="esm":t}function S(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/1024**n).toFixed(2)} ${e[n]}`}function h(t,e=3){return t.split("/").slice(-e).join("/")}function q(t,e){return e==="cjs"?t:void 0}function G(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${A(e)}($|\\/|\\\\)`):e)}function P(t,e){return G(t.external||[]).concat(F(e).map((n)=>new RegExp(`^${A(n)}($|\\/|\\\\)`)))}function D(t){return G(t.noExternal||[])}import bt from"node:path";import{ResolverFactory as wt}from"oxc-resolver";import b from"node:path";var $="\x00dts:",X=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(I(r))return r;if(!i||!I(i))return null;let s=await M(r,e,n,y(i));if(!s)return null;let o=E(s);if(t.has(o))return B(o);return null},load(r){if(r.startsWith($)){let i=y(r),s=t.get(i);if(s)return H.add(i),s}return null}}};function k(t){return t.tsconfig?.compilerOptions}function E(t){return t.replace(/\.tsx?$/,".d.ts")}function O(t){let e=b.dirname(t.path||""),n=k(t);return n?.baseUrl?b.resolve(e,n.baseUrl):e}function K(t){let e=new Map,n=k(t)?.paths;if(!n)return e;let r=O(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 ht(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 Et(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 M(t,e,n,r){let i=t.startsWith(".")?b.resolve(b.dirname(r||""),t):ht(t,e,n);if(!i)return Promise.resolve(null);return Et(i)}function I(t){return t.startsWith($)}function y(t){return t.replace($,"")}function B(t){return`${$}${t}`}var Y;function Q(t){return{name:"bunup:types-resolve",buildStart(){Y||=new wt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?y(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let i=r?bt.dirname(r):process.cwd(),{path:s}=await Y.async(i,e);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function Z(t,e,n,r,i,s){let o=E(t),a=B(o),c=P(n,r),l=D(n);try{let{output:f}=await Rt({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[X(e,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&Q(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),yt({dtsInput:!0})],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!f[0]?.code)throw new p("Generated bundle is empty");return f[0].code}catch(f){throw new p(`DTS bundling failed: ${d(f)}`)}}class w{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(!w.instance)w.instance=new w;return w.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[l,...f]=a.split(" "),u=" ".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${e}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}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[f,u]of Object.entries(this.colors.progress))if(i.includes(f)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:e,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var g=w.getInstance();var $t=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ct=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Pt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Dt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Lt(t){let e=new Set,n=[$t,Ct,Pt,Dt,Mt,Bt,Tt];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 z(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=Lt(o);for(let c of a){let l=await M(c,e,n,s);if(!l)continue;if(!r.has(l))r.add(l),i.push(l)}}catch(o){g.warn(`Error processing ${s}: ${d(o)}`)}}return r}import{isolatedDeclaration as At}from"oxc-transform";async function J(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=E(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=At(n,s);if(o)e.set(r,o)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${d(r)}`)}})),e}import tt from"node:fs/promises";import W from"node:path";import{isolatedDeclaration as Ce}from"oxc-transform";async function et(t,e){let n=W.resolve(t),r=W.resolve(n,e);if(!await tt.exists(n))throw new p(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new p(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${r}`);if(W.relative(n,r).startsWith(".."))throw new p(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function nt(t,e,n,r,i){let{absoluteEntry:s}=await et(t,e),o=K(r),a=O(r),c=await z(s,o,a),l=await J(c);return Z(s,l,n,i,o,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function _(t){let e=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=U(),c=`${s}_${a}`;g.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
  ${r[s]} -> ${s}.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.81",
3
+ "version": "0.3.86",
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",
@@ -21,7 +21,7 @@
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
23
  "vitest": "^2.1.9",
24
- "create-bunup": "0.3.81"
24
+ "create-bunup": "0.3.86"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "typescript": ">=4.5.0"
@@ -56,7 +56,7 @@
56
56
  "oxc-resolver": "^5.0.1",
57
57
  "oxc-transform": "^0.58.1",
58
58
  "rolldown": "1.0.0-beta.7",
59
- "rolldown-plugin-dts": "^0.1.0"
59
+ "rolldown-plugin-dts": "^0.4.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "bunup",