bunup 0.4.30 → 0.4.31

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
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
  import{build as Ge}from"rolldown";import{dts as Xe}from"rolldown-plugin-dts";var ee=!1;function B(e){ee=e??!1}class C{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!C.instance)C.instance=new C;return C.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:r,size:n,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[l,...f]=a.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${l}${p} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${f.join(" ")}${m}`}let c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${c}`}output(e,t={},r=console.log){if(ee)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let s=String(e),o=this.colors.default,i,a,c={};if(typeof r==="string")i=r,a=n;else if(r)i=r.size,a=r.identifier,c=r;for(let[f,p]of Object.entries(this.colors.progress))if(s.includes(f)){o=p;break}let l=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:c.muted});this.output(l,c)}}var u=C.getInstance();class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class h extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends E{constructor(e){super(e);this.name="BunupCLIError"}}class v extends E{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},Fe=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{u.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],q=(e,t)=>{let r=b(e),n=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof h)s="DTS ERROR";else if(e instanceof d)s="CLI ERROR";else if(e instanceof v)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";let o=Fe.find((i)=>i.pattern.test(r)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${n}${r}`);if(o)console.log(`
4
4
  `),o.logSolution(r),console.log(`
5
- `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},te=(e,t)=>{q(e,t),process.exit(1)};import re from"node:fs/promises";import We from"node:path";function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function se(e,t,r){return Array.isArray(e)?e.map((n)=>({...n,[t]:r})):{...e,[t]:r}}function ie(e){return Array.isArray(e)?e:[e]}function oe(e,t){switch(e){case"esm":return R(t)?".js":".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function ae(e,t){switch(e){case"esm":return R(t)?".d.ts":".d.mts";case"cjs":return R(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function G(e){return e==="node"||e==="bun"}function R(e){return e==="module"}function L(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function le(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function X(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function y(e,t=3){return e.split("/").slice(-t).join("/")}async function ce(e,t){let r=We.join(e,t);try{await re.rm(r,{recursive:!0,force:!0})}catch(n){throw new w(`Failed to clean output directory: ${n}`)}await re.mkdir(r,{recursive:!0})}function I(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function ue(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${V(t)}($|\\/|\\\\)`):t)}function D(e,t){return ue(e.external||[]).concat(le(t).map((r)=>new RegExp(`^${V(r)}($|\\/|\\\\)`)))}function A(e){return ue(e.noExternal||[])}import qe from"node:path";import{ResolverFactory as Ve}from"oxc-resolver";import{resolveTsImportPath as He}from"ts-import-resolver";var O="\x00dts:",fe=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(Y(n))return n;if(!s||!Y(s))return null;let o=t.tsconfig?He({path:n,importer:S(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!o)return null;let i=$(o);if(e.has(i))return _(i);return null},load(n){if(n.startsWith(O)){let s=S(n),o=e.get(s);if(o)return T.add(s),o}return null}}};function $(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function Y(e){return e.startsWith(O)}function S(e){return e.replace(O,"")}function _(e){return`${O}${e}`}var me;function pe(e){return{name:"bunup:types-resolve",buildStart(){me||=new Ve({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?S(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?qe.dirname(n):process.cwd(),{path:o}=await me.async(s,t);return o}}}async function de(e,t,r,n,s,o){let i=$(e),a=_(i),c=D(r,n),l=A(r);try{let{output:f}=await Ge({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(p,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;m(p)},plugins:[fe(t,s,o),typeof r.dts==="object"&&"resolve"in r.dts&&pe(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Xe({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>c.some((m)=>m.test(p))&&!l.some((m)=>m.test(p))});if(!f[0]?.code)return u.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new h(`DTS bundling failed for entry "${e}": ${b(f)}`)}}import{resolveTsImportPath as Ye}from"ts-import-resolver";var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Je=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qe=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function rt(e){let t=new Set,r=[Ke,Je,ze,Qe,Ze,et,tt];for(let n of r){let s=e.matchAll(n);for(let o of s)if(o[1])t.add(o[1])}return t}async function ge(e,t,r){let n=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=rt(i);for(let c of a){let l=t.tsconfig?Ye({path:c,importer:o,tsconfig:t.tsconfig,rootDir:r}):null;if(!l)continue;if(!n.has(l))n.add(l),s.push(l)}}catch(i){u.warn(`Error processing ${o}: ${b(i)}`)}}return n}import{isolatedDeclaration as nt}from"oxc-transform";async function he(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=$(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:i}=nt(r,o);if(i)t.set(n,i)}catch(n){u.warn(`Failed to generate declaration for ${r}: ${b(n)}`)}})),t}import be from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function ye(e,t){let r=K.resolve(e),n=K.resolve(r,t);if(!await be.exists(r))throw new h(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new h(`Entry file does not exist: ${n}`);if(!I(n))throw new h(`Entry file must be a TypeScript file: ${n}`);if(K.relative(r,n).startsWith(".."))throw new h(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function xe(e){let t=!1;if(await Promise.all([...e].map(async(r)=>{try{let n=r.replace(/\.d\.ts$/,".ts"),s=await Bun.file(n).text(),{errors:o}=st(n,s);for(let i of o){if(!t)console.log(`
5
+ `);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},te=(e,t)=>{q(e,t),process.exit(1)};import re from"node:fs/promises";import We from"node:path";function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function se(e,t,r){return Array.isArray(e)?e.map((n)=>({...n,[t]:r})):{...e,[t]:r}}function ie(e){return Array.isArray(e)?e:[e]}function oe(e,t){switch(e){case"esm":return R(t)?".js":".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function ae(e,t){switch(e){case"esm":return R(t)?".d.ts":".d.mts";case"cjs":return R(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function G(e){return e==="node"||e==="bun"}function R(e){return e==="module"}function L(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function le(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function X(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function y(e,t=3){return e.split("/").slice(-t).join("/")}async function ce(e,t){let r=We.join(e,t);try{await re.rm(r,{recursive:!0,force:!0})}catch(n){throw new w(`Failed to clean output directory: ${n}`)}await re.mkdir(r,{recursive:!0})}function I(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function ue(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${V(t)}($|\\/|\\\\)`):t)}function D(e,t){return ue(e.external||[]).concat(le(t).map((r)=>new RegExp(`^${V(r)}($|\\/|\\\\)`)))}function A(e){return ue(e.noExternal||[])}import qe from"node:path";import{ResolverFactory as Ve}from"oxc-resolver";import{resolveTsImportPath as He}from"ts-import-resolver";var O="\x00dts:",fe=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(Y(n))return n;if(!s||!Y(s))return null;let o=t.tsconfig?He({path:n,importer:S(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!o)return null;let i=$(o);if(e.has(i))return _(i);return null},load(n){if(n.startsWith(O)){let s=S(n),o=e.get(s);if(o)return T.add(s),o}return null}}};function $(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function Y(e){return e.startsWith(O)}function S(e){return e.replace(O,"")}function _(e){return`${O}${e}`}var me;function pe(e){return{name:"bunup:types-resolve",buildStart(){me||=new Ve({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?S(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?qe.dirname(n):process.cwd(),{path:o}=await me.async(s,t);return o}}}async function de(e,t,r,n,s,o){let i=$(e),a=_(i),c=D(r,n),l=A(r);try{let{output:f}=await Ge({input:a,output:{dir:r.outDir},write:!1,onwarn(p,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;m(p)},plugins:[fe(t,s,o),typeof r.dts==="object"&&"resolve"in r.dts&&pe(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Xe({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>c.some((m)=>m.test(p))&&!l.some((m)=>m.test(p))});if(!f[0]?.code)return u.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new h(`DTS bundling failed for entry "${e}": ${b(f)}`)}}import{resolveTsImportPath as Ye}from"ts-import-resolver";var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Je=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qe=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function rt(e){let t=new Set,r=[Ke,Je,ze,Qe,Ze,et,tt];for(let n of r){let s=e.matchAll(n);for(let o of s)if(o[1])t.add(o[1])}return t}async function ge(e,t,r){let n=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=rt(i);for(let c of a){let l=t.tsconfig?Ye({path:c,importer:o,tsconfig:t.tsconfig,rootDir:r}):null;if(!l)continue;if(!n.has(l))n.add(l),s.push(l)}}catch(i){u.warn(`Error processing ${o}: ${b(i)}`)}}return n}import{isolatedDeclaration as nt}from"oxc-transform";async function he(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=$(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:i}=nt(r,o);if(i)t.set(n,i)}catch(n){u.warn(`Failed to generate declaration for ${r}: ${b(n)}`)}})),t}import be from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function ye(e,t){let r=K.resolve(e),n=K.resolve(r,t);if(!await be.exists(r))throw new h(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new h(`Entry file does not exist: ${n}`);if(!I(n))throw new h(`Entry file must be a TypeScript file: ${n}`);if(K.relative(r,n).startsWith(".."))throw new h(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function xe(e){let t=!1;if(await Promise.all([...e].map(async(r)=>{try{let n=r.replace(/\.d\.ts$/,".ts"),s=await Bun.file(n).text(),{errors:o}=st(n,s);for(let i of o){if(!t)console.log(`
6
6
  `);let a=i.labels[0],c=a?it(s,a.start):"",f=`${y(n)}${c}: ${ot(i.message)}`;u.warn(f),t=!0}}catch{}})),t)u.info(`
7
7
  You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
8
8
  `)}function it(e,t){if(t===void 0)return"";let r=e.slice(0,t).split(`
@@ -31,7 +31,7 @@ See: https://bunup.arshadyaseen.com/documentation/#named-entries`,{muted:!0,vert
31
31
  const importMetaUrl = pathToFileURL(__filename).href;
32
32
 
33
33
  `}};function De({format:e,target:t,shims:r}){let s=ct(r).map((o)=>J[o]).filter((o)=>o.appliesTo(e,t));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:lt},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((m)=>m.isNeededInFile(a));if(c.length===0)return;let{shebangLine:l,codeContent:f}=ut(a),p=c.map((m)=>m.generateCode()).join("");return{contents:l+p+f}})}}}function ct(e){if(e===!0)return Object.keys(J);if(!e)return[];return Object.entries(e).filter(([t,r])=>r&&(t in J)).map(([t])=>t)}function ut(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
34
- `);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var T=new Set;async function k(e,t){let r=j(e);if(!r.entry||r.entry.length===0||!r.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)ce(t,r.outDir);B(r.silent);let{packageJson:n,path:s}=await Te(t);if(n&&s)u.cli(`Using package.json: ${y(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=P(r.entry),i=n?.type,a=D(r,n),c=A(r);if(!r.dtsOnly){let l=[Ie(a,c)],f=r.format.flatMap((p)=>o.map((m)=>{return ft(r,t,m,p,i,l)}));await Promise.all(f)}if(r.dts||r.dtsOnly){let l=await Se(t,r.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${y(l.path,2)}`,{muted:!0,identifier:r.name,once:`${l.path}:${r.name}`});let f=r.format.filter((m)=>{if(m==="iife"&&!R(i)&&r.format.includes("cjs"))return!1;return!0}),p=typeof r.dts==="object"&&r.dts.entry?P(r.dts.entry):Ce(o);try{await Promise.all(p.map(async(m)=>{let W=await we(t,m.path,r,l,n);await Promise.all(f.map(async(Z)=>{let Ne=r.outputExtension?.({format:Z,packageType:i,options:r,entry:m}).dts??ae(Z,i),H=`${t}/${r.outDir}/${m.name}${Ne}`;await Bun.write(H,W);let Ue=Bun.file(H).size||0;u.progress("DTS",y(H),X(Ue),r.name)}))}))}catch(m){throw new h(b(m))}}}async function ft(e,t,r,n,s,o){let i=e.outputExtension?.({format:n,packageType:s,options:e,entry:r}).js??oe(n,s),a=await Bun.build({entrypoints:[`${t}/${r.path}`],format:n,naming:{entry:Ee(r.name,i)},splitting:ve(e.splitting,n),bytecode:Pe(e.bytecode,n),define:Be(e.define,e.shims,e.env,n),minify:Oe(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Le(e.env),plugins:[...o,De({format:n,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${r.name}${i}`,l=Bun.file(c).size||0;u.progress(n.toUpperCase(),y(c),X(l),e.name)}var N="0.4.30";var Ae="https://bun.sh/docs/installation",_e="https://bunup.arshadyaseen.com/documentation/#cli-options";function g(e){return(t,r)=>{r[e]=t===!0||t==="true"}}function x(e){return(t,r)=>{if(typeof t==="string")r[e]=t;else throw new d(`Option --${e} requires a string value`)}}function z(e){return(t,r)=>{if(typeof t==="string")r[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function pt(e){return(t,r)=>{if(typeof t==="boolean")r[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")r[e]=t.toLowerCase()==="true";else r[e]=t;else throw new d(`Option --${e} requires a boolean or string value`)}}function dt(){console.log(`
34
+ `);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var T=new Set;async function k(e,t){let r=j(e);if(!r.entry||r.entry.length===0||!r.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)ce(t,r.outDir);B(r.silent);let{packageJson:n,path:s}=await Te(t);if(n&&s)u.cli(`Using package.json: ${y(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=P(r.entry),i=n?.type,a=D(r,n),c=A(r);if(!r.dtsOnly){let l=[Ie(a,c)],f=r.format.flatMap((p)=>o.map((m)=>{return ft(r,t,m,p,i,l)}));await Promise.all(f)}if(r.dts||r.dtsOnly){let l=await Se(t,r.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${y(l.path,2)}`,{muted:!0,identifier:r.name,once:`${l.path}:${r.name}`});let f=r.format.filter((m)=>{if(m==="iife"&&!R(i)&&r.format.includes("cjs"))return!1;return!0}),p=typeof r.dts==="object"&&r.dts.entry?P(r.dts.entry):Ce(o);try{await Promise.all(p.map(async(m)=>{let W=await we(t,m.path,r,l,n);await Promise.all(f.map(async(Z)=>{let Ne=r.outputExtension?.({format:Z,packageType:i,options:r,entry:m}).dts??ae(Z,i),H=`${t}/${r.outDir}/${m.name}${Ne}`;await Bun.write(H,W);let Ue=Bun.file(H).size||0;u.progress("DTS",y(H),X(Ue),r.name)}))}))}catch(m){throw new h(b(m))}}}async function ft(e,t,r,n,s,o){let i=e.outputExtension?.({format:n,packageType:s,options:e,entry:r}).js??oe(n,s),a=await Bun.build({entrypoints:[`${t}/${r.path}`],format:n,naming:{entry:Ee(r.name,i)},splitting:ve(e.splitting,n),bytecode:Pe(e.bytecode,n),define:Be(e.define,e.shims,e.env,n),minify:Oe(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Le(e.env),plugins:[...o,De({format:n,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${r.name}${i}`,l=Bun.file(c).size||0;u.progress(n.toUpperCase(),y(c),X(l),e.name)}var N="0.4.31";var Ae="https://bun.sh/docs/installation",_e="https://bunup.arshadyaseen.com/documentation/#cli-options";function g(e){return(t,r)=>{r[e]=t===!0||t==="true"}}function x(e){return(t,r)=>{if(typeof t==="string")r[e]=t;else throw new d(`Option --${e} requires a string value`)}}function z(e){return(t,r)=>{if(typeof t==="string")r[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function pt(e){return(t,r)=>{if(typeof t==="boolean")r[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")r[e]=t.toLowerCase()==="true";else r[e]=t;else throw new d(`Option --${e} requires a boolean or string value`)}}function dt(){console.log(`
35
35
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
36
36
  `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${_e}\x1B[0m
37
37
  `),process.exit(0)}function gt(){console.log(N),process.exit(0)}var Me={name:{flags:["n","name"],handler:x("name")},format:{flags:["f","format"],handler:z("format")},outDir:{flags:["o","out-dir"],handler:x("outDir")},minify:{flags:["m","minify"],handler:g("minify")},watch:{flags:["w","watch"],handler:g("watch")},dts:{flags:["d","dts"],handler:g("dts")},banner:{flags:["bn","banner"],handler:x("banner")},footer:{flags:["ft","footer"],handler:x("footer")},external:{flags:["e","external"],handler:z("external")},sourcemap:{flags:["sm","sourcemap"],handler:pt("sourcemap")},target:{flags:["t","target"],handler:x("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:g("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:g("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:g("minifySyntax")},clean:{flags:["c","clean"],handler:g("clean")},splitting:{flags:["s","splitting"],handler:g("splitting")},noExternal:{flags:["ne","no-external"],handler:z("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:x("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:g("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:g("dtsOnly")},silent:{flags:["silent"],handler:g("silent")},config:{flags:["config"],handler:x("config")},publicPath:{flags:["pp","public-path"],handler:x("publicPath")},env:{flags:["env"],handler:x("env")},shims:{flags:["shims"],handler:g("shims")},entry:{flags:["entry"],handler:(e,t,r)=>{if(typeof e!=="string")throw new d(`Entry${r?` --entry.${r}`:""} requires a string value`);let n=t.entry||{};if(r){if(n[r])u.warn(`Duplicate entry name '${r}' provided via --entry.${r}. Overwriting previous entry.`);n[r]=e}else{let s=M(e);if(n[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);n[s]=e}t.entry=n}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>dt()},version:{flags:["v","version"],handler:()=>gt()}},U={};for(let e of Object.values(Me))for(let t of e.flags)U[t]=e.handler;function je(e){let t={};for(let r=0;r<e.length;r++){let n=e[r];if(n.startsWith("--")){let s,o;if(n.includes("=")){let[i,a]=n.slice(2).split("=",2);s=i,o=a}else{s=n.slice(2);let i=e[r+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")r++}if(s.includes(".")){let[i,a]=s.split(".",2),c=U[i];if(c)c(o,t,a);else throw new d(`Unknown option: --${s}`)}else{let i=U[s];if(i)i(o,t);else throw new d(`Unknown option: --${s}`)}}else if(n.startsWith("-")){let s=n.slice(1),o=e[r+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")r++;let a=U[s];if(a)a(i,t);else throw new d(`Unknown option: -${s}`)}else Me.entry.handler(n,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var We=require("node:module");var _e=Object.create;var{getPrototypeOf:ve,defineProperty:w,getOwnPropertyNames:V,getOwnPropertyDescriptor:je}=Object,G=Object.prototype.hasOwnProperty;var R=(e,t,r)=>{r=e!=null?_e(ve(e)):{};let n=t||!e||!e.__esModule?w(r,"default",{value:e,enumerable:!0}):r;for(let s of V(e))if(!G.call(n,s))w(n,s,{get:()=>e[s],enumerable:!0});return n},U=new WeakMap,Ne=(e)=>{var t=U.get(e),r;if(t)return t;if(t=w({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")V(e).map((n)=>!G.call(t,n)&&w(t,n,{get:()=>e[n],enumerable:!(r=je(e,n))||r.enumerable}));return U.set(e,t),t};var Fe=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0,configurable:!0,set:(n)=>t[r]=()=>n})};var tt={};Fe(tt,{defineWorkspace:()=>X,defineConfig:()=>q,build:()=>Le});module.exports=Ne(tt);function q(e){return e}function X(e){return e}var le=require("rolldown"),ce=require("rolldown-plugin-dts");var H=!1;function K(e){H=e??!1}class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:r,size:n,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${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),d=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${u}${d} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${c}`}let m=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${a}${m}`}output(e,t={},r=console.log){if(H)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let s=String(e),i=this.colors.default,o,a,m={};if(typeof r==="string")o=r,a=n;else if(r)o=r.size,a=r.identifier,m=r;for(let[l,d]of Object.entries(this.colors.progress))if(s.includes(l)){i=d;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:m.muted});this.output(u,m)}}var f=x.getInstance();class L extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends L{constructor(e){super(e);this.name="BunupBuildError"}}class g extends L{constructor(e){super(e);this.name="BunupDTSBuildError"}}var p=(e)=>{if(e instanceof Error)return e.message;return String(e)};var M=R(require("node:fs/promises")),Y=R(require("node:path"));function O(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function Z(e,t){switch(e){case"esm":return b(t)?".js":".mjs";case"cjs":return b(t)?".cjs":".js";case"iife":return".global.js"}}function z(e,t){switch(e){case"esm":return b(t)?".d.ts":".d.mts";case"cjs":return b(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function A(e){return e==="node"||e==="bun"}function b(e){return e==="module"}function J(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function _(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function y(e,t=3){return e.split("/").slice(-t).join("/")}async function ee(e,t){let r=Y.default.join(e,t);try{await M.default.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await M.default.mkdir(r,{recursive:!0})}function $(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function te(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${O(t)}($|\\/|\\\\)`):t)}function T(e,t){return te(e.external||[]).concat(J(t).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function P(e){return te(e.noExternal||[])}var ie=R(require("node:path")),ae=require("oxc-resolver");var re=require("ts-import-resolver");var S="\x00dts:",ne=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(v(n))return n;if(!s||!v(s))return null;let i=t.tsconfig?re.resolveTsImportPath({path:n,importer:C(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!i)return null;let o=E(i);if(e.has(o))return B(o);return null},load(n){if(n.startsWith(S)){let s=C(n),i=e.get(s);if(i)return se.add(s),i}return null}}};function E(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function v(e){return e.startsWith(S)}function C(e){return e.replace(S,"")}function B(e){return`${S}${e}`}var oe;function ue(e){return{name:"bunup:types-resolve",buildStart(){oe||=new ae.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?C(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?ie.default.dirname(n):process.cwd(),{path:i}=await oe.async(s,t);return i}}}async function me(e,t,r,n,s,i){let o=E(e),a=B(o),m=T(r,n),u=P(r);try{let{output:l}=await le.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(d,c){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(d.code??""))return;c(d)},plugins:[ne(t,s,i),typeof r.dts==="object"&&"resolve"in r.dts&&ue(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),ce.dts({dtsInput:!0,emitDtsOnly:!0})],external:(d)=>m.some((c)=>c.test(d))&&!u.some((c)=>c.test(d))});if(!l[0]?.code)return f.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return l[0].code}catch(l){throw new g(`DTS bundling failed for entry "${e}": ${p(l)}`)}}var fe=require("ts-import-resolver");var ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ue=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ve=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ge=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qe=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Xe=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,He=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Ke(e){let t=new Set,r=[ke,Ue,Ve,Ge,qe,Xe,He];for(let n of r){let s=e.matchAll(n);for(let i of s)if(i[1])t.add(i[1])}return t}async function de(e,t,r){let n=new Set([e]),s=[e];while(s.length){let i=s.pop();if(!i)continue;try{let o=await Bun.file(i).text(),a=Ke(o);for(let m of a){let u=t.tsconfig?fe.resolveTsImportPath({path:m,importer:i,tsconfig:t.tsconfig,rootDir:r}):null;if(!u)continue;if(!n.has(u))n.add(u),s.push(u)}}catch(o){f.warn(`Error processing ${i}: ${p(o)}`)}}return n}var ge=require("oxc-transform");async function pe(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let i=await Bun.file(r).text(),{code:o}=ge.isolatedDeclaration(r,i);if(o)t.set(n,o)}catch(n){f.warn(`Failed to generate declaration for ${r}: ${p(n)}`)}})),t}var j=R(require("node:fs/promises")),D=R(require("node:path")),Ye=require("oxc-transform");async function xe(e,t){let r=D.default.resolve(e),n=D.default.resolve(r,t);if(!await j.default.exists(r))throw new g(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new g(`Entry file does not exist: ${n}`);if(!$(n))throw new g(`Entry file must be a TypeScript file: ${n}`);if(D.default.relative(r,n).startsWith(".."))throw new g(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function he(e,t,r,n,s){let{absoluteEntry:i}=await xe(e,t),o=await de(i,n,e),a=await pe(o);return me(i,a,r,s,n,e)}function be(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,s={};function i(o,a){if(n.has(o)){let m=Q(),u=`${o}_${m}`;if(t)f.warn(`Output name conflict: "${o}" is used by multiple files.
1
+ var We=require("node:module");var _e=Object.create;var{getPrototypeOf:ve,defineProperty:w,getOwnPropertyNames:V,getOwnPropertyDescriptor:je}=Object,G=Object.prototype.hasOwnProperty;var R=(e,t,r)=>{r=e!=null?_e(ve(e)):{};let n=t||!e||!e.__esModule?w(r,"default",{value:e,enumerable:!0}):r;for(let s of V(e))if(!G.call(n,s))w(n,s,{get:()=>e[s],enumerable:!0});return n},U=new WeakMap,Ne=(e)=>{var t=U.get(e),r;if(t)return t;if(t=w({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")V(e).map((n)=>!G.call(t,n)&&w(t,n,{get:()=>e[n],enumerable:!(r=je(e,n))||r.enumerable}));return U.set(e,t),t};var Fe=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0,configurable:!0,set:(n)=>t[r]=()=>n})};var tt={};Fe(tt,{defineWorkspace:()=>X,defineConfig:()=>q,build:()=>Le});module.exports=Ne(tt);function q(e){return e}function X(e){return e}var le=require("rolldown"),ce=require("rolldown-plugin-dts");var H=!1;function K(e){H=e??!1}class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:r,size:n,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${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),d=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${u}${d} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${c}`}let m=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${a}${m}`}output(e,t={},r=console.log){if(H)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let s=String(e),i=this.colors.default,o,a,m={};if(typeof r==="string")o=r,a=n;else if(r)o=r.size,a=r.identifier,m=r;for(let[l,d]of Object.entries(this.colors.progress))if(s.includes(l)){i=d;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:m.muted});this.output(u,m)}}var f=x.getInstance();class L extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends L{constructor(e){super(e);this.name="BunupBuildError"}}class g extends L{constructor(e){super(e);this.name="BunupDTSBuildError"}}var p=(e)=>{if(e instanceof Error)return e.message;return String(e)};var M=R(require("node:fs/promises")),Y=R(require("node:path"));function O(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function Z(e,t){switch(e){case"esm":return b(t)?".js":".mjs";case"cjs":return b(t)?".cjs":".js";case"iife":return".global.js"}}function z(e,t){switch(e){case"esm":return b(t)?".d.ts":".d.mts";case"cjs":return b(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function A(e){return e==="node"||e==="bun"}function b(e){return e==="module"}function J(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function _(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function y(e,t=3){return e.split("/").slice(-t).join("/")}async function ee(e,t){let r=Y.default.join(e,t);try{await M.default.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await M.default.mkdir(r,{recursive:!0})}function $(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function te(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${O(t)}($|\\/|\\\\)`):t)}function T(e,t){return te(e.external||[]).concat(J(t).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function P(e){return te(e.noExternal||[])}var ie=R(require("node:path")),ae=require("oxc-resolver");var re=require("ts-import-resolver");var S="\x00dts:",ne=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(v(n))return n;if(!s||!v(s))return null;let i=t.tsconfig?re.resolveTsImportPath({path:n,importer:C(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!i)return null;let o=E(i);if(e.has(o))return B(o);return null},load(n){if(n.startsWith(S)){let s=C(n),i=e.get(s);if(i)return se.add(s),i}return null}}};function E(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function v(e){return e.startsWith(S)}function C(e){return e.replace(S,"")}function B(e){return`${S}${e}`}var oe;function ue(e){return{name:"bunup:types-resolve",buildStart(){oe||=new ae.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?C(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?ie.default.dirname(n):process.cwd(),{path:i}=await oe.async(s,t);return i}}}async function me(e,t,r,n,s,i){let o=E(e),a=B(o),m=T(r,n),u=P(r);try{let{output:l}=await le.build({input:a,output:{dir:r.outDir},write:!1,onwarn(d,c){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(d.code??""))return;c(d)},plugins:[ne(t,s,i),typeof r.dts==="object"&&"resolve"in r.dts&&ue(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),ce.dts({dtsInput:!0,emitDtsOnly:!0})],external:(d)=>m.some((c)=>c.test(d))&&!u.some((c)=>c.test(d))});if(!l[0]?.code)return f.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return l[0].code}catch(l){throw new g(`DTS bundling failed for entry "${e}": ${p(l)}`)}}var fe=require("ts-import-resolver");var ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ue=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ve=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ge=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qe=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Xe=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,He=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Ke(e){let t=new Set,r=[ke,Ue,Ve,Ge,qe,Xe,He];for(let n of r){let s=e.matchAll(n);for(let i of s)if(i[1])t.add(i[1])}return t}async function de(e,t,r){let n=new Set([e]),s=[e];while(s.length){let i=s.pop();if(!i)continue;try{let o=await Bun.file(i).text(),a=Ke(o);for(let m of a){let u=t.tsconfig?fe.resolveTsImportPath({path:m,importer:i,tsconfig:t.tsconfig,rootDir:r}):null;if(!u)continue;if(!n.has(u))n.add(u),s.push(u)}}catch(o){f.warn(`Error processing ${i}: ${p(o)}`)}}return n}var ge=require("oxc-transform");async function pe(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let i=await Bun.file(r).text(),{code:o}=ge.isolatedDeclaration(r,i);if(o)t.set(n,o)}catch(n){f.warn(`Failed to generate declaration for ${r}: ${p(n)}`)}})),t}var j=R(require("node:fs/promises")),D=R(require("node:path")),Ye=require("oxc-transform");async function xe(e,t){let r=D.default.resolve(e),n=D.default.resolve(r,t);if(!await j.default.exists(r))throw new g(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new g(`Entry file does not exist: ${n}`);if(!$(n))throw new g(`Entry file must be a TypeScript file: ${n}`);if(D.default.relative(r,n).startsWith(".."))throw new g(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function he(e,t,r,n,s){let{absoluteEntry:i}=await xe(e,t),o=await de(i,n,e),a=await pe(o);return me(i,a,r,s,n,e)}function be(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,s={};function i(o,a){if(n.has(o)){let m=Q(),u=`${o}_${m}`;if(t)f.warn(`Output name conflict: "${o}" is used by multiple files.
2
2
  Bunup uses filenames without extensions as output names by default.
3
3
 
4
4
  ${s[o]} -> ${o}.js
package/build/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- function ye(e){return e}function Ee(e){return e}import{build as $e}from"rolldown";import{dts as Te}from"rolldown-plugin-dts";var j=!1;function N(e){j=e??!1}class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:r,size:n,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),d=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),c=o?` \x1B[48;5;${e};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${s}${u}${d} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${c}`}let m=o?` \x1B[48;5;${e};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${s}${a}${m}`}output(e,t={},r=console.log){if(j)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let o=String(e),i=this.colors.default,s,a,m={};if(typeof r==="string")s=r,a=n;else if(r)s=r.size,a=r.identifier,m=r;for(let[l,d]of Object.entries(this.colors.progress))if(o.includes(l)){i=d;break}let u=this.formatMessage({colorCode:i,label:o,message:t,size:s,identifier:a,muted:m.muted});this.output(u,m)}}var f=x.getInstance();class B extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends B{constructor(e){super(e);this.name="BunupBuildError"}}class g extends B{constructor(e){super(e);this.name="BunupDTSBuildError"}}var p=(e)=>{if(e instanceof Error)return e.message;return String(e)};import F from"node:fs/promises";import we from"node:path";function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function k(e,t){switch(e){case"esm":return b(t)?".js":".mjs";case"cjs":return b(t)?".cjs":".js";case"iife":return".global.js"}}function U(e,t){switch(e){case"esm":return b(t)?".d.ts":".d.mts";case"cjs":return b(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function I(e){return e==="node"||e==="bun"}function b(e){return e==="module"}function V(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function L(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function y(e,t=3){return e.split("/").slice(-t).join("/")}async function G(e,t){let r=we.join(e,t);try{await F.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await F.mkdir(r,{recursive:!0})}function C(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function q(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${D(t)}($|\\/|\\\\)`):t)}function S(e,t){return q(e.external||[]).concat(V(t).map((r)=>new RegExp(`^${D(r)}($|\\/|\\\\)`)))}function $(e){return q(e.noExternal||[])}import Ce from"node:path";import{ResolverFactory as Se}from"oxc-resolver";import{resolveTsImportPath as Re}from"ts-import-resolver";var R="\x00dts:",X=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,o){if(M(n))return n;if(!o||!M(o))return null;let i=t.tsconfig?Re({path:n,importer:w(o),tsconfig:t.tsconfig,rootDir:r}):null;if(!i)return null;let s=E(i);if(e.has(s))return T(s);return null},load(n){if(n.startsWith(R)){let o=w(n),i=e.get(o);if(i)return H.add(o),i}return null}}};function E(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function M(e){return e.startsWith(R)}function w(e){return e.replace(R,"")}function T(e){return`${R}${e}`}var K;function Y(e){return{name:"bunup:types-resolve",buildStart(){K||=new Se({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?w(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let o=n?Ce.dirname(n):process.cwd(),{path:i}=await K.async(o,t);return i}}}async function Q(e,t,r,n,o,i){let s=E(e),a=T(s),m=S(r,n),u=$(r);try{let{output:l}=await $e({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(d,c){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(d.code??""))return;c(d)},plugins:[X(t,o,i),typeof r.dts==="object"&&"resolve"in r.dts&&Y(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Te({dtsInput:!0,emitDtsOnly:!0})],external:(d)=>m.some((c)=>c.test(d))&&!u.some((c)=>c.test(d))});if(!l[0]?.code)return f.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return l[0].code}catch(l){throw new g(`DTS bundling failed for entry "${e}": ${p(l)}`)}}import{resolveTsImportPath as Pe}from"ts-import-resolver";var Be=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,De=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ie=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Le=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Me=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Oe=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ae=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function _e(e){let t=new Set,r=[Be,De,Ie,Le,Me,Oe,Ae];for(let n of r){let o=e.matchAll(n);for(let i of o)if(i[1])t.add(i[1])}return t}async function Z(e,t,r){let n=new Set([e]),o=[e];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=_e(s);for(let m of a){let u=t.tsconfig?Pe({path:m,importer:i,tsconfig:t.tsconfig,rootDir:r}):null;if(!u)continue;if(!n.has(u))n.add(u),o.push(u)}}catch(s){f.warn(`Error processing ${i}: ${p(s)}`)}}return n}import{isolatedDeclaration as ve}from"oxc-transform";async function z(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let i=await Bun.file(r).text(),{code:s}=ve(r,i);if(s)t.set(n,s)}catch(n){f.warn(`Failed to generate declaration for ${r}: ${p(n)}`)}})),t}import J from"node:fs/promises";import O from"node:path";import{isolatedDeclaration as It}from"oxc-transform";async function ee(e,t){let r=O.resolve(e),n=O.resolve(r,t);if(!await J.exists(r))throw new g(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new g(`Entry file does not exist: ${n}`);if(!C(n))throw new g(`Entry file must be a TypeScript file: ${n}`);if(O.relative(r,n).startsWith(".."))throw new g(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function te(e,t,r,n,o){let{absoluteEntry:i}=await ee(e,t),s=await Z(i,n,e),a=await z(s);return Q(i,a,r,o,n,e)}function re(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,o={};function i(s,a){if(n.has(s)){let m=W(),u=`${s}_${m}`;if(t)f.warn(`Output name conflict: "${s}" is used by multiple files.
1
+ function ye(e){return e}function Ee(e){return e}import{build as $e}from"rolldown";import{dts as Te}from"rolldown-plugin-dts";var j=!1;function N(e){j=e??!1}class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:r,size:n,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),d=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),c=o?` \x1B[48;5;${e};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${s}${u}${d} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${c}`}let m=o?` \x1B[48;5;${e};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${s}${a}${m}`}output(e,t={},r=console.log){if(j)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let o=String(e),i=this.colors.default,s,a,m={};if(typeof r==="string")s=r,a=n;else if(r)s=r.size,a=r.identifier,m=r;for(let[l,d]of Object.entries(this.colors.progress))if(o.includes(l)){i=d;break}let u=this.formatMessage({colorCode:i,label:o,message:t,size:s,identifier:a,muted:m.muted});this.output(u,m)}}var f=x.getInstance();class B extends Error{constructor(e){super(e);this.name="BunupError"}}class h extends B{constructor(e){super(e);this.name="BunupBuildError"}}class g extends B{constructor(e){super(e);this.name="BunupDTSBuildError"}}var p=(e)=>{if(e instanceof Error)return e.message;return String(e)};import F from"node:fs/promises";import we from"node:path";function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function k(e,t){switch(e){case"esm":return b(t)?".js":".mjs";case"cjs":return b(t)?".cjs":".js";case"iife":return".global.js"}}function U(e,t){switch(e){case"esm":return b(t)?".d.ts":".d.mts";case"cjs":return b(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function I(e){return e==="node"||e==="bun"}function b(e){return e==="module"}function V(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function L(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function y(e,t=3){return e.split("/").slice(-t).join("/")}async function G(e,t){let r=we.join(e,t);try{await F.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await F.mkdir(r,{recursive:!0})}function C(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function q(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${D(t)}($|\\/|\\\\)`):t)}function S(e,t){return q(e.external||[]).concat(V(t).map((r)=>new RegExp(`^${D(r)}($|\\/|\\\\)`)))}function $(e){return q(e.noExternal||[])}import Ce from"node:path";import{ResolverFactory as Se}from"oxc-resolver";import{resolveTsImportPath as Re}from"ts-import-resolver";var R="\x00dts:",X=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,o){if(M(n))return n;if(!o||!M(o))return null;let i=t.tsconfig?Re({path:n,importer:w(o),tsconfig:t.tsconfig,rootDir:r}):null;if(!i)return null;let s=E(i);if(e.has(s))return T(s);return null},load(n){if(n.startsWith(R)){let o=w(n),i=e.get(o);if(i)return H.add(o),i}return null}}};function E(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function M(e){return e.startsWith(R)}function w(e){return e.replace(R,"")}function T(e){return`${R}${e}`}var K;function Y(e){return{name:"bunup:types-resolve",buildStart(){K||=new Se({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?w(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let o=n?Ce.dirname(n):process.cwd(),{path:i}=await K.async(o,t);return i}}}async function Q(e,t,r,n,o,i){let s=E(e),a=T(s),m=S(r,n),u=$(r);try{let{output:l}=await $e({input:a,output:{dir:r.outDir},write:!1,onwarn(d,c){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(d.code??""))return;c(d)},plugins:[X(t,o,i),typeof r.dts==="object"&&"resolve"in r.dts&&Y(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Te({dtsInput:!0,emitDtsOnly:!0})],external:(d)=>m.some((c)=>c.test(d))&&!u.some((c)=>c.test(d))});if(!l[0]?.code)return f.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return l[0].code}catch(l){throw new g(`DTS bundling failed for entry "${e}": ${p(l)}`)}}import{resolveTsImportPath as Pe}from"ts-import-resolver";var Be=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,De=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ie=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Le=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Me=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Oe=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ae=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function _e(e){let t=new Set,r=[Be,De,Ie,Le,Me,Oe,Ae];for(let n of r){let o=e.matchAll(n);for(let i of o)if(i[1])t.add(i[1])}return t}async function Z(e,t,r){let n=new Set([e]),o=[e];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=_e(s);for(let m of a){let u=t.tsconfig?Pe({path:m,importer:i,tsconfig:t.tsconfig,rootDir:r}):null;if(!u)continue;if(!n.has(u))n.add(u),o.push(u)}}catch(s){f.warn(`Error processing ${i}: ${p(s)}`)}}return n}import{isolatedDeclaration as ve}from"oxc-transform";async function z(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let i=await Bun.file(r).text(),{code:s}=ve(r,i);if(s)t.set(n,s)}catch(n){f.warn(`Failed to generate declaration for ${r}: ${p(n)}`)}})),t}import J from"node:fs/promises";import O from"node:path";import{isolatedDeclaration as It}from"oxc-transform";async function ee(e,t){let r=O.resolve(e),n=O.resolve(r,t);if(!await J.exists(r))throw new g(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new g(`Entry file does not exist: ${n}`);if(!C(n))throw new g(`Entry file must be a TypeScript file: ${n}`);if(O.relative(r,n).startsWith(".."))throw new g(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function te(e,t,r,n,o){let{absoluteEntry:i}=await ee(e,t),s=await Z(i,n,e),a=await z(s);return Q(i,a,r,o,n,e)}function re(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,o={};function i(s,a){if(n.has(s)){let m=W(),u=`${s}_${m}`;if(t)f.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
  ${o[s]} -> ${s}.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.4.30",
3
+ "version": "0.4.31",
4
4
  "description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "bunup": "^0.4.23",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "create-bunup": "0.4.30"
23
+ "create-bunup": "0.4.31"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": ">=4.5.0"