bunup 0.3.5 → 0.3.6
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 +9 -9
- package/build/index.d.mts +54 -2
- package/build/index.d.ts +54 -2
- package/build/index.js +4 -4
- package/build/index.mjs +2 -2
- package/package.json +3 -2
package/build/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{loadTsConfig as
|
|
3
|
+
import{loadTsConfig as An}from"load-tsconfig";class C extends Error{constructor(n){super(n);this.name="BunupError"}}class x extends C{constructor(n){super(n);this.name="BunupBuildError"}}class h extends C{constructor(n){super(n);this.name="BunupDTSBuildError"}}class y extends C{constructor(n){super(n);this.name="BunupCLIError"}}class j extends C{constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},Nn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof x)s="BUILD ERROR";else if(n instanceof h)s="DTS ERROR";else if(n instanceof y)s="CLI ERROR";else if(n instanceof j)s="WATCH ERROR";else if(n instanceof C)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")},X=(n,t)=>{Tn(n,t),process.exit(1)};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,...m]=a.split(" "),f=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),g=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 ${m.join(" ")}${g}`}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[m,f]of Object.entries(this.colors.progress))if(s.includes(m)){i=f;break}let u=this.formatMessage({colorCode:i,label:s,message:t,size:o,identifier:a,muted:c.muted});this.output(u,c)}};function V(n){try{return jn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${p(t)}`),{path:n,data:{},files:[]}}}import{rollup as _n}from"rollup";import Gn from"rollup-plugin-dts";import Q from"typescript";import I from"node:fs";import An from"node:path";var C={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0,sourcemap:"none"};function nn(n,t){return{outdir:`${t}/${n.outDir}`,minify:Nn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap,define:n.define}}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 P(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function tn(n=8){return Math.random().toString(36).substring(2,2+n)}function en(n,t){switch(n){case"esm":return".mjs";case"cjs":return j(t)?".cjs":".js";case"iife":return".global.js"}}function rn(n,t){switch(n){case"esm":return".d.mts";case"cjs":return j(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function j(n){return n==="module"}function N(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function sn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function on(n,t){return n===void 0?t==="esm":n}function J(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 O(n,t=3){return n.split("/").slice(-t).join("/")}function Y(n,t){let e=An.join(n,t);if(I.existsSync(e))try{I.rmSync(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}I.mkdirSync(e,{recursive:!0})}function F(n){return n||C.outDir}function an(n){return n===void 0?C.clean:n}function cn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${P(t)}($|\\/|\\\\)`):t)}function A(n,t){return cn(n.external||[]).concat(sn(t).map((e)=>new RegExp(`^${P(e)}($|\\/|\\\\)`)))}function M(n){return cn(n.noExternal||[])}import k from"node:fs";import K from"node:path";async function ln(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=K.join(n,`bunup.config${e}`);try{if(!k.existsSync(r))continue;let s=await Mn(r,e);if(!s)continue;return{configs:Un(s,n),configFilePath:r}}catch(s){throw new x(`Failed to load config from ${r}: ${p(s)}`)}}return{configs:[],configFilePath:""}}async function Mn(n,t){if(t===".json"||t===".jsonc")return kn(n);return Ln(n)}function kn(n){try{let t=k.readFileSync(n,"utf8"),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${p(t)}`)}}async function Ln(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${p(t)}`)}}function Un(n,t){let e=[];if(Hn(n))Dn(n,t,e);else if(Array.isArray(n))Wn(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 Hn(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 Dn(n,t,e){for(let r of n){let s=K.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 Wn(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})}}function L(n){let t=K.join(n,"package.json");try{if(!k.existsSync(t))return null;let e=k.readFileSync(t,"utf8");return JSON.parse(e)}catch(e){return l.warn(`Failed to load package.json at ${t}: ${p(e)}`),null}}import E from"path";var y="\x00virtual:",fn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(y))return t;if(!e?.startsWith(y)||!t.startsWith("."))return null;let r=e.slice(y.length),s=E.resolve(E.dirname(r),t);if(t==="."){let o=E.join(E.dirname(r),"index.d.ts");if(n.has(o))return`${y}${o}`;s=E.dirname(r)}if(n.has(s))return`${y}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${y}${i}`;if(t.startsWith(".")){let o=E.join(s,"index.d.ts");if(n.has(o))return`${y}${o}`}return null},load(t){if(t.startsWith(y)){let e=t.slice(y.length),r=n.get(e);if(r)return B.add(e),r}return null}}};async function un(n,t,e,r,s){let i=n.replace(/\.tsx?$/,".d.ts"),o=`${y}${i}`,a=s.data?.compilerOptions,c=L(r),u=A(e,c),m=M(e),f;try{f=await _n({input:o,onwarn(b,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(b.code??""))return;$(b)},plugins:[fn(t),Gn({tsconfig:s.path,compilerOptions:{...a?Q.parseJsonConfigFileContent({compilerOptions:a},Q.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:Q.ScriptTarget.ESNext}})],external:(b)=>u.some(($)=>$.test(b))&&!m.some(($)=>$.test(b))});let{output:g}=await f.generate({});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)}`)}finally{if(f)await f.close()}}import pn from"node:fs";import S from"node:path";var qn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,In=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function mn(n,t){let e=new Set([n]),r=[n],s=Yn(t),i=gn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await pn.promises.readFile(o,"utf8"),c=Pn(a);for(let u of c){let m=u.startsWith(".")?S.resolve(S.dirname(o),u):Fn(u,s,i);if(!m)continue;let f=Jn(m);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${p(a)}`)}}return e}function Pn(n){let t=new Set;for(let e of[qn,In]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}function Jn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(pn.existsSync(r)&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function gn(n){let t=S.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?S.resolve(t,n.data.compilerOptions.baseUrl):t}function Yn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=gn(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}$`,S.join(r,a))}return t}function Fn(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?S.join(e,n):null}import Kn from"node:fs";import{isolatedDeclaration as Qn}from"oxc-transform";async function dn(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts"),s=await Kn.promises.readFile(e,"utf8"),{code:i}=Qn(e,s);if(i)t.set(r,i)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${p(r)}`)}})),t}import z from"node:fs";import Z from"node:path";import{isolatedDeclaration as Zn}from"oxc-transform";function hn(n,t){let e=Z.resolve(n),r=Z.resolve(e,t);if(!z.existsSync(e))throw new d(`Root directory does not exist: ${e}`);if(!z.existsSync(r))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(Z.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function yn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await z.promises.readFile(r,"utf8"),{errors:i}=Zn(r,s);i.forEach((o)=>{if(!t)console.log(`
|
|
6
|
-
`);let a=o.labels[0],c=a?
|
|
5
|
+
`)+"\x1B[0m")},X=(n,t)=>{Nn(n,t),process.exit(1)};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)),g=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(" ")}${g}`}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)}};function V(n){try{return An(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import{rollup as Yn}from"rollup";import In from"rollup-plugin-dts";import Q from"typescript";import P from"node:fs";import kn from"node:path";var E={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function nn(n,t){return{outdir:`${t}/${n.outDir}`,minify:Mn(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 Mn(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 J(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function tn(n=8){return Math.random().toString(36).substring(2,2+n)}function en(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function rn(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 A(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function sn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function on(n,t){return n===void 0?t==="esm":n}function Y(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 O(n,t=3){return n.split("/").slice(-t).join("/")}function I(n,t){let e=kn.join(n,t);if(P.existsSync(e))try{P.rmSync(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}P.mkdirSync(e,{recursive:!0})}function F(n){return n||E.outDir}function an(n){return n===void 0?E.clean:n}function cn(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${J(t)}($|\\/|\\\\)`):t)}function M(n,t){return cn(n.external||[]).concat(sn(t).map((e)=>new RegExp(`^${J(e)}($|\\/|\\\\)`)))}function k(n){return cn(n.noExternal||[])}import L from"node:fs";import K from"node:path";async function ln(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=K.join(n,`bunup.config${e}`);try{if(!L.existsSync(r))continue;let s=await Ln(r,e);if(!s)continue;return{configs:Dn(s,n),configFilePath:r}}catch(s){throw new x(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Ln(n,t){if(t===".json"||t===".jsonc")return Hn(n);return Un(n)}function Hn(n){try{let t=L.readFileSync(n,"utf8"),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Un(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 Dn(n,t){let e=[];if(Wn(n))Gn(n,t,e);else if(Array.isArray(n))_n(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 Wn(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 Gn(n,t,e){for(let r of n){let s=K.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 _n(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})}}function H(n){let t=K.join(n,"package.json");try{if(!L.existsSync(t))return null;let e=L.readFileSync(t,"utf8");return JSON.parse(e)}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),null}}import qn from"node:fs";import Pn from"node:path";import{ResolverFactory as Jn}from"oxc-resolver";import B from"path";var d="\x00virtual:",fn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,e){if(t.startsWith(d))return t;if(!e?.startsWith(d)||!t.startsWith("."))return null;let r=e.slice(d.length),s=B.resolve(B.dirname(r),t);if(t==="."){let o=B.join(B.dirname(r),"index.d.ts");if(n.has(o))return`${d}${o}`;s=B.dirname(r)}if(n.has(s))return`${d}${s}`;let i=`${s}.d.ts`;if(n.has(i))return`${d}${i}`;if(t.startsWith(".")){let o=B.join(s,"index.d.ts");if(n.has(o))return`${d}${o}`}return null},load(t){if(t.startsWith(d)){let e=t.slice(d.length),r=n.get(e);if(r)return v.add(e),r}return null}}};var un;function mn(n){return{name:"bunup:types-resolve",buildStart(){un||=new Jn({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(d,""),/\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?Pn.dirname(e):process.cwd(),{path:s}=await un.async(r,t);if(!s)return;if(/[cm]?jsx?$/.test(s)){let i=s.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await qn.promises.exists(i)?i:void 0}return s}}}async function pn(n,t,e,r,s){let i=n.replace(/\.tsx?$/,".d.ts"),o=`${d}${i}`,a=s.data?.compilerOptions,c=H(r),u=M(e,c),p=k(e),f;try{f=await Yn({input:o,onwarn(b,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(b.code??""))return;$(b)},plugins:[fn(t),typeof e.dts==="object"&&mn(typeof e.dts.resolve==="boolean"?void 0:e.dts.resolve),In({tsconfig:s.path,compilerOptions:{...a?Q.parseJsonConfigFileContent({compilerOptions:a},Q.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:Q.ScriptTarget.ESNext}})],external:(b)=>u.some(($)=>$.test(b))&&!p.some(($)=>$.test(b))});let{output:g}=await f.generate({});if(!g[0]?.code)throw new h("Generated bundle is empty");return g[0].code}catch(g){throw new h(`DTS bundling failed: ${m(g)}`)}finally{if(f)await f.close()}}import gn from"node:fs";import S from"node:path";var Fn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Kn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function dn(n,t){let e=new Set([n]),r=[n],s=zn(t),i=hn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await gn.promises.readFile(o,"utf8"),c=Qn(a);for(let u of c){let p=u.startsWith(".")?S.resolve(S.dirname(o),u):Xn(u,s,i);if(!p)continue;let f=Zn(p);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return e}function Qn(n){let t=new Set;for(let e of[Fn,Kn]){let r;while((r=e.exec(n))!==null)t.add(r[2])}return Array.from(t)}function Zn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let e of t){let r=`${n}${e}`;if(gn.existsSync(r)&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function hn(n){let t=S.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?S.resolve(t,n.data.compilerOptions.baseUrl):t}function zn(n){let t=new Map,e=n.data?.compilerOptions?.paths;if(!e)return t;let r=hn(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}$`,S.join(r,a))}return t}function Xn(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?S.join(e,n):null}import Vn from"node:fs";import{isolatedDeclaration as nt}from"oxc-transform";async function yn(n){let t=new Map;return await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.tsx?$/,".d.ts"),s=await Vn.promises.readFile(e,"utf8"),{code:i}=nt(e,s);if(i)t.set(r,i)}catch(r){l.warn(`Failed to generate declaration for ${e}: ${m(r)}`)}})),t}import z from"node:fs";import Z from"node:path";import{isolatedDeclaration as tt}from"oxc-transform";function xn(n,t){let e=Z.resolve(n),r=Z.resolve(e,t);if(!z.existsSync(e))throw new h(`Root directory does not exist: ${e}`);if(!z.existsSync(r))throw new h(`Entry file does not exist: ${r}`);if(!r.endsWith(".ts"))throw new h(`Entry file must be a TypeScript file (.ts): ${r}`);if(Z.relative(e,r).startsWith(".."))throw new h(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function wn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await z.promises.readFile(r,"utf8"),{errors:i}=tt(r,s);i.forEach((o)=>{if(!t)console.log(`
|
|
6
|
+
`);let a=o.labels[0],c=a?et(s,a.start):"",p=`${O(r)}${c}: ${rt(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
|
-
`)}function
|
|
9
|
-
`),r=e.length,s=e[e.length-1].length+1;return` (${r}:${s})`}function
|
|
8
|
+
`)}function et(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 rt(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function bn(n,t,e){let{absoluteRootDir:r,absoluteEntry:s}=xn(n,t),i=V(e.preferredTsconfigPath),o=await dn(s,i),a=await yn(o);return pn(s,a,e,r,i)}function U(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function T(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=tn(),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,8 +20,8 @@ To fix this, use named entries in your configuration:
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-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=U(i);s(o,i)}else Object.entries(n).forEach(([i,o])=>{s(i,o)});return t}function
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-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=U(i);s(o,i)}else Object.entries(n).forEach(([i,o])=>{s(i,o)});return t}function $n(n,t){return`[dir]/${n}${t}`}function On(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 v=new Set;async function D(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 e=H(t),r=e?.type,s=M(n,e),i=k(n),o=[On(s,i)],a=T(n.entry),c=nn(n,t),u=n.format.flatMap((p)=>a.map((f)=>{return st(n,t,f,p,r,o,c)}));try{await Promise.all(u)}catch(p){throw console.error(p),new x("Build process encountered errors")}if(n.dts){let p=n.format.filter((g)=>{if(g==="iife"&&!N(r)&&n.format.includes("cjs"))return!1;return!0}),f=typeof n.dts==="object"&&n.dts.entry?T(n.dts.entry):a;try{await Promise.all(f.map(async(g)=>{let b=await bn(t,g.path,n);await Promise.all(p.map(async($)=>{let jn=rn($,r),q=`${t}/${n.outDir}/${g.name}${jn}`;await Bun.write(q,b);let Tn=Bun.file(q).size||0;l.progress("DTS",O(q),Y(Tn),n.name)}))}))}catch(g){throw new h(`DTS build process encountered errors: ${m(g)}`)}}}async function st(n,t,e,r,s,i,o){let a=en(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:$n(e.name,a)},splitting:on(n.splitting,r),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((f)=>{if(f.level==="error")l.error(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)}),new x(`Build failed for ${e.path} (${r})`);let u=`${t}/${n.outDir}/${e.name}${a}`,p=Bun.file(u).size||0;l.progress(r.toUpperCase(),O(u),Y(p),n.name)}var W="0.3.6";var Cn="https://bun.sh/docs/installation",En="https://bunup.arshadyaseen.com/#cli-options";function w(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function R(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new y(`Option --${n} requires a string value`)}}function Bn(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new y(`Option --${n} requires a string value`)}}function ot(){console.log(`
|
|
24
24
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
25
|
-
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${
|
|
26
|
-
`),process.exit(0)}function
|
|
27
|
-
To install Bun, visit
|
|
25
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${En}\x1B[0m
|
|
26
|
+
`),process.exit(0)}function at(){console.log(W),process.exit(0)}var ct={name:{flags:["n","name"],handler:R("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new y("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:R("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:R("banner")},footer:{flags:["f","footer"],handler:R("footer")},external:{flags:["e","external"],handler:Bn("external")},sourcemap:{flags:["sm","sourcemap"],handler:R("sourcemap")},target:{flags:["t","target"],handler:R("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:Bn("noExternal")}},lt={help:{flags:["h","help"],handler:()=>ot()},version:{flags:["v","version"],handler:()=>at()}},G={};for(let n of Object.values(ct))if(n)for(let t of n.flags)G[t]=n.handler;for(let n of Object.values(lt))for(let t of n.flags)G[t]=n.handler;function vn(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=U(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new y("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 y(`Option --entry.${a} requires a string value`)}else{let a=G[i];if(a)a(o,t);else throw new y(`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=G[i];if(c)c(a,t);else throw new y(`Unknown option: -${i}`)}else{let i=U(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 y(`Bunup requires Bun to run.
|
|
27
|
+
To install Bun, visit `+Cn)})();import _ from"node:path";import ft from"chokidar";async function Sn(n,t){let e=new Set,r=T(n.entry);r.forEach((a)=>{let c=_.resolve(t,a.path),u=_.dirname(c);e.add(u)});let s=ft.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,_.join(t,n.outDir)]}),i=!1,o=async(a=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await D({...n,entry:r.map((u)=>u.path),clean:!1},t),n.onBuildSuccess?.(),!a)l.cli(`\uD83D\uDCE6 Rebuild finished in ${A(performance.now()-c)}`)}catch(c){throw new j(`Build failed: ${m(c)}`)}finally{i=!1}};s.on("change",(a)=>{let c=_.relative(t,a);l.cli(`File changed: ${c}`),o()}),s.on("error",(a)=>{throw new j(`Watcher error: ${m(a)}`)}),await o(!0)}async function ut(n=Bun.argv.slice(2)){let t=vn(n),{configs:e,configFilePath:r}=await ln(process.cwd());if(l.cli(`Using bunup v${W} and bun v${Bun.version}`,{muted:!0}),r)l.cli(`Using config file: ${O(r,2)}`,{muted:!0});let s=performance.now();if(l.cli("Build started"),e.length===0){let a={...E,...t},c=process.cwd();if(a.clean)I(c,F(a.outDir));await Rn(a,c)}else{for(let{options:a,rootDir:c}of e)if(an(a.clean))I(c,F(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...E,...a,...t};await Rn(u,c)}))}let i=performance.now()-s,o=A(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),v.size>0)await wn(v),v.clear();if(t.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function Rn(n,t){if(n.watch)await Sn(n,t);else await D(n,t),n.onBuildSuccess?.()}ut().catch((n)=>X(n));export{ut as main};
|
package/build/index.d.mts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
/** https://bun.sh/docs/bundler/loaders */
|
|
2
|
+
type Loader = "js" | "jsx" | "ts" | "tsx" | "json" | "toml" | "file" | "napi" | "wasm" | "text" | "css" | "html";
|
|
3
|
+
/** https://bun.sh/docs/bundler#format */
|
|
1
4
|
type Format = "esm" | "cjs" | "iife";
|
|
5
|
+
/** https://bun.sh/docs/bundler#target */
|
|
2
6
|
type Target = "bun" | "node" | "browser";
|
|
7
|
+
/** https://bun.sh/docs/bundler#external */
|
|
3
8
|
type External = string[];
|
|
9
|
+
/** https://bun.sh/docs/bundler#sourcemap */
|
|
4
10
|
type Sourcemap = "none" | "linked" | "external" | "inline";
|
|
11
|
+
/** https://bun.sh/docs/bundler#define */
|
|
5
12
|
type Define = Record<string, string>;
|
|
13
|
+
/** https://bun.sh/docs/bundler#entry */
|
|
6
14
|
type Entry = string[] | Record<string, string>;
|
|
7
15
|
type DtsOptions = {
|
|
8
16
|
/**
|
|
@@ -27,7 +35,11 @@ type DtsOptions = {
|
|
|
27
35
|
* // Using named outputs as an object
|
|
28
36
|
* entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
29
37
|
*/
|
|
30
|
-
entry
|
|
38
|
+
entry?: Entry
|
|
39
|
+
/**
|
|
40
|
+
* Resolve external types used in dts files from node_modules
|
|
41
|
+
*/
|
|
42
|
+
resolve?: boolean | (string | RegExp)[]
|
|
31
43
|
};
|
|
32
44
|
interface BunupOptions {
|
|
33
45
|
/**
|
|
@@ -167,9 +179,49 @@ interface BunupOptions {
|
|
|
167
179
|
*
|
|
168
180
|
* If watch mode is enabled, this callback runs after each rebuild
|
|
169
181
|
*/
|
|
170
|
-
onBuildSuccess?: () =>
|
|
182
|
+
onBuildSuccess?: () => PromiseOr<void>;
|
|
183
|
+
/**
|
|
184
|
+
* A banner to be added to the final bundle, this can be a directive like "use client" for react or a comment block such as a license for the code.
|
|
185
|
+
*
|
|
186
|
+
* @see https://bun.sh/docs/bundler#banner
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* banner: '"use client";'
|
|
190
|
+
*/
|
|
191
|
+
banner?: string;
|
|
192
|
+
/**
|
|
193
|
+
* A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
|
|
194
|
+
*
|
|
195
|
+
* @see https://bun.sh/docs/bundler#footer
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* footer: '// built with love in SF'
|
|
199
|
+
*/
|
|
200
|
+
footer?: string;
|
|
201
|
+
/**
|
|
202
|
+
* Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
|
|
203
|
+
*
|
|
204
|
+
* @see https://bun.sh/docs/bundler#drop
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
|
|
208
|
+
*/
|
|
209
|
+
drop?: string[];
|
|
210
|
+
/**
|
|
211
|
+
* A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
|
|
212
|
+
*
|
|
213
|
+
* @see https://bun.sh/docs/bundler#loader
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* loader: {
|
|
217
|
+
* ".png": "dataurl",
|
|
218
|
+
* ".txt": "file",
|
|
219
|
+
* }
|
|
220
|
+
*/
|
|
221
|
+
loader?: Record<string, Loader>;
|
|
171
222
|
}
|
|
172
223
|
|
|
224
|
+
type PromiseOr<T> = Promise<T> | T;
|
|
173
225
|
type WithOptional<
|
|
174
226
|
T,
|
|
175
227
|
K extends keyof T
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
/** https://bun.sh/docs/bundler/loaders */
|
|
2
|
+
type Loader = "js" | "jsx" | "ts" | "tsx" | "json" | "toml" | "file" | "napi" | "wasm" | "text" | "css" | "html";
|
|
3
|
+
/** https://bun.sh/docs/bundler#format */
|
|
1
4
|
type Format = "esm" | "cjs" | "iife";
|
|
5
|
+
/** https://bun.sh/docs/bundler#target */
|
|
2
6
|
type Target = "bun" | "node" | "browser";
|
|
7
|
+
/** https://bun.sh/docs/bundler#external */
|
|
3
8
|
type External = string[];
|
|
9
|
+
/** https://bun.sh/docs/bundler#sourcemap */
|
|
4
10
|
type Sourcemap = "none" | "linked" | "external" | "inline";
|
|
11
|
+
/** https://bun.sh/docs/bundler#define */
|
|
5
12
|
type Define = Record<string, string>;
|
|
13
|
+
/** https://bun.sh/docs/bundler#entry */
|
|
6
14
|
type Entry = string[] | Record<string, string>;
|
|
7
15
|
type DtsOptions = {
|
|
8
16
|
/**
|
|
@@ -27,7 +35,11 @@ type DtsOptions = {
|
|
|
27
35
|
* // Using named outputs as an object
|
|
28
36
|
* entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
29
37
|
*/
|
|
30
|
-
entry
|
|
38
|
+
entry?: Entry
|
|
39
|
+
/**
|
|
40
|
+
* Resolve external types used in dts files from node_modules
|
|
41
|
+
*/
|
|
42
|
+
resolve?: boolean | (string | RegExp)[]
|
|
31
43
|
};
|
|
32
44
|
interface BunupOptions {
|
|
33
45
|
/**
|
|
@@ -167,9 +179,49 @@ interface BunupOptions {
|
|
|
167
179
|
*
|
|
168
180
|
* If watch mode is enabled, this callback runs after each rebuild
|
|
169
181
|
*/
|
|
170
|
-
onBuildSuccess?: () =>
|
|
182
|
+
onBuildSuccess?: () => PromiseOr<void>;
|
|
183
|
+
/**
|
|
184
|
+
* A banner to be added to the final bundle, this can be a directive like "use client" for react or a comment block such as a license for the code.
|
|
185
|
+
*
|
|
186
|
+
* @see https://bun.sh/docs/bundler#banner
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* banner: '"use client";'
|
|
190
|
+
*/
|
|
191
|
+
banner?: string;
|
|
192
|
+
/**
|
|
193
|
+
* A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
|
|
194
|
+
*
|
|
195
|
+
* @see https://bun.sh/docs/bundler#footer
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* footer: '// built with love in SF'
|
|
199
|
+
*/
|
|
200
|
+
footer?: string;
|
|
201
|
+
/**
|
|
202
|
+
* Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
|
|
203
|
+
*
|
|
204
|
+
* @see https://bun.sh/docs/bundler#drop
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
|
|
208
|
+
*/
|
|
209
|
+
drop?: string[];
|
|
210
|
+
/**
|
|
211
|
+
* A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
|
|
212
|
+
*
|
|
213
|
+
* @see https://bun.sh/docs/bundler#loader
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* loader: {
|
|
217
|
+
* ".png": "dataurl",
|
|
218
|
+
* ".txt": "file",
|
|
219
|
+
* }
|
|
220
|
+
*/
|
|
221
|
+
loader?: Record<string, Loader>;
|
|
171
222
|
}
|
|
172
223
|
|
|
224
|
+
type PromiseOr<T> = Promise<T> | T;
|
|
173
225
|
type WithOptional<
|
|
174
226
|
T,
|
|
175
227
|
K extends keyof T
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var Cr=require("node:module");var Er=Object.create;var{getPrototypeOf:hr,defineProperty:b,getOwnPropertyNames:J,getOwnPropertyDescriptor:yr}=Object,Y=Object.prototype.hasOwnProperty;var p=(r,n,t)=>{t=r!=null?Er(hr(r)):{};let e=n||!r||!r.__esModule?b(t,"default",{value:r,enumerable:!0}):t;for(let s of J(r))if(!Y.call(e,s))b(e,s,{get:()=>r[s],enumerable:!0});return e},H=new WeakMap,$r=(r)=>{var n=H.get(r),t;if(n)return n;if(n=b({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")J(r).map((e)=>!Y.call(n,e)&&b(n,e,{get:()=>r[e],enumerable:!(t=yr(r,e))||t.enumerable}));return H.set(r,n),n};var wr=(r,n)=>{for(var t in n)b(r,t,{get:n[t],enumerable:!0,configurable:!0,set:(e)=>n[t]=()=>e})};var Wr={};wr(Wr,{defineWorkspace:()=>K,defineConfig:()=>q,build:()=>pr});module.exports=$r(Wr);function q(r){return r}function K(r){return r}var Q=require("load-tsconfig");class A extends Error{constructor(r){super(r);this.name="BunupError"}}class $ extends A{constructor(r){super(r);this.name="BunupBuildError"}}class x extends A{constructor(r){super(r);this.name="BunupDTSBuildError"}}var d=(r)=>{if(r instanceof Error)return r.message;return String(r)};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:r,label:n,message:t,size:e,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length)),c=o?`\x1B[38;5;${this.colors.info}m${t}\x1B[0m`:t;if(e){let[g,...u]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-g.length)),m=s?` \x1B[48;5;${r};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${i}${g}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${u.join(" ")}${m}`}let f=s?` \x1B[48;5;${r};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${i}${c}${f}`},output(r,n={},t=console.log){if(n.verticalSpace)console.log("");if(t(r),n.verticalSpace)console.log("")},cli(r,n={}){let t=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)},info(r,n={}){let t=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n)},warn(r,n={}){let t=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.warn)},error(r,n={}){let t=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:r,identifier:n.identifier,muted:n.muted});this.output(t,n,console.error)},progress(r,n,t,e){let s=String(r),o=this.colors.default,i,c,f={};if(typeof t==="string")i=t,c=e;else if(t)i=t.size,c=t.identifier,f=t;for(let[u,a]of Object.entries(this.colors.progress))if(s.includes(u)){o=a;break}let g=this.formatMessage({colorCode:o,label:s,message:n,size:i,identifier:c,muted:f.muted});this.output(g,f)}};function U(r){try{return Q.loadTsConfig(".",r)}catch(n){return l.warn(`Failed to load tsconfig: ${d(n)}`),{path:r,data:{},files:[]}}}var tr=require("rollup"),er=p(require("rollup-plugin-dts")),j=p(require("typescript"));var Rr=p(require("node:fs")),vr=p(require("node:path"));function Z(r,n){return{outdir:`${n}/${r.outDir}`,minify:br(r),target:r.target,splitting:r.splitting,sourcemap:r.sourcemap,define:r.define}}function br(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:s}=r,o=n===!0;return{whitespace:t??o,identifiers:e??o,syntax:s??o}}function D(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _(r=8){return Math.random().toString(36).substring(2,2+r)}function z(r,n){switch(r){case"esm":return".mjs";case"cjs":return R(n)?".cjs":".js";case"iife":return".global.js"}}function P(r,n){switch(r){case"esm":return".d.mts";case"cjs":return R(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function R(r){return r==="module"}function X(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function F(r,n){return r===void 0?n==="esm":r}function T(r){if(r===0)return"0 B";let n=["B","KB","MB","GB"],t=Math.floor(Math.log(r)/Math.log(1024));if(t===0)return`${r} ${n[t]}`;return`${(r/Math.pow(1024,t)).toFixed(2)} ${n[t]}`}function v(r,n=3){return r.split("/").slice(-n).join("/")}function I(r){return r.map((n)=>typeof n==="string"?new RegExp(`^${D(n)}($|\\/|\\\\)`):n)}function O(r,n){return I(r.external||[]).concat(X(n).map((t)=>new RegExp(`^${D(t)}($|\\/|\\\\)`)))}function S(r){return I(r.noExternal||[])}var W=p(require("node:fs")),V=p(require("node:path"));function B(r){let n=V.default.join(r,"package.json");try{if(!W.default.existsSync(n))return null;let t=W.default.readFileSync(n,"utf8");return JSON.parse(t)}catch(t){return l.warn(`Failed to load package.json at ${n}: ${d(t)}`),null}}var w=p(require("path"));var E="\x00virtual:",rr=(r)=>{return{name:"bunup:virtual-dts",resolveId(n,t){if(n.startsWith(E))return n;if(!t?.startsWith(E)||!n.startsWith("."))return null;let e=t.slice(E.length),s=w.default.resolve(w.default.dirname(e),n);if(n==="."){let i=w.default.join(w.default.dirname(e),"index.d.ts");if(r.has(i))return`${E}${i}`;s=w.default.dirname(e)}if(r.has(s))return`${E}${s}`;let o=`${s}.d.ts`;if(r.has(o))return`${E}${o}`;if(n.startsWith(".")){let i=w.default.join(s,"index.d.ts");if(r.has(i))return`${E}${i}`}return null},load(n){if(n.startsWith(E)){let t=n.slice(E.length),e=r.get(t);if(e)return nr.add(t),e}return null}}};async function or(r,n,t,e,s){let o=r.replace(/\.tsx?$/,".d.ts"),i=`${E}${o}`,c=s.data?.compilerOptions,f=B(e),g=O(t,f),u=S(t),a;try{a=await tr.rollup({input:i,onwarn(h,y){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(h.code??""))return;y(h)},plugins:[rr(n),er.default({tsconfig:s.path,compilerOptions:{...c?j.default.parseJsonConfigFileContent({compilerOptions:c},j.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:j.default.ScriptTarget.ESNext}})],external:(h)=>g.some((y)=>y.test(h))&&!u.some((y)=>y.test(h))});let{output:m}=await a.generate({});if(!m[0]?.code)throw new x("Generated bundle is empty");return m[0].code}catch(m){throw new x(`DTS bundling failed: ${d(m)}`)}finally{if(a)await a.close()}}var G=p(require("node:fs")),C=p(require("node:path"));var Or=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Sr=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function sr(r,n){let t=new Set([r]),e=[r],s=Mr(n),o=ir(n);while(e.length){let i=e.pop();if(!i)continue;try{let c=await G.default.promises.readFile(i,"utf8"),f=Br(c);for(let g of f){let u=g.startsWith(".")?C.default.resolve(C.default.dirname(i),g):Nr(g,s,o);if(!u)continue;let a=jr(u);if(a&&!t.has(a))t.add(a),e.push(a)}}catch(c){l.warn(`Error processing ${i}: ${d(c)}`)}}return t}function Br(r){let n=new Set;for(let t of[Or,Sr]){let e;while((e=t.exec(r))!==null)n.add(e[2])}return Array.from(n)}function jr(r){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let t of n){let e=`${r}${t}`;if(G.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function ir(r){let n=C.default.dirname(r.path||"");return r.data?.compilerOptions?.baseUrl?C.default.resolve(n,r.data.compilerOptions.baseUrl):n}function Mr(r){let n=new Map,t=r.data?.compilerOptions?.paths;if(!t)return n;let e=ir(r);for(let[s,o]of Object.entries(t))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),c=o[0].replace(/\*/g,"$1");n.set(`^${i}$`,C.default.join(e,c))}return n}function Nr(r,n,t){for(let[e,s]of n){let o=new RegExp(e),i=r.match(o);if(i)return s.replace("$1",i[1]||"")}return t?C.default.join(t,r):null}var cr=p(require("node:fs")),ar=require("oxc-transform");async function fr(r){let n=new Map;return await Promise.all([...r].map(async(t)=>{try{let e=t.replace(/\.tsx?$/,".d.ts"),s=await cr.default.promises.readFile(t,"utf8"),{code:o}=ar.isolatedDeclaration(t,s);if(o)n.set(e,o)}catch(e){l.warn(`Failed to generate declaration for ${t}: ${d(e)}`)}})),n}var k=p(require("node:fs")),M=p(require("node:path")),Ar=require("oxc-transform");function lr(r,n){let t=M.default.resolve(r),e=M.default.resolve(t,n);if(!k.default.existsSync(t))throw new x(`Root directory does not exist: ${t}`);if(!k.default.existsSync(e))throw new x(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new x(`Entry file must be a TypeScript file (.ts): ${e}`);if(M.default.relative(t,e).startsWith(".."))throw new x(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function ur(r,n,t){let{absoluteRootDir:e,absoluteEntry:s}=lr(r,n),o=U(t.preferredTsconfigPath),i=await sr(s,o),c=await fr(i);return or(s,c,t,e,o)}function Dr(r){return r.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function L(r){let n=[],t=new Set,e={};function s(o,i){if(t.has(o)){let c=_(),f=`${o}_${c}`;l.warn(`Output name conflict: "${o}" is used by multiple files.
|
|
1
|
+
var jn=require("node:module");var bn=Object.create;var{getPrototypeOf:Rn,defineProperty:b,getOwnPropertyNames:J,getOwnPropertyDescriptor:On}=Object,Y=Object.prototype.hasOwnProperty;var m=(n,t,r)=>{r=n!=null?bn(Rn(n)):{};let e=t||!n||!n.__esModule?b(r,"default",{value:n,enumerable:!0}):r;for(let i of J(n))if(!Y.call(e,i))b(e,i,{get:()=>n[i],enumerable:!0});return e},L=new WeakMap,Sn=(n)=>{var t=L.get(n),r;if(t)return t;if(t=b({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")J(n).map((e)=>!Y.call(t,e)&&b(t,e,{get:()=>n[e],enumerable:!(r=On(n,e))||r.enumerable}));return L.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 Yn={};Bn(Yn,{defineWorkspace:()=>K,defineConfig:()=>q,build:()=>wn});module.exports=Sn(Yn);function q(n){return n}function K(n){return n}var Q=require("load-tsconfig");class A extends Error{constructor(n){super(n);this.name="BunupError"}}class w extends A{constructor(n){super(n);this.name="BunupBuildError"}}class y extends A{constructor(n){super(n);this.name="BunupDTSBuildError"}}var x=(n)=>{if(n instanceof Error)return n.message;return String(n)};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:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=o?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),p=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${s}${l}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${p}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${s}${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),o=this.colors.default,s,c,f={};if(typeof r==="string")s=r,c=e;else if(r)s=r.size,c=r.identifier,f=r;for(let[g,a]of Object.entries(this.colors.progress))if(i.includes(g)){o=a;break}let l=this.formatMessage({colorCode:o,label:i,message:t,size:s,identifier:c,muted:f.muted});this.output(l,f)}};function Z(n){try{return Q.loadTsConfig(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${x(t)}`),{path:n,data:{},files:[]}}}var an=require("rollup"),fn=m(require("rollup-plugin-dts")),M=m(require("typescript"));var Nn=m(require("node:fs")),Dn=m(require("node:path"));function U(n,t){return{outdir:`${t}/${n.outDir}`,minify:Mn(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 Mn(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,o=t===!0;return{whitespace:r??o,identifiers:e??o,syntax:i??o}}function T(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function P(n=8){return Math.random().toString(36).substring(2,2+n)}function _(n,t){switch(n){case"esm":return".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function z(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 X(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function F(n,t){return n===void 0?t==="esm":n}function W(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 O(n,t=3){return n.split("/").slice(-t).join("/")}function I(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${T(t)}($|\\/|\\\\)`):t)}function S(n,t){return I(n.external||[]).concat(X(t).map((r)=>new RegExp(`^${T(r)}($|\\/|\\\\)`)))}function B(n){return I(n.noExternal||[])}var v=m(require("node:fs")),V=m(require("node:path"));function j(n){let t=V.default.join(n,"package.json");try{if(!v.default.existsSync(t))return null;let r=v.default.readFileSync(t,"utf8");return JSON.parse(r)}catch(r){return u.warn(`Failed to load package.json at ${t}: ${x(r)}`),null}}var en=m(require("node:fs")),on=m(require("node:path")),sn=require("oxc-resolver");var h=m(require("path"));var d="\x00virtual:",nn=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(d))return t;if(!r?.startsWith(d)||!t.startsWith("."))return null;let e=r.slice(d.length),i=h.default.resolve(h.default.dirname(e),t);if(t==="."){let s=h.default.join(h.default.dirname(e),"index.d.ts");if(n.has(s))return`${d}${s}`;i=h.default.dirname(e)}if(n.has(i))return`${d}${i}`;let o=`${i}.d.ts`;if(n.has(o))return`${d}${o}`;if(t.startsWith(".")){let s=h.default.join(i,"index.d.ts");if(n.has(s))return`${d}${s}`}return null},load(t){if(t.startsWith(d)){let r=t.slice(d.length),e=n.get(r);if(e)return tn.add(r),e}return null}}};var rn;function cn(n){return{name:"bunup:types-resolve",buildStart(){rn||=new sn.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(d,""),/\0/.test(t))return;if(n){if(!n.some((s)=>{let c=!1;if(typeof s==="string")c=s===t||!!(r&&r.includes(s));else c=s.test(t)||!!(r&&s.test(r));return c}))return}let e=r?on.default.dirname(r):process.cwd(),{path:i}=await rn.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let o=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await en.default.promises.exists(o)?o:void 0}return i}}}async function un(n,t,r,e,i){let o=n.replace(/\.tsx?$/,".d.ts"),s=`${d}${o}`,c=i.data?.compilerOptions,f=j(e),l=S(r,f),g=B(r),a;try{a=await an.rollup({input:s,onwarn($,E){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes($.code??""))return;E($)},plugins:[nn(t),typeof r.dts==="object"&&cn(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),fn.default({tsconfig:i.path,compilerOptions:{...c?M.default.parseJsonConfigFileContent({compilerOptions:c},M.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:M.default.ScriptTarget.ESNext}})],external:($)=>l.some((E)=>E.test($))&&!g.some((E)=>E.test($))});let{output:p}=await a.generate({});if(!p[0]?.code)throw new y("Generated bundle is empty");return p[0].code}catch(p){throw new y(`DTS bundling failed: ${x(p)}`)}finally{if(a)await a.close()}}var G=m(require("node:fs")),C=m(require("node:path"));var An=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Tn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function gn(n,t){let r=new Set([n]),e=[n],i=Gn(t),o=ln(t);while(e.length){let s=e.pop();if(!s)continue;try{let c=await G.default.promises.readFile(s,"utf8"),f=Wn(c);for(let l of f){let g=l.startsWith(".")?C.default.resolve(C.default.dirname(s),l):kn(l,i,o);if(!g)continue;let a=vn(g);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${s}: ${x(c)}`)}}return r}function Wn(n){let t=new Set;for(let r of[An,Tn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}function vn(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(G.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function ln(n){let t=C.default.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?C.default.resolve(t,n.data.compilerOptions.baseUrl):t}function Gn(n){let t=new Map,r=n.data?.compilerOptions?.paths;if(!r)return t;let e=ln(n);for(let[i,o]of Object.entries(r))if(Array.isArray(o)&&o.length){let s=i.replace(/\*/g,"(.*)"),c=o[0].replace(/\*/g,"$1");t.set(`^${s}$`,C.default.join(e,c))}return t}function kn(n,t,r){for(let[e,i]of t){let o=new RegExp(e),s=n.match(o);if(s)return i.replace("$1",s[1]||"")}return r?C.default.join(r,n):null}var mn=m(require("node:fs")),pn=require("oxc-transform");async function dn(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),i=await mn.default.promises.readFile(r,"utf8"),{code:o}=pn.isolatedDeclaration(r,i);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${x(e)}`)}})),t}var k=m(require("node:fs")),N=m(require("node:path")),Hn=require("oxc-transform");function xn(n,t){let r=N.default.resolve(n),e=N.default.resolve(r,t);if(!k.default.existsSync(r))throw new y(`Root directory does not exist: ${r}`);if(!k.default.existsSync(e))throw new y(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new y(`Entry file must be a TypeScript file (.ts): ${e}`);if(N.default.relative(r,e).startsWith(".."))throw new y(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function yn(n,t,r){let{absoluteRootDir:e,absoluteEntry:i}=xn(n,t),o=Z(r.preferredTsconfigPath),s=await gn(i,o),c=await dn(s);return un(i,c,r,e,o)}function Ln(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function H(n){let t=[],r=new Set,e={};function i(o,s){if(r.has(o)){let c=P(),f=`${o}_${c}`;u.warn(`Output name conflict: "${o}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${e[o]} -> ${o}.js
|
|
5
|
-
${
|
|
5
|
+
${s} -> ${f}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
10
|
custom_name: "${e[o]}",
|
|
11
|
-
another_name: "${
|
|
11
|
+
another_name: "${s}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:s})}else t.push({name:o,path:s}),r.add(o),e[o]=s}if(Array.isArray(n))for(let o of n){let s=Ln(o);i(s,o)}else Object.entries(n).forEach(([o,s])=>{i(o,s)});return t}function $n(n,t){return`[dir]/${n}${t}`}function En(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((s)=>s.test(i))&&!t.some((s)=>s.test(i)))return{path:i,external:!0};return null})}}}var tn=new Set;async function wn(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 r=j(t),e=r?.type,i=S(n,r),o=B(n),s=[En(i,o)],c=H(n.entry),f=U(n,t),l=n.format.flatMap((g)=>c.map((a)=>{return Jn(n,t,a,g,e,s,f)}));try{await Promise.all(l)}catch(g){throw console.error(g),new w("Build process encountered errors")}if(n.dts){let g=n.format.filter((p)=>{if(p==="iife"&&!R(e)&&n.format.includes("cjs"))return!1;return!0}),a=typeof n.dts==="object"&&n.dts.entry?H(n.dts.entry):c;try{await Promise.all(a.map(async(p)=>{let $=await yn(t,p.path,n);await Promise.all(g.map(async(E)=>{let hn=z(E,e),D=`${t}/${n.outDir}/${p.name}${hn}`;await Bun.write(D,$);let Cn=Bun.file(D).size||0;u.progress("DTS",O(D),W(Cn),n.name)}))}))}catch(p){throw new y(`DTS build process encountered errors: ${x(p)}`)}}}async function Jn(n,t,r,e,i,o,s){let c=_(e,i),f=await Bun.build({...s,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:$n(r.name,c)},splitting:F(n.splitting,e),plugins:o,throw:!1});if(!f.success)throw f.logs.forEach((a)=>{if(a.level==="error")u.error(a.message);else if(a.level==="warning")u.warn(a.message);else if(a.level==="info")u.info(a.message)}),new w(`Build failed for ${r.path} (${e})`);let l=`${t}/${n.outDir}/${r.name}${c}`,g=Bun.file(l).size||0;u.progress(e.toUpperCase(),O(l),W(g),n.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function sn(n){return n}function cn(n){return n}import{loadTsConfig as an}from"load-tsconfig";class j extends Error{constructor(n){super(n);this.name="BunupError"}}class E extends j{constructor(n){super(n);this.name="BunupBuildError"}}class x extends j{constructor(n){super(n);this.name="BunupDTSBuildError"}}var d=(n)=>{if(n instanceof Error)return n.message;return String(n)};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:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=o?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(e){let[l,...g]=c.split(" "),a=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),m=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${s}${l}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${g.join(" ")}${m}`}let f=i?` \x1B[48;5;${n};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${n}m${t}\x1B[0m ${s}${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),o=this.colors.default,s,c,f={};if(typeof r==="string")s=r,c=e;else if(r)s=r.size,c=r.identifier,f=r;for(let[g,a]of Object.entries(this.colors.progress))if(i.includes(g)){o=a;break}let l=this.formatMessage({colorCode:o,label:i,message:t,size:s,identifier:c,muted:f.muted});this.output(l,f)}};function W(n){try{return an(".",n)}catch(t){return u.warn(`Failed to load tsconfig: ${d(t)}`),{path:n,data:{},files:[]}}}import{rollup as pn}from"rollup";import dn from"rollup-plugin-dts";import D from"typescript";import kn from"node:fs";import Ln from"node:path";function v(n,t){return{outdir:`${t}/${n.outDir}`,minify:fn(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 fn(n){let{minify:t,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:i}=n,o=t===!0;return{whitespace:r??o,identifiers:e??o,syntax:i??o}}function M(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(n=8){return Math.random().toString(36).substring(2,2+n)}function k(n,t){switch(n){case"esm":return".mjs";case"cjs":return C(t)?".cjs":".js";case"iife":return".global.js"}}function H(n,t){switch(n){case"esm":return".d.mts";case"cjs":return C(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(n){return n==="module"}function L(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function J(n,t){return n===void 0?t==="esm":n}function N(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 b(n,t=3){return n.split("/").slice(-t).join("/")}function Y(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${M(t)}($|\\/|\\\\)`):t)}function R(n,t){return Y(n.external||[]).concat(L(t).map((r)=>new RegExp(`^${M(r)}($|\\/|\\\\)`)))}function O(n){return Y(n.noExternal||[])}import q from"node:fs";import un from"node:path";function S(n){let t=un.join(n,"package.json");try{if(!q.existsSync(t))return null;let r=q.readFileSync(t,"utf8");return JSON.parse(r)}catch(r){return u.warn(`Failed to load package.json at ${t}: ${d(r)}`),null}}import gn from"node:fs";import ln from"node:path";import{ResolverFactory as mn}from"oxc-resolver";import w from"path";var p="\x00virtual:",K=(n)=>{return{name:"bunup:virtual-dts",resolveId(t,r){if(t.startsWith(p))return t;if(!r?.startsWith(p)||!t.startsWith("."))return null;let e=r.slice(p.length),i=w.resolve(w.dirname(e),t);if(t==="."){let s=w.join(w.dirname(e),"index.d.ts");if(n.has(s))return`${p}${s}`;i=w.dirname(e)}if(n.has(i))return`${p}${i}`;let o=`${i}.d.ts`;if(n.has(o))return`${p}${o}`;if(t.startsWith(".")){let s=w.join(i,"index.d.ts");if(n.has(s))return`${p}${s}`}return null},load(t){if(t.startsWith(p)){let r=t.slice(p.length),e=n.get(r);if(e)return Q.add(r),e}return null}}};var Z;function U(n){return{name:"bunup:types-resolve",buildStart(){Z||=new mn({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(p,""),/\0/.test(t))return;if(n){if(!n.some((s)=>{let c=!1;if(typeof s==="string")c=s===t||!!(r&&r.includes(s));else c=s.test(t)||!!(r&&s.test(r));return c}))return}let e=r?ln.dirname(r):process.cwd(),{path:i}=await Z.async(e,t);if(!i)return;if(/[cm]?jsx?$/.test(i)){let o=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await gn.promises.exists(o)?o:void 0}return i}}}async function P(n,t,r,e,i){let o=n.replace(/\.tsx?$/,".d.ts"),s=`${p}${o}`,c=i.data?.compilerOptions,f=S(e),l=R(r,f),g=O(r),a;try{a=await pn({input:s,onwarn(y,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(y.code??""))return;$(y)},plugins:[K(t),typeof r.dts==="object"&&U(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),dn({tsconfig:i.path,compilerOptions:{...c?D.parseJsonConfigFileContent({compilerOptions:c},D.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:D.ScriptTarget.ESNext}})],external:(y)=>l.some(($)=>$.test(y))&&!g.some(($)=>$.test(y))});let{output:m}=await a.generate({});if(!m[0]?.code)throw new x("Generated bundle is empty");return m[0].code}catch(m){throw new x(`DTS bundling failed: ${d(m)}`)}finally{if(a)await a.close()}}import _ from"node:fs";import h from"node:path";var xn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,yn=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function z(n,t){let r=new Set([n]),e=[n],i=wn(t),o=X(t);while(e.length){let s=e.pop();if(!s)continue;try{let c=await _.promises.readFile(s,"utf8"),f=$n(c);for(let l of f){let g=l.startsWith(".")?h.resolve(h.dirname(s),l):hn(l,i,o);if(!g)continue;let a=En(g);if(a&&!r.has(a))r.add(a),e.push(a)}}catch(c){u.warn(`Error processing ${s}: ${d(c)}`)}}return r}function $n(n){let t=new Set;for(let r of[xn,yn]){let e;while((e=r.exec(n))!==null)t.add(e[2])}return Array.from(t)}function En(n){let t=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of t){let e=`${n}${r}`;if(_.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function X(n){let t=h.dirname(n.path||"");return n.data?.compilerOptions?.baseUrl?h.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=X(n);for(let[i,o]of Object.entries(r))if(Array.isArray(o)&&o.length){let s=i.replace(/\*/g,"(.*)"),c=o[0].replace(/\*/g,"$1");t.set(`^${s}$`,h.join(e,c))}return t}function hn(n,t,r){for(let[e,i]of t){let o=new RegExp(e),s=n.match(o);if(s)return i.replace("$1",s[1]||"")}return r?h.join(r,n):null}import Cn from"node:fs";import{isolatedDeclaration as bn}from"oxc-transform";async function F(n){let t=new Map;return await Promise.all([...n].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),i=await Cn.promises.readFile(r,"utf8"),{code:o}=bn(r,i);if(o)t.set(e,o)}catch(e){u.warn(`Failed to generate declaration for ${r}: ${d(e)}`)}})),t}import I from"node:fs";import A from"node:path";import{isolatedDeclaration as jt}from"oxc-transform";function V(n,t){let r=A.resolve(n),e=A.resolve(r,t);if(!I.existsSync(r))throw new x(`Root directory does not exist: ${r}`);if(!I.existsSync(e))throw new x(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new x(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.relative(r,e).startsWith(".."))throw new x(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function nn(n,t,r){let{absoluteRootDir:e,absoluteEntry:i}=V(n,t),o=W(r.preferredTsconfigPath),s=await z(i,o),c=await F(s);return P(i,c,r,e,o)}function Rn(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function T(n){let t=[],r=new Set,e={};function i(o,s){if(r.has(o)){let c=G(),f=`${o}_${c}`;u.warn(`Output name conflict: "${o}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${e[o]} -> ${o}.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/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:f,path:s})}else t.push({name:o,path:s}),r.add(o),e[o]=s}if(Array.isArray(n))for(let o of n){let s=Rn(o);i(s,o)}else Object.entries(n).forEach(([o,s])=>{i(o,s)});return t}function tn(n,t){return`[dir]/${n}${t}`}function rn(n,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let i=e.path;if(n.some((s)=>s.test(i))&&!t.some((s)=>s.test(i)))return{path:i,external:!0};return null})}}}var Q=new Set;async function On(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=S(t),e=r?.type,i=R(n,r),o=O(n),s=[rn(i,o)],c=T(n.entry),f=v(n,t),l=n.format.flatMap((g)=>c.map((a)=>{return Sn(n,t,a,g,e,s,f)}));try{await Promise.all(l)}catch(g){throw console.error(g),new E("Build process encountered errors")}if(n.dts){let g=n.format.filter((m)=>{if(m==="iife"&&!C(e)&&n.format.includes("cjs"))return!1;return!0}),a=typeof n.dts==="object"&&n.dts.entry?T(n.dts.entry):c;try{await Promise.all(a.map(async(m)=>{let y=await nn(t,m.path,n);await Promise.all(g.map(async($)=>{let en=H($,e),B=`${t}/${n.outDir}/${m.name}${en}`;await Bun.write(B,y);let on=Bun.file(B).size||0;u.progress("DTS",b(B),N(on),n.name)}))}))}catch(m){throw new x(`DTS build process encountered errors: ${d(m)}`)}}}async function Sn(n,t,r,e,i,o,s){let c=k(e,i),f=await Bun.build({...s,entrypoints:[`${t}/${r.path}`],format:e,naming:{entry:tn(r.name,c)},splitting:J(n.splitting,e),plugins:o,throw:!1});if(!f.success)throw f.logs.forEach((a)=>{if(a.level==="error")u.error(a.message);else if(a.level==="warning")u.warn(a.message);else if(a.level==="info")u.info(a.message)}),new E(`Build failed for ${r.path} (${e})`);let l=`${t}/${n.outDir}/${r.name}${c}`,g=Bun.file(l).size||0;u.progress(e.toUpperCase(),b(l),N(g),n.name)}export{cn as defineWorkspace,sn as defineConfig,On as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@types/bun": "^1.2.5",
|
|
19
19
|
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
20
20
|
"bumpp": "^10.1.0",
|
|
21
|
-
"bunup": "^0.3.
|
|
21
|
+
"bunup": "^0.3.5",
|
|
22
22
|
"eslint": "^8.57.1",
|
|
23
23
|
"husky": "^9.1.7",
|
|
24
24
|
"prettier": "^3.5.3",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"chokidar": "^4.0.3",
|
|
57
57
|
"load-tsconfig": "^0.2.5",
|
|
58
|
+
"oxc-resolver": "^5.0.1",
|
|
58
59
|
"oxc-transform": "^0.58.1",
|
|
59
60
|
"rollup": "^4.35.0",
|
|
60
61
|
"rollup-plugin-dts": "^6.1.1"
|