bunup 0.5.6 → 0.5.7
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/LICENSE +1 -1
- package/dist/cli.js +12 -12
- package/dist/index.js +7 -7
- package/package.json +60 -58
package/LICENSE
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var Sr=Object.create;var{getPrototypeOf:Lr,defineProperty:sn,getOwnPropertyNames:kr}=Object;var Mr=Object.prototype.hasOwnProperty;var F=(n,r,t)=>{t=n!=null?Sr(Lr(n)):{};let e=r||!n||!n.__esModule?sn(t,"default",{value:n,enumerable:!0}):t;for(let o of kr(n))if(!Mr.call(e,o))sn(e,o,{get:()=>n[o],enumerable:!0});return e};var $r=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var Er=(n,r)=>{for(var t in r)sn(n,t,{get:r[t],enumerable:!0,configurable:!0,set:(e)=>r[t]=()=>e})};var p=(n,r)=>()=>(n&&(r=n(n=0)),r);var Tr=import.meta.require;var U=$r((ce,an)=>{var Y=process||{},Sn=Y.argv||[],v=Y.env||{},jr=!(!!v.NO_COLOR||Sn.includes("--no-color"))&&(!!v.FORCE_COLOR||Sn.includes("--color")||Y.platform==="win32"||(Y.stdout||{}).isTTY&&v.TERM!=="dumb"||!!v.CI),Ir=(n,r,t=n)=>(e)=>{let o=""+e,i=o.indexOf(r,n.length);return~i?n+Ar(o,r,t,i)+r:n+o+r},Ar=(n,r,t,e)=>{let o="",i=0;do o+=n.substring(i,e)+t,i=e+r.length,e=n.indexOf(r,i);while(~e);return o+n.substring(i)},Ln=(n=jr)=>{let r=n?Ir:()=>String;return{isColorSupported:n,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")}};an.exports=Ln();an.exports.createColors=Ln});function G(n){Mn=n??!1}class T{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(!T.instance)T.instance=new T;return T.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({fgColor:n,bgColor:r,label:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),l=i?this.mutedColor(e):e,a=o?` ${r(m.default.black(` ${o} `))}`:"";return`${n(t)} ${s}${l}${a}`}output(n,r={},t=console.log){if(Mn||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(n),r.verticalSpace)t("")}cli(n,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:m.default.bgBlue,label:this.labels.cli,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(n,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:m.default.bgCyan,label:this.labels.info,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(n,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:m.default.bgYellow,label:this.labels.warn,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(n,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:m.default.bgRed,label:this.labels.error,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(n){for(let[r,t]of Object.entries(this.progressFgColorMap))if(n.includes(r))return t;return this.defaultColor}getProgressBgColor(n){for(let[r,t]of Object.entries(this.progressBgColorMap))if(n.includes(r))return t;return m.default.bgWhite}progress(n,r,t={}){let e=this.getProgressFgColor(n),o=this.getProgressBgColor(n),i=this.formatMessage({fgColor:e,bgColor:o,label:n,message:r,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var m,Mn=!1,g;var B=p(()=>{m=F(U(),1);g=T.getInstance()});function ln(n){return n instanceof D}var b,S,L,K,h,q,D,k=(n)=>{if(n instanceof Error)return n.message;return String(n)},Fr,cn=(n,r)=>{let t=k(n),e=r?`[${r}] `:"",o=ln(n),i="ERROR";if(n instanceof L)i="BUILD ERROR";else if(n instanceof K)i="DTS ERROR";else if(n instanceof h)i="CLI ERROR";else if(n instanceof q)i="WATCH ERROR";else if(o)i="ISOLATED DECL ERROR";else if(n instanceof S)i="BUNUP ERROR";let s=Fr.find((l)=>l.pattern.test(t)&&(l.errorType===i||!l.errorType));if(!s&&!o)console.error(`${b.default.red(i)} ${e}${t}`);if(s)console.log(`
|
|
4
4
|
`),s.logSolution(t),console.log(`
|
|
5
|
-
`);else if(!o)console.error(b.default.dim(b.default.white("If you think this is a bug, please open an issue at: ")+b.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$n=(n,r)=>{cn(n,r),process.exit(1)};var
|
|
6
|
-
`)+b.default.white("Example: ")+b.default.green("`bunup --target bun`")+b.default.white(" or in config: ")+b.default.green("{ target: 'bun' }"))}}]});import
|
|
7
|
-
`)
|
|
8
|
-
`)
|
|
9
|
-
`),
|
|
10
|
-
`),
|
|
11
|
-
`);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var
|
|
5
|
+
`);else if(!o)console.error(b.default.dim(b.default.white("If you think this is a bug, please open an issue at: ")+b.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$n=(n,r)=>{cn(n,r),process.exit(1)};var M=p(()=>{b=F(U(),1);B();S=class S extends Error{constructor(n){super(n);this.name="BunupError"}};L=class L extends S{constructor(n){super(n);this.name="BunupBuildError"}};K=class K extends S{constructor(n){super(n);this.name="BunupDTSBuildError"}};h=class h extends S{constructor(n){super(n);this.name="BunupCLIError"}};q=class q extends S{constructor(n){super(n);this.name="BunupWatchError"}};D=class D extends S{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};Fr=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{g.error(b.default.white("You're trying to build a project that uses Bun. ")+b.default.white("Please set the target option to ")+b.default.cyan("`bun`")+b.default.white(`.
|
|
6
|
+
`)+b.default.white("Example: ")+b.default.green("`bunup --target bun`")+b.default.white(" or in config: ")+b.default.green("{ target: 'bun' }"))}}]});import En from"fs/promises";import Ur from"path";function Tn(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function Rn(n){return Array.isArray(n)?n:[n]}function jn(n,r){switch(n){case"esm":return R(r)?".js":".mjs";case"cjs":return R(r)?".cjs":".js";case"iife":return".global.js"}}function In(n,r){switch(n){case"esm":return R(r)?".d.ts":".d.mts";case"cjs":return R(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function gn(n){return n==="node"||n==="bun"}function R(n){return n==="module"}function Q(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function An(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function $(n,r=3){return n.split("/").slice(-r).join("/")}async function Fn(n,r){let t=Ur.join(n,r);try{await En.rm(t,{recursive:!0,force:!0})}catch(e){throw new L(`Failed to clean output directory: ${e}`)}await En.mkdir(t,{recursive:!0})}var O=p(()=>{M()});function _r(n){return An(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function Un(n,r){return typeof r==="string"?r===n:r.test(n)}function X(n,r,t){let o=_r(t).some((s)=>s.test(n))||r.external?.some((s)=>Un(n,s)),i=r.noExternal?.some((s)=>Un(n,s));return o&&!i}var un=p(()=>{O()});import{isolatedDeclaration as Wr}from"oxc-transform";async function Wn(n){try{let r=await Bun.file(n).text(),{code:t,errors:e}=Wr(n,r);for(let o of e)_n.push({error:o,sourceText:r,tsFile:n});return t}catch(r){return console.log(r),g.warn(`Failed to generate declaration for ${n}: ${k(r)}`),null}}function Hn(n){let r=!1;for(let{error:t,sourceText:e,tsFile:o}of _n){if(!r&&!n)console.log(`
|
|
7
|
+
`);let i=t.labels[0],s=i?Hr(e,i.start):"",a=`${$(o)}${s}: ${vr(t.message)}`;g[n?"warn":"error"](a),r=!0}if(r&&!n)throw console.log(`
|
|
8
|
+
`),console.log(dn.default.gray(`See ${dn.default.blue("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")} for details.`)),console.log(`
|
|
9
|
+
`),new D}function Hr(n,r){if(r===void 0)return"";let t=n.slice(0,r).split(`
|
|
10
|
+
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function vr(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var dn,_n;var mn=p(()=>{dn=F(U(),1);M();B();O();_n=[]});import{resolveTsImportPath as Yr}from"ts-import-resolver";var N="\x00dts:",vn=(n,r,t)=>{let e=new Map;return{name:"bunup:virtual-dts",async resolveId(o,i){if(Z(o))return e.set(o,n),o;if(!i||!Z(i))return null;let s=r.tsconfig?Yr({path:o,importer:z(i),tsconfig:r.tsconfig,rootDir:t}):null;if(!s||!V(s))return null;let l=j(s);if(!l)return null;let a=J(l);return e.set(a,s),a},load:{filter:{id:{include:[Yn],exclude:[Gn]}},async handler(o){if(Z(o)){let i=e.get(o);if(!i)return null;let s=await Wn(i);if(!s)return null;return{code:s,moduleSideEffects:!1}}return null}},buildEnd(){e.clear()}}};var fn=p(()=>{mn();_()});function bn(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function Kn(n){return pn.test(n)&&!bn(n)}function V(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))&&!bn(n)}function j(n){if(bn(n))return n;if(n.endsWith(".mts"))return`${n.slice(0,-4)}.d.mts`;if(n.endsWith(".cts"))return`${n.slice(0,-4)}.d.cts`;if(pn.test(n))return n.replace(pn,".d.ts");return`${n}.d.ts`}function Z(n){return n.startsWith(N)}function z(n){return n.replace(N,"")}function J(n){return`${N}${n}`}function qn(n,r,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let o of e)if(typeof o==="string"&&n===o)return!1;else if(o instanceof RegExp&&o.test(n))return!1}return X(n,r,t)}var Yn,Gn,pn;var _=p(()=>{un();fn();Yn=/\.(d\.ts|d\.mts|d\.cts|ts|mts|cts|tsx)$/,Gn=/[\\/]node_modules[\\/]/,pn=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import{basename as Gr,dirname as Kr,extname as qr}from"path";function P(n){let r=Gr(n),t=qr(r);return t?r.slice(0,-t.length):r}function W(n){if(typeof n==="string")return[{fullEntryPath:n,name:P(n)}];if(typeof n==="object"&&!Array.isArray(n))return Object.entries(n).map(([e,o])=>({fullEntryPath:o,name:e}));let r=[],t=new Set;for(let e of n){let o=P(e);if(!t.has(o)){r.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=Kr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,c;do c=`${o}_${a++}`;while(t.has(c));r.push({fullEntryPath:e,name:c}),t.add(c);continue}let l=!1;for(let a=1;a<=s.length&&!l;a++){let u=`${s.slice(-a).join("/")}/${o}`;if(!t.has(u))r.push({fullEntryPath:e,name:u}),t.add(u),l=!0}if(!l){let a=1,c;do c=`${s.join("/")}/${o}_${a++}`;while(t.has(c));r.push({fullEntryPath:e,name:c}),t.add(c)}}return r}function Dn(n){return n.filter((r)=>V(r.fullEntryPath))}function Qn(n,r){return`[dir]/${n}${r}`}var nn=p(()=>{_()});import Zr from"path";import{loadConfig as Nn}from"coffi";async function Vn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:Zr.resolve(r,e.root),options:Tn(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function zn(n){let{config:r,filepath:t}=await Nn({name:"package",cwd:n,extensions:[".json"]});return{packageJson:r,path:t}}async function Jn(n,r){let{config:t,filepath:e}=await Nn({name:"tsconfig",cwd:n,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:e}}var hn=p(()=>{O()});import Pn from"path";import{ResolverFactory as Nr}from"oxc-resolver";function nr(n,r){return{name:"bunup:types-resolve",buildStart(){Cn||=new Nr({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...n.path&&{tsconfig:{configFile:n.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(r===!1)return;if(t==="bun")return;let o=e?z(e):void 0;if(/\0/.test(t))return;if(Array.isArray(r)){if(!r.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let i=o?Pn.dirname(o):process.cwd(),{path:s}=await Cn.async(i,t);if(!s)return;if(Kn(s)){let l=j(s);try{let{path:a}=await Cn.async(Pn.dirname(s),l);if(a)return a}catch(a){}return}return s}}}var Cn;var rr=p(()=>{_()});import{build as Vr}from"rolldown";import{dts as zr}from"rolldown-plugin-dts";async function er(n,r,t,e,o){let i=j(n),s=J(i),l=typeof r.dts==="object"&&"resolve"in r.dts?r.dts.resolve:void 0,{output:a}=await Vr({input:s,write:!1,...e.path&&{resolve:{tsconfigFilename:e.path}},onwarn(u,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;d(u)},plugins:[vn(n,e,o),l&&nr(e,l),zr({dtsInput:!0,emitDtsOnly:!0})],external:(u)=>qn(u,r,t,l)});Hn(!!r.watch);let c=a[0]?.code;if(!c)return g.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return c}var tr=p(()=>{B();rr();mn();_();fn()});import or from"path";async function ir(n,r,t,e,o){let i=or.resolve(or.resolve(n),r);return er(i,t,o,e,n)}var sr=p(()=>{tr()});function tn(n){return{...Jr,...n}}function ar(n){let{minify:r,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=n,i=r===!0;return{whitespace:t??i,identifiers:e??i,syntax:o??i}}function lr(n,r){return r==="cjs"?n:void 0}function cr(n,r,t,e){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},{}),...n,...e==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function gr(n,r){return n===void 0?r==="esm":n}function ur(n){return typeof n==="string"?n:void 0}var Jr;var wn=p(()=>{Jr={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function dr(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(X(o,n,r))return{path:o,external:!0};return null})}}}var mr=p(()=>{un()});function fr({format:n,target:r,shims:t}){let o=ne(t).map((i)=>yn[i]).filter((i)=>i.appliesTo(n,r));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Pr},async({path:s})=>{let l=await Bun.file(s).text(),a=o.filter((f)=>f.isNeededInFile(l));if(a.length===0)return;let{shebangLine:c,codeContent:u}=re(l),d=a.map((f)=>f.generateCode()).join("");return{contents:c+d+u}})}}}function ne(n){if(n===!0)return Object.keys(yn);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in yn)).map(([r])=>r)}function re(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
|
|
11
|
+
`);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var Pr,yn;var pr=p(()=>{O();Pr=/\.(js|ts|jsx|tsx|mts|cts)$/,yn={dirnameFilename:{appliesTo:(n,r)=>n==="esm"&&gn(r),isNeededInFile:(n)=>/\b__dirname\b/.test(n)||/\b__filename\b/.test(n),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:(n,r)=>n==="cjs"&&
|
|
17
|
+
`},importMetaUrl:{appliesTo:(n,r)=>n==="cjs"&&gn(r),isNeededInFile:(n)=>/\bimport\.meta\.url\b/.test(n),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
18
18
|
|
|
19
19
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
20
20
|
|
|
21
|
-
`}}});function
|
|
21
|
+
`}}});function br(n){if(!n)return[];return n.filter((r)=>r.type==="bun")}function xr(n){if(!n)return[];return n.filter((r)=>r.type==="bunup")}async function hr(n,r){if(!n)return;for(let t of n)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(r)}async function Cr(n,r,t){if(!n)return;for(let e of n)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:r,output:t})}var Br={};Er(Br,{build:()=>Bn});async function Bn(n,r=process.cwd()){let t={files:[]},e=tn(n);if(!e.entry||e.entry.length===0||!e.outDir)throw new L("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)Fn(r,e.outDir);G(e.silent);let{packageJson:o,path:i}=await zn(r);if(o&&i)g.cli(`Using ${$(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=xr(e.plugins);await hr(s,e);let l=W(e.entry),a=o?.type;if(!e.dtsOnly){let c=[dr(e,o),...br(e.plugins).map((d)=>d.plugin)],u=e.format.flatMap((d)=>l.map(async(f)=>{let E=e.outputExtension?.({format:d,packageType:a,options:e,entry:f}).js??jn(d,a),w=await Bun.build({entrypoints:[`${r}/${f.fullEntryPath}`],format:d,naming:{entry:Qn(f.name,E)},splitting:gr(e.splitting,d),bytecode:lr(e.bytecode,d),define:cr(e.define,e.shims,e.env,d),minify:ar(e),outdir:`${r}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:ur(e.env),plugins:[...c,fr({format:d,target:e.target,shims:e.shims})],throw:!1});if(!w.success)for(let y of w.logs){if(y.level==="error")throw new L(y.message);if(y.level==="warning")g.warn(y.message);else if(y.level==="info")g.info(y.message)}let I=wr(e.outDir,f.name,E),A=yr(r,I);t.files.push({fullPath:A,relativePathToOutputDir:I}),g.progress(d.toUpperCase(),I,{identifier:e.name})}));await Promise.all(u)}if(e.dts||e.dtsOnly){let c=await Jn(r,e.preferredTsconfigPath);if(c.path)g.cli(`Using ${$(c.path,2)}`,{muted:!0,identifier:e.name,once:`${c.path}:${e.name}`});let u=e.format.filter((f)=>{if(f==="iife"&&!R(a)&&e.format.includes("cjs"))return!1;return!0}),d=typeof e.dts==="object"&&e.dts.entry?W(e.dts.entry):Dn(l);try{await Promise.all(d.map(async(f)=>{let E=await ir(r,f.fullEntryPath,e,c,o);await Promise.all(u.map(async(w)=>{let I=e.outputExtension?.({format:w,packageType:a,options:e,entry:f}).dts??In(w,a),A=wr(e.outDir,f.name,I),y=yr(r,A);t.files.push({fullPath:y,relativePathToOutputDir:A}),await Bun.write(y,E),g.progress("DTS",A,{identifier:e.name})}))}))}catch(f){if(ln(f))throw f;throw new K(k(f))}}if(await Cr(s,e,t),e.onSuccess)await e.onSuccess(e)}function wr(n,r,t){return`${n}/${r}${t}`}function yr(n,r){return`${n}/${r}`}var On=p(()=>{sr();M();nn();hn();B();wn();mr();pr();O()});import{exec as te}from"tinyexec";var H="0.5.7";var xn=F(U(),1);var kn="https://bunup.dev/docs/guide/cli-options";M();nn();B();function x(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function C(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new h(`Option --${n} requires a string value`)}}function rn(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new h(`Option --${n} requires a string value`)}}function Dr(n){return(r,t)=>{if(typeof r==="boolean")t[n]=r;else if(typeof r==="string")if(r.toLowerCase()==="true"||r.toLowerCase()==="false")t[n]=r.toLowerCase()==="true";else t[n]=r;else throw new h(`Option --${n} requires a boolean or string value`)}}function Qr(){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(`${xn.default.cyan(xn.default.underline(kn))}
|
|
24
|
+
`),process.exit(0)}function Xr(){console.log(H),process.exit(0)}var Xn={name:{flags:["n","name"],handler:C("name")},format:{flags:["f","format"],handler:rn("format")},outDir:{flags:["o","out-dir"],handler:C("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:C("banner")},footer:{flags:["ft","footer"],handler:C("footer")},external:{flags:["e","external"],handler:rn("external")},sourcemap:{flags:["sm","sourcemap"],handler:Dr("sourcemap")},target:{flags:["t","target"],handler:C("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:rn("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:C("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:C("config")},publicPath:{flags:["pp","public-path"],handler:C("publicPath")},env:{flags:["env"],handler:C("env")},shims:{flags:["shims"],handler:x("shims")},onSuccess:{flags:["onSuccess"],handler:C("onSuccess")},filter:{flags:["filter"],handler:rn("filter")},entry:{flags:["entry"],handler:(n,r,t)=>{if(typeof n!=="string")throw new h(`Entry${t?` --entry.${t}`:""} requires a string value`);let e=r.entry||{};if(t){if(e[t])g.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);e[t]=n}else{let o=P(n);if(e[o])g.warn(`Duplicate entry name '${o}' derived from '${n}'. Overwriting previous entry.`);e[o]=n}r.entry=e}},resolveDts:{flags:["rd","resolve-dts"],handler:(n,r)=>{if(!r.dts)r.dts={};if(typeof r.dts==="boolean")r.dts={};if(typeof n==="string")if(n==="true"||n==="false")r.dts.resolve=n==="true";else r.dts.resolve=n.split(",");else r.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>Qr()},version:{flags:["v","version"],handler:()=>Xr()}},en={};for(let n of Object.values(Xn))for(let r of n.flags)en[r]=n.handler;function Zn(n){let r={};for(let t=0;t<n.length;t++){let e=n[t];if(e.startsWith("--")){let o,i;if(e.includes("=")){let[s,l]=e.slice(2).split("=",2);o=s,i=l}else{o=e.slice(2);let s=n[t+1];if(i=s&&!s.startsWith("-")?s:!0,typeof i==="string")t++}if(o.includes(".")){let[s,l]=o.split(".",2),a=en[s];if(a)a(i,r,l);else throw new h(`Unknown option: --${o}`)}else{let s=en[o];if(s)s(i,r);else throw new h(`Unknown option: --${o}`)}}else if(e.startsWith("-")){let o=e.slice(1),i=n[t+1],s=i&&!i.startsWith("-")?i:!0;if(typeof s==="string")t++;let l=en[o];if(l)l(s,r);else throw new h(`Unknown option: -${o}`)}else Xn.entry.handler(e,r,void 0)}return r}M();B();hn();O();import{loadConfig as oe}from"coffi";On();M();nn();B();wn();O();import on from"path";async function Or(n,r){let t=new Set,e=tn(n),o=W(e.entry);for(let c of o){let u=on.resolve(r,c.fullEntryPath),d=on.dirname(u);t.add(d)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,on.join(r,e.outDir)]}),l=!1,a=async(c=!1)=>{if(l)return;l=!0;try{let u=performance.now();if(await Bn({...e,entry:o.map((d)=>d.fullEntryPath),clean:!1},r),!c)g.cli(`\uD83D\uDCE6 Rebuild finished in ${Q(performance.now()-u)}`)}catch(u){cn(u)}finally{l=!1}};s.on("change",(c)=>{let u=on.relative(r,c);g.cli(`File changed: ${u}`,{muted:!0,once:u}),a()}),s.on("error",(c)=>{throw new q(`Watcher error: ${k(c)}`)}),await a(!0)}async function ie(n=Bun.argv.slice(2)){let r=Zn(n);G(r.silent);let t=process.cwd(),{config:e,filepath:o}=await oe({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:r.config,packageJsonProperty:"bunup"}),i=!e?[{rootDir:t,options:r}]:await Vn(e,t,r.filter);if(g.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),o)g.cli(`Using ${$(o,2)}`,{muted:!0});let s=performance.now();g.cli("Build started");let{build:l}=await Promise.resolve().then(() => (On(),Br));await Promise.all(i.flatMap(({options:u,rootDir:d})=>{return Rn(u).map(async(E)=>{let w={...E,...se(r)};if(w.watch)await Or(w,d);else await l(w,d)})}));let a=performance.now()-s,c=Q(a);if(g.cli(`\u26A1\uFE0F Build completed in ${c}`),r.watch)g.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)g.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await te(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function se(n){return{...n,onSuccess:void 0,config:void 0}}ie().catch((n)=>$n(n));
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
`)
|
|
4
|
-
`);let b=p.labels[0],a=b?mr(u,b.start):"",B=`${I(o)}${a}: ${bn(p.message)}`;x[n?"warn":"error"](B),t=!0}}catch(i){x.warn(`Failed to generate declaration for ${o}: ${l(i)}`)}})),t&&!n)throw console.log(`
|
|
2
|
+
var Ur=Object.create;var{getPrototypeOf:Gr,defineProperty:q,getOwnPropertyNames:Yr}=Object;var Dr=Object.prototype.hasOwnProperty;var _=(r,n,t)=>{t=r!=null?Ur(Gr(r)):{};let e=n||!r||!r.__esModule?q(t,"default",{value:r,enumerable:!0}):t;for(let o of Yr(r))if(!Dr.call(e,o))q(e,o,{get:()=>r[o],enumerable:!0});return e};var Kr=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var O=Kr((fn,U)=>{var k=process||{},z=k.argv||[],L=k.env||{},Xr=!(!!L.NO_COLOR||z.includes("--no-color"))&&(!!L.FORCE_COLOR||z.includes("--color")||k.platform==="win32"||(k.stdout||{}).isTTY&&L.TERM!=="dumb"||!!L.CI),Zr=(r,n,t=r)=>(e)=>{let o=""+e,i=o.indexOf(n,r.length);return~i?r+qr(o,n,t,i)+n:r+o+n},qr=(r,n,t,e)=>{let o="",i=0;do o+=r.substring(i,e)+t,i=e+n.length,e=r.indexOf(n,i);while(~e);return o+r.substring(i)},V=(r=Xr)=>{let n=r?Zr:()=>String;return{isColorSupported:r,reset:n("\x1B[0m","\x1B[0m"),bold:n("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:n("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:n("\x1B[3m","\x1B[23m"),underline:n("\x1B[4m","\x1B[24m"),inverse:n("\x1B[7m","\x1B[27m"),hidden:n("\x1B[8m","\x1B[28m"),strikethrough:n("\x1B[9m","\x1B[29m"),black:n("\x1B[30m","\x1B[39m"),red:n("\x1B[31m","\x1B[39m"),green:n("\x1B[32m","\x1B[39m"),yellow:n("\x1B[33m","\x1B[39m"),blue:n("\x1B[34m","\x1B[39m"),magenta:n("\x1B[35m","\x1B[39m"),cyan:n("\x1B[36m","\x1B[39m"),white:n("\x1B[37m","\x1B[39m"),gray:n("\x1B[90m","\x1B[39m"),bgBlack:n("\x1B[40m","\x1B[49m"),bgRed:n("\x1B[41m","\x1B[49m"),bgGreen:n("\x1B[42m","\x1B[49m"),bgYellow:n("\x1B[43m","\x1B[49m"),bgBlue:n("\x1B[44m","\x1B[49m"),bgMagenta:n("\x1B[45m","\x1B[49m"),bgCyan:n("\x1B[46m","\x1B[49m"),bgWhite:n("\x1B[47m","\x1B[49m"),blackBright:n("\x1B[90m","\x1B[39m"),redBright:n("\x1B[91m","\x1B[39m"),greenBright:n("\x1B[92m","\x1B[39m"),yellowBright:n("\x1B[93m","\x1B[39m"),blueBright:n("\x1B[94m","\x1B[39m"),magentaBright:n("\x1B[95m","\x1B[39m"),cyanBright:n("\x1B[96m","\x1B[39m"),whiteBright:n("\x1B[97m","\x1B[39m"),bgBlackBright:n("\x1B[100m","\x1B[49m"),bgRedBright:n("\x1B[101m","\x1B[49m"),bgGreenBright:n("\x1B[102m","\x1B[49m"),bgYellowBright:n("\x1B[103m","\x1B[49m"),bgBlueBright:n("\x1B[104m","\x1B[49m"),bgMagentaBright:n("\x1B[105m","\x1B[49m"),bgCyanBright:n("\x1B[106m","\x1B[49m"),bgWhiteBright:n("\x1B[107m","\x1B[49m")}};U.exports=V();U.exports.createColors=V});function Hr(r){return r}function Qr(r){return r}import xr from"path";import{build as en}from"rolldown";import{dts as tn}from"rolldown-plugin-dts";var c=_(O(),1),N=!1;function J(r){N=r??!1}class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=c.default.blue;mutedColor=c.default.dim;infoColor=c.default.cyan;warnColor=c.default.yellow;errorColor=c.default.red;defaultColor=c.default.white;progressFgColorMap={ESM:c.default.yellow,CJS:c.default.green,IIFE:c.default.magenta,DTS:c.default.blue};progressBgColorMap={ESM:c.default.bgYellow,CJS:c.default.bgGreen,IIFE:c.default.bgMagenta,DTS:c.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:n,label:t,message:e,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),u=i?this.mutedColor(e):e,g=o?` ${n(c.default.black(` ${o} `))}`:"";return`${r(t)} ${s}${u}${g}`}output(r,n={},t=console.log){if(N||!this.shouldLog(n))return;if(n.verticalSpace)t("");if(t(r),n.verticalSpace)t("")}cli(r,n={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:c.default.bgBlue,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(r,n={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:c.default.bgCyan,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(r,n={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:c.default.bgYellow,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(r,n={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:c.default.bgRed,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}getProgressFgColor(r){for(let[n,t]of Object.entries(this.progressFgColorMap))if(r.includes(n))return t;return this.defaultColor}getProgressBgColor(r){for(let[n,t]of Object.entries(this.progressBgColorMap))if(r.includes(n))return t;return c.default.bgWhite}progress(r,n,t={}){let e=this.getProgressFgColor(r),o=this.getProgressBgColor(r),i=this.formatMessage({fgColor:e,bgColor:o,label:r,message:n,identifier:t.identifier,muted:t.muted});this.output(i,t)}}var d=x.getInstance();import br from"path";import{ResolverFactory as nn}from"oxc-resolver";import P from"fs/promises";import Vr from"path";var zr=_(O(),1);class R extends Error{constructor(r){super(r);this.name="BunupError"}}class p extends R{constructor(r){super(r);this.name="BunupBuildError"}}class G extends R{constructor(r){super(r);this.name="BunupDTSBuildError"}}class T extends R{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var I=(r)=>{if(r instanceof Error)return r.message;return String(r)};function v(r){return r instanceof T}function rr(r,n){switch(r){case"esm":return C(n)?".js":".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function nr(r,n){switch(r){case"esm":return C(n)?".d.ts":".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function Y(r){return r==="node"||r==="bun"}function C(r){return r==="module"}function er(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function S(r,n=3){return r.split("/").slice(-n).join("/")}async function tr(r,n){let t=Vr.join(r,n);try{await P.rm(t,{recursive:!0,force:!0})}catch(e){throw new p(`Failed to clean output directory: ${e}`)}await P.mkdir(t,{recursive:!0})}function Nr(r){return er(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function or(r,n){return typeof n==="string"?n===r:n.test(r)}function $(r,n,t){let o=Nr(t).some((s)=>s.test(r))||n.external?.some((s)=>or(r,s)),i=n.noExternal?.some((s)=>or(r,s));return o&&!i}import{resolveTsImportPath as rn}from"ts-import-resolver";var D=_(O(),1);import{isolatedDeclaration as Jr}from"oxc-transform";var ir=[];async function sr(r){try{let n=await Bun.file(r).text(),{code:t,errors:e}=Jr(r,n);for(let o of e)ir.push({error:o,sourceText:n,tsFile:r});return t}catch(n){return console.log(n),d.warn(`Failed to generate declaration for ${r}: ${I(n)}`),null}}function gr(r){let n=!1;for(let{error:t,sourceText:e,tsFile:o}of ir){if(!n&&!r)console.log(`
|
|
3
|
+
`);let i=t.labels[0],s=i?vr(e,i.start):"",g=`${S(o)}${s}: ${Pr(t.message)}`;d[r?"warn":"error"](g),n=!0}if(n&&!r)throw console.log(`
|
|
5
4
|
`),console.log(D.default.gray(`See ${D.default.blue("https://bunup.dev/docs/troubleshooting/explicit-type-annotation-errors")} for details.`)),console.log(`
|
|
6
|
-
`),new
|
|
5
|
+
`),new T}function vr(r,n){if(n===void 0)return"";let t=r.slice(0,n).split(`
|
|
6
|
+
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function Pr(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var y="\x00dts:",ur=(r,n,t)=>{let e=new Map;return{name:"bunup:virtual-dts",async resolveId(o,i){if(j(o))return e.set(o,r),o;if(!i||!j(i))return null;let s=n.tsconfig?rn({path:o,importer:F(i),tsconfig:n.tsconfig,rootDir:t}):null;if(!s||!A(s))return null;let u=h(s);if(!u)return null;let g=W(u);return e.set(g,s),g},load:{filter:{id:{include:[ar],exclude:[cr]}},async handler(o){if(j(o)){let i=e.get(o);if(!i)return null;let s=await sr(i);if(!s)return null;return{code:s,moduleSideEffects:!1}}return null}},buildEnd(){e.clear()}}};var ar=/\.(d\.ts|d\.mts|d\.cts|ts|mts|cts|tsx)$/,cr=/[\\/]node_modules[\\/]/,K=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function H(r){return r.endsWith(".d.ts")||r.endsWith(".d.mts")||r.endsWith(".d.cts")}function mr(r){return K.test(r)&&!H(r)}function A(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))&&!H(r)}function h(r){if(H(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(K.test(r))return r.replace(K,".d.ts");return`${r}.d.ts`}function j(r){return r.startsWith(y)}function F(r){return r.replace(y,"")}function W(r){return`${y}${r}`}function lr(r,n,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let o of e)if(typeof o==="string"&&r===o)return!1;else if(o instanceof RegExp&&o.test(r))return!1}return $(r,n,t)}var Q;function dr(r,n){return{name:"bunup:types-resolve",buildStart(){Q||=new nn({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...r.path&&{tsconfig:{configFile:r.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(n===!1)return;if(t==="bun")return;let o=e?F(e):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((g)=>typeof g==="string"?g===t:g.test(t)))return}let i=o?br.dirname(o):process.cwd(),{path:s}=await Q.async(i,t);if(!s)return;if(mr(s)){let u=h(s);try{let{path:g}=await Q.async(br.dirname(s),u);if(g)return g}catch(g){}return}return s}}}async function fr(r,n,t,e,o){let i=h(r),s=W(i),u=typeof n.dts==="object"&&"resolve"in n.dts?n.dts.resolve:void 0,{output:g}=await en({input:s,write:!1,...e.path&&{resolve:{tsconfigFilename:e.path}},onwarn(b,l){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(b.code??""))return;l(b)},plugins:[ur(r,e,o),u&&dr(e,u),tn({dtsInput:!0,emitDtsOnly:!0})],external:(b)=>lr(b,n,t,u)});gr(!!n.watch);let a=g[0]?.code;if(!a)return d.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return a}async function pr(r,n,t,e,o){let i=xr.resolve(xr.resolve(r),n);return fr(i,t,o,e,r)}import{basename as on,dirname as sn,extname as gn}from"path";function Cr(r){let n=on(r),t=gn(n);return t?n.slice(0,-t.length):n}function X(r){if(typeof r==="string")return[{fullEntryPath:r,name:Cr(r)}];if(typeof r==="object"&&!Array.isArray(r))return Object.entries(r).map(([e,o])=>({fullEntryPath:o,name:e}));let n=[],t=new Set;for(let e of r){let o=Cr(e);if(!t.has(o)){n.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=sn(e).split("/").filter((g)=>g!=="."&&g!=="");if(s.length===0){let g=1,a;do a=`${o}_${g++}`;while(t.has(a));n.push({fullEntryPath:e,name:a}),t.add(a);continue}let u=!1;for(let g=1;g<=s.length&&!u;g++){let b=`${s.slice(-g).join("/")}/${o}`;if(!t.has(b))n.push({fullEntryPath:e,name:b}),t.add(b),u=!0}if(!u){let g=1,a;do a=`${s.join("/")}/${o}_${g++}`;while(t.has(a));n.push({fullEntryPath:e,name:a}),t.add(a)}}return n}function hr(r){return r.filter((n)=>A(n.fullEntryPath))}function Br(r,n){return`[dir]/${r}${n}`}import{loadConfig as wr}from"coffi";async function Mr(r){let{config:n,filepath:t}=await wr({name:"package",cwd:r,extensions:[".json"]});return{packageJson:n,path:t}}async function Sr(r,n){let{config:t,filepath:e}=await wr({name:"tsconfig",cwd:r,extensions:[".json"],preferredPath:n});return{tsconfig:t,path:e}}var un={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Er(r){return{...un,...r}}function Lr(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:o}=r,i=n===!0;return{whitespace:t??i,identifiers:e??i,syntax:o??i}}function kr(r,n){return n==="cjs"?r:void 0}function Or(r,n,t,e){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,...e==="cjs"&&(n===!0||typeof n==="object"&&n.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Rr(r,n){return r===void 0?n==="esm":r}function Tr(r){return typeof r==="string"?r:void 0}function Ir(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if($(o,r,n))return{path:o,external:!0};return null})}}}var an=/\.(js|ts|jsx|tsx|mts|cts)$/,Z={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&Y(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
7
7
|
import { dirname } from 'path';
|
|
8
8
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
10
|
const __dirname = dirname(__filename);
|
|
11
11
|
|
|
12
|
-
`},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&
|
|
12
|
+
`},importMetaUrl:{appliesTo:(r,n)=>r==="cjs"&&Y(n),isNeededInFile:(r)=>/\bimport\.meta\.url\b/.test(r),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
13
13
|
|
|
14
14
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
15
15
|
|
|
16
|
-
`}};function
|
|
17
|
-
`);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function
|
|
16
|
+
`}};function $r({format:r,target:n,shims:t}){let o=cn(t).map((i)=>Z[i]).filter((i)=>i.appliesTo(r,n));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:an},async({path:s})=>{let u=await Bun.file(s).text(),g=o.filter((m)=>m.isNeededInFile(u));if(g.length===0)return;let{shebangLine:a,codeContent:b}=mn(u),l=g.map((m)=>m.generateCode()).join("");return{contents:a+l+b}})}}}function cn(r){if(r===!0)return Object.keys(Z);if(!r)return[];return Object.entries(r).filter(([n,t])=>t&&(n in Z)).map(([n])=>n)}function mn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
|
|
17
|
+
`);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function jr(r){if(!r)return[];return r.filter((n)=>n.type==="bun")}function yr(r){if(!r)return[];return r.filter((n)=>n.type==="bunup")}async function Ar(r,n){if(!r)return;for(let t of r)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(n)}async function Fr(r,n,t){if(!r)return;for(let e of r)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:n,output:t})}async function ln(r,n=process.cwd()){let t={files:[]},e=Er(r);if(!e.entry||e.entry.length===0||!e.outDir)throw new p("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)tr(n,e.outDir);J(e.silent);let{packageJson:o,path:i}=await Mr(n);if(o&&i)d.cli(`Using ${S(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=yr(e.plugins);await Ar(s,e);let u=X(e.entry),g=o?.type;if(!e.dtsOnly){let a=[Ir(e,o),...jr(e.plugins).map((l)=>l.plugin)],b=e.format.flatMap((l)=>u.map(async(m)=>{let E=e.outputExtension?.({format:l,packageType:g,options:e,entry:m}).js??rr(l,g),B=await Bun.build({entrypoints:[`${n}/${m.fullEntryPath}`],format:l,naming:{entry:Br(m.name,E)},splitting:Rr(e.splitting,l),bytecode:kr(e.bytecode,l),define:Or(e.define,e.shims,e.env,l),minify:Lr(e),outdir:`${n}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Tr(e.env),plugins:[...a,$r({format:l,target:e.target,shims:e.shims})],throw:!1});if(!B.success)for(let f of B.logs){if(f.level==="error")throw new p(f.message);if(f.level==="warning")d.warn(f.message);else if(f.level==="info")d.info(f.message)}let w=Wr(e.outDir,m.name,E),M=_r(n,w);t.files.push({fullPath:M,relativePathToOutputDir:w}),d.progress(l.toUpperCase(),w,{identifier:e.name})}));await Promise.all(b)}if(e.dts||e.dtsOnly){let a=await Sr(n,e.preferredTsconfigPath);if(a.path)d.cli(`Using ${S(a.path,2)}`,{muted:!0,identifier:e.name,once:`${a.path}:${e.name}`});let b=e.format.filter((m)=>{if(m==="iife"&&!C(g)&&e.format.includes("cjs"))return!1;return!0}),l=typeof e.dts==="object"&&e.dts.entry?X(e.dts.entry):hr(u);try{await Promise.all(l.map(async(m)=>{let E=await pr(n,m.fullEntryPath,e,a,o);await Promise.all(b.map(async(B)=>{let w=e.outputExtension?.({format:B,packageType:g,options:e,entry:m}).dts??nr(B,g),M=Wr(e.outDir,m.name,w),f=_r(n,M);t.files.push({fullPath:f,relativePathToOutputDir:M}),await Bun.write(f,E),d.progress("DTS",M,{identifier:e.name})}))}))}catch(m){if(v(m))throw m;throw new G(I(m))}}if(await Fr(s,e,t),e.onSuccess)await e.onSuccess(e)}function Wr(r,n,t){return`${r}/${n}${t}`}function _r(r,n){return`${r}/${n}`}export{Qr as defineWorkspace,Hr as defineConfig,ln as build};
|
package/package.json
CHANGED
|
@@ -1,60 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
2
|
+
"name": "bunup",
|
|
3
|
+
"description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
|
|
4
|
+
"version": "0.5.7",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
7
|
+
"maintainers": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Arshad Yaseen",
|
|
10
|
+
"email": "m@arshadyaseen.com",
|
|
11
|
+
"url": "https://arshadyaseen.com"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/arshad-yaseen/bunup.git"
|
|
17
|
+
},
|
|
18
|
+
"funding": "https://github.com/sponsors/arshad-yaseen",
|
|
19
|
+
"homepage": "https://bunup.dev",
|
|
20
|
+
"keywords": ["bun", "bunup", "bun-bundler"],
|
|
21
|
+
"files": ["dist"],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"chokidar": "^4.0.3",
|
|
24
|
+
"coffi": "^0.1.25",
|
|
25
|
+
"oxc-resolver": "^5.0.1",
|
|
26
|
+
"oxc-transform": "^0.58.1",
|
|
27
|
+
"rolldown": "1.0.0-beta.7",
|
|
28
|
+
"rolldown-plugin-dts": "^0.7.0",
|
|
29
|
+
"tinyexec": "^1.0.1",
|
|
30
|
+
"ts-import-resolver": "^0.1.10"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"typescript": ">=4.5.0"
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./plugins": {
|
|
44
|
+
"types": "./dist/plugins.d.ts",
|
|
45
|
+
"default": "./dist/plugins.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"bin": {
|
|
49
|
+
"bunup": "./dist/cli.js"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"typescript": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"npm-publish": "bun publish --access public --no-git-checks",
|
|
58
|
+
"prepack": "cp ../../LICENSE .",
|
|
59
|
+
"postpack": "rm LICENSE"
|
|
60
|
+
},
|
|
61
|
+
"type": "module"
|
|
60
62
|
}
|