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