bunup 0.3.0 → 0.3.2
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 +13 -13
- package/build/index.d.mts +15 -18
- package/build/index.d.ts +15 -18
- package/build/index.js +2 -2
- package/build/index.mjs +2 -2
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{loadTsConfig as
|
|
3
|
+
import{loadTsConfig as Nn}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 d extends C{constructor(n){super(n);this.name="BunupDTSBuildError"}}class h extends C{constructor(n){super(n);this.name="BunupCLIError"}}class R extends C{constructor(n){super(n);this.name="BunupWatchError"}}var m=(n)=>{if(n instanceof Error)return n.message;return String(n)},jn=(n,t)=>{let e=m(n),r=t?`[${t}] `:"",s="ERROR";if(n instanceof x)s="BUILD ERROR";else if(n instanceof d)s="DTS ERROR";else if(n instanceof h)s="CLI ERROR";else if(n instanceof R)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")},
|
|
6
|
-
`);let a=
|
|
5
|
+
`)+"\x1B[0m")},Z=(n,t)=>{jn(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 z(n){try{return Nn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import{rollup as _n}from"rollup";import Gn from"rollup-plugin-dts";import Y from"typescript";import _ from"node:fs";import An from"node:path";var v={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0,sourcemap:"none"};function X(n,t){return{outdir:`${t}/${n.outDir}`,minify:Tn(n),target:n.target,splitting:n.splitting,sourcemap:n.sourcemap}}function Tn(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 G(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(n=8){return Math.random().toString(36).substring(2,2+n)}function nn(n,t){switch(n){case"esm":return".mjs";case"cjs":return N(t)?".cjs":".js";case"iife":return".global.js"}}function tn(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 en(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function rn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function sn(n,t){return n===void 0?t==="esm":n}function q(n){if(n===0)return"0 B";let t=["B","KB","MB","GB"],e=Math.floor(Math.log(n)/Math.log(1024));if(e===0)return`${n} ${t[e]}`;return`${(n/Math.pow(1024,e)).toFixed(2)} ${t[e]}`}function O(n,t=3){return n.split("/").slice(-t).join("/")}function I(n,t){let e=An.join(n,t);if(_.existsSync(e))try{_.rmSync(e,{recursive:!0,force:!0})}catch(r){throw new x(`Failed to clean output directory: ${r}`)}_.mkdirSync(e,{recursive:!0})}function P(n){return n||v.outDir}function on(n){return n===void 0?v.clean:n}function an(n){return n.map((t)=>typeof t==="string"?new RegExp(`^${G(t)}($|\\/|\\\\)`):t)}function T(n,t){return an(n.external||[]).concat(rn(t).map((e)=>new RegExp(`^${G(e)}($|\\/|\\\\)`)))}function A(n){return an(n.noExternal||[])}import M from"node:fs";import J from"node:path";async function cn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=J.join(n,`bunup.config${e}`);try{if(!M.existsSync(r))continue;let s=await Mn(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 Mn(n,t){if(t===".json"||t===".jsonc")return kn(n);return Ln(n)}function kn(n){try{let t=M.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 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. ${m(t)}`)}}function Dn(n,t){let e=[];if(Hn(n))Un(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 Un(n,t,e){for(let r of n){let s=J.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function 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 k(n){let t=J.join(n,"package.json");try{if(!M.existsSync(t))return null;let e=M.readFileSync(t,"utf8");return JSON.parse(e)}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),null}}import E from"path";var y="\x00virtual:",ln=(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 fn(n,t,e,r,s){let i=n.replace(/\.tsx?$/,".d.ts"),o=`${y}${i}`,a=s.data?.compilerOptions,c=k(r),u=T(e,c),p=A(e),f;try{f=await _n({input:o,onwarn(b,$){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(b.code??""))return;$(b)},plugins:[ln(t),Gn({tsconfig:s.path,compilerOptions:{...a?Y.parseJsonConfigFileContent({compilerOptions:a},Y.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:Y.ScriptTarget.ESNext}})],external:(b)=>u.some(($)=>$.test(b))&&!p.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: ${m(g)}`)}finally{if(f)await f.close()}}import un 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 pn(n,t){let e=new Set([n]),r=[n],s=Yn(t),i=mn(t);while(r.length){let o=r.pop();if(!o)continue;try{let a=await un.promises.readFile(o,"utf8"),c=Pn(a);for(let u of c){let p=u.startsWith(".")?S.resolve(S.dirname(o),u):Fn(u,s,i);if(!p)continue;let f=Jn(p);if(f&&!e.has(f))e.add(f),r.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(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(un.existsSync(r)&&(r.endsWith(".ts")||r.endsWith(".tsx")))return r}return null}function mn(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=mn(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 gn(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}: ${m(r)}`)}})),t}import K from"node:fs";import F from"node:path";import{isolatedDeclaration as Zn}from"oxc-transform";function dn(n,t){let e=F.resolve(n),r=F.resolve(e,t);if(!K.existsSync(e))throw new d(`Root directory does not exist: ${e}`);if(!K.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(F.relative(e,r).startsWith(".."))throw new d(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:e,absoluteEntry:r}}async function hn(n){let t=!1;if(await Promise.all([...n].map(async(e)=>{try{let r=e.replace(/\.d\.ts$/,".ts"),s=await K.promises.readFile(r,"utf8"),{errors:i}=Zn(r,s);i.forEach((o)=>{if(!t)console.log(`
|
|
6
|
+
`);let a=o.labels[0],c=a?zn(s,a.start):"",p=`${O(r)}${c}: ${Xn(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 zn(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 Xn(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function yn(n,t,e){let{absoluteRootDir:r,absoluteEntry:s}=dn(n,t),i=z(e.preferredTsconfigPath),o=await pn(s,i),a=await gn(o);return fn(s,a,e,r,i)}function L(n){return n.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(n){let t=[],e=new Set,r={};function s(i,o){if(e.has(i)){let a=V(),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
|
-
${r[
|
|
13
|
-
${
|
|
12
|
+
${r[i]} -> ${i}.js
|
|
13
|
+
${o} -> ${c}.js (auto-renamed to avoid conflict)
|
|
14
14
|
|
|
15
15
|
To fix this, use named entries in your configuration:
|
|
16
16
|
{
|
|
17
17
|
entry: {
|
|
18
|
-
custom_name: "${r[
|
|
19
|
-
another_name: "${
|
|
18
|
+
custom_name: "${r[i]}",
|
|
19
|
+
another_name: "${o}"
|
|
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:
|
|
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=L(i);s(o,i)}else Object.entries(n).forEach(([i,o])=>{s(i,o)});return t}function xn(n,t){return`[dir]/${n}${t}`}function wn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var B=new Set;async function 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=k(t),r=e?.type,s=T(n,e),i=A(n),o=[wn(s,i)],a=j(n.entry),c=X(n,t),u=n.format.flatMap((p)=>a.map((f)=>{return Vn(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=n.dts===!0?a:j(n.dts.entry);try{await Promise.all(f.map(async(g)=>{let b=await yn(t,g.path,n);await Promise.all(p.map(async($)=>{let Sn=tn($,r),W=`${t}/${n.outDir}/${g.name}${Sn}`;await Bun.write(W,b);let Rn=Bun.file(W).size||0;l.progress("DTS",O(W),q(Rn),n.name)}))}))}catch(g){throw new d(`DTS build process encountered errors: ${m(g)}`)}}}async function Vn(n,t,e,r,s,i,o){let a=nn(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:xn(e.name,a)},splitting:sn(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),q(p),n.name)}var bn="0.3.2";var $n="https://bun.sh/docs/installation",On="https://bunup.arshadyaseen.com/#cli-options";function w(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function H(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function Cn(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function tt(){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${On}\x1B[0m
|
|
26
|
+
`),process.exit(0)}function et(){console.log(bn),process.exit(0)}var rt={name:{flags:["n","name"],handler:H("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:H("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},external:{flags:["e","external"],handler:Cn("external")},sourcemap:{flags:["sm","sourcemap"],handler:H("sourcemap")},target:{flags:["t","target"],handler:H("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:Cn("noExternal")}},st={help:{flags:["h","help"],handler:()=>tt()},version:{flags:["v","version"],handler:()=>et()}},U={};for(let n of Object.values(rt))if(n)for(let t of n.flags)U[t]=n.handler;for(let n of Object.values(st))for(let t of n.flags)U[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=L(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=U[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=U[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=L(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
|
|
27
|
+
To install Bun, visit `+$n)})();import Q from"node:path";import it from"chokidar";async function En(n,t){let e=new Set,r=j(n.entry);r.forEach((c)=>{let u=Q.resolve(t,c.path),p=Q.dirname(u);e.add(p)});let s=it.watch(Array.from(e),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,n.outDir]}),i=null,o=!1,a=async()=>{if(o)return;o=!0;try{await D({...n,entry:r.map((c)=>c.path),clean:!1},t),n.onBuildSuccess?.()}catch(c){throw new R(`Build failed: ${m(c)}`)}finally{o=!1}};s.on("change",(c)=>{let u=Q.relative(t,c);if(l.cli(`File changed: ${u}`),i)clearTimeout(i);i=setTimeout(()=>a(),300)}),s.on("error",(c)=>{throw new R(`Watcher error: ${m(c)}`)}),await a()}async function ot(n=Bun.argv.slice(2)){let t=vn(n),{configs:e,configFilePath:r}=await cn(process.cwd());if(r)l.cli(`Using config file: ${O(r,2)}`);if(t.watch)l.cli("Starting watch mode"),l.cli("Watching for file changes");let s=performance.now();if(l.cli("Build started"),e.length===0){let a={...v,...t},c=process.cwd();if(a.clean)I(c,P(a.outDir));await Bn(a,c)}else{for(let{options:a,rootDir:c}of e)if(on(a.clean))I(c,P(a.outDir));await Promise.all(e.map(async({options:a,rootDir:c})=>{let u={...v,...a,...t};await Bn(u,c)}))}let i=performance.now()-s,o=en(i);if(l.cli(`\u26A1\uFE0F Build completed in ${o}`),B.size>0)await hn(B),B.clear();if(!t.watch)process.exit(0)}async function Bn(n,t){if(n.watch)await En(n,t);else await D(n,t),n.onBuildSuccess?.()}ot().catch((n)=>Z(n));export{ot as main};
|
package/build/index.d.mts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
type WithOptional<
|
|
2
|
-
T,
|
|
3
|
-
K extends keyof T
|
|
4
|
-
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
5
|
-
type DefineConfigOption = WithOptional<BunupOptions, "outDir" | "format">;
|
|
6
|
-
type DefineConfigOptions = DefineConfigOption | DefineConfigOption[];
|
|
7
|
-
type DefineWorkspaceOptions = {
|
|
8
|
-
name: string
|
|
9
|
-
root: string
|
|
10
|
-
config: DefineConfigOptions
|
|
11
|
-
}[];
|
|
12
|
-
|
|
13
1
|
type Format = "esm" | "cjs" | "iife";
|
|
14
2
|
type Target = "bun" | "node" | "browser";
|
|
15
3
|
type External = string[];
|
|
@@ -165,15 +153,24 @@ interface BunupOptions {
|
|
|
165
153
|
*
|
|
166
154
|
* If watch mode is enabled, this callback runs after each rebuild
|
|
167
155
|
*/
|
|
168
|
-
|
|
156
|
+
onBuildSuccess?: () => void | Promise<void>;
|
|
169
157
|
}
|
|
170
158
|
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
type WithOptional<
|
|
160
|
+
T,
|
|
161
|
+
K extends keyof T
|
|
162
|
+
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
163
|
+
type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
|
|
164
|
+
type DefineWorkspaceEntry = {
|
|
165
|
+
name: string
|
|
166
|
+
root: string
|
|
167
|
+
config: DefineConfigEntry | DefineConfigEntry[]
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
declare function defineConfig(options: DefineConfigEntry | DefineConfigEntry[]): DefineConfigEntry | DefineConfigEntry[];
|
|
171
|
+
declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
|
|
173
172
|
|
|
174
173
|
declare function build(options: BunupOptions, rootDir: string): Promise<void>;
|
|
175
174
|
|
|
176
|
-
type Options = Partial<BunupOptions>;
|
|
177
|
-
|
|
178
175
|
export { build, defineConfig, defineWorkspace };
|
|
179
|
-
export type {
|
|
176
|
+
export type { DefineConfigEntry, DefineWorkspaceEntry };
|
package/build/index.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
type WithOptional<
|
|
2
|
-
T,
|
|
3
|
-
K extends keyof T
|
|
4
|
-
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
5
|
-
type DefineConfigOption = WithOptional<BunupOptions, "outDir" | "format">;
|
|
6
|
-
type DefineConfigOptions = DefineConfigOption | DefineConfigOption[];
|
|
7
|
-
type DefineWorkspaceOptions = {
|
|
8
|
-
name: string
|
|
9
|
-
root: string
|
|
10
|
-
config: DefineConfigOptions
|
|
11
|
-
}[];
|
|
12
|
-
|
|
13
1
|
type Format = "esm" | "cjs" | "iife";
|
|
14
2
|
type Target = "bun" | "node" | "browser";
|
|
15
3
|
type External = string[];
|
|
@@ -165,15 +153,24 @@ interface BunupOptions {
|
|
|
165
153
|
*
|
|
166
154
|
* If watch mode is enabled, this callback runs after each rebuild
|
|
167
155
|
*/
|
|
168
|
-
|
|
156
|
+
onBuildSuccess?: () => void | Promise<void>;
|
|
169
157
|
}
|
|
170
158
|
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
type WithOptional<
|
|
160
|
+
T,
|
|
161
|
+
K extends keyof T
|
|
162
|
+
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
163
|
+
type DefineConfigEntry = Omit<WithOptional<BunupOptions, "outDir" | "format">, "watch">;
|
|
164
|
+
type DefineWorkspaceEntry = {
|
|
165
|
+
name: string
|
|
166
|
+
root: string
|
|
167
|
+
config: DefineConfigEntry | DefineConfigEntry[]
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
declare function defineConfig(options: DefineConfigEntry | DefineConfigEntry[]): DefineConfigEntry | DefineConfigEntry[];
|
|
171
|
+
declare function defineWorkspace(options: DefineWorkspaceEntry[]): DefineWorkspaceEntry[];
|
|
173
172
|
|
|
174
173
|
declare function build(options: BunupOptions, rootDir: string): Promise<void>;
|
|
175
174
|
|
|
176
|
-
type Options = Partial<BunupOptions>;
|
|
177
|
-
|
|
178
175
|
export { build, defineConfig, defineWorkspace };
|
|
179
|
-
export type {
|
|
176
|
+
export type { DefineConfigEntry, DefineWorkspaceEntry };
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
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}}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.
|
|
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}),n.push({name:f,path:i})}else n.push({name:o,path:i}),t.add(o),e[o]=i}if(Array.isArray(r))for(let o of r){let i=
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:i})}else n.push({name:o,path:i}),t.add(o),e[o]=i}if(Array.isArray(r))for(let o of r){let i=Dr(o);s(i,o)}else Object.entries(r).forEach(([o,i])=>{s(o,i)});return n}function gr(r,n){return`[dir]/${r}${n}`}function mr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let s=e.path;if(r.some((i)=>i.test(s))&&!n.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var nr=new Set;async function pr(r,n){if(!r.entry||r.entry.length===0||!r.outDir)throw new $("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let t=B(n),e=t?.type,s=O(r,t),o=S(r),i=[mr(s,o)],c=L(r.entry),f=Z(r,n),g=r.format.flatMap((u)=>c.map((a)=>{return Tr(r,n,a,u,e,i,f)}));try{await Promise.all(g)}catch(u){throw console.error(u),new $("Build process encountered errors")}if(r.dts){let u=r.format.filter((m)=>{if(m==="iife"&&!R(e)&&r.format.includes("cjs"))return!1;return!0}),a=r.dts===!0?c:L(r.dts.entry);try{await Promise.all(a.map(async(m)=>{let h=await ur(n,m.path,r);await Promise.all(u.map(async(y)=>{let dr=P(y,e),N=`${n}/${r.outDir}/${m.name}${dr}`;await Bun.write(N,h);let xr=Bun.file(N).size||0;l.progress("DTS",v(N),T(xr),r.name)}))}))}catch(m){throw new x(`DTS build process encountered errors: ${d(m)}`)}}}async function Tr(r,n,t,e,s,o,i){let c=z(e,s),f=await Bun.build({...i,entrypoints:[`${n}/${t.path}`],format:e,naming:{entry:gr(t.name,c)},splitting:F(r.splitting,e),plugins:o,throw:!1});if(!f.success)throw f.logs.forEach((a)=>{if(a.level==="error")l.error(a.message);else if(a.level==="warning")l.warn(a.message);else if(a.level==="info")l.info(a.message)}),new $(`Build failed for ${t.path} (${e})`);let g=`${n}/${r.outDir}/${t.name}${c}`,u=Bun.file(g).size||0;l.progress(e.toUpperCase(),v(g),T(u),r.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function er(r){return r}function or(r){return r}import{loadTsConfig as sr}from"load-tsconfig";class B extends Error{constructor(r){super(r);this.name="BunupError"}}class y extends B{constructor(r){super(r);this.name="BunupBuildError"}}class d extends B{constructor(r){super(r);this.name="BunupDTSBuildError"}}var p=(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:i,muted:o}){let s=" ".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=i?` \x1B[48;5;${r};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${s}${g}${a} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${u.join(" ")}${m}`}let f=i?` \x1B[48;5;${r};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${r}m${n}\x1B[0m ${s}${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 i=String(r),o=this.colors.default,s,c,f={};if(typeof t==="string")s=t,c=e;else if(t)s=t.size,c=t.identifier,f=t;for(let[u,a]of Object.entries(this.colors.progress))if(i.includes(u)){o=a;break}let g=this.formatMessage({colorCode:o,label:i,message:n,size:s,identifier:c,muted:f.muted});this.output(g,f)}};function T(r){try{return sr(".",r)}catch(n){return l.warn(`Failed to load tsconfig: ${p(n)}`),{path:r,data:{},files:[]}}}import{rollup as ar}from"rollup";import fr from"rollup-plugin-dts";import N from"typescript";import Nr from"node:fs";import Dr from"node:path";function W(r,n){return{outdir:`${n}/${r.outDir}`,minify:ir(r),target:r.target,splitting:r.splitting,sourcemap:r.sourcemap}}function ir(r){let{minify:n,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:i}=r,o=n===!0;return{whitespace:t??o,identifiers:e??o,syntax:i??o}}function j(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(r=8){return Math.random().toString(36).substring(2,2+r)}function k(r,n){switch(r){case"esm":return".mjs";case"cjs":return C(n)?".cjs":".js";case"iife":return".global.js"}}function L(r,n){switch(r){case"esm":return".d.mts";case"cjs":return C(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function C(r){return r==="module"}function H(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function J(r,n){return r===void 0?n==="esm":r}function M(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 b(r,n=3){return r.split("/").slice(-n).join("/")}function Y(r){return r.map((n)=>typeof n==="string"?new RegExp(`^${j(n)}($|\\/|\\\\)`):n)}function R(r,n){return Y(r.external||[]).concat(H(n).map((t)=>new RegExp(`^${j(t)}($|\\/|\\\\)`)))}function v(r){return Y(r.noExternal||[])}import q from"node:fs";import cr from"node:path";function O(r){let n=cr.join(r,"package.json");try{if(!q.existsSync(n))return null;let t=q.readFileSync(n,"utf8");return JSON.parse(t)}catch(t){return l.warn(`Failed to load package.json at ${n}: ${p(t)}`),null}}import $ from"path";var x="\x00virtual:",K=(r)=>{return{name:"bunup:virtual-dts",resolveId(n,t){if(n.startsWith(x))return n;if(!t?.startsWith(x)||!n.startsWith("."))return null;let e=t.slice(x.length),i=$.resolve($.dirname(e),n);if(n==="."){let s=$.join($.dirname(e),"index.d.ts");if(r.has(s))return`${x}${s}`;i=$.dirname(e)}if(r.has(i))return`${x}${i}`;let o=`${i}.d.ts`;if(r.has(o))return`${x}${o}`;if(n.startsWith(".")){let s=$.join(i,"index.d.ts");if(r.has(s))return`${x}${s}`}return null},load(n){if(n.startsWith(x)){let t=n.slice(x.length),e=r.get(t);if(e)return Q.add(t),e}return null}}};async function U(r,n,t,e,i){let o=r.replace(/\.tsx?$/,".d.ts"),s=`${x}${o}`,c=i.data?.compilerOptions,f=O(e),g=R(t,f),u=v(t),a;try{a=await ar({input:s,onwarn(E,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(E.code??""))return;h(E)},plugins:[K(n),fr({tsconfig:i.path,compilerOptions:{...c?N.parseJsonConfigFileContent({compilerOptions:c},N.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:N.ScriptTarget.ESNext}})],external:(E)=>g.some((h)=>h.test(E))&&!u.some((h)=>h.test(E))});let{output:m}=await a.generate({});if(!m[0]?.code)throw new d("Generated bundle is empty");return m[0].code}catch(m){throw new d(`DTS bundling failed: ${p(m)}`)}finally{if(a)await a.close()}}import Z from"node:fs";import w from"node:path";var lr=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,ur=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function _(r,n){let t=new Set([r]),e=[r],i=pr(n),o=z(n);while(e.length){let s=e.pop();if(!s)continue;try{let c=await Z.promises.readFile(s,"utf8"),f=gr(c);for(let g of f){let u=g.startsWith(".")?w.resolve(w.dirname(s),g):dr(g,i,o);if(!u)continue;let a=mr(u);if(a&&!t.has(a))t.add(a),e.push(a)}}catch(c){l.warn(`Error processing ${s}: ${p(c)}`)}}return t}function gr(r){let n=new Set;for(let t of[lr,ur]){let e;while((e=t.exec(r))!==null)n.add(e[2])}return Array.from(n)}function mr(r){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let t of n){let e=`${r}${t}`;if(Z.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}function z(r){let n=w.dirname(r.path||"");return r.data?.compilerOptions?.baseUrl?w.resolve(n,r.data.compilerOptions.baseUrl):n}function pr(r){let n=new Map,t=r.data?.compilerOptions?.paths;if(!t)return n;let e=z(r);for(let[i,o]of Object.entries(t))if(Array.isArray(o)&&o.length){let s=i.replace(/\*/g,"(.*)"),c=o[0].replace(/\*/g,"$1");n.set(`^${s}$`,w.join(e,c))}return n}function dr(r,n,t){for(let[e,i]of n){let o=new RegExp(e),s=r.match(o);if(s)return i.replace("$1",s[1]||"")}return t?w.join(t,r):null}import xr from"node:fs";import{isolatedDeclaration as Er}from"oxc-transform";async function P(r){let n=new Map;return await Promise.all([...r].map(async(t)=>{try{let e=t.replace(/\.tsx?$/,".d.ts"),i=await xr.promises.readFile(t,"utf8"),{code:o}=Er(t,i);if(o)n.set(e,o)}catch(e){l.warn(`Failed to generate declaration for ${t}: ${p(e)}`)}})),n}import X from"node:fs";import A from"node:path";import{isolatedDeclaration as En}from"oxc-transform";function F(r,n){let t=A.resolve(r),e=A.resolve(t,n);if(!X.existsSync(t))throw new d(`Root directory does not exist: ${t}`);if(!X.existsSync(e))throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(A.relative(t,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}async function I(r,n,t){let{absoluteRootDir:e,absoluteEntry:i}=F(r,n),o=T(t.preferredTsconfigPath),s=await _(i,o),c=await P(s);return U(i,c,t,e,o)}function hr(r){return r.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function D(r){let n=[],t=new Set,e={};function i(o,s){if(t.has(o)){let c=G(),f=`${o}_${c}`;l.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}),n.push({name:f,path:s})}else n.push({name:o,path:s}),t.add(o),e[o]=s}if(Array.isArray(r))for(let o of r){let s=
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),n.push({name:f,path:s})}else n.push({name:o,path:s}),t.add(o),e[o]=s}if(Array.isArray(r))for(let o of r){let s=hr(o);i(s,o)}else Object.entries(r).forEach(([o,s])=>{i(o,s)});return n}function V(r,n){return`[dir]/${r}${n}`}function rr(r,n){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let i=e.path;if(r.some((s)=>s.test(i))&&!n.some((s)=>s.test(i)))return{path:i,external:!0};return null})}}}var Q=new Set;async function yr(r,n){if(!r.entry||r.entry.length===0||!r.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let t=O(n),e=t?.type,i=R(r,t),o=v(r),s=[rr(i,o)],c=D(r.entry),f=W(r,n),g=r.format.flatMap((u)=>c.map((a)=>{return $r(r,n,a,u,e,s,f)}));try{await Promise.all(g)}catch(u){throw console.error(u),new y("Build process encountered errors")}if(r.dts){let u=r.format.filter((m)=>{if(m==="iife"&&!C(e)&&r.format.includes("cjs"))return!1;return!0}),a=r.dts===!0?c:D(r.dts.entry);try{await Promise.all(a.map(async(m)=>{let E=await I(n,m.path,r);await Promise.all(u.map(async(h)=>{let nr=L(h,e),S=`${n}/${r.outDir}/${m.name}${nr}`;await Bun.write(S,E);let tr=Bun.file(S).size||0;l.progress("DTS",b(S),M(tr),r.name)}))}))}catch(m){throw new d(`DTS build process encountered errors: ${p(m)}`)}}}async function $r(r,n,t,e,i,o,s){let c=k(e,i),f=await Bun.build({...s,entrypoints:[`${n}/${t.path}`],format:e,naming:{entry:V(t.name,c)},splitting:J(r.splitting,e),plugins:o,throw:!1});if(!f.success)throw f.logs.forEach((a)=>{if(a.level==="error")l.error(a.message);else if(a.level==="warning")l.warn(a.message);else if(a.level==="info")l.info(a.message)}),new y(`Build failed for ${t.path} (${e})`);let g=`${n}/${r.outDir}/${t.name}${c}`,u=Bun.file(g).size||0;l.progress(e.toUpperCase(),b(g),M(u),r.name)}export{or as defineWorkspace,er as defineConfig,yr as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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.
|
|
21
|
+
"bunup": "^0.3.1",
|
|
22
22
|
"eslint": "^8.57.0",
|
|
23
23
|
"husky": "^9.1.6",
|
|
24
24
|
"prettier": "^3.2.5",
|