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