bunup 0.5.13 → 0.5.16
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 +11 -11
- package/dist/cli.js +38 -47
- package/dist/index.cjs +6 -15
- package/dist/index.d.cts +23 -59
- package/dist/index.d.ts +23 -59
- package/dist/index.js +6 -15
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.d.cts +29 -63
- package/dist/plugins.d.ts +29 -63
- package/dist/plugins.js +1 -1
- package/package.json +7 -12
package/README.md
CHANGED
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
|
|
7
7
|
<!-- markdownlint-disable-next-line no-alt-text -->
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+

|
|
10
10
|
|
|
11
|
-
|
|
11
|
+

|
|
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
|
-
|
|
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 **~50× faster than Tsup**.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
| Bundler | Format | Build Time | Build Time (with dts) |
|
|
18
|
+
| --------- | ------------ | -------------- | --------------------- |
|
|
19
|
+
| **bunup** | **esm, cjs** | **3.42ms ⚡️** | **9.28ms ⚡️** |
|
|
20
|
+
| tsdown | esm, cjs | 22.37ms | 84.48ms |
|
|
21
|
+
| unbuild | esm, cjs | 63.22ms | 386.65ms |
|
|
22
|
+
| bunchee | esm, cjs | 94.98ms | 427.38ms |
|
|
23
|
+
| tsup | esm, cjs | 82.59ms | 1035.61ms |
|
|
24
24
|
|
|
25
25
|
</div>
|
|
26
26
|
<!-- markdownlint-restore -->
|
package/dist/cli.js
CHANGED
|
@@ -1,77 +1,68 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`),
|
|
5
|
-
`);else
|
|
6
|
-
`)+
|
|
7
|
-
|
|
8
|
-
${de.default.gray(a)}`,{verticalSpace:!0})}function nr(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}function ir(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
|
|
9
|
-
`),r=n.length,i=n[n.length-1].length+1;return` (${r}:${i})`}function or(e,t,n){let r=e.split(`
|
|
10
|
-
`),i=e.slice(0,t).split(`
|
|
11
|
-
`).length,o=r[i-1],s=t-e.slice(0,t).lastIndexOf(`
|
|
12
|
-
`)-1,c=n?Math.min(n-e.slice(0,t).lastIndexOf(`
|
|
13
|
-
`)-1,o.length):s+1,a=" ".repeat(s)+de.default.red(de.default.dim("\u23AF".repeat(Math.max(1,c-s))));return`${o}
|
|
14
|
-
${a}`}var de;var st=b(()=>{de=R(F(),1);O();I()});import{isolatedDeclaration as sr}from"oxc-transform";async function at(e){try{let t=await Bun.file(e).text(),{code:n,errors:r}=sr(e,t);for(let i of r)ct.push({error:i,sourceText:t,tsFile:e});return n}catch(t){return d.warn(`Failed to generate declaration for ${e}: ${W(t)}`),null}}function ut(e){let t=!1;for(let{error:n,sourceText:r,tsFile:i}of ct)ot(n,r,i,e),t=!0;if(t&&!e)throw console.log(`${me.default.bgMagentaBright("Pro tip")} Enable "isolatedDeclarations" in your ${me.default.underline("tsconfig.json")} to get these errors early in your editor
|
|
15
|
-
|
|
16
|
-
See why this is happening: ${me.default.blueBright("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")}`),console.log(`
|
|
17
|
-
`),new te}var me,ct;var Se=b(()=>{me=R(F(),1);_();O();st();ct=[]});import{resolveTsImportPath as cr}from"ts-import-resolver";var lt=(e,t,n)=>{let r=new Map;return{name:"bunup:virtual-dts",async resolveId(i,o){if(o===void 0)return r.set(i,e),i;let s=cr({path:i,importer:o,tsconfig:t.tsconfig,rootDir:n});if(!s||!ie(s))return null;let c=oe(s);if(!c)return null;return r.set(c,s),c},load:{filter:{id:{include:[Je],exclude:[Xe]}},async handler(i){if(ne(i)){let o=r.get(i);if(!o)return null;let s=await at(o);if(!s)return null;return{code:s,moduleSideEffects:!1}}return null}},buildEnd(){r.clear()}}};var dt=b(()=>{Se();se()});import{build as ar}from"rolldown";import{dts as ur}from"rolldown-plugin-dts";import lr from"path";async function mt(e,t,n,r){let i=lr.resolve(r,e),o=oe(i),s=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0,{output:c}=await ar({input:o,write:!1,...n.path&&{resolve:{tsconfigFilename:n.path}},onwarn(u,l){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;l(u)},plugins:[lt(i,n,r),ur({dtsInput:!0,emitDtsOnly:!0,resolve:s,tsconfig:n.path??!1})]});ut(!!t.watch);let a=c[0]?.code;if(!a)return d.warn(`Generated empty declaration file for entry "${i}"`,{muted:!0}),"";return a}var gt=b(()=>{O();Se();se();dt()});function ge(e){return{...dr,...e}}function pt(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:i}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:i??o}}function ft(e,t){return t==="cjs"?e:void 0}function bt(e){if(e===!0)return"inline";return typeof e==="string"?e:void 0}function xt(e,t,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((i,o)=>{let s=JSON.stringify(n[o]);return i[`process.env.${o}`]=s,i[`import.meta.env.${o}`]=s,i},{}),...e,...r==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function ht(e,t){return e===void 0?t==="esm":e}function wt(e){return typeof e==="string"?e:void 0}var dr;var ke=b(()=>{dr={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function Ct(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let i=r.path;if(Ce(i,e,t))return{path:i,external:!0};return null})}}}var yt=b(()=>{ye()});function $t({format:e,target:t,shims:n}){let i=gr(n).map((o)=>Ee[o]).filter((o)=>o.appliesTo(e,t));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:mr},async({path:s})=>{let c=await Bun.file(s).text(),a=i.filter((g)=>g.isNeededInFile(c));if(a.length===0)return;let{shebangLine:u,codeContent:l}=pr(c),m=a.map((g)=>g.generateCode()).join("");return{contents:u+m+l}})}}}function gr(e){if(e===!0)return Object.keys(Ee);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in Ee)).map(([t])=>t)}function pr(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
|
|
18
|
-
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var mr,Ee;var Bt=b(()=>{I();mr=/\.(js|ts|jsx|tsx|mts|cts)$/,Ee={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&we(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
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 B=(e,t)=>()=>(e&&(t=e(e=0)),t);var yt=import.meta.require;var v=xt((rn,oe)=>{var V=process||{},Pe=V.argv||[],q=V.env||{},Pt=!(!!q.NO_COLOR||Pe.includes("--no-color"))&&(!!q.FORCE_COLOR||Pe.includes("--color")||V.platform==="win32"||(V.stdout||{}).isTTY&&q.TERM!=="dumb"||!!q.CI),Bt=(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)},Be=(e=Pt)=>{let t=e?Bt:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};oe.exports=Be();oe.exports.createColors=Be});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=B(()=>{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
|
+
`),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=B(()=>{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=[{fullPath:e.entry,outputBasePath:null,dts:!1}];else if(typeof e.entry==="object"&&!Array.isArray(e.entry))n=Object.entries(e.entry).map(([i,r])=>({fullPath:r,outputBasePath:i,dts:!1}));else n=e.entry.map((i)=>({fullPath: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=[{fullPath:t,outputBasePath:null,dts:!0}];else if(typeof t==="object"&&!Array.isArray(t))i=Object.entries(t).map(([o,s])=>({fullPath:s,outputBasePath:o,dts:!0}));else i=t.map((o)=>({fullPath:o,outputBasePath:null,dts:!0}));let r=new Set;n=n.map((o)=>{let s=i.some((a)=>a.fullPath===o.fullPath&&a.outputBasePath===o.outputBasePath);if(s)r.add(`${o.fullPath}:${o.outputBasePath}`);return{...o,dts:s}});for(let o of i)if(!r.has(`${o.fullPath}:${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=B(()=>{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=B(()=>{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=B(()=>{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=B(()=>{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=B(()=>{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=B(()=>{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';
|
|
19
8
|
import { dirname } from 'path';
|
|
20
9
|
|
|
21
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
22
11
|
const __dirname = dirname(__filename);
|
|
23
12
|
|
|
24
|
-
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&
|
|
13
|
+
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&ce(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
25
14
|
|
|
26
15
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
27
16
|
|
|
28
|
-
`}}});function
|
|
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.fullPath}`],format:c,naming:Se(O.outputBasePath,D),splitting:ze(i.splitting,c),bytecode:Je(i.bytecode,c),define:Ge(i.define,i.shims,i.env,c),minify:_e(i),outdir:`${t}/${i.outDir}`,target:i.target,sourcemap:Ue(i.sourcemap),loader:i.loader,drop:i.drop,banner:i.banner,footer:i.footer,publicPath:i.publicPath,env:Ye(i.env),plugins:[...d,...O.dts?[Wt({cwd:t,preferredTsConfigPath:i.preferredTsconfigPath,warnInsteadOfError:i.watch,resolve:l,onDeclarationGenerated:(b)=>{let u=it(b,t);n.files.push({fullPath:b,relativePathToRootDir:u}),m.progress("DTS",u,{identifier:i.name})}})]:[],Qe({format:c,target:i.target,shims:i.shims})],throw:!1});for(let b of z.logs){if(b.level==="error")throw console.log(`
|
|
18
|
+
`),console.log(b),console.log(`
|
|
19
|
+
`),new Error;if(b.level==="warning")m.warn(b.message);else if(b.level==="info")m.info(b.message)}for(let b of z.outputs){let u=it(b.path,t);if(b.kind==="entry-point")m.progress(c.toUpperCase(),u,{identifier:i.name});n.files.push({fullPath:b.path,relativePathToRootDir:u})}}));if(await Promise.all(h),await nt(s,i,n),i.onSuccess)await i.onSuccess(i)}function it(e,t){return e.replace(`${t}/`,"")}var me=B(()=>{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
|
|
29
20
|
|
|
30
21
|
export function hello() {
|
|
31
|
-
return 'Hello from ${
|
|
22
|
+
return 'Hello from ${T.basename(String(o))}';
|
|
32
23
|
}
|
|
33
|
-
`),
|
|
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:(P)=>P?void 0:"Workspace name is required"});if(x($))return null;let U=await G({message:"Workspace root directory:",placeholder:"packages/core",validate:(P)=>P?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:(P)=>P?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((P)=>P.trim())}},xe=!0;while(xe){let $=await gt();if(!$)break;h.push($);for(let F of $.entries){let P=T.join(process.cwd(),$.root,F);if(!await at(P)){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(P),{recursive:!0}),await S.writeFile(P,`// Your entry point
|
|
34
25
|
|
|
35
26
|
export function hello() {
|
|
36
|
-
return 'Hello from ${
|
|
27
|
+
return 'Hello from ${$.name}';
|
|
37
28
|
}
|
|
38
|
-
`),
|
|
39
|
-
${
|
|
29
|
+
`),C.success(`Created ${$.root}/${F}`)}}let U=await j({message:"Add another workspace?",initialValue:!1});if(x(U))break;xe=U}}}let c=[{value:"report",label:"Report",hint:"Logs bundle size report after build",configGenerator:()=>"report()",defaultEnabled:!0}],O=await st({message:"Select plugins to use (optional):",options:c,required:!1,initialValues:c.filter((u)=>u.defaultEnabled).map((u)=>u.value)});if(x(O))R("Initialization cancelled"),process.exit(1);if(l&&h.length>0)await Nt(h,a,String(p),d,O,c,t||void 0);else await Vt(String(o),a,String(p),d,O,c,t||void 0);await lt(),C.success("Configuration generated"),await Kt(i,r),C.success("package.json updated");let D=[{title:"Installing bunup",task:async()=>{return await Xt(i,n),"Bunup installed"}}];try{await Ut(D)}catch(u){C.error(`Error: ${u instanceof Error?u.message:String(u)}`),process.exit(1)}let z=fe(n.agent,"run",["dev"]),b=fe(n.agent,"run",["build"]);Jt(`
|
|
30
|
+
${f.default.bold("\uD83D\uDE80 Happy building with Bunup!")}
|
|
40
31
|
|
|
41
32
|
Run these commands to get started:
|
|
42
|
-
${
|
|
43
|
-
${
|
|
33
|
+
${f.default.cyan(be(b))} - ${f.default.gray("Build your project")}
|
|
34
|
+
${f.default.cyan(be(z))} - ${f.default.gray("Build in watch mode")}
|
|
44
35
|
|
|
45
|
-
${
|
|
46
|
-
`)}async function
|
|
47
|
-
${
|
|
36
|
+
${f.default.dim("Edit")} ${f.default.underline("bunup.config.ts")} ${f.default.dim("to customize your build.")}
|
|
37
|
+
`)}async function Vt(e,t,n,i,r,o,s=T.join(process.cwd(),"bunup.config.ts")){let a=ct(r,o),p=`import { defineConfig } from 'bunup';
|
|
38
|
+
${r.length>0?`import { ${r.join(", ")} } from 'bunup/plugins';
|
|
48
39
|
`:""}
|
|
49
40
|
export default defineConfig({
|
|
50
41
|
entry: '${e}',
|
|
51
|
-
format: [${t.map((
|
|
52
|
-
outDir: '${n}',${
|
|
53
|
-
dts: true,`:""}${
|
|
54
|
-
plugins: [${
|
|
42
|
+
format: [${t.map((d)=>`'${d}'`).join(", ")}],
|
|
43
|
+
outDir: '${n}',${i?`
|
|
44
|
+
dts: true,`:""}${a?`
|
|
45
|
+
plugins: [${a}],`:""}
|
|
55
46
|
});
|
|
56
|
-
`;await
|
|
57
|
-
name: '${
|
|
58
|
-
root: '${
|
|
47
|
+
`;await S.writeFile(s,p)}async function Nt(e,t,n,i,r,o,s=T.join(process.cwd(),"bunup.config.ts")){let a=ct(r,o),p=e.map((l)=>{let h=l.entries.length===1?`'${l.entries[0]}'`:`[${l.entries.map((c)=>`'${c}'`).join(", ")}]`;return` {
|
|
48
|
+
name: '${l.name}',
|
|
49
|
+
root: '${l.root}',
|
|
59
50
|
config: {
|
|
60
|
-
entry: ${
|
|
61
|
-
format: [${t.map((
|
|
62
|
-
outDir: '${n}',${
|
|
63
|
-
dts: true,`:""}${
|
|
64
|
-
plugins: [${
|
|
51
|
+
entry: ${h},
|
|
52
|
+
format: [${t.map((c)=>`'${c}'`).join(", ")}],
|
|
53
|
+
outDir: '${n}',${i?`
|
|
54
|
+
dts: true,`:""}${a?`
|
|
55
|
+
plugins: [${a}],`:""}
|
|
65
56
|
},
|
|
66
57
|
}`}).join(`,
|
|
67
|
-
`),
|
|
68
|
-
${
|
|
58
|
+
`),d=`import { defineWorkspace } from 'bunup';
|
|
59
|
+
${r.length>0?`import { ${r.join(", ")} } from 'bunup/plugins';
|
|
69
60
|
`:""}
|
|
70
61
|
export default defineWorkspace([
|
|
71
|
-
${
|
|
62
|
+
${p}
|
|
72
63
|
]);
|
|
73
|
-
`;await
|
|
74
|
-
`);return}let
|
|
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=B(()=>{f=I(v(),1)});import{exec as Qt}from"tinyexec";var Y="0.5.16";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(`
|
|
75
66
|
Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
|
|
76
|
-
`),console.log("For more information on available options, visit:"),console.log(`${
|
|
77
|
-
`),process.exit(0)}function
|
|
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.fullPath),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,24 +1,15 @@
|
|
|
1
1
|
// @bun @bun-cjs
|
|
2
|
-
(function(exports, require, module, __filename, __dirname) {var
|
|
3
|
-
|
|
4
|
-
${F.default.gray(a)}`,{verticalSpace:!0})}function re(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}function ee(r,e){if(e===void 0)return"";let t=r.slice(0,e).split(`
|
|
5
|
-
`),n=t.length,o=t[t.length-1].length+1;return` (${n}:${o})`}function ne(r,e,t){let n=r.split(`
|
|
6
|
-
`),o=r.slice(0,e).split(`
|
|
7
|
-
`).length,i=n[o-1],s=e-r.slice(0,e).lastIndexOf(`
|
|
8
|
-
`)-1,l=t?Math.min(t-r.slice(0,e).lastIndexOf(`
|
|
9
|
-
`)-1,i.length):s+1,a=" ".repeat(s)+F.default.red(F.default.dim("\u23AF".repeat(Math.max(1,l-s))));return`${i}
|
|
10
|
-
${a}`}var lr=[];async function cr(r){try{let e=await Bun.file(r).text(),{code:t,errors:n}=gr.isolatedDeclaration(r,e);for(let o of n)lr.push({error:o,sourceText:e,tsFile:r});return t}catch(e){return m.warn(`Failed to generate declaration for ${r}: ${k(e)}`),null}}function ur(r){let e=!1;for(let{error:t,sourceText:n,tsFile:o}of lr)ar(t,n,o,r),e=!0;if(e&&!r)throw console.log(`${$.default.bgMagentaBright("Pro tip")} Enable "isolatedDeclarations" in your ${$.default.underline("tsconfig.json")} to get these errors early in your editor
|
|
11
|
-
|
|
12
|
-
See why this is happening: ${$.default.blueBright("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")}`),console.log(`
|
|
13
|
-
`),new I}function te(r){return ir(r).map((e)=>new RegExp(`^${e}($|\\/|\\\\)`))}function dr(r,e){return typeof e==="string"?e===r:e.test(r)}function Y(r,e,t){let o=te(t).some((s)=>s.test(r))||e.external?.some((s)=>dr(r,s)),i=e.noExternal?.some((s)=>dr(r,s));return o&&!i}var fr=/\.(d\.ts|d\.mts|d\.cts)$/,br=/[\\/]node_modules[\\/]/,mr=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function T(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function D(r){return[".ts",".mts",".cts",".tsx"].some((e)=>r.endsWith(e))&&!T(r)}function j(r){if(T(r))return r;if(r.endsWith(".mts"))return`${r.slice(0,-4)}.d.mts`;if(r.endsWith(".cts"))return`${r.slice(0,-4)}.d.cts`;if(mr.test(r))return r.replace(mr,".d.ts");return`${r}.d.ts`}var pr=require("ts-import-resolver");var xr=(r,e,t)=>{let n=new Map;return{name:"bunup:virtual-dts",async resolveId(o,i){if(i===void 0)return n.set(o,r),o;let s=pr.resolveTsImportPath({path:o,importer:i,tsconfig:e.tsconfig,rootDir:t});if(!s||!D(s))return null;let l=j(s);if(!l)return null;return n.set(l,s),l},load:{filter:{id:{include:[fr],exclude:[br]}},async handler(o){if(T(o)){let i=n.get(o);if(!i)return null;let s=await cr(i);if(!s)return null;return{code:s,moduleSideEffects:!1}}return null}},buildEnd(){n.clear()}}};async function wr(r,e,t,n){let o=Br.default.resolve(n,r),i=j(o),s=typeof e.dts==="object"&&"resolve"in e.dts?e.dts.resolve:void 0,{output:l}=await hr.build({input:i,write:!1,...t.path&&{resolve:{tsconfigFilename:t.path}},onwarn(g,b){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;b(g)},plugins:[xr(o,t,n),Cr.dts({dtsInput:!0,emitDtsOnly:!0,resolve:s,tsconfig:t.path??!1})]});ur(!!e.watch);let a=l[0]?.code;if(!a)return m.warn(`Generated empty declaration file for entry "${o}"`,{muted:!0}),"";return a}var w=require("path");function Er(r){let e=w.basename(r),t=w.extname(e);return t?e.slice(0,-t.length):e}function G(r){if(typeof r==="string")return[{fullPath:r,outputBasePath:Er(r)}];if(typeof r==="object"&&!Array.isArray(r))return Object.entries(r).map(([n,o])=>({fullPath:o,outputBasePath:n}));let e=[],t=new Set;for(let n of r){let o=Er(n);if(!t.has(o)){e.push({fullPath:n,outputBasePath:o}),t.add(o);continue}let s=w.dirname(n).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,g;do g=`${o}_${a++}`;while(t.has(g));e.push({fullPath:n,outputBasePath:g}),t.add(g);continue}let l=!1;for(let a=1;a<=s.length&&!l;a++){let b=`${s.slice(-a).join("/")}/${o}`;if(!t.has(b))e.push({fullPath:n,outputBasePath:b}),t.add(b),l=!0}if(!l){let a=1,g;do g=`${s.join("/")}/${o}_${a++}`;while(t.has(g));e.push({fullPath:n,outputBasePath:g}),t.add(g)}}return e}function Or(r){return r.filter((e)=>D(e.fullPath))}function Sr(r,e){return`[dir]/${r}${e}`}function yr(r){return`${r}-[hash].[ext]`}function Mr(r){return`${r}-[name]-[hash].[ext]`}var H=require("coffi");async function Lr(r){let{config:e,filepath:t}=await H.loadConfig({name:"package",cwd:r,extensions:[".json"]});return{packageJson:e,path:t}}async function Rr(r,e){let{config:t,filepath:n}=await H.loadConfig({name:"tsconfig",cwd:r,extensions:[".json"],preferredPath:e});return{tsconfig:t,path:n}}var oe={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Ir(r){return{...oe,...r}}function kr(r){let{minify:e,minifyWhitespace:t,minifyIdentifiers:n,minifySyntax:o}=r,i=e===!0;return{whitespace:t??i,identifiers:n??i,syntax:o??i}}function Fr(r,e){return e==="cjs"?r:void 0}function $r(r){if(r===!0)return"inline";return typeof r==="string"?r:void 0}function Tr(r,e,t,n){return{...typeof t==="object"&&Object.keys(t).reduce((o,i)=>{let s=JSON.stringify(t[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...r,...n==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Dr(r,e){return r===void 0?e==="esm":r}function jr(r){return typeof r==="string"?r:void 0}function Ar(r,e){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(n)=>{let o=n.path;if(Y(o,r,e))return{path:o,external:!0};return null})}}}var ie=/\.(js|ts|jsx|tsx|mts|cts)$/,K={dirnameFilename:{appliesTo:(r,e)=>r==="esm"&&U(e),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
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=[{fullPath:t.entry,outputBasePath:null,dts:!1}];else if(typeof t.entry==="object"&&!Array.isArray(t.entry))n=Object.entries(t.entry).map(([r,i])=>({fullPath:i,outputBasePath:r,dts:!1}));else n=t.entry.map((r)=>({fullPath: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=[{fullPath:e,outputBasePath:null,dts:!0}];else if(typeof e==="object"&&!Array.isArray(e))r=Object.entries(e).map(([o,a])=>({fullPath:a,outputBasePath:o,dts:!0}));else r=e.map((o)=>({fullPath:o,outputBasePath:null,dts:!0}));let i=new Set;n=n.map((o)=>{let a=r.some((g)=>g.fullPath===o.fullPath&&g.outputBasePath===o.outputBasePath);if(a)i.add(`${o.fullPath}:${o.outputBasePath}`);return{...o,dts:a}});for(let o of r)if(!i.has(`${o.fullPath}:${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';
|
|
14
3
|
import { dirname } from 'path';
|
|
15
4
|
|
|
16
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
17
6
|
const __dirname = dirname(__filename);
|
|
18
7
|
|
|
19
|
-
`},importMetaUrl:{appliesTo:(
|
|
8
|
+
`},importMetaUrl:{appliesTo:(t,e)=>t==="cjs"&&S(e),isNeededInFile:(t)=>/\bimport\.meta\.url\b/.test(t),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
20
9
|
|
|
21
10
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
22
11
|
|
|
23
|
-
`}};function
|
|
24
|
-
`);return e===-1?{shebangLine:"",codeContent:
|
|
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.fullPath}`],format:l,naming:W(h.outputBasePath,de),splitting:te(r.splitting,l),bytecode:Z(r.bytecode,l),define:ee(r.define,r.shims,r.env,l),minify:Q(r),outdir:`${e}/${r.outDir}`,target:r.target,sourcemap:V(r.sourcemap),loader:r.loader,drop:r.drop,banner:r.banner,footer:r.footer,publicPath:r.publicPath,env:re(r.env),plugins:[...P,...h.dts?[me.dts({cwd:e,preferredTsConfigPath:r.preferredTsconfigPath,warnInsteadOfError:r.watch,resolve:C,onDeclarationGenerated:(u)=>{let d=pe(u,e);n.files.push({fullPath:u,relativePathToRootDir:d}),m.progress("DTS",d,{identifier:r.name})}})]:[],se({format:l,target:r.target,shims:r.shims})],throw:!1});for(let u of v.logs){if(u.level==="error")throw console.log(`
|
|
14
|
+
`),console.log(u),console.log(`
|
|
15
|
+
`),new Error;if(u.level==="warning")m.warn(u.message);else if(u.level==="info")m.info(u.message)}for(let u of v.outputs){let d=pe(u.path,e);if(u.kind==="entry-point")m.progress(l.toUpperCase(),d,{identifier:r.name});n.files.push({fullPath:u.path,relativePathToRootDir:d})}}));if(await Promise.all(w),await ge(a,r,n),r.onSuccess)await r.onSuccess(r)}function pe(t,e){return t.replace(`${e}/`,"")}})
|
package/dist/index.d.cts
CHANGED
|
@@ -3,17 +3,8 @@ import _Bun from "bun";
|
|
|
3
3
|
//#region src/helpers/entry.d.ts
|
|
4
4
|
type ProcessableEntry = {
|
|
5
5
|
fullPath: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* This is the path that will be used to name the output file.
|
|
10
|
-
*
|
|
11
|
-
* Examples:
|
|
12
|
-
* - "src/index.ts" → "index"
|
|
13
|
-
* - "src/plugins/index.ts" → "plugins/index"
|
|
14
|
-
* - etc.
|
|
15
|
-
*/
|
|
16
|
-
outputBasePath: string;
|
|
6
|
+
outputBasePath: string | null;
|
|
7
|
+
dts: boolean;
|
|
17
8
|
}; //#endregion
|
|
18
9
|
//#region src/plugins/types.d.ts
|
|
19
10
|
/**
|
|
@@ -116,18 +107,8 @@ type DtsOptions = {
|
|
|
116
107
|
* If it's a string or an array of strings, the file name (without extension)
|
|
117
108
|
* will be used as the name for the output declaration file.
|
|
118
109
|
*
|
|
119
|
-
* @
|
|
120
|
-
*
|
|
121
|
-
* entry: 'src/index.ts' // Generates index.d.ts
|
|
122
|
-
*
|
|
123
|
-
* // Using string paths in an array
|
|
124
|
-
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
125
|
-
*
|
|
126
|
-
* // Using named outputs as an object
|
|
127
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
128
|
-
*
|
|
129
|
-
* // Organizing output with subdirectories
|
|
130
|
-
* entry: { "client/index": "src/client/index.ts", "server/index": "src/server/index.ts" } // Generates client/index.d.ts and server/index.d.ts
|
|
110
|
+
* @see https://bunup.dev/docs/guide/typescript-declarations#custom-entry-points
|
|
111
|
+
* @see https://bunup.dev/docs/guide/typescript-declarations#named-entries
|
|
131
112
|
*/
|
|
132
113
|
entry?: Entry;
|
|
133
114
|
/**
|
|
@@ -155,15 +136,7 @@ interface BuildOptions {
|
|
|
155
136
|
* If it's a string or an array of strings, the file name (without extension)
|
|
156
137
|
* will be used as the name for the output file.
|
|
157
138
|
*
|
|
158
|
-
* @
|
|
159
|
-
* // Using a string path
|
|
160
|
-
* entry: 'src/index.ts' // Generates index.js
|
|
161
|
-
*
|
|
162
|
-
* // Using string paths in an array
|
|
163
|
-
* entry: ['src/index.ts'] // Generates index.js
|
|
164
|
-
*
|
|
165
|
-
* // Using named outputs as an object
|
|
166
|
-
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
|
|
139
|
+
* @see https://bunup.dev/docs/#entry-points
|
|
167
140
|
*/
|
|
168
141
|
entry: Entry;
|
|
169
142
|
/**
|
|
@@ -213,21 +186,6 @@ interface BuildOptions {
|
|
|
213
186
|
*/
|
|
214
187
|
dts?: boolean | DtsOptions;
|
|
215
188
|
/**
|
|
216
|
-
* Generate only TypeScript declaration files (.d.ts) without any JavaScript output
|
|
217
|
-
* When set to true, bunup will skip the JavaScript bundling process entirely
|
|
218
|
-
* and only generate declaration files for the specified entry points
|
|
219
|
-
*
|
|
220
|
-
* This is useful when you want to use bunup's fast declaration file generation
|
|
221
|
-
* but handle the JavaScript bundling separately or not at all.
|
|
222
|
-
*
|
|
223
|
-
* Note: When this option is true, the `dts` option is implicitly set to true
|
|
224
|
-
* and other bundling-related options are ignored.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* dtsOnly: true
|
|
228
|
-
*/
|
|
229
|
-
dtsOnly?: boolean;
|
|
230
|
-
/**
|
|
231
189
|
* Path to a preferred tsconfig.json file to use for declaration generation
|
|
232
190
|
*
|
|
233
191
|
* If not specified, the tsconfig.json in the project root will be used.
|
|
@@ -419,26 +377,33 @@ interface BuildOptions {
|
|
|
419
377
|
* Plugins to extend the build process functionality
|
|
420
378
|
*
|
|
421
379
|
* The Plugin type uses a discriminated union pattern with the 'type' field
|
|
422
|
-
* to support different plugin systems.
|
|
423
|
-
* but in the future, this will be extended to include "bunup" plugins as well.
|
|
380
|
+
* to support different plugin systems. Both "bun" and "bunup" plugins are supported.
|
|
424
381
|
*
|
|
425
382
|
* Each plugin type has its own specific plugin implementation:
|
|
426
383
|
* - "bun": Uses Bun's native plugin system (BunPlugin)
|
|
427
|
-
* - "bunup":
|
|
384
|
+
* - "bunup": Uses bunup's own plugin system with lifecycle hooks
|
|
428
385
|
*
|
|
429
386
|
* This architecture allows for extensibility as more plugin systems are added.
|
|
430
387
|
*
|
|
388
|
+
* @see https://bunup.dev/docs/advanced/plugin-development for more information on plugins
|
|
389
|
+
*
|
|
431
390
|
* @example
|
|
432
391
|
* plugins: [
|
|
433
392
|
* {
|
|
434
393
|
* type: "bun",
|
|
435
394
|
* plugin: myBunPlugin()
|
|
436
395
|
* },
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
396
|
+
* {
|
|
397
|
+
* type: "bunup",
|
|
398
|
+
* hooks: {
|
|
399
|
+
* onBuildStart: (options) => {
|
|
400
|
+
* console.log('Build started with options:', options)
|
|
401
|
+
* },
|
|
402
|
+
* onBuildDone: ({ options, output }) => {
|
|
403
|
+
* console.log('Build completed with output:', output)
|
|
404
|
+
* }
|
|
405
|
+
* }
|
|
406
|
+
* }
|
|
442
407
|
* ]
|
|
443
408
|
*/
|
|
444
409
|
plugins?: Plugin[];
|
|
@@ -446,12 +411,12 @@ interface BuildOptions {
|
|
|
446
411
|
* Customize the output file extension for each format.
|
|
447
412
|
*
|
|
448
413
|
* @param options Contains format, packageType, options, and entry information
|
|
449
|
-
* @returns Object with js
|
|
414
|
+
* @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
|
|
450
415
|
*
|
|
451
416
|
* @example
|
|
452
417
|
* outputExtension: ({ format, entry }) => ({
|
|
453
|
-
* js: entry.outputBasePath === 'worker' ? '.worker.js' : `.${format}.js
|
|
454
|
-
* dts
|
|
418
|
+
* js: entry.outputBasePath === 'worker' ? '.worker.js' : `.${format}.js`
|
|
419
|
+
* // For example, if js is '.worker.js', the dts will automatically be '.worker.d.ts'
|
|
455
420
|
* })
|
|
456
421
|
*/
|
|
457
422
|
outputExtension?: (options: {
|
|
@@ -461,7 +426,6 @@ interface BuildOptions {
|
|
|
461
426
|
entry: ProcessableEntry;
|
|
462
427
|
}) => {
|
|
463
428
|
js: string;
|
|
464
|
-
dts: string;
|
|
465
429
|
};
|
|
466
430
|
} //#endregion
|
|
467
431
|
//#region src/types.d.ts
|