bunup 0.3.72 → 0.3.74
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 +10 -10
- package/build/index.d.mts +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +4 -4
- package/build/index.mjs +4 -4
- package/package.json +4 -4
package/build/cli.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{build as
|
|
3
|
+
import{build as Xe}from"rolldown";import{dts as Ye}from"rolldown-plugin-dts";class $ extends Error{constructor(e){super(e);this.name="BunupError"}}class y extends ${constructor(e){super(e);this.name="BunupBuildError"}}class g extends ${constructor(e){super(e);this.name="BunupDTSBuildError"}}class d extends ${constructor(e){super(e);this.name="BunupCLIError"}}class S extends ${constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},We=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",i="ERROR";if(e instanceof y)i="BUILD ERROR";else if(e instanceof g)i="DTS ERROR";else if(e instanceof d)i="CLI ERROR";else if(e instanceof S)i="WATCH ERROR";else if(e instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${n}`);let s=We.find((o)=>o.pattern.test(n)&&(o.errorType===i||!o.errorType));if(s)console.error(`
|
|
4
4
|
\x1B[90mA solution for this error is available at: \x1B[36m${s.link}\x1B[0m
|
|
5
|
-
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},
|
|
6
|
-
`);let a=o.labels[0],
|
|
5
|
+
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},J=(e,t)=>{V(e,t),process.exit(1)};import te from"node:fs/promises";import He from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function ee(e,t){return{outdir:`${t}/${e.outDir}`,minify:je(e),target:e.target,splitting:e.splitting,sourcemap:e.sourcemap,define:e.define,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer}}function je(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,s=t===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function G(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e=8){return Math.random().toString(36).substring(2,2+e)}function re(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function X(e){return Array.isArray(e)?e:[e]}function se(e,t){switch(e){case"esm":return".mjs";case"cjs":return I(t)?".cjs":".js";case"iife":return".global.js"}}function ie(e,t){switch(e){case"esm":return".d.mts";case"cjs":return I(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function I(e){return e==="module"}function M(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function oe(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ae(e,t){return e===void 0?t==="esm":e}function Y(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function x(e,t=3){return e.split("/").slice(-t).join("/")}async function le(e,t){let n=He.join(e,t);try{await te.rm(n,{recursive:!0,force:!0})}catch(r){throw new y(`Failed to clean output directory: ${r}`)}await te.mkdir(n,{recursive:!0})}function ce(e){return e||v.outDir}function ue(e){return e===void 0?v.clean:e}function fe(e,t){return t==="cjs"?e:void 0}function pe(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function U(e,t){return pe(e.external||[]).concat(oe(t).map((n)=>new RegExp(`^${G(n)}($|\\/|\\\\)`)))}function _(e){return pe(e.noExternal||[])}import Ve from"node:path";import{ResolverFactory as Ge}from"oxc-resolver";import B from"node:path";var T="\x00dts:",me=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(K(r))return r;if(!i||!K(i))return null;let s=await N(r,t,n,P(i));if(!s)return null;let o=R(s);if(e.has(o))return k(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=e.get(i);if(s)return C.add(i),s}return null}}};function ge(e){return e.tsconfig?.compilerOptions}function R(e){return e.replace(/\.tsx?$/,".d.ts")}function Q(e){let t=B.dirname(e.path||""),n=ge(e);return n?.baseUrl?B.resolve(t,n.baseUrl):t}function de(e){let t=new Map,n=ge(e)?.paths;if(!n)return t;let r=Q(e);for(let[i,s]of Object.entries(n))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,B.join(r,a))}return t}function Fe(e,t,n){for(let[r,i]of t){let s=new RegExp(r),o=e.match(s);if(o)return i.replace("$1",o[1]||"")}return n?B.join(n,e):null}async function qe(e){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(e,t,n,r){let i=e.startsWith(".")?B.resolve(B.dirname(r||""),e):Fe(e,t,n);if(!i)return Promise.resolve(null);return qe(i)}function K(e){return e.startsWith(T)}function P(e){return e.replace(T,"")}function k(e){return`${T}${e}`}var he;function xe(e){return{name:"bunup:types-resolve",buildStart(){he||=new Ge({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?P(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let i=r?Ve.dirname(r):process.cwd(),{path:s}=await he.async(i,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function be(e,t,n,r,i,s){let o=R(e),a=k(o),l=U(n,r),u=_(n);try{let{output:p}=await Xe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;m(f)},plugins:[me(t,i,s),typeof n.dts==="object"&&"resolve"in n.dts&&xe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ye()],external:(f)=>l.some((m)=>m.test(f))&&!u.some((m)=>m.test(f))});if(!p[0]?.code)throw new g("Generated bundle is empty");return p[0].code}catch(p){throw new g(`DTS bundling failed: ${h(p)}`)}}class O{static instance;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!O.instance)O.instance=new O;return O.instance}formatMessage({colorCode:e,label:t,message:n,size:r,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${n}\x1B[0m`:n;if(r){let[u,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${m}`}let l=i?` \x1B[48;5;${e};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${o}${a}${l}`}output(e,t={},n=console.log){if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let i=String(e),s=this.colors.default,o,a,l={};if(typeof n==="string")o=n,a=r;else if(n)o=n.size,a=n.identifier,l=n;for(let[p,f]of Object.entries(this.colors.progress))if(i.includes(p)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:l.muted});this.output(u,l)}}var c=O.getInstance();var Ke=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Qe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ze=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Je=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function nt(e){let t=new Set,n=[Ke,Qe,Ze,ze,Je,et,tt];for(let r of n){let i=e.matchAll(r);for(let s of i)if(s[1])t.add(s[1])}return t}async function ye(e,t,n){let r=new Set([e]),i=[e];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=nt(o);for(let l of a){let u=await N(l,t,n,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){c.warn(`Error processing ${s}: ${h(o)}`)}}return r}import{isolatedDeclaration as rt}from"oxc-transform";async function we(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=R(n);if(!await Bun.file(n).exists())return;let s=await Bun.file(n).text(),{code:o}=rt(n,s);if(o)t.set(r,o)}catch(r){c.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import Ee from"node:fs/promises";import Z from"node:path";import{isolatedDeclaration as st}from"oxc-transform";async function $e(e,t){let n=Z.resolve(e),r=Z.resolve(n,t);if(!await Ee.exists(n))throw new g(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${r}`);if(Z.relative(n,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Re(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=st(r,i);for(let o of s){if(!t)console.log(`
|
|
6
|
+
`);let a=o.labels[0],l=a?it(i,a.start):"",p=`${x(r)}${l}: ${ot(o.message)}`;c.warn(p),t=!0}}catch{}})),t)c.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=n.length,i=n[n.length-1].length+1;return` (${r}:${i})`}function
|
|
8
|
+
`)}function it(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
|
|
9
|
+
`),r=n.length,i=n[n.length-1].length+1;return` (${r}:${i})`}function ot(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Ce(e,t,n,r,i){let{absoluteEntry:s}=await $e(e,t),o=de(r),a=Q(r),l=await ye(s,o,a),u=await we(l);return be(s,u,n,i,o,a)}function A(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function L(e){let t=[],n=new Set,r={};function i(s,o){if(n.has(s)){let a=ne(),l=`${s}_${a}`;c.warn(`Output name conflict: "${s}" is used by multiple files.
|
|
10
10
|
Bunup uses filenames without extensions as output names by default.
|
|
11
11
|
|
|
12
12
|
${r[s]} -> ${s}.js
|
|
13
|
-
${o} -> ${
|
|
13
|
+
${o} -> ${l}.js (auto-renamed to avoid conflict)
|
|
14
14
|
|
|
15
15
|
To fix this, use named entries in your configuration:
|
|
16
16
|
{
|
|
@@ -20,8 +20,8 @@ To fix this, use named entries in your configuration:
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:l,path:o})}else t.push({name:s,path:o}),n.add(s),r[s]=o}if(Array.isArray(e))for(let s of e){let o=A(s);i(o,s)}else if(typeof e==="object")for(let[s,o]of Object.entries(e))i(s,o);else{let s=A(e);i(s,e)}return t}function Be(e,t){return`[dir]/${e}${t}`}import{loadConfig as Oe}from"coffi";async function ve(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:re(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Pe(e){let{config:t,filepath:n}=await Oe({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Te(e,t){let{config:n,filepath:r}=await Oe({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}function Ae(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(e.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var C=new Set;async function W(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:n,path:r}=await Pe(t);if(n&&r)c.cli(`Using package.json: ${x(r,2)}`,{muted:!0,identifier:e.name});let i=n?.type,s=U(e,n),o=_(e),a=[Ae(s,o)],l=L(e.entry),u=ee(e,t),p=e.format.flatMap((f)=>l.map((m)=>{return at(e,t,m,f,i,a,u)}));if(await Promise.all(p),e.dts){let f=await Te(t,e.preferredTsconfigPath);if(f.path)c.cli(`Using tsconfig: ${x(f.path,2)}`,{muted:!0,identifier:e.name});let m=e.format.filter((E)=>{if(E==="iife"&&!I(i)&&e.format.includes("cjs"))return!1;return!0}),F=typeof e.dts==="object"&&e.dts.entry?L(e.dts.entry):l;try{await Promise.all(F.map(async(E)=>{let Ue=await Ce(t,E.path,e,f,n);await Promise.all(m.map(async(_e)=>{let Ne=ie(_e,i),q=`${t}/${e.outDir}/${E.name}${Ne}`;await Bun.write(q,Ue);let ke=Bun.file(q).size||0;c.progress("DTS",x(q),Y(ke),e.name)}))}))}catch(E){throw new g(h(E))}}}async function at(e,t,n,r,i,s,o){let a=se(r,i),l=await Bun.build({...o,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Be(n.name,a)},splitting:ae(e.splitting,r),bytecode:fe(e.bytecode,r),plugins:s,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new y(f.message);if(f.level==="warning")c.warn(f.message);else if(f.level==="info")c.info(f.message)}let u=`${t}/${e.outDir}/${n.name}${a}`,p=Bun.file(u).size||0;c.progress(r.toUpperCase(),x(u),Y(p),e.name)}var j="0.3.74";var Le="https://bun.sh/docs/installation",De="https://bunup.arshadyaseen.com/#cli-options";function b(e){return(t,n)=>{n[e]=t===!0?!0:t==="true"}}function w(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new d(`Option --${e} requires a string value`)}}function Se(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function ct(){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${De}\x1B[0m
|
|
26
|
+
`),process.exit(0)}function ut(){console.log(j),process.exit(0)}var ft={name:{flags:["n","name"],handler:w("name")},format:{flags:["f","format"],handler:(e,t)=>{if(typeof e==="string")t.format=e.split(",");else throw new d("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:w("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:w("banner")},footer:{flags:["f","footer"],handler:w("footer")},external:{flags:["e","external"],handler:Se("external")},sourcemap:{flags:["sm","sourcemap"],handler:w("sourcemap")},target:{flags:["t","target"],handler:w("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:Se("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:b("bytecode")}},pt={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}}},mt={help:{flags:["h","help"],handler:()=>ct()},version:{flags:["v","version"],handler:()=>ut()}},D={};for(let e of Object.values(ft))if(e)for(let t of e.flags)D[t]=e.handler;for(let e of Object.values(pt))for(let t of e.flags)D[t]=e.handler;for(let e of Object.values(mt))for(let t of e.flags)D[t]=e.handler;function Ie(e){let t={},n={},r=0;while(r<e.length){let i=e[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,l]=i.slice(2).split("=",2);s=a,o=l}else{s=i.slice(2);let a=e[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=A(o);if(n[a])c.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);n[a]=o}else throw new d("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(n[a])c.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=o}else throw new d(`Option --entry.${a} requires a string value`)}else{let a=D[s];if(a)a(o,t);else throw new d(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=e[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let l=D[s];if(l)l(a,t);else throw new d(`Unknown option: -${s}`)}else{let s=A(i);if(n[s])c.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);n[s]=i}r++}if(Object.keys(n).length>0)t.entry=n;return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
|
|
27
|
+
To install Bun, visit ${Le}`)})();import{loadConfig as dt}from"coffi";import H from"node:path";import gt from"chokidar";async function Me(e,t){let n=new Set,r=L(e.entry);for(let a of r){let l=H.resolve(t,a.path),u=H.dirname(l);n.add(u)}let i=gt.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,H.join(t,e.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let l=performance.now();if(await W({...e,entry:r.map((u)=>u.path),clean:!1},t),e.onBuildSuccess?.(),!a)c.cli(`\uD83D\uDCE6 Rebuild finished in ${M(performance.now()-l)}`);await z()}catch(l){V(l)}finally{s=!1}};i.on("change",(a)=>{let l=H.relative(t,a);c.cli(`File changed: ${l}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new S(`Watcher error: ${h(a)}`)}),await o(!0)}async function ht(e=Bun.argv.slice(2)){let t=Ie(e),n=process.cwd(),{config:r,filepath:i}=await dt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1}),s=!r?[{rootDir:n,options:t}]:await ve(r,n);if(c.cli(`Using bunup v${j} and bun v${Bun.version}`,{muted:!0}),i)c.cli(`Using config file: ${x(i,2)}`,{muted:!0});let o=performance.now();c.cli("Build started");for(let{options:u,rootDir:p}of s){let f=X(u);await Promise.all(f.map((m)=>{if(ue(m.clean))le(p,ce(m.outDir))}))}await Promise.all(s.flatMap(({options:u,rootDir:p})=>{return X(u).map(async(m)=>{let F={...v,...m,...t};return xt(F,p)})}));let a=performance.now()-o,l=M(a);if(c.cli(`\u26A1\uFE0F Build completed in ${l}`),await z(),t.watch)c.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function z(){if(C.size>0)await Re(C),C.clear()}async function xt(e,t){if(e.watch)await Me(e,t);else await W(e,t),e.onBuildSuccess?.()}ht().catch((e)=>J(e));export{z as validateDtsFiles,ht as main};
|
package/build/index.d.mts
CHANGED
|
@@ -468,7 +468,7 @@ type DefineWorkspaceEntry = {
|
|
|
468
468
|
|
|
469
469
|
//#endregion
|
|
470
470
|
//#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
|
|
471
|
-
declare function defineConfig(options: DefineConfigEntry
|
|
471
|
+
declare function defineConfig(options: Arrayable<DefineConfigEntry>): Arrayable<DefineConfigEntry>;
|
|
472
472
|
declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
|
|
473
473
|
|
|
474
474
|
//#endregion
|
package/build/index.d.ts
CHANGED
|
@@ -468,7 +468,7 @@ type DefineWorkspaceEntry = {
|
|
|
468
468
|
|
|
469
469
|
//#endregion
|
|
470
470
|
//#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
|
|
471
|
-
declare function defineConfig(options: DefineConfigEntry
|
|
471
|
+
declare function defineConfig(options: Arrayable<DefineConfigEntry>): Arrayable<DefineConfigEntry>;
|
|
472
472
|
declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
|
|
473
473
|
|
|
474
474
|
//#endregion
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Lt=require("node:module");var Bt=Object.create;var{getPrototypeOf:Mt,defineProperty:y,getOwnPropertyNames:j,getOwnPropertyDescriptor:Tt}=Object,q=Object.prototype.hasOwnProperty;var E=(t,n,r)=>{r=t!=null?Bt(Mt(t)):{};let e=n||!t||!t.__esModule?y(r,"default",{value:t,enumerable:!0}):r;for(let i of j(t))if(!q.call(e,i))y(e,i,{get:()=>t[i],enumerable:!0});return e},F=new WeakMap,At=(t)=>{var n=F.get(t),r;if(n)return n;if(n=y({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((e)=>!q.call(n,e)&&y(n,e,{get:()=>t[e],enumerable:!(r=Tt(t,e))||r.enumerable}));return F.set(t,n),n};var St=(t,n)=>{for(var r in n)y(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var Kt={};St(Kt,{defineWorkspace:()=>X,defineConfig:()=>G,build:()=>wt});module.exports=At(Kt);function G(t){return t}function X(t){return t}var ct=require("rolldown"),ut=require("rolldown-plugin-dts");class I extends Error{constructor(t){super(t);this.name="BunupError"}}class $ extends I{constructor(t){super(t);this.name="BunupBuildError"}}class p extends I{constructor(t){super(t);this.name="BunupDTSBuildError"}}var x=(t)=>{if(t instanceof Error)return t.message;return String(t)};var Wt=E(require("node:fs/promises")),_t=E(require("node:path"));function H(t,n){return{outdir:`${n}/${t.outDir}`,minify:It(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function It(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function W(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){return Math.random().toString(36).substring(2,2+t)}function K(t,n){switch(t){case"esm":return".mjs";case"cjs":return D(n)?".cjs":".js";case"iife":return".global.js"}}function Y(t,n){switch(t){case"esm":return".d.mts";case"cjs":return D(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(t){return t==="module"}function Q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Z(t,n){return t===void 0?n==="esm":t}function _(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/1024**r).toFixed(2)} ${n[r]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function z(t,n){return n==="cjs"?t:void 0}function J(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${W(n)}($|\\/|\\\\)`):n)}function B(t,n){return J(t.external||[]).concat(Q(n).map((r)=>new RegExp(`^${W(r)}($|\\/|\\\\)`)))}function M(t){return J(t.noExternal||[])}var it=E(require("node:path")),ot=require("oxc-resolver");var d=E(require("node:path"));var P="\x00dts:",tt=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(O(e))return e;if(!i||!O(i))return null;let s=await T(e,n,r,C(i));if(!s)return null;let o=R(s);if(t.has(o))return A(o);return null},load(e){if(e.startsWith(P)){let i=C(e),s=t.get(i);if(s)return nt.add(i),s}return null}}};function rt(t){return t.tsconfig?.compilerOptions}function R(t){return t.replace(/\.tsx?$/,".d.ts")}function N(t){let n=d.default.dirname(t.path||""),r=rt(t);return r?.baseUrl?d.default.resolve(n,r.baseUrl):n}function et(t){let n=new Map,r=rt(t)?.paths;if(!r)return n;let e=N(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,d.default.join(e,a))}return n}function Ot(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?d.default.join(r,t):null}async function Nt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function T(t,n,r,e){let i=t.startsWith(".")?d.default.resolve(d.default.dirname(e||""),t):Ot(t,n,r);if(!i)return Promise.resolve(null);return Nt(i)}function O(t){return t.startsWith(P)}function C(t){return t.replace(P,"")}function A(t){return`${P}${t}`}var st;function at(t){return{name:"bunup:types-resolve",buildStart(){st||=new ot.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){let e=r?C(r):void 0;if(/\0/.test(n))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===n||!!e?.includes(a);else c=a.test(n)||!!(e&&a.test(e));return c}))return}let i=e?it.default.dirname(e):process.cwd(),{path:s}=await st.async(i,n);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function lt(t,n,r,e,i,s){let o=R(t),a=A(o),c=B(r,e),l=M(r);try{let{output:g}=await ct.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[tt(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&at(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),ut.dts()],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${x(g)}`)}}class w{static instance;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(!w.instance)w.instance=new w;return w.instance}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${c}`}output(t,n={},r=console.log){if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,c={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,c=r;for(let[g,u]of Object.entries(this.colors.progress))if(i.includes(g)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var f=w.getInstance();var Ut=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Xt(t){let n=new Set,r=[Ut,vt,Vt,Ft,jt,qt,Gt];for(let e of r){let i=t.matchAll(e);for(let s of i)if(s[1])n.add(s[1])}return n}async function ft(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Xt(o);for(let c of a){let l=await T(c,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${x(o)}`)}}return e}var gt=require("oxc-transform");async function mt(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=R(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=gt.isolatedDeclaration(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),n}var U=E(require("node:fs/promises")),S=E(require("node:path")),Ht=require("oxc-transform");async function pt(t,n){let r=S.default.resolve(t),e=S.default.resolve(r,n);if(!await U.default.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(S.default.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function xt(t,n,r,e,i){let{absoluteEntry:s}=await pt(t,n),o=et(e),a=N(e),c=await ft(s,o,a),l=await mt(c);return lt(s,l,r,i,o,a)}function dt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=k(),c=`${s}_${a}`;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
|
${e[s]} -> ${s}.js
|
|
5
|
-
${
|
|
5
|
+
${o} -> ${c}.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
10
|
custom_name: "${e[s]}",
|
|
11
|
-
another_name: "${
|
|
11
|
+
another_name: "${o}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:c,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=dt(s);i(o,s)}else if(typeof t==="object")for(let[s,o]of Object.entries(t))i(s,o);else{let s=dt(t);i(s,t)}return n}function ht(t,n){return`[dir]/${t}${n}`}var V=require("coffi");async function Et(t){let{config:n,filepath:r}=await V.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:n,path:r}}async function bt(t,n){let{config:r,filepath:e}=await V.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:n,maxDepth:3});return{tsconfig:r,path:e}}function Rt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var nt=new Set;async function wt(t,n){if(!t.entry||t.entry.length===0||!t.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 Et(n);if(r&&e)f.cli(`Using package.json: ${b(e,2)}`,{muted:!0,identifier:t.name});let i=r?.type,s=B(t,r),o=M(t),a=[Rt(s,o)],c=v(t.entry),l=H(t,n),g=t.format.flatMap((u)=>c.map((m)=>{return kt(t,n,m,u,i,a,l)}));if(await Promise.all(g),t.dts){let u=await bt(n,t.preferredTsconfigPath);if(u.path)f.cli(`Using tsconfig: ${b(u.path,2)}`,{muted:!0,identifier:t.name});let m=t.format.filter((h)=>{if(h==="iife"&&!D(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?v(t.dts.entry):c;try{await Promise.all(yt.map(async(h)=>{let $t=await xt(n,h.path,t,u,r);await Promise.all(m.map(async(Ct)=>{let Pt=Y(Ct,i),L=`${n}/${t.outDir}/${h.name}${Pt}`;await Bun.write(L,$t);let Dt=Bun.file(L).size||0;f.progress("DTS",b(L),_(Dt),t.name)}))}))}catch(h){throw new p(x(h))}}}async function kt(t,n,r,e,i,s,o){let a=K(e,i),c=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:ht(r.name,a)},splitting:Z(t.splitting,e),bytecode:z(t.bytecode,e),plugins:s,throw:!1});if(!c.success)for(let u of c.logs){if(u.level==="error")throw new $(u.message);if(u.level==="warning")f.warn(u.message);else if(u.level==="info")f.info(u.message)}let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),b(l),_(g),t.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function
|
|
1
|
+
function pt(t){return t}function xt(t){return t}import{build as wt}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class A extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends A{constructor(t){super(t);this.name="BunupBuildError"}}class p extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var x=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import Ft from"node:path";function N(t,n){return{outdir:`${n}/${t.outDir}`,minify:dt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function dt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function S(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(t=8){return Math.random().toString(36).substring(2,2+t)}function v(t,n){switch(t){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function V(t,n){switch(t){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function F(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function j(t,n){return t===void 0?n==="esm":t}function L(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/1024**r).toFixed(2)} ${n[r]}`}function h(t,n=3){return t.split("/").slice(-n).join("/")}function q(t,n){return n==="cjs"?t:void 0}function G(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${S(n)}($|\\/|\\\\)`):n)}function P(t,n){return G(t.external||[]).concat(F(n).map((r)=>new RegExp(`^${S(r)}($|\\/|\\\\)`)))}function D(t){return G(t.noExternal||[])}import bt from"node:path";import{ResolverFactory as Rt}from"oxc-resolver";import b from"node:path";var $="\x00dts:",X=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(I(e))return e;if(!i||!I(i))return null;let s=await B(e,n,r,y(i));if(!s)return null;let o=E(s);if(t.has(o))return M(o);return null},load(e){if(e.startsWith($)){let i=y(e),s=t.get(i);if(s)return H.add(i),s}return null}}};function k(t){return t.tsconfig?.compilerOptions}function E(t){return t.replace(/\.tsx?$/,".d.ts")}function W(t){let n=b.dirname(t.path||""),r=k(t);return r?.baseUrl?b.resolve(n,r.baseUrl):n}function K(t){let n=new Map,r=k(t)?.paths;if(!r)return n;let e=W(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,b.join(e,a))}return n}function ht(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?b.join(r,t):null}async function Et(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function B(t,n,r,e){let i=t.startsWith(".")?b.resolve(b.dirname(e||""),t):ht(t,n,r);if(!i)return Promise.resolve(null);return Et(i)}function I(t){return t.startsWith($)}function y(t){return t.replace($,"")}function M(t){return`${$}${t}`}var Y;function Q(t){return{name:"bunup:types-resolve",buildStart(){Y||=new Rt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){let e=r?y(r):void 0;if(/\0/.test(n))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===n||!!e?.includes(a);else c=a.test(n)||!!(e&&a.test(e));return c}))return}let i=e?bt.dirname(e):process.cwd(),{path:s}=await Y.async(i,n);if(!s)return;if(/[cm]?jsx?$/.test(s)){let o=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(o).exists()?o:void 0}return s}}}async function Z(t,n,r,e,i,s){let o=E(t),a=M(o),c=P(r,e),l=D(r);try{let{output:g}=await wt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;m(u)},plugins:[X(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&Q(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),yt()],external:(u)=>c.some((m)=>m.test(u))&&!l.some((m)=>m.test(u))});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${x(g)}`)}}class R{static instance;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(!R.instance)R.instance=new R;return R.instance}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${u} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${c}`}output(t,n={},r=console.log){if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,c={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,c=r;for(let[g,u]of Object.entries(this.colors.progress))if(i.includes(g)){s=u;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:c.muted});this.output(l,c)}}var f=R.getInstance();var $t=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ct=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Pt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Dt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Tt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function At(t){let n=new Set,r=[$t,Ct,Pt,Dt,Bt,Mt,Tt];for(let e of r){let i=t.matchAll(e);for(let s of i)if(s[1])n.add(s[1])}return n}async function z(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=At(o);for(let c of a){let l=await B(c,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${x(o)}`)}}return e}import{isolatedDeclaration as St}from"oxc-transform";async function J(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=E(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=St(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),n}import tt from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as Pn}from"oxc-transform";async function nt(t,n){let r=_.resolve(t),e=_.resolve(r,n);if(!await tt.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(_.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function rt(t,n,r,e,i){let{absoluteEntry:s}=await nt(t,n),o=K(e),a=W(e),c=await z(s,o,a),l=await J(c);return Z(s,l,r,i,o,a)}function et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function O(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=U(),c=`${s}_${a}`;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
|
${e[s]} -> ${s}.js
|
|
5
|
-
${
|
|
5
|
+
${o} -> ${c}.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
10
|
custom_name: "${e[s]}",
|
|
11
|
-
another_name: "${
|
|
11
|
+
another_name: "${o}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:c,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=et(s);i(o,s)}else if(typeof t==="object")for(let[s,o]of Object.entries(t))i(s,o);else{let s=et(t);i(s,t)}return n}function st(t,n){return`[dir]/${t}${n}`}import{loadConfig as it}from"coffi";async function ot(t){let{config:n,filepath:r}=await it({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:n,path:r}}async function at(t,n){let{config:r,filepath:e}=await it({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:n,maxDepth:3});return{tsconfig:r,path:e}}function ct(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var H=new Set;async function Lt(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await ot(n);if(r&&e)f.cli(`Using package.json: ${h(e,2)}`,{muted:!0,identifier:t.name});let i=r?.type,s=P(t,r),o=D(t),a=[ct(s,o)],c=O(t.entry),l=N(t,n),g=t.format.flatMap((u)=>c.map((m)=>{return It(t,n,m,u,i,a,l)}));if(await Promise.all(g),t.dts){let u=await at(n,t.preferredTsconfigPath);if(u.path)f.cli(`Using tsconfig: ${h(u.path,2)}`,{muted:!0,identifier:t.name});let m=t.format.filter((d)=>{if(d==="iife"&&!C(i)&&t.format.includes("cjs"))return!1;return!0}),ut=typeof t.dts==="object"&&t.dts.entry?O(t.dts.entry):c;try{await Promise.all(ut.map(async(d)=>{let lt=await rt(n,d.path,t,u,r);await Promise.all(m.map(async(ft)=>{let gt=V(ft,i),T=`${n}/${t.outDir}/${d.name}${gt}`;await Bun.write(T,lt);let mt=Bun.file(T).size||0;f.progress("DTS",h(T),L(mt),t.name)}))}))}catch(d){throw new p(x(d))}}}async function It(t,n,r,e,i,s,o){let a=v(e,i),c=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:st(r.name,a)},splitting:j(t.splitting,e),bytecode:q(t.bytecode,e),plugins:s,throw:!1});if(!c.success)for(let u of c.logs){if(u.level==="error")throw new w(u.message);if(u.level==="warning")f.warn(u.message);else if(u.level==="info")f.info(u.message)}let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),h(l),L(g),t.name)}export{xt as defineWorkspace,pt as defineConfig,Lt as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.74",
|
|
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",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"@commitlint/config-conventional": "^19.5.0",
|
|
18
18
|
"@types/bun": "^1.2.5",
|
|
19
19
|
"bumpp": "^10.1.0",
|
|
20
|
-
"bunup": "^0.3.
|
|
20
|
+
"bunup": "^0.3.73",
|
|
21
21
|
"husky": "^9.1.7",
|
|
22
22
|
"typescript": "^5.8.3",
|
|
23
23
|
"vitest": "^2.1.9",
|
|
24
|
-
"create-bunup": "0.3.
|
|
24
|
+
"create-bunup": "0.3.74"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"typescript": ">=4.5.0"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"chokidar": "^4.0.3",
|
|
55
|
-
"
|
|
55
|
+
"coffi": "^0.1.16",
|
|
56
56
|
"oxc-resolver": "^5.0.1",
|
|
57
57
|
"oxc-transform": "^0.58.1",
|
|
58
58
|
"rolldown": "1.0.0-beta.7",
|