bunup 0.3.16 → 0.3.17
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 +4 -4
- package/build/index.js +2 -2
- package/build/index.mjs +2 -2
- package/package.json +1 -1
package/build/cli.mjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
import{rolldown as Ln}from"rolldown";import{dts as Hn}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 h extends ${constructor(n){super(n);this.name="BunupCLIError"}}class j extends ${constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},Sn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof x)s="BUILD ERROR";else if(n instanceof d)s="DTS ERROR";else if(n instanceof h)s="CLI ERROR";else if(n instanceof j)s="WATCH ERROR";else if(n instanceof $)s="BUNUP ERROR";if(console.error(`\x1B[31m${s}\x1B[0m ${r}${e}`),n instanceof Error&&n.stack)console.error("\x1B[2m"+n.stack.split(`
|
|
4
4
|
`).slice(1).join(`
|
|
5
|
-
`)+"\x1B[0m")},z=(n,t)=>{Sn(n,t),process.exit(1)};import G from"node:fs/promises";import Tn from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function K(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(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 Nn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function _(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(n=8){return Math.random().toString(36).substring(2,2+n)}function Z(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function X(n,t){switch(n){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function T(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function F(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function V(n,t){return n===void 0?t==="esm":n}function q(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 w(n,t=3){return n.split("/").slice(-t).join("/")}async function P(n,t){let e=Tn.join(n,t);if(await G.exists(e))try{await G.rm(e,{recursive:!0})}catch(s){
|
|
6
|
-
`);let a=o.labels[0],c=a?In(s,a.start):"",
|
|
5
|
+
`)+"\x1B[0m")},z=(n,t)=>{Sn(n,t),process.exit(1)};import G from"node:fs/promises";import Tn from"node:path";var l={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"},formatMessage({colorCode:n,label:t,message:e,size:r,identifier:s,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(r){let[u,...p]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),R=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${u}${f} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${p.join(" ")}${R}`}let c=s?` \x1B[48;5;${n};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${a}${c}`},output(n,t={},e=console.log){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 s=String(n),i=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[p,f]of Object.entries(this.colors.progress))if(s.includes(p)){i=f;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}};var O={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function K(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(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 Nn(n){let{minify:t,minifyWhitespace:e,minifyIdentifiers:r,minifySyntax:s}=n,i=t===!0;return{whitespace:e??i,identifiers:r??i,syntax:s??i}}function _(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(n=8){return Math.random().toString(36).substring(2,2+n)}function Z(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function X(n,t){switch(n){case"esm":return".d.mts";case"cjs":return N(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(n){return n==="module"}function T(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function F(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function V(n,t){return n===void 0?t==="esm":n}function q(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 w(n,t=3){return n.split("/").slice(-t).join("/")}async function P(n,t){let e=Tn.join(n,t);if(await G.exists(e))try{await G.rm(e,{recursive:!0})}catch(s){l.warn(`Could not clean output directory: ${m(s)}`)}try{await G.mkdir(e,{recursive:!0})}catch(s){throw new x(`Failed to create output directory: ${m(s)}`)}}function Y(n){return n||O.outDir}function nn(n){return n===void 0?O.clean:n}function tn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${_(t)}($|\\/|\\\\)`):t)}function M(n,t){return tn(n.external||[]).concat(F(t).map((e)=>new RegExp(`^${_(e)}($|\\/|\\\\)`)))}function k(n){return tn(n.noExternal||[])}import Mn from"node:path";import{ResolverFactory as kn}from"oxc-resolver";import C from"path";var g="\x00virtual:",en=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(g))return t;if(!e?.startsWith(g)||!t.startsWith("."))return null;let r=e.slice(g.length),s=C.resolve(C.dirname(r),t);if(t==="."){let o=C.join(C.dirname(r),"index.d.ts");if(n.has(o))return`${g}${o}`;s=C.dirname(r)}if(n.has(s))return`${g}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${g}${i}`;if(t.startsWith(".")){let o=C.join(s,"index.d.ts");if(n.has(o))return`${g}${o}`}return null},load(t){if(t.startsWith(g)){let e=t.slice(g.length),r=n.get(e);if(r)return B.add(e),r}return null}}};var rn;function sn(n){return{name:"bunup:types-resolve",buildStart(){rn||=new kn({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(e=e?.replace(g,""),/\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?Mn.dirname(e):process.cwd(),{path:s}=await rn.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return s}}}async function on(n,t,e,r){let s=n.replace(/\.tsx?$/,".d.ts"),i=`${g}${s}`,o=M(e,r),a=k(e),c;try{c=await Ln({input:i,onwarn(p,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;f(p)},plugins:[en(t),typeof e.dts==="object"&&"resolve"in e.dts&&sn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Hn()],external:(p)=>o.some((f)=>f.test(p))&&!a.some((f)=>f.test(p))});let{output:u}=await c.generate({});if(!u[0]?.code)throw new d("Generated bundle is empty");return u[0].code}catch(u){throw new d(`DTS bundling failed: ${m(u)}`)}finally{if(c)await c.close()}}import E from"node:path";var Un=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Dn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function an(n,t){let e=new Set([n]),r=[n],s=_n(t),i=cn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await Bun.file(o).text(),c=Wn(a);for(let u of c){let p=u.startsWith(".")?E.resolve(E.dirname(o),u):qn(u,s,i);if(!p)continue;let f=await Gn(p);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return e}function Wn(n){let t=new Set;for(let e of[Un,Dn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}async function Gn(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 cn(n){let t=E.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?E.resolve(t,n.data.compilerOptions.baseUrl):t}function _n(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=cn(n);for(let[s,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");t.set(`^${o}$`,E.join(r,a))}return t}function qn(n,t,e){for(let[r,s]of t){let i=new RegExp(r),o=n.match(i);if(o)return s.replace("$1",o[1]||"")}return e?E.join(e,n):null}import{isolatedDeclaration as Pn}from"oxc-transform";async function ln(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Pn(e,i);if(o)t.set(r,o)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import fn from"node:fs/promises";import I from"node:path";import{isolatedDeclaration as Yn}from"oxc-transform";async function un(n,t){let e=I.resolve(n),r=I.resolve(e,t);if(!await fn.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(I.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function mn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:i}=Yn(r,s);i.forEach((o)=>{if(!t)console.log(`
|
|
6
|
+
`);let a=o.labels[0],c=a?In(s,a.start):"",p=`${w(r)}${c}: ${Jn(o.message)}`;l.warn(p),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
8
|
`)}function In(n,t){if(t===void 0)return"";let e=n.slice(0,t).split(`
|
|
9
|
-
`),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function Jn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function
|
|
9
|
+
`),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function Jn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function pn(n,t,e,r,s){let{absoluteEntry:i}=await un(n,t),o=await an(i,r),a=await ln(o);return on(i,a,e,s)}function A(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function S(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=Q(),c=`${i}_${a}`;l.warn(`Output name conflict: "${i}" is used by multiple files.
|
|
10
10
|
Bunup uses filenames without extensions as output names by default.
|
|
11
11
|
|
|
12
12
|
${r[i]} -> ${i}.js
|
|
@@ -20,7 +20,7 @@ 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}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function gn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as zn}from"load-tsconfig";function dn(n){try{return zn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import J from"node:path";async function hn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=J.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Kn(r,e);if(!i)continue;return{configs:Xn(i,n),configFilePath:r}}catch(s){throw new x(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Kn(n,t){if(t===".json"||t===".jsonc")return Qn(n);return Zn(n)}async function Qn(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. ${m(t)}`)}}async function Zn(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. ${m(t)}`)}}function Xn(n,t){let e=[];if(Fn(n))Vn(n,t,e);else if(Array.isArray(n))nt(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 Fn(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 Vn(n,t,e){for(let r of n){let s=J.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function nt(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 xn(n){let t=J.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}: ${m(e)}`),{packageJson:null,path:t}}}function wn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var B=new Set;async function L(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 xn(t);if(e)l.cli(`Using package.json: ${w(r,2)}`,{muted:!0});let s=e?.type,i=M(n,e),o=k(n),a=[wn(i,o)],c=S(n.entry),u=K(n,t),p=n.format.flatMap((f)=>c.map((R)=>{return tt(n,t,R,f,s,a,u)}));if(await Promise.all(p),n.dts){let f=dn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path,2)}`,{muted:!0});let R=n.format.filter((b)=>{if(b==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),En=typeof n.dts==="object"&&n.dts.entry?S(n.dts.entry):c;try{await Promise.all(En.map(async(b)=>{let vn=await pn(t,b.path,n,f,e);await Promise.all(R.map(async(Rn)=>{let jn=X(Rn,s),W=`${t}/${n.outDir}/${b.name}${jn}`;await Bun.write(W,vn);let An=Bun.file(W).size||0;l.progress("DTS",w(W),q(An),n.name)}))}))}catch(b){throw new d(m(b))}}}async function tt(n,t,e,r,s,i,o){let a=Z(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:gn(e.name,a)},splitting:V(n.splitting,r),plugins:i,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}`,p=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),q(p),n.name)}var H="0.3.17";var yn="https://bun.sh/docs/installation",bn="https://bunup.arshadyaseen.com/#cli-options";function y(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function v(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function $n(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function rt(){console.log(`
|
|
24
24
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
25
25
|
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${bn}\x1B[0m
|
|
26
26
|
`),process.exit(0)}function st(){console.log(H),process.exit(0)}var it={name:{flags:["n","name"],handler:v("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:v("outDir")},minify:{flags:["m","minify"],handler:y("minify")},watch:{flags:["w","watch"],handler:y("watch")},dts:{flags:["d","dts"],handler:y("dts")},banner:{flags:["b","banner"],handler:v("banner")},footer:{flags:["f","footer"],handler:v("footer")},external:{flags:["e","external"],handler:$n("external")},sourcemap:{flags:["sm","sourcemap"],handler:v("sourcemap")},target:{flags:["t","target"],handler:v("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:y("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:y("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:y("minifySyntax")},clean:{flags:["c","clean"],handler:y("clean")},splitting:{flags:["s","splitting"],handler:y("splitting")},noExternal:{flags:["ne","no-external"],handler:$n("noExternal")}},ot={help:{flags:["h","help"],handler:()=>rt()},version:{flags:["v","version"],handler:()=>st()}},U={};for(let n of Object.values(it))if(n)for(let t of n.flags)U[t]=n.handler;for(let n of Object.values(ot))for(let t of n.flags)U[t]=n.handler;function On(n){let t={},e={},r=0;while(r<n.length){let s=n[r];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(i==="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 h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.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 h(`Option --entry.${a} requires a string value`)}else{let a=U[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=U[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=A(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var jn=require("node:module");var Cn=Object.create;var{getPrototypeOf:hn,defineProperty:b,getOwnPropertyNames:v,getOwnPropertyDescriptor:bn}=Object,G=Object.prototype.hasOwnProperty;var d=(n,t,r)=>{r=n!=null?Cn(hn(n)):{};let e=t||!n||!n.__esModule?b(r,"default",{value:n,enumerable:!0}):r;for(let i of v(n))if(!G.call(e,i))b(e,i,{get:()=>n[i],enumerable:!0});return e},T=new WeakMap,Rn=(n)=>{var t=T.get(n),r;if(t)return t;if(t=b({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")v(n).map((e)=>!G.call(t,e)&&b(t,e,{get:()=>n[e],enumerable:!(r=bn(n,e))||r.enumerable}));return T.set(n,t),t};var Bn=(n,t)=>{for(var r in t)b(n,r,{get:t[r],enumerable:!0,configurable:!0,set:(e)=>t[r]=()=>e})};var Hn={};Bn(Hn,{defineWorkspace:()=>H,defineConfig:()=>k,build:()=>pn});module.exports=Rn(Hn);function k(n){return n}function H(n){return n}var V=require("rolldown"),F=require("rolldown-plugin-dts");class A extends Error{constructor(n){super(n);this.name="BunupError"}}class y extends A{constructor(n){super(n);this.name="BunupBuildError"}}class p extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var
|
|
1
|
+
var jn=require("node:module");var Cn=Object.create;var{getPrototypeOf:hn,defineProperty:b,getOwnPropertyNames:v,getOwnPropertyDescriptor:bn}=Object,G=Object.prototype.hasOwnProperty;var d=(n,t,r)=>{r=n!=null?Cn(hn(n)):{};let e=t||!n||!n.__esModule?b(r,"default",{value:n,enumerable:!0}):r;for(let i of v(n))if(!G.call(e,i))b(e,i,{get:()=>n[i],enumerable:!0});return e},T=new WeakMap,Rn=(n)=>{var t=T.get(n),r;if(t)return t;if(t=b({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")v(n).map((e)=>!G.call(t,e)&&b(t,e,{get:()=>n[e],enumerable:!(r=bn(n,e))||r.enumerable}));return T.set(n,t),t};var Bn=(n,t)=>{for(var r in t)b(n,r,{get:t[r],enumerable:!0,configurable:!0,set:(e)=>t[r]=()=>e})};var Hn={};Bn(Hn,{defineWorkspace:()=>H,defineConfig:()=>k,build:()=>pn});module.exports=Rn(Hn);function k(n){return n}function H(n){return n}var V=require("rolldown"),F=require("rolldown-plugin-dts");class A extends Error{constructor(n){super(n);this.name="BunupError"}}class y extends A{constructor(n){super(n);this.name="BunupBuildError"}}class p extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)};var Mn=d(require("node:fs/promises")),An=d(require("node:path"));var u={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[g,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),h=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${g}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${h}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let g=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(g,f)}};function L(n,t){return{outdir:`${t}/${n.outDir}`,minify:On(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 On(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function N(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(n=8){return Math.random().toString(36).substring(2,2+n)}function J(n,t){switch(n){case"esm":return".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function q(n,t){switch(n){case"esm":return".d.mts";case"cjs":return R(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(n){return n==="module"}function K(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function Q(n,t){return n===void 0?t==="esm":n}function S(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function C(n,t=3){return n.split("/").slice(-t).join("/")}function Z(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${N(t)}($|\\/|\\\\)`):t)}function B(n,t){return Z(n.external||[]).concat(K(t).map((r)=>new RegExp(`^${N(r)}($|\\/|\\\\)`)))}function j(n){return Z(n.noExternal||[])}var P=d(require("node:path")),X=require("oxc-resolver");var w=d(require("path"));var x="\x00virtual:",U=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(x))return t;if(!r?.startsWith(x)||!t.startsWith("."))return null;let e=r.slice(x.length),i=w.default.resolve(w.default.dirname(e),t);if(t==="."){let o=w.default.join(w.default.dirname(e),"index.d.ts");if(n.has(o))return`${x}${o}`;i=w.default.dirname(e)}if(n.has(i))return`${x}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${x}${s}`;if(t.startsWith(".")){let o=w.default.join(i,"index.d.ts");if(n.has(o))return`${x}${o}`}return null},load(t){if(t.startsWith(x)){let r=t.slice(x.length),e=n.get(r);if(e)return _.add(r),e}return null}}};var z;function I(n){return{name:"bunup:types-resolve",buildStart(){z||=new X.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(x,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?P.default.dirname(r):process.cwd(),{path:i}=await z.async(e,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 nn(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${x}${i}`,o=B(r,e),c=j(r),f;try{f=await V.rolldown({input:s,onwarn(l,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;a(l)},plugins:[U(t),typeof r.dts==="object"&&"resolve"in r.dts&&I(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),F.dts()],external:(l)=>o.some((a)=>a.test(l))&&!c.some((a)=>a.test(l))});let{output:g}=await f.generate({});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${m(g)}`)}finally{if(f)await f.close()}}var $=d(require("node:path"));var Nn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Sn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function tn(n,t){let r=new Set([n]),e=[n],i=Tn(t),s=rn(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=Dn(c);for(let g of f){let l=g.startsWith(".")?$.default.resolve($.default.dirname(o),g):vn(g,i,s);if(!l)continue;let a=await Wn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${o}: ${m(c)}`)}}return r}function Dn(n){let t=new Set;for(let r of[Nn,Sn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function Wn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function rn(n){let t=$.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?$.default.resolve(t,n.data.compilerOptions.baseUrl):t}function Tn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=rn(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,$.default.join(e,c))}return t}function vn(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?$.default.join(r,n):null}var en=require("oxc-transform");async function sn(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=en.isolatedDeclaration(r,s);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${m(e)}`)}})),t}var D=d(require("node:fs/promises")),O=d(require("node:path")),Gn=require("oxc-transform");async function on(n,t){let r=O.default.resolve(n),e=O.default.resolve(r,t);if(!await D.default.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(O.default.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function cn(n,t,r,e,i){let{absoluteEntry:s}=await on(n,t),o=await tn(s,e),c=await sn(o);return nn(s,c,r,i)}function an(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=Y(),f=`${s}_${c}`;u.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
|
|
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=an(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=an(n);i(s,n)}return t}function fn(n,t){return`[dir]/${n}${t}`}var un=require("load-tsconfig");function gn(n){try{return un.loadTsConfig(".",n)}catch(t){return
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=an(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=an(n);i(s,n)}return t}function fn(n,t){return`[dir]/${n}${t}`}var un=require("load-tsconfig");function gn(n){try{return un.loadTsConfig(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}var ln=d(require("node:path"));async function mn(n){let t=ln.default.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return u.warn(`Failed to load package.json at ${t}: ${m(r)}`),{packageJson:null,path:t}}}function xn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var _=new Set;async function pn(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:r,path:e}=await mn(t);if(r)u.cli(`Using package.json: ${C(e,2)}`,{muted:!0});let i=r?.type,s=B(n,r),o=j(n),c=[xn(s,o)],f=W(n.entry),g=L(n,t),l=n.format.flatMap((a)=>f.map((h)=>{return kn(n,t,h,a,i,c,g)}));if(await Promise.all(l),n.dts){let a=gn(n.preferredTsconfigPath);if(a.path)u.cli(`Using tsconfig: ${C(a.path,2)}`,{muted:!0});let h=n.format.filter((E)=>{if(E==="iife"&&!R(i)&&n.format.includes("cjs"))return!1;return!0}),dn=typeof n.dts==="object"&&n.dts.entry?W(n.dts.entry):f;try{await Promise.all(dn.map(async(E)=>{let wn=await cn(t,E.path,n,a,r);await Promise.all(h.map(async($n)=>{let En=q($n,i),M=`${t}/${n.outDir}/${E.name}${En}`;await Bun.write(M,wn);let yn=Bun.file(M).size||0;u.progress("DTS",C(M),S(yn),n.name)}))}))}catch(E){throw new p(m(E))}}}async function kn(n,t,r,e,i,s,o){let c=J(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:fn(r.name,c)},splitting:Q(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new y(a.message);else if(a.level==="warning")u.warn(a.message);else if(a.level==="info")u.info(a.message)});let g=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(g).size||0;u.progress(e.toUpperCase(),C(g),S(l),n.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function on(n){return n}function cn(n){return n}import{rolldown as gn}from"rolldown";import{dts as ln}from"rolldown-plugin-dts";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends j{constructor(n){super(n);this.name="BunupBuildError"}}class p extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var
|
|
1
|
+
function on(n){return n}function cn(n){return n}import{rolldown as gn}from"rolldown";import{dts as ln}from"rolldown-plugin-dts";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends j{constructor(n){super(n);this.name="BunupBuildError"}}class p extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)};import Nn from"node:fs/promises";import Dn from"node:path";var u={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"},formatMessage({colorCode:n,label:t,message:r,size:e,identifier:i,muted:s}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=s?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[g,...l]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),C=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${g}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${l.join(" ")}${C}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${o}${c}${f}`},output(n,t={},r=console.log){if(t.verticalSpace)console.log("");if(r(n),t.verticalSpace)console.log("")},cli(n,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},info(n,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t)},warn(n,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)},error(n,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:n,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)},progress(n,t,r,e){let i=String(n),s=this.colors.default,o,c,f={};if(typeof r==="string")o=r,c=e;else if(r)o=r.size,c=r.identifier,f=r;for(let[l,a]of Object.entries(this.colors.progress))if(i.includes(l)){s=a;break}let g=this.formatMessage({colorCode:s,label:i,message:t,size:o,identifier:c,muted:f.muted});this.output(g,f)}};function S(n,t){return{outdir:`${t}/${n.outDir}`,minify:an(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 an(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,s=t===!0;return{whitespace:r??s,identifiers:e??s,syntax:i??s}}function O(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(n=8){return Math.random().toString(36).substring(2,2+n)}function W(n,t){switch(n){case"esm":return".mjs";case"cjs":return h(t)?".cjs":".js";case"iife":return".global.js"}}function T(n,t){switch(n){case"esm":return".d.mts";case"cjs":return h(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function h(n){return n==="module"}function v(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function G(n,t){return n===void 0?t==="esm":n}function M(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(1024));if(r===0)return`${n} ${t[r]}`;return`${(n/Math.pow(1024,r)).toFixed(2)} ${t[r]}`}function $(n,t=3){return n.split("/").slice(-t).join("/")}function k(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${O(t)}($|\\/|\\\\)`):t)}function b(n,t){return k(n.external||[]).concat(v(t).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function R(n){return k(n.noExternal||[])}import fn from"node:path";import{ResolverFactory as un}from"oxc-resolver";import E from"path";var x="\x00virtual:",H=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(x))return t;if(!r?.startsWith(x)||!t.startsWith("."))return null;let e=r.slice(x.length),i=E.resolve(E.dirname(e),t);if(t==="."){let o=E.join(E.dirname(e),"index.d.ts");if(n.has(o))return`${x}${o}`;i=E.dirname(e)}if(n.has(i))return`${x}${i}`;let s=`${i}.d.ts`;if(n.has(s))return`${x}${s}`;if(t.startsWith(".")){let o=E.join(i,"index.d.ts");if(n.has(o))return`${x}${o}`}return null},load(t){if(t.startsWith(x)){let r=t.slice(x.length),e=n.get(r);if(e)return L.add(r),e}return null}}};var Y;function J(n){return{name:"bunup:types-resolve",buildStart(){Y||=new un({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(r=r?.replace(x,""),/\0/.test(t))return;if(n){if(!n.some((o)=>{let c=!1;if(typeof o==="string")c=o===t||!!(r&&r.includes(o));else c=o.test(t)||!!(r&&o.test(r));return c}))return}let e=r?fn.dirname(r):process.cwd(),{path:i}=await Y.async(e,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 q(n,t,r,e){let i=n.replace(/\.tsx?$/,".d.ts"),s=`${x}${i}`,o=b(r,e),c=R(r),f;try{f=await gn({input:s,onwarn(l,a){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(l.code??""))return;a(l)},plugins:[H(t),typeof r.dts==="object"&&"resolve"in r.dts&&J(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),ln()],external:(l)=>o.some((a)=>a.test(l))&&!c.some((a)=>a.test(l))});let{output:g}=await f.generate({});if(!g[0]?.code)throw new p("Generated bundle is empty");return g[0].code}catch(g){throw new p(`DTS bundling failed: ${m(g)}`)}finally{if(f)await f.close()}}import y from"node:path";var mn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,xn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function K(n,t){let r=new Set([n]),e=[n],i=wn(t),s=Q(t);while(e.length){let o=e.pop();if(!o)continue;try{let c=await Bun.file(o).text(),f=pn(c);for(let g of f){let l=g.startsWith(".")?y.resolve(y.dirname(o),g):$n(g,i,s);if(!l)continue;let a=await dn(l);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${o}: ${m(c)}`)}}return r}function pn(n){let t=new Set;for(let r of[mn,xn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}async function dn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(await Bun.file(e).exists()&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function Q(n){let t=y.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?y.resolve(t,n.data.compilerOptions.baseUrl):t}function wn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=Q(n);for(let[i,s]of Object.entries(r))if(Array.isArray(s)&&s.length){let o=i.replace(/\*/g,"(.*)"),c=s[0].replace(/\*/g,"$1");t.set(`^${o}$`,y.join(e,c))}return t}function $n(n,t,r){for(let[e,i]of t){let s=new RegExp(e),o=n.match(s);if(o)return i.replace("$1",o[1]||"")}return r?y.join(r,n):null}import{isolatedDeclaration as En}from"oxc-transform";async function Z(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts");if(!await Bun.file(r).exists())return;let s=await Bun.file(r).text(),{code:o}=En(r,s);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${m(e)}`)}})),t}import U from"node:fs/promises";import A from"node:path";import{isolatedDeclaration as lt}from"oxc-transform";async function _(n,t){let r=A.resolve(n),e=A.resolve(r,t);if(!await U.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(e).exists())throw new p(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.relative(r,e).startsWith(".."))throw new p(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function z(n,t,r,e,i){let{absoluteEntry:s}=await _(n,t),o=await K(s,e),c=await Z(o);return q(s,c,r,i)}function P(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(n){let t=[],r=new Set,e={};function i(s,o){if(r.has(s)){let c=D(),f=`${s}_${c}`;u.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
|
|
@@ -12,4 +12,4 @@ To fix this, use named entries in your configuration:
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=P(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=P(n);i(s,n)}return t}function X(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as yn}from"load-tsconfig";function I(n){try{return yn(".",n)}catch(t){return
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:o})}else t.push({name:s,path:o}),r.add(s),e[s]=o}if(Array.isArray(n))for(let s of n){let o=P(s);i(o,s)}else if(typeof n==="object")Object.entries(n).forEach(([s,o])=>{i(s,o)});else{let s=P(n);i(s,n)}return t}function X(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as yn}from"load-tsconfig";function I(n){try{return yn(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import Cn from"node:path";async function V(n){let t=Cn.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let e=await Bun.file(t).text();return{packageJson:JSON.parse(e),path:t}}catch(r){return u.warn(`Failed to load package.json at ${t}: ${m(r)}`),{packageJson:null,path:t}}}function F(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((o)=>o.test(i))&&!t.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var L=new Set;async function hn(n,t){if(!n.entry||n.entry.length===0||!n.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 V(t);if(r)u.cli(`Using package.json: ${$(e,2)}`,{muted:!0});let i=r?.type,s=b(n,r),o=R(n),c=[F(s,o)],f=N(n.entry),g=S(n,t),l=n.format.flatMap((a)=>f.map((C)=>{return bn(n,t,C,a,i,c,g)}));if(await Promise.all(l),n.dts){let a=I(n.preferredTsconfigPath);if(a.path)u.cli(`Using tsconfig: ${$(a.path,2)}`,{muted:!0});let C=n.format.filter((d)=>{if(d==="iife"&&!h(i)&&n.format.includes("cjs"))return!1;return!0}),nn=typeof n.dts==="object"&&n.dts.entry?N(n.dts.entry):f;try{await Promise.all(nn.map(async(d)=>{let tn=await z(t,d.path,n,a,r);await Promise.all(C.map(async(rn)=>{let en=T(rn,i),B=`${t}/${n.outDir}/${d.name}${en}`;await Bun.write(B,tn);let sn=Bun.file(B).size||0;u.progress("DTS",$(B),M(sn),n.name)}))}))}catch(d){throw new p(m(d))}}}async function bn(n,t,r,e,i,s,o){let c=W(e,i),f=await Bun.build({...o,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:X(r.name,c)},splitting:G(n.splitting,e),plugins:s,throw:!1});if(!f.success)f.logs.forEach((a)=>{if(a.level==="error")throw new w(a.message);else if(a.level==="warning")u.warn(a.message);else if(a.level==="info")u.info(a.message)});let g=`${t}/${n.outDir}/${r.name}${c}`,l=Bun.file(g).size||0;u.progress(e.toUpperCase(),$(g),M(l),n.name)}export{cn as defineWorkspace,on as defineConfig,hn as build};
|