bunup 0.4.87 → 0.4.90
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 +11 -11
- package/dist/index.js +6 -6
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var Lr=Object.create;var{getPrototypeOf:Rr,defineProperty:on,getOwnPropertyNames:$r}=Object;var kr=Object.prototype.hasOwnProperty;var W=(n,r,t)=>{t=n!=null?Lr(Rr(n)):{};let e=r||!n||!n.__esModule?on(t,"default",{value:n,enumerable:!0}):t;for(let o of $r(n))if(!kr.call(e,o))on(e,o,{get:()=>n[o],enumerable:!0});return e};var Tr=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var Ir=(n,r)=>{for(var t in r)on(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 Mr=import.meta.require;var q=Tr((be,sn)=>{var Q=process||{},On=Q.argv||[],G=Q.env||{},jr=!(!!G.NO_COLOR||On.includes("--no-color"))&&(!!G.FORCE_COLOR||On.includes("--color")||Q.platform==="win32"||(Q.stdout||{}).isTTY&&G.TERM!=="dumb"||!!G.CI),Ar=(n,r,t=n)=>(e)=>{let o=""+e,i=o.indexOf(r,n.length);return~i?n+Er(o,r,t,i)+r:n+o+r},Er=(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)},Sn=(n=jr)=>{let r=n?Ar:()=>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")}};sn.exports=Sn();sn.exports.createColors=Sn});function Z(n){Rn=n??!1}class E{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=d.default.blue;mutedColor=d.default.dim;infoColor=d.default.cyan;warnColor=d.default.yellow;errorColor=d.default.red;defaultColor=d.default.white;progressFgColorMap={ESM:d.default.yellow,CJS:d.default.green,IIFE:d.default.magenta,DTS:d.default.blue};progressBgColorMap={ESM:d.default.bgYellow,CJS:d.default.bgGreen,IIFE:d.default.bgMagenta,DTS:d.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!E.instance)E.instance=new E;return E.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)),c=i?this.mutedColor(e):e,a=o?` ${r(d.default.black(` ${o} `))}`:"";return`${n(t)} ${s}${c}${a}`}output(n,r={},t=console.log){if(Rn||!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:d.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:d.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:d.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:d.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 d.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 d,Rn=!1,l;var R=p(()=>{d=W(q(),1);l=E.getInstance()});function an(n){return n instanceof X}var b,I,M,h,C,V,X,w=(n)=>{if(n instanceof Error)return n.message;return String(n)},Ur,gn=(n,r)=>{let t=w(n),e=r?`[${r}] `:"",o=an(n),i="ERROR";if(n instanceof M)i="BUILD ERROR";else if(n instanceof h)i="DTS ERROR";else if(n instanceof C)i="CLI ERROR";else if(n instanceof V)i="WATCH ERROR";else if(o)i="ISOLATED DECL ERROR";else if(n instanceof I)i="BUNUP ERROR";let s=Ur.find((c)=>c.pattern.test(t)&&(c.errorType===i||!c.errorType));if(!s)console.error(`${b.default.red(i)} ${e}${o?b.default.dim(t):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")))}
|
|
6
|
-
`)+b.default.white("Example: ")+b.default.green("`bunup --target bun`")+b.default.white(" or in config: ")+b.default.green("{ target: 'bun' }"))}}]});import
|
|
7
|
-
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function
|
|
8
|
-
`);let f=
|
|
9
|
-
`),new
|
|
10
|
-
`);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)=>{gn(n,r),process.exit(1)};var y=p(()=>{b=W(q(),1);R();I=class I extends Error{constructor(n){super(n);this.name="BunupError"}};M=class M extends I{constructor(n){super(n);this.name="BunupBuildError"}};h=class h extends I{constructor(n){super(n);this.name="BunupDTSBuildError"}};C=class C extends I{constructor(n){super(n);this.name="BunupCLIError"}};V=class V extends I{constructor(n){super(n);this.name="BunupWatchError"}};X=class X extends I{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};Ur=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.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 kn from"fs/promises";import _r from"path";function Tn(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function In(n){return Array.isArray(n)?n:[n]}function Mn(n,r){switch(n){case"esm":return U(r)?".js":".mjs";case"cjs":return U(r)?".cjs":".js";case"iife":return".global.js"}}function jn(n,r){switch(n){case"esm":return U(r)?".d.ts":".d.mts";case"cjs":return U(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function cn(n){return n==="node"||n==="bun"}function U(n){return n==="module"}function z(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 j(n,r=3){return n.split("/").slice(-r).join("/")}async function En(n,r){let t=_r.join(n,r);try{await kn.rm(t,{recursive:!0,force:!0})}catch(e){throw new M(`Failed to clean output directory: ${e}`)}await kn.mkdir(t,{recursive:!0})}var $=p(()=>{y()});function Hr(n){return An(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function Un(n,r){return typeof r==="string"?r===n:r.test(n)}function D(n,r,t){let o=Hr(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 ln=p(()=>{$()});import{resolveTsImportPath as Wr}from"ts-import-resolver";var Y="\x00dts:",_n=(n,r,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(mn(e))return e;if(!o||!mn(o))return null;let i=r.tsconfig?Wr({path:e,importer:F(o),tsconfig:r.tsconfig,rootDir:t}):null;if(!i)return null;let s=k(i);if(n.has(s))return J(s);return null},load(e){if(e.startsWith(Y)){let o=F(e),i=n.get(o);if(i)return i}return null}}};var fn=p(()=>{T()});function v(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function Hn(n){return un.test(n)&&!v(n)}function _(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))&&!v(n)}function k(n){if(v(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(un.test(n))return n.replace(un,".d.ts");return`${n}.d.ts`}function mn(n){return n.startsWith(Y)}function F(n){return n.replace(Y,"")}function J(n){return`${Y}${n}`}function Wn(n,r){if(r===void 0)return"";let t=n.slice(0,r).split(`
|
|
7
|
+
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}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 D(n,r,t)}var un;var T=p(()=>{ln();fn();un=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import{basename as qr,dirname as Fr,extname as Yr}from"path";function N(n){let r=qr(n),t=Yr(r);return t?r.slice(0,-t.length):r}function K(n){if(typeof n==="string")return[{fullEntryPath:n,name:N(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=N(e);if(!t.has(o)){r.push({fullEntryPath:e,name:o}),t.add(o);continue}let s=Fr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,g;do g=`${o}_${a++}`;while(t.has(g));r.push({fullEntryPath:e,name:g}),t.add(g);continue}let c=!1;for(let a=1;a<=s.length&&!c;a++){let m=`${s.slice(-a).join("/")}/${o}`;if(!t.has(m))r.push({fullEntryPath:e,name:m}),t.add(m),c=!0}if(!c){let a=1,g;do g=`${s.join("/")}/${o}_${a++}`;while(t.has(g));r.push({fullEntryPath:e,name:g}),t.add(g)}}return r}function Fn(n){return n.filter((r)=>_(r.fullEntryPath))}function Yn(n,r){return`[dir]/${n}${r}`}var P=p(()=>{T()});import Qr from"path";import{loadConfig as Gn}from"unconfig";async function Qn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:Qr.resolve(r,e.root),options:Tn(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function Zn(n){let{config:r,sources:t}=await Gn({sources:[{files:"package.json",extensions:[]}],cwd:n});return{packageJson:r,path:t?.[0]}}async function Vn(n,r){let{config:t,sources:e}=await Gn({sources:r?[{files:r,extensions:[]}]:[{files:"tsconfig.json",extensions:[]}],cwd:n});return{tsconfig:t,path:e?.[0]}}var pn=p(()=>{$()});import Xn from"path";import{ResolverFactory as Zr}from"oxc-resolver";function zn(n,r){return{name:"bunup:types-resolve",buildStart(){bn||=new Zr({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?F(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?Xn.dirname(o):process.cwd(),{path:s}=await bn.async(i,t);if(!s)return;if(Hn(s)){let c=k(s);try{let{path:a}=await bn.async(Xn.dirname(s),c);if(a)return a}catch(a){}return}return s}}}var bn;var Dn=p(()=>{T()});import{build as Vr}from"rolldown";import{dts as Xr}from"rolldown-plugin-dts";async function Jn(n,r,t,e,o,i){let s=k(n),c=J(s),a=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:g}=await Vr({input:c,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(m,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;f(m)},plugins:[_n(r,o,i),a&&zn(o,a),Xr({dtsInput:!0,emitDtsOnly:!0})],external:(m)=>qn(m,t,e,a)});if(!g[0]?.code)return l.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return g[0].code}catch(g){throw new h(`DTS bundling failed for entry "${n}": ${w(g)}`)}}var Nn=p(()=>{y();R();Dn();T();fn()});import{resolveTsImportPath as zr}from"ts-import-resolver";function te(n){let r=new Set,t=[Dr,Jr,Nr,Pr,ne,re,ee];for(let e of t){let o=n.matchAll(e);for(let i of o)if(i[1])r.add(i[1])}return r}async function Pn(n,r,t){let e=new Set([n]),o=[n];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),c=te(s);for(let a of c){let g=r.tsconfig?zr({path:a,importer:i,tsconfig:r.tsconfig,rootDir:t}):null;if(!g||!(_(g)||v(g)))continue;if(!e.has(g))e.add(g),o.push(g)}}catch(s){l.warn(`Error processing ${i}: ${w(s)}`)}}return e}var Dr,Jr,Nr,Pr,ne,re,ee;var nr=p(()=>{y();R();T();Dr=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Jr=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Nr=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Pr=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ne=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,re=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ee=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g});import{isolatedDeclaration as oe}from"oxc-transform";async function rr(n,r){let t=!1,e=new Map;if(await Promise.all([...n].map(async(o)=>{try{let i=k(o);if(!await Bun.file(o).exists())return;let c=await Bun.file(o).text(),{code:a,errors:g}=oe(o,c);if(a)e.set(i,a);for(let m of g){if(!t&&!r)console.log(`
|
|
8
|
+
`);let f=m.labels[0],u=f?Wn(c,f.start):"",O=`${j(o)}${u}: ${ie(m.message)}`;l[r?"warn":"error"](O),t=!0}}catch(i){l.warn(`Failed to generate declaration for ${o}: ${w(i)}`)}})),t&&!r)throw console.log(`
|
|
9
|
+
`),new X(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${xn.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${xn.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function ie(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var xn;var er=p(()=>{xn=W(q(),1);y();R();$();T()});import tr from"fs/promises";import hn from"path";async function or(n,r){let t=hn.resolve(n),e=hn.resolve(t,r);if(!await tr.exists(t))throw new h(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new h(`Entry file does not exist: ${e}`);if(!_(e))throw new h(`Entry file must be a TypeScript file: ${e}`);if(hn.relative(t,e).startsWith(".."))throw new h(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}var ir=p(()=>{y();T()});async function sr(n,r,t,e,o){let{absoluteEntry:i}=await or(n,r),s=await Pn(i,e,n),c=await rr(s,t.watch);return Jn(i,c,t,o,e,n)}var ar=p(()=>{Nn();nr();er();ir()});function en(n){return{...se,...n}}function gr(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 cr(n,r){return r==="cjs"?n:void 0}function lr(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 mr(n,r){return n===void 0?r==="esm":n}function fr(n){return typeof n==="string"?n:void 0}var se;var wn=p(()=>{se={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function ur(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(D(o,n,r))return{path:o,external:!0};return null})}}}var dr=p(()=>{ln()});function pr({format:n,target:r,shims:t}){let o=ge(t).map((i)=>Cn[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:ae},async({path:s})=>{let c=await Bun.file(s).text(),a=o.filter((u)=>u.isNeededInFile(c));if(a.length===0)return;let{shebangLine:g,codeContent:m}=ce(c),f=a.map((u)=>u.generateCode()).join("");return{contents:g+f+m}})}}}function ge(n){if(n===!0)return Object.keys(Cn);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in Cn)).map(([r])=>r)}function ce(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
|
|
10
|
+
`);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var ae,Cn;var br=p(()=>{$();ae=/\.(js|ts|jsx|tsx|mts|cts)$/,Cn={dirnameFilename:{appliesTo:(n,r)=>n==="esm"&&cn(r),isNeededInFile:(n)=>/\b__dirname\b/.test(n)||/\b__filename\b/.test(n),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
11
11
|
import { dirname } from 'path';
|
|
12
12
|
|
|
13
13
|
const __filename = fileURLToPath(import.meta.url);
|
|
14
14
|
const __dirname = dirname(__filename);
|
|
15
15
|
|
|
16
|
-
`},importMetaUrl:{appliesTo:(n,r)=>n==="cjs"&&
|
|
16
|
+
`},importMetaUrl:{appliesTo:(n,r)=>n==="cjs"&&cn(r),isNeededInFile:(n)=>/\bimport\.meta\.url\b/.test(n),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
17
17
|
|
|
18
18
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
19
19
|
|
|
20
|
-
`}}});function
|
|
20
|
+
`}}});function xr(n){if(!n)return[];return n.filter((r)=>r.type==="bun")}function hr(n){if(!n)return[];return n.filter((r)=>r.type==="bunup")}async function wr(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 Or={};Ir(Or,{build:()=>yn});async function yn(n,r=process.cwd()){let t={files:[]},e=en(n);if(!e.entry||e.entry.length===0||!e.outDir)throw new M("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)En(r,e.outDir);Z(e.silent);let{packageJson:o,path:i}=await Zn(r);if(o&&i)l.cli(`Using ${j(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=hr(e.plugins);await wr(s,e);let c=K(e.entry),a=o?.type;if(!e.dtsOnly){let g=[ur(e,o),...xr(e.plugins).map((f)=>f.plugin)],m=e.format.flatMap((f)=>c.map(async(u)=>{let A=e.outputExtension?.({format:f,packageType:a,options:e,entry:u}).js??Mn(f,a),O=await Bun.build({entrypoints:[`${r}/${u.fullEntryPath}`],format:f,naming:{entry:Yn(u.name,A)},splitting:mr(e.splitting,f),bytecode:cr(e.bytecode,f),define:lr(e.define,e.shims,e.env,f),minify:gr(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:fr(e.env),plugins:[...g,pr({format:f,target:e.target,shims:e.shims})],throw:!1});if(!O.success)for(let L of O.logs){if(L.level==="error")throw new M(L.message);if(L.level==="warning")l.warn(L.message);else if(L.level==="info")l.info(L.message)}let S=yr(e.outDir,u.name,A),H=Br(r,S);t.files.push({fullPath:H,relativePathToOutputDir:S}),l.progress(f.toUpperCase(),S,{identifier:e.name})}));await Promise.all(m)}if(e.dts||e.dtsOnly){let g=await Vn(r,e.preferredTsconfigPath);if(g.path)l.cli(`Using ${j(g.path,2)}`,{muted:!0,identifier:e.name,once:`${g.path}:${e.name}`});let m=e.format.filter((u)=>{if(u==="iife"&&!U(a)&&e.format.includes("cjs"))return!1;return!0}),f=typeof e.dts==="object"&&e.dts.entry?K(e.dts.entry):Fn(c);try{await Promise.all(f.map(async(u)=>{let A=await sr(r,u.fullEntryPath,e,g,o);await Promise.all(m.map(async(O)=>{let S=e.outputExtension?.({format:O,packageType:a,options:e,entry:u}).dts??jn(O,a),H=yr(e.outDir,u.name,S),L=Br(r,H);t.files.push({fullPath:L,relativePathToOutputDir:H}),await Bun.write(L,A),l.progress("DTS",H,{identifier:e.name})}))}))}catch(u){if(an(u))throw u;throw new h(w(u))}}if(await Cr(s,e,t),e.onSuccess)await e.onSuccess(e)}function yr(n,r,t){return`${n}/${r}${t}`}function Br(n,r){return`${n}/${r}`}var Bn=p(()=>{ar();y();P();pn();R();wn();dr();br();$()});import{exec as me}from"tinyexec";var dn=W(q(),1);var Ln="https://bunup.dev/cli-options";y();P();R();function x(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function B(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new C(`Option --${n} requires a string value`)}}function nn(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new C(`Option --${n} requires a string value`)}}function vr(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 C(`Option --${n} requires a boolean or string value`)}}function Kr(){console.log(`
|
|
21
21
|
Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
|
|
22
|
-
`),console.log("For more information on available options, visit:"),console.log(`${
|
|
23
|
-
`),process.exit(0)}function
|
|
22
|
+
`),console.log("For more information on available options, visit:"),console.log(`${dn.default.cyan(dn.default.underline(Ln))}
|
|
23
|
+
`),process.exit(0)}function Gr(){console.log("0.4.74"),process.exit(0)}var vn={name:{flags:["n","name"],handler:B("name")},format:{flags:["f","format"],handler:nn("format")},outDir:{flags:["o","out-dir"],handler:B("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:B("banner")},footer:{flags:["ft","footer"],handler:B("footer")},external:{flags:["e","external"],handler:nn("external")},sourcemap:{flags:["sm","sourcemap"],handler:vr("sourcemap")},target:{flags:["t","target"],handler:B("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:nn("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:B("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:B("config")},publicPath:{flags:["pp","public-path"],handler:B("publicPath")},env:{flags:["env"],handler:B("env")},shims:{flags:["shims"],handler:x("shims")},onSuccess:{flags:["onSuccess"],handler:B("onSuccess")},filter:{flags:["filter"],handler:nn("filter")},entry:{flags:["entry"],handler:(n,r,t)=>{if(typeof n!=="string")throw new C(`Entry${t?` --entry.${t}`:""} requires a string value`);let e=r.entry||{};if(t){if(e[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);e[t]=n}else{let o=N(n);if(e[o])l.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:()=>Kr()},version:{flags:["v","version"],handler:()=>Gr()}},rn={};for(let n of Object.values(vn))for(let r of n.flags)rn[r]=n.handler;function Kn(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,c]=e.slice(2).split("=",2);o=s,i=c}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,c]=o.split(".",2),a=rn[s];if(a)a(i,r,c);else throw new C(`Unknown option: --${o}`)}else{let s=rn[o];if(s)s(i,r);else throw new C(`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 c=rn[o];if(c)c(s,r);else throw new C(`Unknown option: -${o}`)}else vn.entry.handler(e,r,void 0)}return r}y();R();pn();$();Bn();y();P();R();wn();$();import tn from"path";async function Sr(n,r){let t=new Set,e=en(n),o=K(e.entry);for(let g of o){let m=tn.resolve(r,g.fullEntryPath),f=tn.dirname(m);t.add(f)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,tn.join(r,e.outDir)]}),c=!1,a=async(g=!1)=>{if(c)return;c=!0;try{let m=performance.now();if(await yn({...e,entry:o.map((f)=>f.fullEntryPath),clean:!1},r),!g)l.cli(`\uD83D\uDCE6 Rebuild finished in ${z(performance.now()-m)}`)}catch(m){gn(m)}finally{c=!1}};s.on("change",(g)=>{let m=tn.relative(r,g);l.cli(`File changed: ${m}`,{muted:!0,once:m}),a()}),s.on("error",(g)=>{throw new V(`Watcher error: ${w(g)}`)}),await a(!0)}import{loadConfig as fe}from"unconfig";async function ue(n=Bun.argv.slice(2)){let r=Kn(n);Z(r.silent);let t=process.cwd(),{config:e,sources:o}=await fe({sources:r.config?[{files:r.config,extensions:[]}]:[{files:"bunup.config",extensions:["ts","js","mjs","cjs"]},{files:"package.json",extensions:[],rewrite(f){return f?.bunup}}],merge:!1}),i=o?.[0],s=!e?[{rootDir:t,options:r}]:await Qn(e,t,r.filter);if(l.cli(`Using bunup v0.4.74 and bun v${Bun.version}`,{muted:!0}),i)l.cli(`Using ${j(i,2)}`,{muted:!0});let c=performance.now();l.cli("Build started");let{build:a}=await Promise.resolve().then(() => (Bn(),Or));await Promise.all(s.flatMap(({options:f,rootDir:u})=>{return In(f).map(async(O)=>{let S={...O,...de(r)};if(S.watch)await Sr(S,u);else await a(S,u)})}));let g=performance.now()-c,m=z(g);if(l.cli(`\u26A1\uFE0F Build completed in ${m}`),r.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)l.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await me(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function de(n){return{...n,onSuccess:void 0,config:void 0}}ue().catch((n)=>$n(n));
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function
|
|
4
|
-
`);let
|
|
5
|
-
`),new _(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${
|
|
2
|
+
var Fr=Object.create;var{getPrototypeOf:Yr,defineProperty:V,getOwnPropertyNames:Kr}=Object;var qr=Object.prototype.hasOwnProperty;var F=(r,n,t)=>{t=r!=null?Fr(Yr(r)):{};let e=n||!r||!r.__esModule?V(t,"default",{value:r,enumerable:!0}):t;for(let o of Kr(r))if(!qr.call(e,o))V(e,o,{get:()=>r[o],enumerable:!0});return e};var Gr=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var j=Gr((Sn,Y)=>{var $=process||{},X=$.argv||[],E=$.env||{},Qr=!(!!E.NO_COLOR||X.includes("--no-color"))&&(!!E.FORCE_COLOR||X.includes("--color")||$.platform==="win32"||($.stdout||{}).isTTY&&E.TERM!=="dumb"||!!E.CI),Zr=(r,n,t=r)=>(e)=>{let o=""+e,i=o.indexOf(n,r.length);return~i?r+zr(o,n,t,i)+n:r+o+n},zr=(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)},J=(r=Qr)=>{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")}};Y.exports=J();Y.exports.createColors=J});function Hr(r){return r}function Dr(r){return r}import{build as Pr}from"rolldown";import{dts as rn}from"rolldown-plugin-dts";var Vr=F(j(),1);var c=F(j(),1),N=!1;function v(r){N=r??!1}class w{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(!w.instance)w.instance=new w;return w.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 f=w.getInstance();class A extends Error{constructor(r){super(r);this.name="BunupError"}}class h extends A{constructor(r){super(r);this.name="BunupBuildError"}}class p extends A{constructor(r){super(r);this.name="BunupDTSBuildError"}}class _ extends A{constructor(r){super(r);this.name="BunupIsolatedDeclError"}}var l=(r)=>{if(r instanceof Error)return r.message;return String(r)};function P(r){return r instanceof _}import cr from"path";import{ResolverFactory as vr}from"oxc-resolver";import rr from"fs/promises";import Xr from"path";function nr(r,n){switch(r){case"esm":return R(n)?".js":".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function er(r,n){switch(r){case"esm":return R(n)?".d.ts":".d.mts";case"cjs":return R(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function K(r){return r==="node"||r==="bun"}function R(r){return r==="module"}function tr(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function I(r,n=3){return r.split("/").slice(-n).join("/")}async function or(r,n){let t=Xr.join(r,n);try{await rr.rm(t,{recursive:!0,force:!0})}catch(e){throw new h(`Failed to clean output directory: ${e}`)}await rr.mkdir(t,{recursive:!0})}function Jr(r){return tr(r).map((n)=>new RegExp(`^${n}($|\\/|\\\\)`))}function ir(r,n){return typeof n==="string"?n===r:n.test(r)}function W(r,n,t){let o=Jr(t).some((s)=>s.test(r))||n.external?.some((s)=>ir(r,s)),i=n.noExternal?.some((s)=>ir(r,s));return o&&!i}import{resolveTsImportPath as Nr}from"ts-import-resolver";var O="\x00dts:",sr=(r,n,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,o){if(q(e))return e;if(!o||!q(o))return null;let i=n.tsconfig?Nr({path:e,importer:M(o),tsconfig:n.tsconfig,rootDir:t}):null;if(!i)return null;let s=C(i);if(r.has(s))return U(s);return null},load(e){if(e.startsWith(O)){let o=M(e),i=r.get(o);if(i)return i}return null}}};var G=/\.(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 gr(r){return G.test(r)&&!T(r)}function S(r){return[".ts",".mts",".cts",".tsx"].some((n)=>r.endsWith(n))&&!T(r)}function C(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(G.test(r))return r.replace(G,".d.ts");return`${r}.d.ts`}function q(r){return r.startsWith(O)}function M(r){return r.replace(O,"")}function U(r){return`${O}${r}`}function mr(r,n){if(n===void 0)return"";let t=r.slice(0,n).split(`
|
|
3
|
+
`),e=t.length,o=t[t.length-1].length+1;return` (${e}:${o})`}function ur(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 W(r,n,t)}var H;function ar(r,n){return{name:"bunup:types-resolve",buildStart(){H||=new vr({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?M(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?cr.dirname(o):process.cwd(),{path:s}=await H.async(i,t);if(!s)return;if(gr(s)){let u=C(s);try{let{path:g}=await H.async(cr.dirname(s),u);if(g)return g}catch(g){}return}return s}}}async function br(r,n,t,e,o,i){let s=C(r),u=U(s),g=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:m}=await Pr({input:u,output:{dir:t.outDir},write:!1,...o.path&&{resolve:{tsconfigFilename:o.path}},onwarn(x,b){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;b(x)},plugins:[sr(n,o,i),g&&ar(o,g),rn({dtsInput:!0,emitDtsOnly:!0})],external:(x)=>ur(x,t,e,g)});if(!m[0]?.code)return f.warn(`Generated empty declaration file for entry "${r}"`,{muted:!0}),"";return m[0].code}catch(m){throw new p(`DTS bundling failed for entry "${r}": ${l(m)}`)}}import{resolveTsImportPath as nn}from"ts-import-resolver";var en=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,tn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,on=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,sn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,gn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,mn=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,un=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function cn(r){let n=new Set,t=[en,tn,on,sn,gn,mn,un];for(let e of t){let o=r.matchAll(e);for(let i of o)if(i[1])n.add(i[1])}return n}async function xr(r,n,t){let e=new Set([r]),o=[r];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),u=cn(s);for(let g of u){let m=n.tsconfig?nn({path:g,importer:i,tsconfig:n.tsconfig,rootDir:t}):null;if(!m||!(S(m)||T(m)))continue;if(!e.has(m))e.add(m),o.push(m)}}catch(s){f.warn(`Error processing ${i}: ${l(s)}`)}}return e}var D=F(j(),1);import{isolatedDeclaration as an}from"oxc-transform";async function fr(r,n){let t=!1,e=new Map;if(await Promise.all([...r].map(async(o)=>{try{let i=C(o);if(!await Bun.file(o).exists())return;let u=await Bun.file(o).text(),{code:g,errors:m}=an(o,u);if(g)e.set(i,g);for(let x of m){if(!t&&!n)console.log(`
|
|
4
|
+
`);let b=x.labels[0],a=b?mr(u,b.start):"",B=`${I(o)}${a}: ${bn(x.message)}`;f[n?"warn":"error"](B),t=!0}}catch(i){f.warn(`Failed to generate declaration for ${o}: ${l(i)}`)}})),t&&!n)throw console.log(`
|
|
5
|
+
`),new _(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${D.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${D.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function bn(r){return r.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}import pr from"fs/promises";import Q from"path";async function dr(r,n){let t=Q.resolve(r),e=Q.resolve(t,n);if(!await pr.exists(t))throw new p(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!S(e))throw new p(`Entry file must be a TypeScript file: ${e}`);if(Q.relative(t,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function lr(r,n,t,e,o){let{absoluteEntry:i}=await dr(r,n),s=await xr(i,e,r),u=await fr(s,t.watch);return br(i,u,t,o,e,r)}import{basename as xn,dirname as fn,extname as pn}from"path";function Cr(r){let n=xn(r),t=pn(n);return t?n.slice(0,-t.length):n}function Z(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=fn(e).split("/").filter((g)=>g!=="."&&g!=="");if(s.length===0){let g=1,m;do m=`${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m);continue}let u=!1;for(let g=1;g<=s.length&&!u;g++){let x=`${s.slice(-g).join("/")}/${o}`;if(!t.has(x))n.push({fullEntryPath:e,name:x}),t.add(x),u=!0}if(!u){let g=1,m;do m=`${s.join("/")}/${o}_${g++}`;while(t.has(m));n.push({fullEntryPath:e,name:m}),t.add(m)}}return n}function Br(r){return r.filter((n)=>S(n.fullEntryPath))}function wr(r,n){return`[dir]/${r}${n}`}import{loadConfig as hr}from"unconfig";async function Rr(r){let{config:n,sources:t}=await hr({sources:[{files:"package.json",extensions:[]}],cwd:r});return{packageJson:n,path:t?.[0]}}async function Sr(r,n){let{config:t,sources:e}=await hr({sources:n?[{files:n,extensions:[]}]:[{files:"tsconfig.json",extensions:[]}],cwd:r});return{tsconfig:t,path:e?.[0]}}var dn={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function kr(r){return{...dn,...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 yr(r,n){return n==="cjs"?r:void 0}function Ir(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 Mr(r,n){return r===void 0?n==="esm":r}function Or(r){return typeof r==="string"?r:void 0}function Tr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let o=e.path;if(W(o,r,n))return{path:o,external:!0};return null})}}}var ln=/\.(js|ts|jsx|tsx|mts|cts)$/,z={dirnameFilename:{appliesTo:(r,n)=>r==="esm"&&K(n),isNeededInFile:(r)=>/\b__dirname\b/.test(r)||/\b__filename\b/.test(r),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
6
6
|
import { dirname } from 'path';
|
|
7
7
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -12,5 +12,5 @@ var Zr=Object.create;var{getPrototypeOf:Hr,defineProperty:J,getOwnPropertyNames:
|
|
|
12
12
|
|
|
13
13
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
14
14
|
|
|
15
|
-
`}};function
|
|
16
|
-
`);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function
|
|
15
|
+
`}};function Er({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:ln},async({path:s})=>{let u=await Bun.file(s).text(),g=o.filter((a)=>a.isNeededInFile(u));if(g.length===0)return;let{shebangLine:m,codeContent:x}=Bn(u),b=g.map((a)=>a.generateCode()).join("");return{contents:m+b+x}})}}}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 Bn(r){if(!r.startsWith("#!"))return{shebangLine:"",codeContent:r};let n=r.indexOf(`
|
|
16
|
+
`);return n===-1?{shebangLine:"",codeContent:r}:{shebangLine:r.slice(0,n+1),codeContent:r.slice(n+1)}}function $r(r){if(!r)return[];return r.filter((n)=>n.type==="bun")}function jr(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 _r(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 wn(r,n=process.cwd()){let t={files:[]},e=kr(r);if(!e.entry||e.entry.length===0||!e.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)or(n,e.outDir);v(e.silent);let{packageJson:o,path:i}=await Rr(n);if(o&&i)f.cli(`Using ${I(i,2)}`,{muted:!0,identifier:e.name,once:`${i}:${e.name}`});let s=jr(e.plugins);await Ar(s,e);let u=Z(e.entry),g=o?.type;if(!e.dtsOnly){let m=[Tr(e,o),...$r(e.plugins).map((b)=>b.plugin)],x=e.format.flatMap((b)=>u.map(async(a)=>{let k=e.outputExtension?.({format:b,packageType:g,options:e,entry:a}).js??nr(b,g),B=await Bun.build({entrypoints:[`${n}/${a.fullEntryPath}`],format:b,naming:{entry:wr(a.name,k)},splitting:Mr(e.splitting,b),bytecode:yr(e.bytecode,b),define:Ir(e.define,e.shims,e.env,b),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:Or(e.env),plugins:[...m,Er({format:b,target:e.target,shims:e.shims})],throw:!1});if(!B.success)for(let d of B.logs){if(d.level==="error")throw new h(d.message);if(d.level==="warning")f.warn(d.message);else if(d.level==="info")f.info(d.message)}let L=Wr(e.outDir,a.name,k),y=Ur(n,L);t.files.push({fullPath:y,relativePathToOutputDir:L}),f.progress(b.toUpperCase(),L,{identifier:e.name})}));await Promise.all(x)}if(e.dts||e.dtsOnly){let m=await Sr(n,e.preferredTsconfigPath);if(m.path)f.cli(`Using ${I(m.path,2)}`,{muted:!0,identifier:e.name,once:`${m.path}:${e.name}`});let x=e.format.filter((a)=>{if(a==="iife"&&!R(g)&&e.format.includes("cjs"))return!1;return!0}),b=typeof e.dts==="object"&&e.dts.entry?Z(e.dts.entry):Br(u);try{await Promise.all(b.map(async(a)=>{let k=await lr(n,a.fullEntryPath,e,m,o);await Promise.all(x.map(async(B)=>{let L=e.outputExtension?.({format:B,packageType:g,options:e,entry:a}).dts??er(B,g),y=Wr(e.outDir,a.name,L),d=Ur(n,y);t.files.push({fullPath:d,relativePathToOutputDir:y}),await Bun.write(d,k),f.progress("DTS",y,{identifier:e.name})}))}))}catch(a){if(P(a))throw a;throw new p(l(a))}}if(await _r(s,e,t),e.onSuccess)await e.onSuccess(e)}function Wr(r,n,t){return`${r}/${n}${t}`}function Ur(r,n){return`${r}/${n}`}export{Dr as defineWorkspace,Hr as defineConfig,wn as build};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
3
|
"description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.90",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
7
7
|
"type": "module",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@biomejs/biome": "^1.9.4",
|
|
80
80
|
"@types/bun": "^1.2.5",
|
|
81
81
|
"bumpp": "^10.1.0",
|
|
82
|
-
"bunup": "^0.4.
|
|
82
|
+
"bunup": "^0.4.87",
|
|
83
83
|
"create-bunup": "workspace:create-bunup",
|
|
84
84
|
"husky": "^9.1.7",
|
|
85
85
|
"lint-staged": "^15.5.1",
|