bunup 0.4.12 → 0.4.13
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 +28 -0
- package/build/index.d.ts +28 -0
- package/build/index.js +4 -4
- package/build/index.mjs +3 -3
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{build as Qe}from"rolldown";import{dts as Ze}from"rolldown-plugin-dts";var
|
|
3
|
+
import{build as Qe}from"rolldown";import{dts as Ze}from"rolldown-plugin-dts";var re=!1;function L(e){re=e??!1}class C{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!C.instance)C.instance=new C;return C.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(e){if(!e?.once)return!0;if(this.loggedOnceMessages.has(e.once))return!1;return this.loggedOnceMessages.add(e.once),!0}formatMessage({colorCode:e,label:t,message:n,size:r,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),a=o?`\x1B[38;5;${this.colors.info}m${n}\x1B[0m`:n;if(r){let[c,...f]=a.split(" "),m=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-c.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${c}${m} \x1B[38;5;${this.colors.size}m${r}\x1B[0m ${f.join(" ")}${p}`}let l=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${l}`}output(e,t={},n=console.log){if(re)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(n(e),t.verticalSpace)console.log("")}cli(e,t={}){let n=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}info(e,t={}){let n=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t)}warn(e,t={}){let n=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.warn)}error(e,t={}){let n=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(n,t,console.error)}progress(e,t,n,r){let s=String(e),o=this.colors.default,i,a,l={};if(typeof n==="string")i=n,a=r;else if(n)i=n.size,a=n.identifier,l=n;for(let[f,m]of Object.entries(this.colors.progress))if(s.includes(f)){o=m;break}let c=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:l.muted});this.output(c,l)}}var u=C.getInstance();class E extends Error{constructor(e){super(e);this.name="BunupError"}}class w extends E{constructor(e){super(e);this.name="BunupBuildError"}}class h extends E{constructor(e){super(e);this.name="BunupDTSBuildError"}}class g extends E{constructor(e){super(e);this.name="BunupCLIError"}}class A extends E{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},Ve=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{u.error("\x1B[0mYou're trying to build a project that uses Bun. Please set the target option to \x1B[36m`bun`\x1B[0m.\nExample: \x1B[32m`bunup --target bun`\x1B[0m or in config: \x1B[32m{ target: 'bun' }\x1B[0m")}}],Y=(e,t)=>{let n=b(e),r=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof h)s="DTS ERROR";else if(e instanceof g)s="CLI ERROR";else if(e instanceof A)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";let o=Ve.find((i)=>i.pattern.test(n)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${r}${n}`);if(o)console.log(`
|
|
4
4
|
`),o.logSolution(n),console.log(`
|
|
5
|
-
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},
|
|
5
|
+
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshadyaseen/bunup/issues/new\x1B[0m")},se=(e,t)=>{Y(e,t),process.exit(1)};import ie from"node:fs/promises";import Ye from"node:path";function X(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function ae(e,t,n){return Array.isArray(e)?e.map((r)=>({...r,[t]:n})):{...e,[t]:n}}function le(e){return Array.isArray(e)?e:[e]}function ce(e,t){switch(e){case"esm":return $(t)?".js":".mjs";case"cjs":return $(t)?".cjs":".js";case"iife":return".global.js"}}function ue(e,t){switch(e){case"esm":return $(t)?".d.ts":".d.mts";case"cjs":return $(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function K(e){return e==="node"||e==="bun"}function $(e){return e==="module"}function I(e){return e>=1000?`${(e/1000).toFixed(2)}s`:`${Math.round(e)}ms`}function fe(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function J(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(1024));if(n===0)return`${e} ${t[n]}`;return`${(e/1024**n).toFixed(2)} ${t[n]}`}function x(e,t=3){return e.split("/").slice(-t).join("/")}async function pe(e,t){let n=Ye.join(e,t);try{await ie.rm(n,{recursive:!0,force:!0})}catch(r){throw new w(`Failed to clean output directory: ${r}`)}await ie.mkdir(n,{recursive:!0})}function M(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function me(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${X(t)}($|\\/|\\\\)`):t)}function D(e,t){return me(e.external||[]).concat(fe(t).map((n)=>new RegExp(`^${X(n)}($|\\/|\\\\)`)))}function _(e){return me(e.noExternal||[])}import Je from"node:path";import{ResolverFactory as ze}from"oxc-resolver";import R from"node:path";var P="\x00dts:",ge=(e,t,n)=>{return{name:"bunup:virtual-dts",async resolveId(r,s){if(z(r))return r;if(!s||!z(s))return null;let o=await v(r,t,n,O(s));if(!o)return null;let i=S(o);if(e.has(i))return j(i);return null},load(r){if(r.startsWith(P)){let s=O(r),o=e.get(s);if(o)return T.add(s),o}return null}}};function de(e){return e.tsconfig?.compilerOptions}function S(e){return e.replace(/\.tsx?$/,".d.ts")}function Q(e){let t=R.dirname(e.path||""),n=de(e);return n?.baseUrl?R.resolve(t,n.baseUrl):t}function he(e){let t=new Map,n=de(e)?.paths;if(!n)return t;let r=Q(e);for(let[s,o]of Object.entries(n))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");t.set(`^${i}$`,R.join(r,a))}return t}function Xe(e,t,n){for(let[r,s]of t){let o=new RegExp(r),i=e.match(o);if(i)return s.replace("$1",i[1]||"")}return n?R.join(n,e):null}async function Ke(e){let t=["",".ts",".tsx",".cts",".mts","/index.ts","/index.tsx","/index.cts","/index.mts"];for(let n of t){let r=`${e}${n}`;if(await Bun.file(r).exists()&&(r.endsWith(".ts")||r.endsWith(".tsx")||r.endsWith(".cts")||r.endsWith(".mts")))return r}return null}function v(e,t,n,r){let s=e.startsWith(".")?R.resolve(R.dirname(r||""),e):Xe(e,t,n);if(!s)return Promise.resolve(null);return Ke(s)}function z(e){return e.startsWith(P)}function O(e){return e.replace(P,"")}function j(e){return`${P}${e}`}var be;function xe(e){return{name:"bunup:types-resolve",buildStart(){be||=new ze({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,n){let r=n?O(n):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>{let l=!1;if(typeof a==="string")l=a===t||!!r?.includes(a);else l=a.test(t)||!!(r&&a.test(r));return l}))return}let s=r?Je.dirname(r):process.cwd(),{path:o}=await be.async(s,t);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function ye(e,t,n,r,s,o){let i=S(e),a=j(i),l=D(n,r),c=_(n);try{let{output:f}=await Qe({input:a,output:{dir:n.outDir,inlineDynamicImports:!0},write:!1,onwarn(m,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;p(m)},plugins:[ge(t,s,o),typeof n.dts==="object"&&"resolve"in n.dts&&xe(typeof n.dts.resolve==="boolean"?void 0:n.dts.resolve),Ze({dtsInput:!0})],external:(m)=>l.some((p)=>p.test(m))&&!c.some((p)=>p.test(m))});if(!f[0]?.code)return u.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return f[0].code}catch(f){throw new h(`DTS bundling failed for entry "${e}": ${b(f)}`)}}var et=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,tt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,nt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,rt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,st=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,it=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ot=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function at(e){let t=new Set,n=[et,tt,nt,rt,st,it,ot];for(let r of n){let s=e.matchAll(r);for(let o of s)if(o[1])t.add(o[1])}return t}async function we(e,t,n){let r=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=at(i);for(let l of a){let c=await v(l,t,n,o);if(!c)continue;if(!r.has(c))r.add(c),s.push(c)}}catch(i){u.warn(`Error processing ${o}: ${b(i)}`)}}return r}import{isolatedDeclaration as lt}from"oxc-transform";async function Ce(e){let t=new Map;return await Promise.all([...e].map(async(n)=>{try{let r=S(n);if(!await Bun.file(n).exists())return;let o=await Bun.file(n).text(),{code:i}=lt(n,o);if(i)t.set(r,i)}catch(r){u.warn(`Failed to generate declaration for ${n}: ${b(r)}`)}})),t}import Ee from"node:fs/promises";import Z from"node:path";import{isolatedDeclaration as ct}from"oxc-transform";async function $e(e,t){let n=Z.resolve(e),r=Z.resolve(n,t);if(!await Ee.exists(n))throw new h(`Root directory does not exist: ${n}`);if(!await Bun.file(r).exists())throw new h(`Entry file does not exist: ${r}`);if(!M(r))throw new h(`Entry file must be a TypeScript file: ${r}`);if(Z.relative(n,r).startsWith(".."))throw new h(`Entry file must be within rootDir: ${r}`);return{absoluteRootDir:n,absoluteEntry:r}}async function Se(e){let t=!1;if(await Promise.all([...e].map(async(n)=>{try{let r=n.replace(/\.d\.ts$/,".ts"),s=await Bun.file(r).text(),{errors:o}=ct(r,s);for(let i of o){if(!t)console.log(`
|
|
6
6
|
`);let a=i.labels[0],l=a?ut(s,a.start):"",f=`${x(r)}${l}: ${ft(i.message)}`;u.warn(f),t=!0}}catch{}})),t)u.info(`
|
|
7
7
|
You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
|
|
8
8
|
`)}function ut(e,t){if(t===void 0)return"";let n=e.slice(0,t).split(`
|
|
9
|
-
`),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function ft(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function
|
|
9
|
+
`),r=n.length,s=n[n.length-1].length+1;return` (${r}:${s})`}function ft(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,t,n,r,s){let{absoluteEntry:o}=await $e(e,t),i=he(r),a=Q(r),l=await we(o,i,a),c=await Ce(l);return ye(o,c,n,s,i,a)}function U(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function B(e,{warnOnConflict:t=!0}={}){let n=[],r=new Set,s={};function o(i,a){if(r.has(i)){let l=oe(),c=`${i}_${l}`;if(t)u.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
|
${s[i]} -> ${i}.js
|
|
@@ -20,7 +20,7 @@ To fix this, use named entries in your configuration:
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});n.push({name:c,path:a})}else n.push({name:i,path:a}),r.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=U(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=U(e);o(i,e)}return n}function Re(e){return e.filter((t)=>M(t.path))}function Oe(e,t){return`[dir]/${e}${t}`}import{loadConfig as Pe}from"coffi";async function Be(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((n)=>({rootDir:n.root,options:ae(n.config,"name",n.name)})):[{rootDir:t,options:e}]}async function Le(e){let{config:t,filepath:n}=await Pe({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:n}}async function Ae(e,t){let{config:n,filepath:r}=await Pe({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:n,path:r}}var pt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function k(e){return{...pt,...e}}function Ie(e){let{minify:t,minifyWhitespace:n,minifyIdentifiers:r,minifySyntax:s}=e,o=t===!0;return{whitespace:n??o,identifiers:r??o,syntax:s??o}}function Me(e,t){return t==="cjs"?e:void 0}function De(e,t,n,r){return{...typeof n==="object"&&Object.keys(n).reduce((s,o)=>{let i=JSON.stringify(n[o]);return s[`process.env.${o}`]=i,s[`import.meta.env.${o}`]=i,s},{}),...e,...r==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function _e(e,t){return e===void 0?t==="esm":e}function ve(e){return typeof e==="string"?e:void 0}function je(e,t){return{name:"bunup:external-plugin",setup(n){n.onResolve({filter:/.*/},(r)=>{let s=r.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var N={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&K(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
24
24
|
import { dirname } from 'path';
|
|
25
25
|
|
|
26
26
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -30,9 +30,9 @@ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0})
|
|
|
30
30
|
|
|
31
31
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
32
32
|
|
|
33
|
-
`}};var mt=/\.(js|ts|jsx|tsx|mts|cts)$/;function
|
|
34
|
-
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var
|
|
33
|
+
`}};var mt=/\.(js|ts|jsx|tsx|mts|cts)$/;function Ue({format:e,target:t,shims:n}){let s=gt(n).map((o)=>N[o]).filter((o)=>o.appliesTo(e,t));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:mt},async({path:i})=>{let a=await Bun.file(i).text(),l=s.filter((p)=>p.isNeededInFile(a));if(l.length===0)return;let{shebangLine:c,codeContent:f}=dt(a),m=l.map((p)=>p.generateCode()).join("");return{contents:c+m+f}})}}}function gt(e){if(e===!0)return Object.keys(N);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in N)).map(([t])=>t)}function dt(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
|
|
34
|
+
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var T=new Set;async function F(e,t){let n=k(e);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.");if(n.clean)pe(t,n.outDir);L(n.silent);let{packageJson:r,path:s}=await Le(t);if(r&&s)u.cli(`Using package.json: ${x(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let o=B(n.entry),i=r?.type,a=D(n,r),l=_(n);if(!n.dtsOnly){let c=[je(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return ht(n,t,p,m,i,c)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let c=await Ae(t,n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${x(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let f=n.format.filter((p)=>{if(p==="iife"&&!$(i)&&n.format.includes("cjs"))return!1;return!0}),m=typeof n.dts==="object"&&n.dts.entry?B(n.dts.entry):Re(o);try{await Promise.all(m.map(async(p)=>{let G=await Te(t,p.path,n,c,r);await Promise.all(f.map(async(ne)=>{let qe=n.outputExtension?.({format:ne,packageType:i,options:n,entry:p}).dts??ue(ne,i),V=`${t}/${n.outDir}/${p.name}${qe}`;await Bun.write(V,G);let Ge=Bun.file(V).size||0;u.progress("DTS",x(V),J(Ge),n.name)}))}))}catch(p){throw new h(b(p))}}}async function ht(e,t,n,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:n}).js??ce(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Oe(n.name,i)},splitting:_e(e.splitting,r),bytecode:Me(e.bytecode,r),define:De(e.define,e.shims,e.env,r),minify:Ie(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:ve(e.env),plugins:[...o,Ue({format:r,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let l=`${t}/${e.outDir}/${n.name}${i}`,c=Bun.file(l).size||0;u.progress(r.toUpperCase(),x(l),J(c),e.name)}var W="0.4.13";var ke="https://bun.sh/docs/installation",Ne="https://bunup.arshadyaseen.com/#cli-options";function d(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new g(`Option --${e} requires a string value`)}}function ee(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new g(`Option --${e} requires a string value`)}}function xt(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new g(`Option --${e} requires a boolean or string value`)}}function yt(){console.log(`
|
|
35
35
|
Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
|
|
36
|
-
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${
|
|
37
|
-
`),process.exit(0)}function wt(){console.log(W),process.exit(0)}var
|
|
38
|
-
To install Bun, visit ${ke}`)})();import{loadConfig as Et}from"coffi";import q from"node:path";import Ct from"chokidar";async function
|
|
36
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Ne}\x1B[0m
|
|
37
|
+
`),process.exit(0)}function wt(){console.log(W),process.exit(0)}var Fe={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:ee("format")},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:d("minify")},watch:{flags:["w","watch"],handler:d("watch")},dts:{flags:["d","dts"],handler:d("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:ee("external")},sourcemap:{flags:["sm","sourcemap"],handler:xt("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:d("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:d("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:d("minifySyntax")},clean:{flags:["c","clean"],handler:d("clean")},splitting:{flags:["s","splitting"],handler:d("splitting")},noExternal:{flags:["ne","no-external"],handler:ee("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:d("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:d("dtsOnly")},silent:{flags:["silent"],handler:d("silent")},config:{flags:["config"],handler:y("config")},publicPath:{flags:["pp","public-path"],handler:y("publicPath")},env:{flags:["env"],handler:y("env")},shims:{flags:["shims"],handler:d("shims")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new g(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=U(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>yt()},version:{flags:["v","version"],handler:()=>wt()}},H={};for(let e of Object.values(Fe))for(let t of e.flags)H[t]=e.handler;function We(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),l=H[i];if(l)l(o,t,a);else throw new g(`Unknown option: --${s}`)}else{let i=H[s];if(i)i(o,t);else throw new g(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=H[s];if(a)a(i,t);else throw new g(`Unknown option: -${s}`)}else Fe.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new g(`Bunup requires Bun to run.
|
|
38
|
+
To install Bun, visit ${ke}`)})();import{loadConfig as Et}from"coffi";import q from"node:path";import Ct from"chokidar";async function He(e,t){let n=new Set,r=k(e),s=B(r.entry);for(let l of s){let c=q.resolve(t,l.path),f=q.dirname(c);n.add(f)}let o=Ct.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,q.join(t,r.outDir)]}),i=!1,a=async(l=!1)=>{if(i)return;i=!0;try{let c=performance.now();if(await F({...r,entry:s.map((f)=>f.path),clean:!1},t),r.onBuildSuccess?.(),!l)u.cli(`\uD83D\uDCE6 Rebuild finished in ${I(performance.now()-c)}`);await te()}catch(c){Y(c)}finally{i=!1}};o.on("change",(l)=>{let c=q.relative(t,l);u.cli(`File changed: ${c}`,{muted:!0}),a()}),o.on("error",(l)=>{throw new A(`Watcher error: ${b(l)}`)}),await a(!0)}async function $t(e=Bun.argv.slice(2)){let t=We(e);L(t.silent);let n=process.cwd(),{config:r,filepath:s}=await Et({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Be(r,n);if(u.cli(`Using bunup v${W} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${x(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:c,rootDir:f})=>{return le(c).map(async(p)=>{let G={...p,...t};return St(G,f)})}));let a=performance.now()-i,l=I(a);if(u.cli(`\u26A1\uFE0F Build completed in ${l}`),await te(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function te(){if(T.size>0)await Se(T),T.clear()}async function St(e,t){if(e.watch)await He(e,t);else await F(e,t),e.onBuildSuccess?.()}$t().catch((e)=>se(e));export{te as validateDtsFiles,$t as main};
|
package/build/index.d.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
2
|
|
|
3
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/helpers/entry.d.ts
|
|
4
|
+
type ProcessableEntry = {
|
|
5
|
+
name: string
|
|
6
|
+
path: string
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
3
10
|
//#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
|
|
4
11
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
5
12
|
type Define = BunBuildOptions["define"];
|
|
@@ -337,6 +344,27 @@ interface BuildOptions {
|
|
|
337
344
|
* @see https://bun.sh/docs/bundler/plugins for more information about Bun's plugin system
|
|
338
345
|
*/
|
|
339
346
|
bunBuildPlugins?: BunPlugin[];
|
|
347
|
+
/**
|
|
348
|
+
* Customize the output file extension for each format.
|
|
349
|
+
*
|
|
350
|
+
* @param options Contains format, packageType, options, and entry information
|
|
351
|
+
* @returns Object with js and dts extensions (including the leading dot)
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* outputExtension: ({ format, entry }) => ({
|
|
355
|
+
* js: entry.name === 'worker' ? '.worker.js' : `.${format}.js`,
|
|
356
|
+
* dts: `.${format}.d.ts`
|
|
357
|
+
* })
|
|
358
|
+
*/
|
|
359
|
+
outputExtension?: (options: {
|
|
360
|
+
format: Format
|
|
361
|
+
packageType: string | undefined
|
|
362
|
+
options: BuildOptions
|
|
363
|
+
entry: ProcessableEntry
|
|
364
|
+
}) => {
|
|
365
|
+
js: string
|
|
366
|
+
dts: string
|
|
367
|
+
};
|
|
340
368
|
}
|
|
341
369
|
|
|
342
370
|
//#endregion
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
2
|
|
|
3
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/helpers/entry.d.ts
|
|
4
|
+
type ProcessableEntry = {
|
|
5
|
+
name: string
|
|
6
|
+
path: string
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
3
10
|
//#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
|
|
4
11
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
5
12
|
type Define = BunBuildOptions["define"];
|
|
@@ -337,6 +344,27 @@ interface BuildOptions {
|
|
|
337
344
|
* @see https://bun.sh/docs/bundler/plugins for more information about Bun's plugin system
|
|
338
345
|
*/
|
|
339
346
|
bunBuildPlugins?: BunPlugin[];
|
|
347
|
+
/**
|
|
348
|
+
* Customize the output file extension for each format.
|
|
349
|
+
*
|
|
350
|
+
* @param options Contains format, packageType, options, and entry information
|
|
351
|
+
* @returns Object with js and dts extensions (including the leading dot)
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* outputExtension: ({ format, entry }) => ({
|
|
355
|
+
* js: entry.name === 'worker' ? '.worker.js' : `.${format}.js`,
|
|
356
|
+
* dts: `.${format}.d.ts`
|
|
357
|
+
* })
|
|
358
|
+
*/
|
|
359
|
+
outputExtension?: (options: {
|
|
360
|
+
format: Format
|
|
361
|
+
packageType: string | undefined
|
|
362
|
+
options: BuildOptions
|
|
363
|
+
entry: ProcessableEntry
|
|
364
|
+
}) => {
|
|
365
|
+
js: string
|
|
366
|
+
dts: string
|
|
367
|
+
};
|
|
340
368
|
}
|
|
341
369
|
|
|
342
370
|
//#endregion
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Vt=require("node:module");var Nt=Object.create;var{getPrototypeOf:Ut,defineProperty:
|
|
1
|
+
var Vt=require("node:module");var Nt=Object.create;var{getPrototypeOf:Ut,defineProperty:S,getOwnPropertyNames:q,getOwnPropertyDescriptor:Wt}=Object,X=Object.prototype.hasOwnProperty;var h=(t,e,r)=>{r=t!=null?Nt(Ut(t)):{};let n=e||!t||!t.__esModule?S(r,"default",{value:t,enumerable:!0}):r;for(let s of q(t))if(!X.call(n,s))S(n,s,{get:()=>t[s],enumerable:!0});return n},H=new WeakMap,kt=(t)=>{var e=H.get(t),r;if(e)return e;if(e=S({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")q(t).map((n)=>!X.call(e,n)&&S(e,n,{get:()=>t[n],enumerable:!(r=Wt(t,n))||r.enumerable}));return H.set(t,e),e};var Gt=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})};var oe={};Gt(oe,{defineWorkspace:()=>K,defineConfig:()=>Y,build:()=>At});module.exports=kt(oe);function Y(t){return t}function K(t){return t}var mt=require("rolldown"),pt=require("rolldown-plugin-dts");var Q=!1;function Z(t){Q=t??!1}class b{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!b.instance)b.instance=new b;return b.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:e,message:r,size:n,identifier:s,muted:o}){let i=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=o?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),m=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),f=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${u}${m} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${f}`}let c=s?` \x1B[48;5;${t};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${i}${a}${c}`}output(t,e={},r=console.log){if(Q)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(r(t),e.verticalSpace)console.log("")}cli(t,e={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}info(t,e={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}warn(t,e={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.warn)}error(t,e={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.error)}progress(t,e,r,n){let s=String(t),o=this.colors.default,i,a,c={};if(typeof r==="string")i=r,a=n;else if(r)i=r.size,a=r.identifier,c=r;for(let[l,m]of Object.entries(this.colors.progress))if(s.includes(l)){o=m;break}let u=this.formatMessage({colorCode:o,label:s,message:e,size:i,identifier:a,muted:c.muted});this.output(u,c)}}var g=b.getInstance();class A extends Error{constructor(t){super(t);this.name="BunupError"}}class E extends A{constructor(t){super(t);this.name="BunupBuildError"}}class p extends A{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};var _=h(require("node:fs/promises")),z=h(require("node:path"));function j(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function J(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function tt(t,e){switch(t){case"esm":return y(e)?".js":".mjs";case"cjs":return y(e)?".cjs":".js";case"iife":return".global.js"}}function et(t,e){switch(t){case"esm":return y(e)?".d.ts":".d.mts";case"cjs":return y(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function F(t){return t==="node"||t==="bun"}function y(t){return t==="module"}function rt(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function N(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${e[r]}`;return`${(t/1024**r).toFixed(2)} ${e[r]}`}function w(t,e=3){return t.split("/").slice(-e).join("/")}async function nt(t,e){let r=z.default.join(t,e);try{await _.default.rm(r,{recursive:!0,force:!0})}catch(n){throw new E(`Failed to clean output directory: ${n}`)}await _.default.mkdir(r,{recursive:!0})}function T(t){return[".ts",".mts",".cts",".tsx"].some((e)=>t.endsWith(e))}function st(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${j(e)}($|\\/|\\\\)`):e)}function P(t,e){return st(t.external||[]).concat(rt(e).map((r)=>new RegExp(`^${j(r)}($|\\/|\\\\)`)))}function B(t){return st(t.noExternal||[])}var lt=h(require("node:path")),ft=require("oxc-resolver");var x=h(require("node:path"));var C="\x00dts:",it=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(U(n))return n;if(!s||!U(s))return null;let o=await D(n,e,r,$(s));if(!o)return null;let i=R(o);if(t.has(i))return M(i);return null},load(n){if(n.startsWith(C)){let s=$(n),o=t.get(s);if(o)return ot.add(s),o}return null}}};function at(t){return t.tsconfig?.compilerOptions}function R(t){return t.replace(/\.tsx?$/,".d.ts")}function W(t){let e=x.default.dirname(t.path||""),r=at(t);return r?.baseUrl?x.default.resolve(e,r.baseUrl):e}function ut(t){let e=new Map,r=at(t)?.paths;if(!r)return e;let n=W(t);for(let[s,o]of Object.entries(r))if(Array.isArray(o)&&o.length){let i=s.replace(/\*/g,"(.*)"),a=o[0].replace(/\*/g,"$1");e.set(`^${i}$`,x.default.join(n,a))}return e}function vt(t,e,r){for(let[n,s]of e){let o=new RegExp(n),i=t.match(o);if(i)return s.replace("$1",i[1]||"")}return r?x.default.join(r,t):null}async function Ht(t){let e=["",".ts",".tsx",".cts",".mts","/index.ts","/index.tsx","/index.cts","/index.mts"];for(let r of e){let n=`${t}${r}`;if(await Bun.file(n).exists()&&(n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".cts")||n.endsWith(".mts")))return n}return null}function D(t,e,r,n){let s=t.startsWith(".")?x.default.resolve(x.default.dirname(n||""),t):vt(t,e,r);if(!s)return Promise.resolve(null);return Ht(s)}function U(t){return t.startsWith(C)}function $(t){return t.replace(C,"")}function M(t){return`${C}${t}`}var ct;function gt(t){return{name:"bunup:types-resolve",buildStart(){ct||=new ft.ResolverFactory({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,r){let n=r?$(r):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!n?.includes(a);else c=a.test(e)||!!(n&&a.test(n));return c}))return}let s=n?lt.default.dirname(n):process.cwd(),{path:o}=await ct.async(s,e);if(!o)return;if(/[cm]?jsx?$/.test(o)){let i=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(i).exists()?i:void 0}return o}}}async function dt(t,e,r,n,s,o){let i=R(t),a=M(i),c=P(r,n),u=B(r);try{let{output:l}=await mt.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(m,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;f(m)},plugins:[it(e,s,o),typeof r.dts==="object"&&"resolve"in r.dts&>(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),pt.dts({dtsInput:!0})],external:(m)=>c.some((f)=>f.test(m))&&!u.some((f)=>f.test(m))});if(!l[0]?.code)return g.warn(`Generated empty declaration file for entry "${t}"`,{muted:!0}),"";return l[0].code}catch(l){throw new p(`DTS bundling failed for entry "${t}": ${d(l)}`)}}var qt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Xt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Yt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Kt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Qt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Zt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,zt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Jt(t){let e=new Set,r=[qt,Xt,Yt,Kt,Qt,Zt,zt];for(let n of r){let s=t.matchAll(n);for(let o of s)if(o[1])e.add(o[1])}return e}async function xt(t,e,r){let n=new Set([t]),s=[t];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=Jt(i);for(let c of a){let u=await D(c,e,r,o);if(!u)continue;if(!n.has(u))n.add(u),s.push(u)}}catch(i){g.warn(`Error processing ${o}: ${d(i)}`)}}return n}var ht=require("oxc-transform");async function bt(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=R(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:i}=ht.isolatedDeclaration(r,o);if(i)e.set(n,i)}catch(n){g.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}var k=h(require("node:fs/promises")),I=h(require("node:path")),te=require("oxc-transform");async function Et(t,e){let r=I.default.resolve(t),n=I.default.resolve(r,e);if(!await k.default.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new p(`Entry file does not exist: ${n}`);if(!T(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(I.default.relative(r,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function yt(t,e,r,n,s){let{absoluteEntry:o}=await Et(t,e),i=ut(n),a=W(n),c=await xt(o,i,a),u=await bt(c);return dt(o,u,r,s,i,a)}function wt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function G(t,{warnOnConflict:e=!0}={}){let r=[],n=new Set,s={};function o(i,a){if(n.has(i)){let c=J(),u=`${i}_${c}`;if(e)g.warn(`Output name conflict: "${i}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${s[i]} -> ${i}.js
|
|
@@ -12,7 +12,7 @@ To fix this, use named entries in your configuration:
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:u,path:a})}else r.push({name:i,path:a}),n.add(i),s[i]=a}if(Array.isArray(t))for(let i of t){let a=
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:u,path:a})}else r.push({name:i,path:a}),n.add(i),s[i]=a}if(Array.isArray(t))for(let i of t){let a=wt(i);o(a,i)}else if(typeof t==="object")for(let[i,a]of Object.entries(t))o(i,a);else{let i=wt(t);o(i,t)}return r}function Rt(t){return t.filter((e)=>T(e.path))}function St(t,e){return`[dir]/${t}${e}`}var V=require("coffi");async function $t(t){let{config:e,filepath:r}=await V.loadConfig({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:r}}async function Ct(t,e){let{config:r,filepath:n}=await V.loadConfig({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:r,path:n}}var ee={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Tt(t){return{...ee,...t}}function Pt(t){let{minify:e,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:s}=t,o=e===!0;return{whitespace:r??o,identifiers:n??o,syntax:s??o}}function Bt(t,e){return e==="cjs"?t:void 0}function Dt(t,e,r,n){return{...typeof r==="object"&&Object.keys(r).reduce((s,o)=>{let i=JSON.stringify(r[o]);return s[`process.env.${o}`]=i,s[`import.meta.env.${o}`]=i,s},{}),...t,...n==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function Mt(t,e){return t===void 0?e==="esm":t}function It(t){return typeof t==="string"?t:void 0}function Lt(t,e){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let s=n.path;if(t.some((i)=>i.test(s))&&!e.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var L={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&F(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
16
16
|
import { dirname } from 'path';
|
|
17
17
|
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -22,5 +22,5 @@ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0})
|
|
|
22
22
|
|
|
23
23
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
24
24
|
|
|
25
|
-
`}};var re=/\.(js|ts|jsx|tsx|mts|cts)$/;function
|
|
26
|
-
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}var
|
|
25
|
+
`}};var re=/\.(js|ts|jsx|tsx|mts|cts)$/;function Ot({format:t,target:e,shims:r}){let s=ne(r).map((o)=>L[o]).filter((o)=>o.appliesTo(t,e));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:re},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((f)=>f.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:l}=se(a),m=c.map((f)=>f.generateCode()).join("");return{contents:u+m+l}})}}}function ne(t){if(t===!0)return Object.keys(L);if(!t)return[];return Object.entries(t).filter(([e,r])=>r&&(e in L)).map(([e])=>e)}function se(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
|
|
26
|
+
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}var ot=new Set;async function At(t,e){let r=Tt(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)nt(e,r.outDir);Z(r.silent);let{packageJson:n,path:s}=await $t(e);if(n&&s)g.cli(`Using package.json: ${w(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=G(r.entry),i=n?.type,a=P(r,n),c=B(r);if(!r.dtsOnly){let u=[Lt(a,c)],l=r.format.flatMap((m)=>o.map((f)=>{return ie(r,e,f,m,i,u)}));await Promise.all(l)}if(r.dts||r.dtsOnly){let u=await Ct(e,r.preferredTsconfigPath);if(u.path)g.cli(`Using tsconfig: ${w(u.path,2)}`,{muted:!0,identifier:r.name,once:`${u.path}:${r.name}`});let l=r.format.filter((f)=>{if(f==="iife"&&!y(i)&&r.format.includes("cjs"))return!1;return!0}),m=typeof r.dts==="object"&&r.dts.entry?G(r.dts.entry):Rt(o);try{await Promise.all(m.map(async(f)=>{let _t=await yt(e,f.path,r,u,n);await Promise.all(l.map(async(v)=>{let jt=r.outputExtension?.({format:v,packageType:i,options:r,entry:f}).dts??et(v,i),O=`${e}/${r.outDir}/${f.name}${jt}`;await Bun.write(O,_t);let Ft=Bun.file(O).size||0;g.progress("DTS",w(O),N(Ft),r.name)}))}))}catch(f){throw new p(d(f))}}}async function ie(t,e,r,n,s,o){let i=t.outputExtension?.({format:n,packageType:s,options:t,entry:r}).js??tt(n,s),a=await Bun.build({entrypoints:[`${e}/${r.path}`],format:n,naming:{entry:St(r.name,i)},splitting:Mt(t.splitting,n),bytecode:Bt(t.bytecode,n),define:Dt(t.define,t.shims,t.env,n),minify:Pt(t),outdir:`${e}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:It(t.env),plugins:[...o,Ot({format:n,target:t.target,shims:t.shims}),...t.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let l of a.logs){if(l.level==="error")throw new E(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let c=`${e}/${t.outDir}/${r.name}${i}`,u=Bun.file(c).size||0;g.progress(n.toUpperCase(),w(c),N(u),t.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function $t(t){return t}function Ct(t){return t}import{build as It}from"rolldown";import{dts as Lt}from"rolldown-plugin-dts";var W=!1;function k(t){W=t??!1}class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(t){if(!t?.once)return!0;if(this.loggedOnceMessages.has(t.once))return!1;return this.loggedOnceMessages.add(t.once),!0}formatMessage({colorCode:t,label:e,message:r,size:n,identifier:o,muted:i}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-e.length)),a=i?`\x1B[38;5;${this.colors.info}m${r}\x1B[0m`:r;if(n){let[u,...l]=a.split(" "),m=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),f=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${m} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${f}`}let c=o?` \x1B[48;5;${t};38;5;0m ${o} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},r=console.log){if(W)return;if(!this.shouldLog(e))return;if(e.verticalSpace)console.log("");if(r(t),e.verticalSpace)console.log("")}cli(t,e={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}info(t,e={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e)}warn(t,e={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.warn)}error(t,e={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:t,identifier:e.identifier,muted:e.muted});this.output(r,e,console.error)}progress(t,e,r,n){let o=String(t),i=this.colors.default,s,a,c={};if(typeof r==="string")s=r,a=n;else if(r)s=r.size,a=r.identifier,c=r;for(let[l,m]of Object.entries(this.colors.progress))if(o.includes(l)){i=m;break}let u=this.formatMessage({colorCode:i,label:o,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var g=x.getInstance();class I extends Error{constructor(t){super(t);this.name="BunupError"}}class h extends I{constructor(t){super(t);this.name="BunupBuildError"}}class p extends I{constructor(t){super(t);this.name="BunupDTSBuildError"}}var d=(t)=>{if(t instanceof Error)return t.message;return String(t)};import G from"node:fs/promises";import Tt from"node:path";function L(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function v(t,e){switch(t){case"esm":return b(e)?".js":".mjs";case"cjs":return b(e)?".cjs":".js";case"iife":return".global.js"}}function H(t,e){switch(t){case"esm":return b(e)?".d.ts":".d.mts";case"cjs":return b(e)?".d.cts":".d.ts";case"iife":return".d.ts"}}function O(t){return t==="node"||t==="bun"}function b(t){return t==="module"}function q(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function A(t){if(t===0)return"0 B";let e=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${e[r]}`;return`${(t/1024**r).toFixed(2)} ${e[r]}`}function E(t,e=3){return t.split("/").slice(-e).join("/")}async function X(t,e){let r=Tt.join(t,e);try{await G.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await G.mkdir(r,{recursive:!0})}function $(t){return[".ts",".mts",".cts",".tsx"].some((e)=>t.endsWith(e))}function Y(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${L(e)}($|\\/|\\\\)`):e)}function C(t,e){return Y(t.external||[]).concat(q(e).map((r)=>new RegExp(`^${L(r)}($|\\/|\\\\)`)))}function T(t){return Y(t.noExternal||[])}import Dt from"node:path";import{ResolverFactory as Mt}from"oxc-resolver";import w from"node:path";var S="\x00dts:",K=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,o){if(_(n))return n;if(!o||!_(o))return null;let i=await P(n,e,r,R(o));if(!i)return null;let s=y(i);if(t.has(s))return B(s);return null},load(n){if(n.startsWith(S)){let o=R(n),i=t.get(o);if(i)return Q.add(o),i}return null}}};function Z(t){return t.tsconfig?.compilerOptions}function y(t){return t.replace(/\.tsx?$/,".d.ts")}function j(t){let e=w.dirname(t.path||""),r=Z(t);return r?.baseUrl?w.resolve(e,r.baseUrl):e}function z(t){let e=new Map,r=Z(t)?.paths;if(!r)return e;let n=j(t);for(let[o,i]of Object.entries(r))if(Array.isArray(i)&&i.length){let s=o.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");e.set(`^${s}$`,w.join(n,a))}return e}function Pt(t,e,r){for(let[n,o]of e){let i=new RegExp(n),s=t.match(i);if(s)return o.replace("$1",s[1]||"")}return r?w.join(r,t):null}async function Bt(t){let e=["",".ts",".tsx",".cts",".mts","/index.ts","/index.tsx","/index.cts","/index.mts"];for(let r of e){let n=`${t}${r}`;if(await Bun.file(n).exists()&&(n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".cts")||n.endsWith(".mts")))return n}return null}function P(t,e,r,n){let o=t.startsWith(".")?w.resolve(w.dirname(n||""),t):Pt(t,e,r);if(!o)return Promise.resolve(null);return Bt(o)}function _(t){return t.startsWith(S)}function R(t){return t.replace(S,"")}function B(t){return`${S}${t}`}var J;function tt(t){return{name:"bunup:types-resolve",buildStart(){J||=new Mt({mainFields:["types"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".ts",".d.cts",".d.mts",".cts",".mts"],modules:["node_modules","node_modules/@types"]})},async resolveId(e,r){let n=r?R(r):void 0;if(/\0/.test(e))return;if(t){if(!t.some((a)=>{let c=!1;if(typeof a==="string")c=a===e||!!n?.includes(a);else c=a.test(e)||!!(n&&a.test(n));return c}))return}let o=n?Dt.dirname(n):process.cwd(),{path:i}=await J.async(o,e);if(!i)return;if(/[cm]?jsx?$/.test(i)){let s=i.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return i}}}async function et(t,e,r,n,o,i){let s=y(t),a=B(s),c=C(r,n),u=T(r);try{let{output:l}=await It({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(m,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;f(m)},plugins:[K(e,o,i),typeof r.dts==="object"&&"resolve"in r.dts&&tt(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),Lt({dtsInput:!0})],external:(m)=>c.some((f)=>f.test(m))&&!u.some((f)=>f.test(m))});if(!l[0]?.code)return g.warn(`Generated empty declaration file for entry "${t}"`,{muted:!0}),"";return l[0].code}catch(l){throw new p(`DTS bundling failed for entry "${t}": ${d(l)}`)}}var Ot=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,At=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,_t=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,jt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ft=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Nt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ut=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Wt(t){let e=new Set,r=[Ot,At,_t,jt,Ft,Nt,Ut];for(let n of r){let o=t.matchAll(n);for(let i of o)if(i[1])e.add(i[1])}return e}async function rt(t,e,r){let n=new Set([t]),o=[t];while(o.length){let i=o.pop();if(!i)continue;try{let s=await Bun.file(i).text(),a=Wt(s);for(let c of a){let u=await P(c,e,r,i);if(!u)continue;if(!n.has(u))n.add(u),o.push(u)}}catch(s){g.warn(`Error processing ${i}: ${d(s)}`)}}return n}import{isolatedDeclaration as kt}from"oxc-transform";async function nt(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=y(r);if(!await Bun.file(r).exists())return;let i=await Bun.file(r).text(),{code:s}=kt(r,i);if(s)e.set(n,s)}catch(n){g.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}import st from"node:fs/promises";import F from"node:path";import{isolatedDeclaration as _e}from"oxc-transform";async function it(t,e){let r=F.resolve(t),n=F.resolve(r,e);if(!await st.exists(r))throw new p(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new p(`Entry file does not exist: ${n}`);if(!$(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(F.relative(r,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function ot(t,e,r,n,o){let{absoluteEntry:i}=await it(t,e),s=z(n),a=j(n),c=await rt(i,s,a),u=await nt(c);return et(i,u,r,o,s,a)}function at(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function N(t,{warnOnConflict:e=!0}={}){let r=[],n=new Set,o={};function i(s,a){if(n.has(s)){let c=V(),u=`${s}_${c}`;if(e)g.warn(`Output name conflict: "${s}" is used by multiple files.
|
|
2
2
|
Bunup uses filenames without extensions as output names by default.
|
|
3
3
|
|
|
4
4
|
${o[s]} -> ${s}.js
|
|
@@ -12,7 +12,7 @@ To fix this, use named entries in your configuration:
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:u,path:a})}else r.push({name:s,path:a}),n.add(s),o[s]=a}if(Array.isArray(t))for(let s of t){let a=
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:u,path:a})}else r.push({name:s,path:a}),n.add(s),o[s]=a}if(Array.isArray(t))for(let s of t){let a=at(s);i(a,s)}else if(typeof t==="object")for(let[s,a]of Object.entries(t))i(s,a);else{let s=at(t);i(s,t)}return r}function ut(t){return t.filter((e)=>$(e.path))}function ct(t,e){return`[dir]/${t}${e}`}import{loadConfig as lt}from"coffi";async function ft(t){let{config:e,filepath:r}=await lt({name:"package",cwd:t,extensions:[".json"],maxDepth:1});return{packageJson:e,path:r}}async function gt(t,e){let{config:r,filepath:n}=await lt({name:"tsconfig",cwd:t,extensions:[".json"],preferredPath:e,maxDepth:3});return{tsconfig:r,path:n}}var Gt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function mt(t){return{...Gt,...t}}function pt(t){let{minify:e,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:o}=t,i=e===!0;return{whitespace:r??i,identifiers:n??i,syntax:o??i}}function dt(t,e){return e==="cjs"?t:void 0}function xt(t,e,r,n){return{...typeof r==="object"&&Object.keys(r).reduce((o,i)=>{let s=JSON.stringify(r[i]);return o[`process.env.${i}`]=s,o[`import.meta.env.${i}`]=s,o},{}),...t,...n==="cjs"&&(e===!0||typeof e==="object"&&e.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function ht(t,e){return t===void 0?e==="esm":t}function bt(t){return typeof t==="string"?t:void 0}function Et(t,e){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let o=n.path;if(t.some((s)=>s.test(o))&&!e.some((s)=>s.test(o)))return{path:o,external:!0};return null})}}}var D={dirnameFilename:{appliesTo:(t,e)=>t==="esm"&&O(e),isNeededInFile:(t)=>/\b__dirname\b/.test(t)||/\b__filename\b/.test(t),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
16
16
|
import { dirname } from 'path';
|
|
17
17
|
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -23,4 +23,4 @@ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0})
|
|
|
23
23
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
24
24
|
|
|
25
25
|
`}};var Vt=/\.(js|ts|jsx|tsx|mts|cts)$/;function yt({format:t,target:e,shims:r}){let o=vt(r).map((i)=>D[i]).filter((i)=>i.appliesTo(t,e));if(o.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(i){i.onLoad({filter:Vt},async({path:s})=>{let a=await Bun.file(s).text(),c=o.filter((f)=>f.isNeededInFile(a));if(c.length===0)return;let{shebangLine:u,codeContent:l}=Ht(a),m=c.map((f)=>f.generateCode()).join("");return{contents:u+m+l}})}}}function vt(t){if(t===!0)return Object.keys(D);if(!t)return[];return Object.entries(t).filter(([e,r])=>r&&(e in D)).map(([e])=>e)}function Ht(t){if(!t.startsWith("#!"))return{shebangLine:"",codeContent:t};let e=t.indexOf(`
|
|
26
|
-
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}var
|
|
26
|
+
`);return e===-1?{shebangLine:"",codeContent:t}:{shebangLine:t.slice(0,e+1),codeContent:t.slice(e+1)}}var Q=new Set;async function qt(t,e){let r=mt(t);if(!r.entry||r.entry.length===0||!r.outDir)throw new h("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)X(e,r.outDir);k(r.silent);let{packageJson:n,path:o}=await ft(e);if(n&&o)g.cli(`Using package.json: ${E(o,2)}`,{muted:!0,identifier:r.name,once:`${o}:${r.name}`});let i=N(r.entry),s=n?.type,a=C(r,n),c=T(r);if(!r.dtsOnly){let u=[Et(a,c)],l=r.format.flatMap((m)=>i.map((f)=>{return Xt(r,e,f,m,s,u)}));await Promise.all(l)}if(r.dts||r.dtsOnly){let u=await gt(e,r.preferredTsconfigPath);if(u.path)g.cli(`Using tsconfig: ${E(u.path,2)}`,{muted:!0,identifier:r.name,once:`${u.path}:${r.name}`});let l=r.format.filter((f)=>{if(f==="iife"&&!b(s)&&r.format.includes("cjs"))return!1;return!0}),m=typeof r.dts==="object"&&r.dts.entry?N(r.dts.entry):ut(i);try{await Promise.all(m.map(async(f)=>{let wt=await ot(e,f.path,r,u,n);await Promise.all(l.map(async(U)=>{let Rt=r.outputExtension?.({format:U,packageType:s,options:r,entry:f}).dts??H(U,s),M=`${e}/${r.outDir}/${f.name}${Rt}`;await Bun.write(M,wt);let St=Bun.file(M).size||0;g.progress("DTS",E(M),A(St),r.name)}))}))}catch(f){throw new p(d(f))}}}async function Xt(t,e,r,n,o,i){let s=t.outputExtension?.({format:n,packageType:o,options:t,entry:r}).js??v(n,o),a=await Bun.build({entrypoints:[`${e}/${r.path}`],format:n,naming:{entry:ct(r.name,s)},splitting:ht(t.splitting,n),bytecode:dt(t.bytecode,n),define:xt(t.define,t.shims,t.env,n),minify:pt(t),outdir:`${e}/${t.outDir}`,target:t.target,sourcemap:t.sourcemap,loader:t.loader,drop:t.drop,banner:t.banner,footer:t.footer,publicPath:t.publicPath,env:bt(t.env),plugins:[...i,yt({format:n,target:t.target,shims:t.shims}),...t.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let l of a.logs){if(l.level==="error")throw new h(l.message);if(l.level==="warning")g.warn(l.message);else if(l.level==="info")g.info(l.message)}let c=`${e}/${t.outDir}/${r.name}${s}`,u=Bun.file(c).size||0;g.progress(n.toUpperCase(),E(c),A(u),t.name)}export{Ct as defineWorkspace,$t as defineConfig,qt as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
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",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"bunup": "^0.4.11",
|
|
21
21
|
"husky": "^9.1.7",
|
|
22
22
|
"typescript": "^5.8.3",
|
|
23
|
-
"create-bunup": "0.4.
|
|
23
|
+
"create-bunup": "0.4.13"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"typescript": ">=4.5.0"
|