bunup 0.1.38 → 0.1.40
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/README.md +37 -32
- package/build/cli.mjs +6 -6
- package/build/dtsWorker.js +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
# bunup
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/bunup)
|
|
4
|
+
[](https://www.npmjs.com/package/bunup)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by [Bun](https://bun.sh) and [Oxc](https://oxc.rs/).
|
|
6
7
|
|
|
7
|
-
| Bundler
|
|
8
|
-
|
|
|
9
|
-
| bunup
|
|
10
|
-
| bunup (+ dts)
|
|
11
|
-
|
|
|
12
|
-
|
|
|
8
|
+
| Bundler | Format | Build Time | Relative Speed |
|
|
9
|
+
| -------------- | -------- | ---------- | -------------------- |
|
|
10
|
+
| bunup | esm, cjs | **6ms** | **⚡️ 9.7x faster** |
|
|
11
|
+
| bunup (+ dts) | esm, cjs | **32ms** | **⚡️ 25.8x faster** |
|
|
12
|
+
| tsdown | esm, cjs | 22ms | 2.6x faster |
|
|
13
|
+
| tsdown (+ dts) | esm, cjs | 52ms | 15.9x faster |
|
|
14
|
+
| tsup | esm, cjs | 58ms | baseline |
|
|
15
|
+
| tsup (+ dts) | esm, cjs | 825ms | baseline |
|
|
13
16
|
|
|
14
17
|
_Lower build time is better. Benchmark run on the same code with identical output formats._
|
|
15
18
|
|
|
16
|
-
##
|
|
19
|
+
## 🚀 Quick Start
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
### Installation
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
```bash
|
|
24
|
+
# Using Bun
|
|
25
|
+
bun add bunup -d
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
# Using pnpm
|
|
28
|
+
pnpm add bunup -D
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
# Using npm
|
|
31
|
+
npm i bunup -D
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
# Using Yarn
|
|
34
|
+
yarn add bunup --dev
|
|
28
35
|
```
|
|
29
36
|
|
|
30
37
|
### Basic Usage
|
|
@@ -34,7 +41,7 @@ Create a simple TypeScript file:
|
|
|
34
41
|
```typescript
|
|
35
42
|
// src/index.ts
|
|
36
43
|
export function greet(name: string): string {
|
|
37
|
-
|
|
44
|
+
return `Hello, ${name}!`;
|
|
38
45
|
}
|
|
39
46
|
```
|
|
40
47
|
|
|
@@ -52,10 +59,10 @@ Add a build script to your `package.json`:
|
|
|
52
59
|
|
|
53
60
|
```json
|
|
54
61
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
"name": "my-package",
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "bunup src/index.ts --format esm,cjs --dts"
|
|
65
|
+
}
|
|
59
66
|
}
|
|
60
67
|
```
|
|
61
68
|
|
|
@@ -65,7 +72,7 @@ Then run:
|
|
|
65
72
|
npm run build
|
|
66
73
|
```
|
|
67
74
|
|
|
68
|
-
### Configuration File
|
|
75
|
+
### ⚙️ Configuration File
|
|
69
76
|
|
|
70
77
|
Create a `bunup.config.ts` file for more control:
|
|
71
78
|
|
|
@@ -73,22 +80,20 @@ Create a `bunup.config.ts` file for more control:
|
|
|
73
80
|
import {defineConfig} from 'bunup';
|
|
74
81
|
|
|
75
82
|
export default defineConfig({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
entry: ['src/index.ts'],
|
|
84
|
+
outDir: 'dist',
|
|
85
|
+
format: ['esm', 'cjs'],
|
|
86
|
+
dts: true,
|
|
87
|
+
minify: true,
|
|
81
88
|
});
|
|
82
89
|
```
|
|
83
90
|
|
|
84
|
-
## Documentation
|
|
91
|
+
## 📚 Documentation
|
|
85
92
|
|
|
86
93
|
For complete documentation, visit [the full documentation](https://bunup.arshadyaseen.com/).
|
|
87
94
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
## Contributing
|
|
95
|
+
## ❤️ Contributing
|
|
91
96
|
|
|
92
97
|
For guidelines on contributing, please read the [contributing guide](https://github.com/arshad-yaseen/bunup/blob/main/CONTRIBUTING.md).
|
|
93
98
|
|
|
94
|
-
We welcome contributions from the community to enhance Bunup's capabilities and make it even more powerful.
|
|
99
|
+
We welcome contributions from the community to enhance Bunup's capabilities and make it even more powerful.
|
package/build/cli.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import
|
|
3
|
+
import Z from"node:fs";import zt from"node:path";import{isMainThread as kt}from"node:worker_threads";import{isMainThread as Xt,parentPort as T,Worker as Yt,workerData as Jt}from"node:worker_threads";class O extends Error{constructor(t){super(t);this.name="BunupError"}}class y extends O{constructor(t){super(t);this.name="BunupBuildError"}}class d extends O{constructor(t){super(t);this.name="BunupDTSBuildError"}}class h extends O{constructor(t){super(t);this.name="BunupCLIError"}}class b extends O{constructor(t){super(t);this.name="BunupWatchError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)},bt=(t,n)=>{let r=m(t),e=n?`[${n}] `:"",s="ERROR";if(t instanceof y)s="BUILD ERROR";else if(t instanceof d)s="DTS ERROR";else if(t instanceof h)s="CLI ERROR";else if(t instanceof b)s="WATCH ERROR";else if(t instanceof O)s="BUNUP ERROR";if(console.error(`\x1B[31m[${s}]\x1B[0m ${e}${r}`),t instanceof Error&&t.stack)console.error("\x1B[2m"+t.stack.split(`
|
|
4
4
|
`).slice(1).join(`
|
|
5
|
-
`)+"\x1B[0m")},
|
|
6
|
-
`);let a=o.labels[0],c=a?
|
|
5
|
+
`)+"\x1B[0m")},k=(t,n)=>{bt(t,n),process.exit(1)};var l={MAX_LABEL_LENGTH:5,colors:{cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,n,r,e){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));if(e){let[i,...o]=r.split(" ");return`\x1B[38;5;${t}m[${n}]\x1B[0m ${s}${i} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${o.join(" ")}`}return`\x1B[38;5;${t}m[${n}]\x1B[0m ${s}${r}`},cli(t){let n=this.labels.cli;console.log(this.formatMessage(this.colors.cli,n,t))},info(t){console.log(`\x1B[38;5;${this.colors.info}m${t}\x1B[0m`)},warn(t){let n=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,n,t))},error(t){let n=this.labels.error;console.error(this.formatMessage(this.colors.error,n,t))},progress(t,n,r){let e=String(t),s=this.colors.default;for(let[i,o]of Object.entries(this.colors.progress))if(e.includes(i)){s=o;break}console.log(this.formatMessage(s,e,n,r))}};function D(t,n){return`${n?`${n.replace(/-/g,"_")}_`:""}${t}`.toUpperCase()}function G(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function tt(t=8){return Math.random().toString(36).substring(2,2+t)}function nt(t,n){switch(t){case"esm":return".mjs";case"cjs":return N(n)?".cjs":".js";case"iife":return".global.js"}}function rt(t,n){switch(t){case"esm":return".d.mts";case"cjs":return N(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(t){return t==="module"}function j(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function et(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function st(t,n){return t===void 0?n==="esm":t}function I(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function F(t,n=3){return t.split("/").slice(-n).join("/")}import{loadTsConfig as At}from"load-tsconfig";function it(t){try{return At(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}import S from"node:path";import{rollup as jt}from"rollup";import It from"rollup-plugin-dts";import X from"typescript";function ot(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${G(n)}($|\\/|\\\\)`):n)}function M(t,n){return ot(t.external||[]).concat(et(n).map((r)=>new RegExp(`^${G(r)}($|\\/|\\\\)`)))}function L(t){return ot(t.noExternal||[])}import W from"node:fs";import lt from"node:path";var R={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0,sourcemap:"none"};function at(t,n){return{outdir:`${n}/${t.outDir}`,minify:Nt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap}}function Nt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:s}=t,i=n===!0;return{whitespace:r??i,identifiers:e??i,syntax:s??i}}async function ct(t){let n=[],r="";for(let e of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let s=lt.join(t,`bunup.config${e}`);try{if(!W.existsSync(s))continue;let i;if(r=s,e===".json"||e===".jsonc"){let o=W.readFileSync(s,"utf8"),a=JSON.parse(o);i=a.bunup||a}else{let o=await import(`file://${s}`);if(i=o.default||o,!i)l.warn(`No default export found in ${s}`),i={}}if(Array.isArray(i))for(let o of i)n.push({options:{...R,...o},rootDir:t});else n.push({options:{...R,...i},rootDir:t});break}catch(i){throw new y(`Failed to load config from ${s}: ${m(i)}`)}}return{configs:n,configFilePath:r}}function H(t){let n=lt.join(t,"package.json");try{if(!W.existsSync(n))return null;let r=W.readFileSync(n,"utf8");return JSON.parse(r)}catch(r){return l.warn(`Failed to load package.json at ${n}: ${m(r)}`),null}}var Ft=()=>{return global.allFilesUsedToBundleDts||C||new Set};async function ft(t,n,r,e,s){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,c=s.data?.compilerOptions,g={name:"bunup:virtual-dts",resolveId(p,$){if(p.startsWith("\x00virtual:"))return p;if(!$?.startsWith("\x00virtual:")||!p.startsWith("."))return null;let x=$.slice(9),P=S.resolve(S.dirname(x),p);if(p==="."){let B=S.join(S.dirname(x),"index.d.ts");if(n.has(B))return`\x00virtual:${B}`;P=S.dirname(x)}if(n.has(P))return`\x00virtual:${P}`;let z=`${P}.d.ts`;if(n.has(z))return`\x00virtual:${z}`;if(p.startsWith(".")){let B=S.join(P,"index.d.ts");if(n.has(B))return`\x00virtual:${B}`}return null},load(p){if(p.startsWith("\x00virtual:")){let $=p.slice(9),x=n.get($);if(x)return Ft().add($),x}return null}},u=H(e),f=M(r,u),w=L(r),E;try{E=await jt({input:a,onwarn($,x){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes($.code??""))return;x($)},plugins:[g,It({tsconfig:s.path,compilerOptions:{...c?X.parseJsonConfigFileContent({compilerOptions:c},X.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:X.ScriptTarget.ESNext}})],external:($)=>f.some((x)=>x.test($))&&!w.some((x)=>x.test($))});let{output:p}=await E.generate({});if(!p[0]?.code)throw new d("Generated bundle is empty");return p[0].code}catch(p){throw new d(`DTS bundling failed: ${m(p)}`)}finally{if(E)await E.close()}}import pt from"node:fs";import gt from"node:path";import _ from"node:path";function Y(t){let n=_.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?_.resolve(n,t.data.compilerOptions.baseUrl):n}function ut(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=Y(t);for(let[s,i]of Object.entries(r))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");n.set(`^${o}$`,_.join(e,a))}return n}function mt(t,n,r){for(let[e,s]of n){let i=new RegExp(e),o=t.match(i);if(o)return s.replace("$1",o[1]||"")}return r?_.join(r,t):null}var Mt=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,Lt=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function dt(t,n){let r=new Set([t]),e=[t],s=ut(n),i=Y(n);while(e.length){let o=e.pop();if(!o)continue;try{let a=await pt.promises.readFile(o,"utf8"),c=Wt(a);for(let g of c){let u=g.startsWith(".")?gt.resolve(gt.dirname(o),g):mt(g,s,i);if(!u)continue;let f=Ht(u);if(f&&!r.has(f))r.add(f),e.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return r}function Wt(t){let n=new Set;for(let r of[Mt,Lt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}function Ht(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(pt.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}import _t from"node:fs";import{isolatedDeclaration as Tt}from"oxc-transform";async function xt(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),s=await _t.promises.readFile(r,"utf8"),{code:i}=Tt(r,s);if(i)n.set(e,i)}catch(e){l.warn(`Failed to generate declaration for ${r}: ${m(e)}`)}})),n}import K from"node:fs";import J from"node:path";import{isolatedDeclaration as Ut}from"oxc-transform";function ht(t,n){let r=J.resolve(t),e=J.resolve(r,n);if(!K.existsSync(r))throw new d(`Root directory does not exist: ${r}`);if(!K.existsSync(e))throw new d(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new d(`Entry file must be a TypeScript file (.ts): ${e}`);if(J.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function $t(t){let n=!1;if(await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.d\.ts$/,".ts"),s=await K.promises.readFile(e,"utf8"),{errors:i}=Ut(e,s);i.forEach((o)=>{if(!n)console.log(`
|
|
6
|
+
`);let a=o.labels[0],c=a?qt(s,a.start):"",u=`${F(e)}${c}: ${Gt(o.message)}`;l.warn(u),n=!0})}catch{}})),n)l.info(`
|
|
7
7
|
You may have noticed some TypeScript warnings above related to missing type annotations. This is because Bunup uses TypeScript's "isolatedDeclarations" approach for generating declaration files. This modern approach requires explicit type annotations on exports for better, more accurate type declarations. Other bundlers might not show these warnings because they use different, potentially less precise methods. Adding the suggested type annotations will not only silence these warnings but also improve the quality of your published type definitions, making your library more reliable for consumers.
|
|
8
|
-
`)}function
|
|
9
|
-
`),
|
|
10
|
-
To install Bun, visit https://bun.sh/docs/installation`)})();import
|
|
8
|
+
`)}function qt(t,n){if(n===void 0)return"";let r=t.slice(0,n).split(`
|
|
9
|
+
`),e=r.length,s=r[r.length-1].length+1;return` (${e}:${s})`}function Gt(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function wt(t,n,r){let{absoluteRootDir:e,absoluteEntry:s}=ht(t,n),i=it(r.preferredTsconfigPath),o=await dt(s,i),a=await xt(o);return ft(s,a,r,e,i)}async function yt(t,n,r,e,s){return new Promise((i,o)=>{let{onBuildEnd:a,...c}=e,g={rootDir:t,entries:n,formats:r,options:c,packageType:s},u=new Yt(new URL("./dtsWorker.js",import.meta.url),{workerData:g});u.on("message",async(f)=>{if(f.success){let w=j(f.timeMs);if(l.progress("DTS",`Bundled types in ${w}`),f.filesUsed)f.filesUsed.forEach((E)=>C.add(E));i()}else o(new d(f.error||"Unknown DTS worker error"))}),u.on("error",o),u.on("exit",(f)=>{if(f!==0)o(new d(`DTS worker stopped with exit code ${f}`))})})}if(!Xt&&T){let{rootDir:t,entries:n,formats:r,options:e,packageType:s}=Jt,i=performance.now(),o=new Set;global.allFilesUsedToBundleDts=o,l.progress("DTS","Bundling types");try{(async()=>{try{await Promise.all(n.map(async(c)=>{let g=await wt(t,c.path,e);await Promise.all(r.map(async(u)=>{let f=rt(u,s),w=`${e.outDir}/${c.name}${f}`,E=`${t}/${w}`;await Bun.write(E,g);let p=Bun.file(E).size||0;l.progress("DTS",w,I(p))}))}));let a=performance.now()-i;T?.postMessage({success:!0,timeMs:a,filesUsed:[...o]})}catch(a){T?.postMessage({success:!1,error:m(a)})}})()}catch(a){T?.postMessage({success:!1,error:m(a)})}}function Kt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function A(t){let n=[],r=new Set;function e(s,i){if(r.has(s)){let o=tt();n.push({name:`${s}_${o}`,path:i})}else n.push({name:s,path:i}),r.add(s)}if(Array.isArray(t))for(let s of t){let i=Kt(s);e(i,s)}else Object.entries(t).forEach(([s,i])=>{e(s,i)});return n}function Et(t,n){return`[dir]/${t}${n}`}function vt(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let s=e.path;if(t.some((o)=>o.test(s))&&!n.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}async function U(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=performance.now(),e=H(n),s=e?.type,i=M(t,e),o=L(t),a=[vt(i,o)],c=A(t.entry),g=t.format.flatMap((u)=>c.map((f)=>{return Qt(t,n,f,u,s,a)}));try{await Promise.all(g);let u=performance.now()-r,f=j(u);l.cli(`\uD83D\uDCE6 Build success in ${f}`)}catch{throw new y("Build process encountered errors")}if(t.dts){let u=t.format.filter((w)=>{if(w==="iife"&&!N(s)&&t.format.includes("cjs"))return!1;return!0}),f=t.dts===!0?c:A(t.dts.entry);try{await yt(n,f,u,t,s)}catch(w){throw new d(`DTS build process encountered errors: ${m(w)}`)}}}async function Qt(t,n,r,e,s,i){let o=nt(e,s),a=at(t,n),c=await Bun.build({...a,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:Et(r.name,o)},splitting:st(t.splitting,e),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((f)=>{if(f.level==="error")l.error(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)}),new y(`Build failed for ${r} (${e})`);let g=`${t.outDir}/${r.name}${o}`,u=Bun.file(g).size||0;l.progress(D(e,t.name),g,I(u))}function v(t){return(n,r)=>{r[t]=n===!0?!0:n==="true"}}function q(t){return(n,r)=>{if(typeof n==="string")r[t]=n;else throw new h(`Option --${t} requires a string value`)}}function Ct(t){return(n,r)=>{if(typeof n==="string")r[t]=n.split(",");else throw new h(`Option --${t} requires a string value`)}}var Vt={name:{flags:["n","name"],handler:q("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:q("outDir")},minify:{flags:["m","minify"],handler:v("minify")},watch:{flags:["w","watch"],handler:v("watch")},dts:{flags:["d","dts"],handler:v("dts")},external:{flags:["e","external"],handler:Ct("external")},sourcemap:{flags:["sm","sourcemap"],handler:q("sourcemap")},target:{flags:["t","target"],handler:q("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:v("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:v("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:v("minifySyntax")},clean:{flags:["c","clean"],handler:v("clean")},splitting:{flags:["s","splitting"],handler:v("splitting")},noExternal:{flags:["ne","no-external"],handler:Ct("noExternal")}},Q={};for(let t of Object.values(Vt))if(t)for(let n of t.flags)Q[n]=t.handler;function Ot(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function Rt(t){let n={},r={},e=0;while(e<t.length){let s=t[e];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=t[e+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")e++}if(i==="entry")if(typeof o==="string"){let a=Ot(o);if(r[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);r[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(r[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);r[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=Q[i];if(a)a(o,n);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=t[e+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")e++;let c=Q[i];if(c)c(a,n);else throw new h(`Unknown option: -${i}`)}else{let i=Ot(s);if(r[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);r[i]=s}e++}if(Object.keys(r).length>0)n.entry=r;return n}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
|
|
10
|
+
To install Bun, visit https://bun.sh/docs/installation`)})();import V from"node:path";import Zt from"chokidar";async function St(t,n){let r=new Set,e=A(t.entry);e.forEach((c)=>{let g=V.resolve(n,c.path),u=V.dirname(g);r.add(u)});let s=Zt.watch(Array.from(r),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,t.outDir]}),i=null,o=!1,a=async()=>{if(o)return;o=!0;try{await U({...t,entry:e.map((c)=>c.path),clean:!1},n),t.onBuildEnd?.()}catch(c){throw new b(`Build failed: ${m(c)}`)}finally{o=!1}};s.on("change",(c)=>{let g=V.relative(n,c);if(l.cli(`File changed: ${g}`),i)clearTimeout(i);i=setTimeout(()=>a(),300)}),s.on("error",(c)=>{throw new b(`Watcher error: ${m(c)}`)}),await a()}var C=new Set;async function Dt(t=Bun.argv.slice(2)){let n=Rt(t),{configs:r,configFilePath:e}=await ct(process.cwd());l.cli(`Using config file: ${F(e,2)}`);let s=process.cwd();if(n.watch)l.cli("Starting watch mode"),l.cli("Watching for file changes");if(r.length===0){let i={...R,...n};if(i.clean)Bt(s,i.outDir);await Pt(i,s)}else{for(let{options:i,rootDir:o}of r)if(i.clean)Bt(o,i.outDir);l.cli("Build started"),await Promise.all(r.map(async({options:i,rootDir:o})=>{let a={...R,...i,...n};await Pt(a,o)}))}if(C.size>0)await $t(C),C.clear();if(!n.watch)process.exit(0)}async function Pt(t,n){if(t.watch)await St(t,n);else await U(t,n),t.onBuildEnd?.()}function Bt(t,n){let r=zt.join(t,n);if(Z.existsSync(r))try{Z.rmSync(r,{recursive:!0,force:!0})}catch(e){throw new y(`Failed to clean output directory: ${e}`)}Z.mkdirSync(r,{recursive:!0})}if(kt)Dt().catch((t)=>k(t));export{Dt as main,C as allFilesUsedToBundleDts};
|
package/build/dtsWorker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Qt=require("node:module");var Gt=Object.create;var{getPrototypeOf:Xt,defineProperty:N,getOwnPropertyNames:it,getOwnPropertyDescriptor:Yt}=Object,ot=Object.prototype.hasOwnProperty;var d=(t,n,r)=>{r=t!=null?Gt(Xt(t)):{};let e=n||!t||!t.__esModule?N(r,"default",{value:t,enumerable:!0}):r;for(let s of it(t))if(!ot.call(e,s))N(e,s,{get:()=>t[s],enumerable:!0});return e},st=new WeakMap,Jt=(t)=>{var n=st.get(t),r;if(n)return n;if(n=N({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")it(t).map((e)=>!ot.call(n,e)&&N(n,e,{get:()=>t[e],enumerable:!(r=Yt(t,e))||r.enumerable}));return st.set(t,n),n};var Kt=(t,n)=>{for(var r in n)N(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var cn={};Kt(cn,{runDtsInWorker:()=>k});module.exports=Jt(cn);var y=require("node:worker_threads");var Q=d(require("node:fs")),bt=d(require("node:path")),At=require("node:worker_threads");class P extends Error{constructor(t){super(t);this.name="BunupError"}}class v extends P{constructor(t){super(t);this.name="BunupBuildError"}}class x extends P{constructor(t){super(t);this.name="BunupDTSBuildError"}}class $ extends P{constructor(t){super(t);this.name="BunupCLIError"}}class j extends P{constructor(t){super(t);this.name="BunupWatchError"}}var m=(t)=>{if(t instanceof Error)return t.message;return String(t)},Vt=(t,n)=>{let r=m(t),e=n?`[${n}] `:"",s="ERROR";if(t instanceof v)s="BUILD ERROR";else if(t instanceof x)s="DTS ERROR";else if(t instanceof $)s="CLI ERROR";else if(t instanceof j)s="WATCH ERROR";else if(t instanceof P)s="BUNUP ERROR";if(console.error(`\x1B[31m[${s}]\x1B[0m ${e}${r}`),t instanceof Error&&t.stack)console.error("\x1B[2m"+t.stack.split(`
|
|
2
2
|
`).slice(1).join(`
|
|
3
|
-
`)+"\x1B[0m")},at=(t,n)=>{
|
|
4
|
-
To install Bun, visit https://bun.sh/docs/installation`)})();var
|
|
5
|
-
`);let a=o.labels[0],c=a?tn(
|
|
3
|
+
`)+"\x1B[0m")},at=(t,n)=>{Vt(t,n),process.exit(1)};function Z(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lt(t=8){return Math.random().toString(36).substring(2,2+t)}function ct(t,n){switch(t){case"esm":return".mjs";case"cjs":return L(n)?".cjs":".js";case"iife":return".global.js"}}function ft(t,n){switch(t){case"esm":return".d.mts";case"cjs":return L(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function L(t){return t==="module"}function W(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ut(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function mt(t,n){return t===void 0?n==="esm":t}function H(t){if(t===0)return"0 B";let n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));if(r===0)return`${t} ${n[r]}`;return`${(t/Math.pow(1024,r)).toFixed(2)} ${n[r]}`}function _(t,n=3){return t.split("/").slice(-n).join("/")}function Zt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function I(t){let n=[],r=new Set;function e(s,i){if(r.has(s)){let o=lt();n.push({name:`${s}_${o}`,path:i})}else n.push({name:s,path:i}),r.add(s)}if(Array.isArray(t))for(let s of t){let i=Zt(s);e(i,s)}else Object.entries(t).forEach(([s,i])=>{e(s,i)});return n}function gt(t,n){return`[dir]/${t}${n}`}function pt(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${Z(n)}($|\\/|\\\\)`):n)}function T(t,n){return pt(t.external||[]).concat(ut(n).map((r)=>new RegExp(`^${Z(r)}($|\\/|\\\\)`)))}function U(t){return pt(t.noExternal||[])}var F=d(require("node:fs")),z=d(require("node:path"));var l={MAX_LABEL_LENGTH:5,colors:{cli:"147",info:"245",warn:"179",error:"174",progress:{ESM:"172",CJS:"108",IIFE:"146",DTS:"110"},default:"252",size:"65"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,n,r,e){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));if(e){let[i,...o]=r.split(" ");return`\x1B[38;5;${t}m[${n}]\x1B[0m ${s}${i} \x1B[38;5;${this.colors.size}m${e}\x1B[0m ${o.join(" ")}`}return`\x1B[38;5;${t}m[${n}]\x1B[0m ${s}${r}`},cli(t){let n=this.labels.cli;console.log(this.formatMessage(this.colors.cli,n,t))},info(t){console.log(`\x1B[38;5;${this.colors.info}m${t}\x1B[0m`)},warn(t){let n=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,n,t))},error(t){let n=this.labels.error;console.error(this.formatMessage(this.colors.error,n,t))},progress(t,n,r){let e=String(t),s=this.colors.default;for(let[i,o]of Object.entries(this.colors.progress))if(e.includes(i)){s=o;break}console.log(this.formatMessage(s,e,n,r))}};function dt(t,n){return`${n?`${n.replace(/-/g,"_")}_`:""}${t}`.toUpperCase()}var B={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0,sourcemap:"none"};function xt(t,n){return{outdir:`${n}/${t.outDir}`,minify:zt(t),target:t.target,splitting:t.splitting,sourcemap:t.sourcemap}}function zt(t){let{minify:n,minifyWhitespace:r,minifyIdentifiers:e,minifySyntax:s}=t,i=n===!0;return{whitespace:r??i,identifiers:e??i,syntax:s??i}}async function ht(t){let n=[],r="";for(let e of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let s=z.default.join(t,`bunup.config${e}`);try{if(!F.default.existsSync(s))continue;let i;if(r=s,e===".json"||e===".jsonc"){let o=F.default.readFileSync(s,"utf8"),a=JSON.parse(o);i=a.bunup||a}else{let o=await import(`file://${s}`);if(i=o.default||o,!i)l.warn(`No default export found in ${s}`),i={}}if(Array.isArray(i))for(let o of i)n.push({options:{...B,...o},rootDir:t});else n.push({options:{...B,...i},rootDir:t});break}catch(i){throw new v(`Failed to load config from ${s}: ${m(i)}`)}}return{configs:n,configFilePath:r}}function q(t){let n=z.default.join(t,"package.json");try{if(!F.default.existsSync(n))return null;let r=F.default.readFileSync(n,"utf8");return JSON.parse(r)}catch(r){return l.warn(`Failed to load package.json at ${n}: ${m(r)}`),null}}function $t(t,n){return{name:"bunup:external-plugin",setup(r){r.onResolve({filter:/.*/},(e)=>{let s=e.path;if(t.some((o)=>o.test(s))&&!n.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}async function G(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new v("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=performance.now(),e=q(n),s=e?.type,i=T(t,e),o=U(t),a=[$t(i,o)],c=I(t.entry),g=t.format.flatMap((u)=>c.map((f)=>{return kt(t,n,f,u,s,a)}));try{await Promise.all(g);let u=performance.now()-r,f=W(u);l.cli(`\uD83D\uDCE6 Build success in ${f}`)}catch{throw new v("Build process encountered errors")}if(t.dts){let u=t.format.filter((E)=>{if(E==="iife"&&!L(s)&&t.format.includes("cjs"))return!1;return!0}),f=t.dts===!0?c:I(t.dts.entry);try{await k(n,f,u,t,s)}catch(E){throw new x(`DTS build process encountered errors: ${m(E)}`)}}}async function kt(t,n,r,e,s,i){let o=ct(e,s),a=xt(t,n),c=await Bun.build({...a,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:gt(r.name,o)},splitting:mt(t.splitting,e),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((f)=>{if(f.level==="error")l.error(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)}),new v(`Build failed for ${r} (${e})`);let g=`${t.outDir}/${r.name}${o}`,u=Bun.file(g).size||0;l.progress(dt(e,t.name),g,H(u))}function O(t){return(n,r)=>{r[t]=n===!0?!0:n==="true"}}function X(t){return(n,r)=>{if(typeof n==="string")r[t]=n;else throw new $(`Option --${t} requires a string value`)}}function wt(t){return(n,r)=>{if(typeof n==="string")r[t]=n.split(",");else throw new $(`Option --${t} requires a string value`)}}var Dt={name:{flags:["n","name"],handler:X("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new $("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:X("outDir")},minify:{flags:["m","minify"],handler:O("minify")},watch:{flags:["w","watch"],handler:O("watch")},dts:{flags:["d","dts"],handler:O("dts")},external:{flags:["e","external"],handler:wt("external")},sourcemap:{flags:["sm","sourcemap"],handler:X("sourcemap")},target:{flags:["t","target"],handler:X("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:O("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:O("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:O("minifySyntax")},clean:{flags:["c","clean"],handler:O("clean")},splitting:{flags:["s","splitting"],handler:O("splitting")},noExternal:{flags:["ne","no-external"],handler:wt("noExternal")}},D={};for(let t of Object.values(Dt))if(t)for(let n of t.flags)D[n]=t.handler;function yt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function Et(t){let n={},r={},e=0;while(e<t.length){let s=t[e];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=t[e+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")e++}if(i==="entry")if(typeof o==="string"){let a=yt(o);if(r[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);r[a]=o}else throw new $("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(r[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);r[a]=o}else throw new $(`Option --entry.${a} requires a string value`)}else{let a=D[i];if(a)a(o,n);else throw new $(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=t[e+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")e++;let c=D[i];if(c)c(a,n);else throw new $(`Unknown option: -${i}`)}else{let i=yt(s);if(r[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);r[i]=s}e++}if(Object.keys(r).length>0)n.entry=r;return n}(()=>{if(typeof Bun==="undefined")throw new $(`Bunup requires Bun to run.
|
|
4
|
+
To install Bun, visit https://bun.sh/docs/installation`)})();var J=d(require("node:fs")),Y=d(require("node:path")),vt=require("oxc-transform");function Ct(t,n){let r=Y.default.resolve(t),e=Y.default.resolve(r,n);if(!J.default.existsSync(r))throw new x(`Root directory does not exist: ${r}`);if(!J.default.existsSync(e))throw new x(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new x(`Entry file must be a TypeScript file (.ts): ${e}`);if(Y.default.relative(r,e).startsWith(".."))throw new x(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function Ot(t){let n=!1;if(await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.d\.ts$/,".ts"),s=await J.default.promises.readFile(e,"utf8"),{errors:i}=vt.isolatedDeclaration(e,s);i.forEach((o)=>{if(!n)console.log(`
|
|
5
|
+
`);let a=o.labels[0],c=a?tn(s,a.start):"",u=`${_(e)}${c}: ${nn(o.message)}`;l.warn(u),n=!0})}catch{}})),n)l.info(`
|
|
6
6
|
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.
|
|
7
7
|
`)}function tn(t,n){if(n===void 0)return"";let r=t.slice(0,n).split(`
|
|
8
|
-
`),
|
|
8
|
+
`),e=r.length,s=r[r.length-1].length+1;return` (${e}:${s})`}function nn(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var K=d(require("node:path")),Rt=d(require("chokidar"));async function St(t,n){let r=new Set,e=I(t.entry);e.forEach((c)=>{let g=K.default.resolve(n,c.path),u=K.default.dirname(g);r.add(u)});let s=Rt.default.watch(Array.from(r),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,t.outDir]}),i=null,o=!1,a=async()=>{if(o)return;o=!0;try{await G({...t,entry:e.map((c)=>c.path),clean:!1},n),t.onBuildEnd?.()}catch(c){throw new j(`Build failed: ${m(c)}`)}finally{o=!1}};s.on("change",(c)=>{let g=K.default.relative(n,c);if(l.cli(`File changed: ${g}`),i)clearTimeout(i);i=setTimeout(()=>a(),300)}),s.on("error",(c)=>{throw new j(`Watcher error: ${m(c)}`)}),await a()}var R=new Set;async function rn(t=Bun.argv.slice(2)){let n=Et(t),{configs:r,configFilePath:e}=await ht(process.cwd());l.cli(`Using config file: ${_(e,2)}`);let s=process.cwd();if(n.watch)l.cli("Starting watch mode"),l.cli("Watching for file changes");if(r.length===0){let i={...B,...n};if(i.clean)Bt(s,i.outDir);await Pt(i,s)}else{for(let{options:i,rootDir:o}of r)if(i.clean)Bt(o,i.outDir);l.cli("Build started"),await Promise.all(r.map(async({options:i,rootDir:o})=>{let a={...B,...i,...n};await Pt(a,o)}))}if(R.size>0)await Ot(R),R.clear();if(!n.watch)process.exit(0)}async function Pt(t,n){if(t.watch)await St(t,n);else await G(t,n),t.onBuildEnd?.()}function Bt(t,n){let r=bt.default.join(t,n);if(Q.default.existsSync(r))try{Q.default.rmSync(r,{recursive:!0,force:!0})}catch(e){throw new v(`Failed to clean output directory: ${e}`)}Q.default.mkdirSync(r,{recursive:!0})}if(At.isMainThread)rn().catch((t)=>at(t));var Nt=require("load-tsconfig");function jt(t){try{return Nt.loadTsConfig(".",t)}catch(n){return l.warn(`Failed to load tsconfig: ${m(n)}`),{path:t,data:{},files:[]}}}var S=d(require("node:path")),It=require("rollup"),Ft=d(require("rollup-plugin-dts")),V=d(require("typescript"));var en=()=>{return global.allFilesUsedToBundleDts||R||new Set};async function Mt(t,n,r,e,s){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,c=s.data?.compilerOptions,g={name:"bunup:virtual-dts",resolveId(p,w){if(p.startsWith("\x00virtual:"))return p;if(!w?.startsWith("\x00virtual:")||!p.startsWith("."))return null;let h=w.slice(9),b=S.default.resolve(S.default.dirname(h),p);if(p==="."){let A=S.default.join(S.default.dirname(h),"index.d.ts");if(n.has(A))return`\x00virtual:${A}`;b=S.default.dirname(h)}if(n.has(b))return`\x00virtual:${b}`;let et=`${b}.d.ts`;if(n.has(et))return`\x00virtual:${et}`;if(p.startsWith(".")){let A=S.default.join(b,"index.d.ts");if(n.has(A))return`\x00virtual:${A}`}return null},load(p){if(p.startsWith("\x00virtual:")){let w=p.slice(9),h=n.get(w);if(h)return en().add(w),h}return null}},u=q(e),f=T(r,u),E=U(r),C;try{C=await It.rollup({input:a,onwarn(w,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(w.code??""))return;h(w)},plugins:[g,Ft.default({tsconfig:s.path,compilerOptions:{...c?V.default.parseJsonConfigFileContent({compilerOptions:c},V.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:V.default.ScriptTarget.ESNext}})],external:(w)=>f.some((h)=>h.test(w))&&!E.some((h)=>h.test(w))});let{output:p}=await C.generate({});if(!p[0]?.code)throw new x("Generated bundle is empty");return p[0].code}catch(p){throw new x(`DTS bundling failed: ${m(p)}`)}finally{if(C)await C.close()}}var rt=d(require("node:fs")),nt=d(require("node:path"));var M=d(require("node:path"));function tt(t){let n=M.default.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?M.default.resolve(n,t.data.compilerOptions.baseUrl):n}function Lt(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=tt(t);for(let[s,i]of Object.entries(r))if(Array.isArray(i)&&i.length){let o=s.replace(/\*/g,"(.*)"),a=i[0].replace(/\*/g,"$1");n.set(`^${o}$`,M.default.join(e,a))}return n}function Wt(t,n,r){for(let[e,s]of n){let i=new RegExp(e),o=t.match(i);if(o)return s.replace("$1",o[1]||"")}return r?M.default.join(r,t):null}var sn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,on=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Ht(t,n){let r=new Set([t]),e=[t],s=Lt(n),i=tt(n);while(e.length){let o=e.pop();if(!o)continue;try{let a=await rt.default.promises.readFile(o,"utf8"),c=an(a);for(let g of c){let u=g.startsWith(".")?nt.default.resolve(nt.default.dirname(o),g):Wt(g,s,i);if(!u)continue;let f=ln(u);if(f&&!r.has(f))r.add(f),e.push(f)}}catch(a){l.warn(`Error processing ${o}: ${m(a)}`)}}return r}function an(t){let n=new Set;for(let r of[sn,on]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}function ln(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(rt.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}var _t=d(require("node:fs")),Tt=require("oxc-transform");async function Ut(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),s=await _t.default.promises.readFile(r,"utf8"),{code:i}=Tt.isolatedDeclaration(r,s);if(i)n.set(e,i)}catch(e){l.warn(`Failed to generate declaration for ${r}: ${m(e)}`)}})),n}async function qt(t,n,r){let{absoluteRootDir:e,absoluteEntry:s}=Ct(t,n),i=jt(r.preferredTsconfigPath),o=await Ht(s,i),a=await Ut(o);return Mt(s,a,r,e,i)}async function k(t,n,r,e,s){return new Promise((i,o)=>{let{onBuildEnd:a,...c}=e,g={rootDir:t,entries:n,formats:r,options:c,packageType:s},u=new y.Worker(new URL("./dtsWorker.js",import.meta.url),{workerData:g});u.on("message",async(f)=>{if(f.success){let E=W(f.timeMs);if(l.progress("DTS",`Bundled types in ${E}`),f.filesUsed)f.filesUsed.forEach((C)=>R.add(C));i()}else o(new x(f.error||"Unknown DTS worker error"))}),u.on("error",o),u.on("exit",(f)=>{if(f!==0)o(new x(`DTS worker stopped with exit code ${f}`))})})}if(!y.isMainThread&&y.parentPort){let{rootDir:t,entries:n,formats:r,options:e,packageType:s}=y.workerData,i=performance.now(),o=new Set;global.allFilesUsedToBundleDts=o,l.progress("DTS","Bundling types");try{(async()=>{try{await Promise.all(n.map(async(c)=>{let g=await qt(t,c.path,e);await Promise.all(r.map(async(u)=>{let f=ft(u,s),E=`${e.outDir}/${c.name}${f}`,C=`${t}/${E}`;await Bun.write(C,g);let p=Bun.file(C).size||0;l.progress("DTS",E,H(p))}))}));let a=performance.now()-i;y.parentPort?.postMessage({success:!0,timeMs:a,filesUsed:[...o]})}catch(a){y.parentPort?.postMessage({success:!1,error:m(a)})}})()}catch(a){y.parentPort?.postMessage({success:!1,error:m(a)})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@types/bun": "^1.2.5",
|
|
19
19
|
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
20
20
|
"bumpp": "^10.1.0",
|
|
21
|
-
"bunup": "^0.1.
|
|
21
|
+
"bunup": "^0.1.38",
|
|
22
22
|
"eslint": "^8.57.0",
|
|
23
23
|
"husky": "^9.1.6",
|
|
24
24
|
"prettier": "^3.2.5",
|