bunup 0.3.18 → 0.3.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{rolldown as Ln}from"rolldown";import{dts as Dn}from"rolldown-plugin-dts";class $ extends Error{constructor(n){super(n);this.name="BunupError"}}class x extends ${constructor(n){super(n);this.name="BunupBuildError"}}class d extends ${constructor(n){super(n);this.name="BunupDTSBuildError"}}class h extends ${constructor(n){super(n);this.name="BunupCLIError"}}class j extends ${constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},Sn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof x)s="BUILD ERROR";else if(n instanceof d)s="DTS ERROR";else if(n instanceof h)s="CLI ERROR";else if(n instanceof j)s="WATCH ERROR";else if(n instanceof $)s="BUNUP ERROR";if(console.error(`\x1B[31m${s}\x1B[0m ${r}${e}`),n instanceof Error&&n.stack)console.error("\x1B[2m"+n.stack.split(`
3
+ import{rolldown as Dn}from"rolldown";import{dts as Hn}from"rolldown-plugin-dts";class $ extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends ${constructor(n){super(n);this.name="BunupBuildError"}}class d extends ${constructor(n){super(n);this.name="BunupDTSBuildError"}}class h extends ${constructor(n){super(n);this.name="BunupCLIError"}}class A extends ${constructor(n){super(n);this.name="BunupWatchError"}}var g=(n)=>{if(n instanceof Error)return n.message;return String(n)},Mn=(n,t)=>{let e=g(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof w)s="BUILD ERROR";else if(n instanceof d)s="DTS ERROR";else if(n instanceof h)s="CLI ERROR";else if(n instanceof A)s="WATCH ERROR";else if(n instanceof $)s="BUNUP ERROR";if(console.error(`\x1B[31m${s}\x1B[0m ${r}${e}`),n instanceof Error&&n.stack)console.error("\x1B[2m"+n.stack.split(`
4
4
  `).slice(1).join(`
5
- `)+"\x1B[0m")},J=(n,t)=>{Sn(n,t),process.exit(1)};import K from"node:fs/promises";import Tn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function z(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function Nn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function G(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(n=8){return Math.random().toString(36).substring(2,2+n)}function Z(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function X(n,t){switch(n){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function T(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function F(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function V(n,t){return n===void 0?t==="esm":n}function _(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function w(n,t=3){return n.split("/").slice(-t).join("/")}async function q(n,t){let e=Tn.join(n,t);try{await K.rm(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await K.mkdir(e,{recursive:!0})}function P(n){return n||O.outDir}function nn(n){return n===void 0?O.clean:n}function tn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function M(n,t){return tn(n.external||[]).concat(F(t).map((e)=>new RegExp(`^${G(e)}($|\\/|\\\\)`)))}function k(n){return tn(n.noExternal||[])}import Mn from"node:path";import{ResolverFactory as kn}from"oxc-resolver";import C from"path";var p="\x00virtual:",en=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(p))return t;if(!e?.startsWith(p)||!t.startsWith("."))return null;let r=e.slice(p.length),s=C.resolve(C.dirname(r),t);if(t==="."){let o=C.join(C.dirname(r),"index.d.ts");if(n.has(o))return`${p}${o}`;s=C.dirname(r)}if(n.has(s))return`${p}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${p}${i}`;if(t.startsWith(".")){let o=C.join(s,"index.d.ts");if(n.has(o))return`${p}${o}`}return null},load(t){if(t.startsWith(p)){let e=t.slice(p.length),r=n.get(e);if(r)return B.add(e),r}return null}}};var rn;function sn(n){return{name:"bunup:types-resolve",buildStart(){rn||=new kn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?.replace(p,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?Mn.dirname(e):process.cwd(),{path:s}=await rn.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return s}}}async function on(n,t,e,r){let s=n.replace(/\.tsx?$/,".d.ts"),i=`${p}${s}`,o=M(e,r),a=k(e),c;try{c=await Ln({input:i,onwarn(g,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;f(g)},plugins:[en(t),typeof e.dts==="object"&&"resolve"in e.dts&&sn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Dn()],external:(g)=>o.some((f)=>f.test(g))&&!a.some((f)=>f.test(g))});let{output:u}=await c.generate({});if(!u[0]?.code)throw new d("Generated bundle is empty");return u[0].code}catch(u){throw new d(`DTS bundling failed: ${m(u)}`)}finally{if(c)await c.close()}}import E from"node:path";var l={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"},formatMessage({colorCode:n,label:t,message:e,size:r,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),R=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${R}`}let c=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`},output(n,t={},e=console.log){if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")},cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)},info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)},warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)},error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)},progress(n,t,e,r){let s=String(n),i=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,f]of Object.entries(this.colors.progress))if(s.includes(g)){i=f;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}};var Hn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Un=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function an(n,t){let e=new Set([n]),r=[n],s=_n(t),i=cn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await Bun.file(o).text(),c=Wn(a);for(let u of c){let g=u.startsWith(".")?E.resolve(E.dirname(o),u):qn(u,s,i);if(!g)continue;let f=await Gn(g);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return e}function Wn(n){let t=new Set;for(let e of[Hn,Un]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}async function Gn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function cn(n){let t=E.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?E.resolve(t,n.data.compilerOptions.baseUrl):t}function _n(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=cn(n);for(let[s,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");t.set(`^${o}$`,E.join(r,a))}return t}function qn(n,t,e){for(let[r,s]of t){let i=new RegExp(r),o=n.match(i);if(o)return s.replace("$1",o[1]||"")}return e?E.join(e,n):null}import{isolatedDeclaration as Pn}from"oxc-transform";async function ln(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Pn(e,i);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import fn from"node:fs/promises";import Y from"node:path";import{isolatedDeclaration as Yn}from"oxc-transform";async function un(n,t){let e=Y.resolve(n),r=Y.resolve(e,t);if(!await fn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Y.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function mn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:i}=Yn(r,s);i.forEach((o)=>{if(!t)console.log(`
6
- `);let a=o.labels[0],c=a?In(s,a.start):"",g=`${w(r)}${c}: ${Jn(o.message)}`;l.warn(g),t=!0})}catch{}})),t)l.info(`
5
+ `)+"\x1B[0m")},z=(n,t)=>{Mn(n,t),process.exit(1)};import Q from"node:fs/promises";import Tn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function K(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function Nn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function _(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Z(n=8){return Math.random().toString(36).substring(2,2+n)}function X(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function F(n,t){switch(n){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function T(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function V(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function nn(n,t){return n===void 0?t==="esm":n}function q(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function x(n,t=3){return n.split("/").slice(-t).join("/")}async function I(n,t){let e=Tn.join(n,t);try{await Q.rm(e,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await Q.mkdir(e,{recursive:!0})}function P(n){return n||O.outDir}function tn(n){return n===void 0?O.clean:n}function en(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${_(t)}($|\\/|\\\\)`):t)}function k(n,t){return en(n.external||[]).concat(V(t).map((e)=>new RegExp(`^${_(e)}($|\\/|\\\\)`)))}function L(n){return en(n.noExternal||[])}import kn from"node:path";import{ResolverFactory as Ln}from"oxc-resolver";import C from"path";var m="\x00virtual:",rn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(m))return t;if(!e?.startsWith(m)||!t.startsWith("."))return null;let r=e.slice(m.length),s=C.resolve(C.dirname(r),t);if(t==="."){let o=C.join(C.dirname(r),"index.d.ts");if(n.has(o))return`${m}${o}`;s=C.dirname(r)}if(n.has(s))return`${m}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${m}${i}`;if(t.startsWith(".")){let o=C.join(s,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let e=t.slice(m.length),r=n.get(e);if(r)return B.add(e),r}return null}}};var sn;function on(n){return{name:"bunup:types-resolve",buildStart(){sn||=new Ln({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?kn.dirname(e):process.cwd(),{path:s}=await sn.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return s}}}async function an(n,t,e,r){let s=n.replace(/\.tsx?$/,".d.ts"),i=`${m}${s}`,o=k(e,r),a=L(e),c;try{c=await Dn({input:i,onwarn(p,u){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;u(p)},plugins:[rn(t),typeof e.dts==="object"&&"resolve"in e.dts&&on(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Hn()],external:(p)=>o.some((u)=>u.test(p))&&!a.some((u)=>u.test(p))});let{output:f}=await c.generate({});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${g(f)}`)}finally{if(c)await c.close()}}import v from"node:path";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(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({colorCode:n,label:t,message:e,size:r,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[f,...p]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-f.length)),j=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${f}${u} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${j}`}let c=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`}output(n,t={},e=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")}cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)}error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)}progress(n,t,e,r){let s=String(n),i=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[p,u]of Object.entries(this.colors.progress))if(s.includes(p)){i=u;break}let f=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(f,c)}}var l=E.getInstance();var Un=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Wn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function cn(n,t){let e=new Set([n]),r=[n],s=qn(t),i=ln(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await Bun.file(o).text(),c=Gn(a);for(let f of c){let p=f.startsWith(".")?v.resolve(v.dirname(o),f):In(f,s,i);if(!p)continue;let u=await _n(p);if(u&&!e.has(u))e.add(u),r.push(u)}}catch(a){l.warn(`Error processing ${o}: ${g(a)}`)}}return e}function Gn(n){let t=new Set;for(let e of[Un,Wn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}async function _n(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function ln(n){let t=v.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?v.resolve(t,n.data.compilerOptions.baseUrl):t}function qn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=ln(n);for(let[s,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");t.set(`^${o}$`,v.join(r,a))}return t}function In(n,t,e){for(let[r,s]of t){let i=new RegExp(r),o=n.match(i);if(o)return s.replace("$1",o[1]||"")}return e?v.join(e,n):null}import{isolatedDeclaration as Pn}from"oxc-transform";async function un(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Pn(e,i);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${g(r)}`)}})),t}import fn from"node:fs/promises";import Y from"node:path";import{isolatedDeclaration as Yn}from"oxc-transform";async function gn(n,t){let e=Y.resolve(n),r=Y.resolve(e,t);if(!await fn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Y.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function pn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:i}=Yn(r,s);i.forEach((o)=>{if(!t)console.log(`
6
+ `);let a=o.labels[0],c=a?Jn(s,a.start):"",p=`${x(r)}${c}: ${zn(o.message)}`;l.warn(p),t=!0})}catch{}})),t)l.info(`
7
7
  You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
8
- `)}function In(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
9
- `),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function Jn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function gn(n,t,e,r,s){let{absoluteEntry:i}=await un(n,t),o=await an(i,r),a=await ln(o);return on(i,a,e,s)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function S(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=Q(),c=`${i}_${a}`;l.warn(`Output name conflict: "${i}" is used by multiple files.
8
+ `)}function Jn(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
9
+ `),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function zn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function mn(n,t,e,r,s){let{absoluteEntry:i}=await gn(n,t),o=await cn(i,r),a=await un(o);return an(i,a,e,s)}function S(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function M(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=Z(),c=`${i}_${a}`;l.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
  ${r[i]} -> ${i}.js
@@ -20,8 +20,8 @@ To fix this, use named entries in your configuration:
20
20
  }
21
21
  }
22
22
 
23
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function pn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as zn}from"load-tsconfig";function dn(n){try{return zn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import I from"node:path";async function hn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=I.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Kn(r,e);if(!i)continue;return{configs:Xn(i,n),configFilePath:r}}catch(s){throw new x(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Kn(n,t){if(t===".json"||t===".jsonc")return Qn(n);return Zn(n)}async function Qn(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Zn(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${m(t)}`)}}function Xn(n,t){let e=[];if(Fn(n))Vn(n,t,e);else if(Array.isArray(n))nt(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function Fn(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function Vn(n,t,e){for(let r of n){let s=I.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function nt(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function xn(n){let t=I.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),{packageJson:null,path:t}}}function wn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var B=new Set;async function L(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await xn(t);if(e)l.cli(`Using package.json: ${w(r,2)}`,{muted:!0});let s=e?.type,i=M(n,e),o=k(n),a=[wn(i,o)],c=S(n.entry),u=z(n,t),g=n.format.flatMap((f)=>c.map((R)=>{return tt(n,t,R,f,s,a,u)}));if(await Promise.all(g),n.dts){let f=dn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path,2)}`,{muted:!0});let R=n.format.filter((b)=>{if(b==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),En=typeof n.dts==="object"&&n.dts.entry?S(n.dts.entry):c;try{await Promise.all(En.map(async(b)=>{let vn=await gn(t,b.path,n,f,e);await Promise.all(R.map(async(Rn)=>{let jn=X(Rn,s),W=`${t}/${n.outDir}/${b.name}${jn}`;await Bun.write(W,vn);let An=Bun.file(W).size||0;l.progress("DTS",w(W),_(An),n.name)}))}))}catch(b){throw new d(m(b))}}}async function tt(n,t,e,r,s,i,o){let a=Z(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:pn(e.name,a)},splitting:V(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),_(g),n.name)}var D="0.3.18";var yn="https://bun.sh/docs/installation",bn="https://bunup.arshadyaseen.com/#cli-options";function y(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function v(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function $n(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function rt(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=S(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=S(n);s(i,n)}return t}function dn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Kn}from"load-tsconfig";function hn(n){try{return Kn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${g(t)}`),{path:n,data:{},files:[]}}}import J from"node:path";async function wn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=J.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Qn(r,e);if(!i)continue;return{configs:Fn(i,n),configFilePath:r}}catch(s){throw new w(`Failed to load config from ${r}: ${g(s)}`)}}return{configs:[],configFilePath:""}}async function Qn(n,t){if(t===".json"||t===".jsonc")return Zn(n);return Xn(n)}async function Zn(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${g(t)}`)}}async function Xn(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${g(t)}`)}}function Fn(n,t){let e=[];if(Vn(n))nt(n,t,e);else if(Array.isArray(n))tt(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function Vn(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function nt(n,t,e){for(let r of n){let s=J.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function tt(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function xn(n){let t=J.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${g(e)}`),{packageJson:null,path:t}}}function yn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var B=new Set;async function D(n,t){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.");let{packageJson:e,path:r}=await xn(t);if(e)l.cli(`Using package.json: ${x(r,2)}`,{muted:!0,once:r});let s=e?.type,i=k(n,e),o=L(n),a=[yn(i,o)],c=M(n.entry),f=K(n,t),p=n.format.flatMap((u)=>c.map((j)=>{return et(n,t,j,u,s,a,f)}));if(await Promise.all(p),n.dts){let u=hn(n.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${x(u.path,2)}`,{muted:!0,once:u.path});let j=n.format.filter((b)=>{if(b==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),vn=typeof n.dts==="object"&&n.dts.entry?M(n.dts.entry):c;try{await Promise.all(vn.map(async(b)=>{let Rn=await mn(t,b.path,n,u,e);await Promise.all(j.map(async(jn)=>{let An=F(jn,s),G=`${t}/${n.outDir}/${b.name}${An}`;await Bun.write(G,Rn);let Sn=Bun.file(G).size||0;l.progress("DTS",x(G),q(Sn),n.name)}))}))}catch(b){throw new d(g(b))}}}async function et(n,t,e,r,s,i,o){let a=X(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:dn(e.name,a)},splitting:nn(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((u)=>{if(u.level==="error")throw new w(u.message);else if(u.level==="warning")l.warn(u.message);else if(u.level==="info")l.info(u.message)});let f=`${t}/${n.outDir}/${e.name}${a}`,p=Bun.file(f).size||0;l.progress(r.toUpperCase(),x(f),q(p),n.name)}var H="0.3.19";var bn="https://bun.sh/docs/installation",$n="https://bunup.arshadyaseen.com/#cli-options";function y(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function R(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function On(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function st(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
- `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${bn}\x1B[0m
26
- `),process.exit(0)}function st(){console.log(D),process.exit(0)}var it={name:{flags:["n","name"],handler:v("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:v("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},banner:{flags:["b","banner"],handler:v("banner")},footer:{flags:["f","footer"],handler:v("footer")},external:{flags:["e","external"],handler:$n("external")},sourcemap:{flags:["sm","sourcemap"],handler:v("sourcemap")},target:{flags:["t","target"],handler:v("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:y("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:y("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:y("minifySyntax")},clean:{flags:["c","clean"],handler:y("clean")},splitting:{flags:["s","splitting"],handler:y("splitting")},noExternal:{flags:["ne","no-external"],handler:$n("noExternal")}},ot={help:{flags:["h","help"],handler:()=>rt()},version:{flags:["v","version"],handler:()=>st()}},H={};for(let n of Object.values(it))if(n)for(let t of n.flags)H[t]=n.handler;for(let n of Object.values(ot))for(let t of n.flags)H[t]=n.handler;function On(n){let t={},e={},r=0;while(r<n.length){let s=n[r];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(i==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=H[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=H[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=A(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
27
- To install Bun, visit `+yn)})();import U from"node:path";import at from"chokidar";async function Cn(n,t){let e=new Set,r=S(n.entry);r.forEach((a)=>{let c=U.resolve(t,a.path),u=U.dirname(c);e.add(u)});let s=at.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,U.join(t,n.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await L({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${T(performance.now()-c)}`)}catch(c){throw new j(`Build failed: ${m(c)}`)}finally{i=!1}};s.on("change",(a)=>{let c=U.relative(t,a);l.cli(`File changed: ${c}`),o()}),s.on("error",(a)=>{throw new j(`Watcher error: ${m(a)}`)}),await o(!0)}async function ct(n=Bun.argv.slice(2)){let t=On(n),{configs:e,configFilePath:r}=await hn(process.cwd());if(l.cli(`Using bunup v${D} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${w(r,2)}`,{muted:!0});let s=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...t},c=process.cwd();if(a.clean)q(c,P(a.outDir));await Bn(a,c)}else{for(let{options:a,rootDir:c}of e)if(nn(a.clean))q(c,P(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...O,...a,...t};await Bn(u,c)}))}let i=performance.now()-s,o=T(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),B.size>0)await mn(B),B.clear();if(t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Bn(n,t){if(n.watch)await Cn(n,t);else await L(n,t),n.onBuildSuccess?.()}ct().catch((n)=>J(n));export{ct as main};
25
+ `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${$n}\x1B[0m
26
+ `),process.exit(0)}function it(){console.log(H),process.exit(0)}var ot={name:{flags:["n","name"],handler:R("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:R("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},banner:{flags:["b","banner"],handler:R("banner")},footer:{flags:["f","footer"],handler:R("footer")},external:{flags:["e","external"],handler:On("external")},sourcemap:{flags:["sm","sourcemap"],handler:R("sourcemap")},target:{flags:["t","target"],handler:R("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:y("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:y("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:y("minifySyntax")},clean:{flags:["c","clean"],handler:y("clean")},splitting:{flags:["s","splitting"],handler:y("splitting")},noExternal:{flags:["ne","no-external"],handler:On("noExternal")}},at={help:{flags:["h","help"],handler:()=>st()},version:{flags:["v","version"],handler:()=>it()}},U={};for(let n of Object.values(ot))if(n)for(let t of n.flags)U[t]=n.handler;for(let n of Object.values(at))for(let t of n.flags)U[t]=n.handler;function Cn(n){let t={},e={},r=0;while(r<n.length){let s=n[r];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(i==="entry")if(typeof o==="string"){let a=S(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=U[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=U[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=S(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
27
+ To install Bun, visit `+bn)})();import W from"node:path";import ct from"chokidar";async function Bn(n,t){let e=new Set,r=M(n.entry);r.forEach((a)=>{let c=W.resolve(t,a.path),f=W.dirname(c);e.add(f)});let s=ct.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(t,n.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await D({...n,entry:r.map((f)=>f.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${T(performance.now()-c)}`)}catch(c){throw new A(`Build failed: ${g(c)}`)}finally{i=!1}};s.on("change",(a)=>{let c=W.relative(t,a);l.cli(`File changed: ${c}`),o()}),s.on("error",(a)=>{throw new A(`Watcher error: ${g(a)}`)}),await o(!0)}async function lt(n=Bun.argv.slice(2)){let t=Cn(n),{configs:e,configFilePath:r}=await wn(process.cwd());if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${x(r,2)}`,{muted:!0});let s=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...t},c=process.cwd();if(a.clean)I(c,P(a.outDir));await En(a,c)}else{for(let{options:a,rootDir:c}of e)if(tn(a.clean))I(c,P(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let f={...O,...a,...t};await En(f,c)}))}let i=performance.now()-s,o=T(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),B.size>0)await pn(B),B.clear();if(t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0);l.dispose()}async function En(n,t){if(n.watch)await Bn(n,t);else await D(n,t),n.onBuildSuccess?.()}lt().catch((n)=>z(n));export{lt as main};
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var jn=require("node:module");var hn=Object.create;var{getPrototypeOf:Cn,defineProperty:b,getOwnPropertyNames:v,getOwnPropertyDescriptor:bn}=Object,G=Object.prototype.hasOwnProperty;var d=(n,t,r)=>{r=n!=null?hn(Cn(n)):{};let e=t||!n||!n.__esModule?b(r,"default",{value:n,enumerable:!0}):r;for(let i of v(n))if(!G.call(e,i))b(e,i,{get:()=>n[i],enumerable:!0});return e},T=new WeakMap,Rn=(n)=>{var t=T.get(n),r;if(t)return t;if(t=b({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")v(n).map((e)=>!G.call(t,e)&&b(t,e,{get:()=>n[e],enumerable:!(r=bn(n,e))||r.enumerable}));return T.set(n,t),t};var Bn=(n,t)=>{for(var r in t)b(n,r,{get:t[r],enumerable:!0,configurable:!0,set:(e)=>t[r]=()=>e})};var Hn={};Bn(Hn,{defineWorkspace:()=>H,defineConfig:()=>k,build:()=>pn});module.exports=Rn(Hn);function k(n){return n}function H(n){return n}var V=require("rolldown"),F=require("rolldown-plugin-dts");class A extends Error{constructor(n){super(n);this.name="BunupError"}}class y extends A{constructor(n){super(n);this.name="BunupBuildError"}}class p extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var x=(n)=>{if(n instanceof Error)return n.message;return String(n)};var Mn=d(require("node:fs/promises")),An=d(require("node:path"));function L(n,t){return{outdir:`${t}/${n.outDir}`,minify:On(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function On(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function N(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(n=8){return Math.random().toString(36).substring(2,2+n)}function J(n,t){switch(n){case"esm":return".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function q(n,t){switch(n){case"esm":return".d.mts";case"cjs":return R(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(n){return n==="module"}function K(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function Q(n,t){return n===void 0?t==="esm":n}function D(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function h(n,t=3){return n.split("/").slice(-t).join("/")}function Z(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${N(t)}($|\\/|\\\\)`):t)}function B(n,t){return Z(n.external||[]).concat(K(t).map((r)=>new RegExp(`^${N(r)}($|\\/|\\\\)`)))}function j(n){return Z(n.noExternal||[])}var z=d(require("node:path")),X=require("oxc-resolver");var w=d(require("path"));var m="\x00virtual:",U=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=w.default.resolve(w.default.dirname(e),t);if(t==="."){let o=w.default.join(w.default.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=w.default.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=w.default.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return P.add(r),e}return null}}};var _;function I(n){return{name:"bunup:types-resolve",buildStart(){_||=new X.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?z.default.dirname(r):process.cwd(),{path:i}=await _.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function nn(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${m}${i}`,o=B(r,e),c=j(r),f;try{f=await V.rolldown({input:s,onwarn(l,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;a(l)},plugins:[U(t),typeof r.dts==="object"&&"resolve"in r.dts&&I(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),F.dts()],external:(l)=>o.some((a)=>a.test(l))&&!c.some((a)=>a.test(l))});let{output:u}=await f.generate({});if(!u[0]?.code)throw new p("Generated bundle is empty");return u[0].code}catch(u){throw new p(`DTS bundling failed: ${x(u)}`)}finally{if(f)await f.close()}}var E=d(require("node:path"));var g={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[u,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),C=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${C}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(u,f)}};var Nn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Dn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function tn(n,t){let r=new Set([n]),e=[n],i=Tn(t),s=rn(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=Sn(c);for(let u of f){let l=u.startsWith(".")?E.default.resolve(E.default.dirname(o),u):vn(u,i,s);if(!l)continue;let a=await Wn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){g.warn(`Error processing ${o}: ${x(c)}`)}}return r}function Sn(n){let t=new Set;for(let r of[Nn,Dn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function Wn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function rn(n){let t=E.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?E.default.resolve(t,n.data.compilerOptions.baseUrl):t}function Tn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=rn(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,E.default.join(e,c))}return t}function vn(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?E.default.join(r,n):null}var en=require("oxc-transform");async function sn(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=en.isolatedDeclaration(r,s);if(o)t.set(e,o)}catch(e){g.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),t}var S=d(require("node:fs/promises")),O=d(require("node:path")),Gn=require("oxc-transform");async function on(n,t){let r=O.default.resolve(n),e=O.default.resolve(r,t);if(!await S.default.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(O.default.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function cn(n,t,r,e,i){let{absoluteEntry:s}=await on(n,t),o=await tn(s,e),c=await sn(o);return nn(s,c,r,i)}function an(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=Y(),f=`${s}_${c}`;g.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ var jn=require("node:module");var hn=Object.create;var{getPrototypeOf:Cn,defineProperty:R,getOwnPropertyNames:G,getOwnPropertyDescriptor:Rn}=Object,k=Object.prototype.hasOwnProperty;var x=(n,t,r)=>{r=n!=null?hn(Cn(n)):{};let e=t||!n||!n.__esModule?R(r,"default",{value:n,enumerable:!0}):r;for(let i of G(n))if(!k.call(e,i))R(e,i,{get:()=>n[i],enumerable:!0});return e},T=new WeakMap,Bn=(n)=>{var t=T.get(n),r;if(t)return t;if(t=R({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")G(n).map((e)=>!k.call(t,e)&&R(t,e,{get:()=>n[e],enumerable:!(r=Rn(n,e))||r.enumerable}));return T.set(n,t),t};var On=(n,t)=>{for(var r in t)R(n,r,{get:t[r],enumerable:!0,configurable:!0,set:(e)=>t[r]=()=>e})};var Ln={};On(Ln,{defineWorkspace:()=>L,defineConfig:()=>H,build:()=>xn});module.exports=Bn(Ln);function H(n){return n}function L(n){return n}var F=require("rolldown"),nn=require("rolldown-plugin-dts");class N extends Error{constructor(n){super(n);this.name="BunupError"}}class b extends N{constructor(n){super(n);this.name="BunupBuildError"}}class d extends N{constructor(n){super(n);this.name="BunupDTSBuildError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)};var An=x(require("node:fs/promises")),Nn=x(require("node:path"));function Y(n,t){return{outdir:`${t}/${n.outDir}`,minify:Mn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function Mn(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function S(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function J(n=8){return Math.random().toString(36).substring(2,2+n)}function q(n,t){switch(n){case"esm":return".mjs";case"cjs":return B(t)?".cjs":".js";case"iife":return".global.js"}}function K(n,t){switch(n){case"esm":return".d.mts";case"cjs":return B(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function B(n){return n==="module"}function Q(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function Z(n,t){return n===void 0?t==="esm":n}function D(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function y(n,t=3){return n.split("/").slice(-t).join("/")}function U(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${S(t)}($|\\/|\\\\)`):t)}function O(n,t){return U(n.external||[]).concat(Q(t).map((r)=>new RegExp(`^${S(r)}($|\\/|\\\\)`)))}function j(n){return U(n.noExternal||[])}var X=x(require("node:path")),I=require("oxc-resolver");var w=x(require("path"));var m="\x00virtual:",P=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=w.default.resolve(w.default.dirname(e),t);if(t==="."){let o=w.default.join(w.default.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=w.default.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=w.default.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return _.add(r),e}return null}}};var z;function V(n){return{name:"bunup:types-resolve",buildStart(){z||=new I.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(r&&r.includes(o));else a=o.test(t)||!!(r&&o.test(r));return a}))return}let e=r?X.default.dirname(r):process.cwd(),{path:i}=await z.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function tn(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${m}${i}`,o=O(r,e),a=j(r),f;try{f=await F.rolldown({input:s,onwarn(l,c){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;c(l)},plugins:[P(t),typeof r.dts==="object"&&"resolve"in r.dts&&V(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),nn.dts()],external:(l)=>o.some((c)=>c.test(l))&&!a.some((c)=>c.test(l))});let{output:u}=await f.generate({});if(!u[0]?.code)throw new d("Generated bundle is empty");return u[0].code}catch(u){throw new d(`DTS bundling failed: ${p(u)}`)}finally{if(f)await f.close()}}var E=x(require("node:path"));class h{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(!h.instance)h.instance=new h;return h.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[u,...l]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),C=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${C}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${f}`}output(n,t={},r=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")}cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(n,t,r,e){let i=String(n),s=this.colors.default,o,a,f={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,f=r;for(let[l,c]of Object.entries(this.colors.progress))if(i.includes(l)){s=c;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:f.muted});this.output(u,f)}}var g=h.getInstance();var Sn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Dn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function rn(n,t){let r=new Set([n]),e=[n],i=Tn(t),s=en(t);while(e.length){let o=e.pop();if(!o)continue;try{let a=await Bun.file(o).text(),f=Wn(a);for(let u of f){let l=u.startsWith(".")?E.default.resolve(E.default.dirname(o),u):Gn(u,i,s);if(!l)continue;let c=await vn(l);if(c&&!r.has(c))r.add(c),e.push(c)}}catch(a){g.warn(`Error processing ${o}: ${p(a)}`)}}return r}function Wn(n){let t=new Set;for(let r of[Sn,Dn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function vn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function en(n){let t=E.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?E.default.resolve(t,n.data.compilerOptions.baseUrl):t}function Tn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=en(n);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");t.set(`^${o}$`,E.default.join(e,a))}return t}function Gn(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?E.default.join(r,n):null}var sn=require("oxc-transform");async function on(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=sn.isolatedDeclaration(r,s);if(o)t.set(e,o)}catch(e){g.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),t}var W=x(require("node:fs/promises")),M=x(require("node:path")),kn=require("oxc-transform");async function cn(n,t){let r=M.default.resolve(n),e=M.default.resolve(r,t);if(!await W.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(M.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function an(n,t,r,e,i){let{absoluteEntry:s}=await cn(n,t),o=await rn(s,e),a=await on(o);return tn(s,a,r,i)}function fn(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=J(),f=`${s}_${a}`;g.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${e[s]} -> ${s}.js
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=an(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=an(n);i(s,n)}return t}function fn(n,t){return`[dir]/${n}${t}`}var un=require("load-tsconfig");function gn(n){try{return un.loadTsConfig(".",n)}catch(t){return g.warn(`Failed to load tsconfig: ${x(t)}`),{path:n,data:{},files:[]}}}var ln=d(require("node:path"));async function mn(n){let t=ln.default.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return g.warn(`Failed to load package.json at ${t}: ${x(r)}`),{packageJson:null,path:t}}}function xn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var P=new Set;async function pn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await mn(t);if(r)g.cli(`Using package.json: ${h(e,2)}`,{muted:!0});let i=r?.type,s=B(n,r),o=j(n),c=[xn(s,o)],f=W(n.entry),u=L(n,t),l=n.format.flatMap((a)=>f.map((C)=>{return kn(n,t,C,a,i,c,u)}));if(await Promise.all(l),n.dts){let a=gn(n.preferredTsconfigPath);if(a.path)g.cli(`Using tsconfig: ${h(a.path,2)}`,{muted:!0});let C=n.format.filter(($)=>{if($==="iife"&&!R(i)&&n.format.includes("cjs"))return!1;return!0}),dn=typeof n.dts==="object"&&n.dts.entry?W(n.dts.entry):f;try{await Promise.all(dn.map(async($)=>{let wn=await cn(t,$.path,n,a,r);await Promise.all(C.map(async(En)=>{let $n=q(En,i),M=`${t}/${n.outDir}/${$.name}${$n}`;await Bun.write(M,wn);let yn=Bun.file(M).size||0;g.progress("DTS",h(M),D(yn),n.name)}))}))}catch($){throw new p(x($))}}}async function kn(n,t,r,e,i,s,o){let c=J(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:fn(r.name,c)},splitting:Q(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new y(a.message);else if(a.level==="warning")g.warn(a.message);else if(a.level==="info")g.info(a.message)});let u=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(u).size||0;g.progress(e.toUpperCase(),h(u),D(l),n.name)}
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=fn(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=fn(n);i(s,n)}return t}function un(n,t){return`[dir]/${n}${t}`}var gn=require("load-tsconfig");function ln(n){try{return gn.loadTsConfig(".",n)}catch(t){return g.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}var mn=x(require("node:path"));async function pn(n){let t=mn.default.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return g.warn(`Failed to load package.json at ${t}: ${p(r)}`),{packageJson:null,path:t}}}function dn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var _=new Set;async function xn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await pn(t);if(r)g.cli(`Using package.json: ${y(e,2)}`,{muted:!0,once:e});let i=r?.type,s=O(n,r),o=j(n),a=[dn(s,o)],f=v(n.entry),u=Y(n,t),l=n.format.flatMap((c)=>f.map((C)=>{return Hn(n,t,C,c,i,a,u)}));if(await Promise.all(l),n.dts){let c=ln(n.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${y(c.path,2)}`,{muted:!0,once:c.path});let C=n.format.filter(($)=>{if($==="iife"&&!B(i)&&n.format.includes("cjs"))return!1;return!0}),wn=typeof n.dts==="object"&&n.dts.entry?v(n.dts.entry):f;try{await Promise.all(wn.map(async($)=>{let En=await an(t,$.path,n,c,r);await Promise.all(C.map(async($n)=>{let bn=K($n,i),A=`${t}/${n.outDir}/${$.name}${bn}`;await Bun.write(A,En);let yn=Bun.file(A).size||0;g.progress("DTS",y(A),D(yn),n.name)}))}))}catch($){throw new d(p($))}}}async function Hn(n,t,r,e,i,s,o){let a=q(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:un(r.name,a)},splitting:Z(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new b(c.message);else if(c.level==="warning")g.warn(c.message);else if(c.level==="info")g.info(c.message)});let u=`${t}/${n.outDir}/${r.name}${a}`,l=Bun.file(u).size||0;g.progress(e.toUpperCase(),y(u),D(l),n.name)}
package/build/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- function on(n){return n}function cn(n){return n}import{rolldown as gn}from"rolldown";import{dts as ln}from"rolldown-plugin-dts";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends j{constructor(n){super(n);this.name="BunupBuildError"}}class p extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var x=(n)=>{if(n instanceof Error)return n.message;return String(n)};import An from"node:fs/promises";import Dn from"node:path";function D(n,t){return{outdir:`${t}/${n.outDir}`,minify:an(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function an(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function O(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function S(n=8){return Math.random().toString(36).substring(2,2+n)}function W(n,t){switch(n){case"esm":return".mjs";case"cjs":return C(t)?".cjs":".js";case"iife":return".global.js"}}function T(n,t){switch(n){case"esm":return".d.mts";case"cjs":return C(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(n){return n==="module"}function v(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function G(n,t){return n===void 0?t==="esm":n}function M(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function E(n,t=3){return n.split("/").slice(-t).join("/")}function k(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${O(t)}($|\\/|\\\\)`):t)}function b(n,t){return k(n.external||[]).concat(v(t).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function R(n){return k(n.noExternal||[])}import fn from"node:path";import{ResolverFactory as un}from"oxc-resolver";import $ from"path";var m="\x00virtual:",H=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=$.resolve($.dirname(e),t);if(t==="."){let o=$.join($.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=$.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=$.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return L.add(r),e}return null}}};var Y;function J(n){return{name:"bunup:types-resolve",buildStart(){Y||=new un({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?fn.dirname(r):process.cwd(),{path:i}=await Y.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function q(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${m}${i}`,o=b(r,e),c=R(r),f;try{f=await gn({input:s,onwarn(l,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;a(l)},plugins:[H(t),typeof r.dts==="object"&&"resolve"in r.dts&&J(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),ln()],external:(l)=>o.some((a)=>a.test(l))&&!c.some((a)=>a.test(l))});let{output:u}=await f.generate({});if(!u[0]?.code)throw new p("Generated bundle is empty");return u[0].code}catch(u){throw new p(`DTS bundling failed: ${x(u)}`)}finally{if(f)await f.close()}}import y from"node:path";var g={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[u,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${h}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(u,f)}};var mn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,xn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function K(n,t){let r=new Set([n]),e=[n],i=wn(t),s=Q(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=pn(c);for(let u of f){let l=u.startsWith(".")?y.resolve(y.dirname(o),u):En(u,i,s);if(!l)continue;let a=await dn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){g.warn(`Error processing ${o}: ${x(c)}`)}}return r}function pn(n){let t=new Set;for(let r of[mn,xn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function dn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function Q(n){let t=y.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?y.resolve(t,n.data.compilerOptions.baseUrl):t}function wn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=Q(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,y.join(e,c))}return t}function En(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?y.join(r,n):null}import{isolatedDeclaration as $n}from"oxc-transform";async function Z(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=$n(r,s);if(o)t.set(e,o)}catch(e){g.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),t}import U from"node:fs/promises";import A from"node:path";import{isolatedDeclaration as gt}from"oxc-transform";async function P(n,t){let r=A.resolve(n),e=A.resolve(r,t);if(!await U.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function _(n,t,r,e,i){let{absoluteEntry:s}=await P(n,t),o=await K(s,e),c=await Z(o);return q(s,c,r,i)}function z(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=S(),f=`${s}_${c}`;g.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function cn(n){return n}function an(n){return n}import{rolldown as ln}from"rolldown";import{dts as mn}from"rolldown-plugin-dts";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends j{constructor(n){super(n);this.name="BunupBuildError"}}class d extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)};import Nn from"node:fs/promises";import Dn from"node:path";function D(n,t){return{outdir:`${t}/${n.outDir}`,minify:fn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function fn(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function M(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(n=8){return Math.random().toString(36).substring(2,2+n)}function v(n,t){switch(n){case"esm":return".mjs";case"cjs":return C(t)?".cjs":".js";case"iife":return".global.js"}}function T(n,t){switch(n){case"esm":return".d.mts";case"cjs":return C(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(n){return n==="module"}function G(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function k(n,t){return n===void 0?t==="esm":n}function A(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function E(n,t=3){return n.split("/").slice(-t).join("/")}function H(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${M(t)}($|\\/|\\\\)`):t)}function R(n,t){return H(n.external||[]).concat(G(t).map((r)=>new RegExp(`^${M(r)}($|\\/|\\\\)`)))}function B(n){return H(n.noExternal||[])}import un from"node:path";import{ResolverFactory as gn}from"oxc-resolver";import $ from"path";var m="\x00virtual:",L=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(m))return t;if(!r?.startsWith(m)||!t.startsWith("."))return null;let e=r.slice(m.length),i=$.resolve($.dirname(e),t);if(t==="."){let o=$.join($.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=$.dirname(e)}if(n.has(i))return`${m}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${m}${s}`;if(t.startsWith(".")){let o=$.join(i,"index.d.ts");if(n.has(o))return`${m}${o}`}return null},load(t){if(t.startsWith(m)){let r=t.slice(m.length),e=n.get(r);if(e)return Y.add(r),e}return null}}};var J;function q(n){return{name:"bunup:types-resolve",buildStart(){J||=new gn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(m,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(r&&r.includes(o));else a=o.test(t)||!!(r&&o.test(r));return a}))return}let e=r?un.dirname(r):process.cwd(),{path:i}=await J.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function K(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${m}${i}`,o=R(r,e),a=B(r),f;try{f=await ln({input:s,onwarn(l,c){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;c(l)},plugins:[L(t),typeof r.dts==="object"&&"resolve"in r.dts&&q(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),mn()],external:(l)=>o.some((c)=>c.test(l))&&!a.some((c)=>c.test(l))});let{output:u}=await f.generate({});if(!u[0]?.code)throw new d("Generated bundle is empty");return u[0].code}catch(u){throw new d(`DTS bundling failed: ${p(u)}`)}finally{if(f)await f.close()}}import y from"node:path";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(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[u,...l]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${h}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${f}`}output(n,t={},r=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")}cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(n,t,r,e){let i=String(n),s=this.colors.default,o,a,f={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,f=r;for(let[l,c]of Object.entries(this.colors.progress))if(i.includes(l)){s=c;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:f.muted});this.output(u,f)}}var g=b.getInstance();var pn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,dn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Q(n,t){let r=new Set([n]),e=[n],i=En(t),s=Z(t);while(e.length){let o=e.pop();if(!o)continue;try{let a=await Bun.file(o).text(),f=xn(a);for(let u of f){let l=u.startsWith(".")?y.resolve(y.dirname(o),u):$n(u,i,s);if(!l)continue;let c=await wn(l);if(c&&!r.has(c))r.add(c),e.push(c)}}catch(a){g.warn(`Error processing ${o}: ${p(a)}`)}}return r}function xn(n){let t=new Set;for(let r of[pn,dn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function wn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function Z(n){let t=y.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?y.resolve(t,n.data.compilerOptions.baseUrl):t}function En(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=Z(n);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");t.set(`^${o}$`,y.join(e,a))}return t}function $n(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?y.join(r,n):null}import{isolatedDeclaration as bn}from"oxc-transform";async function U(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=bn(r,s);if(o)t.set(e,o)}catch(e){g.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),t}import P from"node:fs/promises";import N from"node:path";import{isolatedDeclaration as lt}from"oxc-transform";async function _(n,t){let r=N.resolve(n),e=N.resolve(r,t);if(!await P.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(N.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function z(n,t,r,e,i){let{absoluteEntry:s}=await _(n,t),o=await Q(s,e),a=await U(o);return K(s,a,r,i)}function X(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function S(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=W(),f=`${s}_${a}`;g.warn(`Output name conflict: "${s}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${e[s]} -> ${s}.js
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
12
12
  }
13
13
  }
14
14
 
15
- See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=z(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=z(n);i(s,n)}return t}function X(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as yn}from"load-tsconfig";function I(n){try{return yn(".",n)}catch(t){return g.warn(`Failed to load tsconfig: ${x(t)}`),{path:n,data:{},files:[]}}}import hn from"node:path";async function V(n){let t=hn.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return g.warn(`Failed to load package.json at ${t}: ${x(r)}`),{packageJson:null,path:t}}}function F(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var L=new Set;async function Cn(n,t){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.");let{packageJson:r,path:e}=await V(t);if(r)g.cli(`Using package.json: ${E(e,2)}`,{muted:!0});let i=r?.type,s=b(n,r),o=R(n),c=[F(s,o)],f=N(n.entry),u=D(n,t),l=n.format.flatMap((a)=>f.map((h)=>{return bn(n,t,h,a,i,c,u)}));if(await Promise.all(l),n.dts){let a=I(n.preferredTsconfigPath);if(a.path)g.cli(`Using tsconfig: ${E(a.path,2)}`,{muted:!0});let h=n.format.filter((d)=>{if(d==="iife"&&!C(i)&&n.format.includes("cjs"))return!1;return!0}),nn=typeof n.dts==="object"&&n.dts.entry?N(n.dts.entry):f;try{await Promise.all(nn.map(async(d)=>{let tn=await _(t,d.path,n,a,r);await Promise.all(h.map(async(rn)=>{let en=T(rn,i),B=`${t}/${n.outDir}/${d.name}${en}`;await Bun.write(B,tn);let sn=Bun.file(B).size||0;g.progress("DTS",E(B),M(sn),n.name)}))}))}catch(d){throw new p(x(d))}}}async function bn(n,t,r,e,i,s,o){let c=W(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:X(r.name,c)},splitting:G(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new w(a.message);else if(a.level==="warning")g.warn(a.message);else if(a.level==="info")g.info(a.message)});let u=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(u).size||0;g.progress(e.toUpperCase(),E(u),M(l),n.name)}export{cn as defineWorkspace,on as defineConfig,Cn as build};
15
+ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=X(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=X(n);i(s,n)}return t}function I(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as yn}from"load-tsconfig";function V(n){try{return yn(".",n)}catch(t){return g.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import hn from"node:path";async function F(n){let t=hn.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return g.warn(`Failed to load package.json at ${t}: ${p(r)}`),{packageJson:null,path:t}}}function nn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var Y=new Set;async function Cn(n,t){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.");let{packageJson:r,path:e}=await F(t);if(r)g.cli(`Using package.json: ${E(e,2)}`,{muted:!0,once:e});let i=r?.type,s=R(n,r),o=B(n),a=[nn(s,o)],f=S(n.entry),u=D(n,t),l=n.format.flatMap((c)=>f.map((h)=>{return Rn(n,t,h,c,i,a,u)}));if(await Promise.all(l),n.dts){let c=V(n.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,once:c.path});let h=n.format.filter((x)=>{if(x==="iife"&&!C(i)&&n.format.includes("cjs"))return!1;return!0}),tn=typeof n.dts==="object"&&n.dts.entry?S(n.dts.entry):f;try{await Promise.all(tn.map(async(x)=>{let rn=await z(t,x.path,n,c,r);await Promise.all(h.map(async(en)=>{let sn=T(en,i),O=`${t}/${n.outDir}/${x.name}${sn}`;await Bun.write(O,rn);let on=Bun.file(O).size||0;g.progress("DTS",E(O),A(on),n.name)}))}))}catch(x){throw new d(p(x))}}}async function Rn(n,t,r,e,i,s,o){let a=v(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:I(r.name,a)},splitting:k(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")g.warn(c.message);else if(c.level==="info")g.info(c.message)});let u=`${t}/${n.outDir}/${r.name}${a}`,l=Bun.file(u).size||0;g.progress(e.toUpperCase(),E(u),A(l),n.name)}export{an as defineWorkspace,cn as defineConfig,Cn as build};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.18",
3
+ "version": "0.3.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",
@@ -18,7 +18,7 @@
18
18
  "@types/bun": "^1.2.5",
19
19
  "@typescript-eslint/eslint-plugin": "^7.3.1",
20
20
  "bumpp": "^10.1.0",
21
- "bunup": "^0.3.17",
21
+ "bunup": "^0.3.18",
22
22
  "eslint": "^8.57.1",
23
23
  "husky": "^9.1.7",
24
24
  "prettier": "^3.5.3",