bunup 0.6.1 → 0.7.0
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/dist/cli.js +33 -44
- package/dist/index.cjs +3 -14
- package/dist/index.d.cts +35 -35
- package/dist/index.d.ts +35 -35
- package/dist/index.js +3 -14
- package/dist/plugins.cjs +13 -1
- package/dist/plugins.d.cts +50 -41
- package/dist/plugins.d.ts +50 -41
- package/dist/plugins.js +13 -1
- package/package.json +84 -84
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
[](https://www.npmjs.com/package/bunup) [](https://npmjs.com/package/bunup) [](https://bun.sh) [](https://github.com/sponsors/arshad-yaseen)
|
|
14
14
|
|
|
15
|
-
Bunup is the **blazing-fast build tool** for TypeScript and JavaScript libraries, designed for flawless developer experience and speed, **powered by Bun's native bundler** — up to **~100× faster than Tsup**.
|
|
15
|
+
Bunup is the **blazing-fast build tool** for TypeScript and JavaScript libraries, designed for flawless developer experience and speed, **powered by Bun's native bundler and Oxc** — up to **~100× faster than Tsup**.
|
|
16
16
|
|
|
17
17
|
| Bundler | Format | Build Time | Build Time (with dts) |
|
|
18
18
|
| --------- | ------------ | -------------- | --------------------- |
|
package/dist/cli.js
CHANGED
|
@@ -1,68 +1,57 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`),
|
|
5
|
-
`);else console.error(
|
|
6
|
-
`)+
|
|
7
|
-
`)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = dirname(__filename);
|
|
12
|
-
|
|
13
|
-
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&ce(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
14
|
-
|
|
15
|
-
const importMetaUrl = pathToFileURL(__filename).href;
|
|
16
|
-
|
|
17
|
-
`}}});function He(e){if(!e)return[];return e.filter((t)=>t.type==="bun")}function et(e){if(!e)return[];return e.filter((t)=>t.type==="bunup")}async function tt(e,t){if(!e)return;for(let n of e)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(t)}async function nt(e,t,n){if(!e)return;for(let i of e)if(i.hooks.onBuildDone)await i.hooks.onBuildDone({options:t,output:n})}var rt={};we(rt,{build:()=>ge});import{dts as Wt}from"bun-dts";async function ge(e,t=process.cwd()){let n={files:[]},i=ne(e);if(!i.entry||i.entry.length===0||!i.outDir)throw new _("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(i.clean)Ae(t,i.outDir);N(i.silent);let{packageJson:r,path:o}=await We(t);if(r&&o)m.cli(`Using ${te(o,2)}`,{muted:!0,identifier:i.name,once:`${o}:${i.name}`});let s=et(i.plugins);await tt(s,i);let a=X(i),p=r?.type,d=[Ke(i,r),...He(i.plugins).map((c)=>c.plugin)],l=typeof i.dts==="object"&&"resolve"in i.dts?i.dts.resolve:void 0,h=i.format.flatMap((c)=>a.map(async(O)=>{let D=i.outputExtension?.({format:c,packageType:p,options:i,entry:O.path}).js??Ie(c,p),z=await Bun.build({entrypoints:[`${t}/${O.path}`],format:c,naming:Se(O.outputBasePath,D),splitting:ze(i.splitting,c),bytecode:Je(i.bytecode,c),define:Ge(i.define,i.shims,i.env,c),minify:_e(i),outdir:`${t}/${i.outDir}`,target:i.target,sourcemap:Ue(i.sourcemap),loader:i.loader,drop:i.drop,banner:i.banner,footer:i.footer,publicPath:i.publicPath,env:Ye(i.env),plugins:[...d,...O.dts?[Wt({cwd:t,preferredTsConfigPath:i.preferredTsconfigPath,warnInsteadOfError:i.watch,resolve:l,onDeclarationGenerated:(b)=>{let u=it(b,t);n.files.push({fullPath:b,relativePathToRootDir:u}),m.progress("DTS",u,{identifier:i.name})}})]:[],Qe({format:c,target:i.target,shims:i.shims})],throw:!1});for(let b of z.logs){if(b.level==="error")throw console.log(`
|
|
18
|
-
`),console.log(b),console.log(`
|
|
19
|
-
`),new Error;if(b.level==="warning")m.warn(b.message);else if(b.level==="info")m.info(b.message)}for(let b of z.outputs){let u=it(b.path,t);if(b.kind==="entry-point")m.progress(c.toUpperCase(),u,{identifier:i.name});n.files.push({fullPath:b.path,relativePathToRootDir:u})}}));if(await Promise.all(h),await nt(s,i,n),i.onSuccess)await i.onSuccess(i)}function it(e,t){return e.replace(`${t}/`,"")}var me=P(()=>{J();Q();ue();L();pe();Xe();Ze();M()});var ut={};we(ut,{init:()=>qt});import S from"fs/promises";import T from"path";import{cancel as R,confirm as j,intro as _t,isCancel as x,log as C,multiselect as st,outro as Jt,tasks as Ut,text as G}from"@clack/prompts";import{loadConfig as he}from"coffi";import{detect as Gt,resolveCommand as fe}from"package-manager-detector";import{exec as zt}from"tinyexec";async function at(e){try{return await S.access(e),!0}catch{return!1}}async function Yt(){let{config:e,filepath:t}=await he({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,packageJsonProperty:"bunup"});return{exists:!!e,filepath:t||void 0}}async function qt(){_t(f.default.bgCyan(f.default.black(" Bunup "))),await lt();let{exists:e,filepath:t}=await Yt();if(e){let u=await j({message:`A bunup configuration already exists at ${f.default.cyan(t||"bunup.config.ts")}. Continue and overwrite it?`,initialValue:!1});if(x(u)||!u)R("Initialization cancelled"),process.exit(1)}let n=await Gt();if(!n)C.error("No package manager detected"),process.exit(1);let{config:i,filepath:r}=await he({name:"package",cwd:process.cwd(),extensions:[".json"]});if(!i||!r)C.error("Cannot find package.json."),process.exit(1);let o=await G({message:"Entry point for your library:",placeholder:"src/index.ts",defaultValue:"src/index.ts"});if(x(o))R("Initialization cancelled"),process.exit(1);let s=T.join(process.cwd(),String(o));if(!await at(s)){let u=await j({message:`Entry file ${f.default.cyan(String(o))} does not exist. Create it?`,initialValue:!0});if(x(u))R("Initialization cancelled"),process.exit(1);if(u)await S.mkdir(T.dirname(s),{recursive:!0}),await S.writeFile(s,`// Your entry point
|
|
3
|
+
var pt=Object.create;var{getPrototypeOf:bt,defineProperty:se,getOwnPropertyNames:xt}=Object;var wt=Object.prototype.hasOwnProperty;var L=(e,t,i)=>{i=e!=null?pt(bt(e)):{};let r=t||!e||!e.__esModule?se(i,"default",{value:e,enumerable:!0}):i;for(let n of xt(e))if(!wt.call(r,n))se(r,n,{get:()=>e[n],enumerable:!0});return r};var ht=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ce=(e,t)=>{for(var i in t)se(e,i,{get:t[i],enumerable:!0,configurable:!0,set:(r)=>t[i]=()=>r})};var B=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ct=import.meta.require;var A=ht((Ht,oe)=>{var D=process||{},$e=D.argv||[],X=D.env||{},yt=!(!!X.NO_COLOR||$e.includes("--no-color"))&&(!!X.FORCE_COLOR||$e.includes("--color")||D.platform==="win32"||(D.stdout||{}).isTTY&&X.TERM!=="dumb"||!!X.CI),Bt=(e,t,i=e)=>(r)=>{let n=""+r,s=n.indexOf(t,e.length);return~s?e+Et(n,t,i,s)+t:e+n+t},Et=(e,t,i,r)=>{let n="",s=0;do n+=e.substring(s,r)+i,s=r+t.length,r=e.indexOf(t,s);while(~r);return n+e.substring(s)},ye=(e=yt)=>{let t=e?Bt:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};oe.exports=ye();oe.exports.createColors=ye});function Q(e){Be=e??!1}class T{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=g.default.blue;mutedColor=g.default.dim;infoColor=g.default.cyan;warnColor=g.default.yellow;errorColor=g.default.red;defaultColor=g.default.white;progressFgColorMap={ESM:g.default.yellow,CJS:g.default.green,IIFE:g.default.magenta,DTS:g.default.blue};progressIdentifierBgColorMap={ESM:g.default.bgYellow,CJS:g.default.bgGreen,IIFE:g.default.bgMagenta,DTS:g.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!T.instance)T.instance=new T;return T.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({fgColor:e,bgColor:t,label:i,message:r,identifier:n,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-i.length)),c=s?this.mutedColor(r):r,l=n?` ${t(g.default.black(` ${n} `))}`:"";return`${e(i)} ${o}${c}${l}`}output(e,t={},i=console.log){if(Be||!this.shouldLog(t))return;if(t.verticalSpace)i("");if(i(e),t.verticalSpace)i("")}cli(e,t={}){let i=this.formatMessage({fgColor:this.cliColor,bgColor:g.default.bgBlue,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(i,t)}info(e,t={}){let i=this.formatMessage({fgColor:this.infoColor,bgColor:g.default.bgCyan,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(i,t)}warn(e,t={}){let i=this.formatMessage({fgColor:this.warnColor,bgColor:g.default.bgYellow,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(i,t,console.warn)}error(e,t={}){let i=this.formatMessage({fgColor:this.errorColor,bgColor:g.default.bgRed,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(i,t,console.error)}getProgressFgColor(e){for(let[t,i]of Object.entries(this.progressFgColorMap))if(e.includes(t))return i;return this.defaultColor}getProgressBgColor(e){for(let[t,i]of Object.entries(this.progressIdentifierBgColorMap))if(e.includes(t))return i;return g.default.bgWhite}progress(e,t,i={}){let r=this.getProgressFgColor(e),n=this.getProgressBgColor(e),s=this.formatMessage({fgColor:r,bgColor:n,label:e,message:t,identifier:i.identifier,muted:i.muted});this.output(s,i)}}var g,Be=!1,f;var Y=B(()=>{g=L(A(),1);f=T.getInstance()});var w,q,V,Ee,E,Z,ce=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ot,ae=(e,t)=>{let i=ce(e),r=t?`[${t}] `:"",n="";if(e instanceof V)n="BUILD ERROR";else if(e instanceof Ee)n="DTS ERROR";else if(e instanceof E)n="CLI ERROR";else if(e instanceof Z)n="WATCH ERROR";else if(e instanceof q)n="BUNUP ERROR";let s=Ot.find((o)=>o.pattern.test(i)&&(o.errorType===n||!o.errorType));if(!s&&n)console.error(`${w.default.red(n)} ${r}${i}`);if(s)console.log(`
|
|
4
|
+
`),s.logSolution(i),console.log(`
|
|
5
|
+
`);else console.error(w.default.dim(w.default.white("If you think this is a bug, please open an issue at: ")+w.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},Oe=(e,t)=>{ae(e,t),process.exit(1)};var z=B(()=>{w=L(A(),1);Y();q=class q extends Error{constructor(e){super(e);this.name="BunupError"}};V=class V extends q{constructor(e){super(e);this.name="BunupBuildError"}};Ee=class Ee extends q{constructor(e){super(e);this.name="BunupDTSBuildError"}};E=class E extends q{constructor(e){super(e);this.name="BunupCLIError"}};Z=class Z extends q{constructor(e){super(e);this.name="BunupWatchError"}};Ot=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{f.error(w.default.white("You're trying to build a project that uses Bun. ")+w.default.white("Please set the target option to ")+w.default.cyan("`bun`")+w.default.white(`.
|
|
6
|
+
`)+w.default.white("Example: ")+w.default.green("`bunup --target bun`")+w.default.white(" or in config: ")+w.default.green("{ target: 'bun' }"))}}]});import Me from"fs/promises";import J,{normalize as oi}from"path";function ke(e,t,i){return Array.isArray(e)?e.map((r)=>({...r,[t]:i})):{...e,[t]:i}}function je(e){return Array.isArray(e)?e:[e]}function Ie(e,t){switch(e){case"esm":return Re(t)?".js":".mjs";case"cjs":return Re(t)?".cjs":".js";case"iife":return".global.js"}}function We(e){let t=J.basename(e),i=J.extname(t);return i?t.slice(0,-i.length):t}function Fe(e){return e.replace(J.extname(e),"")}function Le(e){return e.replace(/\\/g,"/")}function Re(e){return e==="module"}function N(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function Ae(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function v(e,t=3){return e.split("/").slice(-t).join("/")}async function Ge(e,t){let i=J.join(e,t);try{await Me.rm(i,{recursive:!0,force:!0})}catch(r){throw new V(`Failed to clean output directory: ${r}`)}await Me.mkdir(i,{recursive:!0})}var R=B(()=>{z()});import kt from"path";import{loadConfig as jt}from"coffi";async function qe(e,t,i){return Array.isArray(e)&&"root"in e[0]?e.filter((r)=>i?i.includes(r.name):!0).map((r)=>({rootDir:kt.resolve(t,r.root),options:ke(r.config,"name",r.name)})):[{rootDir:t,options:e}]}async function Ve(e){let{config:t,filepath:i}=await jt({name:"package",cwd:e,extensions:[".json"]});return{data:t,path:i}}var le=B(()=>{R()});function te(e){let t=typeof e.dts==="object"&&"entry"in e.dts?e.dts.entry:void 0,i=ze(e.entry,!1);if(typeof e.dts!=="undefined"){if(!t)return i.map((c)=>({...c,dts:!0}));let r=ze(t,!0),n=new Set,s=i.map((c)=>{let l=r.find((d)=>d.entry===c.entry&&d.outputBasePath===c.outputBasePath);if(l)n.add(`${c.entry}:${c.outputBasePath}`);return{...c,dts:!!l}}),o=r.filter((c)=>!n.has(`${c.entry}:${c.outputBasePath}`));return[...s,...o]}return i}function ze(e,t){if(typeof e==="string")return[{entry:e,outputBasePath:Ue(e),dts:t}];if(typeof e==="object"&&!Array.isArray(e))return Object.entries(e).map(([i,r])=>({entry:r,outputBasePath:i,dts:t}));return e.map((i)=>({entry:i,outputBasePath:Ue(i),dts:t}))}function Ue(e){let t=Le(Fe(e)).split("/");return t.length>1?t.slice(1).join("/"):t.join("/")}function Ke(e,t){return{entry:`[dir]/${e}${t}`,chunk:`${e}-[hash].[ext]`,asset:`${e}-[name]-[hash].[ext]`}}var de=B(()=>{R()});function ie(e){return{...It,...e}}function _e(e){let{minify:t,minifyWhitespace:i,minifyIdentifiers:r,minifySyntax:n}=e,s=t===!0;return{whitespace:i??s,identifiers:r??s,syntax:n??s}}function Pe(e,t){return t==="cjs"?e:void 0}function Xe(e){if(e===!0)return"inline";return typeof e==="string"?e:void 0}function De(e,t){return{...typeof t==="object"&&Object.keys(t).reduce((i,r)=>{let n=JSON.stringify(t[r]);return i[`process.env.${r}`]=n,i[`import.meta.env.${r}`]=n,i},{}),...e}}function Qe(e,t){return e===void 0?t==="esm":e}function Ze(e){return typeof e==="string"?e:void 0}var It;var me=B(()=>{It={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function Wt(e){return Ae(e).map((t)=>new RegExp(`^${t}($|\\/|\\\\)`))}function Je(e,t){return typeof t==="string"?t===e:t.test(e)}function Ne(e,t,i){let n=Wt(i).some((o)=>o.test(e))||t.external?.some((o)=>Je(e,o)),s=t.noExternal?.some((o)=>Je(e,o));return n&&!s}var ve=B(()=>{R()});function He(e,t){return{name:"bunup:external-option-plugin",setup(i){i.onResolve({filter:/.*/},(r)=>{let n=r.path;if(Ne(n,e,t))return{path:n,external:!0};return null})}}}var et=B(()=>{ve()});function tt(e){if(!e)return[];return e.filter((t)=>t.type==="bun")}function it(e){if(!e)return[];return e.filter((t)=>t.type==="bunup")}async function rt(e,t){if(!e)return;for(let i of e)if(i.hooks.onBuildStart)await i.hooks.onBuildStart(t)}async function nt(e,t,i,r){if(!e)return;for(let n of e)if(n.hooks.onBuildDone)await n.hooks.onBuildDone({options:t,output:i,meta:r})}var ot={};Ce(ot,{build:()=>ge});import{dts as Lt}from"bun-dts";async function ge(e,t=process.cwd()){let i={files:[]},r=ie(e);if(!r.entry||r.entry.length===0||!r.outDir)throw new V("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)Ge(t,r.outDir);Q(r.silent);let n=await Ve(t);if(n.data&&n.path)f.cli(`Using ${v(n.path,2)}`,{muted:!0,identifier:r.name,once:`${n.path}:${r.name}`});let s=it(r.plugins);await rt(s,r);let o=te(r),c=n.data?.type,l=[He(r,n.data),...tt(r.plugins).map((m)=>m.plugin)],d=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,u=r.format.flatMap((m)=>o.map(async({entry:b,outputBasePath:M,dts:W})=>{let ne=r.outputExtension?.({format:m,packageType:c,options:r,entry:b}).js??Ie(m,c),_=await Bun.build({entrypoints:[`${t}/${b}`],format:m,naming:Ke(M,ne),splitting:Qe(r.splitting,m),bytecode:Pe(r.bytecode,m),define:De(r.define,r.env),minify:_e(r),outdir:`${t}/${r.outDir}`,target:r.target,sourcemap:Xe(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:Ze(r.env),plugins:[...l,...W?[Lt({cwd:t,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:d,onDeclarationGenerated:(a)=>{let F=st(a,t);i.files.push({fullPath:a,relativePathToRootDir:F,dts:!0,entry:b,outputBasePath:M,format:m}),f.progress("DTS",F,{identifier:r.name})}})]:[]],throw:!1});for(let a of _.logs){if(a.level==="error")throw console.log(`
|
|
7
|
+
`),console.log(a),console.log(`
|
|
8
|
+
`),new Error;if(a.level==="warning")f.warn(a.message);else if(a.level==="info")f.info(a.message)}for(let a of _.outputs){let F=st(a.path,t);if(a.kind==="entry-point")f.progress(m.toUpperCase(),F,{identifier:r.name});i.files.push({fullPath:a.path,relativePathToRootDir:F,dts:!1,entry:b,outputBasePath:M,format:m})}}));if(await Promise.all(u),await nt(s,r,i,{packageJson:n}),r.onSuccess)await r.onSuccess(r)}function st(e,t){return e.replace(`${t}/`,"")}var fe=B(()=>{z();de();le();Y();me();et();R()});var mt={};Ce(mt,{init:()=>zt});import S from"fs/promises";import I from"path";import{cancel as k,confirm as j,intro as At,isCancel as x,log as $,multiselect as ut,outro as Gt,tasks as Tt,text as K}from"@clack/prompts";import{loadConfig as xe}from"coffi";import{detect as Yt,resolveCommand as pe}from"package-manager-detector";import{exec as qt}from"tinyexec";async function lt(e){try{return await S.access(e),!0}catch{return!1}}async function Vt(){let{config:e,filepath:t}=await xe({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,packageJsonProperty:"bunup"});return{exists:!!e,filepath:t||void 0}}async function zt(){At(p.default.bgCyan(p.default.black(" Bunup ")));let{exists:e,filepath:t}=await Vt();if(e){let a=await j({message:`A bunup configuration already exists at ${p.default.cyan(t||"bunup.config.ts")}. Continue and overwrite it?`,initialValue:!1});if(x(a)||!a)k("Initialization cancelled"),process.exit(1)}let i=await Yt();if(!i)$.error("No package manager detected"),process.exit(1);let{config:r,filepath:n}=await xe({name:"package",cwd:process.cwd(),extensions:[".json"]});if(!r||!n)$.error("Cannot find package.json."),process.exit(1);let s=await K({message:"Entry point for your library:",placeholder:"src/index.ts",defaultValue:"src/index.ts"});if(x(s))k("Initialization cancelled"),process.exit(1);let o=I.join(process.cwd(),String(s));if(!await lt(o)){let a=await j({message:`Entry file ${p.default.cyan(String(s))} does not exist. Create it?`,initialValue:!0});if(x(a))k("Initialization cancelled"),process.exit(1);if(a)await S.mkdir(I.dirname(o),{recursive:!0}),await S.writeFile(o,`// Your entry point
|
|
20
9
|
|
|
21
10
|
export function hello() {
|
|
22
|
-
return 'Hello from ${
|
|
11
|
+
return 'Hello from ${I.basename(String(s))}';
|
|
23
12
|
}
|
|
24
|
-
`)
|
|
13
|
+
`),$.success(`Created ${s}`)}let c=await ut({message:"Output formats:",options:[{value:"esm",label:"ESM",hint:"ECMAScript modules"},{value:"cjs",label:"CJS",hint:"CommonJS modules"},{value:"iife",label:"IIFE",hint:"Immediately Invoked Function Expression"}],initialValues:["esm","cjs"],required:!0});if(x(c))k("Initialization cancelled"),process.exit(1);let l=await K({message:"Output directory:",placeholder:"dist",initialValue:"dist",validate:(a)=>a?void 0:"Output directory is required"});if(x(l))k("Initialization cancelled"),process.exit(1);let d=await j({message:"Generate TypeScript declarations (.d.ts files)?",initialValue:!0});if(x(d))k("Initialization cancelled"),process.exit(1);let u=!1,m=[];if(r.workspaces){let a=await j({message:"Detected workspaces. Set up Bunup for multiple packages?",initialValue:!0});if(x(a))k("Initialization cancelled"),process.exit(1);if(u=a,u){let F=async()=>{let y=await K({message:"Workspace name:",placeholder:"core",validate:(h)=>h?void 0:"Workspace name is required"});if(x(y))return null;let U=await K({message:"Workspace root directory:",placeholder:"packages/core",validate:(h)=>h?void 0:"Workspace root is required"});if(x(U))return null;let G=await K({message:"Workspace entry points (comma-separated):",placeholder:"src/index.ts",validate:(h)=>h?void 0:"At least one entry point is required"});if(x(G))return null;return{name:String(y),root:String(U),entries:String(G).split(",").map((h)=>h.trim())}},we=!0;while(we){let y=await F();if(!y)break;m.push(y);for(let G of y.entries){let h=I.join(process.cwd(),y.root,G);if(!await lt(h)){let he=await j({message:`Entry file ${p.default.cyan(`${y.root}/${G}`)} does not exist. Create it?`,initialValue:!0});if(x(he))break;if(he)await S.mkdir(I.dirname(h),{recursive:!0}),await S.writeFile(h,`// Your entry point
|
|
25
14
|
|
|
26
15
|
export function hello() {
|
|
27
|
-
return 'Hello from ${
|
|
16
|
+
return 'Hello from ${y.name}';
|
|
28
17
|
}
|
|
29
|
-
`)
|
|
30
|
-
${
|
|
18
|
+
`),$.success(`Created ${y.root}/${G}`)}}let U=await j({message:"Add another workspace?",initialValue:!1});if(x(U))break;we=U}}}let b=[{value:"report",label:"Report",hint:"Logs bundle size report after build (recommended)",configGenerator:()=>"report()",defaultEnabled:!0},{value:"exports",label:"Exports",hint:"Generates exports field in package.json after build (recommended)",configGenerator:()=>"exports()",defaultEnabled:!0}],M=await ut({message:"Select plugins to use (optional):",options:b,required:!1,initialValues:b.filter((a)=>a.defaultEnabled).map((a)=>a.value)});if(x(M))k("Initialization cancelled"),process.exit(1);if(u&&m.length>0)await Kt(m,c,String(l),d,M,b,t||void 0);else await Ut(String(s),c,String(l),d,M,b,t||void 0);await Xt(),$.success("Configuration generated"),await _t(r,n),$.success("package.json updated");let W=[{title:"Installing bunup",task:async()=>{return await Pt(r,i),"Bunup installed"}}];try{await Tt(W)}catch(a){$.error(`Error: ${a instanceof Error?a.message:String(a)}`),process.exit(1)}let ne=pe(i.agent,"run",["dev"]),_=pe(i.agent,"run",["build"]);Gt(`
|
|
19
|
+
${p.default.bold("\uD83D\uDE80 Happy building with Bunup!")}
|
|
31
20
|
|
|
32
21
|
Run these commands to get started:
|
|
33
|
-
${
|
|
34
|
-
${
|
|
22
|
+
${p.default.cyan(be(_))} - ${p.default.gray("Build your project")}
|
|
23
|
+
${p.default.cyan(be(ne))} - ${p.default.gray("Build in watch mode")}
|
|
35
24
|
|
|
36
|
-
${
|
|
37
|
-
`)}async function
|
|
38
|
-
${
|
|
25
|
+
${p.default.dim("Edit")} ${p.default.underline("bunup.config.ts")} ${p.default.dim("to customize your build.")}
|
|
26
|
+
`)}async function Ut(e,t,i,r,n,s,o=I.join(process.cwd(),"bunup.config.ts")){let c=dt(n,s),l=`import { defineConfig } from 'bunup';
|
|
27
|
+
${n.length>0?`import { ${n.join(", ")} } from 'bunup/plugins';
|
|
39
28
|
`:""}
|
|
40
29
|
export default defineConfig({
|
|
41
30
|
entry: '${e}',
|
|
42
31
|
format: [${t.map((d)=>`'${d}'`).join(", ")}],
|
|
43
|
-
outDir: '${
|
|
44
|
-
dts: true,`:""}${
|
|
45
|
-
plugins: [${
|
|
32
|
+
outDir: '${i}',${r?`
|
|
33
|
+
dts: true,`:""}${c?`
|
|
34
|
+
plugins: [${c}],`:""}
|
|
46
35
|
});
|
|
47
|
-
`;await S.writeFile(
|
|
48
|
-
name: '${
|
|
49
|
-
root: '${
|
|
36
|
+
`;await S.writeFile(o,l)}async function Kt(e,t,i,r,n,s,o=I.join(process.cwd(),"bunup.config.ts")){let c=dt(n,s),l=e.map((u)=>{let m=u.entries.length===1?`'${u.entries[0]}'`:`[${u.entries.map((b)=>`'${b}'`).join(", ")}]`;return` {
|
|
37
|
+
name: '${u.name}',
|
|
38
|
+
root: '${u.root}',
|
|
50
39
|
config: {
|
|
51
|
-
entry: ${
|
|
52
|
-
format: [${t.map((
|
|
53
|
-
outDir: '${
|
|
54
|
-
dts: true,`:""}${
|
|
55
|
-
plugins: [${
|
|
40
|
+
entry: ${m},
|
|
41
|
+
format: [${t.map((b)=>`'${b}'`).join(", ")}],
|
|
42
|
+
outDir: '${i}',${r?`
|
|
43
|
+
dts: true,`:""}${c?`
|
|
44
|
+
plugins: [${c}],`:""}
|
|
56
45
|
},
|
|
57
46
|
}`}).join(`,
|
|
58
47
|
`),d=`import { defineWorkspace } from 'bunup';
|
|
59
|
-
${
|
|
48
|
+
${n.length>0?`import { ${n.join(", ")} } from 'bunup/plugins';
|
|
60
49
|
`:""}
|
|
61
50
|
export default defineWorkspace([
|
|
62
|
-
${
|
|
51
|
+
${l}
|
|
63
52
|
]);
|
|
64
|
-
`;await S.writeFile(
|
|
65
|
-
`);return}let
|
|
53
|
+
`;await S.writeFile(o,d)}function dt(e,t){return t.filter((i)=>e.includes(i.value)).map((i)=>i.configGenerator?i.configGenerator():`${i.value}()`).join(", ")}async function _t(e,t){let i=e.scripts||{},r=!1;for(let[n,s]of[["build","bunup"],["dev","bunup --watch"]])if(!i[n]||await j({message:`Script '${n}' exists. Replace with '${s}'?`,initialValue:!0}))i[n]=s,r=!0;if(r)e.scripts=i,await S.writeFile(t,JSON.stringify(e,null,2))}async function Pt(e,t){if(e.dependencies?.bunup||e.devDependencies?.bunup){$.info(`Bunup is already installed
|
|
54
|
+
`);return}let r={bun:"-d",npm:"-D",pnpm:"-D",yarn:"-D"},n=pe(t.agent,"add",[r[t.agent]||"-D","bunup"]);if(!n)throw new Error("Failed to resolve install command");await qt(be(n),[],{nodeOptions:{shell:!0,stdio:"pipe"}})}function be(e){if(!e)return"";return`${e.command} ${e.args.join(" ")}`}async function Xt(){let e={},t=!1,i=I.join(process.cwd(),"tsconfig.json");try{let{config:n,filepath:s}=await xe({name:"tsconfig",cwd:process.cwd(),extensions:[".json"]});if(n&&s)e=n,t=!0,i=s}catch{}if(e.compilerOptions?.isolatedDeclarations!==!0){$.info(`${p.default.cyan("About isolatedDeclarations:")} ${p.default.gray(`A ${p.default.bold("modern TypeScript feature")} for library authors`)}`),$.info(p.default.gray(`Benefits: ${p.default.bold("faster builds")}, ${p.default.bold("more reliable API types")}, and ${p.default.bold("better editor support")} to catch issues during development`));let n=await j({message:"Enable isolatedDeclarations in tsconfig.json? (recommended but optional)",initialValue:!0});if(x(n))return;if(n){if(e.compilerOptions=e.compilerOptions||{},e.compilerOptions.isolatedDeclarations=!0,e.compilerOptions.declaration=!0,"allowJs"in e.compilerOptions)e.compilerOptions.allowJs=null;if(e.exclude=e.exclude||[],!e.exclude.includes("bunup.config.ts"))e.exclude.push("bunup.config.ts");await S.writeFile(i,JSON.stringify(e,null,2)),$.success("Updated tsconfig.json with isolatedDeclarations")}}else if(t){if(e.exclude=e.exclude||[],!e.exclude.includes("bunup.config.ts"))e.exclude.push("bunup.config.ts"),await S.writeFile(i,JSON.stringify(e,null,2))}}var p;var gt=B(()=>{p=L(A(),1)});import{exec as Dt}from"tinyexec";var P="0.7.0";z();Y();var ue=L(A(),1);var Se="https://bunup.dev/docs/guide/cli-options";z();Y();R();function C(e){return(t,i)=>{i[e]=t===!0||t==="true"}}function O(e){return(t,i)=>{if(typeof t==="string")i[e]=t;else throw new E(`Option --${e} requires a string value`)}}function H(e){return(t,i)=>{if(typeof t==="string")i[e]=t.split(",");else throw new E(`Option --${e} requires a string value`)}}function St(e){return(t,i)=>{if(typeof t==="boolean")i[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")i[e]=t.toLowerCase()==="true";else i[e]=t;else throw new E(`Option --${e} requires a boolean or string value`)}}function Mt(){console.log(`
|
|
66
55
|
Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
|
|
67
|
-
`),console.log("For more information on available options, visit:"),console.log(`${
|
|
68
|
-
`),process.exit(0)}function Rt(){console.log(
|
|
56
|
+
`),console.log("For more information on available options, visit:"),console.log(`${ue.default.cyan(ue.default.underline(Se))}
|
|
57
|
+
`),process.exit(0)}function Rt(){console.log(P),process.exit(0)}var Te={name:{flags:["n","name"],handler:O("name")},format:{flags:["f","format"],handler:H("format")},outDir:{flags:["o","out-dir"],handler:O("outDir")},minify:{flags:["m","minify"],handler:C("minify")},watch:{flags:["w","watch"],handler:C("watch")},dts:{flags:["d","dts"],handler:C("dts")},banner:{flags:["bn","banner"],handler:O("banner")},footer:{flags:["ft","footer"],handler:O("footer")},external:{flags:["e","external"],handler:H("external")},sourcemap:{flags:["sm","sourcemap"],handler:St("sourcemap")},target:{flags:["t","target"],handler:O("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:C("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:C("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:C("minifySyntax")},clean:{flags:["c","clean"],handler:C("clean")},splitting:{flags:["s","splitting"],handler:C("splitting")},noExternal:{flags:["ne","no-external"],handler:H("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:O("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:C("bytecode")},silent:{flags:["silent"],handler:C("silent")},config:{flags:["config"],handler:O("config")},publicPath:{flags:["pp","public-path"],handler:O("publicPath")},env:{flags:["env"],handler:O("env")},onSuccess:{flags:["onSuccess"],handler:O("onSuccess")},filter:{flags:["filter"],handler:H("filter")},init:{flags:["init"],handler:C("init")},entry:{flags:["entry"],handler:(e,t,i)=>{if(typeof e!=="string")throw new E(`Entry${i?` --entry.${i}`:""} requires a string value`);let r=t.entry||{};if(i){if(r[i])f.warn(`Duplicate entry name '${i}' provided via --entry.${i}. Overwriting previous entry.`);r[i]=e}else{let n=We(e);if(r[n])f.warn(`Duplicate entry name '${n}' derived from '${e}'. Overwriting previous entry.`);r[n]=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:()=>Mt()},version:{flags:["v","version"],handler:()=>Rt()}},ee={};for(let e of Object.values(Te))for(let t of e.flags)ee[t]=e.handler;function Ye(e){let t={};for(let i=0;i<e.length;i++){let r=e[i];if(r.startsWith("--")){let n,s;if(r.includes("=")){let[o,c]=r.slice(2).split("=",2);n=o,s=c}else{n=r.slice(2);let o=e[i+1];if(s=o&&!o.startsWith("-")?o:!0,typeof s==="string")i++}if(n.includes(".")){let[o,c]=n.split(".",2),l=ee[o];if(l)l(s,t,c);else throw new E(`Unknown option: --${n}`)}else{let o=ee[n];if(o)o(s,t);else throw new E(`Unknown option: --${n}`)}}else if(r.startsWith("-")){let n=r.slice(1),s=e[i+1],o=s&&!s.startsWith("-")?s:!0;if(typeof o==="string")i++;let c=ee[n];if(c)c(o,t);else throw new E(`Unknown option: -${n}`)}else Te.entry.handler(r,t,void 0)}return t}var ft=L(A(),1);le();R();import{loadConfig as Qt}from"coffi";var ct=L(A(),1);fe();z();de();Y();me();R();import re from"path";async function at(e,t){let i=new Set,r=ie(e),n=te(r);for(let{entry:d}of n){let u=re.resolve(t,d),m=re.dirname(u);i.add(m)}let o=(await import("chokidar")).watch(Array.from(i),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,re.join(t,r.outDir)]}),c=!1,l=async(d=!1)=>{if(c)return;c=!0;try{let u=performance.now();if(await ge(r,t),!d)f.cli(`\uD83D\uDCE6 Rebuild finished in ${ct.default.green(N(performance.now()-u))}`)}catch(u){ae(u)}finally{c=!1}};o.on("change",(d)=>{let u=re.relative(t,d);f.cli(`File changed: ${u}`,{muted:!0,once:u}),l()}),o.on("error",(d)=>{throw new Z(`Watcher error: ${ce(d)}`)}),await l(!0)}async function Zt(e=Bun.argv.slice(2)){let t=Ye(e);if(t.init){let{init:u}=await Promise.resolve().then(() => (gt(),mt));await u();return}Q(t.silent);let i=process.cwd(),{config:r,filepath:n}=await Qt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config,packageJsonProperty:"bunup"}),s=!r?[{rootDir:i,options:t}]:await qe(r,i,t.filter);if(f.cli(`Using bunup v${P} and bun v${Bun.version}`,{muted:!0}),n)f.cli(`Using ${v(n,2)}`,{muted:!0});let o=performance.now();f.cli("Build started");let{build:c}=await Promise.resolve().then(() => (fe(),ot));await Promise.all(s.flatMap(({options:u,rootDir:m})=>{return je(u).map(async(M)=>{let W={...M,...Jt(t)};if(W.watch)await at(W,m);else await c(W,m)})}));let l=performance.now()-o,d=N(l);if(f.cli(`\u26A1\uFE0F Build completed in ${ft.default.green(d)}`),t.watch)f.cli("\uD83D\uDC40 Watching for file changes");if(t.onSuccess)f.cli(`Running command: ${t.onSuccess}`,{muted:!0}),await Dt(t.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!t.watch)process.exit(process.exitCode??0)}function Jt(e){return{...e,onSuccess:void 0,config:void 0,filter:void 0,init:void 0}}Zt().catch((e)=>Oe(e));
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
// @bun @bun-cjs
|
|
2
|
-
(function(exports, require, module, __filename, __dirname) {var fe=Object.create;var{getPrototypeOf:be,defineProperty:f,getOwnPropertyNames:M,getOwnPropertyDescriptor:he}=Object,D=Object.prototype.hasOwnProperty;var x=(t,e,n)=>{n=t!=null?fe(be(t)):{};let r=e||!t||!t.__esModule?f(n,"default",{value:t,enumerable:!0}):n;for(let i of M(t))if(!D.call(r,i))f(r,i,{get:()=>t[i],enumerable:!0});return r},T=new WeakMap,xe=(t)=>{var e=T.get(t),n;if(e)return e;if(e=f({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")M(t).map((r)=>!D.call(e,r)&&f(e,r,{get:()=>t[r],enumerable:!(n=he(t,r))||n.enumerable}));return T.set(t,e),e},ye=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Be=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var R=ye((Le,O)=>{var B=process||{},F=B.argv||[],y=B.env||{},Pe=!(!!y.NO_COLOR||F.includes("--no-color"))&&(!!y.FORCE_COLOR||F.includes("--color")||B.platform==="win32"||(B.stdout||{}).isTTY&&y.TERM!=="dumb"||!!y.CI),Ce=(t,e,n=t)=>(r)=>{let i=""+r,o=i.indexOf(e,t.length);return~o?t+we(i,e,n,o)+e:t+i+e},we=(t,e,n,r)=>{let i="",o=0;do i+=t.substring(o,r)+n,o=r+e.length,r=t.indexOf(e,o);while(~r);return i+t.substring(o)},j=(t=Pe)=>{let e=t?Ce:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};O.exports=j();O.exports.createColors=j});var Te={};Be(Te,{defineWorkspace:()=>$,defineConfig:()=>L,build:()=>ce});module.exports=xe(Te);function L(t){return t}function $(t){return t}var me=require("bun-dts");var Oe=x(R());var s=x(R()),I=!1;function A(t){I=t??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=s.default.blue;mutedColor=s.default.dim;infoColor=s.default.cyan;warnColor=s.default.yellow;errorColor=s.default.red;defaultColor=s.default.white;progressFgColorMap={ESM:s.default.yellow,CJS:s.default.green,IIFE:s.default.magenta,DTS:s.default.blue};progressIdentifierBgColorMap={ESM:s.default.bgYellow,CJS:s.default.bgGreen,IIFE:s.default.bgMagenta,DTS:s.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!c.instance)c.instance=new c;return c.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({fgColor:t,bgColor:e,label:n,message:r,identifier:i,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),g=o?this.mutedColor(r):r,p=i?` ${e(s.default.black(` ${i} `))}`:"";return`${t(n)} ${a}${g}${p}`}output(t,e={},n=console.log){if(I||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(t),e.verticalSpace)n("")}cli(t,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:s.default.bgBlue,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:s.default.bgCyan,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:s.default.bgYellow,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({fgColor:this.errorColor,bgColor:s.default.bgRed,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(t){for(let[e,n]of Object.entries(this.progressFgColorMap))if(t.includes(e))return n;return this.defaultColor}getProgressBgColor(t){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(t.includes(e))return n;return s.default.bgWhite}progress(t,e,n={}){let r=this.getProgressFgColor(t),i=this.getProgressBgColor(t),o=this.formatMessage({fgColor:r,bgColor:i,label:t,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var m=c.getInstance();class N extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends N{constructor(t){super(t);this.name="BunupBuildError"}}function _(t){let e=typeof t.dts==="object"&&"entry"in t.dts?t.dts.entry:void 0,n=[];if(typeof t.entry==="string")n=[{path:t.entry,outputBasePath:null,dts:!1}];else if(typeof t.entry==="object"&&!Array.isArray(t.entry))n=Object.entries(t.entry).map(([r,i])=>({path:i,outputBasePath:r,dts:!1}));else n=t.entry.map((r)=>({path:r,outputBasePath:null,dts:!1}));if(typeof t.dts!=="undefined"&&!e)n=n.map((r)=>({...r,dts:!0}));else if(e){let r=[];if(typeof e==="string")r=[{path:e,outputBasePath:null,dts:!0}];else if(typeof e==="object"&&!Array.isArray(e))r=Object.entries(e).map(([o,a])=>({path:a,outputBasePath:o,dts:!0}));else r=e.map((o)=>({path:o,outputBasePath:null,dts:!0}));let i=new Set;n=n.map((o)=>{let a=r.some((g)=>g.path===o.path&&g.outputBasePath===o.outputBasePath);if(a)i.add(`${o.path}:${o.outputBasePath}`);return{...o,dts:a}});for(let o of r)if(!i.has(`${o.path}:${o.outputBasePath}`))n.push(o)}return n}function W(t,e){return{entry:`[dir]/${t||"[name]"}${e}`,chunk:`${t||"[name]"}-[hash].[ext]`,asset:`${t?`${t}-`:""}[name]-[hash].[ext]`}}var X=require("coffi");var E=x(require("fs/promises")),G=x(require("path"));function H(t,e){switch(t){case"esm":return U(e)?".js":".mjs";case"cjs":return U(e)?".cjs":".js";case"iife":return".global.js"}}function S(t){return t==="node"||t==="bun"}function U(t){return t==="module"}function J(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Y(t,e=3){return t.split("/").slice(-e).join("/")}async function K(t,e){let n=G.default.join(t,e);try{await E.default.rm(n,{recursive:!0,force:!0})}catch(r){throw new b(`Failed to clean output directory: ${r}`)}await E.default.mkdir(n,{recursive:!0})}async function z(t){let{config:e,filepath:n}=await X.loadConfig({name:"package",cwd:t,extensions:[".json"]});return{packageJson:e,path:n}}var Re={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function q(t){return{...Re,...t}}function Q(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:i??o}}function Z(t,e){return e==="cjs"?t:void 0}function V(t){if(t===!0)return"inline";return typeof t==="string"?t:void 0}function ee(t,e,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((i,o)=>{let a=JSON.stringify(n[o]);return i[`process.env.${o}`]=a,i[`import.meta.env.${o}`]=a,i},{}),...t,...r==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function te(t,e){return t===void 0?e==="esm":t}function re(t){return typeof t==="string"?t:void 0}function Ee(t){return J(t).map((e)=>new RegExp(`^${e}($|\\/|\\\\)`))}function ne(t,e){return typeof e==="string"?e===t:e.test(t)}function oe(t,e,n){let i=Ee(n).some((a)=>a.test(t))||e.external?.some((a)=>ne(t,a)),o=e.noExternal?.some((a)=>ne(t,a));return i&&!o}function ie(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(oe(i,t,e))return{path:i,external:!0};return null})}}}var Se=/\.(js|ts|jsx|tsx|mts|cts)$/,k={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&S(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
-
const __dirname = dirname(__filename);
|
|
7
|
-
|
|
8
|
-
`},importMetaUrl:{appliesTo:(t,e)=>t==="cjs"&&S(e),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
9
|
-
|
|
10
|
-
const importMetaUrl = pathToFileURL(__filename).href;
|
|
11
|
-
|
|
12
|
-
`}};function se({format:t,target:e,shims:n}){let i=ke(n).map((o)=>k[o]).filter((o)=>o.appliesTo(t,e));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:Se},async({path:a})=>{let g=await Bun.file(a).text(),p=i.filter((l)=>l.isNeededInFile(g));if(p.length===0)return;let{shebangLine:P,codeContent:C}=ve(g),w=p.map((l)=>l.generateCode()).join("");return{contents:P+w+C}})}}}function ke(t){if(t===!0)return Object.keys(k);if(!t)return[];return Object.entries(t).filter(([e,n])=>n&&(e in k)).map(([e])=>e)}function ve(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
|
|
13
|
-
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}function ae(t){if(!t)return[];return t.filter((e)=>e.type==="bun")}function le(t){if(!t)return[];return t.filter((e)=>e.type==="bunup")}async function ue(t,e){if(!t)return;for(let n of t)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function ge(t,e,n){if(!t)return;for(let r of t)if(r.hooks.onBuildDone)await r.hooks.onBuildDone({options:e,output:n})}async function ce(t,e=process.cwd()){let n={files:[]},r=q(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)K(e,r.outDir);A(r.silent);let{packageJson:i,path:o}=await z(e);if(i&&o)m.cli(`Using ${Y(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let a=le(r.plugins);await ue(a,r);let g=_(r),p=i?.type,P=[ie(r,i),...ae(r.plugins).map((l)=>l.plugin)],C=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,w=r.format.flatMap((l)=>g.map(async(h)=>{let de=r.outputExtension?.({format:l,packageType:p,options:r,entry:h.path}).js??H(l,p),v=await Bun.build({entrypoints:[`${e}/${h.path}`],format:l,naming:W(h.outputBasePath,de),splitting:te(r.splitting,l),bytecode:Z(r.bytecode,l),define:ee(r.define,r.shims,r.env,l),minify:Q(r),outdir:`${e}/${r.outDir}`,target:r.target,sourcemap:V(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:re(r.env),plugins:[...P,...h.dts?[me.dts({cwd:e,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:C,onDeclarationGenerated:(u)=>{let d=pe(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),m.progress("DTS",d,{identifier:r.name})}})]:[],se({format:l,target:r.target,shims:r.shims})],throw:!1});for(let u of v.logs){if(u.level==="error")throw console.log(`
|
|
14
|
-
`),console.log(u),console.log(`
|
|
15
|
-
`),new Error;if(u.level==="warning")m.warn(u.message);else if(u.level==="info")m.info(u.message)}for(let u of v.outputs){let d=pe(u.path,e);if(u.kind==="entry-point")m.progress(l.toUpperCase(),d,{identifier:r.name});n.files.push({fullPath:u.path,relativePathToRootDir:d})}}));if(await Promise.all(w),await ge(a,r,n),r.onSuccess)await r.onSuccess(r)}function pe(t,e){return t.replace(`${e}/`,"")}})
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var ar=Object.create;var{getPrototypeOf:Br,defineProperty:f,getOwnPropertyNames:$,getOwnPropertyDescriptor:hr}=Object,W=Object.prototype.hasOwnProperty;var h=(e,r,g)=>{g=e!=null?ar(Br(e)):{};let n=r||!e||!e.__esModule?f(g,"default",{value:e,enumerable:!0}):g;for(let i of $(e))if(!W.call(n,i))f(n,i,{get:()=>e[i],enumerable:!0});return n},S=new WeakMap,wr=(e)=>{var r=S.get(e),g;if(r)return r;if(r=f({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")$(e).map((n)=>!W.call(r,n)&&f(r,n,{get:()=>e[n],enumerable:!(g=hr(e,n))||g.enumerable}));return S.set(e,r),r},Mr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var Rr=(e,r)=>{for(var g in r)f(e,g,{get:r[g],enumerable:!0,configurable:!0,set:(n)=>r[g]=()=>n})};var E=Mr((Nr,I)=>{var M=process||{},Y=M.argv||[],w=M.env||{},pr=!(!!w.NO_COLOR||Y.includes("--no-color"))&&(!!w.FORCE_COLOR||Y.includes("--color")||M.platform==="win32"||(M.stdout||{}).isTTY&&w.TERM!=="dumb"||!!w.CI),Ir=(e,r,g=e)=>(n)=>{let i=""+n,o=i.indexOf(r,e.length);return~o?e+Er(i,r,g,o)+r:e+i+r},Er=(e,r,g,n)=>{let i="",o=0;do i+=e.substring(o,n)+g,o=n+r.length,n=e.indexOf(r,o);while(~n);return i+e.substring(o)},G=(e=pr)=>{let r=e?Ir:()=>String;return{isColorSupported:e,reset:r("\x1B[0m","\x1B[0m"),bold:r("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:r("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:r("\x1B[3m","\x1B[23m"),underline:r("\x1B[4m","\x1B[24m"),inverse:r("\x1B[7m","\x1B[27m"),hidden:r("\x1B[8m","\x1B[28m"),strikethrough:r("\x1B[9m","\x1B[29m"),black:r("\x1B[30m","\x1B[39m"),red:r("\x1B[31m","\x1B[39m"),green:r("\x1B[32m","\x1B[39m"),yellow:r("\x1B[33m","\x1B[39m"),blue:r("\x1B[34m","\x1B[39m"),magenta:r("\x1B[35m","\x1B[39m"),cyan:r("\x1B[36m","\x1B[39m"),white:r("\x1B[37m","\x1B[39m"),gray:r("\x1B[90m","\x1B[39m"),bgBlack:r("\x1B[40m","\x1B[49m"),bgRed:r("\x1B[41m","\x1B[49m"),bgGreen:r("\x1B[42m","\x1B[49m"),bgYellow:r("\x1B[43m","\x1B[49m"),bgBlue:r("\x1B[44m","\x1B[49m"),bgMagenta:r("\x1B[45m","\x1B[49m"),bgCyan:r("\x1B[46m","\x1B[49m"),bgWhite:r("\x1B[47m","\x1B[49m"),blackBright:r("\x1B[90m","\x1B[39m"),redBright:r("\x1B[91m","\x1B[39m"),greenBright:r("\x1B[92m","\x1B[39m"),yellowBright:r("\x1B[93m","\x1B[39m"),blueBright:r("\x1B[94m","\x1B[39m"),magentaBright:r("\x1B[95m","\x1B[39m"),cyanBright:r("\x1B[96m","\x1B[39m"),whiteBright:r("\x1B[97m","\x1B[39m"),bgBlackBright:r("\x1B[100m","\x1B[49m"),bgRedBright:r("\x1B[101m","\x1B[49m"),bgGreenBright:r("\x1B[102m","\x1B[49m"),bgYellowBright:r("\x1B[103m","\x1B[49m"),bgBlueBright:r("\x1B[104m","\x1B[49m"),bgMagentaBright:r("\x1B[105m","\x1B[49m"),bgCyanBright:r("\x1B[106m","\x1B[49m"),bgWhiteBright:r("\x1B[107m","\x1B[49m")}};I.exports=G();I.exports.createColors=G});var $r={};Rr($r,{defineWorkspace:()=>N,defineConfig:()=>F,build:()=>dr});module.exports=wr($r);function F(e){return e}function N(e){return e}var mr=require("bun-dts");var Lr=h(E());var t=h(E()),T=!1;function A(e){T=e??!1}class d{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=t.default.blue;mutedColor=t.default.dim;infoColor=t.default.cyan;warnColor=t.default.yellow;errorColor=t.default.red;defaultColor=t.default.white;progressFgColorMap={ESM:t.default.yellow,CJS:t.default.green,IIFE:t.default.magenta,DTS:t.default.blue};progressIdentifierBgColorMap={ESM:t.default.bgYellow,CJS:t.default.bgGreen,IIFE:t.default.bgMagenta,DTS:t.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!d.instance)d.instance=new d;return d.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({fgColor:e,bgColor:r,label:g,message:n,identifier:i,muted:o}){let x=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-g.length)),b=o?this.mutedColor(n):n,m=i?` ${r(t.default.black(` ${i} `))}`:"";return`${e(g)} ${x}${b}${m}`}output(e,r={},g=console.log){if(T||!this.shouldLog(r))return;if(r.verticalSpace)g("");if(g(e),r.verticalSpace)g("")}cli(e,r={}){let g=this.formatMessage({fgColor:this.cliColor,bgColor:t.default.bgBlue,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(g,r)}info(e,r={}){let g=this.formatMessage({fgColor:this.infoColor,bgColor:t.default.bgCyan,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(g,r)}warn(e,r={}){let g=this.formatMessage({fgColor:this.warnColor,bgColor:t.default.bgYellow,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(g,r,console.warn)}error(e,r={}){let g=this.formatMessage({fgColor:this.errorColor,bgColor:t.default.bgRed,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(g,r,console.error)}getProgressFgColor(e){for(let[r,g]of Object.entries(this.progressFgColorMap))if(e.includes(r))return g;return this.defaultColor}getProgressBgColor(e){for(let[r,g]of Object.entries(this.progressIdentifierBgColorMap))if(e.includes(r))return g;return t.default.bgWhite}progress(e,r,g={}){let n=this.getProgressFgColor(e),i=this.getProgressBgColor(e),o=this.formatMessage({fgColor:n,bgColor:i,label:e,message:r,identifier:g.identifier,muted:g.muted});this.output(o,g)}}var l=d.getInstance();class H extends Error{constructor(e){super(e);this.name="BunupError"}}class C extends H{constructor(e){super(e);this.name="BunupBuildError"}}var L=h(require("fs/promises")),R=h(require("path"));function U(e,r){switch(e){case"esm":return K(r)?".js":".mjs";case"cjs":return K(r)?".cjs":".js";case"iife":return".global.js"}}function X(e){return e.replace(R.default.extname(e),"")}function _(e){return e.replace(/\\/g,"/")}function K(e){return e==="module"}function j(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function q(e,r=3){return e.split("/").slice(-r).join("/")}async function Q(e,r){let g=R.default.join(e,r);try{await L.default.rm(g,{recursive:!0,force:!0})}catch(n){throw new C(`Failed to clean output directory: ${n}`)}await L.default.mkdir(g,{recursive:!0})}function v(e){let r=typeof e.dts==="object"&&"entry"in e.dts?e.dts.entry:void 0,g=Z(e.entry,!1);if(typeof e.dts!=="undefined"){if(!r)return g.map((b)=>({...b,dts:!0}));let n=Z(r,!0),i=new Set,o=g.map((b)=>{let m=n.find((a)=>a.entry===b.entry&&a.outputBasePath===b.outputBasePath);if(m)i.add(`${b.entry}:${b.outputBasePath}`);return{...b,dts:!!m}}),x=n.filter((b)=>!i.has(`${b.entry}:${b.outputBasePath}`));return[...o,...x]}return g}function Z(e,r){if(typeof e==="string")return[{entry:e,outputBasePath:k(e),dts:r}];if(typeof e==="object"&&!Array.isArray(e))return Object.entries(e).map(([g,n])=>({entry:n,outputBasePath:g,dts:r}));return e.map((g)=>({entry:g,outputBasePath:k(g),dts:r}))}function k(e){let r=_(X(e)).split("/");return r.length>1?r.slice(1).join("/"):r.join("/")}function z(e,r){return{entry:`[dir]/${e}${r}`,chunk:`${e}-[hash].[ext]`,asset:`${e}-[name]-[hash].[ext]`}}var V=require("coffi");async function J(e){let{config:r,filepath:g}=await V.loadConfig({name:"package",cwd:e,extensions:[".json"]});return{data:r,path:g}}var Or={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function D(e){return{...Or,...e}}function P(e){let{minify:r,minifyWhitespace:g,minifyIdentifiers:n,minifySyntax:i}=e,o=r===!0;return{whitespace:g??o,identifiers:n??o,syntax:i??o}}function y(e,r){return r==="cjs"?e:void 0}function rr(e){if(e===!0)return"inline";return typeof e==="string"?e:void 0}function er(e,r){return{...typeof r==="object"&&Object.keys(r).reduce((g,n)=>{let i=JSON.stringify(r[n]);return g[`process.env.${n}`]=i,g[`import.meta.env.${n}`]=i,g},{}),...e}}function nr(e,r){return e===void 0?r==="esm":e}function gr(e){return typeof e==="string"?e:void 0}function Sr(e){return j(e).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function ir(e,r){return typeof r==="string"?r===e:r.test(e)}function or(e,r,g){let i=Sr(g).some((x)=>x.test(e))||r.external?.some((x)=>ir(e,x)),o=r.noExternal?.some((x)=>ir(e,x));return i&&!o}function tr(e,r){return{name:"bunup:external-option-plugin",setup(g){g.onResolve({filter:/.*/},(n)=>{let i=n.path;if(or(i,e,r))return{path:i,external:!0};return null})}}}function br(e){if(!e)return[];return e.filter((r)=>r.type==="bun")}function sr(e){if(!e)return[];return e.filter((r)=>r.type==="bunup")}async function xr(e,r){if(!e)return;for(let g of e)if(g.hooks.onBuildStart)await g.hooks.onBuildStart(r)}async function ur(e,r,g,n){if(!e)return;for(let i of e)if(i.hooks.onBuildDone)await i.hooks.onBuildDone({options:r,output:g,meta:n})}async function dr(e,r=process.cwd()){let g={files:[]},n=D(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new C("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)Q(r,n.outDir);A(n.silent);let i=await J(r);if(i.data&&i.path)l.cli(`Using ${q(i.path,2)}`,{muted:!0,identifier:n.name,once:`${i.path}:${n.name}`});let o=sr(n.plugins);await xr(o,n);let x=v(n),b=i.data?.type,m=[tr(n,i.data),...br(n.plugins).map((u)=>u.plugin)],a=typeof n.dts==="object"&&"resolve"in n.dts?n.dts.resolve:void 0,cr=n.format.flatMap((u)=>x.map(async({entry:B,outputBasePath:p,dts:fr})=>{let Cr=n.outputExtension?.({format:u,packageType:b,options:n,entry:B}).js??U(u,b),O=await Bun.build({entrypoints:[`${r}/${B}`],format:u,naming:z(p,Cr),splitting:nr(n.splitting,u),bytecode:y(n.bytecode,u),define:er(n.define,n.env),minify:P(n),outdir:`${r}/${n.outDir}`,target:n.target,sourcemap:rr(n.sourcemap),loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer,publicPath:n.publicPath,env:gr(n.env),plugins:[...m,...fr?[mr.dts({cwd:r,preferredTsConfigPath:n.preferredTsconfigPath,warnInsteadOfError:n.watch,resolve:a,onDeclarationGenerated:(s)=>{let c=lr(s,r);g.files.push({fullPath:s,relativePathToRootDir:c,dts:!0,entry:B,outputBasePath:p,format:u}),l.progress("DTS",c,{identifier:n.name})}})]:[]],throw:!1});for(let s of O.logs){if(s.level==="error")throw console.log(`
|
|
3
|
+
`),console.log(s),console.log(`
|
|
4
|
+
`),new Error;if(s.level==="warning")l.warn(s.message);else if(s.level==="info")l.info(s.message)}for(let s of O.outputs){let c=lr(s.path,r);if(s.kind==="entry-point")l.progress(u.toUpperCase(),c,{identifier:n.name});g.files.push({fullPath:s.path,relativePathToRootDir:c,dts:!1,entry:B,outputBasePath:p,format:u})}}));if(await Promise.all(cr),await ur(o,n,g,{packageJson:i}),n.onSuccess)await n.onSuccess(n)}function lr(e,r){return e.replace(`${r}/`,"")}})
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
|
+
type PackageJson = {
|
|
3
|
+
/** The parsed content of the package.json file */
|
|
4
|
+
data: Record<string, unknown> | null
|
|
5
|
+
/** The path to the package.json file */
|
|
6
|
+
path: string | null
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Represents a Bun plugin that can be used with Bunup
|
|
4
10
|
*/
|
|
@@ -11,16 +17,37 @@ type BunupBunPlugin = {
|
|
|
11
17
|
plugin: BunPlugin
|
|
12
18
|
};
|
|
13
19
|
/**
|
|
20
|
+
* Represents the meta data of the build
|
|
21
|
+
*/
|
|
22
|
+
type BuildMeta = {
|
|
23
|
+
/** The package.json file */
|
|
24
|
+
packageJson: PackageJson
|
|
25
|
+
};
|
|
26
|
+
type BuildOutputFile = {
|
|
27
|
+
/** Path to the generated file */
|
|
28
|
+
fullPath: string
|
|
29
|
+
/** Path to the generated file relative to the root directory */
|
|
30
|
+
relativePathToRootDir: string
|
|
31
|
+
/** Whether the file is a dts file */
|
|
32
|
+
dts: boolean
|
|
33
|
+
/** The path to the entry file (defined in config.entry) that generated this output file */
|
|
34
|
+
entry: string
|
|
35
|
+
/**
|
|
36
|
+
* The base path of the output file relative to the output directory, excluding the extension.
|
|
37
|
+
* Examples:
|
|
38
|
+
* - If the entry is "src/client/index.ts", the outputBasePath will be "client/index"
|
|
39
|
+
* - If the entry is "src/index.ts", the outputBasePath will be "index"
|
|
40
|
+
*/
|
|
41
|
+
outputBasePath: string
|
|
42
|
+
/** The format of the output file */
|
|
43
|
+
format: Format
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
14
46
|
* Represents the output of a build operation
|
|
15
47
|
*/
|
|
16
48
|
type BuildOutput = {
|
|
17
49
|
/** Array of generated files with their paths and contents */
|
|
18
|
-
files:
|
|
19
|
-
/** Path to the generated file */
|
|
20
|
-
fullPath: string
|
|
21
|
-
/** Path to the generated file relative to the root directory */
|
|
22
|
-
relativePathToRootDir: string
|
|
23
|
-
}>
|
|
50
|
+
files: BuildOutputFile[]
|
|
24
51
|
};
|
|
25
52
|
/**
|
|
26
53
|
* Context provided to build hooks
|
|
@@ -30,6 +57,8 @@ type BuildContext = {
|
|
|
30
57
|
options: BuildOptions
|
|
31
58
|
/** The output of the build */
|
|
32
59
|
output: BuildOutput
|
|
60
|
+
/** The meta data of the build */
|
|
61
|
+
meta: BuildMeta
|
|
33
62
|
};
|
|
34
63
|
/**
|
|
35
64
|
* Hooks that can be implemented by Bunup plugins
|
|
@@ -69,17 +98,6 @@ type Target = BunBuildOptions["target"];
|
|
|
69
98
|
type External = (string | RegExp)[];
|
|
70
99
|
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
71
100
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
72
|
-
type ShimOptions = {
|
|
73
|
-
/**
|
|
74
|
-
* Adds __dirname and __filename shims for ESM files when used
|
|
75
|
-
*/
|
|
76
|
-
dirnameFilename?: boolean
|
|
77
|
-
/**
|
|
78
|
-
* Adds import.meta.url shims for CJS files when used
|
|
79
|
-
*/
|
|
80
|
-
importMetaUrl?: boolean
|
|
81
|
-
};
|
|
82
|
-
type Shims = boolean | ShimOptions;
|
|
83
101
|
type DtsResolve = boolean | (string | RegExp)[];
|
|
84
102
|
type DtsOptions = {
|
|
85
103
|
/**
|
|
@@ -296,24 +314,6 @@ interface BuildOptions {
|
|
|
296
314
|
*/
|
|
297
315
|
publicPath?: string;
|
|
298
316
|
/**
|
|
299
|
-
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
300
|
-
*
|
|
301
|
-
* When set to true, automatically injects all shims when needed
|
|
302
|
-
* When set to an object, only injects the specified shims
|
|
303
|
-
*
|
|
304
|
-
* Available shims:
|
|
305
|
-
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
306
|
-
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* // Enable all shims
|
|
310
|
-
* shims: true
|
|
311
|
-
*
|
|
312
|
-
* // Enable only specific shims
|
|
313
|
-
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
314
|
-
*/
|
|
315
|
-
shims?: Shims;
|
|
316
|
-
/**
|
|
317
317
|
* Controls how environment variables are handled during bundling.
|
|
318
318
|
*
|
|
319
319
|
* Can be one of:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
|
+
type PackageJson = {
|
|
3
|
+
/** The parsed content of the package.json file */
|
|
4
|
+
data: Record<string, unknown> | null
|
|
5
|
+
/** The path to the package.json file */
|
|
6
|
+
path: string | null
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Represents a Bun plugin that can be used with Bunup
|
|
4
10
|
*/
|
|
@@ -11,16 +17,37 @@ type BunupBunPlugin = {
|
|
|
11
17
|
plugin: BunPlugin
|
|
12
18
|
};
|
|
13
19
|
/**
|
|
20
|
+
* Represents the meta data of the build
|
|
21
|
+
*/
|
|
22
|
+
type BuildMeta = {
|
|
23
|
+
/** The package.json file */
|
|
24
|
+
packageJson: PackageJson
|
|
25
|
+
};
|
|
26
|
+
type BuildOutputFile = {
|
|
27
|
+
/** Path to the generated file */
|
|
28
|
+
fullPath: string
|
|
29
|
+
/** Path to the generated file relative to the root directory */
|
|
30
|
+
relativePathToRootDir: string
|
|
31
|
+
/** Whether the file is a dts file */
|
|
32
|
+
dts: boolean
|
|
33
|
+
/** The path to the entry file (defined in config.entry) that generated this output file */
|
|
34
|
+
entry: string
|
|
35
|
+
/**
|
|
36
|
+
* The base path of the output file relative to the output directory, excluding the extension.
|
|
37
|
+
* Examples:
|
|
38
|
+
* - If the entry is "src/client/index.ts", the outputBasePath will be "client/index"
|
|
39
|
+
* - If the entry is "src/index.ts", the outputBasePath will be "index"
|
|
40
|
+
*/
|
|
41
|
+
outputBasePath: string
|
|
42
|
+
/** The format of the output file */
|
|
43
|
+
format: Format
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
14
46
|
* Represents the output of a build operation
|
|
15
47
|
*/
|
|
16
48
|
type BuildOutput = {
|
|
17
49
|
/** Array of generated files with their paths and contents */
|
|
18
|
-
files:
|
|
19
|
-
/** Path to the generated file */
|
|
20
|
-
fullPath: string
|
|
21
|
-
/** Path to the generated file relative to the root directory */
|
|
22
|
-
relativePathToRootDir: string
|
|
23
|
-
}>
|
|
50
|
+
files: BuildOutputFile[]
|
|
24
51
|
};
|
|
25
52
|
/**
|
|
26
53
|
* Context provided to build hooks
|
|
@@ -30,6 +57,8 @@ type BuildContext = {
|
|
|
30
57
|
options: BuildOptions
|
|
31
58
|
/** The output of the build */
|
|
32
59
|
output: BuildOutput
|
|
60
|
+
/** The meta data of the build */
|
|
61
|
+
meta: BuildMeta
|
|
33
62
|
};
|
|
34
63
|
/**
|
|
35
64
|
* Hooks that can be implemented by Bunup plugins
|
|
@@ -69,17 +98,6 @@ type Target = BunBuildOptions["target"];
|
|
|
69
98
|
type External = (string | RegExp)[];
|
|
70
99
|
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
71
100
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
72
|
-
type ShimOptions = {
|
|
73
|
-
/**
|
|
74
|
-
* Adds __dirname and __filename shims for ESM files when used
|
|
75
|
-
*/
|
|
76
|
-
dirnameFilename?: boolean
|
|
77
|
-
/**
|
|
78
|
-
* Adds import.meta.url shims for CJS files when used
|
|
79
|
-
*/
|
|
80
|
-
importMetaUrl?: boolean
|
|
81
|
-
};
|
|
82
|
-
type Shims = boolean | ShimOptions;
|
|
83
101
|
type DtsResolve = boolean | (string | RegExp)[];
|
|
84
102
|
type DtsOptions = {
|
|
85
103
|
/**
|
|
@@ -296,24 +314,6 @@ interface BuildOptions {
|
|
|
296
314
|
*/
|
|
297
315
|
publicPath?: string;
|
|
298
316
|
/**
|
|
299
|
-
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
300
|
-
*
|
|
301
|
-
* When set to true, automatically injects all shims when needed
|
|
302
|
-
* When set to an object, only injects the specified shims
|
|
303
|
-
*
|
|
304
|
-
* Available shims:
|
|
305
|
-
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
306
|
-
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* // Enable all shims
|
|
310
|
-
* shims: true
|
|
311
|
-
*
|
|
312
|
-
* // Enable only specific shims
|
|
313
|
-
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
314
|
-
*/
|
|
315
|
-
shims?: Shims;
|
|
316
|
-
/**
|
|
317
317
|
* Controls how environment variables are handled during bundling.
|
|
318
318
|
*
|
|
319
319
|
* Can be one of:
|