bunup 0.4.18 → 0.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/cli.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{build as Qe}from"rolldown";import{dts as Ze}from"rolldown-plugin-dts";var ne=!1;function L(e){ne=e??!1}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(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:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...f]=a.split(" "),m=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${c}${m} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${p}`}let l=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${l}`}output(e,t={},n=console.log){if(ne)return;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 s=String(e),o=this.colors.default,i,a,l={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,l=n;for(let[f,m]of Object.entries(this.colors.progress))if(s.includes(f)){o=m;break}let c=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:l.muted});this.output(c,l)}}var u=C.getInstance();class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class h extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends E{constructor(e){super(e);this.name="BunupCLIError"}}class D extends E{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ve=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{u.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],G=(e,t)=>{let n=b(e),r=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof h)s="DTS ERROR";else if(e instanceof d)s="CLI ERROR";else if(e instanceof D)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";let o=Ve.find((i)=>i.pattern.test(n)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${r}${n}`);if(o)console.log(`
3
+ import{build as Ge}from"rolldown";import{dts as Xe}from"rolldown-plugin-dts";var ee=!1;function P(e){ee=e??!1}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(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:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...f]=a.split(" "),m=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${c}${m} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${p}`}let l=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${l}`}output(e,t={},n=console.log){if(ee)return;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 s=String(e),o=this.colors.default,i,a,l={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,l=n;for(let[f,m]of Object.entries(this.colors.progress))if(s.includes(f)){o=m;break}let c=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:l.muted});this.output(c,l)}}var u=C.getInstance();class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class h extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends E{constructor(e){super(e);this.name="BunupCLIError"}}class L extends E{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},Fe=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{u.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],q=(e,t)=>{let n=b(e),r=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof h)s="DTS ERROR";else if(e instanceof d)s="CLI ERROR";else if(e instanceof L)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";let o=Fe.find((i)=>i.pattern.test(n)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${r}${n}`);if(o)console.log(`
4
4
  `),o.logSolution(n),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")},re=(e,t)=>{G(e,t),process.exit(1)};import se from"node:fs/promises";import Ge from"node:path";function X(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ie(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function oe(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function ae(e){return Array.isArray(e)?e:[e]}function le(e,t){switch(e){case"esm":return $(t)?".js":".mjs";case"cjs":return $(t)?".cjs":".js";case"iife":return".global.js"}}function ce(e,t){switch(e){case"esm":return $(t)?".d.ts":".d.mts";case"cjs":return $(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function Y(e){return e==="node"||e==="bun"}function $(e){return e==="module"}function A(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function ue(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function K(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 fe(e,t){let n=Ge.join(e,t);try{await se.rm(n,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await se.mkdir(n,{recursive:!0})}function I(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function pe(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${X(t)}($|\\/|\\\\)`):t)}function M(e,t){return pe(e.external||[]).concat(ue(t).map((n)=>new RegExp(`^${X(n)}($|\\/|\\\\)`)))}function _(e){return pe(e.noExternal||[])}import Je from"node:path";import{ResolverFactory as ze}from"oxc-resolver";import O from"node:path";var S="\x00dts:",me=(e,t)=>{return{name:"bunup:virtual-dts",async resolveId(n,r){if(J(n))return n;if(!r||!J(r))return null;let s=await v(n,P(r),t);if(!s)return null;let o=T(s);if(e.has(o))return j(o);return null},load(n){if(n.startsWith(S)){let r=P(n),s=e.get(r);if(s)return R.add(r),s}return null}}};function de(e){return e.tsconfig?.compilerOptions}function T(e){return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function ge(e){if(!e.path)return"";let t=O.dirname(e.path),n=de(e);return n?.baseUrl?O.resolve(t,n.baseUrl):t}function Xe(e){let t=new Map,n=de(e)?.paths;if(!n)return t;let r=ge(e);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=0,l=o[0].replace(/\*/g,()=>`$${++a}`);t.set(`^${i}$`,O.join(r,l))}return t}function Ye(e,t,n){for(let[r,s]of t){let o=new RegExp(r),i=e.match(o);if(i)return s.replace("$1",i[1]||"")}return n?O.join(n,e):null}async function Ke(e){let t=["",".ts",".tsx",".cts",".mts","/index.ts","/index.tsx","/index.cts","/index.mts"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")||r.endsWith(".cts")||r.endsWith(".mts")))return r}return null}function v(e,t,n){if(!n)return Promise.resolve(null);let r=Xe(n),s=ge(n),o=e.startsWith(".")?O.resolve(O.dirname(t||""),e):Ye(e,r,s);if(!o)return Promise.resolve(null);return Ke(o)}function J(e){return e.startsWith(S)}function P(e){return e.replace(S,"")}function j(e){return`${S}${e}`}var he;function be(e){return{name:"bunup:types-resolve",buildStart(){he||=new ze({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],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 s=r?Je.dirname(r):process.cwd(),{path:o}=await he.async(s,t);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function xe(e,t,n,r,s){let o=T(e),i=j(o),a=M(n,r),l=_(n);try{let{output:c}=await Qe({input:i,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,s),typeof n.dts==="object"&&"resolve"in n.dts&&be(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ze({dtsInput:!0,emitDtsOnly:!0})],external:(f)=>a.some((m)=>m.test(f))&&!l.some((m)=>m.test(f))});if(!c[0]?.code)return u.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return c[0].code}catch(c){throw new h(`DTS bundling failed for entry "${e}": ${b(c)}`)}}var et=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,tt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,nt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,rt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,st=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,it=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ot=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function at(e){let t=new Set,n=[et,tt,nt,rt,st,it,ot];for(let r of n){let s=e.matchAll(r);for(let o of s)if(o[1])t.add(o[1])}return t}async function ye(e,t){let n=new Set([e]),r=[e];while(r.length){let s=r.pop();if(!s)continue;try{let o=await Bun.file(s).text(),i=at(o);for(let a of i){let l=await v(a,s,t);if(!l)continue;if(!n.has(l))n.add(l),r.push(l)}}catch(o){u.warn(`Error processing ${s}: ${b(o)}`)}}return n}import{isolatedDeclaration as lt}from"oxc-transform";async function we(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=T(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=lt(n,o);if(i)t.set(r,i)}catch(r){u.warn(`Failed to generate declaration for ${n}: ${b(r)}`)}})),t}import Ce from"node:fs/promises";import z from"node:path";import{isolatedDeclaration as ct}from"oxc-transform";async function Ee(e,t){let n=z.resolve(e),r=z.resolve(n,t);if(!await Ce.exists(n))throw new h(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new h(`Entry file does not exist: ${r}`);if(!I(r))throw new h(`Entry file must be a TypeScript file: ${r}`);if(z.relative(n,r).startsWith(".."))throw new h(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function $e(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:o}=ct(r,s);for(let i of o){if(!t)console.log(`
6
- `);let a=i.labels[0],l=a?ut(s,a.start):"",f=`${x(r)}${l}: ${ft(i.message)}`;u.warn(f),t=!0}}catch{}})),t)u.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")},te=(e,t)=>{q(e,t),process.exit(1)};import ne from"node:fs/promises";import We from"node:path";function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function re(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function se(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function ie(e){return Array.isArray(e)?e:[e]}function oe(e,t){switch(e){case"esm":return $(t)?".js":".mjs";case"cjs":return $(t)?".cjs":".js";case"iife":return".global.js"}}function ae(e,t){switch(e){case"esm":return $(t)?".d.ts":".d.mts";case"cjs":return $(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function G(e){return e==="node"||e==="bun"}function $(e){return e==="module"}function D(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function le(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function X(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 ce(e,t){let n=We.join(e,t);try{await ne.rm(n,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await ne.mkdir(n,{recursive:!0})}function A(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function ue(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${V(t)}($|\\/|\\\\)`):t)}function I(e,t){return ue(e.external||[]).concat(le(t).map((n)=>new RegExp(`^${V(n)}($|\\/|\\\\)`)))}function M(e){return ue(e.noExternal||[])}import qe from"node:path";import{ResolverFactory as Ve}from"oxc-resolver";import{resolveTypeScriptImportPath as He}from"ts-import-resolver";var O="\x00dts:",fe=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(Y(r))return r;if(!s||!Y(s))return null;let o=He({path:r,importer:R(s),tsconfig:t.tsconfig,rootDir:n});if(!o)return null;let i=T(o);if(e.has(i))return _(i);return null},load(r){if(r.startsWith(O)){let s=R(r),o=e.get(s);if(o)return S.add(s),o}return null}}};function T(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function Y(e){return e.startsWith(O)}function R(e){return e.replace(O,"")}function _(e){return`${O}${e}`}var pe;function me(e){return{name:"bunup:types-resolve",buildStart(){pe||=new Ve({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?R(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 s=r?qe.dirname(r):process.cwd(),{path:o}=await pe.async(s,t);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function de(e,t,n,r,s,o){let i=T(e),a=_(i),l=I(n,r),c=M(n);try{let{output:f}=await Ge({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(m,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;p(m)},plugins:[fe(t,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&me(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Xe({dtsInput:!0,emitDtsOnly:!0})],external:(m)=>l.some((p)=>p.test(m))&&!c.some((p)=>p.test(m))});if(!f[0]?.code)return u.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new h(`DTS bundling failed for entry "${e}": ${b(f)}`)}}import{resolveTypeScriptImportPath as Ye}from"ts-import-resolver";var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Je=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qe=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/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,Je,ze,Qe,Ze,et,tt];for(let r of n){let s=e.matchAll(r);for(let o of s)if(o[1])t.add(o[1])}return t}async function ge(e,t,n){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=nt(i);for(let l of a){let c=Ye({path:l,importer:o,tsconfig:t.tsconfig,rootDir:n});if(!c)continue;if(!r.has(c))r.add(c),s.push(c)}}catch(i){u.warn(`Error processing ${o}: ${b(i)}`)}}return r}import{isolatedDeclaration as rt}from"oxc-transform";async function he(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=T(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=rt(n,o);if(i)t.set(r,i)}catch(r){u.warn(`Failed to generate declaration for ${n}: ${b(r)}`)}})),t}import be from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function xe(e,t){let n=K.resolve(e),r=K.resolve(n,t);if(!await be.exists(n))throw new h(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new h(`Entry file does not exist: ${r}`);if(!A(r))throw new h(`Entry file must be a TypeScript file: ${r}`);if(K.relative(n,r).startsWith(".."))throw new h(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function ye(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:o}=st(r,s);for(let i of o){if(!t)console.log(`
6
+ `);let a=i.labels[0],l=a?it(s,a.start):"",f=`${x(r)}${l}: ${ot(i.message)}`;u.warn(f),t=!0}}catch{}})),t)u.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 ut(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
9
- `),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function ft(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,t,n,r,s){let{absoluteEntry:o}=await Ee(e,t),i=await ye(o,r),a=await we(i);return xe(o,a,n,s,r)}function U(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function B(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let l=ie(),c=`${i}_${l}`;if(t)u.warn(`Output name conflict: "${i}" is used by multiple files.
8
+ `)}function it(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
9
+ `),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function ot(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function we(e,t,n,r,s){let{absoluteEntry:o}=await xe(e,t),i=await ge(o,r,e),a=await he(i);return de(o,a,n,s,r,e)}function j(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function B(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let l=re(),c=`${i}_${l}`;if(t)u.warn(`Output name conflict: "${i}" is used by multiple files.
10
10
  Bunup uses filenames without extensions as output names by default.
11
11
 
12
12
  ${s[i]} -> ${i}.js
@@ -20,19 +20,19 @@ 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});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=U(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=U(e);o(i,e)}return n}function Re(e){return e.filter((t)=>I(t.path))}function Oe(e,t){return`[dir]/${e}${t}`}import{loadConfig as Pe}from"coffi";async function Se(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:oe(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Be(e){let{config:t,filepath:n}=await Pe({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Le(e,t){let{config:n,filepath:r}=await Pe({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var pt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function k(e){return{...pt,...e}}function De(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Ae(e,t){return t==="cjs"?e:void 0}function Ie(e,t,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((s,o)=>{let i=JSON.stringify(n[o]);return s[`process.env.${o}`]=i,s[`import.meta.env.${o}`]=i,s},{}),...e,...r==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Me(e,t){return e===void 0?t==="esm":e}function _e(e){return typeof e==="string"?e:void 0}function ve(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var mt=/\.(js|ts|jsx|tsx|mts|cts)$/,Q={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&Y(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=j(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=j(e);o(i,e)}return n}function Ce(e){return e.filter((t)=>A(t.path))}function Ee(e,t){return`[dir]/${e}${t}`}import{loadConfig as $e}from"coffi";async function Te(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:se(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Se(e){let{config:t,filepath:n}=await $e({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Re(e,t){let{config:n,filepath:r}=await $e({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var at={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function v(e){return{...at,...e}}function Oe(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Be(e,t){return t==="cjs"?e:void 0}function Pe(e,t,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((s,o)=>{let i=JSON.stringify(n[o]);return s[`process.env.${o}`]=i,s[`import.meta.env.${o}`]=i,s},{}),...e,...r==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Le(e,t){return e===void 0?t==="esm":e}function De(e){return typeof e==="string"?e:void 0}function Ae(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var lt=/\.(js|ts|jsx|tsx|mts|cts)$/,J={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&G(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
24
24
  import { dirname } from 'path';
25
25
 
26
26
  const __filename = fileURLToPath(import.meta.url);
27
27
  const __dirname = dirname(__filename);
28
28
 
29
- `},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&Y(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
29
+ `},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&G(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
30
30
 
31
31
  const importMetaUrl = pathToFileURL(__filename).href;
32
32
 
33
- `}};function je({format:e,target:t,shims:n}){let s=dt(n).map((o)=>Q[o]).filter((o)=>o.appliesTo(e,t));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:mt},async({path:i})=>{let a=await Bun.file(i).text(),l=s.filter((p)=>p.isNeededInFile(a));if(l.length===0)return;let{shebangLine:c,codeContent:f}=gt(a),m=l.map((p)=>p.generateCode()).join("");return{contents:c+m+f}})}}}function dt(e){if(e===!0)return Object.keys(Q);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in Q)).map(([t])=>t)}function gt(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
34
- `);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var R=new Set;async function N(e,t){let n=k(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)fe(t,n.outDir);L(n.silent);let{packageJson:r,path:s}=await Be(t);if(r&&s)u.cli(`Using package.json: ${x(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let o=B(n.entry),i=r?.type,a=M(n,r),l=_(n);if(!n.dtsOnly){let c=[ve(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return ht(n,t,p,m,i,c)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let c=await Le(t,n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${x(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let f=n.format.filter((p)=>{if(p==="iife"&&!$(i)&&n.format.includes("cjs"))return!1;return!0}),m=typeof n.dts==="object"&&n.dts.entry?B(n.dts.entry):Re(o);try{await Promise.all(m.map(async(p)=>{let q=await Te(t,p.path,n,c,r);await Promise.all(f.map(async(te)=>{let He=n.outputExtension?.({format:te,packageType:i,options:n,entry:p}).dts??ce(te,i),V=`${t}/${n.outDir}/${p.name}${He}`;await Bun.write(V,q);let qe=Bun.file(V).size||0;u.progress("DTS",x(V),K(qe),n.name)}))}))}catch(p){throw new h(b(p))}}}async function ht(e,t,n,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:n}).js??le(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Oe(n.name,i)},splitting:Me(e.splitting,r),bytecode:Ae(e.bytecode,r),define:Ie(e.define,e.shims,e.env,r),minify:De(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:_e(e.env),plugins:[...o,je({format:r,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let l=`${t}/${e.outDir}/${n.name}${i}`,c=Bun.file(l).size||0;u.progress(r.toUpperCase(),x(l),K(c),e.name)}var F="0.4.18";var Ue="https://bun.sh/docs/installation",ke="https://bunup.arshadyaseen.com/#cli-options";function g(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new d(`Option --${e} requires a string value`)}}function Z(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function xt(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new d(`Option --${e} requires a boolean or string value`)}}function yt(){console.log(`
33
+ `}};function Ie({format:e,target:t,shims:n}){let s=ct(n).map((o)=>J[o]).filter((o)=>o.appliesTo(e,t));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:lt},async({path:i})=>{let a=await Bun.file(i).text(),l=s.filter((p)=>p.isNeededInFile(a));if(l.length===0)return;let{shebangLine:c,codeContent:f}=ut(a),m=l.map((p)=>p.generateCode()).join("");return{contents:c+m+f}})}}}function ct(e){if(e===!0)return Object.keys(J);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in J)).map(([t])=>t)}function ut(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
34
+ `);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var S=new Set;async function k(e,t){let n=v(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)ce(t,n.outDir);P(n.silent);let{packageJson:r,path:s}=await Se(t);if(r&&s)u.cli(`Using package.json: ${x(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let o=B(n.entry),i=r?.type,a=I(n,r),l=M(n);if(!n.dtsOnly){let c=[Ae(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return ft(n,t,p,m,i,c)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let c=await Re(t,n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${x(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let f=n.format.filter((p)=>{if(p==="iife"&&!$(i)&&n.format.includes("cjs"))return!1;return!0}),m=typeof n.dts==="object"&&n.dts.entry?B(n.dts.entry):Ce(o);try{await Promise.all(m.map(async(p)=>{let W=await we(t,p.path,n,c,r);await Promise.all(f.map(async(Z)=>{let Ne=n.outputExtension?.({format:Z,packageType:i,options:n,entry:p}).dts??ae(Z,i),H=`${t}/${n.outDir}/${p.name}${Ne}`;await Bun.write(H,W);let Ue=Bun.file(H).size||0;u.progress("DTS",x(H),X(Ue),n.name)}))}))}catch(p){throw new h(b(p))}}}async function ft(e,t,n,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:n}).js??oe(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ee(n.name,i)},splitting:Le(e.splitting,r),bytecode:Be(e.bytecode,r),define:Pe(e.define,e.shims,e.env,r),minify:Oe(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:De(e.env),plugins:[...o,Ie({format:r,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let l=`${t}/${e.outDir}/${n.name}${i}`,c=Bun.file(l).size||0;u.progress(r.toUpperCase(),x(l),X(c),e.name)}var N="0.4.19";var Me="https://bun.sh/docs/installation",_e="https://bunup.arshadyaseen.com/#cli-options";function g(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new d(`Option --${e} requires a string value`)}}function z(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function mt(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new d(`Option --${e} requires a boolean or string value`)}}function dt(){console.log(`
35
35
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
36
- `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${ke}\x1B[0m
37
- `),process.exit(0)}function wt(){console.log(F),process.exit(0)}var Ne={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:Z("format")},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:g("minify")},watch:{flags:["w","watch"],handler:g("watch")},dts:{flags:["d","dts"],handler:g("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:Z("external")},sourcemap:{flags:["sm","sourcemap"],handler:xt("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:g("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:g("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:g("minifySyntax")},clean:{flags:["c","clean"],handler:g("clean")},splitting:{flags:["s","splitting"],handler:g("splitting")},noExternal:{flags:["ne","no-external"],handler:Z("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:g("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:g("dtsOnly")},silent:{flags:["silent"],handler:g("silent")},config:{flags:["config"],handler:y("config")},publicPath:{flags:["pp","public-path"],handler:y("publicPath")},env:{flags:["env"],handler:y("env")},shims:{flags:["shims"],handler:g("shims")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new d(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=U(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},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}},help:{flags:["h","help"],handler:()=>yt()},version:{flags:["v","version"],handler:()=>wt()}},W={};for(let e of Object.values(Ne))for(let t of e.flags)W[t]=e.handler;function Fe(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),l=W[i];if(l)l(o,t,a);else throw new d(`Unknown option: --${s}`)}else{let i=W[s];if(i)i(o,t);else throw new d(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=W[s];if(a)a(i,t);else throw new d(`Unknown option: -${s}`)}else Ne.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
38
- To install Bun, visit ${Ue}`)})();import{loadConfig as Et}from"coffi";import H from"node:path";import Ct from"chokidar";async function We(e,t){let n=new Set,r=k(e),s=B(r.entry);for(let l of s){let c=H.resolve(t,l.path),f=H.dirname(c);n.add(f)}let o=Ct.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,H.join(t,r.outDir)]}),i=!1,a=async(l=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await N({...r,entry:s.map((f)=>f.path),clean:!1},t),r.onBuildSuccess?.(),!l)u.cli(`\uD83D\uDCE6 Rebuild finished in ${A(performance.now()-c)}`);await ee()}catch(c){G(c)}finally{i=!1}};o.on("change",(l)=>{let c=H.relative(t,l);u.cli(`File changed: ${c}`,{muted:!0,once:c}),a()}),o.on("error",(l)=>{throw new D(`Watcher error: ${b(l)}`)}),await a(!0)}async function $t(e=Bun.argv.slice(2)){let t=Fe(e);L(t.silent);let n=process.cwd(),{config:r,filepath:s}=await Et({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Se(r,n);if(u.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${x(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:c,rootDir:f})=>{return ae(c).map(async(p)=>{let q={...p,...t};return Tt(q,f)})}));let a=performance.now()-i,l=A(a);if(u.cli(`\u26A1\uFE0F Build completed in ${l}`),await ee(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function ee(){if(R.size>0)await $e(R),R.clear()}async function Tt(e,t){if(e.watch)await We(e,t);else await N(e,t),e.onBuildSuccess?.()}$t().catch((e)=>re(e));export{ee as validateDtsFiles,$t as main};
36
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${_e}\x1B[0m
37
+ `),process.exit(0)}function gt(){console.log(N),process.exit(0)}var je={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:z("format")},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:g("minify")},watch:{flags:["w","watch"],handler:g("watch")},dts:{flags:["d","dts"],handler:g("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:z("external")},sourcemap:{flags:["sm","sourcemap"],handler:mt("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:g("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:g("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:g("minifySyntax")},clean:{flags:["c","clean"],handler:g("clean")},splitting:{flags:["s","splitting"],handler:g("splitting")},noExternal:{flags:["ne","no-external"],handler:z("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:g("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:g("dtsOnly")},silent:{flags:["silent"],handler:g("silent")},config:{flags:["config"],handler:y("config")},publicPath:{flags:["pp","public-path"],handler:y("publicPath")},env:{flags:["env"],handler:y("env")},shims:{flags:["shims"],handler:g("shims")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new d(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=j(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},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}},help:{flags:["h","help"],handler:()=>dt()},version:{flags:["v","version"],handler:()=>gt()}},U={};for(let e of Object.values(je))for(let t of e.flags)U[t]=e.handler;function ve(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),l=U[i];if(l)l(o,t,a);else throw new d(`Unknown option: --${s}`)}else{let i=U[s];if(i)i(o,t);else throw new d(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=U[s];if(a)a(i,t);else throw new d(`Unknown option: -${s}`)}else je.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
38
+ To install Bun, visit ${Me}`)})();import{loadConfig as bt}from"coffi";import F from"node:path";import ht from"chokidar";async function ke(e,t){let n=new Set,r=v(e),s=B(r.entry);for(let l of s){let c=F.resolve(t,l.path),f=F.dirname(c);n.add(f)}let o=ht.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,F.join(t,r.outDir)]}),i=!1,a=async(l=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await k({...r,entry:s.map((f)=>f.path),clean:!1},t),r.onBuildSuccess?.(),!l)u.cli(`\uD83D\uDCE6 Rebuild finished in ${D(performance.now()-c)}`);await Q()}catch(c){q(c)}finally{i=!1}};o.on("change",(l)=>{let c=F.relative(t,l);u.cli(`File changed: ${c}`,{muted:!0,once:c}),a()}),o.on("error",(l)=>{throw new L(`Watcher error: ${b(l)}`)}),await a(!0)}async function xt(e=Bun.argv.slice(2)){let t=ve(e);P(t.silent);let n=process.cwd(),{config:r,filepath:s}=await bt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Te(r,n);if(u.cli(`Using bunup v${N} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${x(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:c,rootDir:f})=>{return ie(c).map(async(p)=>{let W={...p,...t};return yt(W,f)})}));let a=performance.now()-i,l=D(a);if(u.cli(`\u26A1\uFE0F Build completed in ${l}`),await Q(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Q(){if(S.size>0)await ye(S),S.clear()}async function yt(e,t){if(e.watch)await ke(e,t);else await k(e,t),e.onBuildSuccess?.()}xt().catch((e)=>te(e));export{Q as validateDtsFiles,xt as main};
package/build/index.js CHANGED
@@ -1,26 +1,26 @@
1
- var vt=require("node:module");var Ft=Object.create;var{getPrototypeOf:Nt,defineProperty:C,getOwnPropertyNames:q,getOwnPropertyDescriptor:Wt}=Object,X=Object.prototype.hasOwnProperty;var h=(t,r,e)=>{e=t!=null?Ft(Nt(t)):{};let n=r||!t||!t.__esModule?C(e,"default",{value:t,enumerable:!0}):e;for(let s of q(t))if(!X.call(n,s))C(n,s,{get:()=>t[s],enumerable:!0});return n},G=new WeakMap,Ut=(t)=>{var r=G.get(t),e;if(r)return r;if(r=C({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")q(t).map((n)=>!X.call(r,n)&&C(r,n,{get:()=>t[n],enumerable:!(e=Wt(t,n))||e.enumerable}));return G.set(t,r),r};var kt=(t,r)=>{for(var e in r)C(t,e,{get:r[e],enumerable:!0,configurable:!0,set:(n)=>r[e]=()=>n})};var oe={};kt(oe,{defineWorkspace:()=>K,defineConfig:()=>H,build:()=>It});module.exports=Ut(oe);function H(t){return t}function K(t){return t}var gt=require("rolldown"),mt=require("rolldown-plugin-dts");var Y=!1;function Q(t){Y=t??!1}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(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:r,message:e,size:n,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(n){let[c,...l]=a.split(" "),g=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),m=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${r}\x1B[0m ${o}${c}${g} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${m}`}let u=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${r}\x1B[0m ${o}${a}${u}`}output(t,r={},e=console.log){if(Y)return;if(!this.shouldLog(r))return;if(r.verticalSpace)console.log("");if(e(t),r.verticalSpace)console.log("")}cli(t,r={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r)}info(t,r={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r)}warn(t,r={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r,console.warn)}error(t,r={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r,console.error)}progress(t,r,e,n){let s=String(t),i=this.colors.default,o,a,u={};if(typeof e==="string")o=e,a=n;else if(e)o=e.size,a=e.identifier,u=e;for(let[l,g]of Object.entries(this.colors.progress))if(s.includes(l)){i=g;break}let c=this.formatMessage({colorCode:i,label:s,message:r,size:o,identifier:a,muted:u.muted});this.output(c,u)}}var f=b.getInstance();class I extends Error{constructor(t){super(t);this.name="BunupError"}}class y 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 A=h(require("node:fs/promises")),Z=h(require("node:path"));function _(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function z(t=8){let r="";while(r.length<t)r+=Math.random().toString(36).substring(2);return r.substring(0,t)}function J(t,r){switch(t){case"esm":return E(r)?".js":".mjs";case"cjs":return E(r)?".cjs":".js";case"iife":return".global.js"}}function tt(t,r){switch(t){case"esm":return E(r)?".d.ts":".d.mts";case"cjs":return E(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function j(t){return t==="node"||t==="bun"}function E(t){return t==="module"}function et(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function F(t){if(t===0)return"0 B";let r=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${r[e]}`;return`${(t/1024**e).toFixed(2)} ${r[e]}`}function w(t,r=3){return t.split("/").slice(-r).join("/")}async function rt(t,r){let e=Z.default.join(t,r);try{await A.default.rm(e,{recursive:!0,force:!0})}catch(n){throw new y(`Failed to clean output directory: ${n}`)}await A.default.mkdir(e,{recursive:!0})}function P(t){return[".ts",".mts",".cts",".tsx"].some((r)=>t.endsWith(r))}function nt(t){return t.map((r)=>typeof r==="string"?new RegExp(`^${_(r)}($|\\/|\\\\)`):r)}function S(t,r){return nt(t.external||[]).concat(et(r).map((e)=>new RegExp(`^${_(e)}($|\\/|\\\\)`)))}function D(t){return nt(t.noExternal||[])}var ct=h(require("node:path")),lt=require("oxc-resolver");var x=h(require("node:path"));var T="\x00dts:",st=(t,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,n){if(N(e))return e;if(!n||!N(n))return null;let s=await B(e,$(n),r);if(!s)return null;let i=R(s);if(t.has(i))return L(i);return null},load(e){if(e.startsWith(T)){let n=$(e),s=t.get(n);if(s)return it.add(n),s}return null}}};function ot(t){return t.tsconfig?.compilerOptions}function R(t){return t.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function at(t){if(!t.path)return"";let r=x.default.dirname(t.path),e=ot(t);return e?.baseUrl?x.default.resolve(r,e.baseUrl):r}function Vt(t){let r=new Map,e=ot(t)?.paths;if(!e)return r;let n=at(t);for(let[s,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=0,u=i[0].replace(/\*/g,()=>`$${++a}`);r.set(`^${o}$`,x.default.join(n,u))}return r}function Gt(t,r,e){for(let[n,s]of r){let i=new RegExp(n),o=t.match(i);if(o)return s.replace("$1",o[1]||"")}return e?x.default.join(e,t):null}async function qt(t){let r=["",".ts",".tsx",".cts",".mts","/index.ts","/index.tsx","/index.cts","/index.mts"];for(let e of r){let n=`${t}${e}`;if(await Bun.file(n).exists()&&(n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".cts")||n.endsWith(".mts")))return n}return null}function B(t,r,e){if(!e)return Promise.resolve(null);let n=Vt(e),s=at(e),i=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):Gt(t,n,s);if(!i)return Promise.resolve(null);return qt(i)}function N(t){return t.startsWith(T)}function $(t){return t.replace(T,"")}function L(t){return`${T}${t}`}var ut;function ft(t){return{name:"bunup:types-resolve",buildStart(){ut||=new lt.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(r,e){let n=e?$(e):void 0;if(/\0/.test(r))return;if(t){if(!t.some((a)=>{let u=!1;if(typeof a==="string")u=a===r||!!n?.includes(a);else u=a.test(r)||!!(n&&a.test(n));return u}))return}let s=n?ct.default.dirname(n):process.cwd(),{path:i}=await ut.async(s,r);if(!i)return;if(/[cm]?jsx?$/.test(i)){let o=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return i}}}async function pt(t,r,e,n,s){let i=R(t),o=L(i),a=S(e,n),u=D(e);try{let{output:c}=await gt.build({input:o,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,g){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;g(l)},plugins:[st(r,s),typeof e.dts==="object"&&"resolve"in e.dts&&ft(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),mt.dts({dtsInput:!0,emitDtsOnly:!0})],external:(l)=>a.some((g)=>g.test(l))&&!u.some((g)=>g.test(l))});if(!c[0]?.code)return f.warn(`Generated empty declaration file for entry "${t}"`,{muted:!0}),"";return c[0].code}catch(c){throw new p(`DTS bundling failed for entry "${t}": ${d(c)}`)}}var Xt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ht=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Kt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Yt=/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 Jt(t){let r=new Set,e=[Xt,Ht,Kt,Yt,Qt,Zt,zt];for(let n of e){let s=t.matchAll(n);for(let i of s)if(i[1])r.add(i[1])}return r}async function dt(t,r){let e=new Set([t]),n=[t];while(n.length){let s=n.pop();if(!s)continue;try{let i=await Bun.file(s).text(),o=Jt(i);for(let a of o){let u=await B(a,s,r);if(!u)continue;if(!e.has(u))e.add(u),n.push(u)}}catch(i){f.warn(`Error processing ${s}: ${d(i)}`)}}return e}var xt=require("oxc-transform");async function ht(t){let r=new Map;return await Promise.all([...t].map(async(e)=>{try{let n=R(e);if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=xt.isolatedDeclaration(e,i);if(o)r.set(n,o)}catch(n){f.warn(`Failed to generate declaration for ${e}: ${d(n)}`)}})),r}var W=h(require("node:fs/promises")),M=h(require("node:path")),te=require("oxc-transform");async function bt(t,r){let e=M.default.resolve(t),n=M.default.resolve(e,r);if(!await W.default.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(n).exists())throw new p(`Entry file does not exist: ${n}`);if(!P(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(M.default.relative(e,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:e,absoluteEntry:n}}async function yt(t,r,e,n,s){let{absoluteEntry:i}=await bt(t,r),o=await dt(i,n),a=await ht(o);return pt(i,a,e,s,n)}function Et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function U(t,{warnOnConflict:r=!0}={}){let e=[],n=new Set,s={};function i(o,a){if(n.has(o)){let u=z(),c=`${o}_${u}`;if(r)f.warn(`Output name conflict: "${o}" is used by multiple files.
1
+ var Ut=require("node:module");var _t=Object.create;var{getPrototypeOf:jt,defineProperty:w,getOwnPropertyNames:G,getOwnPropertyDescriptor:Nt}=Object,q=Object.prototype.hasOwnProperty;var R=(t,e,r)=>{r=t!=null?_t(jt(t)):{};let n=e||!t||!t.__esModule?w(r,"default",{value:t,enumerable:!0}):r;for(let i of G(t))if(!q.call(n,i))w(n,i,{get:()=>t[i],enumerable:!0});return n},V=new WeakMap,Ft=(t)=>{var e=V.get(t),r;if(e)return e;if(e=w({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")G(t).map((n)=>!q.call(e,n)&&w(e,n,{get:()=>t[n],enumerable:!(r=Nt(t,n))||r.enumerable}));return V.set(t,e),e};var Wt=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})};var ee={};Wt(ee,{defineWorkspace:()=>H,defineConfig:()=>X,build:()=>It});module.exports=Ft(ee);function X(t){return t}function H(t){return t}var ct=require("rolldown"),lt=require("rolldown-plugin-dts");var K=!1;function Y(t){K=t??!1}class x{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(!x.instance)x.instance=new x;return x.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:r,size:n,identifier:i,muted:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),g=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${g} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${f}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},r=console.log){if(K)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(r(t),e.verticalSpace)console.log("")}cli(t,e={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}info(t,e={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}warn(t,e={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.warn)}error(t,e={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.error)}progress(t,e,r,n){let i=String(t),o=this.colors.default,s,a,c={};if(typeof r==="string")s=r,a=n;else if(r)s=r.size,a=r.identifier,c=r;for(let[l,g]of Object.entries(this.colors.progress))if(i.includes(l)){o=g;break}let u=this.formatMessage({colorCode:o,label:i,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var m=x.getInstance();class I extends Error{constructor(t){super(t);this.name="BunupError"}}class h 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 M=R(require("node:fs/promises")),v=R(require("node:path"));function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function Z(t,e){switch(t){case"esm":return b(e)?".js":".mjs";case"cjs":return b(e)?".cjs":".js";case"iife":return".global.js"}}function z(t,e){switch(t){case"esm":return b(e)?".d.ts":".d.mts";case"cjs":return b(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function A(t){return t==="node"||t==="bun"}function b(t){return t==="module"}function J(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function _(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${e[r]}`;return`${(t/1024**r).toFixed(2)} ${e[r]}`}function y(t,e=3){return t.split("/").slice(-e).join("/")}async function tt(t,e){let r=v.default.join(t,e);try{await M.default.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await M.default.mkdir(r,{recursive:!0})}function $(t){return[".ts",".mts",".cts",".tsx"].some((e)=>t.endsWith(e))}function et(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function T(t,e){return et(t.external||[]).concat(J(e).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function P(t){return et(t.noExternal||[])}var ot=R(require("node:path")),at=require("oxc-resolver");var rt=require("ts-import-resolver");var S="\x00dts:",nt=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,i){if(j(n))return n;if(!i||!j(i))return null;let o=rt.resolveTypeScriptImportPath({path:n,importer:C(i),tsconfig:e.tsconfig,rootDir:r});if(!o)return null;let s=E(o);if(t.has(s))return B(s);return null},load(n){if(n.startsWith(S)){let i=C(n),o=t.get(i);if(o)return st.add(i),o}return null}}};function E(t){if(t.endsWith(".d.ts")||t.endsWith(".d.mts")||t.endsWith(".d.cts"))return t;return t.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function j(t){return t.startsWith(S)}function C(t){return t.replace(S,"")}function B(t){return`${S}${t}`}var it;function ut(t){return{name:"bunup:types-resolve",buildStart(){it||=new at.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,r){let n=r?C(r):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!n?.includes(a);else c=a.test(e)||!!(n&&a.test(n));return c}))return}let i=n?ot.default.dirname(n):process.cwd(),{path:o}=await it.async(i,e);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 ft(t,e,r,n,i,o){let s=E(t),a=B(s),c=T(r,n),u=P(r);try{let{output:l}=await ct.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(g,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;f(g)},plugins:[nt(e,i,o),typeof r.dts==="object"&&"resolve"in r.dts&&ut(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),lt.dts({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>c.some((f)=>f.test(g))&&!u.some((f)=>f.test(g))});if(!l[0]?.code)return m.warn(`Generated empty declaration file for entry "${t}"`,{muted:!0}),"";return l[0].code}catch(l){throw new p(`DTS bundling failed for entry "${t}": ${d(l)}`)}}var mt=require("ts-import-resolver");var kt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Gt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Xt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ht=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Kt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Yt(t){let e=new Set,r=[kt,Vt,Gt,qt,Xt,Ht,Kt];for(let n of r){let i=t.matchAll(n);for(let o of i)if(o[1])e.add(o[1])}return e}async function gt(t,e,r){let n=new Set([t]),i=[t];while(i.length){let o=i.pop();if(!o)continue;try{let s=await Bun.file(o).text(),a=Yt(s);for(let c of a){let u=mt.resolveTypeScriptImportPath({path:c,importer:o,tsconfig:e.tsconfig,rootDir:r});if(!u)continue;if(!n.has(u))n.add(u),i.push(u)}}catch(s){m.warn(`Error processing ${o}: ${d(s)}`)}}return n}var pt=require("oxc-transform");async function dt(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:s}=pt.isolatedDeclaration(r,o);if(s)e.set(n,s)}catch(n){m.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}var N=R(require("node:fs/promises")),D=R(require("node:path")),vt=require("oxc-transform");async function xt(t,e){let r=D.default.resolve(t),n=D.default.resolve(r,e);if(!await N.default.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new p(`Entry file does not exist: ${n}`);if(!$(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(D.default.relative(r,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function ht(t,e,r,n,i){let{absoluteEntry:o}=await xt(t,e),s=await gt(o,n,t),a=await dt(s);return ft(o,a,r,i,n,t)}function bt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function F(t,{warnOnConflict:e=!0}={}){let r=[],n=new Set,i={};function o(s,a){if(n.has(s)){let c=Q(),u=`${s}_${c}`;if(e)m.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
- ${s[o]} -> ${o}.js
5
- ${a} -> ${c}.js (auto-renamed to avoid conflict)
4
+ ${i[s]} -> ${s}.js
5
+ ${a} -> ${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
- custom_name: "${s[o]}",
10
+ custom_name: "${i[s]}",
11
11
  another_name: "${a}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});e.push({name:c,path:a})}else e.push({name:o,path:a}),n.add(o),s[o]=a}if(Array.isArray(t))for(let o of t){let a=Et(o);i(a,o)}else if(typeof t==="object")for(let[o,a]of Object.entries(t))i(o,a);else{let o=Et(t);i(o,t)}return e}function wt(t){return t.filter((r)=>P(r.path))}function Rt(t,r){return`[dir]/${t}${r}`}var k=require("coffi");async function Ct(t){let{config:r,filepath:e}=await k.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:r,path:e}}async function $t(t,r){let{config:e,filepath:n}=await k.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:r,maxDepth:3});return{tsconfig:e,path:n}}var ee={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Tt(t){return{...ee,...t}}function Pt(t){let{minify:r,minifyWhitespace:e,minifyIdentifiers:n,minifySyntax:s}=t,i=r===!0;return{whitespace:e??i,identifiers:n??i,syntax:s??i}}function St(t,r){return r==="cjs"?t:void 0}function Dt(t,r,e,n){return{...typeof e==="object"&&Object.keys(e).reduce((s,i)=>{let o=JSON.stringify(e[i]);return s[`process.env.${i}`]=o,s[`import.meta.env.${i}`]=o,s},{}),...t,...n==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Bt(t,r){return t===void 0?r==="esm":t}function Lt(t){return typeof t==="string"?t:void 0}function Mt(t,r){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(n)=>{let s=n.path;if(t.some((o)=>o.test(s))&&!r.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var re=/\.(js|ts|jsx|tsx|mts|cts)$/,v={dirnameFilename:{appliesTo:(t,r)=>t==="esm"&&j(r),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:u,path:a})}else r.push({name:s,path:a}),n.add(s),i[s]=a}if(Array.isArray(t))for(let s of t){let a=bt(s);o(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))o(s,a);else{let s=bt(t);o(s,t)}return r}function yt(t){return t.filter((e)=>$(e.path))}function Et(t,e){return`[dir]/${t}${e}`}var W=require("coffi");async function wt(t){let{config:e,filepath:r}=await W.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:r}}async function Rt(t,e){let{config:r,filepath:n}=await W.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:r,path:n}}var Qt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Ct(t){return{...Qt,...t}}function St(t){let{minify:e,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:i}=t,o=e===!0;return{whitespace:r??o,identifiers:n??o,syntax:i??o}}function $t(t,e){return e==="cjs"?t:void 0}function Tt(t,e,r,n){return{...typeof r==="object"&&Object.keys(r).reduce((i,o)=>{let s=JSON.stringify(r[o]);return i[`process.env.${o}`]=s,i[`import.meta.env.${o}`]=s,i},{}),...t,...n==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Pt(t,e){return t===void 0?e==="esm":t}function Bt(t){return typeof t==="string"?t:void 0}function Dt(t,e){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let i=n.path;if(t.some((s)=>s.test(i))&&!e.some((s)=>s.test(i)))return{path:i,external:!0};return null})}}}var Zt=/\.(js|ts|jsx|tsx|mts|cts)$/,U={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&A(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
16
16
  import { dirname } from 'path';
17
17
 
18
18
  const __filename = fileURLToPath(import.meta.url);
19
19
  const __dirname = dirname(__filename);
20
20
 
21
- `},importMetaUrl:{appliesTo:(t,r)=>t==="cjs"&&j(r),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
21
+ `},importMetaUrl:{appliesTo:(t,e)=>t==="cjs"&&A(e),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
22
22
 
23
23
  const importMetaUrl = pathToFileURL(__filename).href;
24
24
 
25
- `}};function Ot({format:t,target:r,shims:e}){let s=ne(e).map((i)=>v[i]).filter((i)=>i.appliesTo(t,r));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:re},async({path:o})=>{let a=await Bun.file(o).text(),u=s.filter((m)=>m.isNeededInFile(a));if(u.length===0)return;let{shebangLine:c,codeContent:l}=se(a),g=u.map((m)=>m.generateCode()).join("");return{contents:c+g+l}})}}}function ne(t){if(t===!0)return Object.keys(v);if(!t)return[];return Object.entries(t).filter(([r,e])=>e&&(r in v)).map(([r])=>r)}function se(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let r=t.indexOf(`
26
- `);return r===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,r+1),codeContent:t.slice(r+1)}}var it=new Set;async function It(t,r){let e=Tt(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.");if(e.clean)rt(r,e.outDir);Q(e.silent);let{packageJson:n,path:s}=await Ct(r);if(n&&s)f.cli(`Using package.json: ${w(s,2)}`,{muted:!0,identifier:e.name,once:`${s}:${e.name}`});let i=U(e.entry),o=n?.type,a=S(e,n),u=D(e);if(!e.dtsOnly){let c=[Mt(a,u)],l=e.format.flatMap((g)=>i.map((m)=>{return ie(e,r,m,g,o,c)}));await Promise.all(l)}if(e.dts||e.dtsOnly){let c=await $t(r,e.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,identifier:e.name,once:`${c.path}:${e.name}`});let l=e.format.filter((m)=>{if(m==="iife"&&!E(o)&&e.format.includes("cjs"))return!1;return!0}),g=typeof e.dts==="object"&&e.dts.entry?U(e.dts.entry):wt(i);try{await Promise.all(g.map(async(m)=>{let At=await yt(r,m.path,e,c,n);await Promise.all(l.map(async(V)=>{let _t=e.outputExtension?.({format:V,packageType:o,options:e,entry:m}).dts??tt(V,o),O=`${r}/${e.outDir}/${m.name}${_t}`;await Bun.write(O,At);let jt=Bun.file(O).size||0;f.progress("DTS",w(O),F(jt),e.name)}))}))}catch(m){throw new p(d(m))}}}async function ie(t,r,e,n,s,i){let o=t.outputExtension?.({format:n,packageType:s,options:t,entry:e}).js??J(n,s),a=await Bun.build({entrypoints:[`${r}/${e.path}`],format:n,naming:{entry:Rt(e.name,o)},splitting:Bt(t.splitting,n),bytecode:St(t.bytecode,n),define:Dt(t.define,t.shims,t.env,n),minify:Pt(t),outdir:`${r}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:Lt(t.env),plugins:[...i,Ot({format:n,target:t.target,shims:t.shims}),...t.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let l of a.logs){if(l.level==="error")throw new y(l.message);if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}let u=`${r}/${t.outDir}/${e.name}${o}`,c=Bun.file(u).size||0;f.progress(n.toUpperCase(),w(u),F(c),t.name)}
25
+ `}};function Lt({format:t,target:e,shims:r}){let i=zt(r).map((o)=>U[o]).filter((o)=>o.appliesTo(t,e));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:Zt},async({path:s})=>{let a=await Bun.file(s).text(),c=i.filter((f)=>f.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:l}=Jt(a),g=c.map((f)=>f.generateCode()).join("");return{contents:u+g+l}})}}}function zt(t){if(t===!0)return Object.keys(U);if(!t)return[];return Object.entries(t).filter(([e,r])=>r&&(e in U)).map(([e])=>e)}function Jt(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
26
+ `);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}var st=new Set;async function It(t,e){let r=Ct(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)tt(e,r.outDir);Y(r.silent);let{packageJson:n,path:i}=await wt(e);if(n&&i)m.cli(`Using package.json: ${y(i,2)}`,{muted:!0,identifier:r.name,once:`${i}:${r.name}`});let o=F(r.entry),s=n?.type,a=T(r,n),c=P(r);if(!r.dtsOnly){let u=[Dt(a,c)],l=r.format.flatMap((g)=>o.map((f)=>{return te(r,e,f,g,s,u)}));await Promise.all(l)}if(r.dts||r.dtsOnly){let u=await Rt(e,r.preferredTsconfigPath);if(u.path)m.cli(`Using tsconfig: ${y(u.path,2)}`,{muted:!0,identifier:r.name,once:`${u.path}:${r.name}`});let l=r.format.filter((f)=>{if(f==="iife"&&!b(s)&&r.format.includes("cjs"))return!1;return!0}),g=typeof r.dts==="object"&&r.dts.entry?F(r.dts.entry):yt(o);try{await Promise.all(g.map(async(f)=>{let Mt=await ht(e,f.path,r,u,n);await Promise.all(l.map(async(k)=>{let Ot=r.outputExtension?.({format:k,packageType:s,options:r,entry:f}).dts??z(k,s),L=`${e}/${r.outDir}/${f.name}${Ot}`;await Bun.write(L,Mt);let At=Bun.file(L).size||0;m.progress("DTS",y(L),_(At),r.name)}))}))}catch(f){throw new p(d(f))}}}async function te(t,e,r,n,i,o){let s=t.outputExtension?.({format:n,packageType:i,options:t,entry:r}).js??Z(n,i),a=await Bun.build({entrypoints:[`${e}/${r.path}`],format:n,naming:{entry:Et(r.name,s)},splitting:Pt(t.splitting,n),bytecode:$t(t.bytecode,n),define:Tt(t.define,t.shims,t.env,n),minify:St(t),outdir:`${e}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:Bt(t.env),plugins:[...o,Lt({format:n,target:t.target,shims:t.shims}),...t.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let l of a.logs){if(l.level==="error")throw new h(l.message);if(l.level==="warning")m.warn(l.message);else if(l.level==="info")m.info(l.message)}let c=`${e}/${t.outDir}/${r.name}${s}`,u=Bun.file(c).size||0;m.progress(n.toUpperCase(),y(c),_(u),t.name)}
package/build/index.mjs CHANGED
@@ -1,26 +1,26 @@
1
- function Ct(t){return t}function $t(t){return t}import{build as Mt}from"rolldown";import{dts as Ot}from"rolldown-plugin-dts";var W=!1;function U(t){W=t??!1}class x{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(!x.instance)x.instance=new x;return x.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:r,message:e,size:n,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length)),a=s?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(n){let[c,...l]=a.split(" "),g=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${r}\x1B[0m ${o}${c}${g} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${r}\x1B[0m ${o}${a}${u}`}output(t,r={},e=console.log){if(W)return;if(!this.shouldLog(r))return;if(r.verticalSpace)console.log("");if(e(t),r.verticalSpace)console.log("")}cli(t,r={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r)}info(t,r={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r)}warn(t,r={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r,console.warn)}error(t,r={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:r.identifier,muted:r.muted});this.output(e,r,console.error)}progress(t,r,e,n){let i=String(t),s=this.colors.default,o,a,u={};if(typeof e==="string")o=e,a=n;else if(e)o=e.size,a=e.identifier,u=e;for(let[l,g]of Object.entries(this.colors.progress))if(i.includes(l)){s=g;break}let c=this.formatMessage({colorCode:s,label:i,message:r,size:o,identifier:a,muted:u.muted});this.output(c,u)}}var f=x.getInstance();class L extends Error{constructor(t){super(t);this.name="BunupError"}}class h 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 k from"node:fs/promises";import Tt from"node:path";function M(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function v(t=8){let r="";while(r.length<t)r+=Math.random().toString(36).substring(2);return r.substring(0,t)}function V(t,r){switch(t){case"esm":return b(r)?".js":".mjs";case"cjs":return b(r)?".cjs":".js";case"iife":return".global.js"}}function G(t,r){switch(t){case"esm":return b(r)?".d.ts":".d.mts";case"cjs":return b(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function O(t){return t==="node"||t==="bun"}function b(t){return t==="module"}function q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function I(t){if(t===0)return"0 B";let r=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${r[e]}`;return`${(t/1024**e).toFixed(2)} ${r[e]}`}function y(t,r=3){return t.split("/").slice(-r).join("/")}async function X(t,r){let e=Tt.join(t,r);try{await k.rm(e,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await k.mkdir(e,{recursive:!0})}function $(t){return[".ts",".mts",".cts",".tsx"].some((r)=>t.endsWith(r))}function H(t){return t.map((r)=>typeof r==="string"?new RegExp(`^${M(r)}($|\\/|\\\\)`):r)}function T(t,r){return H(t.external||[]).concat(q(r).map((e)=>new RegExp(`^${M(e)}($|\\/|\\\\)`)))}function P(t){return H(t.noExternal||[])}import Bt from"node:path";import{ResolverFactory as Lt}from"oxc-resolver";import w from"node:path";var C="\x00dts:",K=(t,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,n){if(A(e))return e;if(!n||!A(n))return null;let i=await S(e,R(n),r);if(!i)return null;let s=E(i);if(t.has(s))return D(s);return null},load(e){if(e.startsWith(C)){let n=R(e),i=t.get(n);if(i)return Y.add(n),i}return null}}};function Q(t){return t.tsconfig?.compilerOptions}function E(t){return t.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function Z(t){if(!t.path)return"";let r=w.dirname(t.path),e=Q(t);return e?.baseUrl?w.resolve(r,e.baseUrl):r}function Pt(t){let r=new Map,e=Q(t)?.paths;if(!e)return r;let n=Z(t);for(let[i,s]of Object.entries(e))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=0,u=s[0].replace(/\*/g,()=>`$${++a}`);r.set(`^${o}$`,w.join(n,u))}return r}function St(t,r,e){for(let[n,i]of r){let s=new RegExp(n),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return e?w.join(e,t):null}async function Dt(t){let r=["",".ts",".tsx",".cts",".mts","/index.ts","/index.tsx","/index.cts","/index.mts"];for(let e of r){let n=`${t}${e}`;if(await Bun.file(n).exists()&&(n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".cts")||n.endsWith(".mts")))return n}return null}function S(t,r,e){if(!e)return Promise.resolve(null);let n=Pt(e),i=Z(e),s=t.startsWith(".")?w.resolve(w.dirname(r||""),t):St(t,n,i);if(!s)return Promise.resolve(null);return Dt(s)}function A(t){return t.startsWith(C)}function R(t){return t.replace(C,"")}function D(t){return`${C}${t}`}var z;function J(t){return{name:"bunup:types-resolve",buildStart(){z||=new Lt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(r,e){let n=e?R(e):void 0;if(/\0/.test(r))return;if(t){if(!t.some((a)=>{let u=!1;if(typeof a==="string")u=a===r||!!n?.includes(a);else u=a.test(r)||!!(n&&a.test(n));return u}))return}let i=n?Bt.dirname(n):process.cwd(),{path:s}=await z.async(i,r);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 tt(t,r,e,n,i){let s=E(t),o=D(s),a=T(e,n),u=P(e);try{let{output:c}=await Mt({input:o,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,g){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;g(l)},plugins:[K(r,i),typeof e.dts==="object"&&"resolve"in e.dts&&J(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Ot({dtsInput:!0,emitDtsOnly:!0})],external:(l)=>a.some((g)=>g.test(l))&&!u.some((g)=>g.test(l))});if(!c[0]?.code)return f.warn(`Generated empty declaration file for entry "${t}"`,{muted:!0}),"";return c[0].code}catch(c){throw new p(`DTS bundling failed for entry "${t}": ${d(c)}`)}}var It=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,At=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,_t=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Nt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Wt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Ut(t){let r=new Set,e=[It,At,_t,jt,Ft,Nt,Wt];for(let n of e){let i=t.matchAll(n);for(let s of i)if(s[1])r.add(s[1])}return r}async function et(t,r){let e=new Set([t]),n=[t];while(n.length){let i=n.pop();if(!i)continue;try{let s=await Bun.file(i).text(),o=Ut(s);for(let a of o){let u=await S(a,i,r);if(!u)continue;if(!e.has(u))e.add(u),n.push(u)}}catch(s){f.warn(`Error processing ${i}: ${d(s)}`)}}return e}import{isolatedDeclaration as kt}from"oxc-transform";async function rt(t){let r=new Map;return await Promise.all([...t].map(async(e)=>{try{let n=E(e);if(!await Bun.file(e).exists())return;let s=await Bun.file(e).text(),{code:o}=kt(e,s);if(o)r.set(n,o)}catch(n){f.warn(`Failed to generate declaration for ${e}: ${d(n)}`)}})),r}import nt from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as _e}from"oxc-transform";async function st(t,r){let e=_.resolve(t),n=_.resolve(e,r);if(!await nt.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(n).exists())throw new p(`Entry file does not exist: ${n}`);if(!$(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(_.relative(e,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:e,absoluteEntry:n}}async function it(t,r,e,n,i){let{absoluteEntry:s}=await st(t,r),o=await et(s,n),a=await rt(o);return tt(s,a,e,i,n)}function ot(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t,{warnOnConflict:r=!0}={}){let e=[],n=new Set,i={};function s(o,a){if(n.has(o)){let u=v(),c=`${o}_${u}`;if(r)f.warn(`Output name conflict: "${o}" is used by multiple files.
1
+ function yt(t){return t}function Et(t){return t}import{build as $t}from"rolldown";import{dts as Tt}from"rolldown-plugin-dts";var N=!1;function F(t){N=t??!1}class x{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(!x.instance)x.instance=new x;return x.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:r,size:n,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=i?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),g=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),f=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${g} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${f}`}let c=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},r=console.log){if(N)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(r(t),e.verticalSpace)console.log("")}cli(t,e={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}info(t,e={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}warn(t,e={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.warn)}error(t,e={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.error)}progress(t,e,r,n){let o=String(t),i=this.colors.default,s,a,c={};if(typeof r==="string")s=r,a=n;else if(r)s=r.size,a=r.identifier,c=r;for(let[l,g]of Object.entries(this.colors.progress))if(o.includes(l)){i=g;break}let u=this.formatMessage({colorCode:i,label:o,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var m=x.getInstance();class B extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends B{constructor(t){super(t);this.name="BunupBuildError"}}class p extends B{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import W from"node:fs/promises";import wt from"node:path";function D(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function k(t,e){switch(t){case"esm":return b(e)?".js":".mjs";case"cjs":return b(e)?".cjs":".js";case"iife":return".global.js"}}function V(t,e){switch(t){case"esm":return b(e)?".d.ts":".d.mts";case"cjs":return b(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(t){return t==="node"||t==="bun"}function b(t){return t==="module"}function G(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function I(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${e[r]}`;return`${(t/1024**r).toFixed(2)} ${e[r]}`}function y(t,e=3){return t.split("/").slice(-e).join("/")}async function q(t,e){let r=wt.join(t,e);try{await W.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await W.mkdir(r,{recursive:!0})}function C(t){return[".ts",".mts",".cts",".tsx"].some((e)=>t.endsWith(e))}function X(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${D(e)}($|\\/|\\\\)`):e)}function S(t,e){return X(t.external||[]).concat(G(e).map((r)=>new RegExp(`^${D(r)}($|\\/|\\\\)`)))}function $(t){return X(t.noExternal||[])}import Ct from"node:path";import{ResolverFactory as St}from"oxc-resolver";import{resolveTypeScriptImportPath as Rt}from"ts-import-resolver";var R="\x00dts:",H=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,o){if(M(n))return n;if(!o||!M(o))return null;let i=Rt({path:n,importer:w(o),tsconfig:e.tsconfig,rootDir:r});if(!i)return null;let s=E(i);if(t.has(s))return T(s);return null},load(n){if(n.startsWith(R)){let o=w(n),i=t.get(o);if(i)return K.add(o),i}return null}}};function E(t){if(t.endsWith(".d.ts")||t.endsWith(".d.mts")||t.endsWith(".d.cts"))return t;return t.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function M(t){return t.startsWith(R)}function w(t){return t.replace(R,"")}function T(t){return`${R}${t}`}var Y;function v(t){return{name:"bunup:types-resolve",buildStart(){Y||=new St({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,r){let n=r?w(r):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!n?.includes(a);else c=a.test(e)||!!(n&&a.test(n));return c}))return}let o=n?Ct.dirname(n):process.cwd(),{path:i}=await Y.async(o,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 Q(t,e,r,n,o,i){let s=E(t),a=T(s),c=S(r,n),u=$(r);try{let{output:l}=await $t({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(g,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;f(g)},plugins:[H(e,o,i),typeof r.dts==="object"&&"resolve"in r.dts&&v(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Tt({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>c.some((f)=>f.test(g))&&!u.some((f)=>f.test(g))});if(!l[0]?.code)return m.warn(`Generated empty declaration file for entry "${t}"`,{muted:!0}),"";return l[0].code}catch(l){throw new p(`DTS bundling failed for entry "${t}": ${d(l)}`)}}import{resolveTypeScriptImportPath as Pt}from"ts-import-resolver";var Bt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Dt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Lt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,It=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ot=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,At=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function _t(t){let e=new Set,r=[Bt,Dt,Lt,It,Mt,Ot,At];for(let n of r){let o=t.matchAll(n);for(let i of o)if(i[1])e.add(i[1])}return e}async function Z(t,e,r){let n=new Set([t]),o=[t];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=_t(s);for(let c of a){let u=Pt({path:c,importer:i,tsconfig:e.tsconfig,rootDir:r});if(!u)continue;if(!n.has(u))n.add(u),o.push(u)}}catch(s){m.warn(`Error processing ${i}: ${d(s)}`)}}return n}import{isolatedDeclaration as jt}from"oxc-transform";async function z(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let i=await Bun.file(r).text(),{code:s}=jt(r,i);if(s)e.set(n,s)}catch(n){m.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}import J from"node:fs/promises";import O from"node:path";import{isolatedDeclaration as Le}from"oxc-transform";async function tt(t,e){let r=O.resolve(t),n=O.resolve(r,e);if(!await J.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new p(`Entry file does not exist: ${n}`);if(!C(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(O.relative(r,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function et(t,e,r,n,o){let{absoluteEntry:i}=await tt(t,e),s=await Z(i,n,t),a=await z(s);return Q(i,a,r,o,n,t)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(t,{warnOnConflict:e=!0}={}){let r=[],n=new Set,o={};function i(s,a){if(n.has(s)){let c=U(),u=`${s}_${c}`;if(e)m.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
- ${i[o]} -> ${o}.js
5
- ${a} -> ${c}.js (auto-renamed to avoid conflict)
4
+ ${o[s]} -> ${s}.js
5
+ ${a} -> ${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
- custom_name: "${i[o]}",
10
+ custom_name: "${o[s]}",
11
11
  another_name: "${a}"
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});e.push({name:c,path:a})}else e.push({name:o,path:a}),n.add(o),i[o]=a}if(Array.isArray(t))for(let o of t){let a=ot(o);s(a,o)}else if(typeof t==="object")for(let[o,a]of Object.entries(t))s(o,a);else{let o=ot(t);s(o,t)}return e}function at(t){return t.filter((r)=>$(r.path))}function ut(t,r){return`[dir]/${t}${r}`}import{loadConfig as ct}from"coffi";async function lt(t){let{config:r,filepath:e}=await ct({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:r,path:e}}async function ft(t,r){let{config:e,filepath:n}=await ct({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:r,maxDepth:3});return{tsconfig:e,path:n}}var vt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function gt(t){return{...vt,...t}}function mt(t){let{minify:r,minifyWhitespace:e,minifyIdentifiers:n,minifySyntax:i}=t,s=r===!0;return{whitespace:e??s,identifiers:n??s,syntax:i??s}}function pt(t,r){return r==="cjs"?t:void 0}function dt(t,r,e,n){return{...typeof e==="object"&&Object.keys(e).reduce((i,s)=>{let o=JSON.stringify(e[s]);return i[`process.env.${s}`]=o,i[`import.meta.env.${s}`]=o,i},{}),...t,...n==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function xt(t,r){return t===void 0?r==="esm":t}function ht(t){return typeof t==="string"?t:void 0}function bt(t,r){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(n)=>{let i=n.path;if(t.some((o)=>o.test(i))&&!r.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var Vt=/\.(js|ts|jsx|tsx|mts|cts)$/,F={dirnameFilename:{appliesTo:(t,r)=>t==="esm"&&O(r),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:u,path:a})}else r.push({name:s,path:a}),n.add(s),o[s]=a}if(Array.isArray(t))for(let s of t){let a=rt(s);i(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))i(s,a);else{let s=rt(t);i(s,t)}return r}function nt(t){return t.filter((e)=>C(e.path))}function st(t,e){return`[dir]/${t}${e}`}import{loadConfig as it}from"coffi";async function ot(t){let{config:e,filepath:r}=await it({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:r}}async function at(t,e){let{config:r,filepath:n}=await it({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:r,path:n}}var Nt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function ut(t){return{...Nt,...t}}function ct(t){let{minify:e,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:o}=t,i=e===!0;return{whitespace:r??i,identifiers:n??i,syntax:o??i}}function lt(t,e){return e==="cjs"?t:void 0}function ft(t,e,r,n){return{...typeof r==="object"&&Object.keys(r).reduce((o,i)=>{let s=JSON.stringify(r[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...t,...n==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function mt(t,e){return t===void 0?e==="esm":t}function gt(t){return typeof t==="string"?t:void 0}function pt(t,e){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let o=n.path;if(t.some((s)=>s.test(o))&&!e.some((s)=>s.test(o)))return{path:o,external:!0};return null})}}}var Ft=/\.(js|ts|jsx|tsx|mts|cts)$/,_={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&L(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
16
16
  import { dirname } from 'path';
17
17
 
18
18
  const __filename = fileURLToPath(import.meta.url);
19
19
  const __dirname = dirname(__filename);
20
20
 
21
- `},importMetaUrl:{appliesTo:(t,r)=>t==="cjs"&&O(r),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
21
+ `},importMetaUrl:{appliesTo:(t,e)=>t==="cjs"&&L(e),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
22
22
 
23
23
  const importMetaUrl = pathToFileURL(__filename).href;
24
24
 
25
- `}};function yt({format:t,target:r,shims:e}){let i=Gt(e).map((s)=>F[s]).filter((s)=>s.appliesTo(t,r));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(s){s.onLoad({filter:Vt},async({path:o})=>{let a=await Bun.file(o).text(),u=i.filter((m)=>m.isNeededInFile(a));if(u.length===0)return;let{shebangLine:c,codeContent:l}=qt(a),g=u.map((m)=>m.generateCode()).join("");return{contents:c+g+l}})}}}function Gt(t){if(t===!0)return Object.keys(F);if(!t)return[];return Object.entries(t).filter(([r,e])=>e&&(r in F)).map(([r])=>r)}function qt(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let r=t.indexOf(`
26
- `);return r===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,r+1),codeContent:t.slice(r+1)}}var Y=new Set;async function Xt(t,r){let e=gt(t);if(!e.entry||e.entry.length===0||!e.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)X(r,e.outDir);U(e.silent);let{packageJson:n,path:i}=await lt(r);if(n&&i)f.cli(`Using package.json: ${y(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=j(e.entry),o=n?.type,a=T(e,n),u=P(e);if(!e.dtsOnly){let c=[bt(a,u)],l=e.format.flatMap((g)=>s.map((m)=>{return Ht(e,r,m,g,o,c)}));await Promise.all(l)}if(e.dts||e.dtsOnly){let c=await ft(r,e.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${y(c.path,2)}`,{muted:!0,identifier:e.name,once:`${c.path}:${e.name}`});let l=e.format.filter((m)=>{if(m==="iife"&&!b(o)&&e.format.includes("cjs"))return!1;return!0}),g=typeof e.dts==="object"&&e.dts.entry?j(e.dts.entry):at(s);try{await Promise.all(g.map(async(m)=>{let Et=await it(r,m.path,e,c,n);await Promise.all(l.map(async(N)=>{let wt=e.outputExtension?.({format:N,packageType:o,options:e,entry:m}).dts??G(N,o),B=`${r}/${e.outDir}/${m.name}${wt}`;await Bun.write(B,Et);let Rt=Bun.file(B).size||0;f.progress("DTS",y(B),I(Rt),e.name)}))}))}catch(m){throw new p(d(m))}}}async function Ht(t,r,e,n,i,s){let o=t.outputExtension?.({format:n,packageType:i,options:t,entry:e}).js??V(n,i),a=await Bun.build({entrypoints:[`${r}/${e.path}`],format:n,naming:{entry:ut(e.name,o)},splitting:xt(t.splitting,n),bytecode:pt(t.bytecode,n),define:dt(t.define,t.shims,t.env,n),minify:mt(t),outdir:`${r}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:ht(t.env),plugins:[...s,yt({format:n,target:t.target,shims:t.shims}),...t.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let l of a.logs){if(l.level==="error")throw new h(l.message);if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}let u=`${r}/${t.outDir}/${e.name}${o}`,c=Bun.file(u).size||0;f.progress(n.toUpperCase(),y(u),I(c),t.name)}export{$t as defineWorkspace,Ct as defineConfig,Xt as build};
25
+ `}};function dt({format:t,target:e,shims:r}){let o=Wt(r).map((i)=>_[i]).filter((i)=>i.appliesTo(t,e));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Ft},async({path:s})=>{let a=await Bun.file(s).text(),c=o.filter((f)=>f.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:l}=Ut(a),g=c.map((f)=>f.generateCode()).join("");return{contents:u+g+l}})}}}function Wt(t){if(t===!0)return Object.keys(_);if(!t)return[];return Object.entries(t).filter(([e,r])=>r&&(e in _)).map(([e])=>e)}function Ut(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
26
+ `);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}var K=new Set;async function kt(t,e){let r=ut(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)q(e,r.outDir);F(r.silent);let{packageJson:n,path:o}=await ot(e);if(n&&o)m.cli(`Using package.json: ${y(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let i=A(r.entry),s=n?.type,a=S(r,n),c=$(r);if(!r.dtsOnly){let u=[pt(a,c)],l=r.format.flatMap((g)=>i.map((f)=>{return Vt(r,e,f,g,s,u)}));await Promise.all(l)}if(r.dts||r.dtsOnly){let u=await at(e,r.preferredTsconfigPath);if(u.path)m.cli(`Using tsconfig: ${y(u.path,2)}`,{muted:!0,identifier:r.name,once:`${u.path}:${r.name}`});let l=r.format.filter((f)=>{if(f==="iife"&&!b(s)&&r.format.includes("cjs"))return!1;return!0}),g=typeof r.dts==="object"&&r.dts.entry?A(r.dts.entry):nt(i);try{await Promise.all(g.map(async(f)=>{let xt=await et(e,f.path,r,u,n);await Promise.all(l.map(async(j)=>{let ht=r.outputExtension?.({format:j,packageType:s,options:r,entry:f}).dts??V(j,s),P=`${e}/${r.outDir}/${f.name}${ht}`;await Bun.write(P,xt);let bt=Bun.file(P).size||0;m.progress("DTS",y(P),I(bt),r.name)}))}))}catch(f){throw new p(d(f))}}}async function Vt(t,e,r,n,o,i){let s=t.outputExtension?.({format:n,packageType:o,options:t,entry:r}).js??k(n,o),a=await Bun.build({entrypoints:[`${e}/${r.path}`],format:n,naming:{entry:st(r.name,s)},splitting:mt(t.splitting,n),bytecode:lt(t.bytecode,n),define:ft(t.define,t.shims,t.env,n),minify:ct(t),outdir:`${e}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:gt(t.env),plugins:[...i,dt({format:n,target:t.target,shims:t.shims}),...t.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let l of a.logs){if(l.level==="error")throw new h(l.message);if(l.level==="warning")m.warn(l.message);else if(l.level==="info")m.info(l.message)}let c=`${e}/${t.outDir}/${r.name}${s}`,u=Bun.file(c).size||0;m.progress(n.toUpperCase(),y(c),I(u),t.name)}export{Et as defineWorkspace,yt as defineConfig,kt as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.4.18",
3
+ "version": "0.4.19",
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",
@@ -20,7 +20,7 @@
20
20
  "bunup": "^0.4.11",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "create-bunup": "0.4.18"
23
+ "create-bunup": "0.4.19"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": ">=4.5.0"
@@ -55,7 +55,8 @@
55
55
  "oxc-resolver": "^5.0.1",
56
56
  "oxc-transform": "^0.58.1",
57
57
  "rolldown": "1.0.0-beta.7",
58
- "rolldown-plugin-dts": "^0.4.0"
58
+ "rolldown-plugin-dts": "^0.4.0",
59
+ "ts-import-resolver": "^0.1.5"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "bunup",
@@ -75,6 +76,6 @@
75
76
  "publish:ci": "pnpm --filter bunup --filter create-bunup publish --access public --no-git-checks",
76
77
  "benchmark": "pnpm -C benchmarks benchmark",
77
78
  "upgrade-deps": "pnpx taze -r -w && pnpm install && git add . && git commit -m 'chore: upgrade deps' && pnpm release:ci",
78
- "update-create-bunup-starter-root-dev-dependencies": "pnpm -C create-bunup update-starter-root-dev-dependencies"
79
+ "fetch-latest-dep-versions": "pnpm -C create-bunup fetch-latest-dep-versions"
79
80
  }
80
81
  }