bunup 0.3.88 → 0.3.90
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 +1 -1
- package/build/cli.mjs +13 -13
- package/build/index.d.mts +29 -220
- package/build/index.d.ts +29 -220
- package/build/index.js +6 -6
- package/build/index.mjs +6 -6
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ To run the benchmarks yourself, clone this repo and run `pnpm benchmark` and che
|
|
|
24
24
|
|
|
25
25
|
- 🔥 **Bytecode Generation**: Faster startups by compiling to Bun bytecode—perfect for CLIs.
|
|
26
26
|
|
|
27
|
-
- 📦 **Workspace Support**: Build multiple packages with
|
|
27
|
+
- 📦 **Workspace Support**: Build multiple packages with [defineWorkspace()](https://bunup.arshadyaseen.com/#workspaces) in one config file and command.
|
|
28
28
|
|
|
29
29
|
- 🎯 **Bun Targeting**: Optimize for Bun runtime with `--target bun` for native features.
|
|
30
30
|
|
package/build/cli.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{build as
|
|
4
|
-
\x1B[90mA solution for this error is available at: \x1B[36m${
|
|
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=
|
|
3
|
+
import{build as qe}from"rolldown";import{dts as Ve}from"rolldown-plugin-dts";class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class d extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class g extends E{constructor(e){super(e);this.name="BunupCLIError"}}class v extends E{constructor(e){super(e);this.name="BunupWatchError"}}var h=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ne=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],q=(e,t)=>{let n=h(e),r=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof d)s="DTS ERROR";else if(e instanceof g)s="CLI ERROR";else if(e instanceof v)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";console.error(`\x1B[31m${s}\x1B[0m ${r}${n}`);let o=Ne.find((i)=>i.pattern.test(n)&&(i.errorType===s||!i.errorType));if(o)console.error(`
|
|
4
|
+
\x1B[90mA solution for this error is available at: \x1B[36m${o.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")},Z=(e,t)=>{q(e,t),process.exit(1)};import z from"node:fs/promises";import ke from"node:path";function V(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function J(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function ee(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function te(e){return Array.isArray(e)?e:[e]}function ne(e,t){switch(e){case"esm":return".mjs";case"cjs":return L(t)?".cjs":".js";case"iife":return".global.js"}}function re(e,t){switch(e){case"esm":return".d.mts";case"cjs":return L(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(e){return e==="module"}function S(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function se(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function ie(e,t){return e===void 0?t==="esm":e}function G(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 b(e,t=3){return e.split("/").slice(-t).join("/")}async function oe(e,t){let n=ke.join(e,t);try{await z.rm(n,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await z.mkdir(n,{recursive:!0})}function ae(e,t){return t==="cjs"?e:void 0}function le(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${V(t)}($|\\/|\\\\)`):t)}function A(e,t){return le(e.external||[]).concat(se(t).map((n)=>new RegExp(`^${V(n)}($|\\/|\\\\)`)))}function I(e){return le(e.noExternal||[])}import Fe from"node:path";import{ResolverFactory as He}from"oxc-resolver";import R from"node:path";var T="\x00dts:",ce=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(X(r))return r;if(!s||!X(s))return null;let o=await M(r,t,n,B(s));if(!o)return null;let i=C(o);if(e.has(i))return D(i);return null},load(r){if(r.startsWith(T)){let s=B(r),o=e.get(s);if(o)return $.add(s),o}return null}}};function ue(e){return e.tsconfig?.compilerOptions}function C(e){return e.replace(/\.tsx?$/,".d.ts")}function Y(e){let t=R.dirname(e.path||""),n=ue(e);return n?.baseUrl?R.resolve(t,n.baseUrl):t}function fe(e){let t=new Map,n=ue(e)?.paths;if(!n)return t;let r=Y(e);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");t.set(`^${i}$`,R.join(r,a))}return t}function We(e,t,n){for(let[r,s]of t){let o=new RegExp(r),i=e.match(o);if(i)return s.replace("$1",i[1]||"")}return n?R.join(n,e):null}async function je(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 M(e,t,n,r){let s=e.startsWith(".")?R.resolve(R.dirname(r||""),e):We(e,t,n);if(!s)return Promise.resolve(null);return je(s)}function X(e){return e.startsWith(T)}function B(e){return e.replace(T,"")}function D(e){return`${T}${e}`}var me;function pe(e){return{name:"bunup:types-resolve",buildStart(){me||=new He({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?B(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 s=r?Fe.dirname(r):process.cwd(),{path:o}=await me.async(s,t);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function de(e,t,n,r,s,o){let i=C(e),a=D(i),l=A(n,r),c=I(n);try{let{output:m}=await qe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;p(f)},plugins:[ce(t,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&pe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ve({dtsInput:!0})],external:(f)=>l.some((p)=>p.test(f))&&!c.some((p)=>p.test(f))});if(!m[0]?.code)throw new d("Generated bundle is empty");return m[0].code}catch(m){throw new d(`DTS bundling failed: ${h(m)}`)}}var ge=!1;function U(e){ge=e??!1}class O{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!O.instance)O.instance=new O;return O.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...m]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${c}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${m.join(" ")}${p}`}let l=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${l}`}output(e,t={},n=console.log){if(ge)return;if(!this.shouldLog(t))return;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 s=String(e),o=this.colors.default,i,a,l={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,l=n;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){o=f;break}let c=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:l.muted});this.output(c,l)}}var u=O.getInstance();var Ge=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Xe=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Ye=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ke=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qe=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ze=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ze=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Je(e){let t=new Set,n=[Ge,Xe,Ye,Ke,Qe,Ze,ze];for(let r of n){let s=e.matchAll(r);for(let o of s)if(o[1])t.add(o[1])}return t}async function he(e,t,n){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=Je(i);for(let l of a){let c=await M(l,t,n,o);if(!c)continue;if(!r.has(c))r.add(c),s.push(c)}}catch(i){u.warn(`Error processing ${o}: ${h(i)}`)}}return r}import{isolatedDeclaration as et}from"oxc-transform";async function xe(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=C(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=et(n,o);if(i)t.set(r,i)}catch(r){u.warn(`Failed to generate declaration for ${n}: ${h(r)}`)}})),t}import be from"node:fs/promises";import K from"node:path";import{isolatedDeclaration as tt}from"oxc-transform";async function ye(e,t){let n=K.resolve(e),r=K.resolve(n,t);if(!await be.exists(n))throw new d(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(K.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function we(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:o}=tt(r,s);for(let i of o){if(!t)console.log(`
|
|
6
|
+
`);let a=i.labels[0],l=a?nt(s,a.start):"",m=`${b(r)}${l}: ${rt(i.message)}`;u.warn(m),t=!0}}catch{}})),t)u.info(`
|
|
7
7
|
You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
|
|
8
|
-
`)}function
|
|
9
|
-
`),r=n.length,
|
|
8
|
+
`)}function nt(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
|
|
9
|
+
`),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function rt(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Ee(e,t,n,r,s){let{absoluteEntry:o}=await ye(e,t),i=fe(r),a=Y(r),l=await he(o,i,a),c=await xe(l);return de(o,c,n,s,i,a)}function _(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function P(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let l=J(),c=`${i}_${l}`;if(t)u.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
|
-
${
|
|
13
|
-
${
|
|
12
|
+
${s[i]} -> ${i}.js
|
|
13
|
+
${a} -> ${c}.js (auto-renamed to avoid conflict)
|
|
14
14
|
|
|
15
15
|
To fix this, use named entries in your configuration:
|
|
16
16
|
{
|
|
17
17
|
entry: {
|
|
18
|
-
custom_name: "${
|
|
19
|
-
another_name: "${
|
|
18
|
+
custom_name: "${s[i]}",
|
|
19
|
+
another_name: "${a}"
|
|
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});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=_(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=_(e);o(i,e)}return n}function Ce(e,t){return`[dir]/${e}${t}`}import{loadConfig as $e}from"coffi";async function Re(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:ee(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Oe(e){let{config:t,filepath:n}=await $e({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Be(e,t){let{config:n,filepath:r}=await $e({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var Te={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Pe(e,t){return{outdir:`${t}/${e.outDir}`,minify:st(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 st(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function ve(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var $=new Set;async function N(e,t){if(!e.entry||e.entry.length===0||!e.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)oe(t,e.outDir);U(e.silent);let{packageJson:n,path:r}=await Oe(t);if(n&&r)u.cli(`Using package.json: ${b(r,2)}`,{muted:!0,identifier:e.name,once:`${r}:${e.name}`});let s=P(e.entry),o=n?.type,i=A(e,n),a=I(e);if(!e.dtsOnly){let l=[ve(i,a)],c=Pe(e,t),m=e.format.flatMap((f)=>s.map((p)=>{return it(e,t,p,f,o,l,c)}));await Promise.all(m)}if(e.dts||e.dtsOnly){let l=await Be(t,e.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${b(l.path,2)}`,{muted:!0,identifier:e.name,once:`${l.path}:${e.name}`});let c=e.format.filter((f)=>{if(f==="iife"&&!L(o)&&e.format.includes("cjs"))return!1;return!0}),m=typeof e.dts==="object"&&e.dts.entry?P(e.dts.entry):s;try{await Promise.all(m.map(async(f)=>{let p=await Ee(t,f.path,e,l,n);await Promise.all(c.map(async(F)=>{let Ue=re(F,o),H=`${t}/${e.outDir}/${f.name}${Ue}`;await Bun.write(H,p);let _e=Bun.file(H).size||0;u.progress("DTS",b(H),G(_e),e.name)}))}))}catch(f){throw new d(h(f))}}}async function it(e,t,n,r,s,o,i){let a=ne(r,s),l=await Bun.build({...i,entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ce(n.name,a)},splitting:ie(e.splitting,r),bytecode:ae(e.bytecode,r),plugins:o,throw:!1});if(!l.success)for(let f of l.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${n.name}${a}`,m=Bun.file(c).size||0;u.progress(r.toUpperCase(),b(c),G(m),e.name)}var k="0.3.90";var Le="https://bun.sh/docs/installation",Se="https://bunup.arshadyaseen.com/#cli-options";function x(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new g(`Option --${e} requires a string value`)}}function Ae(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new g(`Option --${e} requires a string value`)}}function at(){console.log(`
|
|
24
24
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
25
25
|
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Se}\x1B[0m
|
|
26
|
-
`),process.exit(0)}function
|
|
27
|
-
To install Bun, visit ${
|
|
26
|
+
`),process.exit(0)}function lt(){console.log(k),process.exit(0)}var Ie={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(e,t)=>{if(typeof e==="string")t.format=e.split(",");else throw new g("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:Ae("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:Ae("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:y("config")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new g(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=_(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>at()},version:{flags:["v","version"],handler:()=>lt()}},W={};for(let e of Object.values(Ie))for(let t of e.flags)W[t]=e.handler;function Me(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),l=W[i];if(l)l(o,t,a);else throw new g(`Unknown option: --${s}`)}else{let i=W[s];if(i)i(o,t);else throw new g(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=W[s];if(a)a(i,t);else throw new g(`Unknown option: -${s}`)}else Ie.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new g(`Bunup requires Bun to run.
|
|
27
|
+
To install Bun, visit ${Le}`)})();import{loadConfig as ut}from"coffi";import j from"node:path";import ct from"chokidar";async function De(e,t){let n=new Set,r=P(e.entry);for(let a of r){let l=j.resolve(t,a.path),c=j.dirname(l);n.add(c)}let s=ct.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,j.join(t,e.outDir)]}),o=!1,i=async(a=!1)=>{if(o)return;o=!0;try{let l=performance.now();if(await N({...e,entry:r.map((c)=>c.path),clean:!1},t),e.onBuildSuccess?.(),!a)u.cli(`\uD83D\uDCE6 Rebuild finished in ${S(performance.now()-l)}`);await Q()}catch(l){q(l)}finally{o=!1}};s.on("change",(a)=>{let l=j.relative(t,a);u.cli(`File changed: ${l}`,{muted:!0}),i()}),s.on("error",(a)=>{throw new v(`Watcher error: ${h(a)}`)}),await i(!0)}async function ft(e=Bun.argv.slice(2)){let t=Me(e);U(t.silent);let n=process.cwd(),{config:r,filepath:s}=await ut({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Re(r,n);if(u.cli(`Using bunup v${k} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${b(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:c,rootDir:m})=>{return te(c).map(async(p)=>{let F={...Te,...p,...t};return mt(F,m)})}));let a=performance.now()-i,l=S(a);if(u.cli(`\u26A1\uFE0F Build completed in ${l}`),await Q(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Q(){if($.size>0)await we($),$.clear()}async function mt(e,t){if(e.watch)await De(e,t);else await N(e,t),e.onBuildSuccess?.()}ft().catch((e)=>Z(e));export{Q as validateDtsFiles,ft as main};
|
package/build/index.d.mts
CHANGED
|
@@ -1,221 +1,13 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
2
|
|
|
3
3
|
//#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Entry point files for TypeScript declaration file generation
|
|
6
|
-
*
|
|
7
|
-
* This can be:
|
|
8
|
-
* - A string path to a file
|
|
9
|
-
* - An array of file paths
|
|
10
|
-
* - An object where keys are output names and values are input file paths
|
|
11
|
-
*
|
|
12
|
-
* The key names are used for the generated declaration files.
|
|
13
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
14
|
-
*
|
|
15
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
16
|
-
*
|
|
17
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
18
|
-
* will be used as the name for the output declaration file.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Using a string path
|
|
22
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
23
|
-
*
|
|
24
|
-
* // Using string paths in an array
|
|
25
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
26
|
-
*
|
|
27
|
-
* // Using named outputs as an object
|
|
28
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
29
|
-
*/
|
|
30
4
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
31
|
-
/**
|
|
32
|
-
* Entry point files for TypeScript declaration file generation
|
|
33
|
-
*
|
|
34
|
-
* This can be:
|
|
35
|
-
* - A string path to a file
|
|
36
|
-
* - An array of file paths
|
|
37
|
-
* - An object where keys are output names and values are input file paths
|
|
38
|
-
*
|
|
39
|
-
* The key names are used for the generated declaration files.
|
|
40
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
41
|
-
*
|
|
42
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
43
|
-
*
|
|
44
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
45
|
-
* will be used as the name for the output declaration file.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* // Using a string path
|
|
49
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
50
|
-
*
|
|
51
|
-
* // Using string paths in an array
|
|
52
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
53
|
-
*
|
|
54
|
-
* // Using named outputs as an object
|
|
55
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
56
|
-
*/
|
|
57
5
|
type Define = BunBuildOptions["define"];
|
|
58
|
-
/**
|
|
59
|
-
* Entry point files for TypeScript declaration file generation
|
|
60
|
-
*
|
|
61
|
-
* This can be:
|
|
62
|
-
* - A string path to a file
|
|
63
|
-
* - An array of file paths
|
|
64
|
-
* - An object where keys are output names and values are input file paths
|
|
65
|
-
*
|
|
66
|
-
* The key names are used for the generated declaration files.
|
|
67
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
68
|
-
*
|
|
69
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
70
|
-
*
|
|
71
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
72
|
-
* will be used as the name for the output declaration file.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* // Using a string path
|
|
76
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
77
|
-
*
|
|
78
|
-
* // Using string paths in an array
|
|
79
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
80
|
-
*
|
|
81
|
-
* // Using named outputs as an object
|
|
82
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
83
|
-
*/
|
|
84
6
|
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
85
|
-
/**
|
|
86
|
-
* Entry point files for TypeScript declaration file generation
|
|
87
|
-
*
|
|
88
|
-
* This can be:
|
|
89
|
-
* - A string path to a file
|
|
90
|
-
* - An array of file paths
|
|
91
|
-
* - An object where keys are output names and values are input file paths
|
|
92
|
-
*
|
|
93
|
-
* The key names are used for the generated declaration files.
|
|
94
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
95
|
-
*
|
|
96
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
97
|
-
*
|
|
98
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
99
|
-
* will be used as the name for the output declaration file.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* // Using a string path
|
|
103
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
104
|
-
*
|
|
105
|
-
* // Using string paths in an array
|
|
106
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
107
|
-
*
|
|
108
|
-
* // Using named outputs as an object
|
|
109
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
110
|
-
*/
|
|
111
7
|
type Format = Exclude<BunBuildOptions["format"], undefined>;
|
|
112
|
-
/**
|
|
113
|
-
* Entry point files for TypeScript declaration file generation
|
|
114
|
-
*
|
|
115
|
-
* This can be:
|
|
116
|
-
* - A string path to a file
|
|
117
|
-
* - An array of file paths
|
|
118
|
-
* - An object where keys are output names and values are input file paths
|
|
119
|
-
*
|
|
120
|
-
* The key names are used for the generated declaration files.
|
|
121
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
122
|
-
*
|
|
123
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
124
|
-
*
|
|
125
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
126
|
-
* will be used as the name for the output declaration file.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* // Using a string path
|
|
130
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
131
|
-
*
|
|
132
|
-
* // Using string paths in an array
|
|
133
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
134
|
-
*
|
|
135
|
-
* // Using named outputs as an object
|
|
136
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
137
|
-
*/
|
|
138
8
|
type Target = BunBuildOptions["target"];
|
|
139
|
-
/**
|
|
140
|
-
* Entry point files for TypeScript declaration file generation
|
|
141
|
-
*
|
|
142
|
-
* This can be:
|
|
143
|
-
* - A string path to a file
|
|
144
|
-
* - An array of file paths
|
|
145
|
-
* - An object where keys are output names and values are input file paths
|
|
146
|
-
*
|
|
147
|
-
* The key names are used for the generated declaration files.
|
|
148
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
149
|
-
*
|
|
150
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
151
|
-
*
|
|
152
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
153
|
-
* will be used as the name for the output declaration file.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* // Using a string path
|
|
157
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
158
|
-
*
|
|
159
|
-
* // Using string paths in an array
|
|
160
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
161
|
-
*
|
|
162
|
-
* // Using named outputs as an object
|
|
163
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
164
|
-
*/
|
|
165
9
|
type External = (string | RegExp)[];
|
|
166
|
-
/**
|
|
167
|
-
* Entry point files for TypeScript declaration file generation
|
|
168
|
-
*
|
|
169
|
-
* This can be:
|
|
170
|
-
* - A string path to a file
|
|
171
|
-
* - An array of file paths
|
|
172
|
-
* - An object where keys are output names and values are input file paths
|
|
173
|
-
*
|
|
174
|
-
* The key names are used for the generated declaration files.
|
|
175
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
176
|
-
*
|
|
177
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
178
|
-
*
|
|
179
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
180
|
-
* will be used as the name for the output declaration file.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* // Using a string path
|
|
184
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
185
|
-
*
|
|
186
|
-
* // Using string paths in an array
|
|
187
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
188
|
-
*
|
|
189
|
-
* // Using named outputs as an object
|
|
190
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
191
|
-
*/
|
|
192
10
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
193
|
-
/**
|
|
194
|
-
* Entry point files for TypeScript declaration file generation
|
|
195
|
-
*
|
|
196
|
-
* This can be:
|
|
197
|
-
* - A string path to a file
|
|
198
|
-
* - An array of file paths
|
|
199
|
-
* - An object where keys are output names and values are input file paths
|
|
200
|
-
*
|
|
201
|
-
* The key names are used for the generated declaration files.
|
|
202
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
203
|
-
*
|
|
204
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
205
|
-
*
|
|
206
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
207
|
-
* will be used as the name for the output declaration file.
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* // Using a string path
|
|
211
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
212
|
-
*
|
|
213
|
-
* // Using string paths in an array
|
|
214
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
215
|
-
*
|
|
216
|
-
* // Using named outputs as an object
|
|
217
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
218
|
-
*/
|
|
219
11
|
type DtsOptions = {
|
|
220
12
|
/**
|
|
221
13
|
* Entry point files for TypeScript declaration file generation
|
|
@@ -249,11 +41,7 @@ type DtsOptions = {
|
|
|
249
41
|
*/
|
|
250
42
|
resolve?: boolean | (string | RegExp)[]
|
|
251
43
|
};
|
|
252
|
-
|
|
253
|
-
* Name of the build configuration
|
|
254
|
-
* Used for logging and identification purposes
|
|
255
|
-
*/
|
|
256
|
-
interface BunupOptions {
|
|
44
|
+
interface BuildOptions {
|
|
257
45
|
/**
|
|
258
46
|
* Name of the build configuration
|
|
259
47
|
* Used for logging and identification purposes
|
|
@@ -331,6 +119,21 @@ interface BunupOptions {
|
|
|
331
119
|
*/
|
|
332
120
|
dts?: boolean | DtsOptions;
|
|
333
121
|
/**
|
|
122
|
+
* Generate only TypeScript declaration files (.d.ts) without any JavaScript output
|
|
123
|
+
* When set to true, bunup will skip the JavaScript bundling process entirely
|
|
124
|
+
* and only generate declaration files for the specified entry points
|
|
125
|
+
*
|
|
126
|
+
* This is useful when you want to use bunup's fast declaration file generation
|
|
127
|
+
* but handle the JavaScript bundling separately or not at all.
|
|
128
|
+
*
|
|
129
|
+
* Note: When this option is true, the `dts` option is implicitly set to true
|
|
130
|
+
* and other bundling-related options are ignored.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* dtsOnly: true
|
|
134
|
+
*/
|
|
135
|
+
dtsOnly?: boolean;
|
|
136
|
+
/**
|
|
334
137
|
* Path to a preferred tsconfig.json file to use for declaration generation
|
|
335
138
|
*
|
|
336
139
|
* If not specified, the tsconfig.json in the project root will be used.
|
|
@@ -447,6 +250,12 @@ interface BunupOptions {
|
|
|
447
250
|
* @default false
|
|
448
251
|
*/
|
|
449
252
|
bytecode?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Disable logging during the build process. When set to true, no logs will be printed to the console.
|
|
255
|
+
*
|
|
256
|
+
* @default false
|
|
257
|
+
*/
|
|
258
|
+
silent?: boolean;
|
|
450
259
|
}
|
|
451
260
|
|
|
452
261
|
//#endregion
|
|
@@ -459,21 +268,21 @@ type WithOptional<
|
|
|
459
268
|
type Arrayable<T> = T | T[];
|
|
460
269
|
type Bun = typeof _Bun;
|
|
461
270
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
462
|
-
type
|
|
463
|
-
type
|
|
271
|
+
type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
|
|
272
|
+
type DefineWorkspaceItem = {
|
|
464
273
|
name: string
|
|
465
274
|
root: string
|
|
466
|
-
config:
|
|
275
|
+
config: DefineConfigItem | DefineConfigItem[]
|
|
467
276
|
};
|
|
468
277
|
|
|
469
278
|
//#endregion
|
|
470
279
|
//#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
|
|
471
|
-
declare function defineConfig(options: Arrayable<
|
|
472
|
-
declare function defineWorkspace(options:
|
|
280
|
+
declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
|
|
281
|
+
declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
|
|
473
282
|
|
|
474
283
|
//#endregion
|
|
475
284
|
//#region \0dts:/home/runner/work/bunup/bunup/src/build.d.ts
|
|
476
|
-
declare function build(options:
|
|
285
|
+
declare function build(options: BuildOptions, rootDir: string): Promise<void>;
|
|
477
286
|
|
|
478
287
|
//#endregion
|
|
479
|
-
export {
|
|
288
|
+
export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, build, defineConfig, defineWorkspace };
|
package/build/index.d.ts
CHANGED
|
@@ -1,221 +1,13 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
2
|
|
|
3
3
|
//#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Entry point files for TypeScript declaration file generation
|
|
6
|
-
*
|
|
7
|
-
* This can be:
|
|
8
|
-
* - A string path to a file
|
|
9
|
-
* - An array of file paths
|
|
10
|
-
* - An object where keys are output names and values are input file paths
|
|
11
|
-
*
|
|
12
|
-
* The key names are used for the generated declaration files.
|
|
13
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
14
|
-
*
|
|
15
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
16
|
-
*
|
|
17
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
18
|
-
* will be used as the name for the output declaration file.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Using a string path
|
|
22
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
23
|
-
*
|
|
24
|
-
* // Using string paths in an array
|
|
25
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
26
|
-
*
|
|
27
|
-
* // Using named outputs as an object
|
|
28
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
29
|
-
*/
|
|
30
4
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
31
|
-
/**
|
|
32
|
-
* Entry point files for TypeScript declaration file generation
|
|
33
|
-
*
|
|
34
|
-
* This can be:
|
|
35
|
-
* - A string path to a file
|
|
36
|
-
* - An array of file paths
|
|
37
|
-
* - An object where keys are output names and values are input file paths
|
|
38
|
-
*
|
|
39
|
-
* The key names are used for the generated declaration files.
|
|
40
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
41
|
-
*
|
|
42
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
43
|
-
*
|
|
44
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
45
|
-
* will be used as the name for the output declaration file.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* // Using a string path
|
|
49
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
50
|
-
*
|
|
51
|
-
* // Using string paths in an array
|
|
52
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
53
|
-
*
|
|
54
|
-
* // Using named outputs as an object
|
|
55
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
56
|
-
*/
|
|
57
5
|
type Define = BunBuildOptions["define"];
|
|
58
|
-
/**
|
|
59
|
-
* Entry point files for TypeScript declaration file generation
|
|
60
|
-
*
|
|
61
|
-
* This can be:
|
|
62
|
-
* - A string path to a file
|
|
63
|
-
* - An array of file paths
|
|
64
|
-
* - An object where keys are output names and values are input file paths
|
|
65
|
-
*
|
|
66
|
-
* The key names are used for the generated declaration files.
|
|
67
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
68
|
-
*
|
|
69
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
70
|
-
*
|
|
71
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
72
|
-
* will be used as the name for the output declaration file.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* // Using a string path
|
|
76
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
77
|
-
*
|
|
78
|
-
* // Using string paths in an array
|
|
79
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
80
|
-
*
|
|
81
|
-
* // Using named outputs as an object
|
|
82
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
83
|
-
*/
|
|
84
6
|
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
85
|
-
/**
|
|
86
|
-
* Entry point files for TypeScript declaration file generation
|
|
87
|
-
*
|
|
88
|
-
* This can be:
|
|
89
|
-
* - A string path to a file
|
|
90
|
-
* - An array of file paths
|
|
91
|
-
* - An object where keys are output names and values are input file paths
|
|
92
|
-
*
|
|
93
|
-
* The key names are used for the generated declaration files.
|
|
94
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
95
|
-
*
|
|
96
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
97
|
-
*
|
|
98
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
99
|
-
* will be used as the name for the output declaration file.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* // Using a string path
|
|
103
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
104
|
-
*
|
|
105
|
-
* // Using string paths in an array
|
|
106
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
107
|
-
*
|
|
108
|
-
* // Using named outputs as an object
|
|
109
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
110
|
-
*/
|
|
111
7
|
type Format = Exclude<BunBuildOptions["format"], undefined>;
|
|
112
|
-
/**
|
|
113
|
-
* Entry point files for TypeScript declaration file generation
|
|
114
|
-
*
|
|
115
|
-
* This can be:
|
|
116
|
-
* - A string path to a file
|
|
117
|
-
* - An array of file paths
|
|
118
|
-
* - An object where keys are output names and values are input file paths
|
|
119
|
-
*
|
|
120
|
-
* The key names are used for the generated declaration files.
|
|
121
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
122
|
-
*
|
|
123
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
124
|
-
*
|
|
125
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
126
|
-
* will be used as the name for the output declaration file.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* // Using a string path
|
|
130
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
131
|
-
*
|
|
132
|
-
* // Using string paths in an array
|
|
133
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
134
|
-
*
|
|
135
|
-
* // Using named outputs as an object
|
|
136
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
137
|
-
*/
|
|
138
8
|
type Target = BunBuildOptions["target"];
|
|
139
|
-
/**
|
|
140
|
-
* Entry point files for TypeScript declaration file generation
|
|
141
|
-
*
|
|
142
|
-
* This can be:
|
|
143
|
-
* - A string path to a file
|
|
144
|
-
* - An array of file paths
|
|
145
|
-
* - An object where keys are output names and values are input file paths
|
|
146
|
-
*
|
|
147
|
-
* The key names are used for the generated declaration files.
|
|
148
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
149
|
-
*
|
|
150
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
151
|
-
*
|
|
152
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
153
|
-
* will be used as the name for the output declaration file.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* // Using a string path
|
|
157
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
158
|
-
*
|
|
159
|
-
* // Using string paths in an array
|
|
160
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
161
|
-
*
|
|
162
|
-
* // Using named outputs as an object
|
|
163
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
164
|
-
*/
|
|
165
9
|
type External = (string | RegExp)[];
|
|
166
|
-
/**
|
|
167
|
-
* Entry point files for TypeScript declaration file generation
|
|
168
|
-
*
|
|
169
|
-
* This can be:
|
|
170
|
-
* - A string path to a file
|
|
171
|
-
* - An array of file paths
|
|
172
|
-
* - An object where keys are output names and values are input file paths
|
|
173
|
-
*
|
|
174
|
-
* The key names are used for the generated declaration files.
|
|
175
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
176
|
-
*
|
|
177
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
178
|
-
*
|
|
179
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
180
|
-
* will be used as the name for the output declaration file.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* // Using a string path
|
|
184
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
185
|
-
*
|
|
186
|
-
* // Using string paths in an array
|
|
187
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
188
|
-
*
|
|
189
|
-
* // Using named outputs as an object
|
|
190
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
191
|
-
*/
|
|
192
10
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
193
|
-
/**
|
|
194
|
-
* Entry point files for TypeScript declaration file generation
|
|
195
|
-
*
|
|
196
|
-
* This can be:
|
|
197
|
-
* - A string path to a file
|
|
198
|
-
* - An array of file paths
|
|
199
|
-
* - An object where keys are output names and values are input file paths
|
|
200
|
-
*
|
|
201
|
-
* The key names are used for the generated declaration files.
|
|
202
|
-
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
203
|
-
*
|
|
204
|
-
* If not specified, the main entry points will be used for declaration file generation.
|
|
205
|
-
*
|
|
206
|
-
* If it's a string or an array of strings, the file name (without extension)
|
|
207
|
-
* will be used as the name for the output declaration file.
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* // Using a string path
|
|
211
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
212
|
-
*
|
|
213
|
-
* // Using string paths in an array
|
|
214
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
215
|
-
*
|
|
216
|
-
* // Using named outputs as an object
|
|
217
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
218
|
-
*/
|
|
219
11
|
type DtsOptions = {
|
|
220
12
|
/**
|
|
221
13
|
* Entry point files for TypeScript declaration file generation
|
|
@@ -249,11 +41,7 @@ type DtsOptions = {
|
|
|
249
41
|
*/
|
|
250
42
|
resolve?: boolean | (string | RegExp)[]
|
|
251
43
|
};
|
|
252
|
-
|
|
253
|
-
* Name of the build configuration
|
|
254
|
-
* Used for logging and identification purposes
|
|
255
|
-
*/
|
|
256
|
-
interface BunupOptions {
|
|
44
|
+
interface BuildOptions {
|
|
257
45
|
/**
|
|
258
46
|
* Name of the build configuration
|
|
259
47
|
* Used for logging and identification purposes
|
|
@@ -331,6 +119,21 @@ interface BunupOptions {
|
|
|
331
119
|
*/
|
|
332
120
|
dts?: boolean | DtsOptions;
|
|
333
121
|
/**
|
|
122
|
+
* Generate only TypeScript declaration files (.d.ts) without any JavaScript output
|
|
123
|
+
* When set to true, bunup will skip the JavaScript bundling process entirely
|
|
124
|
+
* and only generate declaration files for the specified entry points
|
|
125
|
+
*
|
|
126
|
+
* This is useful when you want to use bunup's fast declaration file generation
|
|
127
|
+
* but handle the JavaScript bundling separately or not at all.
|
|
128
|
+
*
|
|
129
|
+
* Note: When this option is true, the `dts` option is implicitly set to true
|
|
130
|
+
* and other bundling-related options are ignored.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* dtsOnly: true
|
|
134
|
+
*/
|
|
135
|
+
dtsOnly?: boolean;
|
|
136
|
+
/**
|
|
334
137
|
* Path to a preferred tsconfig.json file to use for declaration generation
|
|
335
138
|
*
|
|
336
139
|
* If not specified, the tsconfig.json in the project root will be used.
|
|
@@ -447,6 +250,12 @@ interface BunupOptions {
|
|
|
447
250
|
* @default false
|
|
448
251
|
*/
|
|
449
252
|
bytecode?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Disable logging during the build process. When set to true, no logs will be printed to the console.
|
|
255
|
+
*
|
|
256
|
+
* @default false
|
|
257
|
+
*/
|
|
258
|
+
silent?: boolean;
|
|
450
259
|
}
|
|
451
260
|
|
|
452
261
|
//#endregion
|
|
@@ -459,21 +268,21 @@ type WithOptional<
|
|
|
459
268
|
type Arrayable<T> = T | T[];
|
|
460
269
|
type Bun = typeof _Bun;
|
|
461
270
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
462
|
-
type
|
|
463
|
-
type
|
|
271
|
+
type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
|
|
272
|
+
type DefineWorkspaceItem = {
|
|
464
273
|
name: string
|
|
465
274
|
root: string
|
|
466
|
-
config:
|
|
275
|
+
config: DefineConfigItem | DefineConfigItem[]
|
|
467
276
|
};
|
|
468
277
|
|
|
469
278
|
//#endregion
|
|
470
279
|
//#region \0dts:/home/runner/work/bunup/bunup/src/define.d.ts
|
|
471
|
-
declare function defineConfig(options: Arrayable<
|
|
472
|
-
declare function defineWorkspace(options:
|
|
280
|
+
declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
|
|
281
|
+
declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
|
|
473
282
|
|
|
474
283
|
//#endregion
|
|
475
284
|
//#region \0dts:/home/runner/work/bunup/bunup/src/build.d.ts
|
|
476
|
-
declare function build(options:
|
|
285
|
+
declare function build(options: BuildOptions, rootDir: string): Promise<void>;
|
|
477
286
|
|
|
478
287
|
//#endregion
|
|
479
|
-
export {
|
|
288
|
+
export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, build, defineConfig, defineWorkspace };
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Ot=require("node:module");var Bt=Object.create;var{getPrototypeOf:It,defineProperty:$,getOwnPropertyNames:j,getOwnPropertyDescriptor:Lt}=Object,G=Object.prototype.hasOwnProperty;var h=(t,e,n)=>{n=t!=null?Bt(It(t)):{};let r=e||!t||!t.__esModule?$(n,"default",{value:t,enumerable:!0}):n;for(let s of j(t))if(!G.call(r,s))$(r,s,{get:()=>t[s],enumerable:!0});return r},V=new WeakMap,St=(t)=>{var e=V.get(t),n;if(e)return e;if(e=$({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")j(t).map((r)=>!G.call(e,r)&&$(e,r,{get:()=>t[r],enumerable:!(n=Lt(t,r))||n.enumerable}));return V.set(t,e),e};var At=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var Kt={};At(Kt,{defineWorkspace:()=>X,defineConfig:()=>q,build:()=>Pt});module.exports=St(Kt);function q(t){return t}function X(t){return t}var lt=require("rolldown"),ut=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends S{constructor(t){super(t);this.name="BunupBuildError"}}class d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};var A=h(require("node:fs/promises")),H=h(require("node:path"));function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function K(t,e){switch(t){case"esm":return".mjs";case"cjs":return P(e)?".cjs":".js";case"iife":return".global.js"}}function Y(t,e){switch(t){case"esm":return".d.mts";case"cjs":return P(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function P(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,e){return t===void 0?e==="esm":t}function _(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function E(t,e=3){return t.split("/").slice(-e).join("/")}async function z(t,e){let n=H.default.join(t,e);try{await A.default.rm(n,{recursive:!0,force:!0})}catch(r){throw new b(`Failed to clean output directory: ${r}`)}await A.default.mkdir(n,{recursive:!0})}function J(t,e){return e==="cjs"?t:void 0}function tt(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function D(t,e){return tt(t.external||[]).concat(Q(e).map((n)=>new RegExp(`^${O(n)}($|\\/|\\\\)`)))}function M(t){return tt(t.noExternal||[])}var ot=h(require("node:path")),at=require("oxc-resolver");var x=h(require("node:path"));var C="\x00dts:",et=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(N(r))return r;if(!s||!N(s))return null;let o=await T(r,e,n,y(s));if(!o)return null;let i=w(o);if(t.has(i))return B(i);return null},load(r){if(r.startsWith(C)){let s=y(r),o=t.get(s);if(o)return nt.add(s),o}return null}}};function rt(t){return t.tsconfig?.compilerOptions}function w(t){return t.replace(/\.tsx?$/,".d.ts")}function W(t){let e=x.default.dirname(t.path||""),n=rt(t);return n?.baseUrl?x.default.resolve(e,n.baseUrl):e}function st(t){let e=new Map,n=rt(t)?.paths;if(!n)return e;let r=W(t);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");e.set(`^${i}$`,x.default.join(r,a))}return e}function _t(t,e,n){for(let[r,s]of e){let o=new RegExp(r),i=t.match(o);if(i)return s.replace("$1",i[1]||"")}return n?x.default.join(n,t):null}async function Nt(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function T(t,e,n,r){let s=t.startsWith(".")?x.default.resolve(x.default.dirname(r||""),t):_t(t,e,n);if(!s)return Promise.resolve(null);return Nt(s)}function N(t){return t.startsWith(C)}function y(t){return t.replace(C,"")}function B(t){return`${C}${t}`}var it;function ct(t){return{name:"bunup:types-resolve",buildStart(){it||=new at.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,n){let r=n?y(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let s=r?ot.default.dirname(r):process.cwd(),{path:o}=await it.async(s,e);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function ft(t,e,n,r,s,o){let i=w(t),a=B(i),c=D(n,r),u=M(n);try{let{output:f}=await lt.build({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[et(e,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&ct(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),ut.dts({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${p(f)}`)}}var gt=!1;function mt(t){gt=t??!1}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!R.instance)R.instance=new R;return R.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:e,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...f]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${a}${c}`}output(t,e={},n=console.log){if(gt)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let s=String(t),o=this.colors.default,i,a,c={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,c=n;for(let[f,l]of Object.entries(this.colors.progress))if(s.includes(f)){o=l;break}let u=this.formatMessage({colorCode:o,label:s,message:e,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var g=R.getInstance();var Wt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ut=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,vt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Vt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Gt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function qt(t){let e=new Set,n=[Wt,Ut,vt,Ft,Vt,jt,Gt];for(let r of n){let s=t.matchAll(r);for(let o of s)if(o[1])e.add(o[1])}return e}async function dt(t,e,n){let r=new Set([t]),s=[t];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=qt(i);for(let c of a){let u=await T(c,e,n,o);if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){g.warn(`Error processing ${o}: ${p(i)}`)}}return r}var pt=require("oxc-transform");async function xt(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=w(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=pt.isolatedDeclaration(n,o);if(i)e.set(r,i)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}var U=h(require("node:fs/promises")),I=h(require("node:path")),Xt=require("oxc-transform");async function ht(t,e){let n=I.default.resolve(t),r=I.default.resolve(n,e);if(!await U.default.exists(n))throw new d(`Root directory does not exist: ${n}`);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.default.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function bt(t,e,n,r,s){let{absoluteEntry:o}=await ht(t,e),i=st(r),a=W(r),c=await dt(o,i,a),u=await xt(c);return ft(o,u,n,s,i,a)}function Et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function v(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=k(),u=`${i}_${c}`;if(e)g.warn(`Output name conflict: "${i}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
|
-
${
|
|
5
|
-
${
|
|
4
|
+
${s[i]} -> ${i}.js
|
|
5
|
+
${a} -> ${u}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
|
-
custom_name: "${
|
|
11
|
-
another_name: "${
|
|
10
|
+
custom_name: "${s[i]}",
|
|
11
|
+
another_name: "${a}"
|
|
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:u,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(t))for(let i of t){let a=Et(i);o(a,i)}else if(typeof t==="object")for(let[i,a]of Object.entries(t))o(i,a);else{let i=Et(t);o(i,t)}return n}function wt(t,e){return`[dir]/${t}${e}`}var F=require("coffi");async function Rt(t){let{config:e,filepath:n}=await F.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function $t(t,e){let{config:n,filepath:r}=await F.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function yt(t,e){return{outdir:`${e}/${t.outDir}`,minify:Ht(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 Ht(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Ct(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(t.some((i)=>i.test(s))&&!e.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var nt=new Set;async function Pt(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)z(e,t.outDir);mt(t.silent);let{packageJson:n,path:r}=await Rt(e);if(n&&r)g.cli(`Using package.json: ${E(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let s=v(t.entry),o=n?.type,i=D(t,n),a=M(t);if(!t.dtsOnly){let c=[Ct(i,a)],u=yt(t,e),f=t.format.flatMap((l)=>s.map((m)=>{return kt(t,e,m,l,o,c,u)}));await Promise.all(f)}if(t.dts||t.dtsOnly){let c=await $t(e,t.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,identifier:t.name,once:`${c.path}:${t.name}`});let u=t.format.filter((l)=>{if(l==="iife"&&!P(o)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?v(t.dts.entry):s;try{await Promise.all(f.map(async(l)=>{let m=await bt(e,l.path,t,c,n);await Promise.all(u.map(async(Dt)=>{let Mt=Y(Dt,o),L=`${e}/${t.outDir}/${l.name}${Mt}`;await Bun.write(L,m);let Tt=Bun.file(L).size||0;g.progress("DTS",E(L),_(Tt),t.name)}))}))}catch(l){throw new d(p(l))}}}async function kt(t,e,n,r,s,o,i){let a=K(r,s),c=await Bun.build({...i,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:wt(n.name,a)},splitting:Z(t.splitting,r),bytecode:J(t.bytecode,r),plugins:o,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new b(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(u).size||0;g.progress(r.toUpperCase(),E(u),_(f),t.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function pt(t){return t}function
|
|
1
|
+
function pt(t){return t}function xt(t){return t}import{build as $t}from"rolldown";import{dts as yt}from"rolldown-plugin-dts";class B extends Error{constructor(t){super(t);this.name="BunupError"}}class x extends B{constructor(t){super(t);this.name="BunupBuildError"}}class d extends B{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import N from"node:fs/promises";import ht from"node:path";function I(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function U(t,e){switch(t){case"esm":return".mjs";case"cjs":return y(e)?".cjs":".js";case"iife":return".global.js"}}function v(t,e){switch(t){case"esm":return".d.mts";case"cjs":return y(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function y(t){return t==="module"}function F(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,e){return t===void 0?e==="esm":t}function L(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(1024));if(n===0)return`${t} ${e[n]}`;return`${(t/1024**n).toFixed(2)} ${e[n]}`}function h(t,e=3){return t.split("/").slice(-e).join("/")}async function j(t,e){let n=ht.join(t,e);try{await N.rm(n,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await N.mkdir(n,{recursive:!0})}function G(t,e){return e==="cjs"?t:void 0}function q(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${I(e)}($|\\/|\\\\)`):e)}function C(t,e){return q(t.external||[]).concat(F(e).map((n)=>new RegExp(`^${I(n)}($|\\/|\\\\)`)))}function P(t){return q(t.noExternal||[])}import wt from"node:path";import{ResolverFactory as Rt}from"oxc-resolver";import E from"node:path";var $="\x00dts:",X=(t,e,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,o){if(S(r))return r;if(!o||!S(o))return null;let i=await D(r,e,n,R(o));if(!i)return null;let s=b(i);if(t.has(s))return M(s);return null},load(r){if(r.startsWith($)){let o=R(r),i=t.get(o);if(i)return H.add(o),i}return null}}};function k(t){return t.tsconfig?.compilerOptions}function b(t){return t.replace(/\.tsx?$/,".d.ts")}function A(t){let e=E.dirname(t.path||""),n=k(t);return n?.baseUrl?E.resolve(e,n.baseUrl):e}function K(t){let e=new Map,n=k(t)?.paths;if(!n)return e;let r=A(t);for(let[o,i]of Object.entries(n))if(Array.isArray(i)&&i.length){let s=o.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");e.set(`^${s}$`,E.join(r,a))}return e}function bt(t,e,n){for(let[r,o]of e){let i=new RegExp(r),s=t.match(i);if(s)return o.replace("$1",s[1]||"")}return n?E.join(n,t):null}async function Et(t){let e=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of e){let r=`${t}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function D(t,e,n,r){let o=t.startsWith(".")?E.resolve(E.dirname(r||""),t):bt(t,e,n);if(!o)return Promise.resolve(null);return Et(o)}function S(t){return t.startsWith($)}function R(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(e,n){let r=n?R(n):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!r?.includes(a);else c=a.test(e)||!!(r&&a.test(r));return c}))return}let o=r?wt.dirname(r):process.cwd(),{path:i}=await Y.async(o,e);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 Z(t,e,n,r,o,i){let s=b(t),a=M(s),c=C(n,r),u=P(n);try{let{output:f}=await $t({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(l,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;m(l)},plugins:[X(e,o,i),typeof n.dts==="object"&&"resolve"in n.dts&&Q(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),yt({dtsInput:!0})],external:(l)=>c.some((m)=>m.test(l))&&!u.some((m)=>m.test(l))});if(!f[0]?.code)throw new d("Generated bundle is empty");return f[0].code}catch(f){throw new d(`DTS bundling failed: ${p(f)}`)}}var z=!1;function J(t){z=t??!1}class w{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!w.instance)w.instance=new w;return w.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:e,message:n,size:r,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=i?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[u,...f]=a.split(" "),l=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),m=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${l} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${m}`}let c=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},n=console.log){if(z)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(n(t),e.verticalSpace)console.log("")}cli(t,e={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}progress(t,e,n,r){let o=String(t),i=this.colors.default,s,a,c={};if(typeof n==="string")s=n,a=r;else if(n)s=n.size,a=n.identifier,c=n;for(let[f,l]of Object.entries(this.colors.progress))if(o.includes(f)){i=l;break}let u=this.formatMessage({colorCode:i,label:o,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var g=w.getInstance();var Ct=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Pt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Dt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Mt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Tt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Bt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,It=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Lt(t){let e=new Set,n=[Ct,Pt,Dt,Mt,Tt,Bt,It];for(let r of n){let o=t.matchAll(r);for(let i of o)if(i[1])e.add(i[1])}return e}async function tt(t,e,n){let r=new Set([t]),o=[t];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=Lt(s);for(let c of a){let u=await D(c,e,n,i);if(!u)continue;if(!r.has(u))r.add(u),o.push(u)}}catch(s){g.warn(`Error processing ${i}: ${p(s)}`)}}return r}import{isolatedDeclaration as St}from"oxc-transform";async function et(t){let e=new Map;return await Promise.all([...t].map(async(n)=>{try{let r=b(n);if(!await Bun.file(n).exists())return;let i=await Bun.file(n).text(),{code:s}=St(n,i);if(s)e.set(r,s)}catch(r){g.warn(`Failed to generate declaration for ${n}: ${p(r)}`)}})),e}import nt from"node:fs/promises";import O from"node:path";import{isolatedDeclaration as Re}from"oxc-transform";async function rt(t,e){let n=O.resolve(t),r=O.resolve(n,e);if(!await nt.exists(n))throw new d(`Root directory does not exist: ${n}`);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(O.relative(n,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function st(t,e,n,r,o){let{absoluteEntry:i}=await rt(t,e),s=K(r),a=A(r),c=await tt(i,s,a),u=await et(c);return Z(i,u,n,o,s,a)}function it(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function _(t,{warnOnConflict:e=!0}={}){let n=[],r=new Set,o={};function i(s,a){if(r.has(s)){let c=W(),u=`${s}_${c}`;if(e)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
|
-
${
|
|
5
|
-
${
|
|
4
|
+
${o[s]} -> ${s}.js
|
|
5
|
+
${a} -> ${u}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
|
-
custom_name: "${
|
|
11
|
-
another_name: "${
|
|
10
|
+
custom_name: "${o[s]}",
|
|
11
|
+
another_name: "${a}"
|
|
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:u,path:a})}else n.push({name:s,path:a}),r.add(s),o[s]=a}if(Array.isArray(t))for(let s of t){let a=it(s);i(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))i(s,a);else{let s=it(t);i(s,t)}return n}function ot(t,e){return`[dir]/${t}${e}`}import{loadConfig as at}from"coffi";async function ct(t){let{config:e,filepath:n}=await at({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:n}}async function lt(t,e){let{config:n,filepath:r}=await at({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:n,path:r}}function ut(t,e){return{outdir:`${e}/${t.outDir}`,minify:At(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 At(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:o}=t,i=e===!0;return{whitespace:n??i,identifiers:r??i,syntax:o??i}}function ft(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let o=r.path;if(t.some((s)=>s.test(o))&&!e.some((s)=>s.test(o)))return{path:o,external:!0};return null})}}}var H=new Set;async function Ot(t,e){if(!t.entry||t.entry.length===0||!t.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)j(e,t.outDir);J(t.silent);let{packageJson:n,path:r}=await ct(e);if(n&&r)g.cli(`Using package.json: ${h(r,2)}`,{muted:!0,identifier:t.name,once:`${r}:${t.name}`});let o=_(t.entry),i=n?.type,s=C(t,n),a=P(t);if(!t.dtsOnly){let c=[ft(s,a)],u=ut(t,e),f=t.format.flatMap((l)=>o.map((m)=>{return _t(t,e,m,l,i,c,u)}));await Promise.all(f)}if(t.dts||t.dtsOnly){let c=await lt(e,t.preferredTsconfigPath);if(c.path)g.cli(`Using tsconfig: ${h(c.path,2)}`,{muted:!0,identifier:t.name,once:`${c.path}:${t.name}`});let u=t.format.filter((l)=>{if(l==="iife"&&!y(i)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?_(t.dts.entry):o;try{await Promise.all(f.map(async(l)=>{let m=await st(e,l.path,t,c,n);await Promise.all(u.map(async(gt)=>{let mt=v(gt,i),T=`${e}/${t.outDir}/${l.name}${mt}`;await Bun.write(T,m);let dt=Bun.file(T).size||0;g.progress("DTS",h(T),L(dt),t.name)}))}))}catch(l){throw new d(p(l))}}}async function _t(t,e,n,r,o,i,s){let a=U(r,o),c=await Bun.build({...s,entrypoints:[`${e}/${n.path}`],format:r,naming:{entry:ot(n.name,a)},splitting:V(t.splitting,r),bytecode:G(t.bytecode,r),plugins:i,throw:!1});if(!c.success)for(let l of c.logs){if(l.level==="error")throw new x(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let u=`${e}/${t.outDir}/${n.name}${a}`,f=Bun.file(u).size||0;g.progress(r.toUpperCase(),h(u),L(f),t.name)}export{xt as defineWorkspace,pt as defineConfig,Ot as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.90",
|
|
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,10 @@
|
|
|
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.89",
|
|
21
21
|
"husky": "^9.1.7",
|
|
22
22
|
"typescript": "^5.8.3",
|
|
23
|
-
"
|
|
24
|
-
"create-bunup": "0.3.88"
|
|
23
|
+
"create-bunup": "0.3.90"
|
|
25
24
|
},
|
|
26
25
|
"peerDependencies": {
|
|
27
26
|
"typescript": ">=4.5.0"
|
|
@@ -65,7 +64,7 @@
|
|
|
65
64
|
"create-bunup": "create-bunup",
|
|
66
65
|
"dev:docs": "pnpm -C docs dev",
|
|
67
66
|
"test-build": "pnpm -C tests build",
|
|
68
|
-
"test": "
|
|
67
|
+
"test": "bun test",
|
|
69
68
|
"lint": "biome check .",
|
|
70
69
|
"lint:fix": "biome check --write .",
|
|
71
70
|
"format": "biome format .",
|