bunup 0.3.61 → 0.3.64
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 +14 -14
- package/build/index.d.mts +13 -1
- package/build/index.d.ts +13 -1
- package/build/index.js +2 -2
- package/build/index.mjs +2 -2
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{build as
|
|
3
|
+
import{build as qt}from"rolldown";import{dts as Gt}from"rolldown-plugin-dts";class O extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends O{constructor(t){super(t);this.name="BunupBuildError"}}class d extends O{constructor(t){super(t);this.name="BunupDTSBuildError"}}class m extends O{constructor(t){super(t);this.name="BunupCLIError"}}class T extends O{constructor(t){super(t);this.name="BunupWatchError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)},Nt=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",solution:`By default, bunup targets the node environment. To use Bun-specific features, set the target to bun:
|
|
4
4
|
|
|
5
5
|
1. In your config file:
|
|
6
6
|
\`\`\`
|
|
@@ -12,30 +12,30 @@ import{build as Yt}from"rolldown";import{dts as vt}from"rolldown-plugin-dts";cla
|
|
|
12
12
|
});
|
|
13
13
|
\`\`\`
|
|
14
14
|
|
|
15
|
-
2. Or via CLI: \`bunup src/index.ts --target bun\``}],
|
|
15
|
+
2. Or via CLI: \`bunup src/index.ts --target bun\``}],V=(t,n)=>{let e=p(t),s=n?`[${n}] `:"",r="ERROR";if(t instanceof b)r="BUILD ERROR";else if(t instanceof d)r="DTS ERROR";else if(t instanceof m)r="CLI ERROR";else if(t instanceof T)r="WATCH ERROR";else if(t instanceof O)r="BUNUP ERROR";console.error(`\x1B[31m${r}\x1B[0m ${s}${e}`);let i=Nt.find((o)=>o.pattern.test(e)&&(o.errorType===r||!o.errorType));if(i)console.error(`
|
|
16
16
|
\x1B[33mSolution:\x1B[0m
|
|
17
17
|
|
|
18
|
-
\x1B[90m${
|
|
19
|
-
`);else console.error("\x1B[33mThis error might be addressed in the troubleshooting section: \x1B[0m\x1B[36mhttps://bunup.arshadyaseen.com/#troubleshooting\x1B[0m"),console.error("\x1B[33mIf not, please open an issue at: \x1B[0m\x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},tt=(t,n)=>{
|
|
20
|
-
`);let
|
|
18
|
+
\x1B[90m${i.solution}\x1B[0m
|
|
19
|
+
`);else console.error("\x1B[33mThis error might be addressed in the troubleshooting section: \x1B[0m\x1B[36mhttps://bunup.arshadyaseen.com/#troubleshooting\x1B[0m"),console.error("\x1B[33mIf not, please open an issue at: \x1B[0m\x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},tt=(t,n)=>{V(t,n),process.exit(1)};import et from"node:fs/promises";import Ft from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function nt(t,n){return{outdir:`${n}/${t.outDir}`,minify:Ut(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 Ut(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:r}=t,i=n===!0;return{whitespace:e??i,identifiers:s??i,syntax:r??i}}function q(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function st(t=8){return Math.random().toString(36).substring(2,2+t)}function it(t,n){switch(t){case"esm":return".mjs";case"cjs":return L(n)?".cjs":".js";case"iife":return".global.js"}}function rt(t,n){switch(t){case"esm":return".d.mts";case"cjs":return L(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(t){return t==="module"}function j(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ot(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function at(t,n){return t===void 0?n==="esm":t}function G(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function x(t,n=3){return t.split("/").slice(-n).join("/")}async function X(t,n){let e=Ft.join(t,n);try{await et.rm(e,{recursive:!0,force:!0})}catch(s){throw new b(`Failed to clean output directory: ${s}`)}await et.mkdir(e,{recursive:!0})}function Y(t){return t||v.outDir}function ct(t){return t===void 0?v.clean:t}function lt(t,n){return n==="cjs"?t:void 0}function ft(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${q(n)}($|\\/|\\\\)`):n)}function _(t,n){return ft(t.external||[]).concat(ot(n).map((e)=>new RegExp(`^${q(e)}($|\\/|\\\\)`)))}function D(t){return ft(t.noExternal||[])}import kt from"node:path";import{ResolverFactory as Vt}from"oxc-resolver";import P from"node:path";var I="\x00dts:",ut=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,r){if(J(s))return s;if(!r||!J(r))return null;let i=await N(s,n,e,A(r));if(!i)return null;let o=C(i);if(t.has(o))return U(o);return null},load(s){if(s.startsWith(I)){let r=A(s),i=t.get(r);if(i)return E.add(r),i}return null}}};function C(t){return t.replace(/\.tsx?$/,".d.ts")}function K(t){let n=P.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?P.resolve(n,t.data.compilerOptions.baseUrl):n}function pt(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=K(t);for(let[r,i]of Object.entries(e))if(Array.isArray(i)&&i.length){let o=r.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");n.set(`^${o}$`,P.join(s,a))}return n}function Ht(t,n,e){for(let[s,r]of n){let i=new RegExp(s),o=t.match(i);if(o)return r.replace("$1",o[1]||"")}return e?P.join(e,t):null}async function Wt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function N(t,n,e,s){let r=t.startsWith(".")?P.resolve(P.dirname(s||""),t):Ht(t,n,e);if(!r)return Promise.resolve(null);return Wt(r)}function J(t){return t.startsWith(I)}function A(t){return t.replace(I,"")}function U(t){return`${I}${t}`}var gt;function dt(t){return{name:"bunup:types-resolve",buildStart(){gt||=new Vt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?A(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?kt.dirname(e):process.cwd(),{path:r}=await gt.async(s,n);if(!r)return;if(/[cm]?jsx?$/.test(r)){let i=r.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return r}}}async function mt(t,n,e,s,r,i){let o=C(t),a=U(o),c=_(e,s),f=D(e);try{let{output:g}=await qt({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(u,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(u.code??""))return;h(u)},plugins:[ut(n,r,i),typeof e.dts==="object"&&"resolve"in e.dts&&dt(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),Gt()],external:(u)=>c.some((h)=>h.test(u))&&!f.some((h)=>h.test(u))});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(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:e,size:s,identifier:r,muted:i}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=i?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[f,...g]=a.split(" "),u=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-f.length)),h=r?` \x1B[48;5;${t};38;5;0m ${r} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${f}${u} \x1B[38;5;${this.colors.size}m${s}\x1B[0m ${g.join(" ")}${h}`}let c=r?` \x1B[48;5;${t};38;5;0m ${r} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${c}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let r=String(t),i=this.colors.default,o,a,c={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,c=e;for(let[g,u]of Object.entries(this.colors.progress))if(r.includes(g)){i=u;break}let f=this.formatMessage({colorCode:i,label:r,message:n,size:o,identifier:a,muted:c.muted});this.output(f,c)}}var l=R.getInstance();var Xt=/(?: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 ht(t,n,e){let s=new Set([t]),r=[t];while(r.length){let i=r.pop();if(!i)continue;try{let o=await Bun.file(i).text(),a=Jt(o);for(let c of a){let f=await N(c,n,e,i);if(!f)continue;if(!s.has(f))s.add(f),r.push(f)}}catch(o){l.warn(`Error processing ${i}: ${p(o)}`)}}return s}function Jt(t){let n=new Set;for(let e of[Xt,Yt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}import{isolatedDeclaration as Kt}from"oxc-transform";async function bt(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=C(e);if(!await Bun.file(e).exists())return;let i=await Bun.file(e).text(),{code:o}=Kt(e,i);if(o)n.set(s,o)}catch(s){l.warn(`Failed to generate declaration for ${e}: ${p(s)}`)}})),n}import xt from"node:fs/promises";import Q from"node:path";import{isolatedDeclaration as Qt}from"oxc-transform";async function wt(t,n){let e=Q.resolve(t),s=Q.resolve(e,n);if(!await xt.exists(e))throw new d(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new d(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${s}`);if(Q.relative(e,s).startsWith(".."))throw new d(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function yt(t){let n=!1;if(await Promise.all([...t].map(async(e)=>{try{let s=e.replace(/\.d\.ts$/,".ts"),r=await Bun.file(s).text(),{errors:i}=Qt(s,r);i.forEach((o)=>{if(!n)console.log(`
|
|
20
|
+
`);let a=o.labels[0],c=a?Zt(r,a.start):"",g=`${x(s)}${c}: ${zt(o.message)}`;l.warn(g),n=!0})}catch{}})),n)l.info(`
|
|
21
21
|
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.
|
|
22
|
-
`)}function
|
|
23
|
-
`),
|
|
22
|
+
`)}function Zt(t,n){if(n===void 0)return"";let e=t.slice(0,n).split(`
|
|
23
|
+
`),s=e.length,r=e[e.length-1].length+1;return` (${s}:${r})`}function zt(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function $t(t,n,e,s,r){let{absoluteEntry:i}=await wt(t,n),o=pt(s),a=K(s),c=await ht(i,o,a),f=await bt(c);return mt(i,f,e,r,o,a)}function M(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function B(t){let n=[],e=new Set,s={};function r(i,o){if(e.has(i)){let a=st(),c=`${i}_${a}`;l.warn(`Output name conflict: "${i}" is used by multiple files.
|
|
24
24
|
Bunup uses filenames without extensions as output names by default.
|
|
25
25
|
|
|
26
|
-
${i
|
|
27
|
-
${o} -> ${
|
|
26
|
+
${s[i]} -> ${i}.js
|
|
27
|
+
${o} -> ${c}.js (auto-renamed to avoid conflict)
|
|
28
28
|
|
|
29
29
|
To fix this, use named entries in your configuration:
|
|
30
30
|
{
|
|
31
31
|
entry: {
|
|
32
|
-
custom_name: "${i
|
|
32
|
+
custom_name: "${s[i]}",
|
|
33
33
|
another_name: "${o}"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:
|
|
37
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:c,path:o})}else n.push({name:i,path:o}),e.add(i),s[i]=o}if(Array.isArray(t))for(let i of t){let o=M(i);r(o,i)}else if(typeof t==="object")Object.entries(t).forEach(([i,o])=>{r(i,o)});else{let i=M(t);r(i,t)}return n}function Ot(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as tn}from"load-tsconfig";function vt(t){try{return tn(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import Z from"node:path";async function Ct(t){let n=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of n){let s=Z.join(t,`bunup.config${e}`);try{if(!await Bun.file(s).exists())continue;let i=await nn(s,e);if(!i)continue;return{configs:rn(i,t),configFilePath:s}}catch(r){throw new b(`Failed to load config from ${s}: ${p(r)}`)}}return{configs:[],configFilePath:""}}async function nn(t,n){if(n===".json"||n===".jsonc")return en(t);return sn(t)}async function en(t){try{let n=await Bun.file(t).text(),e=JSON.parse(n);return e.bunup||e}catch(n){throw new Error(`Invalid JSON in config file. ${p(n)}`)}}async function sn(t){try{let n=await import(`file://${t}`),e=n.default||n;if(!e)return l.warn(`No export found in ${t}. Make sure you're exporting your configuration.`),{};return e}catch(n){throw new Error(`Failed to import config file. ${p(n)}`)}}function rn(t,n){let e=[];if(on(t))an(t,n,e);else if(Array.isArray(t))cn(t,n,e);else if(t&&typeof t==="object")e.push({options:t,rootDir:n});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function on(t){return Array.isArray(t)&&t.length>0&&t.every((n)=>typeof n==="object"&&n!==null&&("name"in n)&&("root"in n)&&("config"in n))}function an(t,n,e){for(let s of t){let r=Z.resolve(n,s.root);if(Array.isArray(s.config))for(let i of s.config)e.push({options:{name:s.name,...i},rootDir:r});else e.push({options:{name:s.name,...s.config},rootDir:r})}}function cn(t,n,e){for(let s of t){if(!s||typeof s!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:s,rootDir:n})}}async function Et(t){let n=Z.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return l.warn(`Failed to load package.json at ${n}: ${p(e)}`),{packageJson:null,path:n}}}function Pt(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let r=s.path;if(t.some((o)=>o.test(r))&&!n.some((o)=>o.test(r)))return{path:r,external:!0};return null})}}}var E=new Set;async function F(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await Et(n);if(e)l.cli(`Using package.json: ${x(s,2)}`,{muted:!0,once:s,identifier:t.name});let r=e?.type,i=_(t,e),o=D(t),a=[Pt(i,o)],c=B(t.entry),f=nt(t,n),g=t.format.flatMap((u)=>c.map((h)=>{return ln(t,n,h,u,r,a,f)}));if(await Promise.all(g),t.dts){let u=vt(t.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${x(u.path,2)}`,{muted:!0,once:u.path,identifier:t.name});let h=t.format.filter(($)=>{if($==="iife"&&!L(r)&&t.format.includes("cjs"))return!1;return!0}),Tt=typeof t.dts==="object"&&t.dts.entry?B(t.dts.entry):c;try{await Promise.all(Tt.map(async($)=>{let Lt=await $t(n,$.path,t,u,e);await Promise.all(h.map(async(jt)=>{let _t=rt(jt,r),k=`${n}/${t.outDir}/${$.name}${_t}`;await Bun.write(k,Lt);let Dt=Bun.file(k).size||0;l.progress("DTS",x(k),G(Dt),t.name)}))}))}catch($){throw new d(p($))}}}async function ln(t,n,e,s,r,i,o){let a=it(s,r),c=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:Ot(e.name,a)},splitting:at(t.splitting,s),bytecode:lt(t.bytecode,s),plugins:i,throw:!1});if(!c.success)c.logs.forEach((u)=>{if(u.level==="error")throw new b(u.message);else if(u.level==="warning")l.warn(u.message);else if(u.level==="info")l.info(u.message)});let f=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(f).size||0;l.progress(s.toUpperCase(),x(f),G(g),t.name)}var H="0.3.64";var Rt="https://bun.sh/docs/installation",At="https://bunup.arshadyaseen.com/#cli-options";function w(t){return(n,e)=>{e[t]=n===!0?!0:n==="true"}}function y(t){return(n,e)=>{if(typeof n==="string")e[t]=n;else throw new m(`Option --${t} requires a string value`)}}function It(t){return(n,e)=>{if(typeof n==="string")e[t]=n.split(",");else throw new m(`Option --${t} requires a string value`)}}function un(){console.log(`
|
|
38
38
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
39
|
-
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${
|
|
40
|
-
`),process.exit(0)}function
|
|
41
|
-
To install Bun, visit `+
|
|
39
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${At}\x1B[0m
|
|
40
|
+
`),process.exit(0)}function pn(){console.log(H),process.exit(0)}var gn={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.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:It("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:It("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:w("bytecode")}},dn={resolveDts:{flags:["rd","resolve-dts"],handler:(t,n)=>{if(!n.dts)n.dts={};if(typeof n.dts==="boolean")n.dts={};if(typeof t==="string")if(t==="true"||t==="false")n.dts.resolve=t==="true";else n.dts.resolve=t.split(",");else n.dts.resolve=!0}}},mn={help:{flags:["h","help"],handler:()=>un()},version:{flags:["v","version"],handler:()=>pn()}},S={};for(let t of Object.values(gn))if(t)for(let n of t.flags)S[n]=t.handler;for(let t of Object.values(dn))for(let n of t.flags)S[n]=t.handler;for(let t of Object.values(mn))for(let n of t.flags)S[n]=t.handler;function Mt(t){let n={},e={},s=0;while(s<t.length){let r=t[s];if(r.startsWith("--")){let i,o;if(r.includes("=")){let[a,c]=r.slice(2).split("=",2);i=a,o=c}else{i=r.slice(2);let a=t[s+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")s++}if(i==="entry")if(typeof o==="string"){let a=M(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(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 m(`Option --entry.${a} requires a string value`)}else{let a=S[i];if(a)a(o,n);else throw new m(`Unknown option: --${i}`)}}else if(r.startsWith("-")){let i=r.slice(1),o=t[s+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")s++;let c=S[i];if(c)c(a,n);else throw new m(`Unknown option: -${i}`)}else{let i=M(r);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${r}'. Overwriting previous entry.`);e[i]=r}s++}if(Object.keys(e).length>0)n.entry=e;return n}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
|
|
41
|
+
To install Bun, visit `+Rt)})();import W from"node:path";import hn from"chokidar";async function Bt(t,n){let e=new Set,s=B(t.entry);s.forEach((a)=>{let c=W.resolve(n,a.path),f=W.dirname(c);e.add(f)});let r=hn.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,W.join(n,t.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await F({...t,entry:s.map((f)=>f.path),clean:!1},n),t.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${j(performance.now()-c)}`);await z()}catch(c){V(c)}finally{i=!1}};r.on("change",(a)=>{let c=W.relative(n,a);l.cli(`File changed: ${c}`,{muted:!0}),o()}),r.on("error",(a)=>{throw new T(`Watcher error: ${p(a)}`)}),await o(!0)}async function bn(t=Bun.argv.slice(2)){let n=Mt(t),{configs:e,configFilePath:s}=await Ct(process.cwd());if(l.cli(`Using bunup v${H} and bun v${Bun.version}`,{muted:!0}),s)l.cli(`Using config file: ${x(s,2)}`,{muted:!0});let r=performance.now();if(l.cli("Build started"),e.length===0){let a={...v,...n},c=process.cwd();if(a.clean)X(c,Y(a.outDir));await St(a,c)}else{for(let{options:a,rootDir:c}of e)if(ct(a.clean))X(c,Y(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let f={...v,...a,...n};await St(f,c)}))}let i=performance.now()-r,o=j(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),await z(),n.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!n.watch)process.exit(0);l.dispose()}async function z(){if(E.size>0)await yt(E),E.clear()}async function St(t,n){if(t.watch)await Bt(t,n);else await F(t,n),t.onBuildSuccess?.()}bn().catch((t)=>tt(t));export{z as validateDtsFiles,bn as main};
|
package/build/index.d.mts
CHANGED
|
@@ -434,6 +434,18 @@ interface BunupOptions {
|
|
|
434
434
|
* }
|
|
435
435
|
*/
|
|
436
436
|
loader?: Record<string, Loader>;
|
|
437
|
+
/**
|
|
438
|
+
* Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
|
|
439
|
+
*
|
|
440
|
+
* Bytecode is currently only supported for CommonJS (format: "cjs").
|
|
441
|
+
*
|
|
442
|
+
* Must be target: "bun"
|
|
443
|
+
*
|
|
444
|
+
* @see https://bun.sh/docs/bundler#bytecode
|
|
445
|
+
*
|
|
446
|
+
* @default false
|
|
447
|
+
*/
|
|
448
|
+
bytecode?: boolean;
|
|
437
449
|
}
|
|
438
450
|
|
|
439
451
|
//#endregion
|
|
@@ -444,7 +456,7 @@ type WithOptional<
|
|
|
444
456
|
K extends keyof T
|
|
445
457
|
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
446
458
|
type Arrayable<T> = T | T[];
|
|
447
|
-
type Bun = typeof
|
|
459
|
+
type Bun = typeof Bun;
|
|
448
460
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
449
461
|
type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
|
|
450
462
|
type DefineWorkspaceEntry = {
|
package/build/index.d.ts
CHANGED
|
@@ -434,6 +434,18 @@ interface BunupOptions {
|
|
|
434
434
|
* }
|
|
435
435
|
*/
|
|
436
436
|
loader?: Record<string, Loader>;
|
|
437
|
+
/**
|
|
438
|
+
* Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
|
|
439
|
+
*
|
|
440
|
+
* Bytecode is currently only supported for CommonJS (format: "cjs").
|
|
441
|
+
*
|
|
442
|
+
* Must be target: "bun"
|
|
443
|
+
*
|
|
444
|
+
* @see https://bun.sh/docs/bundler#bytecode
|
|
445
|
+
*
|
|
446
|
+
* @default false
|
|
447
|
+
*/
|
|
448
|
+
bytecode?: boolean;
|
|
437
449
|
}
|
|
438
450
|
|
|
439
451
|
//#endregion
|
|
@@ -444,7 +456,7 @@ type WithOptional<
|
|
|
444
456
|
K extends keyof T
|
|
445
457
|
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
446
458
|
type Arrayable<T> = T | T[];
|
|
447
|
-
type Bun = typeof
|
|
459
|
+
type Bun = typeof Bun;
|
|
448
460
|
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
449
461
|
type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
|
|
450
462
|
type DefineWorkspaceEntry = {
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var It=require("node:module");var At=Object.create;var{getPrototypeOf:Dt,defineProperty:C,getOwnPropertyNames:V,getOwnPropertyDescriptor:Ot}=Object,G=Object.prototype.hasOwnProperty;var x=(t,n,e)=>{e=t!=null?At(Dt(t)):{};let s=n||!t||!t.__esModule?C(e,"default",{value:t,enumerable:!0}):e;for(let i of V(t))if(!G.call(s,i))C(s,i,{get:()=>t[i],enumerable:!0});return s},U=new WeakMap,jt=(t)=>{var n=U.get(t),e;if(n)return n;if(n=C({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")V(t).map((s)=>!G.call(n,s)&&C(n,s,{get:()=>t[s],enumerable:!(e=Ot(t,s))||e.enumerable}));return U.set(t,n),n};var vt=(t,n)=>{for(var e in n)C(t,e,{get:n[e],enumerable:!0,configurable:!0,set:(s)=>n[e]=()=>s})};var Xt={};vt(Xt,{defineWorkspace:()=>B,defineConfig:()=>X,build:()=>Et});module.exports=jt(Xt);function X(t){return t}function B(t){return t}var ot=require("rolldown"),at=require("rolldown-plugin-dts");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class b extends S{constructor(t){super(t);this.name="BunupBuildError"}}class p extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};var Lt=x(require("node:fs/promises")),_t=x(require("node:path"));function H(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:e,minifyIdentifiers:s,minifySyntax:i}=t,r=n===!0;return{whitespace:e??r,identifiers:s??r,syntax:i??r}}function L(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(t=8){return Math.random().toString(36).substring(2,2+t)}function q(t,n){switch(t){case"esm":return".mjs";case"cjs":return M(n)?".cjs":".js";case"iife":return".global.js"}}function J(t,n){switch(t){case"esm":return".d.mts";case"cjs":return M(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function M(t){return t==="module"}function K(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function Q(t,n){return t===void 0?n==="esm":t}function _(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function $(t,n=3){return t.split("/").slice(-n).join("/")}function Z(t,n){return n==="cjs"?t:void 0}function z(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${L(n)}($|\\/|\\\\)`):n)}function A(t,n){return z(t.external||[]).concat(K(n).map((e)=>new RegExp(`^${L(e)}($|\\/|\\\\)`)))}function D(t){return z(t.noExternal||[])}var st=x(require("node:path")),rt=require("oxc-resolver");var h=x(require("node:path"));var P="\x00dts:",k=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,i){if(N(s))return s;if(!i||!N(i))return null;let r=await O(s,n,e,R(i));if(!r)return null;let o=E(r);if(t.has(o))return j(o);return null},load(s){if(s.startsWith(P)){let i=R(s),r=t.get(i);if(r)return tt.add(i),r}return null}}};function E(t){return t.replace(/\.tsx?$/,".d.ts")}function T(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,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=T(t);for(let[i,r]of Object.entries(e))if(Array.isArray(r)&&r.length){let o=i.replace(/\*/g,"(.*)"),a=r[0].replace(/\*/g,"$1");n.set(`^${o}$`,h.default.join(s,a))}return n}function Nt(t,n,e){for(let[s,i]of n){let r=new RegExp(s),o=t.match(r);if(o)return i.replace("$1",o[1]||"")}return e?h.default.join(e,t):null}async function Tt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function O(t,n,e,s){let i=t.startsWith(".")?h.default.resolve(h.default.dirname(s||""),t):Nt(t,n,e);if(!i)return Promise.resolve(null);return Tt(i)}function N(t){return t.startsWith(P)}function R(t){return t.replace(P,"")}function j(t){return`${P}${t}`}var et;function it(t){return{name:"bunup:types-resolve",buildStart(){et||=new rt.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?R(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?st.default.dirname(e):process.cwd(),{path:i}=await et.async(s,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let r=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(r).exists()?r:void 0}return i}}}async function ct(t,n,e,s,i,r){let o=E(t),a=j(o),f=A(e,s),l=D(e);try{let{output:g}=await ot.build({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[k(n,i,r),typeof e.dts==="object"&&"resolve"in e.dts&&it(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),at.dts()],external:(c)=>f.some((d)=>d.test(c))&&!l.some((d)=>d.test(c))});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)}`)}}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:e,size:s,identifier:i,muted:r}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=r?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),d=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${s}\x1B[0m ${g.join(" ")}${d}`}let f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${f}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let i=String(t),r=this.colors.default,o,a,f={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,f=e;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){r=c;break}let l=this.formatMessage({colorCode:r,label:i,message:n,size:o,identifier:a,muted:f.muted});this.output(l,f)}}var u=y.getInstance();var Ft=/(?: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 ft(t,n,e){let s=new Set([t]),i=[t];while(i.length){let r=i.pop();if(!r)continue;try{let o=await Bun.file(r).text(),a=Ut(o);for(let f of a){let l=await O(f,n,e,r);if(!l)continue;if(!s.has(l))s.add(l),i.push(l)}}catch(o){u.warn(`Error processing ${r}: ${m(o)}`)}}return s}function Ut(t){let n=new Set;for(let e of[Ft,Wt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}var lt=require("oxc-transform");async function ut(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=E(e);if(!await Bun.file(e).exists())return;let r=await Bun.file(e).text(),{code:o}=lt.isolatedDeclaration(e,r);if(o)n.set(s,o)}catch(s){u.warn(`Failed to generate declaration for ${e}: ${m(s)}`)}})),n}var F=x(require("node:fs/promises")),v=x(require("node:path")),Vt=require("oxc-transform");async function gt(t,n){let e=v.default.resolve(t),s=v.default.resolve(e,n);if(!await F.default.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new p(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${s}`);if(v.default.relative(e,s).startsWith(".."))throw new p(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function mt(t,n,e,s,i){let{absoluteEntry:r}=await gt(t,n),o=nt(s),a=T(s),f=await ft(r,o,a),l=await ut(f);return ct(r,l,e,i,o,a)}function dt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function W(t){let n=[],e=new Set,s={};function i(r,o){if(e.has(r)){let a=Y(),f=`${r}_${a}`;u.warn(`Output name conflict: "${r}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${s[r]} -> ${r}.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}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=dt(r);i(o,r)}else if(typeof t==="object")Object.entries(t).forEach(([r,o])=>{i(r,o)});else{let r=dt(t);i(r,t)}return n}function pt(t,n){return`[dir]/${t}${n}`}var xt=require("load-tsconfig");function ht(t){try{return xt.loadTsConfig(".",t)}catch(n){return u.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}var wt=x(require("node:path"));async function bt(t){let n=wt.default.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return u.warn(`Failed to load package.json at ${n}: ${m(e)}`),{packageJson:null,path:n}}}function $t(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let i=s.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 Et(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:s}=await bt(n);if(e)u.cli(`Using package.json: ${$(s,2)}`,{muted:!0,once:s,identifier:t.name});let i=e?.type,r=A(t,e),o=D(t),a=[$t(r,o)],f=W(t.entry),l=H(t,n),g=t.format.flatMap((c)=>f.map((d)=>{return Gt(t,n,d,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=ht(t.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${$(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let d=t.format.filter((w)=>{if(w==="iife"&&!M(i)&&t.format.includes("cjs"))return!1;return!0}),yt=typeof t.dts==="object"&&t.dts.entry?W(t.dts.entry):f;try{await Promise.all(yt.map(async(w)=>{let Ct=await mt(n,w.path,t,c,e);await Promise.all(d.map(async(Rt)=>{let Pt=J(Rt,i),I=`${n}/${t.outDir}/${w.name}${Pt}`;await Bun.write(I,Ct);let Mt=Bun.file(I).size||0;u.progress("DTS",$(I),_(Mt),t.name)}))}))}catch(w){throw new p(m(w))}}}async function Gt(t,n,e,s,i,r,o){let a=q(s,i),f=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:pt(e.name,a)},splitting:Q(t.splitting,s),bytecode:Z(t.bytecode,s),plugins:r,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new b(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let l=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(l).size||0;u.progress(s.toUpperCase(),$(l),_(g),t.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function gt(t){return t}function mt(t){return t}import{build as bt}from"rolldown";import{dts as $t}from"rolldown-plugin-dts";class j extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends j{constructor(t){super(t);this.name="BunupBuildError"}}class p extends j{constructor(t){super(t);this.name="BunupDTSBuildError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)};import Lt from"node:fs/promises";import Nt from"node:path";function T(t,n){return{outdir:`${n}/${t.outDir}`,minify:dt(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 dt(t){let{minify:n,minifyWhitespace:e,minifyIdentifiers:s,minifySyntax:i}=t,r=n===!0;return{whitespace:e??r,identifiers:s??r,syntax:i??r}}function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function F(t=8){return Math.random().toString(36).substring(2,2+t)}function W(t,n){switch(t){case"esm":return".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function U(t,n){switch(t){case"esm":return".d.mts";case"cjs":return R(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(t){return t==="module"}function V(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function G(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],e=Math.floor(Math.log(t)/Math.log(1024));if(e===0)return`${t} ${n[e]}`;return`${(t/Math.pow(1024,e)).toFixed(2)} ${n[e]}`}function w(t,n=3){return t.split("/").slice(-n).join("/")}function X(t,n){return n==="cjs"?t:void 0}function B(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${v(n)}($|\\/|\\\\)`):n)}function P(t,n){return B(t.external||[]).concat(V(n).map((e)=>new RegExp(`^${v(e)}($|\\/|\\\\)`)))}function M(t){return B(t.noExternal||[])}import ht from"node:path";import{ResolverFactory as wt}from"oxc-resolver";import $ from"node:path";var C="\x00dts:",H=(t,n,e)=>{return{name:"bunup:virtual-dts",async resolveId(s,i){if(S(s))return s;if(!i||!S(i))return null;let r=await A(s,n,e,y(i));if(!r)return null;let o=b(r);if(t.has(o))return D(o);return null},load(s){if(s.startsWith(C)){let i=y(s),r=t.get(i);if(r)return Y.add(i),r}return null}}};function b(t){return t.replace(/\.tsx?$/,".d.ts")}function L(t){let n=$.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?$.resolve(n,t.data.compilerOptions.baseUrl):n}function q(t){let n=new Map,e=t.data?.compilerOptions?.paths;if(!e)return n;let s=L(t);for(let[i,r]of Object.entries(e))if(Array.isArray(r)&&r.length){let o=i.replace(/\*/g,"(.*)"),a=r[0].replace(/\*/g,"$1");n.set(`^${o}$`,$.join(s,a))}return n}function pt(t,n,e){for(let[s,i]of n){let r=new RegExp(s),o=t.match(r);if(o)return i.replace("$1",o[1]||"")}return e?$.join(e,t):null}async function xt(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of n){let s=`${t}${e}`;if(await Bun.file(s).exists()&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}function A(t,n,e,s){let i=t.startsWith(".")?$.resolve($.dirname(s||""),t):pt(t,n,e);if(!i)return Promise.resolve(null);return xt(i)}function S(t){return t.startsWith(C)}function y(t){return t.replace(C,"")}function D(t){return`${C}${t}`}var J;function K(t){return{name:"bunup:types-resolve",buildStart(){J||=new wt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts"],modules:["node_modules","node_modules/@types"]})},async resolveId(n,e){if(e=e?y(e):void 0,/\0/.test(n))return;if(t){if(!t.some((o)=>{let a=!1;if(typeof o==="string")a=o===n||!!(e&&e.includes(o));else a=o.test(n)||!!(e&&o.test(e));return a}))return}let s=e?ht.dirname(e):process.cwd(),{path:i}=await J.async(s,n);if(!i)return;if(/[cm]?jsx?$/.test(i)){let r=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(r).exists()?r:void 0}return i}}}async function Q(t,n,e,s,i,r){let o=b(t),a=D(o),f=P(e,s),l=M(e);try{let{output:g}=await bt({input:a,output:{dir:e.outDir,inlineDynamicImports:!0},write:!1,onwarn(c,d){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(c.code??""))return;d(c)},plugins:[H(n,i,r),typeof e.dts==="object"&&"resolve"in e.dts&&K(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),$t()],external:(c)=>f.some((d)=>d.test(c))&&!l.some((d)=>d.test(c))});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)}`)}}class E{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(!E.instance)E.instance=new E;return E.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:e,size:s,identifier:i,muted:r}){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),a=r?`\x1B[38;5;${this.colors.info}m${e}\x1B[0m`:e;if(s){let[l,...g]=a.split(" "),c=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),d=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${s}\x1B[0m ${g.join(" ")}${d}`}let f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${n}\x1B[0m ${o}${a}${f}`}output(t,n={},e=console.log){if(!this.shouldLog(n))return;if(n.verticalSpace)console.log("");if(e(t),n.verticalSpace)console.log("")}cli(t,n={}){let e=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}info(t,n={}){let e=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n)}warn(t,n={}){let e=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.warn)}error(t,n={}){let e=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:n.identifier,muted:n.muted});this.output(e,n,console.error)}progress(t,n,e,s){let i=String(t),r=this.colors.default,o,a,f={};if(typeof e==="string")o=e,a=s;else if(e)o=e.size,a=e.identifier,f=e;for(let[g,c]of Object.entries(this.colors.progress))if(i.includes(g)){r=c;break}let l=this.formatMessage({colorCode:r,label:i,message:n,size:o,identifier:a,muted:f.muted});this.output(l,f)}}var u=E.getInstance();var Et=/(?: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 Z(t,n,e){let s=new Set([t]),i=[t];while(i.length){let r=i.pop();if(!r)continue;try{let o=await Bun.file(r).text(),a=Ct(o);for(let f of a){let l=await A(f,n,e,r);if(!l)continue;if(!s.has(l))s.add(l),i.push(l)}}catch(o){u.warn(`Error processing ${r}: ${m(o)}`)}}return s}function Ct(t){let n=new Set;for(let e of[Et,yt]){let s;while((s=e.exec(t))!==null)n.add(s[2])}return Array.from(n)}import{isolatedDeclaration as Rt}from"oxc-transform";async function z(t){let n=new Map;return await Promise.all([...t].map(async(e)=>{try{let s=b(e);if(!await Bun.file(e).exists())return;let r=await Bun.file(e).text(),{code:o}=Rt(e,r);if(o)n.set(s,o)}catch(s){u.warn(`Failed to generate declaration for ${e}: ${m(s)}`)}})),n}import k from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as En}from"oxc-transform";async function tt(t,n){let e=_.resolve(t),s=_.resolve(e,n);if(!await k.exists(e))throw new p(`Root directory does not exist: ${e}`);if(!await Bun.file(s).exists())throw new p(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new p(`Entry file must be a TypeScript file (.ts): ${s}`);if(_.relative(e,s).startsWith(".."))throw new p(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:e,absoluteEntry:s}}async function nt(t,n,e,s,i){let{absoluteEntry:r}=await tt(t,n),o=q(s),a=L(s),f=await Z(r,o,a),l=await z(f);return Q(r,l,e,i,o,a)}function et(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(t){let n=[],e=new Set,s={};function i(r,o){if(e.has(r)){let a=F(),f=`${r}_${a}`;u.warn(`Output name conflict: "${r}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${s[r]} -> ${r}.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}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:o})}else n.push({name:r,path:o}),e.add(r),s[r]=o}if(Array.isArray(t))for(let r of t){let o=et(r);i(o,r)}else if(typeof t==="object")Object.entries(t).forEach(([r,o])=>{i(r,o)});else{let r=et(t);i(r,t)}return n}function st(t,n){return`[dir]/${t}${n}`}import{loadTsConfig as Pt}from"load-tsconfig";function rt(t){try{return Pt(".",t)}catch(n){return u.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}import Mt from"node:path";async function it(t){let n=Mt.join(t,"package.json");try{if(!await Bun.file(n).exists())return{packageJson:null,path:n};let s=await Bun.file(n).text();return{packageJson:JSON.parse(s),path:n}}catch(e){return u.warn(`Failed to load package.json at ${n}: ${m(e)}`),{packageJson:null,path:n}}}function ot(t,n){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(s)=>{let i=s.path;if(t.some((o)=>o.test(i))&&!n.some((o)=>o.test(i)))return{path:i,external:!0};return null})}}}var Y=new Set;async function At(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:e,path:s}=await it(n);if(e)u.cli(`Using package.json: ${w(s,2)}`,{muted:!0,once:s,identifier:t.name});let i=e?.type,r=P(t,e),o=M(t),a=[ot(r,o)],f=N(t.entry),l=T(t,n),g=t.format.flatMap((c)=>f.map((d)=>{return Dt(t,n,d,c,i,a,l)}));if(await Promise.all(g),t.dts){let c=rt(t.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${w(c.path,2)}`,{muted:!0,once:c.path,identifier:t.name});let d=t.format.filter((x)=>{if(x==="iife"&&!R(i)&&t.format.includes("cjs"))return!1;return!0}),at=typeof t.dts==="object"&&t.dts.entry?N(t.dts.entry):f;try{await Promise.all(at.map(async(x)=>{let ct=await nt(n,x.path,t,c,e);await Promise.all(d.map(async(ft)=>{let lt=U(ft,i),O=`${n}/${t.outDir}/${x.name}${lt}`;await Bun.write(O,ct);let ut=Bun.file(O).size||0;u.progress("DTS",w(O),I(ut),t.name)}))}))}catch(x){throw new p(m(x))}}}async function Dt(t,n,e,s,i,r,o){let a=W(s,i),f=await Bun.build({...o,entrypoints:[`${n}/${e.path}`],format:s,naming:{entry:st(e.name,a)},splitting:G(t.splitting,s),bytecode:X(t.bytecode,s),plugins:r,throw:!1});if(!f.success)f.logs.forEach((c)=>{if(c.level==="error")throw new h(c.message);else if(c.level==="warning")u.warn(c.message);else if(c.level==="info")u.info(c.message)});let l=`${n}/${t.outDir}/${e.name}${a}`,g=Bun.file(l).size||0;u.progress(s.toUpperCase(),w(l),I(g),t.name)}export{mt as defineWorkspace,gt as defineConfig,At as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.64",
|
|
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.64"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"typescript": ">=4.5.0"
|