bunup 0.5.18 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +9 -9
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +21 -8
- package/dist/index.d.ts +21 -8
- package/dist/index.js +2 -2
- package/dist/plugins.d.cts +25 -8
- package/dist/plugins.d.ts +25 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
[](https://www.npmjs.com/package/bunup) [](https://npmjs.com/package/bunup) [](https://bun.sh) [](https://github.com/sponsors/arshad-yaseen)
|
|
14
14
|
|
|
15
|
-
Bunup is the **blazing-fast build tool** for TypeScript and JavaScript libraries, designed for flawless developer experience and speed, **powered by Bun's native bundler** — up to **~
|
|
15
|
+
Bunup is the **blazing-fast build tool** for TypeScript and JavaScript libraries, designed for flawless developer experience and speed, **powered by Bun's native bundler** — up to **~100× faster than Tsup**.
|
|
16
16
|
|
|
17
17
|
| Bundler | Format | Build Time | Build Time (with dts) |
|
|
18
18
|
| --------- | ------------ | -------------- | --------------------- |
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var mt=Object.create;var{getPrototypeOf:ft,defineProperty:re,getOwnPropertyNames:bt}=Object;var ht=Object.prototype.hasOwnProperty;var I=(e,t,n)=>{n=e!=null?mt(ft(e)):{};let i=t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n;for(let r of bt(e))if(!ht.call(i,r))re(i,r,{get:()=>e[r],enumerable:!0});return i};var xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var we=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(i)=>t[n]=()=>i})};var
|
|
3
|
+
var mt=Object.create;var{getPrototypeOf:ft,defineProperty:re,getOwnPropertyNames:bt}=Object;var ht=Object.prototype.hasOwnProperty;var I=(e,t,n)=>{n=e!=null?mt(ft(e)):{};let i=t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n;for(let r of bt(e))if(!ht.call(i,r))re(i,r,{get:()=>e[r],enumerable:!0});return i};var xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var we=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(i)=>t[n]=()=>i})};var P=(e,t)=>()=>(e&&(t=e(e=0)),t);var yt=import.meta.require;var v=xt((rn,oe)=>{var V=process||{},Be=V.argv||[],q=V.env||{},Bt=!(!!q.NO_COLOR||Be.includes("--no-color"))&&(!!q.FORCE_COLOR||Be.includes("--color")||V.platform==="win32"||(V.stdout||{}).isTTY&&q.TERM!=="dumb"||!!q.CI),Pt=(e,t,n=e)=>(i)=>{let r=""+i,o=r.indexOf(t,e.length);return~o?e+Ct(r,t,n,o)+t:e+r+t},Ct=(e,t,n,i)=>{let r="",o=0;do r+=e.substring(o,i)+n,o=i+t.length,i=e.indexOf(t,o);while(~i);return r+e.substring(o)},Pe=(e=Bt)=>{let t=e?Pt:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};oe.exports=Pe();oe.exports.createColors=Pe});function N(e){Ce=e??!1}class A{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(!A.instance)A.instance=new A;return A.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({fgColor:e,bgColor:t,label:n,message:i,identifier:r,muted:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=o?this.mutedColor(i):i,p=r?` ${t(g.default.black(` ${r} `))}`:"";return`${e(n)} ${s}${a}${p}`}output(e,t={},n=console.log){if(Ce||!this.shouldLog(t))return;if(t.verticalSpace)n("");if(n(e),t.verticalSpace)n("")}cli(e,t={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:g.default.bgBlue,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:g.default.bgCyan,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:g.default.bgYellow,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:g.default.bgRed,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}getProgressFgColor(e){for(let[t,n]of Object.entries(this.progressFgColorMap))if(e.includes(t))return n;return this.defaultColor}getProgressBgColor(e){for(let[t,n]of Object.entries(this.progressIdentifierBgColorMap))if(e.includes(t))return n;return g.default.bgWhite}progress(e,t,n={}){let i=this.getProgressFgColor(e),r=this.getProgressBgColor(e),o=this.formatMessage({fgColor:i,bgColor:r,label:e,message:t,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var g,Ce=!1,m;var L=P(()=>{g=I(v(),1);m=A.getInstance()});var y,W,_,Oe,k,K,se=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ot,ae=(e,t)=>{let n=se(e),i=t?`[${t}] `:"",r="";if(e instanceof _)r="BUILD ERROR";else if(e instanceof Oe)r="DTS ERROR";else if(e instanceof k)r="CLI ERROR";else if(e instanceof K)r="WATCH ERROR";else if(e instanceof W)r="BUNUP ERROR";let o=Ot.find((s)=>s.pattern.test(n)&&(s.errorType===r||!s.errorType));if(!o&&r)console.error(`${y.default.red(r)} ${i}${n}`);if(o)console.log(`
|
|
4
4
|
`),o.logSolution(n),console.log(`
|
|
5
|
-
`);else console.error(y.default.dim(y.default.white("If you think this is a bug, please open an issue at: ")+y.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$e=(e,t)=>{ae(e,t),process.exit(1)};var J=
|
|
6
|
-
`)+y.default.white("Example: ")+y.default.green("`bunup --target bun`")+y.default.white(" or in config: ")+y.default.green("{ target: 'bun' }"))}}]});import{basename as $t,extname as kt}from"path";function Ee(e){let t=$t(e),n=kt(t);return n?t.slice(0,-n.length):t}function X(e){let t=typeof e.dts==="object"&&"entry"in e.dts?e.dts.entry:void 0,n=[];if(typeof e.entry==="string")n=[{
|
|
7
|
-
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var It,de;var Ze=
|
|
5
|
+
`);else console.error(y.default.dim(y.default.white("If you think this is a bug, please open an issue at: ")+y.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$e=(e,t)=>{ae(e,t),process.exit(1)};var J=P(()=>{y=I(v(),1);L();W=class W extends Error{constructor(e){super(e);this.name="BunupError"}};_=class _ extends W{constructor(e){super(e);this.name="BunupBuildError"}};Oe=class Oe extends W{constructor(e){super(e);this.name="BunupDTSBuildError"}};k=class k extends W{constructor(e){super(e);this.name="BunupCLIError"}};K=class K extends W{constructor(e){super(e);this.name="BunupWatchError"}};Ot=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{m.error(y.default.white("You're trying to build a project that uses Bun. ")+y.default.white("Please set the target option to ")+y.default.cyan("`bun`")+y.default.white(`.
|
|
6
|
+
`)+y.default.white("Example: ")+y.default.green("`bunup --target bun`")+y.default.white(" or in config: ")+y.default.green("{ target: 'bun' }"))}}]});import{basename as $t,extname as kt}from"path";function Ee(e){let t=$t(e),n=kt(t);return n?t.slice(0,-n.length):t}function X(e){let t=typeof e.dts==="object"&&"entry"in e.dts?e.dts.entry:void 0,n=[];if(typeof e.entry==="string")n=[{path:e.entry,outputBasePath:null,dts:!1}];else if(typeof e.entry==="object"&&!Array.isArray(e.entry))n=Object.entries(e.entry).map(([i,r])=>({path:r,outputBasePath:i,dts:!1}));else n=e.entry.map((i)=>({path:i,outputBasePath:null,dts:!1}));if(typeof e.dts!=="undefined"&&!t)n=n.map((i)=>({...i,dts:!0}));else if(t){let i=[];if(typeof t==="string")i=[{path:t,outputBasePath:null,dts:!0}];else if(typeof t==="object"&&!Array.isArray(t))i=Object.entries(t).map(([o,s])=>({path:s,outputBasePath:o,dts:!0}));else i=t.map((o)=>({path:o,outputBasePath:null,dts:!0}));let r=new Set;n=n.map((o)=>{let s=i.some((a)=>a.path===o.path&&a.outputBasePath===o.outputBasePath);if(s)r.add(`${o.path}:${o.outputBasePath}`);return{...o,dts:s}});for(let o of i)if(!r.has(`${o.path}:${o.outputBasePath}`))n.push(o)}return n}function Se(e,t){return{entry:`[dir]/${e||"[name]"}${t}`,chunk:`${e||"[name]"}-[hash].[ext]`,asset:`${e?`${e}-`:""}[name]-[hash].[ext]`}}var Q=()=>{};import Te from"fs/promises";import jt from"path";function Me(e,t,n){return Array.isArray(e)?e.map((i)=>({...i,[t]:n})):{...e,[t]:n}}function Fe(e){return Array.isArray(e)?e:[e]}function Ie(e,t){switch(e){case"esm":return De(t)?".js":".mjs";case"cjs":return De(t)?".cjs":".js";case"iife":return".global.js"}}function ce(e){return e==="node"||e==="bun"}function De(e){return e==="module"}function ee(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function ve(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function te(e,t=3){return e.split("/").slice(-t).join("/")}async function Ae(e,t){let n=jt.join(e,t);try{await Te.rm(n,{recursive:!0,force:!0})}catch(i){throw new _(`Failed to clean output directory: ${i}`)}await Te.mkdir(n,{recursive:!0})}var M=P(()=>{J()});import Tt from"path";import{loadConfig as Dt}from"coffi";async function Le(e,t,n){return Array.isArray(e)&&"root"in e[0]?e.filter((i)=>n?n.includes(i.name):!0).map((i)=>({rootDir:Tt.resolve(t,i.root),options:Me(i.config,"name",i.name)})):[{rootDir:t,options:e}]}async function We(e){let{config:t,filepath:n}=await Dt({name:"package",cwd:e,extensions:[".json"]});return{packageJson:t,path:n}}var ue=P(()=>{M()});function ne(e){return{...Mt,...e}}function _e(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:i,minifySyntax:r}=e,o=t===!0;return{whitespace:n??o,identifiers:i??o,syntax:r??o}}function Je(e,t){return t==="cjs"?e:void 0}function Ue(e){if(e===!0)return"inline";return typeof e==="string"?e:void 0}function Ge(e,t,n,i){return{...typeof n==="object"&&Object.keys(n).reduce((r,o)=>{let s=JSON.stringify(n[o]);return r[`process.env.${o}`]=s,r[`import.meta.env.${o}`]=s,r},{}),...e,...i==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function ze(e,t){return e===void 0?t==="esm":e}function Ye(e){return typeof e==="string"?e:void 0}var Mt;var pe=P(()=>{Mt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function Ft(e){return ve(e).map((t)=>new RegExp(`^${t}($|\\/|\\\\)`))}function qe(e,t){return typeof t==="string"?t===e:t.test(e)}function Ve(e,t,n){let r=Ft(n).some((s)=>s.test(e))||t.external?.some((s)=>qe(e,s)),o=t.noExternal?.some((s)=>qe(e,s));return r&&!o}var Ne=P(()=>{M()});function Ke(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(i)=>{let r=i.path;if(Ve(r,e,t))return{path:r,external:!0};return null})}}}var Xe=P(()=>{Ne()});function Qe({format:e,target:t,shims:n}){let r=vt(n).map((o)=>de[o]).filter((o)=>o.appliesTo(e,t));if(r.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:It},async({path:s})=>{let a=await Bun.file(s).text(),p=r.filter((c)=>c.isNeededInFile(a));if(p.length===0)return;let{shebangLine:d,codeContent:l}=At(a),h=p.map((c)=>c.generateCode()).join("");return{contents:d+h+l}})}}}function vt(e){if(e===!0)return Object.keys(de);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in de)).map(([t])=>t)}function At(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
|
|
7
|
+
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var It,de;var Ze=P(()=>{M();It=/\.(js|ts|jsx|tsx|mts|cts)$/,de={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&ce(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
8
8
|
import { dirname } from 'path';
|
|
9
9
|
|
|
10
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -14,14 +14,14 @@ var mt=Object.create;var{getPrototypeOf:ft,defineProperty:re,getOwnPropertyNames
|
|
|
14
14
|
|
|
15
15
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
16
16
|
|
|
17
|
-
`}}});function He(e){if(!e)return[];return e.filter((t)=>t.type==="bun")}function et(e){if(!e)return[];return e.filter((t)=>t.type==="bunup")}async function tt(e,t){if(!e)return;for(let n of e)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(t)}async function nt(e,t,n){if(!e)return;for(let i of e)if(i.hooks.onBuildDone)await i.hooks.onBuildDone({options:t,output:n})}var rt={};we(rt,{build:()=>ge});import{dts as Wt}from"bun-dts";async function ge(e,t=process.cwd()){let n={files:[]},i=ne(e);if(!i.entry||i.entry.length===0||!i.outDir)throw new _("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(i.clean)Ae(t,i.outDir);N(i.silent);let{packageJson:r,path:o}=await We(t);if(r&&o)m.cli(`Using ${te(o,2)}`,{muted:!0,identifier:i.name,once:`${o}:${i.name}`});let s=et(i.plugins);await tt(s,i);let a=X(i),p=r?.type,d=[Ke(i,r),...He(i.plugins).map((c)=>c.plugin)],l=typeof i.dts==="object"&&"resolve"in i.dts?i.dts.resolve:void 0,h=i.format.flatMap((c)=>a.map(async(O)=>{let D=i.outputExtension?.({format:c,packageType:p,options:i,entry:O}).js??Ie(c,p),z=await Bun.build({entrypoints:[`${t}/${O.
|
|
17
|
+
`}}});function He(e){if(!e)return[];return e.filter((t)=>t.type==="bun")}function et(e){if(!e)return[];return e.filter((t)=>t.type==="bunup")}async function tt(e,t){if(!e)return;for(let n of e)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(t)}async function nt(e,t,n){if(!e)return;for(let i of e)if(i.hooks.onBuildDone)await i.hooks.onBuildDone({options:t,output:n})}var rt={};we(rt,{build:()=>ge});import{dts as Wt}from"bun-dts";async function ge(e,t=process.cwd()){let n={files:[]},i=ne(e);if(!i.entry||i.entry.length===0||!i.outDir)throw new _("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(i.clean)Ae(t,i.outDir);N(i.silent);let{packageJson:r,path:o}=await We(t);if(r&&o)m.cli(`Using ${te(o,2)}`,{muted:!0,identifier:i.name,once:`${o}:${i.name}`});let s=et(i.plugins);await tt(s,i);let a=X(i),p=r?.type,d=[Ke(i,r),...He(i.plugins).map((c)=>c.plugin)],l=typeof i.dts==="object"&&"resolve"in i.dts?i.dts.resolve:void 0,h=i.format.flatMap((c)=>a.map(async(O)=>{let D=i.outputExtension?.({format:c,packageType:p,options:i,entry:O.path}).js??Ie(c,p),z=await Bun.build({entrypoints:[`${t}/${O.path}`],format:c,naming:Se(O.outputBasePath,D),splitting:ze(i.splitting,c),bytecode:Je(i.bytecode,c),define:Ge(i.define,i.shims,i.env,c),minify:_e(i),outdir:`${t}/${i.outDir}`,target:i.target,sourcemap:Ue(i.sourcemap),loader:i.loader,drop:i.drop,banner:i.banner,footer:i.footer,publicPath:i.publicPath,env:Ye(i.env),plugins:[...d,...O.dts?[Wt({cwd:t,preferredTsConfigPath:i.preferredTsconfigPath,warnInsteadOfError:i.watch,resolve:l,onDeclarationGenerated:(b)=>{let u=it(b,t);n.files.push({fullPath:b,relativePathToRootDir:u}),m.progress("DTS",u,{identifier:i.name})}})]:[],Qe({format:c,target:i.target,shims:i.shims})],throw:!1});for(let b of z.logs){if(b.level==="error")throw console.log(`
|
|
18
18
|
`),console.log(b),console.log(`
|
|
19
|
-
`),new Error;if(b.level==="warning")m.warn(b.message);else if(b.level==="info")m.info(b.message)}for(let b of z.outputs){let u=it(b.path,t);if(b.kind==="entry-point")m.progress(c.toUpperCase(),u,{identifier:i.name});n.files.push({fullPath:b.path,relativePathToRootDir:u})}}));if(await Promise.all(h),await nt(s,i,n),i.onSuccess)await i.onSuccess(i)}function it(e,t){return e.replace(`${t}/`,"")}var me=
|
|
19
|
+
`),new Error;if(b.level==="warning")m.warn(b.message);else if(b.level==="info")m.info(b.message)}for(let b of z.outputs){let u=it(b.path,t);if(b.kind==="entry-point")m.progress(c.toUpperCase(),u,{identifier:i.name});n.files.push({fullPath:b.path,relativePathToRootDir:u})}}));if(await Promise.all(h),await nt(s,i,n),i.onSuccess)await i.onSuccess(i)}function it(e,t){return e.replace(`${t}/`,"")}var me=P(()=>{J();Q();ue();L();pe();Xe();Ze();M()});var ut={};we(ut,{init:()=>qt});import S from"fs/promises";import T from"path";import{cancel as R,confirm as j,intro as _t,isCancel as x,log as C,multiselect as st,outro as Jt,tasks as Ut,text as G}from"@clack/prompts";import{loadConfig as he}from"coffi";import{detect as Gt,resolveCommand as fe}from"package-manager-detector";import{exec as zt}from"tinyexec";async function at(e){try{return await S.access(e),!0}catch{return!1}}async function Yt(){let{config:e,filepath:t}=await he({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,packageJsonProperty:"bunup"});return{exists:!!e,filepath:t||void 0}}async function qt(){_t(f.default.bgCyan(f.default.black(" Bunup "))),await lt();let{exists:e,filepath:t}=await Yt();if(e){let u=await j({message:`A bunup configuration already exists at ${f.default.cyan(t||"bunup.config.ts")}. Continue and overwrite it?`,initialValue:!1});if(x(u)||!u)R("Initialization cancelled"),process.exit(1)}let n=await Gt();if(!n)C.error("No package manager detected"),process.exit(1);let{config:i,filepath:r}=await he({name:"package",cwd:process.cwd(),extensions:[".json"]});if(!i||!r)C.error("Cannot find package.json."),process.exit(1);let o=await G({message:"Entry point for your library:",placeholder:"src/index.ts",defaultValue:"src/index.ts"});if(x(o))R("Initialization cancelled"),process.exit(1);let s=T.join(process.cwd(),String(o));if(!await at(s)){let u=await j({message:`Entry file ${f.default.cyan(String(o))} does not exist. Create it?`,initialValue:!0});if(x(u))R("Initialization cancelled"),process.exit(1);if(u)await S.mkdir(T.dirname(s),{recursive:!0}),await S.writeFile(s,`// Your entry point
|
|
20
20
|
|
|
21
21
|
export function hello() {
|
|
22
22
|
return 'Hello from ${T.basename(String(o))}';
|
|
23
23
|
}
|
|
24
|
-
`),C.success(`Created ${o}`)}let a=await st({message:"Output formats:",options:[{value:"esm",label:"ESM",hint:"ECMAScript modules"},{value:"cjs",label:"CJS",hint:"CommonJS modules"},{value:"iife",label:"IIFE",hint:"Immediately Invoked Function Expression"}],initialValues:["esm","cjs"],required:!0});if(x(a))R("Initialization cancelled"),process.exit(1);let p=await G({message:"Output directory:",placeholder:"dist",initialValue:"dist",validate:(u)=>u?void 0:"Output directory is required"});if(x(p))R("Initialization cancelled"),process.exit(1);let d=await j({message:"Generate TypeScript declarations (.d.ts files)?",initialValue:!0});if(x(d))R("Initialization cancelled"),process.exit(1);let l=!1,h=[];if(i.workspaces){let u=await j({message:"Detected workspaces. Set up Bunup for multiple packages?",initialValue:!0});if(x(u))R("Initialization cancelled"),process.exit(1);if(l=u,l){let gt=async()=>{let $=await G({message:"Workspace name:",placeholder:"core",validate:(
|
|
24
|
+
`),C.success(`Created ${o}`)}let a=await st({message:"Output formats:",options:[{value:"esm",label:"ESM",hint:"ECMAScript modules"},{value:"cjs",label:"CJS",hint:"CommonJS modules"},{value:"iife",label:"IIFE",hint:"Immediately Invoked Function Expression"}],initialValues:["esm","cjs"],required:!0});if(x(a))R("Initialization cancelled"),process.exit(1);let p=await G({message:"Output directory:",placeholder:"dist",initialValue:"dist",validate:(u)=>u?void 0:"Output directory is required"});if(x(p))R("Initialization cancelled"),process.exit(1);let d=await j({message:"Generate TypeScript declarations (.d.ts files)?",initialValue:!0});if(x(d))R("Initialization cancelled"),process.exit(1);let l=!1,h=[];if(i.workspaces){let u=await j({message:"Detected workspaces. Set up Bunup for multiple packages?",initialValue:!0});if(x(u))R("Initialization cancelled"),process.exit(1);if(l=u,l){let gt=async()=>{let $=await G({message:"Workspace name:",placeholder:"core",validate:(B)=>B?void 0:"Workspace name is required"});if(x($))return null;let U=await G({message:"Workspace root directory:",placeholder:"packages/core",validate:(B)=>B?void 0:"Workspace root is required"});if(x(U))return null;let F=await G({message:"Workspace entry points (comma-separated):",placeholder:"src/index.ts",validate:(B)=>B?void 0:"At least one entry point is required"});if(x(F))return null;return{name:String($),root:String(U),entries:String(F).split(",").map((B)=>B.trim())}},xe=!0;while(xe){let $=await gt();if(!$)break;h.push($);for(let F of $.entries){let B=T.join(process.cwd(),$.root,F);if(!await at(B)){let ye=await j({message:`Entry file ${f.default.cyan(`${$.root}/${F}`)} does not exist. Create it?`,initialValue:!0});if(x(ye))break;if(ye)await S.mkdir(T.dirname(B),{recursive:!0}),await S.writeFile(B,`// Your entry point
|
|
25
25
|
|
|
26
26
|
export function hello() {
|
|
27
27
|
return 'Hello from ${$.name}';
|
|
@@ -62,7 +62,7 @@ export default defineWorkspace([
|
|
|
62
62
|
${p}
|
|
63
63
|
]);
|
|
64
64
|
`;await S.writeFile(s,d)}function ct(e,t){return t.filter((n)=>e.includes(n.value)).map((n)=>n.configGenerator?n.configGenerator():`${n.value}()`).join(", ")}async function Kt(e,t){let n=e.scripts||{},i=!1;for(let[r,o]of[["build","bunup"],["dev","bunup --watch"]])if(!n[r]||await j({message:`Script '${r}' exists. Replace with '${o}'?`,initialValue:!0}))n[r]=o,i=!0;if(i)e.scripts=n,await S.writeFile(t,JSON.stringify(e,null,2))}async function Xt(e,t){if(e.dependencies?.bunup||e.devDependencies?.bunup){C.info(`Bunup is already installed
|
|
65
|
-
`);return}let i={bun:"-d",npm:"-D",pnpm:"-D",yarn:"-D"},r=fe(t.agent,"add",[i[t.agent]||"-D","bunup"]);if(!r)throw new Error("Failed to resolve install command");await zt(be(r),[],{nodeOptions:{shell:!0,stdio:"pipe"}})}function be(e){if(!e)return"";return`${e.command} ${e.args.join(" ")}`}async function lt(){let e={},t=!1,n=T.join(process.cwd(),"tsconfig.json");try{let{config:r,filepath:o}=await he({name:"tsconfig",cwd:process.cwd(),extensions:[".json"]});if(r&&o)e=r,t=!0,n=o}catch{}if(e.compilerOptions?.isolatedDeclarations!==!0){C.info(`${f.default.cyan("About isolatedDeclarations:")} ${f.default.gray(`A ${f.default.bold("modern TypeScript feature")} for library authors`)}`),C.info(f.default.gray(`Benefits: ${f.default.bold("faster builds")}, ${f.default.bold("more reliable API types")}, and ${f.default.bold("better editor support")} to catch issues during development`));let r=await j({message:"Enable isolatedDeclarations in tsconfig.json? (recommended but optional)",initialValue:!0});if(x(r))return;if(r){if(e.compilerOptions=e.compilerOptions||{},e.compilerOptions.isolatedDeclarations=!0,e.compilerOptions.declaration=!0,"allowJs"in e.compilerOptions)e.compilerOptions.allowJs=null;if(e.exclude=e.exclude||[],!e.exclude.includes("bunup.config.ts"))e.exclude.push("bunup.config.ts");await S.writeFile(n,JSON.stringify(e,null,2)),C.success("Updated tsconfig.json with isolatedDeclarations")}}else if(t){if(e.exclude=e.exclude||[],!e.exclude.includes("bunup.config.ts"))e.exclude.push("bunup.config.ts"),await S.writeFile(n,JSON.stringify(e,null,2))}}var f;var pt=
|
|
65
|
+
`);return}let i={bun:"-d",npm:"-D",pnpm:"-D",yarn:"-D"},r=fe(t.agent,"add",[i[t.agent]||"-D","bunup"]);if(!r)throw new Error("Failed to resolve install command");await zt(be(r),[],{nodeOptions:{shell:!0,stdio:"pipe"}})}function be(e){if(!e)return"";return`${e.command} ${e.args.join(" ")}`}async function lt(){let e={},t=!1,n=T.join(process.cwd(),"tsconfig.json");try{let{config:r,filepath:o}=await he({name:"tsconfig",cwd:process.cwd(),extensions:[".json"]});if(r&&o)e=r,t=!0,n=o}catch{}if(e.compilerOptions?.isolatedDeclarations!==!0){C.info(`${f.default.cyan("About isolatedDeclarations:")} ${f.default.gray(`A ${f.default.bold("modern TypeScript feature")} for library authors`)}`),C.info(f.default.gray(`Benefits: ${f.default.bold("faster builds")}, ${f.default.bold("more reliable API types")}, and ${f.default.bold("better editor support")} to catch issues during development`));let r=await j({message:"Enable isolatedDeclarations in tsconfig.json? (recommended but optional)",initialValue:!0});if(x(r))return;if(r){if(e.compilerOptions=e.compilerOptions||{},e.compilerOptions.isolatedDeclarations=!0,e.compilerOptions.declaration=!0,"allowJs"in e.compilerOptions)e.compilerOptions.allowJs=null;if(e.exclude=e.exclude||[],!e.exclude.includes("bunup.config.ts"))e.exclude.push("bunup.config.ts");await S.writeFile(n,JSON.stringify(e,null,2)),C.success("Updated tsconfig.json with isolatedDeclarations")}}else if(t){if(e.exclude=e.exclude||[],!e.exclude.includes("bunup.config.ts"))e.exclude.push("bunup.config.ts"),await S.writeFile(n,JSON.stringify(e,null,2))}}var f;var pt=P(()=>{f=I(v(),1)});import{exec as Qt}from"tinyexec";var Y="0.6.1";J();L();var le=I(v(),1);var ke="https://bunup.dev/docs/guide/cli-options";J();Q();L();function w(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function E(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new k(`Option --${e} requires a string value`)}}function Z(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new k(`Option --${e} requires a string value`)}}function Et(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new k(`Option --${e} requires a boolean or string value`)}}function St(){console.log(`
|
|
66
66
|
Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
|
|
67
67
|
`),console.log("For more information on available options, visit:"),console.log(`${le.default.cyan(le.default.underline(ke))}
|
|
68
|
-
`),process.exit(0)}function Rt(){console.log(Y),process.exit(0)}var Re={name:{flags:["n","name"],handler:E("name")},format:{flags:["f","format"],handler:Z("format")},outDir:{flags:["o","out-dir"],handler:E("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["bn","banner"],handler:E("banner")},footer:{flags:["ft","footer"],handler:E("footer")},external:{flags:["e","external"],handler:Z("external")},sourcemap:{flags:["sm","sourcemap"],handler:Et("sourcemap")},target:{flags:["t","target"],handler:E("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:Z("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:E("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")},silent:{flags:["silent"],handler:w("silent")},config:{flags:["config"],handler:E("config")},publicPath:{flags:["pp","public-path"],handler:E("publicPath")},env:{flags:["env"],handler:E("env")},shims:{flags:["shims"],handler:w("shims")},onSuccess:{flags:["onSuccess"],handler:E("onSuccess")},filter:{flags:["filter"],handler:Z("filter")},init:{flags:["init"],handler:w("init")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new k(`Entry${n?` --entry.${n}`:""} requires a string value`);let i=t.entry||{};if(n){if(i[n])m.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);i[n]=e}else{let r=Ee(e);if(i[r])m.warn(`Duplicate entry name '${r}' derived from '${e}'. Overwriting previous entry.`);i[r]=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:()=>St()},version:{flags:["v","version"],handler:()=>Rt()}},H={};for(let e of Object.values(Re))for(let t of e.flags)H[t]=e.handler;function je(e){let t={};for(let n=0;n<e.length;n++){let i=e[n];if(i.startsWith("--")){let r,o;if(i.includes("=")){let[s,a]=i.slice(2).split("=",2);r=s,o=a}else{r=i.slice(2);let s=e[n+1];if(o=s&&!s.startsWith("-")?s:!0,typeof o==="string")n++}if(r.includes(".")){let[s,a]=r.split(".",2),p=H[s];if(p)p(o,t,a);else throw new k(`Unknown option: --${r}`)}else{let s=H[r];if(s)s(o,t);else throw new k(`Unknown option: --${r}`)}}else if(i.startsWith("-")){let r=i.slice(1),o=e[n+1],s=o&&!o.startsWith("-")?o:!0;if(typeof s==="string")n++;let a=H[r];if(a)a(s,t);else throw new k(`Unknown option: -${r}`)}else Re.entry.handler(i,t,void 0)}return t}var dt=I(v(),1);ue();M();import{loadConfig as Zt}from"coffi";me();J();Q();L();pe();M();import ie from"path";async function ot(e,t){let n=new Set,i=ne(e),r=X(i);for(let d of r){let l=ie.resolve(t,d.
|
|
68
|
+
`),process.exit(0)}function Rt(){console.log(Y),process.exit(0)}var Re={name:{flags:["n","name"],handler:E("name")},format:{flags:["f","format"],handler:Z("format")},outDir:{flags:["o","out-dir"],handler:E("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["bn","banner"],handler:E("banner")},footer:{flags:["ft","footer"],handler:E("footer")},external:{flags:["e","external"],handler:Z("external")},sourcemap:{flags:["sm","sourcemap"],handler:Et("sourcemap")},target:{flags:["t","target"],handler:E("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:Z("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:E("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")},silent:{flags:["silent"],handler:w("silent")},config:{flags:["config"],handler:E("config")},publicPath:{flags:["pp","public-path"],handler:E("publicPath")},env:{flags:["env"],handler:E("env")},shims:{flags:["shims"],handler:w("shims")},onSuccess:{flags:["onSuccess"],handler:E("onSuccess")},filter:{flags:["filter"],handler:Z("filter")},init:{flags:["init"],handler:w("init")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new k(`Entry${n?` --entry.${n}`:""} requires a string value`);let i=t.entry||{};if(n){if(i[n])m.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);i[n]=e}else{let r=Ee(e);if(i[r])m.warn(`Duplicate entry name '${r}' derived from '${e}'. Overwriting previous entry.`);i[r]=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:()=>St()},version:{flags:["v","version"],handler:()=>Rt()}},H={};for(let e of Object.values(Re))for(let t of e.flags)H[t]=e.handler;function je(e){let t={};for(let n=0;n<e.length;n++){let i=e[n];if(i.startsWith("--")){let r,o;if(i.includes("=")){let[s,a]=i.slice(2).split("=",2);r=s,o=a}else{r=i.slice(2);let s=e[n+1];if(o=s&&!s.startsWith("-")?s:!0,typeof o==="string")n++}if(r.includes(".")){let[s,a]=r.split(".",2),p=H[s];if(p)p(o,t,a);else throw new k(`Unknown option: --${r}`)}else{let s=H[r];if(s)s(o,t);else throw new k(`Unknown option: --${r}`)}}else if(i.startsWith("-")){let r=i.slice(1),o=e[n+1],s=o&&!o.startsWith("-")?o:!0;if(typeof s==="string")n++;let a=H[r];if(a)a(s,t);else throw new k(`Unknown option: -${r}`)}else Re.entry.handler(i,t,void 0)}return t}var dt=I(v(),1);ue();M();import{loadConfig as Zt}from"coffi";me();J();Q();L();pe();M();import ie from"path";async function ot(e,t){let n=new Set,i=ne(e),r=X(i);for(let d of r){let l=ie.resolve(t,d.path),h=ie.dirname(l);n.add(h)}let s=(await import("chokidar")).watch(Array.from(n),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,ie.join(t,i.outDir)]}),a=!1,p=async(d=!1)=>{if(a)return;a=!0;try{let l=performance.now();if(await ge(i,t),!d)m.cli(`\uD83D\uDCE6 Rebuild finished in ${ee(performance.now()-l)}`)}catch(l){ae(l)}finally{a=!1}};s.on("change",(d)=>{let l=ie.relative(t,d);m.cli(`File changed: ${l}`,{muted:!0,once:l}),p()}),s.on("error",(d)=>{throw new K(`Watcher error: ${se(d)}`)}),await p(!0)}async function Ht(e=Bun.argv.slice(2)){let t=je(e);if(t.init){let{init:l}=await Promise.resolve().then(() => (pt(),ut));await l();return}N(t.silent);let n=process.cwd(),{config:i,filepath:r}=await Zt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config,packageJsonProperty:"bunup"}),o=!i?[{rootDir:n,options:t}]:await Le(i,n,t.filter);if(m.cli(`Using bunup v${Y} and bun v${Bun.version}`,{muted:!0}),r)m.cli(`Using ${te(r,2)}`,{muted:!0});let s=performance.now();m.cli("Build started");let{build:a}=await Promise.resolve().then(() => (me(),rt));await Promise.all(o.flatMap(({options:l,rootDir:h})=>{return Fe(l).map(async(O)=>{let D={...O,...en(t)};if(D.watch)await ot(D,h);else await a(D,h)})}));let p=performance.now()-s,d=ee(p);if(m.cli(`\u26A1\uFE0F Build completed in ${dt.default.green(d)}`),t.watch)m.cli("\uD83D\uDC40 Watching for file changes");if(t.onSuccess)m.cli(`Running command: ${t.onSuccess}`,{muted:!0}),await Qt(t.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!t.watch)process.exit(process.exitCode??0)}function en(e){return{...e,onSuccess:void 0,config:void 0,filter:void 0,init:void 0}}Ht().catch((e)=>$e(e));
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun @bun-cjs
|
|
2
|
-
(function(exports, require, module, __filename, __dirname) {var fe=Object.create;var{getPrototypeOf:be,defineProperty:f,getOwnPropertyNames:M,getOwnPropertyDescriptor:he}=Object,D=Object.prototype.hasOwnProperty;var x=(t,e,n)=>{n=t!=null?fe(be(t)):{};let r=e||!t||!t.__esModule?f(n,"default",{value:t,enumerable:!0}):n;for(let i of M(t))if(!D.call(r,i))f(r,i,{get:()=>t[i],enumerable:!0});return r},T=new WeakMap,xe=(t)=>{var e=T.get(t),n;if(e)return e;if(e=f({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")M(t).map((r)=>!D.call(e,r)&&f(e,r,{get:()=>t[r],enumerable:!(n=he(t,r))||n.enumerable}));return T.set(t,e),e},ye=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Be=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var R=ye((Le,O)=>{var B=process||{},F=B.argv||[],y=B.env||{},Pe=!(!!y.NO_COLOR||F.includes("--no-color"))&&(!!y.FORCE_COLOR||F.includes("--color")||B.platform==="win32"||(B.stdout||{}).isTTY&&y.TERM!=="dumb"||!!y.CI),Ce=(t,e,n=t)=>(r)=>{let i=""+r,o=i.indexOf(e,t.length);return~o?t+we(i,e,n,o)+e:t+i+e},we=(t,e,n,r)=>{let i="",o=0;do i+=t.substring(o,r)+n,o=r+e.length,r=t.indexOf(e,o);while(~r);return i+t.substring(o)},j=(t=Pe)=>{let e=t?Ce:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};O.exports=j();O.exports.createColors=j});var Te={};Be(Te,{defineWorkspace:()=>$,defineConfig:()=>L,build:()=>ce});module.exports=xe(Te);function L(t){return t}function $(t){return t}var me=require("bun-dts");var Oe=x(R());var s=x(R()),I=!1;function A(t){I=t??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=s.default.blue;mutedColor=s.default.dim;infoColor=s.default.cyan;warnColor=s.default.yellow;errorColor=s.default.red;defaultColor=s.default.white;progressFgColorMap={ESM:s.default.yellow,CJS:s.default.green,IIFE:s.default.magenta,DTS:s.default.blue};progressIdentifierBgColorMap={ESM:s.default.bgYellow,CJS:s.default.bgGreen,IIFE:s.default.bgMagenta,DTS:s.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!c.instance)c.instance=new c;return c.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({fgColor:t,bgColor:e,label:n,message:r,identifier:i,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),g=o?this.mutedColor(r):r,p=i?` ${e(s.default.black(` ${i} `))}`:"";return`${t(n)} ${a}${g}${p}`}output(t,e={},n=console.log){if(I||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(t),e.verticalSpace)n("")}cli(t,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:s.default.bgBlue,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:s.default.bgCyan,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:s.default.bgYellow,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:s.default.bgRed,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(t){for(let[e,n]of Object.entries(this.progressFgColorMap))if(t.includes(e))return n;return this.defaultColor}getProgressBgColor(t){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(t.includes(e))return n;return s.default.bgWhite}progress(t,e,n={}){let r=this.getProgressFgColor(t),i=this.getProgressBgColor(t),o=this.formatMessage({fgColor:r,bgColor:i,label:t,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var m=c.getInstance();class N extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends N{constructor(t){super(t);this.name="BunupBuildError"}}function _(t){let e=typeof t.dts==="object"&&"entry"in t.dts?t.dts.entry:void 0,n=[];if(typeof t.entry==="string")n=[{
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var fe=Object.create;var{getPrototypeOf:be,defineProperty:f,getOwnPropertyNames:M,getOwnPropertyDescriptor:he}=Object,D=Object.prototype.hasOwnProperty;var x=(t,e,n)=>{n=t!=null?fe(be(t)):{};let r=e||!t||!t.__esModule?f(n,"default",{value:t,enumerable:!0}):n;for(let i of M(t))if(!D.call(r,i))f(r,i,{get:()=>t[i],enumerable:!0});return r},T=new WeakMap,xe=(t)=>{var e=T.get(t),n;if(e)return e;if(e=f({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")M(t).map((r)=>!D.call(e,r)&&f(e,r,{get:()=>t[r],enumerable:!(n=he(t,r))||n.enumerable}));return T.set(t,e),e},ye=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Be=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var R=ye((Le,O)=>{var B=process||{},F=B.argv||[],y=B.env||{},Pe=!(!!y.NO_COLOR||F.includes("--no-color"))&&(!!y.FORCE_COLOR||F.includes("--color")||B.platform==="win32"||(B.stdout||{}).isTTY&&y.TERM!=="dumb"||!!y.CI),Ce=(t,e,n=t)=>(r)=>{let i=""+r,o=i.indexOf(e,t.length);return~o?t+we(i,e,n,o)+e:t+i+e},we=(t,e,n,r)=>{let i="",o=0;do i+=t.substring(o,r)+n,o=r+e.length,r=t.indexOf(e,o);while(~r);return i+t.substring(o)},j=(t=Pe)=>{let e=t?Ce:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};O.exports=j();O.exports.createColors=j});var Te={};Be(Te,{defineWorkspace:()=>$,defineConfig:()=>L,build:()=>ce});module.exports=xe(Te);function L(t){return t}function $(t){return t}var me=require("bun-dts");var Oe=x(R());var s=x(R()),I=!1;function A(t){I=t??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=s.default.blue;mutedColor=s.default.dim;infoColor=s.default.cyan;warnColor=s.default.yellow;errorColor=s.default.red;defaultColor=s.default.white;progressFgColorMap={ESM:s.default.yellow,CJS:s.default.green,IIFE:s.default.magenta,DTS:s.default.blue};progressIdentifierBgColorMap={ESM:s.default.bgYellow,CJS:s.default.bgGreen,IIFE:s.default.bgMagenta,DTS:s.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!c.instance)c.instance=new c;return c.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({fgColor:t,bgColor:e,label:n,message:r,identifier:i,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),g=o?this.mutedColor(r):r,p=i?` ${e(s.default.black(` ${i} `))}`:"";return`${t(n)} ${a}${g}${p}`}output(t,e={},n=console.log){if(I||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(t),e.verticalSpace)n("")}cli(t,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:s.default.bgBlue,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:s.default.bgCyan,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:s.default.bgYellow,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:s.default.bgRed,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(t){for(let[e,n]of Object.entries(this.progressFgColorMap))if(t.includes(e))return n;return this.defaultColor}getProgressBgColor(t){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(t.includes(e))return n;return s.default.bgWhite}progress(t,e,n={}){let r=this.getProgressFgColor(t),i=this.getProgressBgColor(t),o=this.formatMessage({fgColor:r,bgColor:i,label:t,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var m=c.getInstance();class N extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends N{constructor(t){super(t);this.name="BunupBuildError"}}function _(t){let e=typeof t.dts==="object"&&"entry"in t.dts?t.dts.entry:void 0,n=[];if(typeof t.entry==="string")n=[{path:t.entry,outputBasePath:null,dts:!1}];else if(typeof t.entry==="object"&&!Array.isArray(t.entry))n=Object.entries(t.entry).map(([r,i])=>({path:i,outputBasePath:r,dts:!1}));else n=t.entry.map((r)=>({path:r,outputBasePath:null,dts:!1}));if(typeof t.dts!=="undefined"&&!e)n=n.map((r)=>({...r,dts:!0}));else if(e){let r=[];if(typeof e==="string")r=[{path:e,outputBasePath:null,dts:!0}];else if(typeof e==="object"&&!Array.isArray(e))r=Object.entries(e).map(([o,a])=>({path:a,outputBasePath:o,dts:!0}));else r=e.map((o)=>({path:o,outputBasePath:null,dts:!0}));let i=new Set;n=n.map((o)=>{let a=r.some((g)=>g.path===o.path&&g.outputBasePath===o.outputBasePath);if(a)i.add(`${o.path}:${o.outputBasePath}`);return{...o,dts:a}});for(let o of r)if(!i.has(`${o.path}:${o.outputBasePath}`))n.push(o)}return n}function W(t,e){return{entry:`[dir]/${t||"[name]"}${e}`,chunk:`${t||"[name]"}-[hash].[ext]`,asset:`${t?`${t}-`:""}[name]-[hash].[ext]`}}var X=require("coffi");var E=x(require("fs/promises")),G=x(require("path"));function H(t,e){switch(t){case"esm":return U(e)?".js":".mjs";case"cjs":return U(e)?".cjs":".js";case"iife":return".global.js"}}function S(t){return t==="node"||t==="bun"}function U(t){return t==="module"}function J(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Y(t,e=3){return t.split("/").slice(-e).join("/")}async function K(t,e){let n=G.default.join(t,e);try{await E.default.rm(n,{recursive:!0,force:!0})}catch(r){throw new b(`Failed to clean output directory: ${r}`)}await E.default.mkdir(n,{recursive:!0})}async function z(t){let{config:e,filepath:n}=await X.loadConfig({name:"package",cwd:t,extensions:[".json"]});return{packageJson:e,path:n}}var Re={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function q(t){return{...Re,...t}}function Q(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:i??o}}function Z(t,e){return e==="cjs"?t:void 0}function V(t){if(t===!0)return"inline";return typeof t==="string"?t:void 0}function ee(t,e,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((i,o)=>{let a=JSON.stringify(n[o]);return i[`process.env.${o}`]=a,i[`import.meta.env.${o}`]=a,i},{}),...t,...r==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function te(t,e){return t===void 0?e==="esm":t}function re(t){return typeof t==="string"?t:void 0}function Ee(t){return J(t).map((e)=>new RegExp(`^${e}($|\\/|\\\\)`))}function ne(t,e){return typeof e==="string"?e===t:e.test(t)}function oe(t,e,n){let i=Ee(n).some((a)=>a.test(t))||e.external?.some((a)=>ne(t,a)),o=e.noExternal?.some((a)=>ne(t,a));return i&&!o}function ie(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(oe(i,t,e))return{path:i,external:!0};return null})}}}var Se=/\.(js|ts|jsx|tsx|mts|cts)$/,k={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&S(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
11
11
|
|
|
12
12
|
`}};function se({format:t,target:e,shims:n}){let i=ke(n).map((o)=>k[o]).filter((o)=>o.appliesTo(t,e));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:Se},async({path:a})=>{let g=await Bun.file(a).text(),p=i.filter((l)=>l.isNeededInFile(g));if(p.length===0)return;let{shebangLine:P,codeContent:C}=ve(g),w=p.map((l)=>l.generateCode()).join("");return{contents:P+w+C}})}}}function ke(t){if(t===!0)return Object.keys(k);if(!t)return[];return Object.entries(t).filter(([e,n])=>n&&(e in k)).map(([e])=>e)}function ve(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
|
|
13
|
-
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}function ae(t){if(!t)return[];return t.filter((e)=>e.type==="bun")}function le(t){if(!t)return[];return t.filter((e)=>e.type==="bunup")}async function ue(t,e){if(!t)return;for(let n of t)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function ge(t,e,n){if(!t)return;for(let r of t)if(r.hooks.onBuildDone)await r.hooks.onBuildDone({options:e,output:n})}async function ce(t,e=process.cwd()){let n={files:[]},r=q(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)K(e,r.outDir);A(r.silent);let{packageJson:i,path:o}=await z(e);if(i&&o)m.cli(`Using ${Y(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let a=le(r.plugins);await ue(a,r);let g=_(r),p=i?.type,P=[ie(r,i),...ae(r.plugins).map((l)=>l.plugin)],C=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,w=r.format.flatMap((l)=>g.map(async(h)=>{let de=r.outputExtension?.({format:l,packageType:p,options:r,entry:h}).js??H(l,p),v=await Bun.build({entrypoints:[`${e}/${h.
|
|
13
|
+
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}function ae(t){if(!t)return[];return t.filter((e)=>e.type==="bun")}function le(t){if(!t)return[];return t.filter((e)=>e.type==="bunup")}async function ue(t,e){if(!t)return;for(let n of t)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function ge(t,e,n){if(!t)return;for(let r of t)if(r.hooks.onBuildDone)await r.hooks.onBuildDone({options:e,output:n})}async function ce(t,e=process.cwd()){let n={files:[]},r=q(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)K(e,r.outDir);A(r.silent);let{packageJson:i,path:o}=await z(e);if(i&&o)m.cli(`Using ${Y(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let a=le(r.plugins);await ue(a,r);let g=_(r),p=i?.type,P=[ie(r,i),...ae(r.plugins).map((l)=>l.plugin)],C=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,w=r.format.flatMap((l)=>g.map(async(h)=>{let de=r.outputExtension?.({format:l,packageType:p,options:r,entry:h.path}).js??H(l,p),v=await Bun.build({entrypoints:[`${e}/${h.path}`],format:l,naming:W(h.outputBasePath,de),splitting:te(r.splitting,l),bytecode:Z(r.bytecode,l),define:ee(r.define,r.shims,r.env,l),minify:Q(r),outdir:`${e}/${r.outDir}`,target:r.target,sourcemap:V(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:re(r.env),plugins:[...P,...h.dts?[me.dts({cwd:e,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:C,onDeclarationGenerated:(u)=>{let d=pe(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),m.progress("DTS",d,{identifier:r.name})}})]:[],se({format:l,target:r.target,shims:r.shims})],throw:!1});for(let u of v.logs){if(u.level==="error")throw console.log(`
|
|
14
14
|
`),console.log(u),console.log(`
|
|
15
15
|
`),new Error;if(u.level==="warning")m.warn(u.message);else if(u.level==="info")m.info(u.message)}for(let u of v.outputs){let d=pe(u.path,e);if(u.kind==="entry-point")m.progress(l.toUpperCase(),d,{identifier:r.name});n.files.push({fullPath:u.path,relativePathToRootDir:d})}}));if(await Promise.all(w),await ge(a,r,n),r.onSuccess)await r.onSuccess(r)}function pe(t,e){return t.replace(`${e}/`,"")}})
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
dts: boolean
|
|
6
|
-
};
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
4
|
+
*/
|
|
7
5
|
type BunupBunPlugin = {
|
|
8
6
|
/** Identifies this as a native Bun plugin */
|
|
9
7
|
type: "bun"
|
|
@@ -12,6 +10,9 @@ type BunupBunPlugin = {
|
|
|
12
10
|
/** The actual Bun plugin implementation */
|
|
13
11
|
plugin: BunPlugin
|
|
14
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the output of a build operation
|
|
15
|
+
*/
|
|
15
16
|
type BuildOutput = {
|
|
16
17
|
/** Array of generated files with their paths and contents */
|
|
17
18
|
files: Array<{
|
|
@@ -21,12 +22,18 @@ type BuildOutput = {
|
|
|
21
22
|
relativePathToRootDir: string
|
|
22
23
|
}>
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Context provided to build hooks
|
|
27
|
+
*/
|
|
24
28
|
type BuildContext = {
|
|
25
29
|
/** The build options that were used */
|
|
26
30
|
options: BuildOptions
|
|
27
31
|
/** The output of the build */
|
|
28
32
|
output: BuildOutput
|
|
29
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Hooks that can be implemented by Bunup plugins
|
|
36
|
+
*/
|
|
30
37
|
type BunupPluginHooks = {
|
|
31
38
|
/**
|
|
32
39
|
* Called when a build is successfully completed
|
|
@@ -39,6 +46,9 @@ type BunupPluginHooks = {
|
|
|
39
46
|
*/
|
|
40
47
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
41
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Represents a Bunup-specific plugin
|
|
51
|
+
*/
|
|
42
52
|
type BunupPlugin = {
|
|
43
53
|
/** Identifies this as a Bunup-specific plugin */
|
|
44
54
|
type: "bunup"
|
|
@@ -47,6 +57,9 @@ type BunupPlugin = {
|
|
|
47
57
|
/** The hooks implemented by this plugin */
|
|
48
58
|
hooks: BunupPluginHooks
|
|
49
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Union type representing all supported plugin types
|
|
62
|
+
*/
|
|
50
63
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
51
64
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
52
65
|
type Define = BunBuildOptions["define"];
|
|
@@ -335,12 +348,12 @@ interface BuildOptions {
|
|
|
335
348
|
/**
|
|
336
349
|
* Customize the output file extension for each format.
|
|
337
350
|
*
|
|
338
|
-
* @param options Contains format, packageType, options, and entry
|
|
351
|
+
* @param options Contains format, packageType, options, and entry (which is the same as what you defined in the entry option)
|
|
339
352
|
* @returns Object with js extension (including the leading dot). If dts is true, the dts file extension will be automatically derived from the js extension
|
|
340
353
|
*
|
|
341
354
|
* @example
|
|
342
355
|
* outputExtension: ({ format, entry }) => ({
|
|
343
|
-
* js: entry
|
|
356
|
+
* js: entry === 'src/worker.ts' ? '.worker.js' : `.${format}.js`
|
|
344
357
|
* // For example, if js is '.worker.js', the dts will automatically be '.worker.d.ts'
|
|
345
358
|
* })
|
|
346
359
|
*/
|
|
@@ -348,7 +361,7 @@ interface BuildOptions {
|
|
|
348
361
|
format: Format
|
|
349
362
|
packageType: string | undefined
|
|
350
363
|
options: BuildOptions
|
|
351
|
-
entry:
|
|
364
|
+
entry: string
|
|
352
365
|
}) => {
|
|
353
366
|
js: string
|
|
354
367
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
dts: boolean
|
|
6
|
-
};
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
4
|
+
*/
|
|
7
5
|
type BunupBunPlugin = {
|
|
8
6
|
/** Identifies this as a native Bun plugin */
|
|
9
7
|
type: "bun"
|
|
@@ -12,6 +10,9 @@ type BunupBunPlugin = {
|
|
|
12
10
|
/** The actual Bun plugin implementation */
|
|
13
11
|
plugin: BunPlugin
|
|
14
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the output of a build operation
|
|
15
|
+
*/
|
|
15
16
|
type BuildOutput = {
|
|
16
17
|
/** Array of generated files with their paths and contents */
|
|
17
18
|
files: Array<{
|
|
@@ -21,12 +22,18 @@ type BuildOutput = {
|
|
|
21
22
|
relativePathToRootDir: string
|
|
22
23
|
}>
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Context provided to build hooks
|
|
27
|
+
*/
|
|
24
28
|
type BuildContext = {
|
|
25
29
|
/** The build options that were used */
|
|
26
30
|
options: BuildOptions
|
|
27
31
|
/** The output of the build */
|
|
28
32
|
output: BuildOutput
|
|
29
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Hooks that can be implemented by Bunup plugins
|
|
36
|
+
*/
|
|
30
37
|
type BunupPluginHooks = {
|
|
31
38
|
/**
|
|
32
39
|
* Called when a build is successfully completed
|
|
@@ -39,6 +46,9 @@ type BunupPluginHooks = {
|
|
|
39
46
|
*/
|
|
40
47
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
41
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Represents a Bunup-specific plugin
|
|
51
|
+
*/
|
|
42
52
|
type BunupPlugin = {
|
|
43
53
|
/** Identifies this as a Bunup-specific plugin */
|
|
44
54
|
type: "bunup"
|
|
@@ -47,6 +57,9 @@ type BunupPlugin = {
|
|
|
47
57
|
/** The hooks implemented by this plugin */
|
|
48
58
|
hooks: BunupPluginHooks
|
|
49
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Union type representing all supported plugin types
|
|
62
|
+
*/
|
|
50
63
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
51
64
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
52
65
|
type Define = BunBuildOptions["define"];
|
|
@@ -335,12 +348,12 @@ interface BuildOptions {
|
|
|
335
348
|
/**
|
|
336
349
|
* Customize the output file extension for each format.
|
|
337
350
|
*
|
|
338
|
-
* @param options Contains format, packageType, options, and entry
|
|
351
|
+
* @param options Contains format, packageType, options, and entry (which is the same as what you defined in the entry option)
|
|
339
352
|
* @returns Object with js extension (including the leading dot). If dts is true, the dts file extension will be automatically derived from the js extension
|
|
340
353
|
*
|
|
341
354
|
* @example
|
|
342
355
|
* outputExtension: ({ format, entry }) => ({
|
|
343
|
-
* js: entry
|
|
356
|
+
* js: entry === 'src/worker.ts' ? '.worker.js' : `.${format}.js`
|
|
344
357
|
* // For example, if js is '.worker.js', the dts will automatically be '.worker.d.ts'
|
|
345
358
|
* })
|
|
346
359
|
*/
|
|
@@ -348,7 +361,7 @@ interface BuildOptions {
|
|
|
348
361
|
format: Format
|
|
349
362
|
packageType: string | undefined
|
|
350
363
|
options: BuildOptions
|
|
351
|
-
entry:
|
|
364
|
+
entry: string
|
|
352
365
|
}) => {
|
|
353
366
|
js: string
|
|
354
367
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var se=Object.create;var{getPrototypeOf:ae,defineProperty:S,getOwnPropertyNames:le}=Object;var ue=Object.prototype.hasOwnProperty;var k=(t,e,n)=>{n=t!=null?se(ae(t)):{};let r=e||!t||!t.__esModule?S(n,"default",{value:t,enumerable:!0}):n;for(let i of le(t))if(!ue.call(r,i))S(r,i,{get:()=>t[i],enumerable:!0});return r};var ge=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var w=ge((ke,C)=>{var x=process||{},v=x.argv||[],h=x.env||{},ce=!(!!h.NO_COLOR||v.includes("--no-color"))&&(!!h.FORCE_COLOR||v.includes("--color")||x.platform==="win32"||(x.stdout||{}).isTTY&&h.TERM!=="dumb"||!!h.CI),de=(t,e,n=t)=>(r)=>{let i=""+r,o=i.indexOf(e,t.length);return~o?t+fe(i,e,n,o)+e:t+i+e},fe=(t,e,n,r)=>{let i="",o=0;do i+=t.substring(o,r)+n,o=r+e.length,r=t.indexOf(e,o);while(~r);return i+t.substring(o)},T=(t=ce)=>{let e=t?de:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};C.exports=T();C.exports.createColors=T});function pe(t){return t}function me(t){return t}import{dts as Oe}from"bun-dts";var be=k(w(),1);var s=k(w(),1),M=!1;function D(t){M=t??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=s.default.blue;mutedColor=s.default.dim;infoColor=s.default.cyan;warnColor=s.default.yellow;errorColor=s.default.red;defaultColor=s.default.white;progressFgColorMap={ESM:s.default.yellow,CJS:s.default.green,IIFE:s.default.magenta,DTS:s.default.blue};progressIdentifierBgColorMap={ESM:s.default.bgYellow,CJS:s.default.bgGreen,IIFE:s.default.bgMagenta,DTS:s.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!c.instance)c.instance=new c;return c.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({fgColor:t,bgColor:e,label:n,message:r,identifier:i,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),g=o?this.mutedColor(r):r,p=i?` ${e(s.default.black(` ${i} `))}`:"";return`${t(n)} ${a}${g}${p}`}output(t,e={},n=console.log){if(M||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(t),e.verticalSpace)n("")}cli(t,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:s.default.bgBlue,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:s.default.bgCyan,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:s.default.bgYellow,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:s.default.bgRed,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(t){for(let[e,n]of Object.entries(this.progressFgColorMap))if(t.includes(e))return n;return this.defaultColor}getProgressBgColor(t){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(t.includes(e))return n;return s.default.bgWhite}progress(t,e,n={}){let r=this.getProgressFgColor(t),i=this.getProgressBgColor(t),o=this.formatMessage({fgColor:r,bgColor:i,label:t,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var m=c.getInstance();class L extends Error{constructor(t){super(t);this.name="BunupError"}}class f extends L{constructor(t){super(t);this.name="BunupBuildError"}}function $(t){let e=typeof t.dts==="object"&&"entry"in t.dts?t.dts.entry:void 0,n=[];if(typeof t.entry==="string")n=[{
|
|
2
|
+
var se=Object.create;var{getPrototypeOf:ae,defineProperty:S,getOwnPropertyNames:le}=Object;var ue=Object.prototype.hasOwnProperty;var k=(t,e,n)=>{n=t!=null?se(ae(t)):{};let r=e||!t||!t.__esModule?S(n,"default",{value:t,enumerable:!0}):n;for(let i of le(t))if(!ue.call(r,i))S(r,i,{get:()=>t[i],enumerable:!0});return r};var ge=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var w=ge((ke,C)=>{var x=process||{},v=x.argv||[],h=x.env||{},ce=!(!!h.NO_COLOR||v.includes("--no-color"))&&(!!h.FORCE_COLOR||v.includes("--color")||x.platform==="win32"||(x.stdout||{}).isTTY&&h.TERM!=="dumb"||!!h.CI),de=(t,e,n=t)=>(r)=>{let i=""+r,o=i.indexOf(e,t.length);return~o?t+fe(i,e,n,o)+e:t+i+e},fe=(t,e,n,r)=>{let i="",o=0;do i+=t.substring(o,r)+n,o=r+e.length,r=t.indexOf(e,o);while(~r);return i+t.substring(o)},T=(t=ce)=>{let e=t?de:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};C.exports=T();C.exports.createColors=T});function pe(t){return t}function me(t){return t}import{dts as Oe}from"bun-dts";var be=k(w(),1);var s=k(w(),1),M=!1;function D(t){M=t??!1}class c{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=s.default.blue;mutedColor=s.default.dim;infoColor=s.default.cyan;warnColor=s.default.yellow;errorColor=s.default.red;defaultColor=s.default.white;progressFgColorMap={ESM:s.default.yellow,CJS:s.default.green,IIFE:s.default.magenta,DTS:s.default.blue};progressIdentifierBgColorMap={ESM:s.default.bgYellow,CJS:s.default.bgGreen,IIFE:s.default.bgMagenta,DTS:s.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!c.instance)c.instance=new c;return c.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({fgColor:t,bgColor:e,label:n,message:r,identifier:i,muted:o}){let a=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),g=o?this.mutedColor(r):r,p=i?` ${e(s.default.black(` ${i} `))}`:"";return`${t(n)} ${a}${g}${p}`}output(t,e={},n=console.log){if(M||!this.shouldLog(e))return;if(e.verticalSpace)n("");if(n(t),e.verticalSpace)n("")}cli(t,e={}){let n=this.formatMessage({fgColor:this.cliColor,bgColor:s.default.bgBlue,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}info(t,e={}){let n=this.formatMessage({fgColor:this.infoColor,bgColor:s.default.bgCyan,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e)}warn(t,e={}){let n=this.formatMessage({fgColor:this.warnColor,bgColor:s.default.bgYellow,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.warn)}error(t,e={}){let n=this.formatMessage({fgColor:this.errorColor,bgColor:s.default.bgRed,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(n,e,console.error)}getProgressFgColor(t){for(let[e,n]of Object.entries(this.progressFgColorMap))if(t.includes(e))return n;return this.defaultColor}getProgressBgColor(t){for(let[e,n]of Object.entries(this.progressIdentifierBgColorMap))if(t.includes(e))return n;return s.default.bgWhite}progress(t,e,n={}){let r=this.getProgressFgColor(t),i=this.getProgressBgColor(t),o=this.formatMessage({fgColor:r,bgColor:i,label:t,message:e,identifier:n.identifier,muted:n.muted});this.output(o,n)}}var m=c.getInstance();class L extends Error{constructor(t){super(t);this.name="BunupError"}}class f extends L{constructor(t){super(t);this.name="BunupBuildError"}}function $(t){let e=typeof t.dts==="object"&&"entry"in t.dts?t.dts.entry:void 0,n=[];if(typeof t.entry==="string")n=[{path:t.entry,outputBasePath:null,dts:!1}];else if(typeof t.entry==="object"&&!Array.isArray(t.entry))n=Object.entries(t.entry).map(([r,i])=>({path:i,outputBasePath:r,dts:!1}));else n=t.entry.map((r)=>({path:r,outputBasePath:null,dts:!1}));if(typeof t.dts!=="undefined"&&!e)n=n.map((r)=>({...r,dts:!0}));else if(e){let r=[];if(typeof e==="string")r=[{path:e,outputBasePath:null,dts:!0}];else if(typeof e==="object"&&!Array.isArray(e))r=Object.entries(e).map(([o,a])=>({path:a,outputBasePath:o,dts:!0}));else r=e.map((o)=>({path:o,outputBasePath:null,dts:!0}));let i=new Set;n=n.map((o)=>{let a=r.some((g)=>g.path===o.path&&g.outputBasePath===o.outputBasePath);if(a)i.add(`${o.path}:${o.outputBasePath}`);return{...o,dts:a}});for(let o of r)if(!i.has(`${o.path}:${o.outputBasePath}`))n.push(o)}return n}function F(t,e){return{entry:`[dir]/${t||"[name]"}${e}`,chunk:`${t||"[name]"}-[hash].[ext]`,asset:`${t?`${t}-`:""}[name]-[hash].[ext]`}}import{loadConfig as xe}from"coffi";import j from"fs/promises";import he from"path";function A(t,e){switch(t){case"esm":return I(e)?".js":".mjs";case"cjs":return I(e)?".cjs":".js";case"iife":return".global.js"}}function O(t){return t==="node"||t==="bun"}function I(t){return t==="module"}function N(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function _(t,e=3){return t.split("/").slice(-e).join("/")}async function W(t,e){let n=he.join(t,e);try{await j.rm(n,{recursive:!0,force:!0})}catch(r){throw new f(`Failed to clean output directory: ${r}`)}await j.mkdir(n,{recursive:!0})}async function U(t){let{config:e,filepath:n}=await xe({name:"package",cwd:t,extensions:[".json"]});return{packageJson:e,path:n}}var ye={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function G(t){return{...ye,...t}}function H(t){let{minify:e,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=t,o=e===!0;return{whitespace:n??o,identifiers:r??o,syntax:i??o}}function J(t,e){return e==="cjs"?t:void 0}function Y(t){if(t===!0)return"inline";return typeof t==="string"?t:void 0}function K(t,e,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((i,o)=>{let a=JSON.stringify(n[o]);return i[`process.env.${o}`]=a,i[`import.meta.env.${o}`]=a,i},{}),...t,...r==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function X(t,e){return t===void 0?e==="esm":t}function z(t){return typeof t==="string"?t:void 0}function Be(t){return N(t).map((e)=>new RegExp(`^${e}($|\\/|\\\\)`))}function q(t,e){return typeof e==="string"?e===t:e.test(t)}function Q(t,e,n){let i=Be(n).some((a)=>a.test(t))||e.external?.some((a)=>q(t,a)),o=e.noExternal?.some((a)=>q(t,a));return i&&!o}function Z(t,e){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(Q(i,t,e))return{path:i,external:!0};return null})}}}var Pe=/\.(js|ts|jsx|tsx|mts|cts)$/,R={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&O(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -10,6 +10,6 @@ var se=Object.create;var{getPrototypeOf:ae,defineProperty:S,getOwnPropertyNames:
|
|
|
10
10
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
11
11
|
|
|
12
12
|
`}};function V({format:t,target:e,shims:n}){let i=Ce(n).map((o)=>R[o]).filter((o)=>o.appliesTo(t,e));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:Pe},async({path:a})=>{let g=await Bun.file(a).text(),p=i.filter((l)=>l.isNeededInFile(g));if(p.length===0)return;let{shebangLine:y,codeContent:B}=we(g),P=p.map((l)=>l.generateCode()).join("");return{contents:y+P+B}})}}}function Ce(t){if(t===!0)return Object.keys(R);if(!t)return[];return Object.entries(t).filter(([e,n])=>n&&(e in R)).map(([e])=>e)}function we(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
|
|
13
|
-
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}function ee(t){if(!t)return[];return t.filter((e)=>e.type==="bun")}function te(t){if(!t)return[];return t.filter((e)=>e.type==="bunup")}async function re(t,e){if(!t)return;for(let n of t)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function ne(t,e,n){if(!t)return;for(let r of t)if(r.hooks.onBuildDone)await r.hooks.onBuildDone({options:e,output:n})}async function Re(t,e=process.cwd()){let n={files:[]},r=G(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new f("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)W(e,r.outDir);D(r.silent);let{packageJson:i,path:o}=await U(e);if(i&&o)m.cli(`Using ${_(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let a=te(r.plugins);await re(a,r);let g=$(r),p=i?.type,y=[Z(r,i),...ee(r.plugins).map((l)=>l.plugin)],B=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,P=r.format.flatMap((l)=>g.map(async(b)=>{let ie=r.outputExtension?.({format:l,packageType:p,options:r,entry:b}).js??A(l,p),E=await Bun.build({entrypoints:[`${e}/${b.
|
|
13
|
+
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}function ee(t){if(!t)return[];return t.filter((e)=>e.type==="bun")}function te(t){if(!t)return[];return t.filter((e)=>e.type==="bunup")}async function re(t,e){if(!t)return;for(let n of t)if(n.hooks.onBuildStart)await n.hooks.onBuildStart(e)}async function ne(t,e,n){if(!t)return;for(let r of t)if(r.hooks.onBuildDone)await r.hooks.onBuildDone({options:e,output:n})}async function Re(t,e=process.cwd()){let n={files:[]},r=G(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new f("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)W(e,r.outDir);D(r.silent);let{packageJson:i,path:o}=await U(e);if(i&&o)m.cli(`Using ${_(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let a=te(r.plugins);await re(a,r);let g=$(r),p=i?.type,y=[Z(r,i),...ee(r.plugins).map((l)=>l.plugin)],B=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,P=r.format.flatMap((l)=>g.map(async(b)=>{let ie=r.outputExtension?.({format:l,packageType:p,options:r,entry:b.path}).js??A(l,p),E=await Bun.build({entrypoints:[`${e}/${b.path}`],format:l,naming:F(b.outputBasePath,ie),splitting:X(r.splitting,l),bytecode:J(r.bytecode,l),define:K(r.define,r.shims,r.env,l),minify:H(r),outdir:`${e}/${r.outDir}`,target:r.target,sourcemap:Y(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:z(r.env),plugins:[...y,...b.dts?[Oe({cwd:e,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:B,onDeclarationGenerated:(u)=>{let d=oe(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),m.progress("DTS",d,{identifier:r.name})}})]:[],V({format:l,target:r.target,shims:r.shims})],throw:!1});for(let u of E.logs){if(u.level==="error")throw console.log(`
|
|
14
14
|
`),console.log(u),console.log(`
|
|
15
15
|
`),new Error;if(u.level==="warning")m.warn(u.message);else if(u.level==="info")m.info(u.message)}for(let u of E.outputs){let d=oe(u.path,e);if(u.kind==="entry-point")m.progress(l.toUpperCase(),d,{identifier:r.name});n.files.push({fullPath:u.path,relativePathToRootDir:d})}}));if(await Promise.all(P),await ne(a,r,n),r.onSuccess)await r.onSuccess(r)}function oe(t,e){return t.replace(`${e}/`,"")}export{me as defineWorkspace,pe as defineConfig,Re as build};
|
package/dist/plugins.d.cts
CHANGED
|
@@ -4,11 +4,6 @@ type Arrayable<T> = T | T[];
|
|
|
4
4
|
type Bun = typeof _Bun;
|
|
5
5
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
6
6
|
type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
|
|
7
|
-
type ProcessableEntry = {
|
|
8
|
-
fullPath: string
|
|
9
|
-
outputBasePath: string | null
|
|
10
|
-
dts: boolean
|
|
11
|
-
};
|
|
12
7
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
13
8
|
type Define = BunBuildOptions["define"];
|
|
14
9
|
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
@@ -296,12 +291,12 @@ interface BuildOptions {
|
|
|
296
291
|
/**
|
|
297
292
|
* Customize the output file extension for each format.
|
|
298
293
|
*
|
|
299
|
-
* @param options Contains format, packageType, options, and entry
|
|
294
|
+
* @param options Contains format, packageType, options, and entry (which is the same as what you defined in the entry option)
|
|
300
295
|
* @returns Object with js extension (including the leading dot). If dts is true, the dts file extension will be automatically derived from the js extension
|
|
301
296
|
*
|
|
302
297
|
* @example
|
|
303
298
|
* outputExtension: ({ format, entry }) => ({
|
|
304
|
-
* js: entry
|
|
299
|
+
* js: entry === 'src/worker.ts' ? '.worker.js' : `.${format}.js`
|
|
305
300
|
* // For example, if js is '.worker.js', the dts will automatically be '.worker.d.ts'
|
|
306
301
|
* })
|
|
307
302
|
*/
|
|
@@ -309,11 +304,14 @@ interface BuildOptions {
|
|
|
309
304
|
format: Format
|
|
310
305
|
packageType: string | undefined
|
|
311
306
|
options: BuildOptions
|
|
312
|
-
entry:
|
|
307
|
+
entry: string
|
|
313
308
|
}) => {
|
|
314
309
|
js: string
|
|
315
310
|
};
|
|
316
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
314
|
+
*/
|
|
317
315
|
type BunupBunPlugin = {
|
|
318
316
|
/** Identifies this as a native Bun plugin */
|
|
319
317
|
type: "bun"
|
|
@@ -322,6 +320,9 @@ type BunupBunPlugin = {
|
|
|
322
320
|
/** The actual Bun plugin implementation */
|
|
323
321
|
plugin: BunPlugin
|
|
324
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
* Represents the output of a build operation
|
|
325
|
+
*/
|
|
325
326
|
type BuildOutput = {
|
|
326
327
|
/** Array of generated files with their paths and contents */
|
|
327
328
|
files: Array<{
|
|
@@ -331,12 +332,18 @@ type BuildOutput = {
|
|
|
331
332
|
relativePathToRootDir: string
|
|
332
333
|
}>
|
|
333
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* Context provided to build hooks
|
|
337
|
+
*/
|
|
334
338
|
type BuildContext = {
|
|
335
339
|
/** The build options that were used */
|
|
336
340
|
options: BuildOptions
|
|
337
341
|
/** The output of the build */
|
|
338
342
|
output: BuildOutput
|
|
339
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* Hooks that can be implemented by Bunup plugins
|
|
346
|
+
*/
|
|
340
347
|
type BunupPluginHooks = {
|
|
341
348
|
/**
|
|
342
349
|
* Called when a build is successfully completed
|
|
@@ -349,6 +356,9 @@ type BunupPluginHooks = {
|
|
|
349
356
|
*/
|
|
350
357
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
351
358
|
};
|
|
359
|
+
/**
|
|
360
|
+
* Represents a Bunup-specific plugin
|
|
361
|
+
*/
|
|
352
362
|
type BunupPlugin = {
|
|
353
363
|
/** Identifies this as a Bunup-specific plugin */
|
|
354
364
|
type: "bunup"
|
|
@@ -357,6 +367,9 @@ type BunupPlugin = {
|
|
|
357
367
|
/** The hooks implemented by this plugin */
|
|
358
368
|
hooks: BunupPluginHooks
|
|
359
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* Union type representing all supported plugin types
|
|
372
|
+
*/
|
|
360
373
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
361
374
|
type ReportPluginOptions = {
|
|
362
375
|
/**
|
|
@@ -371,5 +384,9 @@ type ReportPluginOptions = {
|
|
|
371
384
|
*/
|
|
372
385
|
gzip?: boolean
|
|
373
386
|
};
|
|
387
|
+
/**
|
|
388
|
+
* A plugin that logs a report of the bundle size.
|
|
389
|
+
* @param options - The options for the report plugin.
|
|
390
|
+
*/
|
|
374
391
|
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
375
392
|
export { report };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -4,11 +4,6 @@ type Arrayable<T> = T | T[];
|
|
|
4
4
|
type Bun = typeof _Bun;
|
|
5
5
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
6
6
|
type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
|
|
7
|
-
type ProcessableEntry = {
|
|
8
|
-
fullPath: string
|
|
9
|
-
outputBasePath: string | null
|
|
10
|
-
dts: boolean
|
|
11
|
-
};
|
|
12
7
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
13
8
|
type Define = BunBuildOptions["define"];
|
|
14
9
|
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
@@ -296,12 +291,12 @@ interface BuildOptions {
|
|
|
296
291
|
/**
|
|
297
292
|
* Customize the output file extension for each format.
|
|
298
293
|
*
|
|
299
|
-
* @param options Contains format, packageType, options, and entry
|
|
294
|
+
* @param options Contains format, packageType, options, and entry (which is the same as what you defined in the entry option)
|
|
300
295
|
* @returns Object with js extension (including the leading dot). If dts is true, the dts file extension will be automatically derived from the js extension
|
|
301
296
|
*
|
|
302
297
|
* @example
|
|
303
298
|
* outputExtension: ({ format, entry }) => ({
|
|
304
|
-
* js: entry
|
|
299
|
+
* js: entry === 'src/worker.ts' ? '.worker.js' : `.${format}.js`
|
|
305
300
|
* // For example, if js is '.worker.js', the dts will automatically be '.worker.d.ts'
|
|
306
301
|
* })
|
|
307
302
|
*/
|
|
@@ -309,11 +304,14 @@ interface BuildOptions {
|
|
|
309
304
|
format: Format
|
|
310
305
|
packageType: string | undefined
|
|
311
306
|
options: BuildOptions
|
|
312
|
-
entry:
|
|
307
|
+
entry: string
|
|
313
308
|
}) => {
|
|
314
309
|
js: string
|
|
315
310
|
};
|
|
316
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
314
|
+
*/
|
|
317
315
|
type BunupBunPlugin = {
|
|
318
316
|
/** Identifies this as a native Bun plugin */
|
|
319
317
|
type: "bun"
|
|
@@ -322,6 +320,9 @@ type BunupBunPlugin = {
|
|
|
322
320
|
/** The actual Bun plugin implementation */
|
|
323
321
|
plugin: BunPlugin
|
|
324
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
* Represents the output of a build operation
|
|
325
|
+
*/
|
|
325
326
|
type BuildOutput = {
|
|
326
327
|
/** Array of generated files with their paths and contents */
|
|
327
328
|
files: Array<{
|
|
@@ -331,12 +332,18 @@ type BuildOutput = {
|
|
|
331
332
|
relativePathToRootDir: string
|
|
332
333
|
}>
|
|
333
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* Context provided to build hooks
|
|
337
|
+
*/
|
|
334
338
|
type BuildContext = {
|
|
335
339
|
/** The build options that were used */
|
|
336
340
|
options: BuildOptions
|
|
337
341
|
/** The output of the build */
|
|
338
342
|
output: BuildOutput
|
|
339
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* Hooks that can be implemented by Bunup plugins
|
|
346
|
+
*/
|
|
340
347
|
type BunupPluginHooks = {
|
|
341
348
|
/**
|
|
342
349
|
* Called when a build is successfully completed
|
|
@@ -349,6 +356,9 @@ type BunupPluginHooks = {
|
|
|
349
356
|
*/
|
|
350
357
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
351
358
|
};
|
|
359
|
+
/**
|
|
360
|
+
* Represents a Bunup-specific plugin
|
|
361
|
+
*/
|
|
352
362
|
type BunupPlugin = {
|
|
353
363
|
/** Identifies this as a Bunup-specific plugin */
|
|
354
364
|
type: "bunup"
|
|
@@ -357,6 +367,9 @@ type BunupPlugin = {
|
|
|
357
367
|
/** The hooks implemented by this plugin */
|
|
358
368
|
hooks: BunupPluginHooks
|
|
359
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* Union type representing all supported plugin types
|
|
372
|
+
*/
|
|
360
373
|
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
361
374
|
type ReportPluginOptions = {
|
|
362
375
|
/**
|
|
@@ -371,5 +384,9 @@ type ReportPluginOptions = {
|
|
|
371
384
|
*/
|
|
372
385
|
gzip?: boolean
|
|
373
386
|
};
|
|
387
|
+
/**
|
|
388
|
+
* A plugin that logs a report of the bundle size.
|
|
389
|
+
* @param options - The options for the report plugin.
|
|
390
|
+
*/
|
|
374
391
|
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
375
392
|
export { report };
|
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.6.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
7
7
|
"maintainers": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@clack/prompts": "^0.10.1",
|
|
43
|
-
"bun-dts": "^0.1.
|
|
43
|
+
"bun-dts": "^0.1.22",
|
|
44
44
|
"chokidar": "^4.0.3",
|
|
45
45
|
"coffi": "^0.1.28",
|
|
46
46
|
"package-manager-detector": "^1.2.0",
|