bunup 0.1.21 → 0.1.22
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 +1 -1
- package/build/dtsWorker.js +1 -1
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import G from"fs";import Gt from"path";import{isMainThread as Lt,parentPort as N,Worker as Wt,workerData as Ft}from"node:worker_threads";class $ extends Error{constructor(t){super(t);this.name="BunupError"}}class w extends ${constructor(t){super(t);this.name="BunupBuildError"}}class g extends ${constructor(t){super(t);this.name="BunupDTSBuildError"}}class h extends ${constructor(t){super(t);this.name="BunupCLIError"}}class P extends ${constructor(t){super(t);this.name="BunupWatchError"}}var u=(t)=>{if(t instanceof Error)return t.message;return String(t)},Bt=(t,r)=>{let n=u(t),s=r?`[${r}] `:"",e="ERROR";if(t instanceof w)e="BUILD ERROR";else if(t instanceof g)e="DTS ERROR";else if(t instanceof h)e="CLI ERROR";else if(t instanceof P)e="WATCH ERROR";else if(t instanceof $)e="BUNUP ERROR";if(console.error(`\x1B[31m[${e}]\x1B[0m ${s}${n}`),t instanceof Error&&t.stack)console.error("\x1B[2m"+t.stack.split(`
|
|
4
4
|
`).slice(1).join(`
|
|
5
5
|
`)+"\x1B[0m")},Y=(t,r)=>{Bt(t,r),process.exit(1)};var f={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,r,n){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length));return`\x1B[38;5;${t}m[${r}]\x1B[0m ${s}${n}`},cli(t){let r=this.labels.cli;console.log(this.formatMessage(this.colors.cli,r,t))},info(t){console.log(`\x1B[38;5;${this.colors.info}m${t}\x1B[0m`)},warn(t){let r=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,r,t))},error(t){let r=this.labels.error;console.error(this.formatMessage(this.colors.error,r,t))},progress(t,r){let n=String(t),s=this.colors.default;for(let[e,o]of Object.entries(this.colors.progress))if(n.includes(e)){s=o;break}console.log(this.formatMessage(s,n,r))}};function J(t,r){return`${r?`${r.replace(/-/g,"_")}_`:""}${t}`.toUpperCase()}function L(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function K(t=8){return Math.random().toString(36).substring(2,2+t)}function Q(t,r){switch(t){case"esm":return".mjs";case"cjs":return D(r)?".cjs":".js";case"iife":return".global.js"}}function V(t,r){switch(t){case"esm":return".d.mts";case"cjs":return D(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function D(t){return t==="module"}function S(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function Z(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function z(t,r){return t===void 0?r==="esm":t}import Rt from"node:fs";import Dt from"oxc-transform";import b from"node:path";function W(t){let r=b.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?b.resolve(r,t.data.compilerOptions.baseUrl):r}function tt(t){let r=new Map,n=t.data?.compilerOptions?.paths;if(!n)return r;let s=W(t);for(let[e,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=e.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");r.set(`^${i}$`,b.join(s,a))}return r}function rt(t,r,n){for(let[s,e]of r){let o=new RegExp(s),i=t.match(o);if(i)return e.replace("$1",i[1]||"")}return n?b.join(n,t):null}function nt(t,r){if(r===void 0)return"";let n=t.slice(0,r).split(`
|
|
6
|
-
`),s=n.length,e=n[n.length-1].length+1;return` (${s}:${e})`}function et(t){return t.replace(" with --isolatedDeclaration","")}var v=new Set;async function st(t){let r=new Map;return await Promise.all([...t].map(async(n)=>{try{let s=n.replace(/\.tsx?$/,".d.ts"),e=await Rt.promises.readFile(n,"utf8"),{code:o,errors:i}=Dt.isolatedDeclaration(n,e);if(i.forEach((a)=>{let l=a.labels[0],c=l?nt(e,l.start):"",x=`${n.split("/").slice(-3).join("/")}${c}: ${et(a.message)}`;if(!v.has(x))v.add(x)}),o)r.set(s,o)}catch(s){f.warn(`Failed to generate declaration for ${n}: ${u(s)}`)}})),r}import dt from"node:fs";import U from"node:path";import{loadTsConfig as St}from"load-tsconfig";function ot(t){try{return St(".",t)}catch(r){return f.warn(`Failed to load tsconfig: ${u(r)}`),{path:t,data:{},files:[]}}}import ft from"node:path";import{rollup as Tt}from"rollup";import kt from"rollup-plugin-dts";import F from"typescript";function it(t){return t.map((r)=>typeof r==="string"?new RegExp(`^${L(r)}($|\\/|\\\\)`):r)}function T(t,r){return it(t.external||[]).concat(Z(r).map((n)=>new RegExp(`^${L(n)}($|\\/|\\\\)`)))}function k(t){return it(t.noExternal||[])}import M from"node:fs";import lt from"node:path";var C={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0};function at(t,r){return{outdir:`${r}/${t.outDir}`,minify:bt(t),target:t.target,splitting:t.splitting}}function bt(t){let{minify:r,minifyWhitespace:n,minifyIdentifiers:s,minifySyntax:e}=t,o=r===!0;return{whitespace:n??o,identifiers:s??o,syntax:e??o}}async function ct(t){let r=[];for(let n of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let s=lt.join(t,`bunup.config${n}`);try{if(!M.existsSync(s))continue;let e;if(n===".json"||n===".jsonc"){let o=M.readFileSync(s,"utf8");e=JSON.parse(o)}else{let o=await import(`file://${s}`);if(e=o.default||o,!e)f.warn(`No default export found in ${s}`),e={}}if(Array.isArray(e))for(let o of e)r.push({options:{...C,...o},rootDir:t});else r.push({options:{...C,...e},rootDir:t});break}catch(e){throw new w(`Failed to load config from ${s}: ${u(e)}`)}if(r.length>0)break}return r}function A(t){let r=lt.join(t,"package.json");try{if(!M.existsSync(r))return null;let n=M.readFileSync(r,"utf8");return JSON.parse(n)}catch(n){return f.warn(`Failed to load package.json at ${r}: ${u(n)}`),null}}async function ut(t,r,n,s,e){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,l=e.data?.compilerOptions,c={name:"bunup:virtual-dts",resolveId(d,y){if(d.startsWith("\x00virtual:"))return d;if(!y?.startsWith("\x00virtual:")||!d.startsWith("."))return null;let O=y.slice(9),I=ft.resolve(ft.dirname(O),d),X=r.has(I)?I:`${I}.d.ts`;return r.has(X)?`\x00virtual:${X}`:null},load(d){return d.startsWith("\x00virtual:")?r.get(d.slice(9))||null:null}},m=A(s),p=T(n,m),x=k(n),R;try{R=await Tt({input:a,onwarn(y,O){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(y.code??""))return;O(y)},plugins:[c,kt({tsconfig:e.path,compilerOptions:{...l?F.parseJsonConfigFileContent({compilerOptions:l},F.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:F.ScriptTarget.ESNext}})],external:(y)=>p.some((O)=>O.test(y))&&!x.some((O)=>O.test(y))});let{output:d}=await R.generate({});if(!d[0]?.code)throw new g("Generated bundle is empty");return d[0].code}catch(d){throw new g(`DTS bundling failed: ${u(d)}`)}finally{if(R)await R.close()}}import mt from"node:fs";import pt from"node:path";var Mt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,At=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function gt(t,r){let n=new Set([t]),s=[t],e=tt(r),o=W(r);while(s.length){let i=s.pop();if(!i)continue;try{let a=await mt.promises.readFile(i,"utf8"),l=Nt(a);for(let c of l){let m=c.startsWith(".")?pt.resolve(pt.dirname(i),c):rt(c,e,o);if(!m)continue;let p=jt(m);if(p&&!n.has(p))n.add(p),s.push(p)}}catch(a){f.warn(`Error processing ${i}: ${u(a)}`)}}return n}function Nt(t){let r=new Set;for(let n of[Mt,At]){let s;while((s=n.exec(t))!==null)r.add(s[2])}return Array.from(r)}function jt(t){let r=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of r){let s=`${t}${n}`;if(mt.existsSync(s)&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}async function ht(t,r,n){let{absoluteRootDir:s,absoluteEntry:e}=It(t,r),o=ot(n.preferredTsconfigPath),i=await gt(e,o),a=await st(i);return ut(e,a,n,s,o)}function It(t,r){let n=U.resolve(t),s=U.resolve(n,r);if(!dt.existsSync(n))throw new g(`Root directory does not exist: ${n}`);if(!dt.existsSync(s))throw new g(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${s}`);if(U.relative(n,s).startsWith(".."))throw new g(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:n,absoluteEntry:s}}async function xt(t,r,n,s,e){return new Promise((o,i)=>{let a={rootDir:t,entries:r,formats:n,options:s,packageType:e},l=new Wt(new URL("./dtsWorker.js",import.meta.url),{workerData:a});l.on("message",(c)=>{if(c.success)o();else i(new g(c.error||"Unknown DTS worker error"))}),l.on("error",i),l.on("exit",(c)=>{if(c!==0)i(new g(`DTS worker stopped with exit code ${c}`))})})}if(!Lt&&N){let{rootDir:t,entries:r,formats:n,options:s,packageType:e}=Ft,o=performance.now();f.progress("DTS","Bundling types");try{let i=r.map(async(a)=>{let l=await ht(t,a.path,s);return Promise.all(n.map(async(c)=>{let m=V(c,e),p=`${s.outDir}/${a.name}${m}`,x=`${t}/${p}`;await Bun.write(x,l),f.progress("DTS",p)}))});Promise.all(i).then(()=>{let a=performance.now()-o;N?.postMessage({success:!0});let l=S(a);if(f.progress("DTS",`Bundled types in ${l}`),v.size>0)console.log(`
|
|
6
|
+
`),s=n.length,e=n[n.length-1].length+1;return` (${s}:${e})`}function et(t){return t.replace(" with --isolatedDeclaration","").replace(" with --isolatedDeclarations","")}var v=new Set;async function st(t){let r=new Map;return await Promise.all([...t].map(async(n)=>{try{let s=n.replace(/\.tsx?$/,".d.ts"),e=await Rt.promises.readFile(n,"utf8"),{code:o,errors:i}=Dt.isolatedDeclaration(n,e);if(i.forEach((a)=>{let l=a.labels[0],c=l?nt(e,l.start):"",x=`${n.split("/").slice(-3).join("/")}${c}: ${et(a.message)}`;if(!v.has(x))v.add(x)}),o)r.set(s,o)}catch(s){f.warn(`Failed to generate declaration for ${n}: ${u(s)}`)}})),r}import dt from"node:fs";import U from"node:path";import{loadTsConfig as St}from"load-tsconfig";function ot(t){try{return St(".",t)}catch(r){return f.warn(`Failed to load tsconfig: ${u(r)}`),{path:t,data:{},files:[]}}}import ft from"node:path";import{rollup as Tt}from"rollup";import kt from"rollup-plugin-dts";import F from"typescript";function it(t){return t.map((r)=>typeof r==="string"?new RegExp(`^${L(r)}($|\\/|\\\\)`):r)}function T(t,r){return it(t.external||[]).concat(Z(r).map((n)=>new RegExp(`^${L(n)}($|\\/|\\\\)`)))}function k(t){return it(t.noExternal||[])}import M from"node:fs";import lt from"node:path";var C={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0};function at(t,r){return{outdir:`${r}/${t.outDir}`,minify:bt(t),target:t.target,splitting:t.splitting}}function bt(t){let{minify:r,minifyWhitespace:n,minifyIdentifiers:s,minifySyntax:e}=t,o=r===!0;return{whitespace:n??o,identifiers:s??o,syntax:e??o}}async function ct(t){let r=[];for(let n of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let s=lt.join(t,`bunup.config${n}`);try{if(!M.existsSync(s))continue;let e;if(n===".json"||n===".jsonc"){let o=M.readFileSync(s,"utf8");e=JSON.parse(o)}else{let o=await import(`file://${s}`);if(e=o.default||o,!e)f.warn(`No default export found in ${s}`),e={}}if(Array.isArray(e))for(let o of e)r.push({options:{...C,...o},rootDir:t});else r.push({options:{...C,...e},rootDir:t});break}catch(e){throw new w(`Failed to load config from ${s}: ${u(e)}`)}if(r.length>0)break}return r}function A(t){let r=lt.join(t,"package.json");try{if(!M.existsSync(r))return null;let n=M.readFileSync(r,"utf8");return JSON.parse(n)}catch(n){return f.warn(`Failed to load package.json at ${r}: ${u(n)}`),null}}async function ut(t,r,n,s,e){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,l=e.data?.compilerOptions,c={name:"bunup:virtual-dts",resolveId(d,y){if(d.startsWith("\x00virtual:"))return d;if(!y?.startsWith("\x00virtual:")||!d.startsWith("."))return null;let O=y.slice(9),I=ft.resolve(ft.dirname(O),d),X=r.has(I)?I:`${I}.d.ts`;return r.has(X)?`\x00virtual:${X}`:null},load(d){return d.startsWith("\x00virtual:")?r.get(d.slice(9))||null:null}},m=A(s),p=T(n,m),x=k(n),R;try{R=await Tt({input:a,onwarn(y,O){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(y.code??""))return;O(y)},plugins:[c,kt({tsconfig:e.path,compilerOptions:{...l?F.parseJsonConfigFileContent({compilerOptions:l},F.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:F.ScriptTarget.ESNext}})],external:(y)=>p.some((O)=>O.test(y))&&!x.some((O)=>O.test(y))});let{output:d}=await R.generate({});if(!d[0]?.code)throw new g("Generated bundle is empty");return d[0].code}catch(d){throw new g(`DTS bundling failed: ${u(d)}`)}finally{if(R)await R.close()}}import mt from"node:fs";import pt from"node:path";var Mt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,At=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function gt(t,r){let n=new Set([t]),s=[t],e=tt(r),o=W(r);while(s.length){let i=s.pop();if(!i)continue;try{let a=await mt.promises.readFile(i,"utf8"),l=Nt(a);for(let c of l){let m=c.startsWith(".")?pt.resolve(pt.dirname(i),c):rt(c,e,o);if(!m)continue;let p=jt(m);if(p&&!n.has(p))n.add(p),s.push(p)}}catch(a){f.warn(`Error processing ${i}: ${u(a)}`)}}return n}function Nt(t){let r=new Set;for(let n of[Mt,At]){let s;while((s=n.exec(t))!==null)r.add(s[2])}return Array.from(r)}function jt(t){let r=["",".ts",".tsx","/index.ts","/index.tsx"];for(let n of r){let s=`${t}${n}`;if(mt.existsSync(s)&&(s.endsWith(".ts")||s.endsWith(".tsx")))return s}return null}async function ht(t,r,n){let{absoluteRootDir:s,absoluteEntry:e}=It(t,r),o=ot(n.preferredTsconfigPath),i=await gt(e,o),a=await st(i);return ut(e,a,n,s,o)}function It(t,r){let n=U.resolve(t),s=U.resolve(n,r);if(!dt.existsSync(n))throw new g(`Root directory does not exist: ${n}`);if(!dt.existsSync(s))throw new g(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${s}`);if(U.relative(n,s).startsWith(".."))throw new g(`Entry file must be within rootDir: ${s}`);return{absoluteRootDir:n,absoluteEntry:s}}async function xt(t,r,n,s,e){return new Promise((o,i)=>{let a={rootDir:t,entries:r,formats:n,options:s,packageType:e},l=new Wt(new URL("./dtsWorker.js",import.meta.url),{workerData:a});l.on("message",(c)=>{if(c.success)o();else i(new g(c.error||"Unknown DTS worker error"))}),l.on("error",i),l.on("exit",(c)=>{if(c!==0)i(new g(`DTS worker stopped with exit code ${c}`))})})}if(!Lt&&N){let{rootDir:t,entries:r,formats:n,options:s,packageType:e}=Ft,o=performance.now();f.progress("DTS","Bundling types");try{let i=r.map(async(a)=>{let l=await ht(t,a.path,s);return Promise.all(n.map(async(c)=>{let m=V(c,e),p=`${s.outDir}/${a.name}${m}`,x=`${t}/${p}`;await Bun.write(x,l),f.progress("DTS",p)}))});Promise.all(i).then(()=>{let a=performance.now()-o;N?.postMessage({success:!0});let l=S(a);if(f.progress("DTS",`Bundled types in ${l}`),v.size>0)console.log(`
|
|
7
7
|
`),v.forEach((c)=>{f.warn(c)}),f.info(`
|
|
8
8
|
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.
|
|
9
9
|
`),v.clear()}).catch((a)=>{N?.postMessage({success:!1,error:u(a)})})}catch(i){N?.postMessage({success:!1,error:u(i)})}}function Ut(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function B(t){let r=[],n=new Set;function s(e,o){if(n.has(e)){let i=K();r.push({name:`${e}_${i}`,path:o})}else r.push({name:e,path:o}),n.add(e)}if(Array.isArray(t))for(let e of t){let o=Ut(e);s(o,e)}else Object.entries(t).forEach(([e,o])=>{s(e,o)});return r}function wt(t,r){return`[dir]/${t}${r}`}function yt(t,r){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(s)=>{let e=s.path;if(t.some((i)=>i.test(e))&&!r.some((i)=>i.test(e)))return{path:e,external:!0};return null})}}}async function j(t,r){if(!t.entry||t.entry.length===0||!t.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let n=performance.now();f.cli("Build started");let s=A(r),e=s?.type,o=T(t,s),i=k(t),a=[yt(o,i)],l=B(t.entry),c=t.format.flatMap((m)=>l.map((p)=>_t(t,r,p,m,e,a)));try{await Promise.all(c);let m=performance.now()-n,p=S(m);f.cli(`\uD83D\uDCE6 Build success in ${p}`)}catch{throw new w("Build process encountered errors")}if(t.dts){let m=t.format.filter((x)=>{if(x==="iife"&&!D(e)&&t.format.includes("cjs"))return!1;return!0}),p=t.dts===!0?l:B(t.dts.entry);try{await xt(r,p,m,t,e)}catch(x){throw new g(`DTS build process encountered errors: ${u(x)}`)}}}async function _t(t,r,n,s,e,o){let i=Q(s,e),a=at(t,r),l=await Bun.build({...a,entrypoints:[`${r}/${n.path}`],format:s,naming:{entry:wt(n.name,i)},splitting:z(t.splitting,s),plugins:o,throw:!1});if(!l.success)throw l.logs.forEach((c)=>{if(c.level==="error")f.error(c.message);else if(c.level==="warning")f.warn(c.message);else if(c.level==="info")f.info(c.message)}),new w(`Build failed for ${n} (${s})`);f.progress(J(s,t.name),`${t.outDir}/${n.name}${i}`)}function E(t){return(r,n)=>{n[t]=r===!0?!0:r==="true"}}function _(t){return(r,n)=>{if(typeof r==="string")n[t]=r;else throw new h(`Option --${t} requires a string value`)}}function Et(t){return(r,n)=>{if(typeof r==="string")n[t]=r.split(",");else throw new h(`Option --${t} requires a string value`)}}var Ht={name:{flags:["n","name"],handler:_("name")},format:{flags:["f","format"],handler:(t,r)=>{if(typeof t==="string")r.format=t.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:_("outDir")},minify:{flags:["m","minify"],handler:E("minify")},watch:{flags:["w","watch"],handler:E("watch")},dts:{flags:["d","dts"],handler:E("dts")},external:{flags:["e","external"],handler:Et("external")},target:{flags:["t","target"],handler:_("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:E("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:E("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:E("minifySyntax")},clean:{flags:["c","clean"],handler:E("clean")},splitting:{flags:["s","splitting"],handler:E("splitting")},noExternal:{flags:["ne","no-external"],handler:Et("noExternal")}},H={};for(let t of Object.values(Ht))if(t)for(let r of t.flags)H[r]=t.handler;function Ot(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function $t(t){let r={},n={},s=0;while(s<t.length){let e=t[s];if(e.startsWith("--")){let o,i;if(e.includes("=")){let[a,l]=e.slice(2).split("=",2);o=a,i=l}else{o=e.slice(2);let a=t[s+1];if(i=a&&!a.startsWith("-")?a:!0,typeof i==="string")s++}if(o==="entry")if(typeof i==="string"){let a=Ot(i);if(n[a])f.warn(`Duplicate entry name '${a}' derived from '${i}'. Overwriting previous entry.`);n[a]=i}else throw new h("Option --entry requires a string value");else if(o.startsWith("entry.")){let a=o.slice(6);if(typeof i==="string"){if(n[a])f.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);n[a]=i}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=H[o];if(a)a(i,r);else throw new h(`Unknown option: --${o}`)}}else if(e.startsWith("-")){let o=e.slice(1),i=t[s+1],a=i&&!i.startsWith("-")?i:!0;if(typeof a==="string")s++;let l=H[o];if(l)l(a,r);else throw new h(`Unknown option: -${o}`)}else{let o=Ot(e);if(n[o])f.warn(`Duplicate entry name '${o}' derived from positional argument '${e}'. Overwriting previous entry.`);n[o]=e}s++}if(Object.keys(n).length>0)r.entry=n;return r}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
|
package/build/dtsWorker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var gt=require("node:module");var ct=Object.create;var{getPrototypeOf:lt,defineProperty:P,getOwnPropertyNames:F,getOwnPropertyDescriptor:pt}=Object,I=Object.prototype.hasOwnProperty;var g=(t,r,o)=>{o=t!=null?ct(lt(t)):{};let e=r||!t||!t.__esModule?P(o,"default",{value:t,enumerable:!0}):o;for(let s of F(t))if(!I.call(e,s))P(e,s,{get:()=>t[s],enumerable:!0});return e},L=new WeakMap,ut=(t)=>{var r=L.get(t),o;if(r)return r;if(r=P({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")F(t).map((e)=>!I.call(r,e)&&P(r,e,{get:()=>t[e],enumerable:!(o=pt(t,e))||o.enumerable}));return L.set(t,r),r};var ft=(t,r)=>{for(var o in r)P(t,o,{get:r[o],enumerable:!0,configurable:!0,set:(e)=>r[o]=()=>e})};var Dt={};ft(Dt,{runDtsInWorker:()=>yt});module.exports=ut(Dt);var d=require("node:worker_threads");class U extends Error{constructor(t){super(t);this.name="BunupError"}}class m extends U{constructor(t){super(t);this.name="BunupDTSBuildError"}}var u=(t)=>{if(t instanceof Error)return t.message;return String(t)};var p={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,r,o){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-r.length));return`\x1B[38;5;${t}m[${r}]\x1B[0m ${e}${o}`},cli(t){let r=this.labels.cli;console.log(this.formatMessage(this.colors.cli,r,t))},info(t){console.log(`\x1B[38;5;${this.colors.info}m${t}\x1B[0m`)},warn(t){let r=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,r,t))},error(t){let r=this.labels.error;console.error(this.formatMessage(this.colors.error,r,t))},progress(t,r){let o=String(t),e=this.colors.default;for(let[s,a]of Object.entries(this.colors.progress))if(o.includes(s)){e=a;break}console.log(this.formatMessage(e,o,r))}};function v(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function W(t,r){switch(t){case"esm":return".d.mts";case"cjs":return mt(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function mt(t){return t==="module"}function j(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function _(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}var H=g(require("node:fs")),q=g(require("oxc-transform"));var $=g(require("node:path"));function B(t){let r=$.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?$.default.resolve(r,t.data.compilerOptions.baseUrl):r}function G(t){let r=new Map,o=t.data?.compilerOptions?.paths;if(!o)return r;let e=B(t);for(let[s,a]of Object.entries(o))if(Array.isArray(a)&&a.length){let n=s.replace(/\*/g,"(.*)"),i=a[0].replace(/\*/g,"$1");r.set(`^${n}$`,$.default.join(e,i))}return r}function J(t,r,o){for(let[e,s]of r){let a=new RegExp(e),n=t.match(a);if(n)return s.replace("$1",n[1]||"")}return o?$.default.join(o,t):null}function X(t,r){if(r===void 0)return"";let o=t.slice(0,r).split(`
|
|
2
|
-
`),e=o.length,s=o[o.length-1].length+1;return` (${e}:${s})`}function Y(t){return t.replace(" with --isolatedDeclaration","")}var D=new Set;async function z(t){let r=new Map;return await Promise.all([...t].map(async(o)=>{try{let e=o.replace(/\.tsx?$/,".d.ts"),s=await H.default.promises.readFile(o,"utf8"),{code:a,errors:n}=q.default.isolatedDeclaration(o,s);if(n.forEach((i)=>{let l=i.labels[0],c=l?X(s,l.start):"",y=`${o.split("/").slice(-3).join("/")}${c}: ${Y(i.message)}`;if(!D.has(y))D.add(y)}),a)r.set(e,a)}catch(e){p.warn(`Failed to generate declaration for ${o}: ${u(e)}`)}})),r}var N=g(require("node:fs")),C=g(require("node:path"));var K=require("load-tsconfig");function Q(t){try{return K.loadTsConfig(".",t)}catch(r){return p.warn(`Failed to load tsconfig: ${u(r)}`),{path:t,data:{},files:[]}}}var S=g(require("node:path")),et=require("rollup"),st=g(require("rollup-plugin-dts")),T=g(require("typescript"));function V(t){return t.map((r)=>typeof r==="string"?new RegExp(`^${v(r)}($|\\/|\\\\)`):r)}function Z(t,r){return V(t.external||[]).concat(_(r).map((o)=>new RegExp(`^${v(o)}($|\\/|\\\\)`)))}function tt(t){return V(t.noExternal||[])}var O=g(require("node:fs")),rt=g(require("node:path"));function ot(t){let r=rt.default.join(t,"package.json");try{if(!O.default.existsSync(r))return null;let o=O.default.readFileSync(r,"utf8");return JSON.parse(o)}catch(o){return p.warn(`Failed to load package.json at ${r}: ${u(o)}`),null}}async function nt(t,r,o,e,s){let i=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,l=s.data?.compilerOptions,c={name:"bunup:virtual-dts",resolveId(f,x){if(f.startsWith("\x00virtual:"))return f;if(!x?.startsWith("\x00virtual:")||!f.startsWith("."))return null;let w=x.slice(9),b=S.default.resolve(S.default.dirname(w),f),A=r.has(b)?b:`${b}.d.ts`;return r.has(A)?`\x00virtual:${A}`:null},load(f){return f.startsWith("\x00virtual:")?r.get(f.slice(9))||null:null}},E=ot(e),h=Z(o,E),y=tt(o),R;try{R=await et.rollup({input:i,onwarn(x,w){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;w(x)},plugins:[c,st.default({tsconfig:s.path,compilerOptions:{...l?T.default.parseJsonConfigFileContent({compilerOptions:l},T.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:T.default.ScriptTarget.ESNext}})],external:(x)=>h.some((w)=>w.test(x))&&!y.some((w)=>w.test(x))});let{output:f}=await R.generate({});if(!f[0]?.code)throw new m("Generated bundle is empty");return f[0].code}catch(f){throw new m(`DTS bundling failed: ${u(f)}`)}finally{if(R)await R.close()}}var k=g(require("node:fs")),M=g(require("node:path"));var dt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,ht=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function it(t,r){let o=new Set([t]),e=[t],s=G(r),a=B(r);while(e.length){let n=e.pop();if(!n)continue;try{let i=await k.default.promises.readFile(n,"utf8"),l=xt(i);for(let c of l){let E=c.startsWith(".")?M.default.resolve(M.default.dirname(n),c):J(c,s,a);if(!E)continue;let h=Et(E);if(h&&!o.has(h))o.add(h),e.push(h)}}catch(i){p.warn(`Error processing ${n}: ${u(i)}`)}}return o}function xt(t){let r=new Set;for(let o of[dt,ht]){let e;while((e=o.exec(t))!==null)r.add(e[2])}return Array.from(r)}function Et(t){let r=["",".ts",".tsx","/index.ts","/index.tsx"];for(let o of r){let e=`${t}${o}`;if(k.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}async function at(t,r,o){let{absoluteRootDir:e,absoluteEntry:s}=wt(t,r),a=Q(o.preferredTsconfigPath),n=await it(s,a),i=await z(n);return nt(s,i,o,e,a)}function wt(t,r){let o=C.default.resolve(t),e=C.default.resolve(o,r);if(!N.default.existsSync(o))throw new m(`Root directory does not exist: ${o}`);if(!N.default.existsSync(e))throw new m(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new m(`Entry file must be a TypeScript file (.ts): ${e}`);if(C.default.relative(o,e).startsWith(".."))throw new m(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:o,absoluteEntry:e}}async function yt(t,r,o,e,s){return new Promise((a,n)=>{let i={rootDir:t,entries:r,formats:o,options:e,packageType:s},l=new d.Worker(new URL("./dtsWorker.js",import.meta.url),{workerData:i});l.on("message",(c)=>{if(c.success)a();else n(new m(c.error||"Unknown DTS worker error"))}),l.on("error",n),l.on("exit",(c)=>{if(c!==0)n(new m(`DTS worker stopped with exit code ${c}`))})})}if(!d.isMainThread&&d.parentPort){let{rootDir:t,entries:r,formats:o,options:e,packageType:s}=d.workerData,a=performance.now();p.progress("DTS","Bundling types");try{let n=r.map(async(i)=>{let l=await at(t,i.path,e);return Promise.all(o.map(async(c)=>{let E=W(c,s),h=`${e.outDir}/${i.name}${E}`,y=`${t}/${h}`;await Bun.write(y,l),p.progress("DTS",h)}))});Promise.all(n).then(()=>{let i=performance.now()-a;d.parentPort?.postMessage({success:!0});let l=j(i);if(p.progress("DTS",`Bundled types in ${l}`),D.size>0)console.log(`
|
|
2
|
+
`),e=o.length,s=o[o.length-1].length+1;return` (${e}:${s})`}function Y(t){return t.replace(" with --isolatedDeclaration","").replace(" with --isolatedDeclarations","")}var D=new Set;async function z(t){let r=new Map;return await Promise.all([...t].map(async(o)=>{try{let e=o.replace(/\.tsx?$/,".d.ts"),s=await H.default.promises.readFile(o,"utf8"),{code:a,errors:n}=q.default.isolatedDeclaration(o,s);if(n.forEach((i)=>{let l=i.labels[0],c=l?X(s,l.start):"",y=`${o.split("/").slice(-3).join("/")}${c}: ${Y(i.message)}`;if(!D.has(y))D.add(y)}),a)r.set(e,a)}catch(e){p.warn(`Failed to generate declaration for ${o}: ${u(e)}`)}})),r}var N=g(require("node:fs")),C=g(require("node:path"));var K=require("load-tsconfig");function Q(t){try{return K.loadTsConfig(".",t)}catch(r){return p.warn(`Failed to load tsconfig: ${u(r)}`),{path:t,data:{},files:[]}}}var S=g(require("node:path")),et=require("rollup"),st=g(require("rollup-plugin-dts")),T=g(require("typescript"));function V(t){return t.map((r)=>typeof r==="string"?new RegExp(`^${v(r)}($|\\/|\\\\)`):r)}function Z(t,r){return V(t.external||[]).concat(_(r).map((o)=>new RegExp(`^${v(o)}($|\\/|\\\\)`)))}function tt(t){return V(t.noExternal||[])}var O=g(require("node:fs")),rt=g(require("node:path"));function ot(t){let r=rt.default.join(t,"package.json");try{if(!O.default.existsSync(r))return null;let o=O.default.readFileSync(r,"utf8");return JSON.parse(o)}catch(o){return p.warn(`Failed to load package.json at ${r}: ${u(o)}`),null}}async function nt(t,r,o,e,s){let i=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,l=s.data?.compilerOptions,c={name:"bunup:virtual-dts",resolveId(f,x){if(f.startsWith("\x00virtual:"))return f;if(!x?.startsWith("\x00virtual:")||!f.startsWith("."))return null;let w=x.slice(9),b=S.default.resolve(S.default.dirname(w),f),A=r.has(b)?b:`${b}.d.ts`;return r.has(A)?`\x00virtual:${A}`:null},load(f){return f.startsWith("\x00virtual:")?r.get(f.slice(9))||null:null}},E=ot(e),h=Z(o,E),y=tt(o),R;try{R=await et.rollup({input:i,onwarn(x,w){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(x.code??""))return;w(x)},plugins:[c,st.default({tsconfig:s.path,compilerOptions:{...l?T.default.parseJsonConfigFileContent({compilerOptions:l},T.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:T.default.ScriptTarget.ESNext}})],external:(x)=>h.some((w)=>w.test(x))&&!y.some((w)=>w.test(x))});let{output:f}=await R.generate({});if(!f[0]?.code)throw new m("Generated bundle is empty");return f[0].code}catch(f){throw new m(`DTS bundling failed: ${u(f)}`)}finally{if(R)await R.close()}}var k=g(require("node:fs")),M=g(require("node:path"));var dt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,ht=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function it(t,r){let o=new Set([t]),e=[t],s=G(r),a=B(r);while(e.length){let n=e.pop();if(!n)continue;try{let i=await k.default.promises.readFile(n,"utf8"),l=xt(i);for(let c of l){let E=c.startsWith(".")?M.default.resolve(M.default.dirname(n),c):J(c,s,a);if(!E)continue;let h=Et(E);if(h&&!o.has(h))o.add(h),e.push(h)}}catch(i){p.warn(`Error processing ${n}: ${u(i)}`)}}return o}function xt(t){let r=new Set;for(let o of[dt,ht]){let e;while((e=o.exec(t))!==null)r.add(e[2])}return Array.from(r)}function Et(t){let r=["",".ts",".tsx","/index.ts","/index.tsx"];for(let o of r){let e=`${t}${o}`;if(k.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}async function at(t,r,o){let{absoluteRootDir:e,absoluteEntry:s}=wt(t,r),a=Q(o.preferredTsconfigPath),n=await it(s,a),i=await z(n);return nt(s,i,o,e,a)}function wt(t,r){let o=C.default.resolve(t),e=C.default.resolve(o,r);if(!N.default.existsSync(o))throw new m(`Root directory does not exist: ${o}`);if(!N.default.existsSync(e))throw new m(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new m(`Entry file must be a TypeScript file (.ts): ${e}`);if(C.default.relative(o,e).startsWith(".."))throw new m(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:o,absoluteEntry:e}}async function yt(t,r,o,e,s){return new Promise((a,n)=>{let i={rootDir:t,entries:r,formats:o,options:e,packageType:s},l=new d.Worker(new URL("./dtsWorker.js",import.meta.url),{workerData:i});l.on("message",(c)=>{if(c.success)a();else n(new m(c.error||"Unknown DTS worker error"))}),l.on("error",n),l.on("exit",(c)=>{if(c!==0)n(new m(`DTS worker stopped with exit code ${c}`))})})}if(!d.isMainThread&&d.parentPort){let{rootDir:t,entries:r,formats:o,options:e,packageType:s}=d.workerData,a=performance.now();p.progress("DTS","Bundling types");try{let n=r.map(async(i)=>{let l=await at(t,i.path,e);return Promise.all(o.map(async(c)=>{let E=W(c,s),h=`${e.outDir}/${i.name}${E}`,y=`${t}/${h}`;await Bun.write(y,l),p.progress("DTS",h)}))});Promise.all(n).then(()=>{let i=performance.now()-a;d.parentPort?.postMessage({success:!0});let l=j(i);if(p.progress("DTS",`Bundled types in ${l}`),D.size>0)console.log(`
|
|
3
3
|
`),D.forEach((c)=>{p.warn(c)}),p.info(`
|
|
4
4
|
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.
|
|
5
5
|
`),D.clear()}).catch((i)=>{d.parentPort?.postMessage({success:!1,error:u(i)})})}catch(n){d.parentPort?.postMessage({success:!1,error:u(n)})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "A 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.1.
|
|
21
|
+
"bunup": "^0.1.21",
|
|
22
22
|
"eslint": "^8.57.0",
|
|
23
23
|
"husky": "^9.1.6",
|
|
24
24
|
"prettier": "^3.2.5",
|