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