bunup 0.3.9 → 0.3.11
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 +9 -9
- package/build/index.d.mts +2 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +6 -6
- package/build/index.mjs +6 -6
- package/package.json +1 -1
package/build/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{
|
|
3
|
+
import{rollup as Dn}from"rollup";import Hn from"rollup-plugin-dts";import I from"typescript";class C extends Error{constructor(n){super(n);this.name="BunupError"}}class y extends C{constructor(n){super(n);this.name="BunupBuildError"}}class d extends C{constructor(n){super(n);this.name="BunupDTSBuildError"}}class h extends C{constructor(n){super(n);this.name="BunupCLIError"}}class j extends C{constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},Tn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof y)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 C)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")},X=(n,t)=>{Nn(n,t),process.exit(1)};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,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),g=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 ${p.join(" ")}${g}`}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[p,f]of Object.entries(this.colors.progress))if(s.includes(p)){i=f;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}};function V(n){try{return An(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import{rollup as Yn}from"rollup";import In from"rollup-plugin-dts";import Q from"typescript";import P from"node:fs";import kn from"node:path";var E={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function nn(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:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function J(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function tn(n=8){return Math.random().toString(36).substring(2,2+n)}function en(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function rn(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 A(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function sn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function on(n,t){return n===void 0?t==="esm":n}function Y(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 O(n,t=3){return n.split("/").slice(-t).join("/")}function I(n,t){let e=kn.join(n,t);if(P.existsSync(e))try{P.rmSync(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}P.mkdirSync(e,{recursive:!0})}function F(n){return n||E.outDir}function an(n){return n===void 0?E.clean:n}function cn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${J(t)}($|\\/|\\\\)`):t)}function M(n,t){return cn(n.external||[]).concat(sn(t).map((e)=>new RegExp(`^${J(e)}($|\\/|\\\\)`)))}function k(n){return cn(n.noExternal||[])}import L from"node:fs";import K from"node:path";async function ln(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=K.join(n,`bunup.config${e}`);try{if(!L.existsSync(r))continue;let s=await Ln(r,e);if(!s)continue;return{configs:Dn(s,n),configFilePath:r}}catch(s){throw new x(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Ln(n,t){if(t===".json"||t===".jsonc")return Hn(n);return Un(n)}function Hn(n){try{let t=L.readFileSync(n,"utf8"),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Un(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 Dn(n,t){let e=[];if(Wn(n))Gn(n,t,e);else if(Array.isArray(n))_n(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 Wn(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 Gn(n,t,e){for(let r of n){let s=K.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 _n(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})}}function H(n){let t=K.join(n,"package.json");try{if(!L.existsSync(t))return null;let e=L.readFileSync(t,"utf8");return JSON.parse(e)}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),null}}import qn from"node:fs";import Pn from"node:path";import{ResolverFactory as Jn}from"oxc-resolver";import B from"path";var d="\x00virtual:",fn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(d))return t;if(!e?.startsWith(d)||!t.startsWith("."))return null;let r=e.slice(d.length),s=B.resolve(B.dirname(r),t);if(t==="."){let o=B.join(B.dirname(r),"index.d.ts");if(n.has(o))return`${d}${o}`;s=B.dirname(r)}if(n.has(s))return`${d}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${d}${i}`;if(t.startsWith(".")){let o=B.join(s,"index.d.ts");if(n.has(o))return`${d}${o}`}return null},load(t){if(t.startsWith(d)){let e=t.slice(d.length),r=n.get(e);if(r)return v.add(e),r}return null}}};var un;function mn(n){return{name:"bunup:types-resolve",buildStart(){un||=new Jn({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(d,""),/\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?Pn.dirname(e):process.cwd(),{path:s}=await un.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await qn.promises.exists(i)?i:void 0}return s}}}async function pn(n,t,e,r,s){let i=n.replace(/\.tsx?$/,".d.ts"),o=`${d}${i}`,a=s.data?.compilerOptions,c=H(r),u=M(e,c),p=k(e),f;try{f=await Yn({input:o,onwarn(b,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(b.code??""))return;$(b)},plugins:[fn(t),typeof e.dts==="object"&&"resolve"in e.dts&&mn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),In({tsconfig:s.path,compilerOptions:{...a?Q.parseJsonConfigFileContent({compilerOptions:a},Q.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:Q.ScriptTarget.ESNext}})],external:(b)=>u.some(($)=>$.test(b))&&!p.some(($)=>$.test(b))});let{output:g}=await f.generate({});if(!g[0]?.code)throw new h("Generated bundle is empty");return g[0].code}catch(g){throw new h(`DTS bundling failed: ${m(g)}`)}finally{if(f)await f.close()}}import gn from"node:fs";import S from"node:path";var Fn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Kn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function dn(n,t){let e=new Set([n]),r=[n],s=zn(t),i=hn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await gn.promises.readFile(o,"utf8"),c=Qn(a);for(let u of c){let p=u.startsWith(".")?S.resolve(S.dirname(o),u):Xn(u,s,i);if(!p)continue;let f=Zn(p);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return e}function Qn(n){let t=new Set;for(let e of[Fn,Kn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}function Zn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(gn.existsSync(r)&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function hn(n){let t=S.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?S.resolve(t,n.data.compilerOptions.baseUrl):t}function zn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=hn(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}$`,S.join(r,a))}return t}function Xn(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?S.join(e,n):null}import Vn from"node:fs";import{isolatedDeclaration as nt}from"oxc-transform";async function yn(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts"),s=await Vn.promises.readFile(e,"utf8"),{code:i}=nt(e,s);if(i)t.set(r,i)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import z from"node:fs";import Z from"node:path";import{isolatedDeclaration as tt}from"oxc-transform";function xn(n,t){let e=Z.resolve(n),r=Z.resolve(e,t);if(!z.existsSync(e))throw new h(`Root directory does not exist: ${e}`);if(!z.existsSync(r))throw new h(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new h(`Entry file must be a TypeScript file (.ts): ${r}`);if(Z.relative(e,r).startsWith(".."))throw new h(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function wn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await z.promises.readFile(r,"utf8"),{errors:i}=tt(r,s);i.forEach((o)=>{if(!t)console.log(`
|
|
6
|
-
`);let a=o.labels[0],c=a?
|
|
5
|
+
`)+"\x1B[0m")},Z=(n,t)=>{Tn(n,t),process.exit(1)};import _ from"node:fs/promises";import Mn from"node:path";var E={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 q(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X(n=8){return Math.random().toString(36).substring(2,2+n)}function F(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function V(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 M(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function nn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function tn(n,t){return n===void 0?t==="esm":n}function P(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 J(n,t){let e=Mn.join(n,t);if(await _.exists(e))try{await _.rm(e,{recursive:!0})}catch(s){throw new y(`Failed to clean output directory: ${s}`)}await _.mkdir(e,{recursive:!0})}function Y(n){return n||E.outDir}function en(n){return n===void 0?E.clean:n}function rn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${q(t)}($|\\/|\\\\)`):t)}function k(n,t){return rn(n.external||[]).concat(nn(t).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function L(n){return rn(n.noExternal||[])}import kn from"node:path";import{ResolverFactory as Ln}from"oxc-resolver";import B from"path";var g="\x00virtual:",sn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(g))return t;if(!e?.startsWith(g)||!t.startsWith("."))return null;let r=e.slice(g.length),s=B.resolve(B.dirname(r),t);if(t==="."){let o=B.join(B.dirname(r),"index.d.ts");if(n.has(o))return`${g}${o}`;s=B.dirname(r)}if(n.has(s))return`${g}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${g}${i}`;if(t.startsWith(".")){let o=B.join(s,"index.d.ts");if(n.has(o))return`${g}${o}`}return null},load(t){if(t.startsWith(g)){let e=t.slice(g.length),r=n.get(e);if(r)return v.add(e),r}return null}}};var on;function an(n){return{name:"bunup:types-resolve",buildStart(){on||=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(g,""),/\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 on.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 cn(n,t,e,r,s){let i=n.replace(/\.tsx?$/,".d.ts"),o=`${g}${i}`,a=r.data?.compilerOptions,c=k(e,s),u=L(e),p;try{p=await Dn({input:o,onwarn(x,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;$(x)},plugins:[sn(t),typeof e.dts==="object"&&"resolve"in e.dts&&an(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Hn({tsconfig:r.path,compilerOptions:{...a?I.parseJsonConfigFileContent({compilerOptions:a},I.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:I.ScriptTarget.ESNext}})],external:(x)=>c.some(($)=>$.test(x))&&!u.some(($)=>$.test(x))});let{output:f}=await p.generate({});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${m(f)}`)}finally{if(p)await p.close()}}import R 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,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),x=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 ${p.join(" ")}${x}`}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[p,f]of Object.entries(this.colors.progress))if(s.includes(p)){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 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 ln(n,t){let e=new Set([n]),r=[n],s=qn(t),i=fn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await Bun.file(o).text(),c=Gn(a);for(let u of c){let p=u.startsWith(".")?R.resolve(R.dirname(o),u):Pn(u,s,i);if(!p)continue;let f=await _n(p);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(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 fn(n){let t=R.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?R.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=fn(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}$`,R.join(r,a))}return t}function Pn(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?R.join(e,n):null}import{isolatedDeclaration as Jn}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}=Jn(e,i);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import mn from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as Yn}from"oxc-transform";async function pn(n,t){let e=K.resolve(n),r=K.resolve(e,t);if(!await mn.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(K.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function gn(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):"",p=`${w(r)}${c}: ${Kn(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
|
|
9
|
-
`),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function
|
|
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 Kn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function dn(n,t,e,r,s){let{absoluteEntry:i}=await pn(n,t),o=await ln(i,r),a=await un(o);return cn(i,a,e,r,s)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function T(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=X(),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/#using-a-configuration-file-with-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=
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-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 hn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Qn}from"load-tsconfig";function xn(n){try{return Qn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import Q from"node:path";async function yn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Q.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Zn(r,e);if(!i)continue;return{configs:Fn(i,n),configFilePath:r}}catch(s){throw new y(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Zn(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. ${m(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. ${m(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=Q.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 wn(n){let t=Q.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 bn(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 v=new Set;async function D(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:e,path:r}=await wn(t);if(e)l.cli(`Using package.json: ${w(r)}`,{muted:!0});let s=e?.type,i=k(n,e),o=L(n),a=[bn(i,o)],c=T(n.entry),u=z(n,t),p=n.format.flatMap((f)=>c.map((x)=>{return et(n,t,x,f,s,a,u)}));if(await Promise.all(p),n.dts){let f=xn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path)}`,{muted:!0});let x=n.format.filter((O)=>{if(O==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),$=typeof n.dts==="object"&&n.dts.entry?T(n.dts.entry):c;try{await Promise.all($.map(async(O)=>{let Rn=await dn(t,O.path,n,f,e);await Promise.all(x.map(async(Sn)=>{let jn=V(Sn,s),G=`${t}/${n.outDir}/${O.name}${jn}`;await Bun.write(G,Rn);let An=Bun.file(G).size||0;l.progress("DTS",w(G),P(An),n.name)}))}))}catch(O){throw new d(m(O))}}}async function et(n,t,e,r,s,i,o){let a=F(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:hn(e.name,a)},splitting:tn(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new y(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}`,p=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),P(p),n.name)}var H="0.3.11";var $n="https://bun.sh/docs/installation",On="https://bunup.arshadyaseen.com/#cli-options";function b(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function S(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function Cn(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${
|
|
26
|
-
`),process.exit(0)}function
|
|
27
|
-
To install Bun, visit
|
|
25
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${On}\x1B[0m
|
|
26
|
+
`),process.exit(0)}function it(){console.log(H),process.exit(0)}var ot={name:{flags:["n","name"],handler:S("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:S("outDir")},minify:{flags:["m","minify"],handler:b("minify")},watch:{flags:["w","watch"],handler:b("watch")},dts:{flags:["d","dts"],handler:b("dts")},banner:{flags:["b","banner"],handler:S("banner")},footer:{flags:["f","footer"],handler:S("footer")},external:{flags:["e","external"],handler:Cn("external")},sourcemap:{flags:["sm","sourcemap"],handler:S("sourcemap")},target:{flags:["t","target"],handler:S("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:b("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:b("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:b("minifySyntax")},clean:{flags:["c","clean"],handler:b("clean")},splitting:{flags:["s","splitting"],handler:b("splitting")},noExternal:{flags:["ne","no-external"],handler:Cn("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 En(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=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=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 `+$n)})();import W from"node:path";import ct from"chokidar";async function Bn(n,t){let e=new Set,r=T(n.entry);r.forEach((a)=>{let c=W.resolve(t,a.path),u=W.dirname(c);e.add(u)});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((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${M(performance.now()-c)}`)}catch(c){throw new j(`Build failed: ${m(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 j(`Watcher error: ${m(a)}`)}),await o(!0)}async function lt(n=Bun.argv.slice(2)){let t=En(n),{configs:e,configFilePath:r}=await yn(process.cwd());if(l.cli(`Using bunup v${H} 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={...E,...t},c=process.cwd();if(a.clean)J(c,Y(a.outDir));await vn(a,c)}else{for(let{options:a,rootDir:c}of e)if(en(a.clean))J(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...E,...a,...t};await vn(u,c)}))}let i=performance.now()-s,o=M(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),v.size>0)await gn(v),v.clear();if(t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function vn(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.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ type Sourcemap = BunBuildOptions["sourcemap"];
|
|
|
6
6
|
type Format = Exclude<BunBuildOptions["format"], undefined>;
|
|
7
7
|
type Target = BunBuildOptions["target"];
|
|
8
8
|
type External = (string | RegExp)[];
|
|
9
|
-
type Entry = string
|
|
9
|
+
type Entry = Arrayable<string> | Record<string, string>;
|
|
10
10
|
type DtsOptions = {
|
|
11
11
|
/**
|
|
12
12
|
* Entry point files for TypeScript declaration file generation
|
|
@@ -221,6 +221,7 @@ type WithOptional<
|
|
|
221
221
|
T,
|
|
222
222
|
K extends keyof T
|
|
223
223
|
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
224
|
+
type Arrayable<T> = T | T[];
|
|
224
225
|
type Bun = typeof bun;
|
|
225
226
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
226
227
|
type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
|
package/build/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type Sourcemap = BunBuildOptions["sourcemap"];
|
|
|
6
6
|
type Format = Exclude<BunBuildOptions["format"], undefined>;
|
|
7
7
|
type Target = BunBuildOptions["target"];
|
|
8
8
|
type External = (string | RegExp)[];
|
|
9
|
-
type Entry = string
|
|
9
|
+
type Entry = Arrayable<string> | Record<string, string>;
|
|
10
10
|
type DtsOptions = {
|
|
11
11
|
/**
|
|
12
12
|
* Entry point files for TypeScript declaration file generation
|
|
@@ -221,6 +221,7 @@ type WithOptional<
|
|
|
221
221
|
T,
|
|
222
222
|
K extends keyof T
|
|
223
223
|
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
224
|
+
type Arrayable<T> = T | T[];
|
|
224
225
|
type Bun = typeof bun;
|
|
225
226
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
226
227
|
type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var jn=require("node:module");var bn=Object.create;var{getPrototypeOf:Rn,defineProperty:b,getOwnPropertyNames:J,getOwnPropertyDescriptor:On}=Object,Y=Object.prototype.hasOwnProperty;var m=(n,t,r)=>{r=n!=null?bn(Rn(n)):{};let e=t||!n||!n.__esModule?b(r,"default",{value:n,enumerable:!0}):r;for(let i of J(n))if(!Y.call(e,i))b(e,i,{get:()=>n[i],enumerable:!0});return e},L=new WeakMap,Sn=(n)=>{var t=L.get(n),r;if(t)return t;if(t=b({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")J(n).map((e)=>!Y.call(t,e)&&b(t,e,{get:()=>n[e],enumerable:!(r=On(n,e))||r.enumerable}));return L.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 Yn={};Bn(Yn,{defineWorkspace:()=>K,defineConfig:()=>q,build:()=>wn});module.exports=Sn(Yn);function q(n){return n}function K(n){return n}var Q=require("load-tsconfig");class A extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends A{constructor(n){super(n);this.name="BunupBuildError"}}class y extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var x=(n)=>{if(n instanceof Error)return n.message;return String(n)};var u={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:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=o?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),p=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${s}${l}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${p}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${s}${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),o=this.colors.default,s,c,f={};if(typeof r==="string")s=r,c=e;else if(r)s=r.size,c=r.identifier,f=r;for(let[g,a]of Object.entries(this.colors.progress))if(i.includes(g)){o=a;break}let l=this.formatMessage({colorCode:o,label:i,message:t,size:s,identifier:c,muted:f.muted});this.output(l,f)}};function Z(n){try{return Q.loadTsConfig(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${x(t)}`),{path:n,data:{},files:[]}}}var an=require("rollup"),fn=m(require("rollup-plugin-dts")),M=m(require("typescript"));var Nn=m(require("node:fs")),Dn=m(require("node:path"));function U(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,o=t===!0;return{whitespace:r??o,identifiers:e??o,syntax:i??o}}function T(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function P(n=8){return Math.random().toString(36).substring(2,2+n)}function _(n,t){switch(n){case"esm":return".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function z(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 X(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function F(n,t){return n===void 0?t==="esm":n}function W(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 O(n,t=3){return n.split("/").slice(-t).join("/")}function I(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${T(t)}($|\\/|\\\\)`):t)}function S(n,t){return I(n.external||[]).concat(X(t).map((r)=>new RegExp(`^${T(r)}($|\\/|\\\\)`)))}function B(n){return I(n.noExternal||[])}var v=m(require("node:fs")),V=m(require("node:path"));function j(n){let t=V.default.join(n,"package.json");try{if(!v.default.existsSync(t))return null;let r=v.default.readFileSync(t,"utf8");return JSON.parse(r)}catch(r){return u.warn(`Failed to load package.json at ${t}: ${x(r)}`),null}}var en=m(require("node:fs")),on=m(require("node:path")),sn=require("oxc-resolver");var h=m(require("path"));var d="\x00virtual:",nn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(d))return t;if(!r?.startsWith(d)||!t.startsWith("."))return null;let e=r.slice(d.length),i=h.default.resolve(h.default.dirname(e),t);if(t==="."){let s=h.default.join(h.default.dirname(e),"index.d.ts");if(n.has(s))return`${d}${s}`;i=h.default.dirname(e)}if(n.has(i))return`${d}${i}`;let o=`${i}.d.ts`;if(n.has(o))return`${d}${o}`;if(t.startsWith(".")){let s=h.default.join(i,"index.d.ts");if(n.has(s))return`${d}${s}`}return null},load(t){if(t.startsWith(d)){let r=t.slice(d.length),e=n.get(r);if(e)return tn.add(r),e}return null}}};var rn;function cn(n){return{name:"bunup:types-resolve",buildStart(){rn||=new sn.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(d,""),/\0/.test(t))return;if(n){if(!n.some((s)=>{let c=!1;if(typeof s==="string")c=s===t||!!(r&&r.includes(s));else c=s.test(t)||!!(r&&s.test(r));return c}))return}let e=r?on.default.dirname(r):process.cwd(),{path:i}=await rn.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let o=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await en.default.promises.exists(o)?o:void 0}return i}}}async function un(n,t,r,e,i){let o=n.replace(/\.tsx?$/,".d.ts"),s=`${d}${o}`,c=i.data?.compilerOptions,f=j(e),l=S(r,f),g=B(r),a;try{a=await an.rollup({input:s,onwarn($,E){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes($.code??""))return;E($)},plugins:[nn(t),typeof r.dts==="object"&&"resolve"in r.dts&&cn(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),fn.default({tsconfig:i.path,compilerOptions:{...c?M.default.parseJsonConfigFileContent({compilerOptions:c},M.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:M.default.ScriptTarget.ESNext}})],external:($)=>l.some((E)=>E.test($))&&!g.some((E)=>E.test($))});let{output:p}=await a.generate({});if(!p[0]?.code)throw new y("Generated bundle is empty");return p[0].code}catch(p){throw new y(`DTS bundling failed: ${x(p)}`)}finally{if(a)await a.close()}}var G=m(require("node:fs")),C=m(require("node:path"));var An=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Tn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function gn(n,t){let r=new Set([n]),e=[n],i=Gn(t),o=ln(t);while(e.length){let s=e.pop();if(!s)continue;try{let c=await G.default.promises.readFile(s,"utf8"),f=Wn(c);for(let l of f){let g=l.startsWith(".")?C.default.resolve(C.default.dirname(s),l):kn(l,i,o);if(!g)continue;let a=vn(g);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${s}: ${x(c)}`)}}return r}function Wn(n){let t=new Set;for(let r of[An,Tn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}function vn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(G.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function ln(n){let t=C.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?C.default.resolve(t,n.data.compilerOptions.baseUrl):t}function Gn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=ln(n);for(let[i,o]of Object.entries(r))if(Array.isArray(o)&&o.length){let s=i.replace(/\*/g,"(.*)"),c=o[0].replace(/\*/g,"$1");t.set(`^${s}$`,C.default.join(e,c))}return t}function kn(n,t,r){for(let[e,i]of t){let o=new RegExp(e),s=n.match(o);if(s)return i.replace("$1",s[1]||"")}return r?C.default.join(r,n):null}var mn=m(require("node:fs")),pn=require("oxc-transform");async function dn(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),i=await mn.default.promises.readFile(r,"utf8"),{code:o}=pn.isolatedDeclaration(r,i);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),t}var k=m(require("node:fs")),N=m(require("node:path")),Hn=require("oxc-transform");function xn(n,t){let r=N.default.resolve(n),e=N.default.resolve(r,t);if(!k.default.existsSync(r))throw new y(`Root directory does not exist: ${r}`);if(!k.default.existsSync(e))throw new y(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new y(`Entry file must be a TypeScript file (.ts): ${e}`);if(N.default.relative(r,e).startsWith(".."))throw new y(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function yn(n,t,r){let{absoluteRootDir:e,absoluteEntry:i}=xn(n,t),o=Z(r.preferredTsconfigPath),s=await gn(i,o),c=await dn(s);return un(i,c,r,e,o)}function Ln(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function H(n){let t=[],r=new Set,e={};function i(o,s){if(r.has(o)){let c=P(),f=`${o}_${c}`;u.warn(`Output name conflict: "${o}" is used by multiple files.
|
|
1
|
+
var jn=require("node:module");var hn=Object.create;var{getPrototypeOf:bn,defineProperty:R,getOwnPropertyNames:G,getOwnPropertyDescriptor:Rn}=Object,H=Object.prototype.hasOwnProperty;var w=(n,t,r)=>{r=n!=null?hn(bn(n)):{};let e=t||!n||!n.__esModule?R(r,"default",{value:n,enumerable:!0}):r;for(let i of G(n))if(!H.call(e,i))R(e,i,{get:()=>n[i],enumerable:!0});return e},k=new WeakMap,Bn=(n)=>{var t=k.get(n),r;if(t)return t;if(t=R({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")G(n).map((e)=>!H.call(t,e)&&R(t,e,{get:()=>n[e],enumerable:!(r=Rn(n,e))||r.enumerable}));return k.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:()=>J,defineConfig:()=>L,build:()=>wn});module.exports=Bn(Ln);function L(n){return n}function J(n){return n}var nn=require("rollup"),tn=w(require("rollup-plugin-dts")),M=w(require("typescript"));class A extends Error{constructor(n){super(n);this.name="BunupError"}}class h extends A{constructor(n){super(n);this.name="BunupBuildError"}}class d extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)};var Nn=w(require("node:fs/promises")),Sn=w(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 D(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(n=8){return Math.random().toString(36).substring(2,2+n)}function K(n,t){switch(n){case"esm":return".mjs";case"cjs":return B(t)?".cjs":".js";case"iife":return".global.js"}}function Q(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 Z(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function U(n,t){return n===void 0?t==="esm":n}function T(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 b(n,t=3){return n.split("/").slice(-t).join("/")}function P(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${D(t)}($|\\/|\\\\)`):t)}function O(n,t){return P(n.external||[]).concat(Z(t).map((r)=>new RegExp(`^${D(r)}($|\\/|\\\\)`)))}function j(n){return P(n.noExternal||[])}var I=w(require("node:path")),V=require("oxc-resolver");var $=w(require("path"));var m="\x00virtual:",_=(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=$.default.resolve($.default.dirname(e),t);if(t==="."){let o=$.default.join($.default.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=$.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=$.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 z.add(r),e}return null}}};var X;function F(n){return{name:"bunup:types-resolve",buildStart(){X||=new V.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?I.default.dirname(r):process.cwd(),{path:i}=await X.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 rn(n,t,r,e,i){let s=n.replace(/\.tsx?$/,".d.ts"),o=`${m}${s}`,a=e.data?.compilerOptions,f=O(r,i),g=j(r),l;try{l=await nn.rollup({input:o,onwarn(x,E){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;E(x)},plugins:[_(t),typeof r.dts==="object"&&"resolve"in r.dts&&F(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),tn.default({tsconfig:e.path,compilerOptions:{...a?M.default.parseJsonConfigFileContent({compilerOptions:a},M.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:M.default.ScriptTarget.ESNext}})],external:(x)=>f.some((E)=>E.test(x))&&!g.some((E)=>E.test(x))});let{output:c}=await l.generate({});if(!c[0]?.code)throw new d("Generated bundle is empty");return c[0].code}catch(c){throw new d(`DTS bundling failed: ${p(c)}`)}finally{if(l)await l.close()}}var y=w(require("node:path"));var u={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)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[g,...l]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),x=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${g}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${x}`}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(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 g=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:f.muted});this.output(g,f)}};var An=/(?: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 en(n,t){let r=new Set([n]),e=[n],i=vn(t),s=sn(t);while(e.length){let o=e.pop();if(!o)continue;try{let a=await Bun.file(o).text(),f=Tn(a);for(let g of f){let l=g.startsWith(".")?y.default.resolve(y.default.dirname(o),g):kn(g,i,s);if(!l)continue;let c=await Wn(l);if(c&&!r.has(c))r.add(c),e.push(c)}}catch(a){u.warn(`Error processing ${o}: ${p(a)}`)}}return r}function Tn(n){let t=new Set;for(let r of[An,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 sn(n){let t=y.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?y.default.resolve(t,n.data.compilerOptions.baseUrl):t}function vn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=sn(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.default.join(e,a))}return t}function kn(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.default.join(r,n):null}var on=require("oxc-transform");async function an(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}=on.isolatedDeclaration(r,s);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),t}var W=w(require("node:fs/promises")),N=w(require("node:path")),Gn=require("oxc-transform");async function cn(n,t){let r=N.default.resolve(n),e=N.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(N.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function fn(n,t,r,e,i){let{absoluteEntry:s}=await cn(n,t),o=await en(s,e),a=await an(o);return rn(s,a,r,e,i)}function un(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=q(),f=`${s}_${a}`;u.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
|
-
${e[
|
|
5
|
-
${
|
|
4
|
+
${e[s]} -> ${s}.js
|
|
5
|
+
${o} -> ${f}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
|
-
custom_name: "${e[
|
|
11
|
-
another_name: "${
|
|
10
|
+
custom_name: "${e[s]}",
|
|
11
|
+
another_name: "${o}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-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=un(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=un(n);i(s,n)}return t}function gn(n,t){return`[dir]/${n}${t}`}var ln=require("load-tsconfig");function mn(n){try{return ln.loadTsConfig(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}var pn=w(require("node:path"));async function xn(n){let t=pn.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 u.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 z=new Set;async function wn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await xn(t);if(r)u.cli(`Using package.json: ${b(e)}`,{muted:!0});let i=r?.type,s=O(n,r),o=j(n),a=[dn(s,o)],f=v(n.entry),g=Y(n,t),l=n.format.flatMap((c)=>f.map((x)=>{return Hn(n,t,x,c,i,a,g)}));if(await Promise.all(l),n.dts){let c=mn(n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${b(c.path)}`,{muted:!0});let x=n.format.filter((C)=>{if(C==="iife"&&!B(i)&&n.format.includes("cjs"))return!1;return!0}),E=typeof n.dts==="object"&&n.dts.entry?v(n.dts.entry):f;try{await Promise.all(E.map(async(C)=>{let En=await fn(t,C.path,n,c,r);await Promise.all(x.map(async($n)=>{let yn=Q($n,i),S=`${t}/${n.outDir}/${C.name}${yn}`;await Bun.write(S,En);let Cn=Bun.file(S).size||0;u.progress("DTS",b(S),T(Cn),n.name)}))}))}catch(C){throw new d(p(C))}}}async function Hn(n,t,r,e,i,s,o){let a=K(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:gn(r.name,a)},splitting:U(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let g=`${t}/${n.outDir}/${r.name}${a}`,l=Bun.file(g).size||0;u.progress(e.toUpperCase(),b(g),T(l),n.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function
|
|
1
|
+
function an(n){return n}function cn(n){return n}import{rollup as ln}from"rollup";import mn from"rollup-plugin-dts";import S from"typescript";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class $ 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 Sn from"node:fs/promises";import Dn from"node:path";function T(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 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 G(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function H(n,t){return n===void 0?t==="esm":n}function N(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 L(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${M(t)}($|\\/|\\\\)`):t)}function R(n,t){return L(n.external||[]).concat(G(t).map((r)=>new RegExp(`^${M(r)}($|\\/|\\\\)`)))}function B(n){return L(n.noExternal||[])}import un from"node:path";import{ResolverFactory as gn}from"oxc-resolver";import C from"path";var m="\x00virtual:",J=(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=C.resolve(C.dirname(e),t);if(t==="."){let o=C.join(C.dirname(e),"index.d.ts");if(n.has(o))return`${m}${o}`;i=C.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=C.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 q;function K(n){return{name:"bunup:types-resolve",buildStart(){q||=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 q.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,i){let s=n.replace(/\.tsx?$/,".d.ts"),o=`${m}${s}`,a=e.data?.compilerOptions,f=R(r,i),g=B(r),l;try{l=await ln({input:o,onwarn(x,w){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;w(x)},plugins:[J(t),typeof r.dts==="object"&&"resolve"in r.dts&&K(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),mn({tsconfig:e.path,compilerOptions:{...a?S.parseJsonConfigFileContent({compilerOptions:a},S.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:S.ScriptTarget.ESNext}})],external:(x)=>f.some((w)=>w.test(x))&&!g.some((w)=>w.test(x))});let{output:c}=await l.generate({});if(!c[0]?.code)throw new d("Generated bundle is empty");return c[0].code}catch(c){throw new d(`DTS bundling failed: ${p(c)}`)}finally{if(l)await l.close()}}import h from"node:path";var u={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)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[g,...l]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),x=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${g}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${x}`}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(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 g=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:f.muted});this.output(g,f)}};var pn=/(?: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 Z(n,t){let r=new Set([n]),e=[n],i=En(t),s=U(t);while(e.length){let o=e.pop();if(!o)continue;try{let a=await Bun.file(o).text(),f=dn(a);for(let g of f){let l=g.startsWith(".")?h.resolve(h.dirname(o),g):$n(g,i,s);if(!l)continue;let c=await wn(l);if(c&&!r.has(c))r.add(c),e.push(c)}}catch(a){u.warn(`Error processing ${o}: ${p(a)}`)}}return r}function dn(n){let t=new Set;for(let r of[pn,xn]){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 U(n){let t=h.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?h.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=U(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}$`,h.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?h.join(r,n):null}import{isolatedDeclaration as yn}from"oxc-transform";async function P(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}=yn(r,s);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),t}import _ from"node:fs/promises";import A from"node:path";import{isolatedDeclaration as mt}from"oxc-transform";async function z(n,t){let r=A.resolve(n),e=A.resolve(r,t);if(!await _.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(A.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function X(n,t,r,e,i){let{absoluteEntry:s}=await z(n,t),o=await Z(s,e),a=await P(o);return Q(s,a,r,e,i)}function I(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function D(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=W(),f=`${s}_${a}`;u.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
|
-
${e[
|
|
5
|
-
${
|
|
4
|
+
${e[s]} -> ${s}.js
|
|
5
|
+
${o} -> ${f}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
|
-
custom_name: "${e[
|
|
11
|
-
another_name: "${
|
|
10
|
+
custom_name: "${e[s]}",
|
|
11
|
+
another_name: "${o}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-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=I(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=I(n);i(s,n)}return t}function V(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Cn}from"load-tsconfig";function F(n){try{return Cn(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import hn from"node:path";async function nn(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 u.warn(`Failed to load package.json at ${t}: ${p(r)}`),{packageJson:null,path:t}}}function tn(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 bn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new $("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await nn(t);if(r)u.cli(`Using package.json: ${y(e)}`,{muted:!0});let i=r?.type,s=R(n,r),o=B(n),a=[tn(s,o)],f=D(n.entry),g=T(n,t),l=n.format.flatMap((c)=>f.map((x)=>{return Rn(n,t,x,c,i,a,g)}));if(await Promise.all(l),n.dts){let c=F(n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${y(c.path)}`,{muted:!0});let x=n.format.filter((E)=>{if(E==="iife"&&!b(i)&&n.format.includes("cjs"))return!1;return!0}),w=typeof n.dts==="object"&&n.dts.entry?D(n.dts.entry):f;try{await Promise.all(w.map(async(E)=>{let rn=await X(t,E.path,n,c,r);await Promise.all(x.map(async(en)=>{let sn=k(en,i),O=`${t}/${n.outDir}/${E.name}${sn}`;await Bun.write(O,rn);let on=Bun.file(O).size||0;u.progress("DTS",y(O),N(on),n.name)}))}))}catch(E){throw new d(p(E))}}}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:V(r.name,a)},splitting:H(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new $(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let g=`${t}/${n.outDir}/${r.name}${a}`,l=Bun.file(g).size||0;u.progress(e.toUpperCase(),y(g),N(l),n.name)}export{cn as defineWorkspace,an as defineConfig,bn as build};
|