bunup 0.2.2 → 0.2.4
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/README.md +11 -9
- package/build/cli.mjs +8 -8
- package/build/index.d.mts +3 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +1 -1
- package/build/index.mjs +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -5,20 +5,22 @@
|
|
|
5
5
|
|
|
6
6
|
An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by [Bun](https://bun.sh) and [Oxc](https://oxc.rs/).
|
|
7
7
|
|
|
8
|
-
| Bundler
|
|
9
|
-
|
|
|
10
|
-
| bunup
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
8
|
+
| Bundler | Format | dts | Build Time |
|
|
9
|
+
| ------- | -------- | ----- | -------------- |
|
|
10
|
+
| bunup | esm, cjs | false | **0.90ms ⚡️** |
|
|
11
|
+
| tsdown | esm, cjs | false | 3.78ms |
|
|
12
|
+
| unbuild | esm, cjs | false | 12.76ms |
|
|
13
|
+
| bunup | esm, cjs | true | **7.38ms ⚡️** |
|
|
14
|
+
| tsdown | esm, cjs | true | 15.17ms |
|
|
15
|
+
| unbuild | esm, cjs | true | 257.60ms |
|
|
16
16
|
|
|
17
17
|
_Lower build time is better. Benchmark run on the same code with identical output formats._
|
|
18
18
|
|
|
19
|
+
To run the benchmarks yourself, clone this repo and run `pnpm benchmark`.
|
|
20
|
+
|
|
19
21
|
## 🚀 Quick Start
|
|
20
22
|
|
|
21
|
-
###
|
|
23
|
+
### Installations
|
|
22
24
|
|
|
23
25
|
```bash
|
|
24
26
|
# Using Bun
|
package/build/cli.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{loadTsConfig as
|
|
3
|
+
import{loadTsConfig as An}from"load-tsconfig";class E extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends E{constructor(n){super(n);this.name="BunupBuildError"}}class m extends E{constructor(n){super(n);this.name="BunupDTSBuildError"}}class d extends E{constructor(n){super(n);this.name="BunupCLIError"}}class b extends E{constructor(n){super(n);this.name="BunupWatchError"}}var u=(n)=>{if(n instanceof Error)return n.message;return String(n)},Tn=(n,r)=>{let t=u(n),e=r?`[${r}] `:"",o="ERROR";if(n instanceof w)o="BUILD ERROR";else if(n instanceof m)o="DTS ERROR";else if(n instanceof d)o="CLI ERROR";else if(n instanceof b)o="WATCH ERROR";else if(n instanceof E)o="BUNUP ERROR";if(console.error(`\x1B[31m${o}\x1B[0m ${e}${t}`),n instanceof Error&&n.stack)console.error("\x1B[2m"+n.stack.split(`
|
|
4
4
|
`).slice(1).join(`
|
|
5
|
-
`)+"\x1B[0m")},
|
|
6
|
-
`);let a
|
|
5
|
+
`)+"\x1B[0m")},Z=(n,r)=>{Tn(n,r),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(n,r,t,e,o){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length));if(e){let[i,...c]=t.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-i.length)),g=o?` \x1B[48;5;${n};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${n}m${r}\x1B[0m ${s}${i}${p} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${c.join(" ")}${g}`}let a=o?` \x1B[48;5;${n};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${n}m${r}\x1B[0m ${s}${t}${a}`},cli(n){let r=this.labels.cli;console.log(this.formatMessage(this.colors.cli,r,n))},info(n){console.log(`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`)},warn(n){let r=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,r,n))},error(n){let r=this.labels.error;console.error(this.formatMessage(this.colors.error,r,n))},progress(n,r,t,e){let o=String(n),s=this.colors.default;for(let[a,i]of Object.entries(this.colors.progress))if(o.includes(a)){s=i;break}console.log(this.formatMessage(s,o,r,t,e))}};function z(n){try{return An(".",n)}catch(r){return l.warn(`Failed to load tsconfig: ${u(r)}`),{path:n,data:{},files:[]}}}import{rollup as Gn}from"rollup";import qn from"rollup-plugin-dts";import J from"typescript";import L from"node:fs";import Un from"node:path";var R={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0,sourcemap:"none"};function X(n,r){return{outdir:`${r}/${n.outDir}`,minify:jn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap}}function jn(n){let{minify:r,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=n,s=r===!0;return{whitespace:t??s,identifiers:e??s,syntax:o??s}}function _(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(n=8){return Math.random().toString(36).substring(2,2+n)}function nn(n,r){switch(n){case"esm":return".mjs";case"cjs":return N(r)?".cjs":".js";case"iife":return".global.js"}}function rn(n,r){switch(n){case"esm":return".d.mts";case"cjs":return N(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function tn(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function en(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function on(n,r){return n===void 0?r==="esm":n}function G(n){if(n===0)return"0 B";let r=["B","KB","MB","GB"],t=Math.floor(Math.log(n)/Math.log(1024));if(t===0)return`${n} ${r[t]}`;return`${(n/Math.pow(1024,t)).toFixed(2)} ${r[t]}`}function C(n,r=3){return n.split("/").slice(-r).join("/")}function q(n,r){let t=Un.join(n,r);if(L.existsSync(t))try{L.rmSync(t,{recursive:!0,force:!0})}catch(e){throw new w(`Failed to clean output directory: ${e}`)}L.mkdirSync(t,{recursive:!0})}function I(n){return n||R.outDir}function sn(n){return n.map((r)=>typeof r==="string"?new RegExp(`^${_(r)}($|\\/|\\\\)`):r)}function T(n,r){return sn(n.external||[]).concat(en(r).map((t)=>new RegExp(`^${_(t)}($|\\/|\\\\)`)))}function A(n){return sn(n.noExternal||[])}import j from"node:fs";import F from"node:path";async function an(n){let r=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let t of r){let e=F.join(n,`bunup.config${t}`);try{if(!j.existsSync(e))continue;let o=await Mn(e,t);if(!o)continue;return{configs:Wn(o,n),configFilePath:e}}catch(o){throw new w(`Failed to load config from ${e}: ${u(o)}`)}}return{configs:[],configFilePath:""}}async function Mn(n,r){if(r===".json"||r===".jsonc")return Hn(n);return Dn(n)}function Hn(n){try{let r=j.readFileSync(n,"utf8"),t=JSON.parse(r);return t.bunup||t}catch(r){throw new Error(`Invalid JSON in config file. ${u(r)}`)}}async function Dn(n){try{let r=await import(`file://${n}`),t=r.default||r;if(!t)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return t}catch(r){throw new Error(`Failed to import config file. ${u(r)}`)}}function Wn(n,r){let t=[];if(kn(n))Ln(n,r,t);else if(Array.isArray(n))_n(n,r,t);else if(n&&typeof n==="object")t.push({options:n,rootDir:r});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return t}function kn(n){return Array.isArray(n)&&n.length>0&&n.every((r)=>typeof r==="object"&&r!==null&&("name"in r)&&("root"in r)&&("config"in r))}function Ln(n,r,t){for(let e of n){let o=F.resolve(r,e.root);if(Array.isArray(e.config))for(let s of e.config)t.push({options:{name:e.name,...s},rootDir:o});else t.push({options:{name:e.name,...e.config},rootDir:o})}}function _n(n,r,t){for(let e of n){if(!e||typeof e!=="object")throw new Error("Invalid configuration item. Expected an object.");t.push({options:e,rootDir:r})}}function U(n){let r=F.join(n,"package.json");try{if(!j.existsSync(r))return null;let t=j.readFileSync(r,"utf8");return JSON.parse(t)}catch(t){return l.warn(`Failed to load package.json at ${r}: ${u(t)}`),null}}import B from"path";var h="\x00virtual:",cn=(n)=>{return{name:"bunup:virtual-dts",resolveId(r,t){if(r.startsWith(h))return r;if(!t?.startsWith(h)||!r.startsWith("."))return null;let e=t.slice(h.length),o=B.resolve(B.dirname(e),r);if(r==="."){let a=B.join(B.dirname(e),"index.d.ts");if(n.has(a))return`${h}${a}`;o=B.dirname(e)}if(n.has(o))return`${h}${o}`;let s=`${o}.d.ts`;if(n.has(s))return`${h}${s}`;if(r.startsWith(".")){let a=B.join(o,"index.d.ts");if(n.has(a))return`${h}${a}`}return null},load(r){if(r.startsWith(h)){let t=r.slice(h.length),e=n.get(t);if(e)return v.add(t),e}return null}}};async function ln(n,r,t,e,o){let s=n.replace(/\.tsx?$/,".d.ts"),a=`${h}${s}`,i=o.data?.compilerOptions,c=U(e),p=T(t,c),g=A(t),f;try{f=await Gn({input:a,onwarn(O,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(O.code??""))return;$(O)},plugins:[cn(r),qn({tsconfig:o.path,compilerOptions:{...i?J.parseJsonConfigFileContent({compilerOptions:i},J.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:J.ScriptTarget.ESNext}})],external:(O)=>p.some(($)=>$.test(O))&&!g.some(($)=>$.test(O))});let{output:x}=await f.generate({});if(!x[0]?.code)throw new m("Generated bundle is empty");return x[0].code}catch(x){throw new m(`DTS bundling failed: ${u(x)}`)}finally{if(f)await f.close()}}import gn from"node:fs";import un from"node:path";import M from"node:path";function P(n){let r=M.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?M.resolve(r,n.data.compilerOptions.baseUrl):r}function fn(n){let r=new Map,t=n.data?.compilerOptions?.paths;if(!t)return r;let e=P(n);for(let[o,s]of Object.entries(t))if(Array.isArray(s)&&s.length){let a=o.replace(/\*/g,"(.*)"),i=s[0].replace(/\*/g,"$1");r.set(`^${a}$`,M.join(e,i))}return r}function pn(n,r,t){for(let[e,o]of r){let s=new RegExp(e),a=n.match(s);if(a)return o.replace("$1",a[1]||"")}return t?M.join(t,n):null}var In=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Fn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function mn(n,r){let t=new Set([n]),e=[n],o=fn(r),s=P(r);while(e.length){let a=e.pop();if(!a)continue;try{let i=await gn.promises.readFile(a,"utf8"),c=Jn(i);for(let p of c){let g=p.startsWith(".")?un.resolve(un.dirname(a),p):pn(p,o,s);if(!g)continue;let f=Pn(g);if(f&&!t.has(f))t.add(f),e.push(f)}}catch(i){l.warn(`Error processing ${a}: ${u(i)}`)}}return t}function Jn(n){let r=new Set;for(let t of[In,Fn]){let e;while((e=t.exec(n))!==null)r.add(e[2])}return Array.from(r)}function Pn(n){let r=["",".ts",".tsx","/index.ts","/index.tsx"];for(let t of r){let e=`${n}${t}`;if(gn.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}import Yn from"node:fs";import{isolatedDeclaration as Kn}from"oxc-transform";async function dn(n){let r=new Map;return await Promise.all([...n].map(async(t)=>{try{let e=t.replace(/\.tsx?$/,".d.ts"),o=await Yn.promises.readFile(t,"utf8"),{code:s}=Kn(t,o);if(s)r.set(e,s)}catch(e){l.warn(`Failed to generate declaration for ${t}: ${u(e)}`)}})),r}import K from"node:fs";import Y from"node:path";import{isolatedDeclaration as Qn}from"oxc-transform";function xn(n,r){let t=Y.resolve(n),e=Y.resolve(t,r);if(!K.existsSync(t))throw new m(`Root directory does not exist: ${t}`);if(!K.existsSync(e))throw new m(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new m(`Entry file must be a TypeScript file (.ts): ${e}`);if(Y.relative(t,e).startsWith(".."))throw new m(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function hn(n){let r=!1;if(await Promise.all([...n].map(async(t)=>{try{let e=t.replace(/\.d\.ts$/,".ts"),o=await K.promises.readFile(e,"utf8"),{errors:s}=Qn(e,o);s.forEach((a)=>{if(!r)console.log(`
|
|
6
|
+
`);let i=a.labels[0],c=i?Zn(o,i.start):"",g=`${C(e)}${c}: ${zn(a.message)}`;l.warn(g),r=!0})}catch{}})),r)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
|
-
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function
|
|
8
|
+
`)}function Zn(n,r){if(r===void 0)return"";let t=n.slice(0,r).split(`
|
|
9
|
+
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function zn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function wn(n,r,t){let{absoluteRootDir:e,absoluteEntry:o}=xn(n,r),s=z(t.preferredTsconfigPath),a=await mn(o,s),i=await dn(a);return ln(o,i,t,e,s)}function Xn(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function S(n){let r=[],t=new Set;function e(o,s){if(t.has(o)){let a=V();r.push({name:`${o}_${a}`,path:s})}else r.push({name:o,path:s}),t.add(o)}if(Array.isArray(n))for(let o of n){let s=Xn(o);e(s,o)}else Object.entries(n).forEach(([o,s])=>{e(o,s)});return r}function yn(n,r){return`[dir]/${n}${r}`}function On(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(n.some((a)=>a.test(o))&&!r.some((a)=>a.test(o)))return{path:o,external:!0};return null})}}}var v=new Set;async function H(n,r){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 t=U(r),e=t?.type,o=T(n,t),s=A(n),a=[On(o,s)],i=S(n.entry),c=X(n,r),p=n.format.flatMap((g)=>i.map((f)=>{return Vn(n,r,f,g,e,a,c)}));try{await Promise.all(p)}catch(g){throw console.error(g),new w("Build process encountered errors")}if(n.dts){let g=n.format.filter((x)=>{if(x==="iife"&&!N(e)&&n.format.includes("cjs"))return!1;return!0}),f=n.dts===!0?i:S(n.dts.entry);try{await Promise.all(f.map(async(x)=>{let O=await wn(r,x.path,n);await Promise.all(g.map(async($)=>{let Sn=rn($,e),k=`${r}/${n.outDir}/${x.name}${Sn}`;await Bun.write(k,O);let Nn=Bun.file(k).size||0;l.progress("DTS",C(k),G(Nn),n.name)}))}))}catch(x){throw new m(`DTS build process encountered errors: ${u(x)}`)}}}async function Vn(n,r,t,e,o,s,a){let i=nn(e,o),c=await Bun.build({...a,entrypoints:[`${r}/${t.path}`],format:e,naming:{entry:yn(t.name,i)},splitting:on(n.splitting,e),plugins:s,throw:!1});if(!c.success)throw c.logs.forEach((f)=>{if(f.level==="error")l.error(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)}),new w(`Build failed for ${t.path} (${e})`);let p=`${r}/${n.outDir}/${t.name}${i}`,g=Bun.file(p).size||0;l.progress(e.toUpperCase(),C(p),G(g),n.name)}var $n="https://bun.sh/docs/installation",Cn="https://bunup.arshadyaseen.com/#cli-options";function y(n){return(r,t)=>{t[n]=r===!0?!0:r==="true"}}function D(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new d(`Option --${n} requires a string value`)}}function En(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new d(`Option --${n} requires a string value`)}}function nr(){console.log(`
|
|
10
10
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
11
|
-
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${
|
|
12
|
-
`),process.exit(0)}var
|
|
13
|
-
To install Bun, visit
|
|
11
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Cn}\x1B[0m
|
|
12
|
+
`),process.exit(0)}var rr={name:{flags:["n","name"],handler:D("name")},format:{flags:["f","format"],handler:(n,r)=>{if(typeof n==="string")r.format=n.split(",");else throw new d("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:D("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},external:{flags:["e","external"],handler:En("external")},sourcemap:{flags:["sm","sourcemap"],handler:D("sourcemap")},target:{flags:["t","target"],handler:D("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:En("noExternal")}},tr={help:{flags:["h","help"],handler:()=>nr()}},W={};for(let n of Object.values(rr))if(n)for(let r of n.flags)W[r]=n.handler;for(let n of Object.values(tr))for(let r of n.flags)W[r]=n.handler;function Bn(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function vn(n){let r={},t={},e=0;while(e<n.length){let o=n[e];if(o.startsWith("--")){let s,a;if(o.includes("=")){let[i,c]=o.slice(2).split("=",2);s=i,a=c}else{s=o.slice(2);let i=n[e+1];if(a=i&&!i.startsWith("-")?i:!0,typeof a==="string")e++}if(s==="entry")if(typeof a==="string"){let i=Bn(a);if(t[i])l.warn(`Duplicate entry name '${i}' derived from '${a}'. Overwriting previous entry.`);t[i]=a}else throw new d("Option --entry requires a string value");else if(s.startsWith("entry.")){let i=s.slice(6);if(typeof a==="string"){if(t[i])l.warn(`Duplicate entry name '${i}' provided via --entry.${i}. Overwriting previous entry.`);t[i]=a}else throw new d(`Option --entry.${i} requires a string value`)}else{let i=W[s];if(i)i(a,r);else throw new d(`Unknown option: --${s}`)}}else if(o.startsWith("-")){let s=o.slice(1),a=n[e+1],i=a&&!a.startsWith("-")?a:!0;if(typeof i==="string")e++;let c=W[s];if(c)c(i,r);else throw new d(`Unknown option: -${s}`)}else{let s=Bn(o);if(t[s])l.warn(`Duplicate entry name '${s}' derived from positional argument '${o}'. Overwriting previous entry.`);t[s]=o}e++}if(Object.keys(t).length>0)r.entry=t;return r}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
|
|
13
|
+
To install Bun, visit `+$n)})();import Q from"node:path";import er from"chokidar";async function bn(n,r){let t=new Set,e=S(n.entry);e.forEach((c)=>{let p=Q.resolve(r,c.path),g=Q.dirname(p);t.add(g)});let o=er.watch(Array.from(t),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,n.outDir]}),s=null,a=!1,i=async()=>{if(a)return;a=!0;try{await H({...n,entry:e.map((c)=>c.path),clean:!1},r),n.onBuildEnd?.()}catch(c){throw new b(`Build failed: ${u(c)}`)}finally{a=!1}};o.on("change",(c)=>{let p=Q.relative(r,c);if(l.cli(`File changed: ${p}`),s)clearTimeout(s);s=setTimeout(()=>i(),300)}),o.on("error",(c)=>{throw new b(`Watcher error: ${u(c)}`)}),await i()}async function or(n=Bun.argv.slice(2)){let r=vn(n),{configs:t,configFilePath:e}=await an(process.cwd());if(e)l.cli(`Using config file: ${C(e,2)}`);if(r.watch)l.cli("Starting watch mode"),l.cli("Watching for file changes");let o=performance.now();if(l.cli("Build started"),t.length===0){let i={...R,...r},c=process.cwd();if(i.clean)q(c,I(i.outDir));await Rn(i,c)}else{for(let{options:i,rootDir:c}of t)if(i.clean)q(c,I(i.outDir));await Promise.all(t.map(async({options:i,rootDir:c})=>{let p={...R,...i,...r};await Rn(p,c)}))}let s=performance.now()-o,a=tn(s);if(l.cli(`\u26A1\uFE0F Build completed in ${a}`),v.size>0)await hn(v),v.clear();if(!r.watch)process.exit(0)}async function Rn(n,r){if(n.watch)await bn(n,r);else await H(n,r),n.onBuildEnd?.()}or().catch((n)=>Z(n));export{or as main};
|
package/build/index.d.mts
CHANGED
|
@@ -171,7 +171,9 @@ interface BunupOptions {
|
|
|
171
171
|
declare function defineConfig(options: DefineConfigOptions): DefineConfigOptions;
|
|
172
172
|
declare function defineWorkspace(options: DefineWorkspaceOptions): DefineWorkspaceOptions;
|
|
173
173
|
|
|
174
|
+
declare function build(options: BunupOptions, rootDir: string): Promise<void>;
|
|
175
|
+
|
|
174
176
|
type Options = Partial<BunupOptions>;
|
|
175
177
|
|
|
176
|
-
export { defineConfig, defineWorkspace };
|
|
178
|
+
export { build, defineConfig, defineWorkspace };
|
|
177
179
|
export type { Options };
|
package/build/index.d.ts
CHANGED
|
@@ -171,7 +171,9 @@ interface BunupOptions {
|
|
|
171
171
|
declare function defineConfig(options: DefineConfigOptions): DefineConfigOptions;
|
|
172
172
|
declare function defineWorkspace(options: DefineWorkspaceOptions): DefineWorkspaceOptions;
|
|
173
173
|
|
|
174
|
+
declare function build(options: BunupOptions, rootDir: string): Promise<void>;
|
|
175
|
+
|
|
174
176
|
type Options = Partial<BunupOptions>;
|
|
175
177
|
|
|
176
|
-
export { defineConfig, defineWorkspace };
|
|
178
|
+
export { build, defineConfig, defineWorkspace };
|
|
177
179
|
export type { Options };
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var D=require("node:module");var{defineProperty:p,getOwnPropertyNames:s,getOwnPropertyDescriptor:O}=Object,u=Object.prototype.hasOwnProperty;var t=new WeakMap,a=(e)=>{var n=t.get(e),o;if(n)return n;if(n=p({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")s(e).map((i)=>!u.call(n,i)&&p(n,i,{get:()=>e[i],enumerable:!(o=O(e,i))||o.enumerable}));return t.set(e,n),n};var c=(e,n)=>{for(var o in n)p(e,o,{get:n[o],enumerable:!0,configurable:!0,set:(i)=>n[o]=()=>i})};var g={};c(g,{defineWorkspace:()=>r,defineConfig:()=>f});module.exports=a(g);function f(e){return e}function r(e){return e}
|
|
1
|
+
var Rr=require("node:module");var hr=Object.create;var{getPrototypeOf:Cr,defineProperty:y,getOwnPropertyNames:U,getOwnPropertyDescriptor:yr}=Object,K=Object.prototype.hasOwnProperty;var g=(r,n,t)=>{t=r!=null?hr(Cr(r)):{};let o=n||!r||!r.__esModule?y(t,"default",{value:r,enumerable:!0}):t;for(let s of U(r))if(!K.call(o,s))y(o,s,{get:()=>r[s],enumerable:!0});return o},q=new WeakMap,Or=(r)=>{var n=q.get(r),t;if(n)return n;if(n=y({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")U(r).map((o)=>!K.call(n,o)&&y(n,o,{get:()=>r[o],enumerable:!(t=yr(r,o))||t.enumerable}));return q.set(r,n),n};var br=(r,n)=>{for(var t in n)y(r,t,{get:n[t],enumerable:!0,configurable:!0,set:(o)=>n[t]=()=>o})};var Gr={};br(Gr,{defineWorkspace:()=>Q,defineConfig:()=>L,build:()=>$r});module.exports=Or(Gr);function L(r){return r}function Q(r){return r}var Z=require("load-tsconfig");class M extends Error{constructor(r){super(r);this.name="BunupError"}}class h extends M{constructor(r){super(r);this.name="BunupBuildError"}}class x extends M{constructor(r){super(r);this.name="BunupDTSBuildError"}}var u=(r)=>{if(r instanceof Error)return r.message;return String(r)};var f={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(r,n,t,o,s){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));if(o){let[c,...$]=t.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),l=s?` \x1B[48;5;${r};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${e}${c}${p} \x1B[38;5;${this.colors.size}m${o}\x1B[0m ${$.join(" ")}${l}`}let i=s?` \x1B[48;5;${r};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${e}${t}${i}`},cli(r){let n=this.labels.cli;console.log(this.formatMessage(this.colors.cli,n,r))},info(r){console.log(`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`)},warn(r){let n=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,n,r))},error(r){let n=this.labels.error;console.error(this.formatMessage(this.colors.error,n,r))},progress(r,n,t,o){let s=String(r),e=this.colors.default;for(let[i,c]of Object.entries(this.colors.progress))if(s.includes(i)){e=c;break}console.log(this.formatMessage(e,s,n,t,o))}};function z(r){try{return Z.loadTsConfig(".",r)}catch(n){return f.warn(`Failed to load tsconfig: ${u(n)}`),{path:r,data:{},files:[]}}}var sr=require("rollup"),er=g(require("rollup-plugin-dts")),j=g(require("typescript"));var vr=g(require("node:fs")),Sr=g(require("node:path"));function _(r,n){return{outdir:`${n}/${r.outDir}`,minify:Br(r),target:r.target,splitting:r.splitting,sourcemap:r.sourcemap}}function Br(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:o,minifySyntax:s}=r,e=n===!0;return{whitespace:t??e,identifiers:o??e,syntax:s??e}}function T(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function F(r=8){return Math.random().toString(36).substring(2,2+r)}function P(r,n){switch(r){case"esm":return".mjs";case"cjs":return b(n)?".cjs":".js";case"iife":return".global.js"}}function X(r,n){switch(r){case"esm":return".d.mts";case"cjs":return b(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function b(r){return r==="module"}function I(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function V(r,n){return r===void 0?n==="esm":r}function D(r){if(r===0)return"0 B";let n=["B","KB","MB","GB"],t=Math.floor(Math.log(r)/Math.log(1024));if(t===0)return`${r} ${n[t]}`;return`${(r/Math.pow(1024,t)).toFixed(2)} ${n[t]}`}function R(r,n=3){return r.split("/").slice(-n).join("/")}function rr(r){return r.map((n)=>typeof n==="string"?new RegExp(`^${T(n)}($|\\/|\\\\)`):n)}function B(r,n){return rr(r.external||[]).concat(I(n).map((t)=>new RegExp(`^${T(t)}($|\\/|\\\\)`)))}function v(r){return rr(r.noExternal||[])}var W=g(require("node:fs")),nr=g(require("node:path"));function S(r){let n=nr.default.join(r,"package.json");try{if(!W.default.existsSync(n))return null;let t=W.default.readFileSync(n,"utf8");return JSON.parse(t)}catch(t){return f.warn(`Failed to load package.json at ${n}: ${u(t)}`),null}}var C=g(require("path"));var d="\x00virtual:",tr=(r)=>{return{name:"bunup:virtual-dts",resolveId(n,t){if(n.startsWith(d))return n;if(!t?.startsWith(d)||!n.startsWith("."))return null;let o=t.slice(d.length),s=C.default.resolve(C.default.dirname(o),n);if(n==="."){let i=C.default.join(C.default.dirname(o),"index.d.ts");if(r.has(i))return`${d}${i}`;s=C.default.dirname(o)}if(r.has(s))return`${d}${s}`;let e=`${s}.d.ts`;if(r.has(e))return`${d}${e}`;if(n.startsWith(".")){let i=C.default.join(s,"index.d.ts");if(r.has(i))return`${d}${i}`}return null},load(n){if(n.startsWith(d)){let t=n.slice(d.length),o=r.get(t);if(o)return or.add(t),o}return null}}};async function ir(r,n,t,o,s){let e=r.replace(/\.tsx?$/,".d.ts"),i=`${d}${e}`,c=s.data?.compilerOptions,$=S(o),p=B(t,$),l=v(t),a;try{a=await sr.rollup({input:i,onwarn(w,E){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(w.code??""))return;E(w)},plugins:[tr(n),er.default({tsconfig:s.path,compilerOptions:{...c?j.default.parseJsonConfigFileContent({compilerOptions:c},j.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:j.default.ScriptTarget.ESNext}})],external:(w)=>p.some((E)=>E.test(w))&&!l.some((E)=>E.test(w))});let{output:m}=await a.generate({});if(!m[0]?.code)throw new x("Generated bundle is empty");return m[0].code}catch(m){throw new x(`DTS bundling failed: ${u(m)}`)}finally{if(a)await a.close()}}var H=g(require("node:fs")),k=g(require("node:path"));var O=g(require("node:path"));function G(r){let n=O.default.dirname(r.path||"");return r.data?.compilerOptions?.baseUrl?O.default.resolve(n,r.data.compilerOptions.baseUrl):n}function cr(r){let n=new Map,t=r.data?.compilerOptions?.paths;if(!t)return n;let o=G(r);for(let[s,e]of Object.entries(t))if(Array.isArray(e)&&e.length){let i=s.replace(/\*/g,"(.*)"),c=e[0].replace(/\*/g,"$1");n.set(`^${i}$`,O.default.join(o,c))}return n}function ar(r,n,t){for(let[o,s]of n){let e=new RegExp(o),i=r.match(e);if(i)return s.replace("$1",i[1]||"")}return t?O.default.join(t,r):null}var jr=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Nr=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function fr(r,n){let t=new Set([r]),o=[r],s=cr(n),e=G(n);while(o.length){let i=o.pop();if(!i)continue;try{let c=await H.default.promises.readFile(i,"utf8"),$=Ar(c);for(let p of $){let l=p.startsWith(".")?k.default.resolve(k.default.dirname(i),p):ar(p,s,e);if(!l)continue;let a=Mr(l);if(a&&!t.has(a))t.add(a),o.push(a)}}catch(c){f.warn(`Error processing ${i}: ${u(c)}`)}}return t}function Ar(r){let n=new Set;for(let t of[jr,Nr]){let o;while((o=t.exec(r))!==null)n.add(o[2])}return Array.from(n)}function Mr(r){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let t of n){let o=`${r}${t}`;if(H.default.existsSync(o)&&(o.endsWith(".ts")||o.endsWith(".tsx")))return o}return null}var lr=g(require("node:fs")),gr=require("oxc-transform");async function pr(r){let n=new Map;return await Promise.all([...r].map(async(t)=>{try{let o=t.replace(/\.tsx?$/,".d.ts"),s=await lr.default.promises.readFile(t,"utf8"),{code:e}=gr.isolatedDeclaration(t,s);if(e)n.set(o,e)}catch(o){f.warn(`Failed to generate declaration for ${t}: ${u(o)}`)}})),n}var J=g(require("node:fs")),N=g(require("node:path")),Tr=require("oxc-transform");function ur(r,n){let t=N.default.resolve(r),o=N.default.resolve(t,n);if(!J.default.existsSync(t))throw new x(`Root directory does not exist: ${t}`);if(!J.default.existsSync(o))throw new x(`Entry file does not exist: ${o}`);if(!o.endsWith(".ts"))throw new x(`Entry file must be a TypeScript file (.ts): ${o}`);if(N.default.relative(t,o).startsWith(".."))throw new x(`Entry file must be within rootDir: ${o}`);return{absoluteRootDir:t,absoluteEntry:o}}async function mr(r,n,t){let{absoluteRootDir:o,absoluteEntry:s}=ur(r,n),e=z(t.preferredTsconfigPath),i=await fr(s,e),c=await pr(i);return ir(s,c,t,o,e)}function Dr(r){return r.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function Y(r){let n=[],t=new Set;function o(s,e){if(t.has(s)){let i=F();n.push({name:`${s}_${i}`,path:e})}else n.push({name:s,path:e}),t.add(s)}if(Array.isArray(r))for(let s of r){let e=Dr(s);o(e,s)}else Object.entries(r).forEach(([s,e])=>{o(s,e)});return n}function xr(r,n){return`[dir]/${r}${n}`}function dr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(o)=>{let s=o.path;if(r.some((i)=>i.test(s))&&!n.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var or=new Set;async function $r(r,n){if(!r.entry||r.entry.length===0||!r.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let t=S(n),o=t?.type,s=B(r,t),e=v(r),i=[dr(s,e)],c=Y(r.entry),$=_(r,n),p=r.format.flatMap((l)=>c.map((a)=>{return Wr(r,n,a,l,o,i,$)}));try{await Promise.all(p)}catch(l){throw console.error(l),new h("Build process encountered errors")}if(r.dts){let l=r.format.filter((m)=>{if(m==="iife"&&!b(o)&&r.format.includes("cjs"))return!1;return!0}),a=r.dts===!0?c:Y(r.dts.entry);try{await Promise.all(a.map(async(m)=>{let w=await mr(n,m.path,r);await Promise.all(l.map(async(E)=>{let wr=X(E,o),A=`${n}/${r.outDir}/${m.name}${wr}`;await Bun.write(A,w);let Er=Bun.file(A).size||0;f.progress("DTS",R(A),D(Er),r.name)}))}))}catch(m){throw new x(`DTS build process encountered errors: ${u(m)}`)}}}async function Wr(r,n,t,o,s,e,i){let c=P(o,s),$=await Bun.build({...i,entrypoints:[`${n}/${t.path}`],format:o,naming:{entry:xr(t.name,c)},splitting:V(r.splitting,o),plugins:e,throw:!1});if(!$.success)throw $.logs.forEach((a)=>{if(a.level==="error")f.error(a.message);else if(a.level==="warning")f.warn(a.message);else if(a.level==="info")f.info(a.message)}),new h(`Build failed for ${t.path} (${o})`);let p=`${n}/${r.outDir}/${t.name}${c}`,l=Bun.file(p).size||0;f.progress(o.toUpperCase(),R(p),D(l),r.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function n(e){return e}function o(e){return e}export{o as
|
|
1
|
+
function ir(r){return r}function cr(r){return r}import{loadTsConfig as ar}from"load-tsconfig";class S extends Error{constructor(r){super(r);this.name="BunupError"}}class E extends S{constructor(r){super(r);this.name="BunupBuildError"}}class m extends S{constructor(r){super(r);this.name="BunupDTSBuildError"}}var p=(r)=>{if(r instanceof Error)return r.message;return String(r)};var f={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(r,n,t,o,s){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));if(o){let[c,...d]=t.split(" "),g=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),l=s?` \x1B[48;5;${r};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${e}${c}${g} \x1B[38;5;${this.colors.size}m${o}\x1B[0m ${d.join(" ")}${l}`}let i=s?` \x1B[48;5;${r};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${e}${t}${i}`},cli(r){let n=this.labels.cli;console.log(this.formatMessage(this.colors.cli,n,r))},info(r){console.log(`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`)},warn(r){let n=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,n,r))},error(r){let n=this.labels.error;console.error(this.formatMessage(this.colors.error,n,r))},progress(r,n,t,o){let s=String(r),e=this.colors.default;for(let[i,c]of Object.entries(this.colors.progress))if(s.includes(i)){e=c;break}console.log(this.formatMessage(e,s,n,t,o))}};function W(r){try{return ar(".",r)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:r,data:{},files:[]}}}import{rollup as gr}from"rollup";import pr from"rollup-plugin-dts";import A from"typescript";import Mr from"node:fs";import Dr from"node:path";function G(r,n){return{outdir:`${n}/${r.outDir}`,minify:fr(r),target:r.target,splitting:r.splitting,sourcemap:r.sourcemap}}function fr(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:o,minifySyntax:s}=r,e=n===!0;return{whitespace:t??e,identifiers:o??e,syntax:s??e}}function j(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(r=8){return Math.random().toString(36).substring(2,2+r)}function H(r,n){switch(r){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function J(r,n){switch(r){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(r){return r==="module"}function Y(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function q(r,n){return r===void 0?n==="esm":r}function N(r){if(r===0)return"0 B";let n=["B","KB","MB","GB"],t=Math.floor(Math.log(r)/Math.log(1024));if(t===0)return`${r} ${n[t]}`;return`${(r/Math.pow(1024,t)).toFixed(2)} ${n[t]}`}function y(r,n=3){return r.split("/").slice(-n).join("/")}function U(r){return r.map((n)=>typeof n==="string"?new RegExp(`^${j(n)}($|\\/|\\\\)`):n)}function O(r,n){return U(r.external||[]).concat(Y(n).map((t)=>new RegExp(`^${j(t)}($|\\/|\\\\)`)))}function b(r){return U(r.noExternal||[])}import K from"node:fs";import lr from"node:path";function R(r){let n=lr.join(r,"package.json");try{if(!K.existsSync(n))return null;let t=K.readFileSync(n,"utf8");return JSON.parse(t)}catch(t){return f.warn(`Failed to load package.json at ${n}: ${p(t)}`),null}}import h from"path";var x="\x00virtual:",L=(r)=>{return{name:"bunup:virtual-dts",resolveId(n,t){if(n.startsWith(x))return n;if(!t?.startsWith(x)||!n.startsWith("."))return null;let o=t.slice(x.length),s=h.resolve(h.dirname(o),n);if(n==="."){let i=h.join(h.dirname(o),"index.d.ts");if(r.has(i))return`${x}${i}`;s=h.dirname(o)}if(r.has(s))return`${x}${s}`;let e=`${s}.d.ts`;if(r.has(e))return`${x}${e}`;if(n.startsWith(".")){let i=h.join(s,"index.d.ts");if(r.has(i))return`${x}${i}`}return null},load(n){if(n.startsWith(x)){let t=n.slice(x.length),o=r.get(t);if(o)return Q.add(t),o}return null}}};async function Z(r,n,t,o,s){let e=r.replace(/\.tsx?$/,".d.ts"),i=`${x}${e}`,c=s.data?.compilerOptions,d=R(o),g=O(t,d),l=b(t),a;try{a=await gr({input:i,onwarn($,w){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes($.code??""))return;w($)},plugins:[L(n),pr({tsconfig:s.path,compilerOptions:{...c?A.parseJsonConfigFileContent({compilerOptions:c},A.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:A.ScriptTarget.ESNext}})],external:($)=>g.some((w)=>w.test($))&&!l.some((w)=>w.test($))});let{output:u}=await a.generate({});if(!u[0]?.code)throw new m("Generated bundle is empty");return u[0].code}catch(u){throw new m(`DTS bundling failed: ${p(u)}`)}finally{if(a)await a.close()}}import P from"node:fs";import F from"node:path";import B from"node:path";function M(r){let n=B.dirname(r.path||"");return r.data?.compilerOptions?.baseUrl?B.resolve(n,r.data.compilerOptions.baseUrl):n}function z(r){let n=new Map,t=r.data?.compilerOptions?.paths;if(!t)return n;let o=M(r);for(let[s,e]of Object.entries(t))if(Array.isArray(e)&&e.length){let i=s.replace(/\*/g,"(.*)"),c=e[0].replace(/\*/g,"$1");n.set(`^${i}$`,B.join(o,c))}return n}function _(r,n,t){for(let[o,s]of n){let e=new RegExp(o),i=r.match(e);if(i)return s.replace("$1",i[1]||"")}return t?B.join(t,r):null}var ur=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,mr=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function X(r,n){let t=new Set([r]),o=[r],s=z(n),e=M(n);while(o.length){let i=o.pop();if(!i)continue;try{let c=await P.promises.readFile(i,"utf8"),d=xr(c);for(let g of d){let l=g.startsWith(".")?F.resolve(F.dirname(i),g):_(g,s,e);if(!l)continue;let a=dr(l);if(a&&!t.has(a))t.add(a),o.push(a)}}catch(c){f.warn(`Error processing ${i}: ${p(c)}`)}}return t}function xr(r){let n=new Set;for(let t of[ur,mr]){let o;while((o=t.exec(r))!==null)n.add(o[2])}return Array.from(n)}function dr(r){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let t of n){let o=`${r}${t}`;if(P.existsSync(o)&&(o.endsWith(".ts")||o.endsWith(".tsx")))return o}return null}import $r from"node:fs";import{isolatedDeclaration as wr}from"oxc-transform";async function I(r){let n=new Map;return await Promise.all([...r].map(async(t)=>{try{let o=t.replace(/\.tsx?$/,".d.ts"),s=await $r.promises.readFile(t,"utf8"),{code:e}=wr(t,s);if(e)n.set(o,e)}catch(o){f.warn(`Failed to generate declaration for ${t}: ${p(o)}`)}})),n}import V from"node:fs";import T from"node:path";import{isolatedDeclaration as Cn}from"oxc-transform";function rr(r,n){let t=T.resolve(r),o=T.resolve(t,n);if(!V.existsSync(t))throw new m(`Root directory does not exist: ${t}`);if(!V.existsSync(o))throw new m(`Entry file does not exist: ${o}`);if(!o.endsWith(".ts"))throw new m(`Entry file must be a TypeScript file (.ts): ${o}`);if(T.relative(t,o).startsWith(".."))throw new m(`Entry file must be within rootDir: ${o}`);return{absoluteRootDir:t,absoluteEntry:o}}async function nr(r,n,t){let{absoluteRootDir:o,absoluteEntry:s}=rr(r,n),e=W(t.preferredTsconfigPath),i=await X(s,e),c=await I(i);return Z(s,c,t,o,e)}function Er(r){return r.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function D(r){let n=[],t=new Set;function o(s,e){if(t.has(s)){let i=k();n.push({name:`${s}_${i}`,path:e})}else n.push({name:s,path:e}),t.add(s)}if(Array.isArray(r))for(let s of r){let e=Er(s);o(e,s)}else Object.entries(r).forEach(([s,e])=>{o(s,e)});return n}function tr(r,n){return`[dir]/${r}${n}`}function or(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(o)=>{let s=o.path;if(r.some((i)=>i.test(s))&&!n.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var Q=new Set;async function hr(r,n){if(!r.entry||r.entry.length===0||!r.outDir)throw new E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let t=R(n),o=t?.type,s=O(r,t),e=b(r),i=[or(s,e)],c=D(r.entry),d=G(r,n),g=r.format.flatMap((l)=>c.map((a)=>{return Cr(r,n,a,l,o,i,d)}));try{await Promise.all(g)}catch(l){throw console.error(l),new E("Build process encountered errors")}if(r.dts){let l=r.format.filter((u)=>{if(u==="iife"&&!C(o)&&r.format.includes("cjs"))return!1;return!0}),a=r.dts===!0?c:D(r.dts.entry);try{await Promise.all(a.map(async(u)=>{let $=await nr(n,u.path,r);await Promise.all(l.map(async(w)=>{let sr=J(w,o),v=`${n}/${r.outDir}/${u.name}${sr}`;await Bun.write(v,$);let er=Bun.file(v).size||0;f.progress("DTS",y(v),N(er),r.name)}))}))}catch(u){throw new m(`DTS build process encountered errors: ${p(u)}`)}}}async function Cr(r,n,t,o,s,e,i){let c=H(o,s),d=await Bun.build({...i,entrypoints:[`${n}/${t.path}`],format:o,naming:{entry:tr(t.name,c)},splitting:q(r.splitting,o),plugins:e,throw:!1});if(!d.success)throw d.logs.forEach((a)=>{if(a.level==="error")f.error(a.message);else if(a.level==="warning")f.warn(a.message);else if(a.level==="info")f.info(a.message)}),new E(`Build failed for ${t.path} (${o})`);let g=`${n}/${r.outDir}/${t.name}${c}`,l=Bun.file(g).size||0;f.progress(o.toUpperCase(),y(g),N(l),r.name)}export{cr as defineWorkspace,ir as defineConfig,hr as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@types/bun": "^1.2.5",
|
|
19
19
|
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
20
20
|
"bumpp": "^10.1.0",
|
|
21
|
-
"bunup": "^0.2.
|
|
21
|
+
"bunup": "^0.2.3",
|
|
22
22
|
"eslint": "^8.57.0",
|
|
23
23
|
"husky": "^9.1.6",
|
|
24
24
|
"prettier": "^3.2.5",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"validate": "pnpm run tsc && pnpm run lint",
|
|
72
72
|
"format": "prettier --write .",
|
|
73
73
|
"release": "bumpp",
|
|
74
|
-
"publish:ci": "pnpm publish --access public --no-git-checks"
|
|
74
|
+
"publish:ci": "pnpm publish --access public --no-git-checks",
|
|
75
|
+
"benchmark": "pnpm -C benchmarks benchmark"
|
|
75
76
|
}
|
|
76
77
|
}
|