bunup 0.5.7 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +12 -12
- package/dist/index.d.ts +427 -444
- package/dist/index.js +8 -8
- package/dist/plugins.d.ts +432 -448
- package/dist/plugins.js +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var fr=Object.create;var{getPrototypeOf:mr,defineProperty:ee,getOwnPropertyNames:pr}=Object;var br=Object.prototype.hasOwnProperty;var T=(e,r,t)=>{t=e!=null?fr(mr(e)):{};let n=r||!e||!e.__esModule?ee(t,"default",{value:e,enumerable:!0}):t;for(let o of pr(e))if(!br.call(n,o))ee(n,o,{get:()=>e[o],enumerable:!0});return n};var xr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var hr=(e,r)=>{for(var t in r)ee(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})};var p=(e,r)=>()=>(e&&(r=e(e=0)),r);var yr=import.meta.require;var v=xr((Jr,re)=>{var _=process||{},be=_.argv||[],F=_.env||{},wr=!(!!F.NO_COLOR||be.includes("--no-color"))&&(!!F.FORCE_COLOR||be.includes("--color")||_.platform==="win32"||(_.stdout||{}).isTTY&&F.TERM!=="dumb"||!!F.CI),Or=(e,r,t=e)=>(n)=>{let o=""+n,i=o.indexOf(r,e.length);return~i?e+Br(o,r,t,i)+r:e+o+r},Br=(e,r,t,n)=>{let o="",i=0;do o+=e.substring(i,n)+t,i=n+r.length,n=e.indexOf(r,i);while(~n);return o+e.substring(i)},xe=(e=wr)=>{let r=e?Or:()=>String;return{isColorSupported:e,reset:r("\x1B[0m","\x1B[0m"),bold:r("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:r("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:r("\x1B[3m","\x1B[23m"),underline:r("\x1B[4m","\x1B[24m"),inverse:r("\x1B[7m","\x1B[27m"),hidden:r("\x1B[8m","\x1B[28m"),strikethrough:r("\x1B[9m","\x1B[29m"),black:r("\x1B[30m","\x1B[39m"),red:r("\x1B[31m","\x1B[39m"),green:r("\x1B[32m","\x1B[39m"),yellow:r("\x1B[33m","\x1B[39m"),blue:r("\x1B[34m","\x1B[39m"),magenta:r("\x1B[35m","\x1B[39m"),cyan:r("\x1B[36m","\x1B[39m"),white:r("\x1B[37m","\x1B[39m"),gray:r("\x1B[90m","\x1B[39m"),bgBlack:r("\x1B[40m","\x1B[49m"),bgRed:r("\x1B[41m","\x1B[49m"),bgGreen:r("\x1B[42m","\x1B[49m"),bgYellow:r("\x1B[43m","\x1B[49m"),bgBlue:r("\x1B[44m","\x1B[49m"),bgMagenta:r("\x1B[45m","\x1B[49m"),bgCyan:r("\x1B[46m","\x1B[49m"),bgWhite:r("\x1B[47m","\x1B[49m"),blackBright:r("\x1B[90m","\x1B[39m"),redBright:r("\x1B[91m","\x1B[39m"),greenBright:r("\x1B[92m","\x1B[39m"),yellowBright:r("\x1B[93m","\x1B[39m"),blueBright:r("\x1B[94m","\x1B[39m"),magentaBright:r("\x1B[95m","\x1B[39m"),cyanBright:r("\x1B[96m","\x1B[39m"),whiteBright:r("\x1B[97m","\x1B[39m"),bgBlackBright:r("\x1B[100m","\x1B[49m"),bgRedBright:r("\x1B[101m","\x1B[49m"),bgGreenBright:r("\x1B[102m","\x1B[49m"),bgYellowBright:r("\x1B[103m","\x1B[49m"),bgBlueBright:r("\x1B[104m","\x1B[49m"),bgMagentaBright:r("\x1B[105m","\x1B[49m"),bgCyanBright:r("\x1B[106m","\x1B[49m"),bgWhiteBright:r("\x1B[107m","\x1B[49m")}};re.exports=xe();re.exports.createColors=xe});function D(e){ye=e??!1}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=m.default.blue;mutedColor=m.default.dim;infoColor=m.default.cyan;warnColor=m.default.yellow;errorColor=m.default.red;defaultColor=m.default.white;progressFgColorMap={ESM:m.default.yellow,CJS:m.default.green,IIFE:m.default.magenta,DTS:m.default.blue};progressBgColorMap={ESM:m.default.bgYellow,CJS:m.default.bgGreen,IIFE:m.default.bgMagenta,DTS:m.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!$.instance)$.instance=new $;return $.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({fgColor:e,bgColor:r,label:t,message:n,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?this.mutedColor(n):n,l=o?` ${r(m.default.black(` ${o} `))}`:"";return`${e(t)} ${s}${a}${l}`}output(e,r={},t=console.log){if(ye||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(e),r.verticalSpace)t("")}cli(e,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:m.default.bgBlue,label:this.labels.cli,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(e,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:m.default.bgCyan,label:this.labels.info,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(e,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:m.default.bgYellow,label:this.labels.warn,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(e,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:m.default.bgRed,label:this.labels.error,message:e,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(e){for(let[r,t]of Object.entries(this.progressFgColorMap))if(e.includes(r))return t;return this.defaultColor}getProgressBgColor(e){for(let[r,t]of Object.entries(this.progressBgColorMap))if(e.includes(r))return t;return m.default.bgWhite}progress(e,r,t={}){let n=this.getProgressFgColor(e),o=this.getProgressBgColor(e),i=this.formatMessage({fgColor:n,bgColor:o,label:e,message:r,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var m,ye=!1,g;var O=p(()=>{m=T(v(),1);g=$.getInstance()});function ne(e){return e instanceof W}var x,S,E,U,C,H,W,L=(e)=>{if(e instanceof Error)return e.message;return String(e)},Sr,te=(e,r)=>{let t=L(e),n=r?`[${r}] `:"",o=ne(e),i="ERROR";if(e instanceof E)i="BUILD ERROR";else if(e instanceof U)i="DTS ERROR";else if(e instanceof C)i="CLI ERROR";else if(e instanceof H)i="WATCH ERROR";else if(o)i="ISOLATED DECL ERROR";else if(e instanceof S)i="BUNUP ERROR";let s=Sr.find((a)=>a.pattern.test(t)&&(a.errorType===i||!a.errorType));if(!s&&!o)console.error(`${x.default.red(i)} ${n}${t}`);if(s)console.log(`
|
|
4
4
|
`),s.logSolution(t),console.log(`
|
|
5
|
-
`);else if(!o)console.error(
|
|
6
|
-
`)+
|
|
7
|
-
`);let i=t.labels[0],s=i?
|
|
8
|
-
`),console.log(
|
|
9
|
-
`),new
|
|
10
|
-
`),
|
|
11
|
-
`);return r===-1?{shebangLine:"",codeContent:
|
|
5
|
+
`);else if(!o)console.error(x.default.dim(x.default.white("If you think this is a bug, please open an issue at: ")+x.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},Ce=(e,r)=>{te(e,r),process.exit(1)};var k=p(()=>{x=T(v(),1);O();S=class S extends Error{constructor(e){super(e);this.name="BunupError"}};E=class E extends S{constructor(e){super(e);this.name="BunupBuildError"}};U=class U extends S{constructor(e){super(e);this.name="BunupDTSBuildError"}};C=class C extends S{constructor(e){super(e);this.name="BunupCLIError"}};H=class H extends S{constructor(e){super(e);this.name="BunupWatchError"}};W=class W extends S{constructor(e){super(e);this.name="BunupIsolatedDeclError"}};Sr=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{g.error(x.default.white("You're trying to build a project that uses Bun. ")+x.default.white("Please set the target option to ")+x.default.cyan("`bun`")+x.default.white(`.
|
|
6
|
+
`)+x.default.white("Example: ")+x.default.green("`bunup --target bun`")+x.default.white(" or in config: ")+x.default.green("{ target: 'bun' }"))}}]});import we from"fs/promises";import Er from"path";function Oe(e,r,t){return Array.isArray(e)?e.map((n)=>({...n,[r]:t})):{...e,[r]:t}}function Be(e){return Array.isArray(e)?e:[e]}function Se(e,r){switch(e){case"esm":return I(r)?".js":".mjs";case"cjs":return I(r)?".cjs":".js";case"iife":return".global.js"}}function Ee(e,r){switch(e){case"esm":return I(r)?".d.ts":".d.mts";case"cjs":return I(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function oe(e){return e==="node"||e==="bun"}function I(e){return e==="module"}function Y(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function Le(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function M(e,r=3){return e.split("/").slice(-r).join("/")}async function ke(e,r){let t=Er.join(e,r);try{await we.rm(t,{recursive:!0,force:!0})}catch(n){throw new E(`Failed to clean output directory: ${n}`)}await we.mkdir(t,{recursive:!0})}var B=p(()=>{k()});function Lr(e){return Le(e).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function Me(e,r){return typeof r==="string"?r===e:r.test(e)}function ie(e,r,t){let o=Lr(t).some((s)=>s.test(e))||r.external?.some((s)=>Me(e,s)),i=r.noExternal?.some((s)=>Me(e,s));return o&&!i}var se=p(()=>{B()});function P(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function G(e){return[".ts",".mts",".cts",".tsx"].some((r)=>e.endsWith(r))&&!P(e)}function q(e){if(P(e))return e;if(e.endsWith(".mts"))return`${e.slice(0,-4)}.d.mts`;if(e.endsWith(".cts"))return`${e.slice(0,-4)}.d.cts`;if(Re.test(e))return e.replace(Re,".d.ts");return`${e}.d.ts`}var Te,ve,Re;var K=p(()=>{se();Te=/\.(d\.ts|d\.mts|d\.cts|ts|mts|cts|tsx)$/,ve=/[\\/]node_modules[\\/]/,Re=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import{basename as kr,dirname as Mr,extname as Rr}from"path";function N(e){let r=kr(e),t=Rr(r);return t?r.slice(0,-t.length):r}function j(e){if(typeof e==="string")return[{fullPath:e,outputBasePath:N(e)}];if(typeof e==="object"&&!Array.isArray(e))return Object.entries(e).map(([n,o])=>({fullPath:o,outputBasePath:n}));let r=[],t=new Set;for(let n of e){let o=N(n);if(!t.has(o)){r.push({fullPath:n,outputBasePath:o}),t.add(o);continue}let s=Mr(n).split("/").filter((l)=>l!=="."&&l!=="");if(s.length===0){let l=1,c;do c=`${o}_${l++}`;while(t.has(c));r.push({fullPath:n,outputBasePath:c}),t.add(c);continue}let a=!1;for(let l=1;l<=s.length&&!a;l++){let d=`${s.slice(-l).join("/")}/${o}`;if(!t.has(d))r.push({fullPath:n,outputBasePath:d}),t.add(d),a=!0}if(!a){let l=1,c;do c=`${s.join("/")}/${o}_${l++}`;while(t.has(c));r.push({fullPath:n,outputBasePath:c}),t.add(c)}}return r}function $e(e){return e.filter((r)=>G(r.fullPath))}function Ie(e,r){return`[dir]/${e}${r}`}function je(e){return`${e}-[hash].[ext]`}function Ae(e){return`${e}-[name]-[hash].[ext]`}var X=p(()=>{K()});import Ir from"path";import{loadConfig as De}from"coffi";async function Ue(e,r,t){return Array.isArray(e)&&"root"in e[0]?e.filter((n)=>t?t.includes(n.name):!0).map((n)=>({rootDir:Ir.resolve(r,n.root),options:Oe(n.config,"name",n.name)})):[{rootDir:r,options:e}]}async function He(e){let{config:r,filepath:t}=await De({name:"package",cwd:e,extensions:[".json"]});return{packageJson:r,path:t}}async function We(e,r){let{config:t,filepath:n}=await De({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:n}}var le=p(()=>{B()});import{isolatedDeclaration as jr}from"oxc-transform";async function Pe(e){try{let r=await Bun.file(e).text(),{code:t,errors:n}=jr(e,r);for(let o of n)Ye.push({error:o,sourceText:r,tsFile:e});return t}catch(r){return console.log(r),g.warn(`Failed to generate declaration for ${e}: ${L(r)}`),null}}function Ge(e){let r=!1;for(let{error:t,sourceText:n,tsFile:o}of Ye){if(!r&&!e)console.log(`
|
|
7
|
+
`);let i=t.labels[0],s=i?Ar(n,i.start):"",l=`${M(o)}${s}: ${Fr(t.message)}`;g[e?"warn":"error"](l),r=!0}if(r&&!e)throw console.log(`
|
|
8
|
+
`),console.log(ce.default.gray(`See ${ce.default.blue("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")} for details.`)),console.log(`
|
|
9
|
+
`),new W}function Ar(e,r){if(r===void 0)return"";let t=e.slice(0,r).split(`
|
|
10
|
+
`),n=t.length,o=t[t.length-1].length+1;return` (${n}:${o})`}function Fr(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var ce,Ye;var ge=p(()=>{ce=T(v(),1);k();O();B();Ye=[]});import{resolveTsImportPath as _r}from"ts-import-resolver";var qe=(e,r,t)=>{let n=new Map;return{name:"bunup:virtual-dts",async resolveId(o,i){if(i===void 0)return n.set(o,e),o;let s=_r({path:o,importer:i,tsconfig:r.tsconfig,rootDir:t});if(!s||!G(s))return null;let a=q(s);if(!a)return null;return n.set(a,s),a},load:{filter:{id:{include:[Te],exclude:[ve]}},async handler(o){if(P(o)){let i=n.get(o);if(!i)return null;let s=await Pe(i);if(!s)return null;return{code:s,moduleSideEffects:!1}}return null}},buildEnd(){n.clear()}}};var Ke=p(()=>{ge();K()});import{build as Dr}from"rolldown";import{dts as Ur}from"rolldown-plugin-dts";import Hr from"path";async function Ne(e,r,t,n){let o=Hr.resolve(n,e),i=q(o),s=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,{output:a}=await Dr({input:i,write:!1,...t.path&&{resolve:{tsconfigFilename:t.path}},onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[qe(o,t,n),Ur({dtsInput:!0,emitDtsOnly:!0,resolve:s})]});Ge(!!r.watch);let l=a[0]?.code;if(!l)return g.warn(`Generated empty declaration file for entry "${o}"`,{muted:!0}),"";return l}var Xe=p(()=>{O();ge();K();Ke()});function Z(e){return{...Wr,...e}}function Ve(e){let{minify:r,minifyWhitespace:t,minifyIdentifiers:n,minifySyntax:o}=e,i=r===!0;return{whitespace:t??i,identifiers:n??i,syntax:o??i}}function Qe(e,r){return r==="cjs"?e:void 0}function Ze(e){if(e===!0)return"inline";return typeof e==="string"?e:void 0}function ze(e,r,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},{}),...e,...n==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Je(e,r){return e===void 0?r==="esm":e}function er(e){return typeof e==="string"?e:void 0}var Wr;var de=p(()=>{Wr={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function rr(e,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(n)=>{let o=n.path;if(ie(o,e,r))return{path:o,external:!0};return null})}}}var nr=p(()=>{se()});function tr({format:e,target:r,shims:t}){let o=Pr(t).map((i)=>ue[i]).filter((i)=>i.appliesTo(e,r));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Yr},async({path:s})=>{let a=await Bun.file(s).text(),l=o.filter((f)=>f.isNeededInFile(a));if(l.length===0)return;let{shebangLine:c,codeContent:d}=Gr(a),u=l.map((f)=>f.generateCode()).join("");return{contents:c+u+d}})}}}function Pr(e){if(e===!0)return Object.keys(ue);if(!e)return[];return Object.entries(e).filter(([r,t])=>t&&(r in ue)).map(([r])=>r)}function Gr(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let r=e.indexOf(`
|
|
11
|
+
`);return r===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,r+1),codeContent:e.slice(r+1)}}var Yr,ue;var or=p(()=>{B();Yr=/\.(js|ts|jsx|tsx|mts|cts)$/,ue={dirnameFilename:{appliesTo:(e,r)=>e==="esm"&&oe(r),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
12
12
|
import { dirname } from 'path';
|
|
13
13
|
|
|
14
14
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
15
|
const __dirname = dirname(__filename);
|
|
16
16
|
|
|
17
|
-
`},importMetaUrl:{appliesTo:(
|
|
17
|
+
`},importMetaUrl:{appliesTo:(e,r)=>e==="cjs"&&oe(r),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
18
18
|
|
|
19
19
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
20
20
|
|
|
21
|
-
`}}});function
|
|
21
|
+
`}}});function ir(e){if(!e)return[];return e.filter((r)=>r.type==="bun")}function sr(e){if(!e)return[];return e.filter((r)=>r.type==="bunup")}async function ar(e,r){if(!e)return;for(let t of e)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(r)}async function lr(e,r,t){if(!e)return;for(let n of e)if(n.hooks.onBuildDone)await n.hooks.onBuildDone({options:r,output:t})}var gr={};hr(gr,{build:()=>fe});async function fe(e,r=process.cwd()){let t={files:[]},n=Z(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)ke(r,n.outDir);D(n.silent);let{packageJson:o,path:i}=await He(r);if(o&&i)g.cli(`Using ${M(i,2)}`,{muted:!0,identifier:n.name,once:`${i}:${n.name}`});let s=sr(n.plugins);await ar(s,n);let a=j(n.entry),l=o?.type;if(!n.dtsOnly){let c=[rr(n,o),...ir(n.plugins).map((u)=>u.plugin)],d=n.format.flatMap((u)=>a.map(async(f)=>{let R=n.outputExtension?.({format:u,packageType:l,options:n,entry:f}).js??Se(u,l),y=await Bun.build({entrypoints:[`${r}/${f.fullPath}`],format:u,naming:{entry:Ie(f.outputBasePath,R),chunk:je(f.outputBasePath),asset:Ae(f.outputBasePath)},splitting:Je(n.splitting,u),bytecode:Qe(n.bytecode,u),define:ze(n.define,n.shims,n.env,u),minify:Ve(n),outdir:`${r}/${n.outDir}`,target:n.target,sourcemap:Ze(n.sourcemap),loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer,publicPath:n.publicPath,env:er(n.env),plugins:[...c,tr({format:u,target:n.target,shims:n.shims})],throw:!1});if(!y.success)for(let b of y.logs){if(b.level==="error")throw new E(b.message);if(b.level==="warning")g.warn(b.message);else if(b.level==="info")g.info(b.message)}for(let b of y.outputs)t.files.push({fullPath:b.path,relativePathToRootDir:b.path.replace(`${r}/`,"")});let J=cr(n.outDir,f.outputBasePath,R);g.progress(u.toUpperCase(),J,{identifier:n.name})}));await Promise.all(d)}if(n.dts||n.dtsOnly){let c=await We(r,n.preferredTsconfigPath);if(c.path)g.cli(`Using ${M(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let d=n.format.filter((f)=>{if(f==="iife"&&!I(l)&&n.format.includes("cjs"))return!1;return!0}),u=typeof n.dts==="object"&&n.dts.entry?j(n.dts.entry):$e(a);try{await Promise.all(u.map(async(f)=>{let R=await Ne(f.fullPath,n,c,r);await Promise.all(d.map(async(y)=>{let J=n.outputExtension?.({format:y,packageType:l,options:n,entry:f}).dts??Ee(y,l),b=cr(n.outDir,f.outputBasePath,J),pe=Kr(r,b);t.files.push({fullPath:pe,relativePathToRootDir:b}),await Bun.write(pe,R),g.progress("DTS",b,{identifier:n.name})}))}))}catch(f){if(ne(f))throw f;throw new U(L(f))}}if(await lr(s,n,t),n.onSuccess)await n.onSuccess(n)}function cr(e,r,t){return`${e}/${r}${t}`}function Kr(e,r){return`${e}/${r}`}var me=p(()=>{Xe();k();X();le();O();de();nr();or();B()});import{exec as Nr}from"tinyexec";var A="0.5.10";var ae=T(v(),1);var he="https://bunup.dev/docs/guide/cli-options";k();X();O();function h(e){return(r,t)=>{t[e]=r===!0||r==="true"}}function w(e){return(r,t)=>{if(typeof r==="string")t[e]=r;else throw new C(`Option --${e} requires a string value`)}}function V(e){return(r,t)=>{if(typeof r==="string")t[e]=r.split(",");else throw new C(`Option --${e} requires a string value`)}}function Tr(e){return(r,t)=>{if(typeof r==="boolean")t[e]=r;else if(typeof r==="string")if(r.toLowerCase()==="true"||r.toLowerCase()==="false")t[e]=r.toLowerCase()==="true";else t[e]=r;else throw new C(`Option --${e} requires a boolean or string value`)}}function vr(){console.log(`
|
|
22
22
|
Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
|
|
23
|
-
`),console.log("For more information on available options, visit:"),console.log(`${
|
|
24
|
-
`),process.exit(0)}function
|
|
23
|
+
`),console.log("For more information on available options, visit:"),console.log(`${ae.default.cyan(ae.default.underline(he))}
|
|
24
|
+
`),process.exit(0)}function $r(){console.log(A),process.exit(0)}var Fe={name:{flags:["n","name"],handler:w("name")},format:{flags:["f","format"],handler:V("format")},outDir:{flags:["o","out-dir"],handler:w("outDir")},minify:{flags:["m","minify"],handler:h("minify")},watch:{flags:["w","watch"],handler:h("watch")},dts:{flags:["d","dts"],handler:h("dts")},banner:{flags:["bn","banner"],handler:w("banner")},footer:{flags:["ft","footer"],handler:w("footer")},external:{flags:["e","external"],handler:V("external")},sourcemap:{flags:["sm","sourcemap"],handler:Tr("sourcemap")},target:{flags:["t","target"],handler:w("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:h("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:h("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:h("minifySyntax")},clean:{flags:["c","clean"],handler:h("clean")},splitting:{flags:["s","splitting"],handler:h("splitting")},noExternal:{flags:["ne","no-external"],handler:V("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:w("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:h("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:h("dtsOnly")},silent:{flags:["silent"],handler:h("silent")},config:{flags:["config"],handler:w("config")},publicPath:{flags:["pp","public-path"],handler:w("publicPath")},env:{flags:["env"],handler:w("env")},shims:{flags:["shims"],handler:h("shims")},onSuccess:{flags:["onSuccess"],handler:w("onSuccess")},filter:{flags:["filter"],handler:V("filter")},entry:{flags:["entry"],handler:(e,r,t)=>{if(typeof e!=="string")throw new C(`Entry${t?` --entry.${t}`:""} requires a string value`);let n=r.entry||{};if(t){if(n[t])g.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);n[t]=e}else{let o=N(e);if(n[o])g.warn(`Duplicate entry name '${o}' derived from '${e}'. Overwriting previous entry.`);n[o]=e}r.entry=n}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,r)=>{if(!r.dts)r.dts={};if(typeof r.dts==="boolean")r.dts={};if(typeof e==="string")if(e==="true"||e==="false")r.dts.resolve=e==="true";else r.dts.resolve=e.split(",");else r.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>vr()},version:{flags:["v","version"],handler:()=>$r()}},Q={};for(let e of Object.values(Fe))for(let r of e.flags)Q[r]=e.handler;function _e(e){let r={};for(let t=0;t<e.length;t++){let n=e[t];if(n.startsWith("--")){let o,i;if(n.includes("=")){let[s,a]=n.slice(2).split("=",2);o=s,i=a}else{o=n.slice(2);let s=e[t+1];if(i=s&&!s.startsWith("-")?s:!0,typeof i==="string")t++}if(o.includes(".")){let[s,a]=o.split(".",2),l=Q[s];if(l)l(i,r,a);else throw new C(`Unknown option: --${o}`)}else{let s=Q[o];if(s)s(i,r);else throw new C(`Unknown option: --${o}`)}}else if(n.startsWith("-")){let o=n.slice(1),i=e[t+1],s=i&&!i.startsWith("-")?i:!0;if(typeof s==="string")t++;let a=Q[o];if(a)a(s,r);else throw new C(`Unknown option: -${o}`)}else Fe.entry.handler(n,r,void 0)}return r}k();O();var ur=T(v(),1);le();B();import{loadConfig as Xr}from"coffi";me();k();X();O();de();B();import z from"path";async function dr(e,r){let t=new Set,n=Z(e),o=j(n.entry);for(let c of o){let d=z.resolve(r,c.fullPath),u=z.dirname(d);t.add(u)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,z.join(r,n.outDir)]}),a=!1,l=async(c=!1)=>{if(a)return;a=!0;try{let d=performance.now();if(await fe({...n,entry:o.map((u)=>u.fullPath),clean:!1},r),!c)g.cli(`\uD83D\uDCE6 Rebuild finished in ${Y(performance.now()-d)}`)}catch(d){te(d)}finally{a=!1}};s.on("change",(c)=>{let d=z.relative(r,c);g.cli(`File changed: ${d}`,{muted:!0,once:d}),l()}),s.on("error",(c)=>{throw new H(`Watcher error: ${L(c)}`)}),await l(!0)}async function Vr(e=Bun.argv.slice(2)){let r=_e(e);D(r.silent);let t=process.cwd(),{config:n,filepath:o}=await Xr({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:r.config,packageJsonProperty:"bunup"}),i=!n?[{rootDir:t,options:r}]:await Ue(n,t,r.filter);if(g.cli(`Using bunup v${A} and bun v${Bun.version}`,{muted:!0}),o)g.cli(`Using ${M(o,2)}`,{muted:!0});let s=performance.now();g.cli("Build started");let{build:a}=await Promise.resolve().then(() => (me(),gr));await Promise.all(i.flatMap(({options:d,rootDir:u})=>{return Be(d).map(async(R)=>{let y={...R,...Qr(r)};if(y.watch)await dr(y,u);else await a(y,u)})}));let l=performance.now()-s,c=Y(l);if(g.cli(`\u26A1\uFE0F Build completed in ${ur.default.green(c)}`),r.watch)g.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)g.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await Nr(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function Qr(e){return{...e,onSuccess:void 0,config:void 0}}Vr().catch((e)=>Ce(e));
|