bunup 0.4.19 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.mjs +14 -14
- package/build/index.js +8 -8
- package/build/index.mjs +8 -8
- package/package.json +4 -4
package/build/cli.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{build as
|
|
4
|
-
`),o.logSolution(
|
|
5
|
-
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/
|
|
6
|
-
`);let a=i.labels[0],
|
|
3
|
+
import{build as nt}from"rolldown";import{dts as st}from"rolldown-plugin-dts";var se=!1;function B(e){se=e??!1}class R{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;MAX_MESSAGE_LENGTH=25;colors={cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!R.instance)R.instance=new R;return R.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(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:r,size:n,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${r}\x1B[0m`:r;if(n){let[l,...f]=a.split(" "),d=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),p=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${l}${d} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${f.join(" ")}${p}`}let c=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${c}`}output(e,t={},r=console.log){if(se)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let s=String(e),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[f,d]of Object.entries(this.colors.progress))if(s.includes(f)){o=d;break}let l=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:c.muted});this.output(l,c)}}var u=R.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 m extends E{constructor(e){super(e);this.name="BunupCLIError"}}class L extends E{constructor(e){super(e);this.name="BunupWatchError"}}var b=(e)=>{if(e instanceof Error)return e.message;return String(e)},Xe=[{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")}}],X=(e,t)=>{let r=b(e),n=t?`[${t}] `:"",s="ERROR";if(e instanceof w)s="BUILD ERROR";else if(e instanceof h)s="DTS ERROR";else if(e instanceof m)s="CLI ERROR";else if(e instanceof L)s="WATCH ERROR";else if(e instanceof E)s="BUNUP ERROR";let o=Xe.find((i)=>i.pattern.test(r)&&(i.errorType===s||!i.errorType));if(!o)console.error(`\x1B[31m${s}\x1B[0m ${n}${r}`);if(o)console.log(`
|
|
4
|
+
`),o.logSolution(r),console.log(`
|
|
5
|
+
`);else console.error("\x1B[90mIf you think this is a bug, please open an issue at: \x1B[36mhttps://github.com/arshad-yaseen/bunup/issues/new\x1B[0m")},ie=(e,t)=>{X(e,t),process.exit(1)};import oe from"node:fs/promises";import Ye from"node:path";function Y(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ae(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function le(e,t,r){return Array.isArray(e)?e.map((n)=>({...n,[t]:r})):{...e,[t]:r}}function ce(e){return Array.isArray(e)?e:[e]}function ue(e,t){switch(e){case"esm":return $(t)?".js":".mjs";case"cjs":return $(t)?".cjs":".js";case"iife":return".global.js"}}function fe(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 J(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 pe(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function K(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function x(e,t=3){return e.split("/").slice(-t).join("/")}async function de(e,t){let r=Ye.join(e,t);try{await oe.rm(r,{recursive:!0,force:!0})}catch(n){throw new w(`Failed to clean output directory: ${n}`)}await oe.mkdir(r,{recursive:!0})}function D(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function me(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${Y(t)}($|\\/|\\\\)`):t)}function A(e,t){return me(e.external||[]).concat(pe(t).map((r)=>new RegExp(`^${Y(r)}($|\\/|\\\\)`)))}function M(e){return me(e.noExternal||[])}import tt from"node:path";import{ResolverFactory as rt}from"oxc-resolver";import ge from"node:fs";import C from"node:path";class he{patternRegexes=new Map;getOrCreatePatternRegex(e){let t=this.patternRegexes.get(e);if(!t){let r=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"(.*)");t=new RegExp(`^${r}$`),this.patternRegexes.set(e,t)}return t}clear(){this.patternRegexes.clear()}}var Je=new he;function j(e){let{path:t,importer:r,tsconfig:n,rootDir:s}=e;if(!n)return null;let o=Ke(n,s);return ze(t,r,o)||null}function Ke(e,t){let r=e.compilerOptions||{},n=r.baseUrl?C.resolve(t,r.baseUrl):t,s=[".ts",".tsx",".d.ts"];if(r.allowJs)s.push(".js",".jsx");if(r.resolveJsonModule)s.push(".json");return{baseUrl:n,paths:r.paths||{},extensions:s,rootDir:t}}function ze(e,t,r){if(Object.keys(r.paths).length>0){let n=Ze(e,r);if(n)return n}if(Qe(e)){let n=C.dirname(t);return _(C.resolve(n,e),r)}if(C.isAbsolute(e))return _(e,r);if(r.baseUrl){let n=C.join(r.baseUrl,e);return _(n,r)}return null}function Qe(e){return e.startsWith("./")||e.startsWith("../")||e==="."}function Ze(e,t){let{paths:r,baseUrl:n}=t;for(let[s,o]of Object.entries(r)){if(!Array.isArray(o)||!o.length)continue;let a=Je.getOrCreatePatternRegex(s).exec(e);if(!a)continue;let c=s.includes("*")?a[1]:"";for(let l of o){let f=l.replace("*",c),d=_(C.resolve(n,f),t);if(d)return d}}return null}function _(e,t){if(z(e))return e;let{extensions:r}=t;for(let n of r){let s=`${e}${n}`;if(z(s))return s}if(et(e))for(let n of r){let s=C.join(e,`index${n}`);if(z(s))return s}return null}function z(e){try{return ge.statSync(e).isFile()}catch{return!1}}function et(e){try{return ge.statSync(e).isDirectory()}catch{return!1}}var v="\x00dts:",be=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(Q(n))return n;if(!s||!Q(s))return null;let o=t.tsconfig?j({path:n,importer:S(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!o)return null;let i=P(o);if(e.has(i))return U(i);return null},load(n){if(n.startsWith(v)){let s=S(n),o=e.get(s);if(o)return T.add(s),o}return null}}};function P(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function Q(e){return e.startsWith(v)}function S(e){return e.replace(v,"")}function U(e){return`${v}${e}`}var xe;function ye(e){return{name:"bunup:types-resolve",buildStart(){xe||=new rt({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?S(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?tt.dirname(n):process.cwd(),{path:o}=await xe.async(s,t);return o}}}async function we(e,t,r,n,s,o){let i=P(e),a=U(i),c=A(r,n),l=M(r);try{let{output:f}=await nt({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(d,p){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(d.code??""))return;p(d)},plugins:[be(t,s,o),typeof r.dts==="object"&&"resolve"in r.dts&&ye(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),st({dtsInput:!0,emitDtsOnly:!0})],external:(d)=>c.some((p)=>p.test(d))&&!l.some((p)=>p.test(d))});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 it=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,ot=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,at=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,lt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ct=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ut=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ft=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function pt(e){let t=new Set,r=[it,ot,at,lt,ct,ut,ft];for(let n of r){let s=e.matchAll(n);for(let o of s)if(o[1])t.add(o[1])}return t}async function Ce(e,t,r){let n=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=pt(i);for(let c of a){let l=t.tsconfig?j({path:c,importer:o,tsconfig:t.tsconfig,rootDir:r}):null;if(!l)continue;if(!n.has(l))n.add(l),s.push(l)}}catch(i){u.warn(`Error processing ${o}: ${b(i)}`)}}return n}import{isolatedDeclaration as dt}from"oxc-transform";async function Re(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=P(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:i}=dt(r,o);if(i)t.set(n,i)}catch(n){u.warn(`Failed to generate declaration for ${r}: ${b(n)}`)}})),t}import Ee from"node:fs/promises";import Z from"node:path";import{isolatedDeclaration as mt}from"oxc-transform";async function $e(e,t){let r=Z.resolve(e),n=Z.resolve(r,t);if(!await Ee.exists(r))throw new h(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new h(`Entry file does not exist: ${n}`);if(!D(n))throw new h(`Entry file must be a TypeScript file: ${n}`);if(Z.relative(r,n).startsWith(".."))throw new h(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function Pe(e){let t=!1;if(await Promise.all([...e].map(async(r)=>{try{let n=r.replace(/\.d\.ts$/,".ts"),s=await Bun.file(n).text(),{errors:o}=mt(n,s);for(let i of o){if(!t)console.log(`
|
|
6
|
+
`);let a=i.labels[0],c=a?gt(s,a.start):"",f=`${x(n)}${c}: ${ht(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
|
-
`)}function
|
|
9
|
-
`),r
|
|
8
|
+
`)}function gt(e,t){if(t===void 0)return"";let r=e.slice(0,t).split(`
|
|
9
|
+
`),n=r.length,s=r[r.length-1].length+1;return` (${n}:${s})`}function ht(e){return e.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function Te(e,t,r,n,s){let{absoluteEntry:o}=await $e(e,t),i=await Ce(o,n,e),a=await Re(i);return we(o,a,r,s,n,e)}function k(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function O(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,s={};function o(i,a){if(n.has(i)){let c=ae(),l=`${i}_${c}`;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
|
|
13
|
-
${a} -> ${
|
|
13
|
+
${a} -> ${l}.js (auto-renamed to avoid conflict)
|
|
14
14
|
|
|
15
15
|
To fix this, use named entries in your configuration:
|
|
16
16
|
{
|
|
@@ -20,19 +20,19 @@ 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});
|
|
23
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:l,path:a})}else r.push({name:i,path:a}),n.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=k(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=k(e);o(i,e)}return r}function Se(e){return e.filter((t)=>D(t.path))}function ve(e,t){return`[dir]/${e}${t}`}import{loadConfig as Oe}from"coffi";async function Be(e,t){return Array.isArray(e)&&"root"in e[0]?e.map((r)=>({rootDir:r.root,options:le(r.config,"name",r.name)})):[{rootDir:t,options:e}]}async function Le(e){let{config:t,filepath:r}=await Oe({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:r}}async function Ie(e,t){let{config:r,filepath:n}=await Oe({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:r,path:n}}var bt={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function F(e){return{...bt,...e}}function De(e){let{minify:t,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:s}=e,o=t===!0;return{whitespace:r??o,identifiers:n??o,syntax:s??o}}function Ae(e,t){return t==="cjs"?e:void 0}function Me(e,t,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},{}),...e,...n==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function _e(e,t){return e===void 0?t==="esm":e}function je(e){return typeof e==="string"?e:void 0}function Ue(e,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let s=n.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var xt=/\.(js|ts|jsx|tsx|mts|cts)$/,ee={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&J(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);
|
|
27
27
|
const __dirname = dirname(__filename);
|
|
28
28
|
|
|
29
|
-
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&
|
|
29
|
+
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&J(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
30
30
|
|
|
31
31
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
32
32
|
|
|
33
|
-
`}};function
|
|
34
|
-
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var
|
|
33
|
+
`}};function ke({format:e,target:t,shims:r}){let s=yt(r).map((o)=>ee[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:xt},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((p)=>p.isNeededInFile(a));if(c.length===0)return;let{shebangLine:l,codeContent:f}=wt(a),d=c.map((p)=>p.generateCode()).join("");return{contents:l+d+f}})}}}function yt(e){if(e===!0)return Object.keys(ee);if(!e)return[];return Object.entries(e).filter(([t,r])=>r&&(t in ee)).map(([t])=>t)}function wt(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 N(e,t){let r=F(e);if(!r.entry||r.entry.length===0||!r.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)de(t,r.outDir);B(r.silent);let{packageJson:n,path:s}=await Le(t);if(n&&s)u.cli(`Using package.json: ${x(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=O(r.entry),i=n?.type,a=A(r,n),c=M(r);if(!r.dtsOnly){let l=[Ue(a,c)],f=r.format.flatMap((d)=>o.map((p)=>{return Ct(r,t,p,d,i,l)}));await Promise.all(f)}if(r.dts||r.dtsOnly){let l=await Ie(t,r.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${x(l.path,2)}`,{muted:!0,identifier:r.name,once:`${l.path}:${r.name}`});let f=r.format.filter((p)=>{if(p==="iife"&&!$(i)&&r.format.includes("cjs"))return!1;return!0}),d=typeof r.dts==="object"&&r.dts.entry?O(r.dts.entry):Se(o);try{await Promise.all(d.map(async(p)=>{let V=await Te(t,p.path,r,l,n);await Promise.all(f.map(async(ne)=>{let Ve=r.outputExtension?.({format:ne,packageType:i,options:r,entry:p}).dts??fe(ne,i),G=`${t}/${r.outDir}/${p.name}${Ve}`;await Bun.write(G,V);let Ge=Bun.file(G).size||0;u.progress("DTS",x(G),K(Ge),r.name)}))}))}catch(p){throw new h(b(p))}}}async function Ct(e,t,r,n,s,o){let i=e.outputExtension?.({format:n,packageType:s,options:e,entry:r}).js??ue(n,s),a=await Bun.build({entrypoints:[`${t}/${r.path}`],format:n,naming:{entry:ve(r.name,i)},splitting:_e(e.splitting,n),bytecode:Ae(e.bytecode,n),define:Me(e.define,e.shims,e.env,n),minify:De(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:je(e.env),plugins:[...o,ke({format:n,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 c=`${t}/${e.outDir}/${r.name}${i}`,l=Bun.file(c).size||0;u.progress(n.toUpperCase(),x(c),K(l),e.name)}var W="0.4.21";var Fe="https://bun.sh/docs/installation",Ne="https://bunup.arshadyaseen.com/#cli-options";function g(e){return(t,r)=>{r[e]=t===!0||t==="true"}}function y(e){return(t,r)=>{if(typeof t==="string")r[e]=t;else throw new m(`Option --${e} requires a string value`)}}function te(e){return(t,r)=>{if(typeof t==="string")r[e]=t.split(",");else throw new m(`Option --${e} requires a string value`)}}function Et(e){return(t,r)=>{if(typeof t==="boolean")r[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")r[e]=t.toLowerCase()==="true";else r[e]=t;else throw new m(`Option --${e} requires a boolean or string value`)}}function $t(){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
|
|
38
|
-
To install Bun, visit ${
|
|
36
|
+
`),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Ne}\x1B[0m
|
|
37
|
+
`),process.exit(0)}function Pt(){console.log(W),process.exit(0)}var We={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:te("format")},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:g("minify")},watch:{flags:["w","watch"],handler:g("watch")},dts:{flags:["d","dts"],handler:g("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:te("external")},sourcemap:{flags:["sm","sourcemap"],handler:Et("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:g("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:g("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:g("minifySyntax")},clean:{flags:["c","clean"],handler:g("clean")},splitting:{flags:["s","splitting"],handler:g("splitting")},noExternal:{flags:["ne","no-external"],handler:te("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:g("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:g("dtsOnly")},silent:{flags:["silent"],handler:g("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:g("shims")},entry:{flags:["entry"],handler:(e,t,r)=>{if(typeof e!=="string")throw new m(`Entry${r?` --entry.${r}`:""} requires a string value`);let n=t.entry||{};if(r){if(n[r])u.warn(`Duplicate entry name '${r}' provided via --entry.${r}. Overwriting previous entry.`);n[r]=e}else{let s=k(e);if(n[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);n[s]=e}t.entry=n}},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:()=>$t()},version:{flags:["v","version"],handler:()=>Pt()}},H={};for(let e of Object.values(We))for(let t of e.flags)H[t]=e.handler;function He(e){let t={};for(let r=0;r<e.length;r++){let n=e[r];if(n.startsWith("--")){let s,o;if(n.includes("=")){let[i,a]=n.slice(2).split("=",2);s=i,o=a}else{s=n.slice(2);let i=e[r+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")r++}if(s.includes(".")){let[i,a]=s.split(".",2),c=H[i];if(c)c(o,t,a);else throw new m(`Unknown option: --${s}`)}else{let i=H[s];if(i)i(o,t);else throw new m(`Unknown option: --${s}`)}}else if(n.startsWith("-")){let s=n.slice(1),o=e[r+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")r++;let a=H[s];if(a)a(i,t);else throw new m(`Unknown option: -${s}`)}else We.entry.handler(n,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new m(`Bunup requires Bun to run.
|
|
38
|
+
To install Bun, visit ${Fe}`)})();import{loadConfig as St}from"coffi";import q from"node:path";import Tt from"chokidar";async function qe(e,t){let r=new Set,n=F(e),s=O(n.entry);for(let c of s){let l=q.resolve(t,c.path),f=q.dirname(l);r.add(f)}let o=Tt.watch(Array.from(r),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,q.join(t,n.outDir)]}),i=!1,a=async(c=!1)=>{if(i)return;i=!0;try{let l=performance.now();if(await N({...n,entry:s.map((f)=>f.path),clean:!1},t),n.onBuildSuccess?.(),!c)u.cli(`\uD83D\uDCE6 Rebuild finished in ${I(performance.now()-l)}`);await re()}catch(l){X(l)}finally{i=!1}};o.on("change",(c)=>{let l=q.relative(t,c);u.cli(`File changed: ${l}`,{muted:!0,once:l}),a()}),o.on("error",(c)=>{throw new L(`Watcher error: ${b(c)}`)}),await a(!0)}async function vt(e=Bun.argv.slice(2)){let t=He(e);B(t.silent);let r=process.cwd(),{config:n,filepath:s}=await St({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!n?[{rootDir:r,options:t}]:await Be(n,r);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:l,rootDir:f})=>{return ce(l).map(async(p)=>{let V={...p,...t};return Ot(V,f)})}));let a=performance.now()-i,c=I(a);if(u.cli(`\u26A1\uFE0F Build completed in ${c}`),await re(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(!t.watch)process.exit(0)}async function re(){if(T.size>0)await Pe(T),T.clear()}async function Ot(e,t){if(e.watch)await qe(e,t);else await N(e,t),e.onBuildSuccess?.()}vt().catch((e)=>ie(e));export{re as validateDtsFiles,vt as main};
|
package/build/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
var Ut=require("node:module");var _t=Object.create;var{getPrototypeOf:jt,defineProperty:w,getOwnPropertyNames:G,getOwnPropertyDescriptor:Nt}=Object,q=Object.prototype.hasOwnProperty;var R=(t,e,r)=>{r=t!=null?_t(jt(t)):{};let n=e||!t||!t.__esModule?w(r,"default",{value:t,enumerable:!0}):r;for(let i of G(t))if(!q.call(n,i))w(n,i,{get:()=>t[i],enumerable:!0});return n},V=new WeakMap,Ft=(t)=>{var e=V.get(t),r;if(e)return e;if(e=w({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")G(t).map((n)=>!q.call(e,n)&&w(e,n,{get:()=>t[n],enumerable:!(r=Nt(t,n))||r.enumerable}));return V.set(t,e),e};var Wt=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})};var ee={};Wt(ee,{defineWorkspace:()=>H,defineConfig:()=>X,build:()=>It});module.exports=Ft(ee);function X(t){return t}function H(t){return t}var ct=require("rolldown"),lt=require("rolldown-plugin-dts");var K=!1;function Y(t){K=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:i,muted:o}){let s=" ".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(" "),g=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-u.length)),f=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${u}${g} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${l.join(" ")}${f}`}let c=i?` \x1B[48;5;${t};38;5;0m ${i} \x1B[0m`:"";return`\x1B[38;5;${t}m${e}\x1B[0m ${s}${a}${c}`}output(t,e={},r=console.log){if(K)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 i=String(t),o=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,g]of Object.entries(this.colors.progress))if(i.includes(l)){o=g;break}let u=this.formatMessage({colorCode:o,label:i,message:e,size:s,identifier:a,muted:c.muted});this.output(u,c)}}var m=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)};var M=R(require("node:fs/promises")),v=R(require("node:path"));function O(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(t=8){let e="";while(e.length<t)e+=Math.random().toString(36).substring(2);return e.substring(0,t)}function Z(t,e){switch(t){case"esm":return b(e)?".js":".mjs";case"cjs":return b(e)?".cjs":".js";case"iife":return".global.js"}}function z(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 A(t){return t==="node"||t==="bun"}function b(t){return t==="module"}function J(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function _(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 y(t,e=3){return t.split("/").slice(-e).join("/")}async function tt(t,e){let r=v.default.join(t,e);try{await M.default.rm(r,{recursive:!0,force:!0})}catch(n){throw new h(`Failed to clean output directory: ${n}`)}await M.default.mkdir(r,{recursive:!0})}function $(t){return[".ts",".mts",".cts",".tsx"].some((e)=>t.endsWith(e))}function et(t){return t.map((e)=>typeof e==="string"?new RegExp(`^${O(e)}($|\\/|\\\\)`):e)}function T(t,e){return et(t.external||[]).concat(J(e).map((r)=>new RegExp(`^${O(r)}($|\\/|\\\\)`)))}function P(t){return et(t.noExternal||[])}var ot=R(require("node:path")),at=require("oxc-resolver");var rt=require("ts-import-resolver");var S="\x00dts:",nt=(t,e,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,i){if(j(n))return n;if(!i||!j(i))return null;let o=rt.resolveTypeScriptImportPath({path:n,importer:C(i),tsconfig:e.tsconfig,rootDir:r});if(!o)return null;let s=E(o);if(t.has(s))return B(s);return null},load(n){if(n.startsWith(S)){let i=C(n),o=t.get(i);if(o)return st.add(i),o}return null}}};function E(t){if(t.endsWith(".d.ts")||t.endsWith(".d.mts")||t.endsWith(".d.cts"))return t;return t.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function j(t){return t.startsWith(S)}function C(t){return t.replace(S,"")}function B(t){return`${S}${t}`}var it;function ut(t){return{name:"bunup:types-resolve",buildStart(){it||=new at.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?C(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 i=n?ot.default.dirname(n):process.cwd(),{path:o}=await it.async(i,e);if(!o)return;if(/[cm]?jsx?$/.test(o)){let s=o.replace(/\.([cm]?)jsx?$/,".d.$1ts");return await Bun.file(s).exists()?s:void 0}return o}}}async function ft(t,e,r,n,i,o){let s=E(t),a=B(s),c=T(r,n),u=P(r);try{let{output:l}=await ct.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(g,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(g.code??""))return;f(g)},plugins:[nt(e,i,o),typeof r.dts==="object"&&"resolve"in r.dts&&ut(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),lt.dts({dtsInput:!0,emitDtsOnly:!0})],external:(g)=>c.some((f)=>f.test(g))&&!u.some((f)=>f.test(g))});if(!l[0]?.code)return m.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 mt=require("ts-import-resolver");var kt=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Vt=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Gt=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,qt=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Xt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ht=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Kt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function Yt(t){let e=new Set,r=[kt,Vt,Gt,qt,Xt,Ht,Kt];for(let n of r){let i=t.matchAll(n);for(let o of i)if(o[1])e.add(o[1])}return e}async function gt(t,e,r){let n=new Set([t]),i=[t];while(i.length){let o=i.pop();if(!o)continue;try{let s=await Bun.file(o).text(),a=Yt(s);for(let c of a){let u=mt.resolveTypeScriptImportPath({path:c,importer:o,tsconfig:e.tsconfig,rootDir:r});if(!u)continue;if(!n.has(u))n.add(u),i.push(u)}}catch(s){m.warn(`Error processing ${o}: ${d(s)}`)}}return n}var pt=require("oxc-transform");async function dt(t){let e=new Map;return await Promise.all([...t].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:s}=pt.isolatedDeclaration(r,o);if(s)e.set(n,s)}catch(n){m.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),e}var N=R(require("node:fs/promises")),D=R(require("node:path")),vt=require("oxc-transform");async function xt(t,e){let r=D.default.resolve(t),n=D.default.resolve(r,e);if(!await N.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(!$(n))throw new p(`Entry file must be a TypeScript file: ${n}`);if(D.default.relative(r,n).startsWith(".."))throw new p(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function ht(t,e,r,n,i){let{absoluteEntry:o}=await xt(t,e),s=await gt(o,n,t),a=await dt(s);return ft(o,a,r,i,n,t)}function bt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function F(t,{warnOnConflict:e=!0}={}){let r=[],n=new Set,i={};function o(s,a){if(n.has(s)){let c=Q(),u=`${s}_${c}`;if(e)m.warn(`Output name conflict: "${s}" is used by multiple files.
|
|
1
|
+
var Ge=require("node:module");var Ue=Object.create;var{getPrototypeOf:We,defineProperty:C,getOwnPropertyNames:K,getOwnPropertyDescriptor:Ne}=Object,Y=Object.prototype.hasOwnProperty;var h=(e,t,r)=>{r=e!=null?Ue(We(e)):{};let n=t||!e||!e.__esModule?C(r,"default",{value:e,enumerable:!0}):r;for(let s of K(e))if(!Y.call(n,s))C(n,s,{get:()=>e[s],enumerable:!0});return n},H=new WeakMap,ke=(e)=>{var t=H.get(e),r;if(t)return t;if(t=C({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")K(e).map((n)=>!Y.call(t,n)&&C(t,n,{get:()=>e[n],enumerable:!(r=Ne(e,n))||r.enumerable}));return H.set(e,t),t};var Ve=(e,t)=>{for(var r in t)C(e,r,{get:t[r],enumerable:!0,configurable:!0,set:(n)=>t[r]=()=>n})};var ft={};Ve(ft,{defineWorkspace:()=>Q,defineConfig:()=>J,build:()=>Ae});module.exports=ke(ft);function J(e){return e}function Q(e){return e}var me=require("rolldown"),de=require("rolldown-plugin-dts");var Z=!1;function z(e){Z=e??!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(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:r,size:n,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${r}\x1B[0m`:r;if(n){let[l,...c]=a.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),f=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${l}${p} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${c.join(" ")}${f}`}let u=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${u}`}output(e,t={},r=console.log){if(Z)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let s=String(e),o=this.colors.default,i,a,u={};if(typeof r==="string")i=r,a=n;else if(r)i=r.size,a=r.identifier,u=r;for(let[c,p]of Object.entries(this.colors.progress))if(s.includes(c)){o=p;break}let l=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:u.muted});this.output(l,u)}}var g=b.getInstance();class L extends Error{constructor(e){super(e);this.name="BunupError"}}class y extends L{constructor(e){super(e);this.name="BunupBuildError"}}class m extends L{constructor(e){super(e);this.name="BunupDTSBuildError"}}var d=(e)=>{if(e instanceof Error)return e.message;return String(e)};var A=h(require("node:fs/promises")),ee=h(require("node:path"));function j(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function te(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function re(e,t){switch(e){case"esm":return R(t)?".js":".mjs";case"cjs":return R(t)?".cjs":".js";case"iife":return".global.js"}}function ne(e,t){switch(e){case"esm":return R(t)?".d.ts":".d.mts";case"cjs":return R(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function _(e){return e==="node"||e==="bun"}function R(e){return e==="module"}function se(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function F(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function E(e,t=3){return e.split("/").slice(-t).join("/")}async function oe(e,t){let r=ee.default.join(e,t);try{await A.default.rm(r,{recursive:!0,force:!0})}catch(n){throw new y(`Failed to clean output directory: ${n}`)}await A.default.mkdir(r,{recursive:!0})}function $(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function ie(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${j(t)}($|\\/|\\\\)`):t)}function T(e,t){return ie(e.external||[]).concat(se(t).map((r)=>new RegExp(`^${j(r)}($|\\/|\\\\)`)))}function D(e){return ie(e.noExternal||[])}var fe=h(require("node:path")),pe=require("oxc-resolver");var W=h(require("node:fs")),x=h(require("node:path"));class ae{patternRegexes=new Map;getOrCreatePatternRegex(e){let t=this.patternRegexes.get(e);if(!t){let r=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"(.*)");t=new RegExp(`^${r}$`),this.patternRegexes.set(e,t)}return t}clear(){this.patternRegexes.clear()}}var qe=new ae;function I(e){let{path:t,importer:r,tsconfig:n,rootDir:s}=e;if(!n)return null;let o=Xe(n,s);return He(t,r,o)||null}function Xe(e,t){let r=e.compilerOptions||{},n=r.baseUrl?x.default.resolve(t,r.baseUrl):t,s=[".ts",".tsx",".d.ts"];if(r.allowJs)s.push(".js",".jsx");if(r.resolveJsonModule)s.push(".json");return{baseUrl:n,paths:r.paths||{},extensions:s,rootDir:t}}function He(e,t,r){if(Object.keys(r.paths).length>0){let n=Ye(e,r);if(n)return n}if(Ke(e)){let n=x.default.dirname(t);return B(x.default.resolve(n,e),r)}if(x.default.isAbsolute(e))return B(e,r);if(r.baseUrl){let n=x.default.join(r.baseUrl,e);return B(n,r)}return null}function Ke(e){return e.startsWith("./")||e.startsWith("../")||e==="."}function Ye(e,t){let{paths:r,baseUrl:n}=t;for(let[s,o]of Object.entries(r)){if(!Array.isArray(o)||!o.length)continue;let a=qe.getOrCreatePatternRegex(s).exec(e);if(!a)continue;let u=s.includes("*")?a[1]:"";for(let l of o){let c=l.replace("*",u),p=B(x.default.resolve(n,c),t);if(p)return p}}return null}function B(e,t){if(U(e))return e;let{extensions:r}=t;for(let n of r){let s=`${e}${n}`;if(U(s))return s}if(Je(e))for(let n of r){let s=x.default.join(e,`index${n}`);if(U(s))return s}return null}function U(e){try{return W.default.statSync(e).isFile()}catch{return!1}}function Je(e){try{return W.default.statSync(e).isDirectory()}catch{return!1}}var S="\x00dts:",le=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(N(n))return n;if(!s||!N(s))return null;let o=t.tsconfig?I({path:n,importer:P(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!o)return null;let i=w(o);if(e.has(i))return v(i);return null},load(n){if(n.startsWith(S)){let s=P(n),o=e.get(s);if(o)return ce.add(s),o}return null}}};function w(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function N(e){return e.startsWith(S)}function P(e){return e.replace(S,"")}function v(e){return`${S}${e}`}var ue;function ge(e){return{name:"bunup:types-resolve",buildStart(){ue||=new pe.ResolverFactory({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?P(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?fe.default.dirname(n):process.cwd(),{path:o}=await ue.async(s,t);return o}}}async function xe(e,t,r,n,s,o){let i=w(e),a=v(i),u=T(r,n),l=D(r);try{let{output:c}=await me.build({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(p,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;f(p)},plugins:[le(t,s,o),typeof r.dts==="object"&&"resolve"in r.dts&&ge(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),de.dts({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>u.some((f)=>f.test(p))&&!l.some((f)=>f.test(p))});if(!c[0]?.code)return g.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return c[0].code}catch(c){throw new m(`DTS bundling failed for entry "${e}": ${d(c)}`)}}var Qe=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ze=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,ze=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,et=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,tt=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,rt=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,nt=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function st(e){let t=new Set,r=[Qe,Ze,ze,et,tt,rt,nt];for(let n of r){let s=e.matchAll(n);for(let o of s)if(o[1])t.add(o[1])}return t}async function he(e,t,r){let n=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=st(i);for(let u of a){let l=t.tsconfig?I({path:u,importer:o,tsconfig:t.tsconfig,rootDir:r}):null;if(!l)continue;if(!n.has(l))n.add(l),s.push(l)}}catch(i){g.warn(`Error processing ${o}: ${d(i)}`)}}return n}var be=require("oxc-transform");async function ye(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=w(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:i}=be.isolatedDeclaration(r,o);if(i)t.set(n,i)}catch(n){g.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),t}var k=h(require("node:fs/promises")),M=h(require("node:path")),ot=require("oxc-transform");async function Re(e,t){let r=M.default.resolve(e),n=M.default.resolve(r,t);if(!await k.default.exists(r))throw new m(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new m(`Entry file does not exist: ${n}`);if(!$(n))throw new m(`Entry file must be a TypeScript file: ${n}`);if(M.default.relative(r,n).startsWith(".."))throw new m(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function Ee(e,t,r,n,s){let{absoluteEntry:o}=await Re(e,t),i=await he(o,n,e),a=await ye(i);return xe(o,a,r,s,n,e)}function we(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function V(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,s={};function o(i,a){if(n.has(i)){let u=te(),l=`${i}_${u}`;if(t)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
|
-
${i
|
|
5
|
-
${a} -> ${
|
|
4
|
+
${s[i]} -> ${i}.js
|
|
5
|
+
${a} -> ${l}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
|
-
custom_name: "${i
|
|
10
|
+
custom_name: "${s[i]}",
|
|
11
11
|
another_name: "${a}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:l,path:a})}else r.push({name:i,path:a}),n.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=we(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=we(e);o(i,e)}return r}function Ce(e){return e.filter((t)=>$(t.path))}function Pe(e,t){return`[dir]/${e}${t}`}var G=require("coffi");async function Se(e){let{config:t,filepath:r}=await G.loadConfig({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:r}}async function $e(e,t){let{config:r,filepath:n}=await G.loadConfig({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:r,path:n}}var it={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function Te(e){return{...it,...e}}function De(e){let{minify:t,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:s}=e,o=t===!0;return{whitespace:r??o,identifiers:n??o,syntax:s??o}}function Be(e,t){return t==="cjs"?e:void 0}function Ie(e,t,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},{}),...e,...n==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function ve(e,t){return e===void 0?t==="esm":e}function Me(e){return typeof e==="string"?e:void 0}function Oe(e,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let s=n.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var at=/\.(js|ts|jsx|tsx|mts|cts)$/,q={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&_(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
16
16
|
import { dirname } from 'path';
|
|
17
17
|
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
19
|
const __dirname = dirname(__filename);
|
|
20
20
|
|
|
21
|
-
`},importMetaUrl:{appliesTo:(t
|
|
21
|
+
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&_(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
22
22
|
|
|
23
23
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
24
24
|
|
|
25
|
-
`}};function
|
|
26
|
-
`);return
|
|
25
|
+
`}};function Le({format:e,target:t,shims:r}){let s=lt(r).map((o)=>q[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:at},async({path:i})=>{let a=await Bun.file(i).text(),u=s.filter((f)=>f.isNeededInFile(a));if(u.length===0)return;let{shebangLine:l,codeContent:c}=ct(a),p=u.map((f)=>f.generateCode()).join("");return{contents:l+p+c}})}}}function lt(e){if(e===!0)return Object.keys(q);if(!e)return[];return Object.entries(e).filter(([t,r])=>r&&(t in q)).map(([t])=>t)}function ct(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
|
|
26
|
+
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var ce=new Set;async function Ae(e,t){let r=Te(e);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.");if(r.clean)oe(t,r.outDir);z(r.silent);let{packageJson:n,path:s}=await Se(t);if(n&&s)g.cli(`Using package.json: ${E(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=V(r.entry),i=n?.type,a=T(r,n),u=D(r);if(!r.dtsOnly){let l=[Oe(a,u)],c=r.format.flatMap((p)=>o.map((f)=>{return ut(r,t,f,p,i,l)}));await Promise.all(c)}if(r.dts||r.dtsOnly){let l=await $e(t,r.preferredTsconfigPath);if(l.path)g.cli(`Using tsconfig: ${E(l.path,2)}`,{muted:!0,identifier:r.name,once:`${l.path}:${r.name}`});let c=r.format.filter((f)=>{if(f==="iife"&&!R(i)&&r.format.includes("cjs"))return!1;return!0}),p=typeof r.dts==="object"&&r.dts.entry?V(r.dts.entry):Ce(o);try{await Promise.all(p.map(async(f)=>{let je=await Ee(t,f.path,r,l,n);await Promise.all(c.map(async(X)=>{let _e=r.outputExtension?.({format:X,packageType:i,options:r,entry:f}).dts??ne(X,i),O=`${t}/${r.outDir}/${f.name}${_e}`;await Bun.write(O,je);let Fe=Bun.file(O).size||0;g.progress("DTS",E(O),F(Fe),r.name)}))}))}catch(f){throw new m(d(f))}}}async function ut(e,t,r,n,s,o){let i=e.outputExtension?.({format:n,packageType:s,options:e,entry:r}).js??re(n,s),a=await Bun.build({entrypoints:[`${t}/${r.path}`],format:n,naming:{entry:Pe(r.name,i)},splitting:ve(e.splitting,n),bytecode:Be(e.bytecode,n),define:Ie(e.define,e.shims,e.env,n),minify:De(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:Me(e.env),plugins:[...o,Le({format:n,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let c of a.logs){if(c.level==="error")throw new y(c.message);if(c.level==="warning")g.warn(c.message);else if(c.level==="info")g.info(c.message)}let u=`${t}/${e.outDir}/${r.name}${i}`,l=Bun.file(u).size||0;g.progress(n.toUpperCase(),E(u),F(l),e.name)}
|
package/build/index.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
function
|
|
1
|
+
function Se(e){return e}function $e(e){return e}import{build as je}from"rolldown";import{dts as _e}from"rolldown-plugin-dts";var N=!1;function k(e){N=e??!1}class h{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(!h.instance)h.instance=new h;return h.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:r,size:n,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${r}\x1B[0m`:r;if(n){let[l,...c]=a.split(" "),p=" ".repeat(Math.max(0,this.MAX_MESSAGE_LENGTH-l.length)),f=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${l}${p} \x1B[38;5;${this.colors.size}m${n}\x1B[0m ${c.join(" ")}${f}`}let u=s?` \x1B[48;5;${e};38;5;0m ${s} \x1B[0m`:"";return`\x1B[38;5;${e}m${t}\x1B[0m ${i}${a}${u}`}output(e,t={},r=console.log){if(N)return;if(!this.shouldLog(t))return;if(t.verticalSpace)console.log("");if(r(e),t.verticalSpace)console.log("")}cli(e,t={}){let r=this.formatMessage({colorCode:this.colors.cli,label:this.labels.cli,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}info(e,t={}){let r=this.formatMessage({colorCode:this.colors.info,label:this.labels.info,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t)}warn(e,t={}){let r=this.formatMessage({colorCode:this.colors.warn,label:this.labels.warn,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.warn)}error(e,t={}){let r=this.formatMessage({colorCode:this.colors.error,label:this.labels.error,message:e,identifier:t.identifier,muted:t.muted});this.output(r,t,console.error)}progress(e,t,r,n){let s=String(e),o=this.colors.default,i,a,u={};if(typeof r==="string")i=r,a=n;else if(r)i=r.size,a=r.identifier,u=r;for(let[c,p]of Object.entries(this.colors.progress))if(s.includes(c)){o=p;break}let l=this.formatMessage({colorCode:o,label:s,message:t,size:i,identifier:a,muted:u.muted});this.output(l,u)}}var g=h.getInstance();class v extends Error{constructor(e){super(e);this.name="BunupError"}}class b extends v{constructor(e){super(e);this.name="BunupBuildError"}}class m extends v{constructor(e){super(e);this.name="BunupDTSBuildError"}}var d=(e)=>{if(e instanceof Error)return e.message;return String(e)};import V from"node:fs/promises";import Te from"node:path";function M(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(e=8){let t="";while(t.length<e)t+=Math.random().toString(36).substring(2);return t.substring(0,e)}function q(e,t){switch(e){case"esm":return y(t)?".js":".mjs";case"cjs":return y(t)?".cjs":".js";case"iife":return".global.js"}}function X(e,t){switch(e){case"esm":return y(t)?".d.ts":".d.mts";case"cjs":return y(t)?".d.cts":".d.ts";case"iife":return".d.ts"}}function O(e){return e==="node"||e==="bun"}function y(e){return e==="module"}function H(e){if(!e)return[];return Array.from(new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.peerDependencies||{})]))}function L(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(1024));if(r===0)return`${e} ${t[r]}`;return`${(e/1024**r).toFixed(2)} ${t[r]}`}function R(e,t=3){return e.split("/").slice(-t).join("/")}async function K(e,t){let r=Te.join(e,t);try{await V.rm(r,{recursive:!0,force:!0})}catch(n){throw new b(`Failed to clean output directory: ${n}`)}await V.mkdir(r,{recursive:!0})}function P(e){return[".ts",".mts",".cts",".tsx"].some((t)=>e.endsWith(t))}function Y(e){return e.map((t)=>typeof t==="string"?new RegExp(`^${M(t)}($|\\/|\\\\)`):t)}function S(e,t){return Y(e.external||[]).concat(H(t).map((r)=>new RegExp(`^${M(r)}($|\\/|\\\\)`)))}function $(e){return Y(e.noExternal||[])}import Le from"node:path";import{ResolverFactory as Ae}from"oxc-resolver";import J from"node:fs";import x from"node:path";class Q{patternRegexes=new Map;getOrCreatePatternRegex(e){let t=this.patternRegexes.get(e);if(!t){let r=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"(.*)");t=new RegExp(`^${r}$`),this.patternRegexes.set(e,t)}return t}clear(){this.patternRegexes.clear()}}var De=new Q;function D(e){let{path:t,importer:r,tsconfig:n,rootDir:s}=e;if(!n)return null;let o=Be(n,s);return Ie(t,r,o)||null}function Be(e,t){let r=e.compilerOptions||{},n=r.baseUrl?x.resolve(t,r.baseUrl):t,s=[".ts",".tsx",".d.ts"];if(r.allowJs)s.push(".js",".jsx");if(r.resolveJsonModule)s.push(".json");return{baseUrl:n,paths:r.paths||{},extensions:s,rootDir:t}}function Ie(e,t,r){if(Object.keys(r.paths).length>0){let n=Me(e,r);if(n)return n}if(ve(e)){let n=x.dirname(t);return T(x.resolve(n,e),r)}if(x.isAbsolute(e))return T(e,r);if(r.baseUrl){let n=x.join(r.baseUrl,e);return T(n,r)}return null}function ve(e){return e.startsWith("./")||e.startsWith("../")||e==="."}function Me(e,t){let{paths:r,baseUrl:n}=t;for(let[s,o]of Object.entries(r)){if(!Array.isArray(o)||!o.length)continue;let a=De.getOrCreatePatternRegex(s).exec(e);if(!a)continue;let u=s.includes("*")?a[1]:"";for(let l of o){let c=l.replace("*",u),p=T(x.resolve(n,c),t);if(p)return p}}return null}function T(e,t){if(A(e))return e;let{extensions:r}=t;for(let n of r){let s=`${e}${n}`;if(A(s))return s}if(Oe(e))for(let n of r){let s=x.join(e,`index${n}`);if(A(s))return s}return null}function A(e){try{return J.statSync(e).isFile()}catch{return!1}}function Oe(e){try{return J.statSync(e).isDirectory()}catch{return!1}}var C="\x00dts:",Z=(e,t,r)=>{return{name:"bunup:virtual-dts",async resolveId(n,s){if(j(n))return n;if(!s||!j(s))return null;let o=t.tsconfig?D({path:n,importer:w(s),tsconfig:t.tsconfig,rootDir:r}):null;if(!o)return null;let i=E(o);if(e.has(i))return B(i);return null},load(n){if(n.startsWith(C)){let s=w(n),o=e.get(s);if(o)return z.add(s),o}return null}}};function E(e){if(e.endsWith(".d.ts")||e.endsWith(".d.mts")||e.endsWith(".d.cts"))return e;return e.replace(/\.(ts|tsx|mts|cts)$/,".d.ts")}function j(e){return e.startsWith(C)}function w(e){return e.replace(C,"")}function B(e){return`${C}${e}`}var ee;function te(e){return{name:"bunup:types-resolve",buildStart(){ee||=new Ae({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],modules:["node_modules","node_modules/@types"]})},async resolveId(t,r){if(t==="bun")return;let n=r?w(r):void 0;if(/\0/.test(t))return;if(e){if(!e.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let s=n?Le.dirname(n):process.cwd(),{path:o}=await ee.async(s,t);return o}}}async function re(e,t,r,n,s,o){let i=E(e),a=B(i),u=S(r,n),l=$(r);try{let{output:c}=await je({input:a,output:{dir:r.outDir,inlineDynamicImports:!0},write:!1,onwarn(p,f){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(p.code??""))return;f(p)},plugins:[Z(t,s,o),typeof r.dts==="object"&&"resolve"in r.dts&&te(typeof r.dts.resolve==="boolean"?void 0:r.dts.resolve),_e({dtsInput:!0,emitDtsOnly:!0})],external:(p)=>u.some((f)=>f.test(p))&&!l.some((f)=>f.test(p))});if(!c[0]?.code)return g.warn(`Generated empty declaration file for entry "${e}"`,{muted:!0}),"";return c[0].code}catch(c){throw new m(`DTS bundling failed for entry "${e}": ${d(c)}`)}}var Fe=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Ue=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,We=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ne=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ke=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Ve=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,Ge=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g;function qe(e){let t=new Set,r=[Fe,Ue,We,Ne,ke,Ve,Ge];for(let n of r){let s=e.matchAll(n);for(let o of s)if(o[1])t.add(o[1])}return t}async function ne(e,t,r){let n=new Set([e]),s=[e];while(s.length){let o=s.pop();if(!o)continue;try{let i=await Bun.file(o).text(),a=qe(i);for(let u of a){let l=t.tsconfig?D({path:u,importer:o,tsconfig:t.tsconfig,rootDir:r}):null;if(!l)continue;if(!n.has(l))n.add(l),s.push(l)}}catch(i){g.warn(`Error processing ${o}: ${d(i)}`)}}return n}import{isolatedDeclaration as Xe}from"oxc-transform";async function se(e){let t=new Map;return await Promise.all([...e].map(async(r)=>{try{let n=E(r);if(!await Bun.file(r).exists())return;let o=await Bun.file(r).text(),{code:i}=Xe(r,o);if(i)t.set(n,i)}catch(n){g.warn(`Failed to generate declaration for ${r}: ${d(n)}`)}})),t}import oe from"node:fs/promises";import _ from"node:path";import{isolatedDeclaration as Vt}from"oxc-transform";async function ie(e,t){let r=_.resolve(e),n=_.resolve(r,t);if(!await oe.exists(r))throw new m(`Root directory does not exist: ${r}`);if(!await Bun.file(n).exists())throw new m(`Entry file does not exist: ${n}`);if(!P(n))throw new m(`Entry file must be a TypeScript file: ${n}`);if(_.relative(r,n).startsWith(".."))throw new m(`Entry file must be within rootDir: ${n}`);return{absoluteRootDir:r,absoluteEntry:n}}async function ae(e,t,r,n,s){let{absoluteEntry:o}=await ie(e,t),i=await ne(o,n,e),a=await se(i);return re(o,a,r,s,n,e)}function le(e){return e.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function F(e,{warnOnConflict:t=!0}={}){let r=[],n=new Set,s={};function o(i,a){if(n.has(i)){let u=G(),l=`${i}_${u}`;if(t)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
|
-
${
|
|
5
|
-
${a} -> ${
|
|
4
|
+
${s[i]} -> ${i}.js
|
|
5
|
+
${a} -> ${l}.js (auto-renamed to avoid conflict)
|
|
6
6
|
|
|
7
7
|
To fix this, use named entries in your configuration:
|
|
8
8
|
{
|
|
9
9
|
entry: {
|
|
10
|
-
custom_name: "${
|
|
10
|
+
custom_name: "${s[i]}",
|
|
11
11
|
another_name: "${a}"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:
|
|
15
|
+
See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0});r.push({name:l,path:a})}else r.push({name:i,path:a}),n.add(i),s[i]=a}if(Array.isArray(e))for(let i of e){let a=le(i);o(a,i)}else if(typeof e==="object")for(let[i,a]of Object.entries(e))o(i,a);else{let i=le(e);o(i,e)}return r}function ce(e){return e.filter((t)=>P(t.path))}function ue(e,t){return`[dir]/${e}${t}`}import{loadConfig as fe}from"coffi";async function pe(e){let{config:t,filepath:r}=await fe({name:"package",cwd:e,extensions:[".json"],maxDepth:1});return{packageJson:t,path:r}}async function ge(e,t){let{config:r,filepath:n}=await fe({name:"tsconfig",cwd:e,extensions:[".json"],preferredPath:t,maxDepth:3});return{tsconfig:r,path:n}}var He={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0};function me(e){return{...He,...e}}function de(e){let{minify:t,minifyWhitespace:r,minifyIdentifiers:n,minifySyntax:s}=e,o=t===!0;return{whitespace:r??o,identifiers:n??o,syntax:s??o}}function xe(e,t){return t==="cjs"?e:void 0}function he(e,t,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},{}),...e,...n==="cjs"&&(t===!0||typeof t==="object"&&t.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function be(e,t){return e===void 0?t==="esm":e}function ye(e){return typeof e==="string"?e:void 0}function Re(e,t){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(n)=>{let s=n.path;if(e.some((i)=>i.test(s))&&!t.some((i)=>i.test(s)))return{path:s,external:!0};return null})}}}var Ke=/\.(js|ts|jsx|tsx|mts|cts)$/,U={dirnameFilename:{appliesTo:(e,t)=>e==="esm"&&O(t),isNeededInFile:(e)=>/\b__dirname\b/.test(e)||/\b__filename\b/.test(e),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
16
16
|
import { dirname } from 'path';
|
|
17
17
|
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
19
|
const __dirname = dirname(__filename);
|
|
20
20
|
|
|
21
|
-
`},importMetaUrl:{appliesTo:(t
|
|
21
|
+
`},importMetaUrl:{appliesTo:(e,t)=>e==="cjs"&&O(t),isNeededInFile:(e)=>/\bimport\.meta\.url\b/.test(e),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
22
22
|
|
|
23
23
|
const importMetaUrl = pathToFileURL(__filename).href;
|
|
24
24
|
|
|
25
|
-
`}};function
|
|
26
|
-
`);return
|
|
25
|
+
`}};function Ee({format:e,target:t,shims:r}){let s=Ye(r).map((o)=>U[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:Ke},async({path:i})=>{let a=await Bun.file(i).text(),u=s.filter((f)=>f.isNeededInFile(a));if(u.length===0)return;let{shebangLine:l,codeContent:c}=Je(a),p=u.map((f)=>f.generateCode()).join("");return{contents:l+p+c}})}}}function Ye(e){if(e===!0)return Object.keys(U);if(!e)return[];return Object.entries(e).filter(([t,r])=>r&&(t in U)).map(([t])=>t)}function Je(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
|
|
26
|
+
`);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var z=new Set;async function Qe(e,t){let r=me(e);if(!r.entry||r.entry.length===0||!r.outDir)throw new b("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(r.clean)K(t,r.outDir);k(r.silent);let{packageJson:n,path:s}=await pe(t);if(n&&s)g.cli(`Using package.json: ${R(s,2)}`,{muted:!0,identifier:r.name,once:`${s}:${r.name}`});let o=F(r.entry),i=n?.type,a=S(r,n),u=$(r);if(!r.dtsOnly){let l=[Re(a,u)],c=r.format.flatMap((p)=>o.map((f)=>{return Ze(r,t,f,p,i,l)}));await Promise.all(c)}if(r.dts||r.dtsOnly){let l=await ge(t,r.preferredTsconfigPath);if(l.path)g.cli(`Using tsconfig: ${R(l.path,2)}`,{muted:!0,identifier:r.name,once:`${l.path}:${r.name}`});let c=r.format.filter((f)=>{if(f==="iife"&&!y(i)&&r.format.includes("cjs"))return!1;return!0}),p=typeof r.dts==="object"&&r.dts.entry?F(r.dts.entry):ce(o);try{await Promise.all(p.map(async(f)=>{let we=await ae(t,f.path,r,l,n);await Promise.all(c.map(async(W)=>{let Ce=r.outputExtension?.({format:W,packageType:i,options:r,entry:f}).dts??X(W,i),I=`${t}/${r.outDir}/${f.name}${Ce}`;await Bun.write(I,we);let Pe=Bun.file(I).size||0;g.progress("DTS",R(I),L(Pe),r.name)}))}))}catch(f){throw new m(d(f))}}}async function Ze(e,t,r,n,s,o){let i=e.outputExtension?.({format:n,packageType:s,options:e,entry:r}).js??q(n,s),a=await Bun.build({entrypoints:[`${t}/${r.path}`],format:n,naming:{entry:ue(r.name,i)},splitting:be(e.splitting,n),bytecode:xe(e.bytecode,n),define:he(e.define,e.shims,e.env,n),minify:de(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:ye(e.env),plugins:[...o,Ee({format:n,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let c of a.logs){if(c.level==="error")throw new b(c.message);if(c.level==="warning")g.warn(c.message);else if(c.level==="info")g.info(c.message)}let u=`${t}/${e.outDir}/${r.name}${i}`,l=Bun.file(u).size||0;g.progress(n.toUpperCase(),R(u),L(l),e.name)}export{$e as defineWorkspace,Se as defineConfig,Qe as build};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.21",
|
|
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",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"@commitlint/config-conventional": "^19.5.0",
|
|
18
18
|
"@types/bun": "^1.2.5",
|
|
19
19
|
"bumpp": "^10.1.0",
|
|
20
|
-
"bunup": "^0.4.
|
|
20
|
+
"bunup": "^0.4.19",
|
|
21
21
|
"husky": "^9.1.7",
|
|
22
22
|
"typescript": "^5.8.3",
|
|
23
|
-
"create-bunup": "0.4.
|
|
23
|
+
"create-bunup": "0.4.21"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"typescript": ">=4.5.0"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"oxc-transform": "^0.58.1",
|
|
57
57
|
"rolldown": "1.0.0-beta.7",
|
|
58
58
|
"rolldown-plugin-dts": "^0.4.0",
|
|
59
|
-
"ts-import-resolver": "^0.1.
|
|
59
|
+
"ts-import-resolver": "^0.1.7"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "bunup",
|