bunup 0.3.66 → 0.3.69
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 +10 -10
- package/build/index.js +4 -4
- package/build/index.mjs +4 -4
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{build as
|
|
4
|
-
\x1B[
|
|
5
|
-
`);else console.error("\x1B[
|
|
6
|
-
`);let a=o.labels[0],c=a?
|
|
3
|
+
import{build as Gn}from"rolldown";import{dts as Xn}from"rolldown-plugin-dts";class $ extends Error{constructor(n){super(n);this.name="BunupError"}}class x extends ${constructor(n){super(n);this.name="BunupBuildError"}}class d extends ${constructor(n){super(n);this.name="BunupDTSBuildError"}}class m extends ${constructor(n){super(n);this.name="BunupCLIError"}}class M extends ${constructor(n){super(n);this.name="BunupWatchError"}}var p=(n)=>{if(n instanceof Error)return n.message;return String(n)},Un=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",link:"https://bunup.arshadyaseen.com/#could-not-resolve-bun-error"}],V=(n,t)=>{let e=p(n),r=t?`[${t}] `:"",i="ERROR";if(n instanceof x)i="BUILD ERROR";else if(n instanceof d)i="DTS ERROR";else if(n instanceof m)i="CLI ERROR";else if(n instanceof M)i="WATCH ERROR";else if(n instanceof $)i="BUNUP ERROR";console.error(`\x1B[31m${i}\x1B[0m ${r}${e}`);let s=Un.find((o)=>o.pattern.test(e)&&(o.errorType===i||!o.errorType));if(s)console.error(`
|
|
4
|
+
\x1B[90mA solution for this error is available at: \x1B[36m${s.link}\x1B[0m
|
|
5
|
+
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},nn=(n,t)=>{V(n,t),process.exit(1)};import en from"node:fs/promises";import Fn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function tn(n,t){return{outdir:`${t}/${n.outDir}`,minify:kn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define,loader:n.loader,drop:n.drop,banner:n.banner,footer:n.footer}}function kn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:i}=n,s=t===!0;return{whitespace:e??s,identifiers:r??s,syntax:i??s}}function q(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rn(n=8){return Math.random().toString(36).substring(2,2+n)}function sn(n,t){switch(n){case"esm":return".mjs";case"cjs":return L(t)?".cjs":".js";case"iife":return".global.js"}}function on(n,t){switch(n){case"esm":return".d.mts";case"cjs":return L(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(n){return n==="module"}function D(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 cn(n,t){return n===void 0?t==="esm":n}function G(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function b(n,t=3){return n.split("/").slice(-t).join("/")}async function X(n,t){let e=Fn.join(n,t);try{await en.rm(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}await en.mkdir(e,{recursive:!0})}function Y(n){return n||O.outDir}function ln(n){return n===void 0?O.clean:n}function un(n,t){return t==="cjs"?n:void 0}function fn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${q(t)}($|\\/|\\\\)`):t)}function _(n,t){return fn(n.external||[]).concat(an(t).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function j(n){return fn(n.noExternal||[])}import Vn from"node:path";import{ResolverFactory as qn}from"oxc-resolver";import C from"node:path";var T="\x00dts:",pn=(n,t,e)=>{return{name:"bunup:virtual-dts",async resolveId(r,i){if(J(r))return r;if(!i||!J(i))return null;let s=await N(r,t,e,P(i));if(!s)return null;let o=v(s);if(n.has(o))return U(o);return null},load(r){if(r.startsWith(T)){let i=P(r),s=n.get(i);if(s)return B.add(i),s}return null}}};function v(n){return n.replace(/\.tsx?$/,".d.ts")}function K(n){let t=C.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?C.resolve(t,n.data.compilerOptions.baseUrl):t}function gn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=K(n);for(let[i,s]of Object.entries(e))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,C.join(r,a))}return t}function Wn(n,t,e){for(let[r,i]of t){let s=new RegExp(r),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return e?C.join(e,n):null}async function Hn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function N(n,t,e,r){let i=n.startsWith(".")?C.resolve(C.dirname(r||""),n):Wn(n,t,e);if(!i)return Promise.resolve(null);return Hn(i)}function J(n){return n.startsWith(T)}function P(n){return n.replace(T,"")}function U(n){return`${T}${n}`}var dn;function mn(n){return{name:"bunup:types-resolve",buildStart(){dn||=new qn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?P(e):void 0,/\0/.test(t))return;if(n){if(!n.some((o)=>{let a=!1;if(typeof o==="string")a=o===t||!!(e&&e.includes(o));else a=o.test(t)||!!(e&&o.test(e));return a}))return}let r=e?Vn.dirname(e):process.cwd(),{path:i}=await dn.async(r,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function hn(n,t,e,r,i,s){let o=v(n),a=U(o),c=_(e,r),u=j(e);try{let{output:g}=await Gn({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(f,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(f.code??""))return;h(f)},plugins:[pn(t,i,s),typeof e.dts==="object"&&"resolve"in e.dts&&mn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Xn()],external:(f)=>c.some((h)=>h.test(f))&&!u.some((h)=>h.test(f))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!R.instance)R.instance=new R;return R.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({colorCode:n,label:t,message:e,size:r,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=s?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...g]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${g.join(" ")}${h}`}let c=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`}output(n,t={},e=console.log){if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(e(n),t.verticalSpace)console.log("")}cli(n,t={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}info(n,t={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t)}warn(n,t={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.warn)}error(n,t={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(e,t,console.error)}progress(n,t,e,r){let i=String(n),s=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=r;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,f]of Object.entries(this.colors.progress))if(i.includes(g)){s=f;break}let u=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}}var l=R.getInstance();var Yn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Jn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function xn(n,t,e){let r=new Set([n]),i=[n];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Kn(o);for(let c of a){let u=await N(c,t,e,s);if(!u)continue;if(!r.has(u))r.add(u),i.push(u)}}catch(o){l.warn(`Error processing ${s}: ${p(o)}`)}}return r}function Kn(n){let t=new Set;for(let e of[Yn,Jn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}import{isolatedDeclaration as Qn}from"oxc-transform";async function bn(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=v(e);if(!await Bun.file(e).exists())return;let s=await Bun.file(e).text(),{code:o}=Qn(e,s);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${p(r)}`)}})),t}import wn from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as Zn}from"oxc-transform";async function yn(n,t){let e=Q.resolve(n),r=Q.resolve(e,t);if(!await wn.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(r).exists())throw new d(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${r}`);if(Q.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function En(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),i=await Bun.file(r).text(),{errors:s}=Zn(r,i);s.forEach((o)=>{if(!t)console.log(`
|
|
6
|
+
`);let a=o.labels[0],c=a?zn(i,a.start):"",g=`${b(r)}${c}: ${nt(o.message)}`;l.warn(g),t=!0})}catch{}})),t)l.info(`
|
|
7
7
|
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. Other bundlers might not show these warnings because they use different, potentially less precise methods. 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.
|
|
8
|
-
`)}function
|
|
9
|
-
`),r=e.length,i=e[e.length-1].length+1;return` (${r}:${i})`}function
|
|
8
|
+
`)}function zn(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
|
|
9
|
+
`),r=e.length,i=e[e.length-1].length+1;return` (${r}:${i})`}function nt(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $n(n,t,e,r,i){let{absoluteEntry:s}=await yn(n,t),o=gn(r),a=K(r),c=await xn(s,o,a),u=await bn(c);return hn(s,u,e,i,o,a)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function I(n){let t=[],e=new Set,r={};function i(s,o){if(e.has(s)){let a=rn(),c=`${s}_${a}`;l.warn(`Output name conflict: "${s}" is used by multiple files.
|
|
10
10
|
Bunup uses filenames without extensions as output names by default.
|
|
11
11
|
|
|
12
12
|
${r[s]} -> ${s}.js
|
|
@@ -20,8 +20,8 @@ To fix this, use named entries in your configuration:
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:s,path:o}),e.add(s),r[s]=o}if(Array.isArray(n))for(let s of n){let o=A(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=A(n);i(s,n)}return t}function On(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as tt}from"load-tsconfig";function vn(n){try{return tt(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import Z from"node:path";async function Bn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Z.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let s=await et(r,e);if(!s)continue;return{configs:it(s,n),configFilePath:r}}catch(i){throw new x(`Failed to load config from ${r}: ${p(i)}`)}}return{configs:[],configFilePath:""}}async function et(n,t){if(t===".json"||t===".jsonc")return rt(n);return st(n)}async function rt(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${p(t)}`)}}async function st(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${p(t)}`)}}function it(n,t){let e=[];if(ot(n))at(n,t,e);else if(Array.isArray(n))ct(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function ot(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function at(n,t,e){for(let r of n){let i=Z.resolve(t,r.root);if(Array.isArray(r.config))for(let s of r.config)e.push({options:{name:r.name,...s},rootDir:i});else e.push({options:{name:r.name,...r.config},rootDir:i})}}function ct(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function Cn(n){let t=Z.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${p(e)}`),{packageJson:null,path:t}}}function Rn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let i=r.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var B=new Set;async function k(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new x("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await Cn(t);if(e)l.cli(`Using package.json: ${b(r,2)}`,{muted:!0,once:r,identifier:n.name});let i=e?.type,s=_(n,e),o=j(n),a=[Rn(s,o)],c=I(n.entry),u=tn(n,t),g=n.format.flatMap((f)=>c.map((h)=>{return lt(n,t,h,f,i,a,u)}));if(await Promise.all(g),n.dts){let f=vn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${b(f.path,2)}`,{muted:!0,once:f.path,identifier:n.name});let h=n.format.filter((E)=>{if(E==="iife"&&!L(i)&&n.format.includes("cjs"))return!1;return!0}),Ln=typeof n.dts==="object"&&n.dts.entry?I(n.dts.entry):c;try{await Promise.all(Ln.map(async(E)=>{let Dn=await $n(t,E.path,n,f,e);await Promise.all(h.map(async(_n)=>{let jn=on(_n,i),H=`${t}/${n.outDir}/${E.name}${jn}`;await Bun.write(H,Dn);let Nn=Bun.file(H).size||0;l.progress("DTS",b(H),G(Nn),n.name)}))}))}catch(E){throw new d(p(E))}}}async function lt(n,t,e,r,i,s,o){let a=sn(r,i),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:On(e.name,a)},splitting:cn(n.splitting,r),bytecode:un(n.bytecode,r),plugins:s,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new x(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,g=Bun.file(u).size||0;l.progress(r.toUpperCase(),b(u),G(g),n.name)}var F="0.3.69";var Pn="https://bun.sh/docs/installation",Tn="https://bunup.arshadyaseen.com/#cli-options";function w(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function y(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new m(`Option --${n} requires a string value`)}}function An(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new m(`Option --${n} requires a string value`)}}function ft(){console.log(`
|
|
24
24
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
25
|
-
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${
|
|
26
|
-
`),process.exit(0)}function
|
|
27
|
-
To install Bun, visit `+
|
|
25
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Tn}\x1B[0m
|
|
26
|
+
`),process.exit(0)}function pt(){console.log(F),process.exit(0)}var gt={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new m("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},banner:{flags:["b","banner"],handler:y("banner")},footer:{flags:["f","footer"],handler:y("footer")},external:{flags:["e","external"],handler:An("external")},sourcemap:{flags:["sm","sourcemap"],handler:y("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:An("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")}},dt={resolveDts:{flags:["rd","resolve-dts"],handler:(n,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof n==="string")if(n==="true"||n==="false")t.dts.resolve=n==="true";else t.dts.resolve=n.split(",");else t.dts.resolve=!0}}},mt={help:{flags:["h","help"],handler:()=>ft()},version:{flags:["v","version"],handler:()=>pt()}},S={};for(let n of Object.values(gt))if(n)for(let t of n.flags)S[t]=n.handler;for(let n of Object.values(dt))for(let t of n.flags)S[t]=n.handler;for(let n of Object.values(mt))for(let t of n.flags)S[t]=n.handler;function In(n){let t={},e={},r=0;while(r<n.length){let i=n[r];if(i.startsWith("--")){let s,o;if(i.includes("=")){let[a,c]=i.slice(2).split("=",2);s=a,o=c}else{s=i.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(s==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new m("Option --entry requires a string value");else if(s.startsWith("entry.")){let a=s.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new m(`Option --entry.${a} requires a string value`)}else{let a=S[s];if(a)a(o,t);else throw new m(`Unknown option: --${s}`)}}else if(i.startsWith("-")){let s=i.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=S[s];if(c)c(a,t);else throw new m(`Unknown option: -${s}`)}else{let s=A(i);if(e[s])l.warn(`Duplicate entry name '${s}' derived from positional argument '${i}'. Overwriting previous entry.`);e[s]=i}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
|
|
27
|
+
To install Bun, visit `+Pn)})();import W from"node:path";import ht from"chokidar";async function Sn(n,t){let e=new Set,r=I(n.entry);r.forEach((a)=>{let c=W.resolve(t,a.path),u=W.dirname(c);e.add(u)});let i=ht.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(t,n.outDir)]}),s=!1,o=async(a=!1)=>{if(s)return;s=!0;try{let c=performance.now();if(await k({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${D(performance.now()-c)}`);await z()}catch(c){V(c)}finally{s=!1}};i.on("change",(a)=>{let c=W.relative(t,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),i.on("error",(a)=>{throw new M(`Watcher error: ${p(a)}`)}),await o(!0)}async function xt(n=Bun.argv.slice(2)){let t=In(n),{configs:e,configFilePath:r}=await Bn(process.cwd());if(l.cli(`Using bunup v${F} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${b(r,2)}`,{muted:!0});let i=performance.now();if(l.cli("Build started"),e.length===0){let a={...O,...t},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await Mn(a,c)}else{for(let{options:a,rootDir:c}of e)if(ln(a.clean))X(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...O,...a,...t};await Mn(u,c)}))}let s=performance.now()-i,o=D(s);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0);l.dispose()}async function z(){if(B.size>0)await En(B),B.clear()}async function Mn(n,t){if(n.watch)await Sn(n,t);else await k(n,t),n.onBuildSuccess?.()}xt().catch((n)=>nn(n));export{z as validateDtsFiles,xt as main};
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var It=require("node:module");var
|
|
1
|
+
var It=require("node:module");var Bt=Object.create;var{getPrototypeOf:Dt,defineProperty:R,getOwnPropertyNames:U,getOwnPropertyDescriptor:Ot}=Object,V=Object.prototype.hasOwnProperty;var x=(t,n,r)=>{r=t!=null?Bt(Dt(t)):{};let e=n||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r;for(let i of U(t))if(!V.call(e,i))R(e,i,{get:()=>t[i],enumerable:!0});return e},F=new WeakMap,At=(t)=>{var n=F.get(t),r;if(n)return n;if(n=R({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")U(t).map((e)=>!V.call(n,e)&&R(n,e,{get:()=>t[e],enumerable:!(r=Ot(t,e))||r.enumerable}));return F.set(t,n),n};var Tt=(t,n)=>{for(var r in n)R(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var kt={};Tt(kt,{defineWorkspace:()=>G,defineConfig:()=>k,build:()=>$t});module.exports=At(kt);function k(t){return t}function G(t){return t}var ot=require("rolldown"),at=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends S{constructor(t){super(t);this.name="BunupBuildError"}}class d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};var vt=x(require("node:fs/promises")),Lt=x(require("node:path"));function X(t,n){return{outdir:`${n}/${t.outDir}`,minify:St(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function St(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function H(t=8){return Math.random().toString(36).substring(2,2+t)}function Y(t,n){switch(t){case"esm":return".mjs";case"cjs":return P(n)?".cjs":".js";case"iife":return".global.js"}}function K(t,n){switch(t){case"esm":return".d.mts";case"cjs":return P(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function P(t){return t==="module"}function q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function J(t,n){return t===void 0?n==="esm":t}function L(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function b(t,n=3){return t.split("/").slice(-n).join("/")}function Q(t,n){return n==="cjs"?t:void 0}function Z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function B(t,n){return Z(t.external||[]).concat(q(n).map((r)=>new RegExp(`^${v(r)}($|\\/|\\\\)`)))}function D(t){return Z(t.noExternal||[])}var et=x(require("node:path")),st=require("oxc-resolver");var h=x(require("node:path"));var M="\x00dts:",z=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(j(e))return e;if(!i||!j(i))return null;let s=await O(e,n,r,C(i));if(!s)return null;let o=$(s);if(t.has(o))return A(o);return null},load(e){if(e.startsWith(M)){let i=C(e),s=t.get(i);if(s)return tt.add(i),s}return null}}};function $(t){return t.replace(/\.tsx?$/,".d.ts")}function _(t){let n=h.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?h.default.resolve(n,t.data.compilerOptions.baseUrl):n}function nt(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=_(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,h.default.join(e,a))}return n}function jt(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?h.default.join(r,t):null}async function _t(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function O(t,n,r,e){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(e||""),t):jt(t,n,r);if(!i)return Promise.resolve(null);return _t(i)}function j(t){return t.startsWith(M)}function C(t){return t.replace(M,"")}function A(t){return`${M}${t}`}var rt;function it(t){return{name:"bunup:types-resolve",buildStart(){rt||=new st.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?C(r):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(r&&r.includes(o));else a=o.test(n)||!!(r&&o.test(r));return a}))return}let e=r?et.default.dirname(r):process.cwd(),{path:i}=await rt.async(e,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function ct(t,n,r,e,i,s){let o=$(t),a=A(o),u=B(r,e),l=D(r);try{let{output:g}=await ot.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[z(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&it(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),at.dts()],external:(c)=>u.some((m)=>m.test(c))&&!l.some((m)=>m.test(c))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class y{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(!y.instance)y.instance=new y;return y.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,u={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:u.muted});this.output(l,u)}}var f=y.getInstance();var Nt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Wt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function ut(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Ft(o);for(let u of a){let l=await O(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${p(o)}`)}}return e}function Ft(t){let n=new Set;for(let r of[Nt,Wt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}var lt=require("oxc-transform");async function ft(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=$(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=lt.isolatedDeclaration(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}var N=x(require("node:fs/promises")),T=x(require("node:path")),Ut=require("oxc-transform");async function gt(t,n){let r=T.default.resolve(t),e=T.default.resolve(r,n);if(!await N.default.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(T.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function pt(t,n,r,e,i){let{absoluteEntry:s}=await gt(t,n),o=nt(e),a=_(e),u=await ut(s,o,a),l=await ft(u);return ct(s,l,r,i,o,a)}function mt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=H(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${e[s]} -> ${s}.js
|
|
5
|
-
${
|
|
5
|
+
${o} -> ${u}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
10
|
custom_name: "${e[s]}",
|
|
11
|
-
another_name: "${
|
|
11
|
+
another_name: "${o}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=mt(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=mt(t);i(s,t)}return n}function dt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}var Et=x(require("node:path"));async function wt(t){let n=Et.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function bt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var tt=new Set;async function $t(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await wt(n);if(r)f.cli(`Using package.json: ${b(e,2)}`,{muted:!0,once:e,identifier:t.name});let i=r?.type,s=B(t,r),o=D(t),a=[bt(s,o)],u=W(t.entry),l=X(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Vt(t,n,m,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${b(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((E)=>{if(E==="iife"&&!P(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):u;try{await Promise.all(yt.map(async(E)=>{let Rt=await pt(n,E.path,t,c,r);await Promise.all(m.map(async(Ct)=>{let Mt=K(Ct,i),I=`${n}/${t.outDir}/${E.name}${Mt}`;await Bun.write(I,Rt);let Pt=Bun.file(I).size||0;f.progress("DTS",b(I),L(Pt),t.name)}))}))}catch(E){throw new d(p(E))}}}async function Vt(t,n,r,e,i,s,o){let a=Y(e,i),u=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:dt(r.name,a)},splitting:J(t.splitting,e),bytecode:Q(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new w(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),b(l),L(g),t.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function gt(t){return t}function
|
|
1
|
+
function gt(t){return t}function pt(t){return t}import{build as wt}from"rolldown";import{dts as bt}from"rolldown-plugin-dts";class A extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends A{constructor(t){super(t);this.name="BunupBuildError"}}class d extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)};import vt from"node:fs/promises";import jt from"node:path";function _(t,n){return{outdir:`${n}/${t.outDir}`,minify:mt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap,define:t.define,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer}}function mt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=t,s=n===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function T(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function F(t,n){switch(t){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(t){return t==="module"}function U(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function V(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function E(t,n=3){return t.split("/").slice(-n).join("/")}function k(t,n){return n==="cjs"?t:void 0}function G(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${T(n)}($|\\/|\\\\)`):n)}function M(t,n){return G(t.external||[]).concat(U(n).map((r)=>new RegExp(`^${T(r)}($|\\/|\\\\)`)))}function P(t){return G(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as Et}from"oxc-resolver";import b from"node:path";var R="\x00dts:",X=(t,n,r)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(S(e))return e;if(!i||!S(i))return null;let s=await B(e,n,r,y(i));if(!s)return null;let o=w(s);if(t.has(o))return D(o);return null},load(e){if(e.startsWith(R)){let i=y(e),s=t.get(i);if(s)return H.add(i),s}return null}}};function w(t){return t.replace(/\.tsx?$/,".d.ts")}function v(t){let n=b.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?b.resolve(n,t.data.compilerOptions.baseUrl):n}function Y(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=v(t);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),a=s[0].replace(/\*/g,"$1");n.set(`^${o}$`,b.join(e,a))}return n}function dt(t,n,r){for(let[e,i]of n){let s=new RegExp(e),o=t.match(s);if(o)return i.replace("$1",o[1]||"")}return r?b.join(r,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function B(t,n,r,e){let i=t.startsWith(".")?b.resolve(b.dirname(e||""),t):dt(t,n,r);if(!i)return Promise.resolve(null);return xt(i)}function S(t){return t.startsWith(R)}function y(t){return t.replace(R,"")}function D(t){return`${R}${t}`}var K;function q(t){return{name:"bunup:types-resolve",buildStart(){K||=new Et({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,r){if(r=r?y(r):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(r&&r.includes(o));else a=o.test(n)||!!(r&&o.test(r));return a}))return}let e=r?ht.dirname(r):process.cwd(),{path:i}=await K.async(e,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function J(t,n,r,e,i,s){let o=w(t),a=D(o),u=M(r,e),l=P(r);try{let{output:g}=await wt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,m){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;m(c)},plugins:[X(n,i,s),typeof r.dts==="object"&&"resolve"in r.dts&&q(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),bt()],external:(c)=>u.some((m)=>m.test(c))&&!l.some((m)=>m.test(c))});if(!g[0]?.code)throw new d("Generated bundle is empty");return g[0].code}catch(g){throw new d(`DTS bundling failed: ${p(g)}`)}}class ${static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",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(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:n,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${l}${c} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let u=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${u}`}output(t,n={},r=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(r(t),n.verticalSpace)console.log("")}cli(t,n={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}info(t,n={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n)}warn(t,n={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.warn)}error(t,n={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(r,n,console.error)}progress(t,n,r,e){let i=String(t),s=this.colors.default,o,a,u={};if(typeof r==="string")o=r,a=e;else if(r)o=r.size,a=r.identifier,u=r;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){s=c;break}let l=this.formatMessage({colorCode:s,label:i,message:n,size:o,identifier:a,muted:u.muted});this.output(l,u)}}var f=$.getInstance();var $t=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,yt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Q(t,n,r){let e=new Set([t]),i=[t];while(i.length){let s=i.pop();if(!s)continue;try{let o=await Bun.file(s).text(),a=Rt(o);for(let u of a){let l=await B(u,n,r,s);if(!l)continue;if(!e.has(l))e.add(l),i.push(l)}}catch(o){f.warn(`Error processing ${s}: ${p(o)}`)}}return e}function Rt(t){let n=new Set;for(let r of[$t,yt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}import{isolatedDeclaration as Ct}from"oxc-transform";async function Z(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=w(r);if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=Ct(r,s);if(o)n.set(e,o)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}import z from"node:fs/promises";import L from"node:path";import{isolatedDeclaration as $n}from"oxc-transform";async function tt(t,n){let r=L.resolve(t),e=L.resolve(r,n);if(!await z.exists(r))throw new d(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(L.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function nt(t,n,r,e,i){let{absoluteEntry:s}=await tt(t,n),o=Y(e),a=v(e),u=await Q(s,o,a),l=await Z(u);return J(s,l,r,i,o,a)}function rt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set,e={};function i(s,o){if(r.has(s)){let a=N(),u=`${s}_${a}`;f.warn(`Output name conflict: "${s}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${e[s]} -> ${s}.js
|
|
5
|
-
${
|
|
5
|
+
${o} -> ${u}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
10
|
custom_name: "${e[s]}",
|
|
11
|
-
another_name: "${
|
|
11
|
+
another_name: "${o}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:u,path:o})}else n.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(t))for(let s of t){let o=rt(s);i(o,s)}else if(typeof t==="object")Object.entries(t).forEach(([s,o])=>{i(s,o)});else{let s=rt(t);i(s,t)}return n}function et(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Mt}from"load-tsconfig";function st(t){try{return Mt(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import Pt from"node:path";async function it(t){let n=Pt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let e=await Bun.file(n).text();return{packageJson:JSON.parse(e),path:n}}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),{packageJson:null,path:n}}}function ot(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var H=new Set;async function Bt(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await it(n);if(r)f.cli(`Using package.json: ${E(e,2)}`,{muted:!0,once:e,identifier:t.name});let i=r?.type,s=M(t,r),o=P(t),a=[ot(s,o)],u=j(t.entry),l=_(t,n),g=t.format.flatMap((c)=>u.map((m)=>{return Dt(t,n,m,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=st(t.preferredTsconfigPath);if(c.path)f.cli(`Using tsconfig: ${E(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let m=t.format.filter((x)=>{if(x==="iife"&&!C(i)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?j(t.dts.entry):u;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,r);await Promise.all(m.map(async(ut)=>{let lt=F(ut,i),O=`${n}/${t.outDir}/${x.name}${lt}`;await Bun.write(O,ct);let ft=Bun.file(O).size||0;f.progress("DTS",E(O),I(ft),t.name)}))}))}catch(x){throw new d(p(x))}}}async function Dt(t,n,r,e,i,s,o){let a=W(e,i),u=await Bun.build({...o,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:et(r.name,a)},splitting:V(t.splitting,e),bytecode:k(t.bytecode,e),plugins:s,throw:!1});if(!u.success)u.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)});let l=`${n}/${t.outDir}/${r.name}${a}`,g=Bun.file(l).size||0;f.progress(e.toUpperCase(),E(l),I(g),t.name)}export{pt as defineWorkspace,gt as defineConfig,Bt as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.69",
|
|
4
4
|
"description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"prettier": "^3.5.3",
|
|
25
25
|
"typescript": "^5.8.3",
|
|
26
26
|
"vitest": "^2.1.9",
|
|
27
|
-
"create-bunup": "0.3.
|
|
27
|
+
"create-bunup": "0.3.69"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"typescript": ">=4.5.0"
|