bunup 0.6.0 → 0.6.2
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 +30 -41
- package/dist/index.cjs +2 -13
- package/dist/index.d.cts +18 -29
- package/dist/index.d.ts +18 -29
- package/dist/index.js +2 -13
- package/dist/plugins.cjs +13 -1
- package/dist/plugins.d.cts +27 -30
- package/dist/plugins.d.ts +27 -30
- 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 **~
|
|
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
|
-
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var It,de;var Ze=P(()=>{M();It=/\.(js|ts|jsx|tsx|mts|cts)$/,de={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&ce(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
8
|
-
import { dirname } from 'path';
|
|
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(`
|
|
3
|
+
var lt=Object.create;var{getPrototypeOf:dt,defineProperty:ie,getOwnPropertyNames:pt}=Object;var mt=Object.prototype.hasOwnProperty;var A=(e,t,n)=>{n=e!=null?lt(dt(e)):{};let r=t||!e||!e.__esModule?ie(n,"default",{value:e,enumerable:!0}):n;for(let i of pt(e))if(!mt.call(r,i))ie(r,i,{get:()=>e[i],enumerable:!0});return r};var gt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xe=(e,t)=>{for(var n in t)ie(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(r)=>t[n]=()=>r})};var E=(e,t)=>()=>(e&&(t=e(e=0)),t);var ft=import.meta.require;var I=gt((Zt,se)=>{var K=process||{},ye=K.argv||[],U=K.env||{},ht=!(!!U.NO_COLOR||ye.includes("--no-color"))&&(!!U.FORCE_COLOR||ye.includes("--color")||K.platform==="win32"||(K.stdout||{}).isTTY&&U.TERM!=="dumb"||!!U.CI),xt=(e,t,n=e)=>(r)=>{let i=""+r,s=i.indexOf(t,e.length);return~s?e+yt(i,t,n,s)+t:e+i+t},yt=(e,t,n,r)=>{let i="",s=0;do i+=e.substring(s,r)+n,s=r+t.length,r=e.indexOf(t,s);while(~r);return i+e.substring(s)},we=(e=ht)=>{let t=e?xt:()=>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")}};se.exports=we();se.exports.createColors=we});function X(e){Ce=e??!1}class T{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=l.default.blue;mutedColor=l.default.dim;infoColor=l.default.cyan;warnColor=l.default.yellow;errorColor=l.default.red;defaultColor=l.default.white;progressFgColorMap={ESM:l.default.yellow,CJS:l.default.green,IIFE:l.default.magenta,DTS:l.default.blue};progressIdentifierBgColorMap={ESM:l.default.bgYellow,CJS:l.default.bgGreen,IIFE:l.default.bgMagenta,DTS:l.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:n,message:r,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?this.mutedColor(r):r,m=i?` ${t(l.default.black(` ${i} `))}`:"";return`${e(n)} ${o}${a}${m}`}output(e,t={},n=console.log){if(Ce||!this.shouldLog(t))return;if(t.verticalSpace)n("");if(n(e),t.verticalSpace)n("")}cli(e,t={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:l.default.bgBlue,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:l.default.bgCyan,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:l.default.bgYellow,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({fgColor:this.errorColor,bgColor:l.default.bgRed,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}getProgressFgColor(e){for(let[t,n]of Object.entries(this.progressFgColorMap))if(e.includes(t))return n;return this.defaultColor}getProgressBgColor(e){for(let[t,n]of Object.entries(this.progressIdentifierBgColorMap))if(e.includes(t))return n;return l.default.bgWhite}progress(e,t,n={}){let r=this.getProgressFgColor(e),i=this.getProgressBgColor(e),s=this.formatMessage({fgColor:r,bgColor:i,label:e,message:t,identifier:n.identifier,muted:n.muted});this.output(s,n)}}var l,Ce=!1,d;var W=E(()=>{l=A(I(),1);d=T.getInstance()});var x,L,G,Be,O,v,oe=(e)=>{if(e instanceof Error)return e.message;return String(e)},wt,ae=(e,t)=>{let n=oe(e),r=t?`[${t}] `:"",i="";if(e instanceof G)i="BUILD ERROR";else if(e instanceof Be)i="DTS ERROR";else if(e instanceof O)i="CLI ERROR";else if(e instanceof v)i="WATCH ERROR";else if(e instanceof L)i="BUNUP ERROR";let s=wt.find((o)=>o.pattern.test(n)&&(o.errorType===i||!o.errorType));if(!s&&i)console.error(`${x.default.red(i)} ${r}${n}`);if(s)console.log(`
|
|
4
|
+
`),s.logSolution(n),console.log(`
|
|
5
|
+
`);else console.error(x.default.dim(x.default.white("If you think this is a bug, please open an issue at: ")+x.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$e=(e,t)=>{ae(e,t),process.exit(1)};var z=E(()=>{x=A(I(),1);W();L=class L extends Error{constructor(e){super(e);this.name="BunupError"}};G=class G extends L{constructor(e){super(e);this.name="BunupBuildError"}};Be=class Be extends L{constructor(e){super(e);this.name="BunupDTSBuildError"}};O=class O extends L{constructor(e){super(e);this.name="BunupCLIError"}};v=class v extends L{constructor(e){super(e);this.name="BunupWatchError"}};wt=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{d.error(x.default.white("You're trying to build a project that uses Bun. ")+x.default.white("Please set the target option to ")+x.default.cyan("`bun`")+x.default.white(`.
|
|
6
|
+
`)+x.default.white("Example: ")+x.default.green("`bunup --target bun`")+x.default.white(" or in config: ")+x.default.green("{ target: 'bun' }"))}}]});import{basename as Ct,extname as Bt}from"path";function Ee(e){let t=Ct(e),n=Bt(t);return n?t.slice(0,-n.length):t}function Q(e){let t=typeof e.dts==="object"&&"entry"in e.dts?e.dts.entry:void 0,n=[];if(typeof e.entry==="string")n=[{path:e.entry,outputBasePath:null,dts:!1}];else if(typeof e.entry==="object"&&!Array.isArray(e.entry))n=Object.entries(e.entry).map(([r,i])=>({path:i,outputBasePath:r,dts:!1}));else n=e.entry.map((r)=>({path:r,outputBasePath:null,dts:!1}));if(typeof e.dts!=="undefined"&&!t)n=n.map((r)=>({...r,dts:!0}));else if(t){let r=[];if(typeof t==="string")r=[{path:t,outputBasePath:null,dts:!0}];else if(typeof t==="object"&&!Array.isArray(t))r=Object.entries(t).map(([s,o])=>({path:o,outputBasePath:s,dts:!0}));else r=t.map((s)=>({path:s,outputBasePath:null,dts:!0}));let i=new Set;n=n.map((s)=>{let o=r.some((a)=>a.path===s.path&&a.outputBasePath===s.outputBasePath);if(o)i.add(`${s.path}:${s.outputBasePath}`);return{...s,dts:o}});for(let s of r)if(!i.has(`${s.path}:${s.outputBasePath}`))n.push(s)}return n}function Oe(e,t){return{entry:`[dir]/${e||"[name]"}${t}`,chunk:`${e||"[name]"}-[hash].[ext]`,asset:`${e?`${e}-`:""}[name]-[hash].[ext]`}}var Z=()=>{};import Se from"fs/promises";import Ot from"path";function Re(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function Fe(e){return Array.isArray(e)?e:[e]}function Ae(e,t){switch(e){case"esm":return Me(t)?".js":".mjs";case"cjs":return Me(t)?".cjs":".js";case"iife":return".global.js"}}function Me(e){return e==="module"}function ee(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function Ie(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function te(e,t=3){return e.split("/").slice(-t).join("/")}async function De(e,t){let n=Ot.join(e,t);try{await Se.rm(n,{recursive:!0,force:!0})}catch(r){throw new G(`Failed to clean output directory: ${r}`)}await Se.mkdir(n,{recursive:!0})}var Y=E(()=>{z()});import Pt from"path";import{loadConfig as jt}from"coffi";async function Te(e,t,n){return Array.isArray(e)&&"root"in e[0]?e.filter((r)=>n?n.includes(r.name):!0).map((r)=>({rootDir:Pt.resolve(t,r.root),options:Re(r.config,"name",r.name)})):[{rootDir:t,options:e}]}async function We(e){let{config:t,filepath:n}=await jt({name:"package",cwd:e,extensions:[".json"]});return{packageJson:t,path:n}}var ue=E(()=>{Y()});function ne(e){return{...St,...e}}function Le(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,s=t===!0;return{whitespace:n??s,identifiers:r??s,syntax:i??s}}function Ge(e,t){return t==="cjs"?e:void 0}function ze(e){if(e===!0)return"inline";return typeof e==="string"?e:void 0}function Ye(e,t){return{...typeof t==="object"&&Object.keys(t).reduce((n,r)=>{let i=JSON.stringify(t[r]);return n[`process.env.${r}`]=i,n[`import.meta.env.${r}`]=i,n},{}),...e}}function Je(e,t){return e===void 0?t==="esm":e}function qe(e){return typeof e==="string"?e:void 0}var St;var le=E(()=>{St={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function Mt(e){return Ie(e).map((t)=>new RegExp(`^${t}($|\\/|\\\\)`))}function Ve(e,t){return typeof t==="string"?t===e:t.test(e)}function _e(e,t,n){let i=Mt(n).some((o)=>o.test(e))||t.external?.some((o)=>Ve(e,o)),s=t.noExternal?.some((o)=>Ve(e,o));return i&&!s}var Ue=E(()=>{Y()});function Ke(e,t){return{name:"bunup:external-option-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(_e(i,e,t))return{path:i,external:!0};return null})}}}var Xe=E(()=>{Ue()});function ve(e){if(!e)return[];return e.filter((t)=>t.type==="bun")}function Qe(e){if(!e)return[];return e.filter((t)=>t.type==="bunup")}async function Ze(e,t){if(!e)return;for(let n of e)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(t)}async function Ne(e,t,n){if(!e)return;for(let r of e)if(r.hooks.onBuildDone)await r.hooks.onBuildDone({options:t,output:n})}var et={};xe(et,{build:()=>de});import{dts as Ft}from"bun-dts";async function de(e,t=process.cwd()){let n={files:[]},r=ne(e);if(!r.entry||r.entry.length===0||!r.outDir)throw new G("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)De(t,r.outDir);X(r.silent);let{packageJson:i,path:s}=await We(t);if(i&&s)d.cli(`Using ${te(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=Qe(r.plugins);await Ze(o,r);let a=Q(r),m=i?.type,g=[Ke(r,i),...ve(r.plugins).map((f)=>f.plugin)],c=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,y=r.format.flatMap((f)=>a.map(async($)=>{let F=r.outputExtension?.({format:f,packageType:m,options:r,entry:$.path}).js??Ae(f,m),V=await Bun.build({entrypoints:[`${t}/${$.path}`],format:f,naming:Oe($.outputBasePath,F),splitting:Je(r.splitting,f),bytecode:Ge(r.bytecode,f),define:Ye(r.define,r.env),minify:Le(r),outdir:`${t}/${r.outDir}`,target:r.target,sourcemap:ze(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:qe(r.env),plugins:[...g,...$.dts?[Ft({cwd:t,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:c,onDeclarationGenerated:(b)=>{let u=He(b,t);n.files.push({fullPath:b,relativePathToRootDir:u}),d.progress("DTS",u,{identifier:r.name})}})]:[]],throw:!1});for(let b of V.logs){if(b.level==="error")throw console.log(`
|
|
18
7
|
`),console.log(b),console.log(`
|
|
19
|
-
`),new Error;if(b.level==="warning")
|
|
8
|
+
`),new Error;if(b.level==="warning")d.warn(b.message);else if(b.level==="info")d.info(b.message)}for(let b of V.outputs){let u=He(b.path,t);if(b.kind==="entry-point")d.progress(f.toUpperCase(),u,{identifier:r.name});n.files.push({fullPath:b.path,relativePathToRootDir:u})}}));if(await Promise.all(y),await Ne(o,r,n),r.onSuccess)await r.onSuccess(r)}function He(e,t){return e.replace(`${t}/`,"")}var pe=E(()=>{z();Z();ue();W();le();Xe();Y()});var ot={};xe(ot,{init:()=>Gt});import j from"fs/promises";import R from"path";import{cancel as S,confirm as M,intro as At,isCancel as h,log as B,multiselect as rt,outro as It,tasks as Dt,text as q}from"@clack/prompts";import{loadConfig as fe}from"coffi";import{detect as Tt,resolveCommand as me}from"package-manager-detector";import{exec as Wt}from"tinyexec";async function it(e){try{return await j.access(e),!0}catch{return!1}}async function Lt(){let{config:e,filepath:t}=await fe({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,packageJsonProperty:"bunup"});return{exists:!!e,filepath:t||void 0}}async function Gt(){At(p.default.bgCyan(p.default.black(" Bunup ")));let{exists:e,filepath:t}=await Lt();if(e){let u=await M({message:`A bunup configuration already exists at ${p.default.cyan(t||"bunup.config.ts")}. Continue and overwrite it?`,initialValue:!1});if(h(u)||!u)S("Initialization cancelled"),process.exit(1)}let n=await Tt();if(!n)B.error("No package manager detected"),process.exit(1);let{config:r,filepath:i}=await fe({name:"package",cwd:process.cwd(),extensions:[".json"]});if(!r||!i)B.error("Cannot find package.json."),process.exit(1);let s=await q({message:"Entry point for your library:",placeholder:"src/index.ts",defaultValue:"src/index.ts"});if(h(s))S("Initialization cancelled"),process.exit(1);let o=R.join(process.cwd(),String(s));if(!await it(o)){let u=await M({message:`Entry file ${p.default.cyan(String(s))} does not exist. Create it?`,initialValue:!0});if(h(u))S("Initialization cancelled"),process.exit(1);if(u)await j.mkdir(R.dirname(o),{recursive:!0}),await j.writeFile(o,`// Your entry point
|
|
20
9
|
|
|
21
10
|
export function hello() {
|
|
22
|
-
return 'Hello from ${
|
|
11
|
+
return 'Hello from ${R.basename(String(s))}';
|
|
23
12
|
}
|
|
24
|
-
`),
|
|
13
|
+
`),B.success(`Created ${s}`)}let a=await rt({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(h(a))S("Initialization cancelled"),process.exit(1);let m=await q({message:"Output directory:",placeholder:"dist",initialValue:"dist",validate:(u)=>u?void 0:"Output directory is required"});if(h(m))S("Initialization cancelled"),process.exit(1);let g=await M({message:"Generate TypeScript declarations (.d.ts files)?",initialValue:!0});if(h(g))S("Initialization cancelled"),process.exit(1);let c=!1,y=[];if(r.workspaces){let u=await M({message:"Detected workspaces. Set up Bunup for multiple packages?",initialValue:!0});if(h(u))S("Initialization cancelled"),process.exit(1);if(c=u,c){let ut=async()=>{let k=await q({message:"Workspace name:",placeholder:"core",validate:(w)=>w?void 0:"Workspace name is required"});if(h(k))return null;let J=await q({message:"Workspace root directory:",placeholder:"packages/core",validate:(w)=>w?void 0:"Workspace root is required"});if(h(J))return null;let D=await q({message:"Workspace entry points (comma-separated):",placeholder:"src/index.ts",validate:(w)=>w?void 0:"At least one entry point is required"});if(h(D))return null;return{name:String(k),root:String(J),entries:String(D).split(",").map((w)=>w.trim())}},be=!0;while(be){let k=await ut();if(!k)break;y.push(k);for(let D of k.entries){let w=R.join(process.cwd(),k.root,D);if(!await it(w)){let he=await M({message:`Entry file ${p.default.cyan(`${k.root}/${D}`)} does not exist. Create it?`,initialValue:!0});if(h(he))break;if(he)await j.mkdir(R.dirname(w),{recursive:!0}),await j.writeFile(w,`// Your entry point
|
|
25
14
|
|
|
26
15
|
export function hello() {
|
|
27
|
-
return 'Hello from ${
|
|
16
|
+
return 'Hello from ${k.name}';
|
|
28
17
|
}
|
|
29
|
-
`),
|
|
30
|
-
${
|
|
18
|
+
`),B.success(`Created ${k.root}/${D}`)}}let J=await M({message:"Add another workspace?",initialValue:!1});if(h(J))break;be=J}}}let f=[{value:"report",label:"Report",hint:"Logs bundle size report after build",configGenerator:()=>"report()",defaultEnabled:!0}],$=await rt({message:"Select plugins to use (optional):",options:f,required:!1,initialValues:f.filter((u)=>u.defaultEnabled).map((u)=>u.value)});if(h($))S("Initialization cancelled"),process.exit(1);if(c&&y.length>0)await Yt(y,a,String(m),g,$,f,t||void 0);else await zt(String(s),a,String(m),g,$,f,t||void 0);await Vt(),B.success("Configuration generated"),await Jt(r,i),B.success("package.json updated");let F=[{title:"Installing bunup",task:async()=>{return await qt(r,n),"Bunup installed"}}];try{await Dt(F)}catch(u){B.error(`Error: ${u instanceof Error?u.message:String(u)}`),process.exit(1)}let V=me(n.agent,"run",["dev"]),b=me(n.agent,"run",["build"]);It(`
|
|
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(ge(b))} - ${p.default.gray("Build your project")}
|
|
23
|
+
${p.default.cyan(ge(V))} - ${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 zt(e,t,n,r,i,s,o=R.join(process.cwd(),"bunup.config.ts")){let a=st(i,s),m=`import { defineConfig } from 'bunup';
|
|
27
|
+
${i.length>0?`import { ${i.join(", ")} } from 'bunup/plugins';
|
|
39
28
|
`:""}
|
|
40
29
|
export default defineConfig({
|
|
41
30
|
entry: '${e}',
|
|
42
|
-
format: [${t.map((
|
|
43
|
-
outDir: '${n}',${
|
|
31
|
+
format: [${t.map((g)=>`'${g}'`).join(", ")}],
|
|
32
|
+
outDir: '${n}',${r?`
|
|
44
33
|
dts: true,`:""}${a?`
|
|
45
34
|
plugins: [${a}],`:""}
|
|
46
35
|
});
|
|
47
|
-
`;await
|
|
48
|
-
name: '${
|
|
49
|
-
root: '${
|
|
36
|
+
`;await j.writeFile(o,m)}async function Yt(e,t,n,r,i,s,o=R.join(process.cwd(),"bunup.config.ts")){let a=st(i,s),m=e.map((c)=>{let y=c.entries.length===1?`'${c.entries[0]}'`:`[${c.entries.map((f)=>`'${f}'`).join(", ")}]`;return` {
|
|
37
|
+
name: '${c.name}',
|
|
38
|
+
root: '${c.root}',
|
|
50
39
|
config: {
|
|
51
|
-
entry: ${
|
|
52
|
-
format: [${t.map((
|
|
53
|
-
outDir: '${n}',${
|
|
40
|
+
entry: ${y},
|
|
41
|
+
format: [${t.map((f)=>`'${f}'`).join(", ")}],
|
|
42
|
+
outDir: '${n}',${r?`
|
|
54
43
|
dts: true,`:""}${a?`
|
|
55
44
|
plugins: [${a}],`:""}
|
|
56
45
|
},
|
|
57
46
|
}`}).join(`,
|
|
58
|
-
`),
|
|
59
|
-
${
|
|
47
|
+
`),g=`import { defineWorkspace } from 'bunup';
|
|
48
|
+
${i.length>0?`import { ${i.join(", ")} } from 'bunup/plugins';
|
|
60
49
|
`:""}
|
|
61
50
|
export default defineWorkspace([
|
|
62
|
-
${
|
|
51
|
+
${m}
|
|
63
52
|
]);
|
|
64
|
-
`;await
|
|
65
|
-
`);return}let
|
|
53
|
+
`;await j.writeFile(o,g)}function st(e,t){return t.filter((n)=>e.includes(n.value)).map((n)=>n.configGenerator?n.configGenerator():`${n.value}()`).join(", ")}async function Jt(e,t){let n=e.scripts||{},r=!1;for(let[i,s]of[["build","bunup"],["dev","bunup --watch"]])if(!n[i]||await M({message:`Script '${i}' exists. Replace with '${s}'?`,initialValue:!0}))n[i]=s,r=!0;if(r)e.scripts=n,await j.writeFile(t,JSON.stringify(e,null,2))}async function qt(e,t){if(e.dependencies?.bunup||e.devDependencies?.bunup){B.info(`Bunup is already installed
|
|
54
|
+
`);return}let r={bun:"-d",npm:"-D",pnpm:"-D",yarn:"-D"},i=me(t.agent,"add",[r[t.agent]||"-D","bunup"]);if(!i)throw new Error("Failed to resolve install command");await Wt(ge(i),[],{nodeOptions:{shell:!0,stdio:"pipe"}})}function ge(e){if(!e)return"";return`${e.command} ${e.args.join(" ")}`}async function Vt(){let e={},t=!1,n=R.join(process.cwd(),"tsconfig.json");try{let{config:i,filepath:s}=await fe({name:"tsconfig",cwd:process.cwd(),extensions:[".json"]});if(i&&s)e=i,t=!0,n=s}catch{}if(e.compilerOptions?.isolatedDeclarations!==!0){B.info(`${p.default.cyan("About isolatedDeclarations:")} ${p.default.gray(`A ${p.default.bold("modern TypeScript feature")} for library authors`)}`),B.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 i=await M({message:"Enable isolatedDeclarations in tsconfig.json? (recommended but optional)",initialValue:!0});if(h(i))return;if(i){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 j.writeFile(n,JSON.stringify(e,null,2)),B.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 j.writeFile(n,JSON.stringify(e,null,2))}}var p;var at=E(()=>{p=A(I(),1)});import{exec as _t}from"tinyexec";var _="0.6.2";z();W();var ce=A(I(),1);var ke="https://bunup.dev/docs/guide/cli-options";z();Z();W();function C(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function P(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new O(`Option --${e} requires a string value`)}}function N(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new O(`Option --${e} requires a string value`)}}function $t(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new O(`Option --${e} requires a boolean or string value`)}}function kt(){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
|
|
56
|
+
`),console.log("For more information on available options, visit:"),console.log(`${ce.default.cyan(ce.default.underline(ke))}
|
|
57
|
+
`),process.exit(0)}function Et(){console.log(_),process.exit(0)}var Pe={name:{flags:["n","name"],handler:P("name")},format:{flags:["f","format"],handler:N("format")},outDir:{flags:["o","out-dir"],handler:P("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:P("banner")},footer:{flags:["ft","footer"],handler:P("footer")},external:{flags:["e","external"],handler:N("external")},sourcemap:{flags:["sm","sourcemap"],handler:$t("sourcemap")},target:{flags:["t","target"],handler:P("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:N("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:P("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:C("bytecode")},silent:{flags:["silent"],handler:C("silent")},config:{flags:["config"],handler:P("config")},publicPath:{flags:["pp","public-path"],handler:P("publicPath")},env:{flags:["env"],handler:P("env")},onSuccess:{flags:["onSuccess"],handler:P("onSuccess")},filter:{flags:["filter"],handler:N("filter")},init:{flags:["init"],handler:C("init")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new O(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])d.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let i=Ee(e);if(r[i])d.warn(`Duplicate entry name '${i}' derived from '${e}'. Overwriting previous entry.`);r[i]=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:()=>kt()},version:{flags:["v","version"],handler:()=>Et()}},H={};for(let e of Object.values(Pe))for(let t of e.flags)H[t]=e.handler;function je(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let i,s;if(r.includes("=")){let[o,a]=r.slice(2).split("=",2);i=o,s=a}else{i=r.slice(2);let o=e[n+1];if(s=o&&!o.startsWith("-")?o:!0,typeof s==="string")n++}if(i.includes(".")){let[o,a]=i.split(".",2),m=H[o];if(m)m(s,t,a);else throw new O(`Unknown option: --${i}`)}else{let o=H[i];if(o)o(s,t);else throw new O(`Unknown option: --${i}`)}}else if(r.startsWith("-")){let i=r.slice(1),s=e[n+1],o=s&&!s.startsWith("-")?s:!0;if(typeof o==="string")n++;let a=H[i];if(a)a(o,t);else throw new O(`Unknown option: -${i}`)}else Pe.entry.handler(r,t,void 0)}return t}var ct=A(I(),1);ue();Y();import{loadConfig as Ut}from"coffi";var tt=A(I(),1);pe();z();Z();W();le();Y();import re from"path";async function nt(e,t){let n=new Set,r=ne(e),i=Q(r);for(let g of i){let c=re.resolve(t,g.path),y=re.dirname(c);n.add(y)}let o=(await import("chokidar")).watch(Array.from(n),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,re.join(t,r.outDir)]}),a=!1,m=async(g=!1)=>{if(a)return;a=!0;try{let c=performance.now();if(await de(r,t),!g)d.cli(`\uD83D\uDCE6 Rebuild finished in ${tt.default.green(ee(performance.now()-c))}`)}catch(c){ae(c)}finally{a=!1}};o.on("change",(g)=>{let c=re.relative(t,g);d.cli(`File changed: ${c}`,{muted:!0,once:c}),m()}),o.on("error",(g)=>{throw new v(`Watcher error: ${oe(g)}`)}),await m(!0)}async function Kt(e=Bun.argv.slice(2)){let t=je(e);if(t.init){let{init:c}=await Promise.resolve().then(() => (at(),ot));await c();return}X(t.silent);let n=process.cwd(),{config:r,filepath:i}=await Ut({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config,packageJsonProperty:"bunup"}),s=!r?[{rootDir:n,options:t}]:await Te(r,n,t.filter);if(d.cli(`Using bunup v${_} and bun v${Bun.version}`,{muted:!0}),i)d.cli(`Using ${te(i,2)}`,{muted:!0});let o=performance.now();d.cli("Build started");let{build:a}=await Promise.resolve().then(() => (pe(),et));await Promise.all(s.flatMap(({options:c,rootDir:y})=>{return Fe(c).map(async($)=>{let F={...$,...Xt(t)};if(F.watch)await nt(F,y);else await a(F,y)})}));let m=performance.now()-o,g=ee(m);if(d.cli(`\u26A1\uFE0F Build completed in ${ct.default.green(g)}`),t.watch)d.cli("\uD83D\uDC40 Watching for file changes");if(t.onSuccess)d.cli(`Running command: ${t.onSuccess}`,{muted:!0}),await _t(t.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!t.watch)process.exit(process.exitCode??0)}function Xt(e){return{...e,onSuccess:void 0,config:void 0,filter:void 0,init:void 0}}Kt().catch((e)=>$e(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
|
-
import { dirname } from 'path';
|
|
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(`
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var ce=Object.create;var{getPrototypeOf:de,defineProperty:p,getOwnPropertyNames:M,getOwnPropertyDescriptor:pe}=Object,k=Object.prototype.hasOwnProperty;var h=(r,e,n)=>{n=r!=null?ce(de(r)):{};let t=e||!r||!r.__esModule?p(n,"default",{value:r,enumerable:!0}):n;for(let s of M(r))if(!k.call(t,s))p(t,s,{get:()=>r[s],enumerable:!0});return t},P=new WeakMap,fe=(r)=>{var e=P.get(r),n;if(e)return e;if(e=p({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")M(r).map((t)=>!k.call(e,t)&&p(e,t,{get:()=>r[t],enumerable:!(n=pe(r,t))||n.enumerable}));return P.set(r,e),e},be=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var xe=(r,e)=>{for(var n in e)p(r,n,{get:e[n],enumerable:!0,configurable:!0,set:(t)=>e[n]=()=>t})};var w=be((ke,C)=>{var y=process||{},$=y.argv||[],B=y.env||{},he=!(!!B.NO_COLOR||$.includes("--no-color"))&&(!!B.FORCE_COLOR||$.includes("--color")||y.platform==="win32"||(y.stdout||{}).isTTY&&B.TERM!=="dumb"||!!B.CI),Be=(r,e,n=r)=>(t)=>{let s=""+t,o=s.indexOf(e,r.length);return~o?r+ye(s,e,n,o)+e:r+s+e},ye=(r,e,n,t)=>{let s="",o=0;do s+=r.substring(o,t)+n,o=t+e.length,t=r.indexOf(e,o);while(~t);return s+r.substring(o)},L=(r=he)=>{let e=r?Be:()=>String;return{isColorSupported:r,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")}};C.exports=L();C.exports.createColors=L});var Oe={};xe(Oe,{defineWorkspace:()=>S,defineConfig:()=>R,build:()=>ae});module.exports=fe(Oe);function R(r){return r}function S(r){return r}var ie=require("bun-dts");var Ce=h(w());var i=h(w()),I=!1;function A(r){I=r??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=i.default.blue;mutedColor=i.default.dim;infoColor=i.default.cyan;warnColor=i.default.yellow;errorColor=i.default.red;defaultColor=i.default.white;progressFgColorMap={ESM:i.default.yellow,CJS:i.default.green,IIFE:i.default.magenta,DTS:i.default.blue};progressIdentifierBgColorMap={ESM:i.default.bgYellow,CJS:i.default.bgGreen,IIFE:i.default.bgMagenta,DTS:i.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(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:e,label:n,message:t,identifier:s,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),m=o?this.mutedColor(t):t,b=s?` ${e(i.default.black(` ${s} `))}`:"";return`${r(n)} ${a}${m}${b}`}output(r,e={},n=console.log){if(I||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(r),e.verticalSpace)n("")}cli(r,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:i.default.bgBlue,label:this.labels.cli,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(r,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:i.default.bgCyan,label:this.labels.info,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(r,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:i.default.bgYellow,label:this.labels.warn,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(r,e={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:i.default.bgRed,label:this.labels.error,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(r){for(let[e,n]of Object.entries(this.progressFgColorMap))if(r.includes(e))return n;return this.defaultColor}getProgressBgColor(r){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(r.includes(e))return n;return i.default.bgWhite}progress(r,e,n={}){let t=this.getProgressFgColor(r),s=this.getProgressBgColor(r),o=this.formatMessage({fgColor:t,bgColor:s,label:r,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var l=c.getInstance();class F extends Error{constructor(r){super(r);this.name="BunupError"}}class f extends F{constructor(r){super(r);this.name="BunupBuildError"}}function j(r){let e=typeof r.dts==="object"&&"entry"in r.dts?r.dts.entry:void 0,n=[];if(typeof r.entry==="string")n=[{path:r.entry,outputBasePath:null,dts:!1}];else if(typeof r.entry==="object"&&!Array.isArray(r.entry))n=Object.entries(r.entry).map(([t,s])=>({path:s,outputBasePath:t,dts:!1}));else n=r.entry.map((t)=>({path:t,outputBasePath:null,dts:!1}));if(typeof r.dts!=="undefined"&&!e)n=n.map((t)=>({...t,dts:!0}));else if(e){let t=[];if(typeof e==="string")t=[{path:e,outputBasePath:null,dts:!0}];else if(typeof e==="object"&&!Array.isArray(e))t=Object.entries(e).map(([o,a])=>({path:a,outputBasePath:o,dts:!0}));else t=e.map((o)=>({path:o,outputBasePath:null,dts:!0}));let s=new Set;n=n.map((o)=>{let a=t.some((m)=>m.path===o.path&&m.outputBasePath===o.outputBasePath);if(a)s.add(`${o.path}:${o.outputBasePath}`);return{...o,dts:a}});for(let o of t)if(!s.has(`${o.path}:${o.outputBasePath}`))n.push(o)}return n}function T(r,e){return{entry:`[dir]/${r||"[name]"}${e}`,chunk:`${r||"[name]"}-[hash].[ext]`,asset:`${r?`${r}-`:""}[name]-[hash].[ext]`}}var _=require("coffi");var E=h(require("fs/promises")),W=h(require("path"));function N(r,e){switch(r){case"esm":return v(e)?".js":".mjs";case"cjs":return v(e)?".cjs":".js";case"iife":return".global.js"}}function v(r){return r==="module"}function D(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function G(r,e=3){return r.split("/").slice(-e).join("/")}async function Y(r,e){let n=W.default.join(r,e);try{await E.default.rm(n,{recursive:!0,force:!0})}catch(t){throw new f(`Failed to clean output directory: ${t}`)}await E.default.mkdir(n,{recursive:!0})}async function K(r){let{config:e,filepath:n}=await _.loadConfig({name:"package",cwd:r,extensions:[".json"]});return{packageJson:e,path:n}}var we={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function H(r){return{...we,...r}}function U(r){let{minify:e,minifyWhitespace:n,minifyIdentifiers:t,minifySyntax:s}=r,o=e===!0;return{whitespace:n??o,identifiers:t??o,syntax:s??o}}function X(r,e){return e==="cjs"?r:void 0}function z(r){if(r===!0)return"inline";return typeof r==="string"?r:void 0}function q(r,e){return{...typeof e==="object"&&Object.keys(e).reduce((n,t)=>{let s=JSON.stringify(e[t]);return n[`process.env.${t}`]=s,n[`import.meta.env.${t}`]=s,n},{}),...r}}function J(r,e){return r===void 0?e==="esm":r}function Q(r){return typeof r==="string"?r:void 0}function Ee(r){return D(r).map((e)=>new RegExp(`^${e}($|\\/|\\\\)`))}function Z(r,e){return typeof e==="string"?e===r:e.test(r)}function V(r,e,n){let s=Ee(n).some((a)=>a.test(r))||e.external?.some((a)=>Z(r,a)),o=e.noExternal?.some((a)=>Z(r,a));return s&&!o}function ee(r,e){return{name:"bunup:external-option-plugin",setup(n){n.onResolve({filter:/.*/},(t)=>{let s=t.path;if(V(s,r,e))return{path:s,external:!0};return null})}}}function re(r){if(!r)return[];return r.filter((e)=>e.type==="bun")}function te(r){if(!r)return[];return r.filter((e)=>e.type==="bunup")}async function ne(r,e){if(!r)return;for(let n of r)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function oe(r,e,n){if(!r)return;for(let t of r)if(t.hooks.onBuildDone)await t.hooks.onBuildDone({options:e,output:n})}async function ae(r,e=process.cwd()){let n={files:[]},t=H(r);if(!t.entry||t.entry.length===0||!t.outDir)throw new f("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)Y(e,t.outDir);A(t.silent);let{packageJson:s,path:o}=await K(e);if(s&&o)l.cli(`Using ${G(o,2)}`,{muted:!0,identifier:t.name,once:`${o}:${t.name}`});let a=te(t.plugins);await ne(a,t);let m=j(t),b=s?.type,ue=[ee(t,s),...re(t.plugins).map((g)=>g.plugin)],ge=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0,le=t.format.flatMap((g)=>m.map(async(x)=>{let me=t.outputExtension?.({format:g,packageType:b,options:t,entry:x.path}).js??N(g,b),O=await Bun.build({entrypoints:[`${e}/${x.path}`],format:g,naming:T(x.outputBasePath,me),splitting:J(t.splitting,g),bytecode:X(t.bytecode,g),define:q(t.define,t.env),minify:U(t),outdir:`${e}/${t.outDir}`,target:t.target,sourcemap:z(t.sourcemap),loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:Q(t.env),plugins:[...ue,...x.dts?[ie.dts({cwd:e,preferredTsConfigPath:t.preferredTsconfigPath,warnInsteadOfError:t.watch,resolve:ge,onDeclarationGenerated:(u)=>{let d=se(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),l.progress("DTS",d,{identifier:t.name})}})]:[]],throw:!1});for(let u of O.logs){if(u.level==="error")throw console.log(`
|
|
14
3
|
`),console.log(u),console.log(`
|
|
15
|
-
`),new Error;if(u.level==="warning")
|
|
4
|
+
`),new Error;if(u.level==="warning")l.warn(u.message);else if(u.level==="info")l.info(u.message)}for(let u of O.outputs){let d=se(u.path,e);if(u.kind==="entry-point")l.progress(g.toUpperCase(),d,{identifier:t.name});n.files.push({fullPath:u.path,relativePathToRootDir:d})}}));if(await Promise.all(le),await oe(a,t,n),t.onSuccess)await t.onSuccess(t)}function se(r,e){return r.replace(`${e}/`,"")}})
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
4
|
+
*/
|
|
2
5
|
type BunupBunPlugin = {
|
|
3
6
|
/** Identifies this as a native Bun plugin */
|
|
4
7
|
type: "bun"
|
|
@@ -7,6 +10,9 @@ type BunupBunPlugin = {
|
|
|
7
10
|
/** The actual Bun plugin implementation */
|
|
8
11
|
plugin: BunPlugin
|
|
9
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the output of a build operation
|
|
15
|
+
*/
|
|
10
16
|
type BuildOutput = {
|
|
11
17
|
/** Array of generated files with their paths and contents */
|
|
12
18
|
files: Array<{
|
|
@@ -16,12 +22,18 @@ type BuildOutput = {
|
|
|
16
22
|
relativePathToRootDir: string
|
|
17
23
|
}>
|
|
18
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Context provided to build hooks
|
|
27
|
+
*/
|
|
19
28
|
type BuildContext = {
|
|
20
29
|
/** The build options that were used */
|
|
21
30
|
options: BuildOptions
|
|
22
31
|
/** The output of the build */
|
|
23
32
|
output: BuildOutput
|
|
24
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Hooks that can be implemented by Bunup plugins
|
|
36
|
+
*/
|
|
25
37
|
type BunupPluginHooks = {
|
|
26
38
|
/**
|
|
27
39
|
* Called when a build is successfully completed
|
|
@@ -34,6 +46,9 @@ type BunupPluginHooks = {
|
|
|
34
46
|
*/
|
|
35
47
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
36
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Represents a Bunup-specific plugin
|
|
51
|
+
*/
|
|
37
52
|
type BunupPlugin = {
|
|
38
53
|
/** Identifies this as a Bunup-specific plugin */
|
|
39
54
|
type: "bunup"
|
|
@@ -42,6 +57,9 @@ type BunupPlugin = {
|
|
|
42
57
|
/** The hooks implemented by this plugin */
|
|
43
58
|
hooks: BunupPluginHooks
|
|
44
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Union type representing all supported plugin types
|
|
62
|
+
*/
|
|
45
63
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
46
64
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
47
65
|
type Define = BunBuildOptions["define"];
|
|
@@ -51,17 +69,6 @@ type Target = BunBuildOptions["target"];
|
|
|
51
69
|
type External = (string | RegExp)[];
|
|
52
70
|
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
53
71
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
54
|
-
type ShimOptions = {
|
|
55
|
-
/**
|
|
56
|
-
* Adds __dirname and __filename shims for ESM files when used
|
|
57
|
-
*/
|
|
58
|
-
dirnameFilename?: boolean
|
|
59
|
-
/**
|
|
60
|
-
* Adds import.meta.url shims for CJS files when used
|
|
61
|
-
*/
|
|
62
|
-
importMetaUrl?: boolean
|
|
63
|
-
};
|
|
64
|
-
type Shims = boolean | ShimOptions;
|
|
65
72
|
type DtsResolve = boolean | (string | RegExp)[];
|
|
66
73
|
type DtsOptions = {
|
|
67
74
|
/**
|
|
@@ -278,24 +285,6 @@ interface BuildOptions {
|
|
|
278
285
|
*/
|
|
279
286
|
publicPath?: string;
|
|
280
287
|
/**
|
|
281
|
-
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
282
|
-
*
|
|
283
|
-
* When set to true, automatically injects all shims when needed
|
|
284
|
-
* When set to an object, only injects the specified shims
|
|
285
|
-
*
|
|
286
|
-
* Available shims:
|
|
287
|
-
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
288
|
-
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* // Enable all shims
|
|
292
|
-
* shims: true
|
|
293
|
-
*
|
|
294
|
-
* // Enable only specific shims
|
|
295
|
-
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
296
|
-
*/
|
|
297
|
-
shims?: Shims;
|
|
298
|
-
/**
|
|
299
288
|
* Controls how environment variables are handled during bundling.
|
|
300
289
|
*
|
|
301
290
|
* Can be one of:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
4
|
+
*/
|
|
2
5
|
type BunupBunPlugin = {
|
|
3
6
|
/** Identifies this as a native Bun plugin */
|
|
4
7
|
type: "bun"
|
|
@@ -7,6 +10,9 @@ type BunupBunPlugin = {
|
|
|
7
10
|
/** The actual Bun plugin implementation */
|
|
8
11
|
plugin: BunPlugin
|
|
9
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the output of a build operation
|
|
15
|
+
*/
|
|
10
16
|
type BuildOutput = {
|
|
11
17
|
/** Array of generated files with their paths and contents */
|
|
12
18
|
files: Array<{
|
|
@@ -16,12 +22,18 @@ type BuildOutput = {
|
|
|
16
22
|
relativePathToRootDir: string
|
|
17
23
|
}>
|
|
18
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Context provided to build hooks
|
|
27
|
+
*/
|
|
19
28
|
type BuildContext = {
|
|
20
29
|
/** The build options that were used */
|
|
21
30
|
options: BuildOptions
|
|
22
31
|
/** The output of the build */
|
|
23
32
|
output: BuildOutput
|
|
24
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Hooks that can be implemented by Bunup plugins
|
|
36
|
+
*/
|
|
25
37
|
type BunupPluginHooks = {
|
|
26
38
|
/**
|
|
27
39
|
* Called when a build is successfully completed
|
|
@@ -34,6 +46,9 @@ type BunupPluginHooks = {
|
|
|
34
46
|
*/
|
|
35
47
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
36
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Represents a Bunup-specific plugin
|
|
51
|
+
*/
|
|
37
52
|
type BunupPlugin = {
|
|
38
53
|
/** Identifies this as a Bunup-specific plugin */
|
|
39
54
|
type: "bunup"
|
|
@@ -42,6 +57,9 @@ type BunupPlugin = {
|
|
|
42
57
|
/** The hooks implemented by this plugin */
|
|
43
58
|
hooks: BunupPluginHooks
|
|
44
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Union type representing all supported plugin types
|
|
62
|
+
*/
|
|
45
63
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
46
64
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
47
65
|
type Define = BunBuildOptions["define"];
|
|
@@ -51,17 +69,6 @@ type Target = BunBuildOptions["target"];
|
|
|
51
69
|
type External = (string | RegExp)[];
|
|
52
70
|
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
53
71
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
54
|
-
type ShimOptions = {
|
|
55
|
-
/**
|
|
56
|
-
* Adds __dirname and __filename shims for ESM files when used
|
|
57
|
-
*/
|
|
58
|
-
dirnameFilename?: boolean
|
|
59
|
-
/**
|
|
60
|
-
* Adds import.meta.url shims for CJS files when used
|
|
61
|
-
*/
|
|
62
|
-
importMetaUrl?: boolean
|
|
63
|
-
};
|
|
64
|
-
type Shims = boolean | ShimOptions;
|
|
65
72
|
type DtsResolve = boolean | (string | RegExp)[];
|
|
66
73
|
type DtsOptions = {
|
|
67
74
|
/**
|
|
@@ -278,24 +285,6 @@ interface BuildOptions {
|
|
|
278
285
|
*/
|
|
279
286
|
publicPath?: string;
|
|
280
287
|
/**
|
|
281
|
-
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
282
|
-
*
|
|
283
|
-
* When set to true, automatically injects all shims when needed
|
|
284
|
-
* When set to an object, only injects the specified shims
|
|
285
|
-
*
|
|
286
|
-
* Available shims:
|
|
287
|
-
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
288
|
-
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* // Enable all shims
|
|
292
|
-
* shims: true
|
|
293
|
-
*
|
|
294
|
-
* // Enable only specific shims
|
|
295
|
-
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
296
|
-
*/
|
|
297
|
-
shims?: Shims;
|
|
298
|
-
/**
|
|
299
288
|
* Controls how environment variables are handled during bundling.
|
|
300
289
|
*
|
|
301
290
|
* Can be one of:
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
import { dirname } from 'path';
|
|
4
|
-
|
|
5
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
-
const __dirname = dirname(__filename);
|
|
7
|
-
|
|
8
|
-
`},importMetaUrl:{appliesTo:(t,e)=>t==="cjs"&&O(e),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
9
|
-
|
|
10
|
-
const importMetaUrl = pathToFileURL(__filename).href;
|
|
11
|
-
|
|
12
|
-
`}};function V({format:t,target:e,shims:n}){let i=Ce(n).map((o)=>R[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:Pe},async({path:a})=>{let g=await Bun.file(a).text(),p=i.filter((l)=>l.isNeededInFile(g));if(p.length===0)return;let{shebangLine:y,codeContent:B}=we(g),P=p.map((l)=>l.generateCode()).join("");return{contents:y+P+B}})}}}function Ce(t){if(t===!0)return Object.keys(R);if(!t)return[];return Object.entries(t).filter(([e,n])=>n&&(e in R)).map(([e])=>e)}function we(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 ee(t){if(!t)return[];return t.filter((e)=>e.type==="bun")}function te(t){if(!t)return[];return t.filter((e)=>e.type==="bunup")}async function re(t,e){if(!t)return;for(let n of t)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function ne(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 Re(t,e=process.cwd()){let n={files:[]},r=G(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new f("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)W(e,r.outDir);D(r.silent);let{packageJson:i,path:o}=await U(e);if(i&&o)m.cli(`Using ${_(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let a=te(r.plugins);await re(a,r);let g=$(r),p=i?.type,y=[Z(r,i),...ee(r.plugins).map((l)=>l.plugin)],B=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,P=r.format.flatMap((l)=>g.map(async(b)=>{let ie=r.outputExtension?.({format:l,packageType:p,options:r,entry:b.path}).js??A(l,p),E=await Bun.build({entrypoints:[`${e}/${b.path}`],format:l,naming:F(b.outputBasePath,ie),splitting:X(r.splitting,l),bytecode:J(r.bytecode,l),define:K(r.define,r.shims,r.env,l),minify:H(r),outdir:`${e}/${r.outDir}`,target:r.target,sourcemap:Y(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:z(r.env),plugins:[...y,...b.dts?[Oe({cwd:e,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:B,onDeclarationGenerated:(u)=>{let d=oe(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),m.progress("DTS",d,{identifier:r.name})}})]:[],V({format:l,target:r.target,shims:r.shims})],throw:!1});for(let u of E.logs){if(u.level==="error")throw console.log(`
|
|
2
|
+
var ne=Object.create;var{getPrototypeOf:oe,defineProperty:w,getOwnPropertyNames:se}=Object;var ie=Object.prototype.hasOwnProperty;var E=(r,e,n)=>{n=r!=null?ne(oe(r)):{};let t=e||!r||!r.__esModule?w(n,"default",{value:r,enumerable:!0}):n;for(let s of se(r))if(!ie.call(t,s))w(t,s,{get:()=>r[s],enumerable:!0});return t};var ae=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var y=ae((we,B)=>{var h=process||{},O=h.argv||[],x=h.env||{},le=!(!!x.NO_COLOR||O.includes("--no-color"))&&(!!x.FORCE_COLOR||O.includes("--color")||h.platform==="win32"||(h.stdout||{}).isTTY&&x.TERM!=="dumb"||!!x.CI),me=(r,e,n=r)=>(t)=>{let s=""+t,o=s.indexOf(e,r.length);return~o?r+ce(s,e,n,o)+e:r+s+e},ce=(r,e,n,t)=>{let s="",o=0;do s+=r.substring(o,t)+n,o=t+e.length,t=r.indexOf(e,o);while(~t);return s+r.substring(o)},P=(r=le)=>{let e=r?me:()=>String;return{isColorSupported:r,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")}};B.exports=P();B.exports.createColors=P});function ue(r){return r}function ge(r){return r}import{dts as he}from"bun-dts";var de=E(y(),1);var i=E(y(),1),M=!1;function k(r){M=r??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=i.default.blue;mutedColor=i.default.dim;infoColor=i.default.cyan;warnColor=i.default.yellow;errorColor=i.default.red;defaultColor=i.default.white;progressFgColorMap={ESM:i.default.yellow,CJS:i.default.green,IIFE:i.default.magenta,DTS:i.default.blue};progressIdentifierBgColorMap={ESM:i.default.bgYellow,CJS:i.default.bgGreen,IIFE:i.default.bgMagenta,DTS:i.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(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:e,label:n,message:t,identifier:s,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),m=o?this.mutedColor(t):t,f=s?` ${e(i.default.black(` ${s} `))}`:"";return`${r(n)} ${a}${m}${f}`}output(r,e={},n=console.log){if(M||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(r),e.verticalSpace)n("")}cli(r,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:i.default.bgBlue,label:this.labels.cli,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(r,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:i.default.bgCyan,label:this.labels.info,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(r,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:i.default.bgYellow,label:this.labels.warn,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(r,e={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:i.default.bgRed,label:this.labels.error,message:r,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(r){for(let[e,n]of Object.entries(this.progressFgColorMap))if(r.includes(e))return n;return this.defaultColor}getProgressBgColor(r){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(r.includes(e))return n;return i.default.bgWhite}progress(r,e,n={}){let t=this.getProgressFgColor(r),s=this.getProgressBgColor(r),o=this.formatMessage({fgColor:t,bgColor:s,label:r,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var l=c.getInstance();class R extends Error{constructor(r){super(r);this.name="BunupError"}}class p extends R{constructor(r){super(r);this.name="BunupBuildError"}}function S(r){let e=typeof r.dts==="object"&&"entry"in r.dts?r.dts.entry:void 0,n=[];if(typeof r.entry==="string")n=[{path:r.entry,outputBasePath:null,dts:!1}];else if(typeof r.entry==="object"&&!Array.isArray(r.entry))n=Object.entries(r.entry).map(([t,s])=>({path:s,outputBasePath:t,dts:!1}));else n=r.entry.map((t)=>({path:t,outputBasePath:null,dts:!1}));if(typeof r.dts!=="undefined"&&!e)n=n.map((t)=>({...t,dts:!0}));else if(e){let t=[];if(typeof e==="string")t=[{path:e,outputBasePath:null,dts:!0}];else if(typeof e==="object"&&!Array.isArray(e))t=Object.entries(e).map(([o,a])=>({path:a,outputBasePath:o,dts:!0}));else t=e.map((o)=>({path:o,outputBasePath:null,dts:!0}));let s=new Set;n=n.map((o)=>{let a=t.some((m)=>m.path===o.path&&m.outputBasePath===o.outputBasePath);if(a)s.add(`${o.path}:${o.outputBasePath}`);return{...o,dts:a}});for(let o of t)if(!s.has(`${o.path}:${o.outputBasePath}`))n.push(o)}return n}function $(r,e){return{entry:`[dir]/${r||"[name]"}${e}`,chunk:`${r||"[name]"}-[hash].[ext]`,asset:`${r?`${r}-`:""}[name]-[hash].[ext]`}}import{loadConfig as fe}from"coffi";import L from"fs/promises";import pe from"path";function A(r,e){switch(r){case"esm":return I(e)?".js":".mjs";case"cjs":return I(e)?".cjs":".js";case"iife":return".global.js"}}function I(r){return r==="module"}function F(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function j(r,e=3){return r.split("/").slice(-e).join("/")}async function T(r,e){let n=pe.join(r,e);try{await L.rm(n,{recursive:!0,force:!0})}catch(t){throw new p(`Failed to clean output directory: ${t}`)}await L.mkdir(n,{recursive:!0})}async function v(r){let{config:e,filepath:n}=await fe({name:"package",cwd:r,extensions:[".json"]});return{packageJson:e,path:n}}var be={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function W(r){return{...be,...r}}function N(r){let{minify:e,minifyWhitespace:n,minifyIdentifiers:t,minifySyntax:s}=r,o=e===!0;return{whitespace:n??o,identifiers:t??o,syntax:s??o}}function D(r,e){return e==="cjs"?r:void 0}function G(r){if(r===!0)return"inline";return typeof r==="string"?r:void 0}function Y(r,e){return{...typeof e==="object"&&Object.keys(e).reduce((n,t)=>{let s=JSON.stringify(e[t]);return n[`process.env.${t}`]=s,n[`import.meta.env.${t}`]=s,n},{}),...r}}function _(r,e){return r===void 0?e==="esm":r}function K(r){return typeof r==="string"?r:void 0}function xe(r){return F(r).map((e)=>new RegExp(`^${e}($|\\/|\\\\)`))}function H(r,e){return typeof e==="string"?e===r:e.test(r)}function U(r,e,n){let s=xe(n).some((a)=>a.test(r))||e.external?.some((a)=>H(r,a)),o=e.noExternal?.some((a)=>H(r,a));return s&&!o}function X(r,e){return{name:"bunup:external-option-plugin",setup(n){n.onResolve({filter:/.*/},(t)=>{let s=t.path;if(U(s,r,e))return{path:s,external:!0};return null})}}}function z(r){if(!r)return[];return r.filter((e)=>e.type==="bun")}function q(r){if(!r)return[];return r.filter((e)=>e.type==="bunup")}async function J(r,e){if(!r)return;for(let n of r)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function Q(r,e,n){if(!r)return;for(let t of r)if(t.hooks.onBuildDone)await t.hooks.onBuildDone({options:e,output:n})}async function Be(r,e=process.cwd()){let n={files:[]},t=W(r);if(!t.entry||t.entry.length===0||!t.outDir)throw new p("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)T(e,t.outDir);k(t.silent);let{packageJson:s,path:o}=await v(e);if(s&&o)l.cli(`Using ${j(o,2)}`,{muted:!0,identifier:t.name,once:`${o}:${t.name}`});let a=q(t.plugins);await J(a,t);let m=S(t),f=s?.type,V=[X(t,s),...z(t.plugins).map((g)=>g.plugin)],ee=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0,re=t.format.flatMap((g)=>m.map(async(b)=>{let te=t.outputExtension?.({format:g,packageType:f,options:t,entry:b.path}).js??A(g,f),C=await Bun.build({entrypoints:[`${e}/${b.path}`],format:g,naming:$(b.outputBasePath,te),splitting:_(t.splitting,g),bytecode:D(t.bytecode,g),define:Y(t.define,t.env),minify:N(t),outdir:`${e}/${t.outDir}`,target:t.target,sourcemap:G(t.sourcemap),loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:K(t.env),plugins:[...V,...b.dts?[he({cwd:e,preferredTsConfigPath:t.preferredTsconfigPath,warnInsteadOfError:t.watch,resolve:ee,onDeclarationGenerated:(u)=>{let d=Z(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),l.progress("DTS",d,{identifier:t.name})}})]:[]],throw:!1});for(let u of C.logs){if(u.level==="error")throw console.log(`
|
|
14
3
|
`),console.log(u),console.log(`
|
|
15
|
-
`),new Error;if(u.level==="warning")
|
|
4
|
+
`),new Error;if(u.level==="warning")l.warn(u.message);else if(u.level==="info")l.info(u.message)}for(let u of C.outputs){let d=Z(u.path,e);if(u.kind==="entry-point")l.progress(g.toUpperCase(),d,{identifier:t.name});n.files.push({fullPath:u.path,relativePathToRootDir:d})}}));if(await Promise.all(re),await Q(a,t,n),t.onSuccess)await t.onSuccess(t)}function Z(r,e){return r.replace(`${e}/`,"")}export{ge as defineWorkspace,ue as defineConfig,Be as build};
|
package/dist/plugins.cjs
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
// @bun @bun-cjs
|
|
2
|
-
(function(exports, require, module, __filename, __dirname) {var $=Object.create;var{getPrototypeOf:
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var $=Object.create;var{getPrototypeOf:D,defineProperty:p,getOwnPropertyNames:k,getOwnPropertyDescriptor:j}=Object,T=Object.prototype.hasOwnProperty;var B=(e,r,t)=>{t=e!=null?$(D(e)):{};let n=r||!e||!e.__esModule?p(t,"default",{value:e,enumerable:!0}):t;for(let i of k(e))if(!T.call(n,i))p(n,i,{get:()=>e[i],enumerable:!0});return n},L=new WeakMap,A=(e)=>{var r=L.get(e),t;if(r)return r;if(r=p({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")k(e).map((n)=>!T.call(r,n)&&p(r,n,{get:()=>e[n],enumerable:!(t=j(e,n))||t.enumerable}));return L.set(e,r),r},N=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var S=(e,r)=>{for(var t in r)p(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})};var y=N((V,M)=>{var C=process||{},F=C.argv||[],w=C.env||{},W=!(!!w.NO_COLOR||F.includes("--no-color"))&&(!!w.FORCE_COLOR||F.includes("--color")||C.platform==="win32"||(C.stdout||{}).isTTY&&w.TERM!=="dumb"||!!w.CI),_=(e,r,t=e)=>(n)=>{let i=""+n,g=i.indexOf(r,e.length);return~g?e+Y(i,r,t,g)+r:e+i+r},Y=(e,r,t,n)=>{let i="",g=0;do i+=e.substring(g,n)+t,g=n+r.length,n=e.indexOf(r,g);while(~n);return i+e.substring(g)},I=(e=W)=>{let r=e?_:()=>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")}};M.exports=I();M.exports.createColors=I});var J={};S(J,{shims:()=>q,report:()=>X});module.exports=A(J);var f=B(y());var o=B(y()),K=!1;class d{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=o.default.blue;mutedColor=o.default.dim;infoColor=o.default.cyan;warnColor=o.default.yellow;errorColor=o.default.red;defaultColor=o.default.white;progressFgColorMap={ESM:o.default.yellow,CJS:o.default.green,IIFE:o.default.magenta,DTS:o.default.blue};progressIdentifierBgColorMap={ESM:o.default.bgYellow,CJS:o.default.bgGreen,IIFE:o.default.bgMagenta,DTS:o.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:t,message:n,identifier:i,muted:g}){let l=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),s=g?this.mutedColor(n):n,a=i?` ${r(o.default.black(` ${i} `))}`:"";return`${e(t)} ${l}${s}${a}`}output(e,r={},t=console.log){if(K||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(e),r.verticalSpace)t("")}cli(e,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:o.default.bgBlue,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(e,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:o.default.bgCyan,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(e,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:o.default.bgYellow,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(e,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:o.default.bgRed,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(e){for(let[r,t]of Object.entries(this.progressFgColorMap))if(e.includes(r))return t;return this.defaultColor}getProgressBgColor(e){for(let[r,t]of Object.entries(this.progressIdentifierBgColorMap))if(e.includes(r))return t;return o.default.bgWhite}progress(e,r,t={}){let n=this.getProgressFgColor(e),i=this.getProgressBgColor(e),g=this.formatMessage({fgColor:n,bgColor:i,label:e,message:r,identifier:t.identifier,muted:t.muted});this.output(g,t)}}function P(e,r,t){let n={};for(let s of e){let a=s.header.length,c=r.map((x)=>x[s.header]?.length||0),m=t?t[s.header]?.length||0:0;n[s.header]=Math.max(a,...c,m)}let i=(s,a,c)=>{return c==="left"?s.padEnd(a):s.padStart(a)},g=e.map((s)=>i(s.header,n[s.header],s.align)).join(o.default.gray(" | "));console.log(o.default.gray(g));let l=e.map((s)=>"-".repeat(n[s.header])).join(" | ");console.log(o.default.gray(l));for(let s of r){let a=e.map((c)=>{let m=s[c.header]||"",x=i(m,n[c.header],c.align);return c.color?c.color(x):x}).join(o.default.gray(" | "));console.log(a)}if(console.log(o.default.gray(l)),t){let s=e.map((a)=>{let c=t[a.header]||"";return i(c,n[a.header],a.align)}).join(o.default.gray(" | "));console.log(s)}}var U=d.getInstance();var H=B(y());function h(e){if(e===0)return"0 B";let r=["B","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(1024));if(t===0)return`${e} ${r[t]}`;return`${(e/1024**t).toFixed(2)} ${r[t]}`}function X(e={}){let{maxBundleSize:r,gzip:t=!0}=e;return{type:"bunup",name:"report",hooks:{onBuildDone:async({options:n,output:i})=>{if(n.watch)return;let g=await Promise.all(i.files.map(async(b)=>{let u=b.relativePathToRootDir,O=Bun.file(b.fullPath).size,R,E;if(t)R=Bun.gzipSync(new Uint8Array(await Bun.file(b.fullPath).arrayBuffer())).length,E=h(R);return{name:u,size:O,formattedSize:h(O),gzipSize:R,formattedGzipSize:E}})),l=g.reduce((b,u)=>b+u.size,0),s=h(l),a,c;if(t)a=g.reduce((b,u)=>b+(u.gzipSize||0),0),c=h(a);let m=[{header:"File",align:"left",color:f.default.blue},{header:"Size",align:"right",color:f.default.green}];if(t)m.push({header:"Gzip",align:"right",color:f.default.magenta});let x=g.map((b)=>{let u={File:b.name,Size:b.formattedSize};if(t&&b.formattedGzipSize)u.Gzip=b.formattedGzipSize;return u}),v={File:"Total",Size:s};if(t&&c)v.Gzip=c;if(console.log(""),P(m,x,v),r&&l>r)console.log(""),console.log(f.default.red(`Your bundle size of ${s} exceeds the configured limit of ${h(r)}`));console.log("")}}}}function q(){return{type:"bun",name:"shims",plugin:{name:"bunup:shims",setup(e){let r=e.config.target==="node"||e.config.target==="bun",t=e.config.format==="esm",n=e.config.format==="cjs";if(!r||!t&&!n)return;e.config.define={...e.config.define,...n&&{"import.meta.url":"importMetaUrl"}},e.onLoad({filter:/\.(js|ts|jsx|tsx|mts|cts)$/},async({path:i})=>{let g=await Bun.file(i).text(),l="";if(t&&(/\b__dirname\b/.test(g)||/\b__filename\b/.test(g)))l=`import { fileURLToPath } from 'url';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
|
|
8
|
+
`;if(n&&/\bimport\.meta\.url\b/.test(g))l=`import { pathToFileURL } from 'url';
|
|
9
|
+
|
|
10
|
+
const importMetaUrl = pathToFileURL(__filename).href;
|
|
11
|
+
|
|
12
|
+
`;if(!l)return;let s=g.split(`
|
|
13
|
+
`),a=s[0],c=s.slice(1);return{contents:[a,l,...c].join(`
|
|
14
|
+
`)}})}}}}})
|
package/dist/plugins.d.cts
CHANGED
|
@@ -12,17 +12,6 @@ type Target = BunBuildOptions["target"];
|
|
|
12
12
|
type External = (string | RegExp)[];
|
|
13
13
|
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
14
14
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
15
|
-
type ShimOptions = {
|
|
16
|
-
/**
|
|
17
|
-
* Adds __dirname and __filename shims for ESM files when used
|
|
18
|
-
*/
|
|
19
|
-
dirnameFilename?: boolean
|
|
20
|
-
/**
|
|
21
|
-
* Adds import.meta.url shims for CJS files when used
|
|
22
|
-
*/
|
|
23
|
-
importMetaUrl?: boolean
|
|
24
|
-
};
|
|
25
|
-
type Shims = boolean | ShimOptions;
|
|
26
15
|
type DtsResolve = boolean | (string | RegExp)[];
|
|
27
16
|
type DtsOptions = {
|
|
28
17
|
/**
|
|
@@ -239,24 +228,6 @@ interface BuildOptions {
|
|
|
239
228
|
*/
|
|
240
229
|
publicPath?: string;
|
|
241
230
|
/**
|
|
242
|
-
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
243
|
-
*
|
|
244
|
-
* When set to true, automatically injects all shims when needed
|
|
245
|
-
* When set to an object, only injects the specified shims
|
|
246
|
-
*
|
|
247
|
-
* Available shims:
|
|
248
|
-
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
249
|
-
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* // Enable all shims
|
|
253
|
-
* shims: true
|
|
254
|
-
*
|
|
255
|
-
* // Enable only specific shims
|
|
256
|
-
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
257
|
-
*/
|
|
258
|
-
shims?: Shims;
|
|
259
|
-
/**
|
|
260
231
|
* Controls how environment variables are handled during bundling.
|
|
261
232
|
*
|
|
262
233
|
* Can be one of:
|
|
@@ -309,6 +280,9 @@ interface BuildOptions {
|
|
|
309
280
|
js: string
|
|
310
281
|
};
|
|
311
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
285
|
+
*/
|
|
312
286
|
type BunupBunPlugin = {
|
|
313
287
|
/** Identifies this as a native Bun plugin */
|
|
314
288
|
type: "bun"
|
|
@@ -317,6 +291,9 @@ type BunupBunPlugin = {
|
|
|
317
291
|
/** The actual Bun plugin implementation */
|
|
318
292
|
plugin: BunPlugin
|
|
319
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* Represents the output of a build operation
|
|
296
|
+
*/
|
|
320
297
|
type BuildOutput = {
|
|
321
298
|
/** Array of generated files with their paths and contents */
|
|
322
299
|
files: Array<{
|
|
@@ -326,12 +303,18 @@ type BuildOutput = {
|
|
|
326
303
|
relativePathToRootDir: string
|
|
327
304
|
}>
|
|
328
305
|
};
|
|
306
|
+
/**
|
|
307
|
+
* Context provided to build hooks
|
|
308
|
+
*/
|
|
329
309
|
type BuildContext = {
|
|
330
310
|
/** The build options that were used */
|
|
331
311
|
options: BuildOptions
|
|
332
312
|
/** The output of the build */
|
|
333
313
|
output: BuildOutput
|
|
334
314
|
};
|
|
315
|
+
/**
|
|
316
|
+
* Hooks that can be implemented by Bunup plugins
|
|
317
|
+
*/
|
|
335
318
|
type BunupPluginHooks = {
|
|
336
319
|
/**
|
|
337
320
|
* Called when a build is successfully completed
|
|
@@ -344,6 +327,9 @@ type BunupPluginHooks = {
|
|
|
344
327
|
*/
|
|
345
328
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
346
329
|
};
|
|
330
|
+
/**
|
|
331
|
+
* Represents a Bunup-specific plugin
|
|
332
|
+
*/
|
|
347
333
|
type BunupPlugin = {
|
|
348
334
|
/** Identifies this as a Bunup-specific plugin */
|
|
349
335
|
type: "bunup"
|
|
@@ -352,6 +338,9 @@ type BunupPlugin = {
|
|
|
352
338
|
/** The hooks implemented by this plugin */
|
|
353
339
|
hooks: BunupPluginHooks
|
|
354
340
|
};
|
|
341
|
+
/**
|
|
342
|
+
* Union type representing all supported plugin types
|
|
343
|
+
*/
|
|
355
344
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
356
345
|
type ReportPluginOptions = {
|
|
357
346
|
/**
|
|
@@ -366,5 +355,13 @@ type ReportPluginOptions = {
|
|
|
366
355
|
*/
|
|
367
356
|
gzip?: boolean
|
|
368
357
|
};
|
|
358
|
+
/**
|
|
359
|
+
* A plugin that logs a report of the bundle size.
|
|
360
|
+
* @param options - The options for the report plugin.
|
|
361
|
+
*/
|
|
369
362
|
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
370
|
-
|
|
363
|
+
/**
|
|
364
|
+
* A plugin that provides shims for Node.js globals and ESM/CJS interoperability.
|
|
365
|
+
*/
|
|
366
|
+
declare function shims(): Plugin;
|
|
367
|
+
export { shims, report };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -12,17 +12,6 @@ type Target = BunBuildOptions["target"];
|
|
|
12
12
|
type External = (string | RegExp)[];
|
|
13
13
|
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
14
14
|
type Entry = Arrayable<string> | Record<string, string>;
|
|
15
|
-
type ShimOptions = {
|
|
16
|
-
/**
|
|
17
|
-
* Adds __dirname and __filename shims for ESM files when used
|
|
18
|
-
*/
|
|
19
|
-
dirnameFilename?: boolean
|
|
20
|
-
/**
|
|
21
|
-
* Adds import.meta.url shims for CJS files when used
|
|
22
|
-
*/
|
|
23
|
-
importMetaUrl?: boolean
|
|
24
|
-
};
|
|
25
|
-
type Shims = boolean | ShimOptions;
|
|
26
15
|
type DtsResolve = boolean | (string | RegExp)[];
|
|
27
16
|
type DtsOptions = {
|
|
28
17
|
/**
|
|
@@ -239,24 +228,6 @@ interface BuildOptions {
|
|
|
239
228
|
*/
|
|
240
229
|
publicPath?: string;
|
|
241
230
|
/**
|
|
242
|
-
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
243
|
-
*
|
|
244
|
-
* When set to true, automatically injects all shims when needed
|
|
245
|
-
* When set to an object, only injects the specified shims
|
|
246
|
-
*
|
|
247
|
-
* Available shims:
|
|
248
|
-
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
249
|
-
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* // Enable all shims
|
|
253
|
-
* shims: true
|
|
254
|
-
*
|
|
255
|
-
* // Enable only specific shims
|
|
256
|
-
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
257
|
-
*/
|
|
258
|
-
shims?: Shims;
|
|
259
|
-
/**
|
|
260
231
|
* Controls how environment variables are handled during bundling.
|
|
261
232
|
*
|
|
262
233
|
* Can be one of:
|
|
@@ -309,6 +280,9 @@ interface BuildOptions {
|
|
|
309
280
|
js: string
|
|
310
281
|
};
|
|
311
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
285
|
+
*/
|
|
312
286
|
type BunupBunPlugin = {
|
|
313
287
|
/** Identifies this as a native Bun plugin */
|
|
314
288
|
type: "bun"
|
|
@@ -317,6 +291,9 @@ type BunupBunPlugin = {
|
|
|
317
291
|
/** The actual Bun plugin implementation */
|
|
318
292
|
plugin: BunPlugin
|
|
319
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* Represents the output of a build operation
|
|
296
|
+
*/
|
|
320
297
|
type BuildOutput = {
|
|
321
298
|
/** Array of generated files with their paths and contents */
|
|
322
299
|
files: Array<{
|
|
@@ -326,12 +303,18 @@ type BuildOutput = {
|
|
|
326
303
|
relativePathToRootDir: string
|
|
327
304
|
}>
|
|
328
305
|
};
|
|
306
|
+
/**
|
|
307
|
+
* Context provided to build hooks
|
|
308
|
+
*/
|
|
329
309
|
type BuildContext = {
|
|
330
310
|
/** The build options that were used */
|
|
331
311
|
options: BuildOptions
|
|
332
312
|
/** The output of the build */
|
|
333
313
|
output: BuildOutput
|
|
334
314
|
};
|
|
315
|
+
/**
|
|
316
|
+
* Hooks that can be implemented by Bunup plugins
|
|
317
|
+
*/
|
|
335
318
|
type BunupPluginHooks = {
|
|
336
319
|
/**
|
|
337
320
|
* Called when a build is successfully completed
|
|
@@ -344,6 +327,9 @@ type BunupPluginHooks = {
|
|
|
344
327
|
*/
|
|
345
328
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
346
329
|
};
|
|
330
|
+
/**
|
|
331
|
+
* Represents a Bunup-specific plugin
|
|
332
|
+
*/
|
|
347
333
|
type BunupPlugin = {
|
|
348
334
|
/** Identifies this as a Bunup-specific plugin */
|
|
349
335
|
type: "bunup"
|
|
@@ -352,6 +338,9 @@ type BunupPlugin = {
|
|
|
352
338
|
/** The hooks implemented by this plugin */
|
|
353
339
|
hooks: BunupPluginHooks
|
|
354
340
|
};
|
|
341
|
+
/**
|
|
342
|
+
* Union type representing all supported plugin types
|
|
343
|
+
*/
|
|
355
344
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
356
345
|
type ReportPluginOptions = {
|
|
357
346
|
/**
|
|
@@ -366,5 +355,13 @@ type ReportPluginOptions = {
|
|
|
366
355
|
*/
|
|
367
356
|
gzip?: boolean
|
|
368
357
|
};
|
|
358
|
+
/**
|
|
359
|
+
* A plugin that logs a report of the bundle size.
|
|
360
|
+
* @param options - The options for the report plugin.
|
|
361
|
+
*/
|
|
369
362
|
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
370
|
-
|
|
363
|
+
/**
|
|
364
|
+
* A plugin that provides shims for Node.js globals and ESM/CJS interoperability.
|
|
365
|
+
*/
|
|
366
|
+
declare function shims(): Plugin;
|
|
367
|
+
export { shims, report };
|
package/dist/plugins.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var F=Object.create;var{getPrototypeOf:I,defineProperty:
|
|
2
|
+
var F=Object.create;var{getPrototypeOf:I,defineProperty:E,getOwnPropertyNames:P}=Object;var $=Object.prototype.hasOwnProperty;var R=(e,r,t)=>{t=e!=null?F(I(e)):{};let n=r||!e||!e.__esModule?E(t,"default",{value:e,enumerable:!0}):t;for(let i of P(e))if(!$.call(n,i))E(n,i,{get:()=>e[i],enumerable:!0});return n};var D=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var C=D((K,B)=>{var w=process||{},L=w.argv||[],f=w.env||{},j=!(!!f.NO_COLOR||L.includes("--no-color"))&&(!!f.FORCE_COLOR||L.includes("--color")||w.platform==="win32"||(w.stdout||{}).isTTY&&f.TERM!=="dumb"||!!f.CI),A=(e,r,t=e)=>(n)=>{let i=""+n,g=i.indexOf(r,e.length);return~g?e+N(i,r,t,g)+r:e+i+r},N=(e,r,t,n)=>{let i="",g=0;do i+=e.substring(g,n)+t,g=n+r.length,n=e.indexOf(r,g);while(~n);return i+e.substring(g)},k=(e=j)=>{let r=e?A:()=>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")}};B.exports=k();B.exports.createColors=k});var p=R(C(),1);var o=R(C(),1),S=!1;class d{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=o.default.blue;mutedColor=o.default.dim;infoColor=o.default.cyan;warnColor=o.default.yellow;errorColor=o.default.red;defaultColor=o.default.white;progressFgColorMap={ESM:o.default.yellow,CJS:o.default.green,IIFE:o.default.magenta,DTS:o.default.blue};progressIdentifierBgColorMap={ESM:o.default.bgYellow,CJS:o.default.bgGreen,IIFE:o.default.bgMagenta,DTS:o.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:t,message:n,identifier:i,muted:g}){let l=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),s=g?this.mutedColor(n):n,a=i?` ${r(o.default.black(` ${i} `))}`:"";return`${e(t)} ${l}${s}${a}`}output(e,r={},t=console.log){if(S||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(e),r.verticalSpace)t("")}cli(e,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:o.default.bgBlue,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(e,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:o.default.bgCyan,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(e,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:o.default.bgYellow,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(e,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:o.default.bgRed,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(e){for(let[r,t]of Object.entries(this.progressFgColorMap))if(e.includes(r))return t;return this.defaultColor}getProgressBgColor(e){for(let[r,t]of Object.entries(this.progressIdentifierBgColorMap))if(e.includes(r))return t;return o.default.bgWhite}progress(e,r,t={}){let n=this.getProgressFgColor(e),i=this.getProgressBgColor(e),g=this.formatMessage({fgColor:n,bgColor:i,label:e,message:r,identifier:t.identifier,muted:t.muted});this.output(g,t)}}function T(e,r,t){let n={};for(let s of e){let a=s.header.length,c=r.map((x)=>x[s.header]?.length||0),m=t?t[s.header]?.length||0:0;n[s.header]=Math.max(a,...c,m)}let i=(s,a,c)=>{return c==="left"?s.padEnd(a):s.padStart(a)},g=e.map((s)=>i(s.header,n[s.header],s.align)).join(o.default.gray(" | "));console.log(o.default.gray(g));let l=e.map((s)=>"-".repeat(n[s.header])).join(" | ");console.log(o.default.gray(l));for(let s of r){let a=e.map((c)=>{let m=s[c.header]||"",x=i(m,n[c.header],c.align);return c.color?c.color(x):x}).join(o.default.gray(" | "));console.log(a)}if(console.log(o.default.gray(l)),t){let s=e.map((a)=>{let c=t[a.header]||"";return i(c,n[a.header],a.align)}).join(o.default.gray(" | "));console.log(s)}}var W=d.getInstance();var _=R(C(),1);function h(e){if(e===0)return"0 B";let r=["B","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(1024));if(t===0)return`${e} ${r[t]}`;return`${(e/1024**t).toFixed(2)} ${r[t]}`}function G(e={}){let{maxBundleSize:r,gzip:t=!0}=e;return{type:"bunup",name:"report",hooks:{onBuildDone:async({options:n,output:i})=>{if(n.watch)return;let g=await Promise.all(i.files.map(async(b)=>{let u=b.relativePathToRootDir,v=Bun.file(b.fullPath).size,y,O;if(t)y=Bun.gzipSync(new Uint8Array(await Bun.file(b.fullPath).arrayBuffer())).length,O=h(y);return{name:u,size:v,formattedSize:h(v),gzipSize:y,formattedGzipSize:O}})),l=g.reduce((b,u)=>b+u.size,0),s=h(l),a,c;if(t)a=g.reduce((b,u)=>b+(u.gzipSize||0),0),c=h(a);let m=[{header:"File",align:"left",color:p.default.blue},{header:"Size",align:"right",color:p.default.green}];if(t)m.push({header:"Gzip",align:"right",color:p.default.magenta});let x=g.map((b)=>{let u={File:b.name,Size:b.formattedSize};if(t&&b.formattedGzipSize)u.Gzip=b.formattedGzipSize;return u}),M={File:"Total",Size:s};if(t&&c)M.Gzip=c;if(console.log(""),T(m,x,M),r&&l>r)console.log(""),console.log(p.default.red(`Your bundle size of ${s} exceeds the configured limit of ${h(r)}`));console.log("")}}}}function rr(){return{type:"bun",name:"shims",plugin:{name:"bunup:shims",setup(e){let r=e.config.target==="node"||e.config.target==="bun",t=e.config.format==="esm",n=e.config.format==="cjs";if(!r||!t&&!n)return;e.config.define={...e.config.define,...n&&{"import.meta.url":"importMetaUrl"}},e.onLoad({filter:/\.(js|ts|jsx|tsx|mts|cts)$/},async({path:i})=>{let g=await Bun.file(i).text(),l="";if(t&&(/\b__dirname\b/.test(g)||/\b__filename\b/.test(g)))l=`import { fileURLToPath } from 'url';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
|
|
8
|
+
`;if(n&&/\bimport\.meta\.url\b/.test(g))l=`import { pathToFileURL } from 'url';
|
|
9
|
+
|
|
10
|
+
const importMetaUrl = pathToFileURL(__filename).href;
|
|
11
|
+
|
|
12
|
+
`;if(!l)return;let s=g.split(`
|
|
13
|
+
`),a=s[0],c=s.slice(1);return{contents:[a,l,...c].join(`
|
|
14
|
+
`)}})}}}}export{rr as shims,G as report};
|
package/package.json
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
2
|
+
"name": "bunup",
|
|
3
|
+
"description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
|
|
4
|
+
"version": "0.6.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
7
|
+
"maintainers": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Arshad Yaseen",
|
|
10
|
+
"email": "m@arshadyaseen.com",
|
|
11
|
+
"url": "https://arshadyaseen.com"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/arshad-yaseen/bunup.git"
|
|
17
|
+
},
|
|
18
|
+
"funding": "https://github.com/sponsors/arshad-yaseen",
|
|
19
|
+
"homepage": "https://bunup.dev",
|
|
20
|
+
"keywords": ["bun", "bunup", "bun-bundler"],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"files": ["dist", "bin"],
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"require": "./dist/index.cjs",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./plugins": {
|
|
33
|
+
"types": "./dist/plugins.d.ts",
|
|
34
|
+
"require": "./dist/plugins.cjs",
|
|
35
|
+
"import": "./dist/plugins.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"bunup": "bin/bunup.mjs"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@clack/prompts": "^0.10.1",
|
|
43
|
+
"bun-dts": "^0.1.23",
|
|
44
|
+
"chokidar": "^4.0.3",
|
|
45
|
+
"coffi": "^0.1.28",
|
|
46
|
+
"package-manager-detector": "^1.2.0",
|
|
47
|
+
"tinyexec": "^1.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "^1.9.4",
|
|
51
|
+
"@types/bun": "^1.2.5",
|
|
52
|
+
"bumpp": "^10.1.0",
|
|
53
|
+
"husky": "^9.1.7",
|
|
54
|
+
"lint-staged": "^15.5.1",
|
|
55
|
+
"typescript": "^5.8.3"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"typescript": ">=4.5.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"typescript": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "bunx bunup@latest",
|
|
67
|
+
"build:docs": "bun run --cwd docs build",
|
|
68
|
+
"dev": "bunx bunup@latest --watch",
|
|
69
|
+
"dev:docs": "bun run --cwd docs dev",
|
|
70
|
+
"format": "biome format .",
|
|
71
|
+
"format:fix": "biome format --write .",
|
|
72
|
+
"lint": "biome check .",
|
|
73
|
+
"lint:fix": "biome check --write .",
|
|
74
|
+
"prepare": "husky",
|
|
75
|
+
"test": "bun test",
|
|
76
|
+
"test-build": "bun run --cwd tests build",
|
|
77
|
+
"tsc": "tsc --noEmit",
|
|
78
|
+
"publish:ci": "bun publish --access public --no-git-checks",
|
|
79
|
+
"release": "bumpp"
|
|
80
|
+
},
|
|
81
|
+
"lint-staged": {
|
|
82
|
+
"*": "bun run format:fix && git add .",
|
|
83
|
+
"src/**/*.(m|c)?(j|t)s": "bun run tsc"
|
|
84
|
+
},
|
|
85
|
+
"workspaces": ["docs", "tests"]
|
|
86
86
|
}
|