bunup 0.4.44 → 0.4.45
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/build/cli.mjs +5 -5
- package/package.json +3 -3
package/build/cli.mjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
import{exec as On}from"tinyexec";import{build as Ve}from"rolldown";import{dts as Je}from"rolldown-plugin-dts";var re=!1;function R(e){re=e??!1}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",muted:"245",info:"117",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};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({colorCode:e,label:n,message:t,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=o?`\x1B[38;5;${this.colors.muted}m${t}\x1B[0m`:t;if(r){let[u,...m]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${n}\x1B[0m ${i}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${m.join(" ")}${p}`}let c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${n}\x1B[0m ${i}${a}${c}`}output(e,n={},t=console.log){if(re)return;if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(t(e),n.verticalSpace)console.log("")}cli(e,n={}){let t=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n)}info(e,n={}){let t=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n)}warn(e,n={}){let t=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)}error(e,n={}){let t=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)}progress(e,n,t,r){let s=String(e),o=this.colors.default,i,a,c={};if(typeof t==="string")i=t,a=r;else if(t)i=t.size,a=t.identifier,c=t;for(let[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){o=f;break}let u=this.formatMessage({colorCode:o,label:s,message:n,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var l=$.getInstance();class O extends Error{constructor(e){super(e);this.name="BunupError"}}class C extends O{constructor(e){super(e);this.name="BunupBuildError"}}class g extends O{constructor(e){super(e);this.name="BunupDTSBuildError"}}class h extends O{constructor(e){super(e);this.name="BunupCLIError"}}class M extends O{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},ze=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],G=(e,n)=>{let t=b(e),r=n?`[${n}] `:"",s="ERROR";if(e instanceof C)s="BUILD ERROR";else if(e instanceof g)s="DTS ERROR";else if(e instanceof h)s="CLI ERROR";else if(e instanceof M)s="WATCH ERROR";else if(e instanceof O)s="BUNUP ERROR";let o=ze.find((i)=>i.pattern.test(t)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${r}${t}`);if(o)console.log(`
|
|
4
4
|
`),o.logSolution(t),console.log(`
|
|
5
|
-
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},se=(e,n)=>{G(e,n),process.exit(1)};import ie from"node:fs/promises";import Qe from"node:path";function K(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e=8){let n="";while(n.length<e)n+=Math.random().toString(36).substring(2);return n.substring(0,e)}function ae(e,n,t){return Array.isArray(e)?e.map((r)=>({...r,[n]:t})):{...e,[n]:t}}function ce(e){return Array.isArray(e)?e:[e]}function ue(e,n){switch(e){case"esm":return
|
|
5
|
+
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},se=(e,n)=>{G(e,n),process.exit(1)};import ie from"node:fs/promises";import Qe from"node:path";function K(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e=8){let n="";while(n.length<e)n+=Math.random().toString(36).substring(2);return n.substring(0,e)}function ae(e,n,t){return Array.isArray(e)?e.map((r)=>({...r,[n]:t})):{...e,[n]:t}}function ce(e){return Array.isArray(e)?e:[e]}function ue(e,n){switch(e){case"esm":return B(n)?".js":".mjs";case"cjs":return B(n)?".cjs":".js";case"iife":return".global.js"}}function le(e,n){switch(e){case"esm":return B(n)?".d.ts":".d.mts";case"cjs":return B(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function Y(e){return e==="node"||e==="bun"}function B(e){return e==="module"}function j(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function me(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function z(e){if(e===0)return"0 B";let n=["B","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(1024));if(t===0)return`${e} ${n[t]}`;return`${(e/1024**t).toFixed(2)} ${n[t]}`}function y(e,n=3){return e.split("/").slice(-n).join("/")}async function pe(e,n){let t=Qe.join(e,n);try{await ie.rm(t,{recursive:!0,force:!0})}catch(r){throw new C(`Failed to clean output directory: ${r}`)}await ie.mkdir(t,{recursive:!0})}function k(e){return[".ts",".mts",".cts",".tsx"].some((n)=>e.endsWith(n))}function fe(e){return e.map((n)=>typeof n==="string"?new RegExp(`^${K(n)}($|\\/|\\\\)`):n)}function I(e,n){return fe(e.external||[]).concat(me(n).map((t)=>new RegExp(`^${K(t)}($|\\/|\\\\)`)))}function _(e){return fe(e.noExternal||[])}import xe from"node:path";import{ResolverFactory as Xe}from"oxc-resolver";import{resolveTsImportPath as Ze}from"ts-import-resolver";var L="\x00dts:",de=(e,n,t)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(Q(r))return r;if(!s||!Q(s))return null;let o=n.tsconfig?Ze({path:r,importer:E(s),tsconfig:n.tsconfig,rootDir:t}):null;if(!o)return null;let i=w(o);if(e.has(i))return N(i);return null},load(r){if(r.startsWith(L)){let s=E(r),o=e.get(s);if(o)return S.add(s),o}return null}}};var Z=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/;function ge(e){return e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts")}function X(e){return Z.test(e)&&!ge(e)}function w(e){if(ge(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(Z.test(e))return e.replace(Z,".d.ts");return`${e}.d.ts`}function be(e){if(X(e))return e;if(e.endsWith(".d.mts"))return`${e.slice(0,-6)}.mts`;if(e.endsWith(".d.cts"))return`${e.slice(0,-6)}.cts`;if(e.endsWith(".d.ts"))return`${e.slice(0,-5)}.ts`;return e}function Q(e){return e.startsWith(L)}function E(e){return e.replace(L,"")}function N(e){return`${L}${e}`}function he(e,n,t,r){if(typeof r==="boolean"&&r)return!1;if(Array.isArray(r)){for(let s of r)if(typeof s==="string"&&e===s)return!1;else if(s instanceof RegExp&&s.test(e))return!1}return n.some((s)=>s.test(e))&&!t.some((s)=>s.test(e))}var V;function ye(e,n){return{name:"bunup:types-resolve",buildStart(){V||=new Xe({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...e.path&&{tsconfig:{configFile:e.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(n===!1)return;if(t==="bun")return;let s=r?E(r):void 0;if(/\0/.test(t))return;if(Array.isArray(n)){if(!n.some((c)=>typeof c==="string"?c===t:c.test(t)))return}let o=s?xe.dirname(s):process.cwd(),{path:i}=await V.async(o,t);if(!i)return;if(X(i)){let a=w(i);try{let{path:c}=await V.async(xe.dirname(i),a);if(c)return c}catch(c){}return}return i}}}async function we(e,n,t,r,s,o){let i=w(e),a=N(i),c=I(t,r),u=_(t),m=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:f}=await Ve({input:a,output:{dir:t.outDir},write:!1,...s.path&&{resolve:{tsconfigFilename:s.path}},onwarn(p,T){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;T(p)},plugins:[de(n,s,o),m&&ye(s,m),Je({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>he(p,c,u,m)});if(!f[0]?.code)return l.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new g(`DTS bundling failed for entry "${e}": ${b(f)}`)}}import{resolveTsImportPath as Pe}from"ts-import-resolver";var en=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,nn=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,tn=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,rn=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,sn=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,on=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,an=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function cn(e){let n=new Set,t=[en,nn,tn,rn,sn,on,an];for(let r of t){let s=e.matchAll(r);for(let o of s)if(o[1])n.add(o[1])}return n}async function Ce(e,n,t){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=cn(i);for(let c of a){let u=n.tsconfig?Pe({path:c,importer:o,tsconfig:n.tsconfig,rootDir:t}):null;if(!u)continue;if(!r.has(u))r.add(u),s.push(u)}}catch(i){l.warn(`Error processing ${o}: ${b(i)}`)}}return r}import{isolatedDeclaration as un}from"oxc-transform";async function $e(e){let n=new Map;return await Promise.all([...e].map(async(t)=>{try{let r=w(t);if(!await Bun.file(t).exists())return;let o=await Bun.file(t).text(),{code:i}=un(t,o);if(i)n.set(r,i)}catch(r){l.warn(`Failed to generate declaration for ${t}: ${b(r)}`)}})),n}import Oe from"node:fs/promises";import J from"node:path";import{isolatedDeclaration as ln}from"oxc-transform";async function Be(e,n){let t=J.resolve(e),r=J.resolve(t,n);if(!await Oe.exists(t))throw new g(`Root directory does not exist: ${t}`);if(!await Bun.file(r).exists())throw new g(`Entry file does not exist: ${r}`);if(!k(r))throw new g(`Entry file must be a TypeScript file: ${r}`);if(J.relative(t,r).startsWith(".."))throw new g(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:t,absoluteEntry:r}}async function Se(e){let n=!1;if(await Promise.all([...e].map(async(t)=>{try{let r=be(t),s=await Bun.file(r).text(),{errors:o}=ln(r,s);for(let i of o){if(!n)console.log(`
|
|
6
6
|
`);let a=i.labels[0],c=a?mn(s,a.start):"",m=`${y(r)}${c}: ${pn(i.message)}`;l.warn(m),n=!0}}catch{}})),n)l.info(`You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.`,{muted:!0,verticalSpace:!0})}function mn(e,n){if(n===void 0)return"";let t=e.slice(0,n).split(`
|
|
7
|
-
`),r=t.length,s=t[t.length-1].length+1;return` (${r}:${s})`}function pn(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,n,t,r,s){let{absoluteEntry:o}=await
|
|
7
|
+
`),r=t.length,s=t[t.length-1].length+1;return` (${r}:${s})`}function pn(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,n,t,r,s){let{absoluteEntry:o}=await Be(e,n),i=await Ce(o,r,e),a=await $e(i);return we(o,a,t,s,r,e)}function U(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(e,{warnOnConflict:n=!0}={}){let t=[],r=new Set,s={};function o(i,a){if(r.has(i)){let c=oe(),u=`${i}_${c}`;if(n)l.warn(`Output name conflict: "${i}" is used by multiple files.
|
|
8
8
|
Bunup uses filenames without extensions as output names by default.
|
|
9
9
|
|
|
10
10
|
${s[i]} -> ${i}.js
|
|
@@ -29,7 +29,7 @@ See: https://bunup.arshadyaseen.com/documentation/#named-entries`,{muted:!0,vert
|
|
|
29
29
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
30
30
|
|
|
31
31
|
`}};function He({format:e,target:n,shims:t}){let s=gn(t).map((o)=>P[o]).filter((o)=>o.appliesTo(e,n));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:dn},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((p)=>p.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:m}=bn(a),f=c.map((p)=>p.generateCode()).join("");return{contents:u+f+m}})}}}function gn(e){if(e===!0)return Object.keys(P);if(!e)return[];return Object.entries(e).filter(([n,t])=>t&&(n in P)).map(([n])=>n)}function bn(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let n=e.indexOf(`
|
|
32
|
-
`);return n===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,n+1),codeContent:e.slice(n+1)}}function We(e){return e.filter((n)=>n.type==="bun").map((n)=>n.plugin)}var
|
|
33
|
-
Bunup -
|
|
32
|
+
`);return n===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,n+1),codeContent:e.slice(n+1)}}function We(e){return e.filter((n)=>n.type==="bun").map((n)=>n.plugin)}var S=new Set;async function H(e,n=process.cwd()){let t=D(e);if(!t.entry||t.entry.length===0||!t.outDir)throw new C("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(t.clean)pe(n,t.outDir);R(t.silent);let{packageJson:r,path:s}=await Me(n);if(r&&s)l.cli(`Using package.json: ${y(s,2)}`,{muted:!0,identifier:t.name,once:`${s}:${t.name}`});let o=A(t.entry),i=r?.type,a=I(t,r),c=_(t);if(!t.dtsOnly){let u=[De(a,c),...We(t.plugins??[])],m=t.format.flatMap((f)=>o.map((p)=>{return hn(t,n,p,f,i,u)}));await Promise.all(m)}if(t.dts||t.dtsOnly){let u=await je(n,t.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${y(u.path,2)}`,{muted:!0,identifier:t.name,once:`${u.path}:${t.name}`});let m=t.format.filter((p)=>{if(p==="iife"&&!B(i)&&t.format.includes("cjs"))return!1;return!0}),f=typeof t.dts==="object"&&t.dts.entry?A(t.dts.entry):Ee(o);try{await Promise.all(f.map(async(p)=>{let T=await Te(n,p.path,t,u,r);await Promise.all(m.map(async(te)=>{let Ke=t.outputExtension?.({format:te,packageType:i,options:t,entry:p}).dts??le(te,i),F=`${n}/${t.outDir}/${p.name}${Ke}`;await Bun.write(F,T);let Ye=Bun.file(F).size||0;l.progress("DTS",y(F),z(Ye),t.name)}))}))}catch(p){throw new g(b(p))}}if(t.onBuildSuccess)await t.onBuildSuccess(t)}async function hn(e,n,t,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:t}).js??ue(r,s),a=await Bun.build({entrypoints:[`${n}/${t.path}`],format:r,naming:{entry:Le(t.name,i)},splitting:Ne(e.splitting,r),bytecode:Ie(e.bytecode,r),define:_e(e.define,e.shims,e.env,r),minify:ke(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:Ue(e.env),plugins:[...o,He({format:r,target:e.target,shims:e.shims})],throw:!1});if(!a.success)for(let m of a.logs){if(m.level==="error")throw new C(m.message);if(m.level==="warning")l.warn(m.message);else if(m.level==="info")l.info(m.message)}let c=`${n}/${e.outDir}/${t.name}${i}`,u=Bun.file(c).size||0;l.progress(r.toUpperCase(),y(c),z(u),e.name)}var W="0.4.45";var ve="https://bunup.arshadyaseen.com/cli-options";function d(e){return(n,t)=>{t[e]=n===!0||n==="true"}}function x(e){return(n,t)=>{if(typeof n==="string")t[e]=n;else throw new h(`Option --${e} requires a string value`)}}function ee(e){return(n,t)=>{if(typeof n==="string")t[e]=n.split(",");else throw new h(`Option --${e} requires a string value`)}}function yn(e){return(n,t)=>{if(typeof n==="boolean")t[e]=n;else if(typeof n==="string")if(n.toLowerCase()==="true"||n.toLowerCase()==="false")t[e]=n.toLowerCase()==="true";else t[e]=n;else throw new h(`Option --${e} requires a boolean or string value`)}}function wn(){console.log(`
|
|
33
|
+
Bunup - A blazing-fast build tool for your libraries built with Bun.
|
|
34
34
|
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${ve}\x1B[0m
|
|
35
|
-
`),process.exit(0)}function Cn(){console.log(W),process.exit(0)}var qe={name:{flags:["n","name"],handler:x("name")},format:{flags:["f","format"],handler:ee("format")},outDir:{flags:["o","out-dir"],handler:x("outDir")},minify:{flags:["m","minify"],handler:d("minify")},watch:{flags:["w","watch"],handler:d("watch")},dts:{flags:["d","dts"],handler:d("dts")},banner:{flags:["bn","banner"],handler:x("banner")},footer:{flags:["ft","footer"],handler:x("footer")},external:{flags:["e","external"],handler:ee("external")},sourcemap:{flags:["sm","sourcemap"],handler:yn("sourcemap")},target:{flags:["t","target"],handler:x("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:d("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:d("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:d("minifySyntax")},clean:{flags:["c","clean"],handler:d("clean")},splitting:{flags:["s","splitting"],handler:d("splitting")},noExternal:{flags:["ne","no-external"],handler:ee("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:x("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:d("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:d("dtsOnly")},silent:{flags:["silent"],handler:d("silent")},config:{flags:["config"],handler:x("config")},publicPath:{flags:["pp","public-path"],handler:x("publicPath")},env:{flags:["env"],handler:x("env")},shims:{flags:["shims"],handler:d("shims")},onSuccess:{flags:["onSuccess"],handler:x("onSuccess")},entry:{flags:["entry"],handler:(e,n,t)=>{if(typeof e!=="string")throw new h(`Entry${t?` --entry.${t}`:""} requires a string value`);let r=n.entry||{};if(t){if(r[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);r[t]=e}else{let s=U(e);if(r[s])l.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}n.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof e==="string")if(e==="true"||e==="false")n.dts.resolve=e==="true";else n.dts.resolve=e.split(",");else n.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>wn()},version:{flags:["v","version"],handler:()=>Cn()}},v={};for(let e of Object.values(qe))for(let n of e.flags)v[n]=e.handler;function Fe(e){let n={};for(let t=0;t<e.length;t++){let r=e[t];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[t+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")t++}if(s.includes(".")){let[i,a]=s.split(".",2),c=v[i];if(c)c(o,n,a);else throw new h(`Unknown option: --${s}`)}else{let i=v[s];if(i)i(o,n);else throw new h(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[t+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")t++;let a=v[s];if(a)a(i,n);else throw new h(`Unknown option: -${s}`)}else qe.entry.handler(r,n,void 0)}return n}import{loadConfig as
|
|
35
|
+
`),process.exit(0)}function Cn(){console.log(W),process.exit(0)}var qe={name:{flags:["n","name"],handler:x("name")},format:{flags:["f","format"],handler:ee("format")},outDir:{flags:["o","out-dir"],handler:x("outDir")},minify:{flags:["m","minify"],handler:d("minify")},watch:{flags:["w","watch"],handler:d("watch")},dts:{flags:["d","dts"],handler:d("dts")},banner:{flags:["bn","banner"],handler:x("banner")},footer:{flags:["ft","footer"],handler:x("footer")},external:{flags:["e","external"],handler:ee("external")},sourcemap:{flags:["sm","sourcemap"],handler:yn("sourcemap")},target:{flags:["t","target"],handler:x("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:d("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:d("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:d("minifySyntax")},clean:{flags:["c","clean"],handler:d("clean")},splitting:{flags:["s","splitting"],handler:d("splitting")},noExternal:{flags:["ne","no-external"],handler:ee("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:x("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:d("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:d("dtsOnly")},silent:{flags:["silent"],handler:d("silent")},config:{flags:["config"],handler:x("config")},publicPath:{flags:["pp","public-path"],handler:x("publicPath")},env:{flags:["env"],handler:x("env")},shims:{flags:["shims"],handler:d("shims")},onSuccess:{flags:["onSuccess"],handler:x("onSuccess")},entry:{flags:["entry"],handler:(e,n,t)=>{if(typeof e!=="string")throw new h(`Entry${t?` --entry.${t}`:""} requires a string value`);let r=n.entry||{};if(t){if(r[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);r[t]=e}else{let s=U(e);if(r[s])l.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}n.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof e==="string")if(e==="true"||e==="false")n.dts.resolve=e==="true";else n.dts.resolve=e.split(",");else n.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>wn()},version:{flags:["v","version"],handler:()=>Cn()}},v={};for(let e of Object.values(qe))for(let n of e.flags)v[n]=e.handler;function Fe(e){let n={};for(let t=0;t<e.length;t++){let r=e[t];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[t+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")t++}if(s.includes(".")){let[i,a]=s.split(".",2),c=v[i];if(c)c(o,n,a);else throw new h(`Unknown option: --${s}`)}else{let i=v[s];if(i)i(o,n);else throw new h(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[t+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")t++;let a=v[s];if(a)a(i,n);else throw new h(`Unknown option: -${s}`)}else qe.entry.handler(r,n,void 0)}return n}import{loadConfig as Bn}from"coffi";import q from"node:path";import $n from"chokidar";async function Ge(e,n){let t=new Set,r=D(e),s=A(r.entry);for(let c of s){let u=q.resolve(n,c.path),m=q.dirname(u);t.add(m)}let o=$n.watch(Array.from(t),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,q.join(n,r.outDir)]}),i=!1,a=async(c=!1)=>{if(i)return;i=!0;try{let u=performance.now();if(await H({...r,entry:s.map((m)=>m.path),clean:!1},n),!c)l.cli(`\uD83D\uDCE6 Rebuild finished in ${j(performance.now()-u)}`);await ne()}catch(u){G(u)}finally{i=!1}};o.on("change",(c)=>{let u=q.relative(n,c);l.cli(`File changed: ${u}`,{muted:!0,once:u}),a()}),o.on("error",(c)=>{throw new M(`Watcher error: ${b(c)}`)}),await a(!0)}async function Sn(e=Bun.argv.slice(2)){let n=Fe(e);R(n.silent);let t=process.cwd(),{config:r,filepath:s}=await Bn({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:n.config,packageJsonProperty:"bunup"}),o=!r?[{rootDir:t,options:n}]:await Re(r,t);if(l.cli(`Using bunup v${W} and bun v${Bun.version}`,{muted:!0}),s)l.cli(`Using config file: ${y(s,2)}`,{muted:!0});let i=performance.now();l.cli("Build started"),await Promise.all(o.flatMap(({options:u,rootDir:m})=>{return ce(u).map(async(p)=>{let T={...p,...Tn(n)};return En(T,m)})}));let a=performance.now()-i,c=j(a);if(l.cli(`\u26A1\uFE0F Build completed in ${c}`),await ne(),n.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(n.onSuccess)l.cli(`Running command: ${n.onSuccess}`,{muted:!0}),On(n.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!n.watch)process.exit(0)}function Tn(e){return{...e,onSuccess:void 0,config:void 0}}async function ne(){if(S.size>0)await Se(S),S.clear()}async function En(e,n){if(e.watch)await Ge(e,n);else await H(e,n)}Sn().catch((e)=>se(e));export{ne as validateDtsFiles};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.45",
|
|
4
|
+
"description": "A blazing-fast build tool for your libraries built with Bun.",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
7
7
|
"module": "./build/index.mjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"bunup": "^0.4.23",
|
|
21
21
|
"husky": "^9.1.7",
|
|
22
22
|
"typescript": "^5.8.3",
|
|
23
|
-
"create-bunup": "0.4.
|
|
23
|
+
"create-bunup": "0.4.45"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"typescript": ">=4.5.0"
|