bunup 0.3.57 → 0.3.59

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