bunup 0.1.26 → 0.1.28

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 CHANGED
@@ -4,8 +4,6 @@ A extremely fast, zero-config bundler for TypeScript & JavaScript, powered by [B
4
4
 
5
5
  ![Demo](/demo.gif)
6
6
 
7
- > Built with speed in mind, Bunup aims to provide the fastest bundling experience possible. This project is currently a work in progress and will be ready for production use soon.
8
-
9
7
  ## Benchmarks
10
8
 
11
9
  Bunup outperforms other popular bundlers by a significant margin:
@@ -18,3 +16,580 @@ Bunup outperforms other popular bundlers by a significant margin:
18
16
  | tsup (+ dts) | esm, cjs | 745.23ms | baseline |
19
17
 
20
18
  _Lower build time is better. Benchmark run on the same code with identical output formats._
19
+
20
+ ## Table of Contents
21
+
22
+ 1. [Quick Start](#quick-start)
23
+ 2. [Configuration](#configuration)
24
+ - [Configuration File](#configuration-file)
25
+ - [CLI Options](#cli-options)
26
+ 3. [Entry Points](#entry-points)
27
+ 4. [Output Formats](#output-formats)
28
+ 5. [TypeScript Declarations](#typescript-declarations)
29
+ 6. [External Dependencies](#external-dependencies)
30
+ 7. [Code Splitting](#code-splitting)
31
+ 8. [Minification](#minification)
32
+ 9. [Watch Mode](#watch-mode)
33
+ 10. [API Reference](#api-reference)
34
+ 11. [Examples](#examples)
35
+
36
+ ## Quick Start
37
+
38
+ ### Installation
39
+
40
+ ```bash
41
+ # Install bunup
42
+ npm install --save-dev bunup
43
+
44
+ # Or with yarn
45
+ yarn add --dev bunup
46
+
47
+ # Or with pnpm
48
+ pnpm add --save-dev bunup
49
+
50
+ # Or with bun
51
+ bun add --dev bunup
52
+ ```
53
+
54
+ ### Basic Usage
55
+
56
+ Create a simple TypeScript file:
57
+
58
+ ```typescript
59
+ // src/index.ts
60
+ export function greet(name: string): string {
61
+ return `Hello, ${name}!`;
62
+ }
63
+ ```
64
+
65
+ Bundle it with bunup:
66
+
67
+ ```bash
68
+ bunup --entry src/index.ts
69
+ ```
70
+
71
+ This will create a bundled output in the `dist` directory.
72
+
73
+ ### Using with package.json
74
+
75
+ Add a build script to your `package.json`:
76
+
77
+ ```json
78
+ {
79
+ "name": "my-package",
80
+ "scripts": {
81
+ "build": "bunup --entry src/index.ts --format esm,cjs --dts"
82
+ }
83
+ }
84
+ ```
85
+
86
+ Then run:
87
+
88
+ ```bash
89
+ npm run build
90
+ ```
91
+
92
+ ### Configuration File
93
+
94
+ Create a `bunup.config.ts` file for more control:
95
+
96
+ ```typescript
97
+ import {defineConfig} from 'bunup';
98
+
99
+ export default defineConfig({
100
+ entry: ['src/index.ts'],
101
+ outDir: 'dist',
102
+ format: ['esm', 'cjs'],
103
+ dts: true,
104
+ minify: true,
105
+ });
106
+ ```
107
+
108
+ ## Configuration
109
+
110
+ ### Configuration File
111
+
112
+ Bunup supports configuration files in multiple formats:
113
+
114
+ - `bunup.config.ts`
115
+ - `bunup.config.js`
116
+ - `bunup.config.mjs`
117
+ - `bunup.config.cjs`
118
+ - `bunup.config.json`
119
+ - `bunup.config.jsonc`
120
+
121
+ Example configuration:
122
+
123
+ ```typescript
124
+ import {defineConfig} from 'bunup';
125
+
126
+ export default defineConfig({
127
+ // Name for this build configuration (used in logs)
128
+ name: 'my-library',
129
+
130
+ // Entry points (can be an array or object)
131
+ entry: ['src/index.ts', 'src/cli.ts'],
132
+
133
+ // Output directory
134
+ outDir: 'dist',
135
+
136
+ // Output formats
137
+ format: ['esm', 'cjs'],
138
+
139
+ // TypeScript declaration generation
140
+ dts: true,
141
+
142
+ // Target environment
143
+ target: 'node',
144
+
145
+ // Minification options
146
+ minify: true,
147
+
148
+ // External dependencies
149
+ external: ['react', 'react-dom'],
150
+
151
+ // Clean output directory before build
152
+ clean: true,
153
+ });
154
+ ```
155
+
156
+ You can also export an array of configurations:
157
+
158
+ ```typescript
159
+ export default defineConfig([
160
+ {
161
+ name: 'node',
162
+ entry: ['src/index.ts'],
163
+ format: ['cjs'],
164
+ target: 'node',
165
+ },
166
+ {
167
+ name: 'browser',
168
+ entry: ['src/index.ts'],
169
+ format: ['esm', 'iife'],
170
+ target: 'browser',
171
+ },
172
+ ]);
173
+ ```
174
+
175
+ ### CLI Options
176
+
177
+ Bunup supports various command-line options:
178
+
179
+ | Option | Alias | Description |
180
+ | ----------------------- | ----- | ---------------------------------------------- |
181
+ | `--entry <path>` | | Entry file path |
182
+ | `--entry.<name> <path>` | | Named entry file path |
183
+ | `--out-dir <dir>` | `-o` | Output directory |
184
+ | `--format <formats>` | `-f` | Output formats (comma-separated: esm,cjs,iife) |
185
+ | `--minify` | `-m` | Enable all minification options |
186
+ | `--minify-whitespace` | `-mw` | Minify whitespace |
187
+ | `--minify-identifiers` | `-mi` | Minify identifiers |
188
+ | `--minify-syntax` | `-ms` | Minify syntax |
189
+ | `--watch` | `-w` | Watch mode |
190
+ | `--dts` | `-d` | Generate TypeScript declarations |
191
+ | `--external <deps>` | `-e` | External dependencies (comma-separated) |
192
+ | `--no-external <deps>` | `-ne` | Force include dependencies (comma-separated) |
193
+ | `--target <target>` | `-t` | Target environment (node, browser, bun) |
194
+ | `--clean` | `-c` | Clean output directory before build |
195
+ | `--splitting` | `-s` | Enable code splitting |
196
+ | `--name <name>` | `-n` | Name for this build configuration |
197
+
198
+ Examples:
199
+
200
+ ```bash
201
+ # Basic usage
202
+ bunup --entry src/index.ts
203
+
204
+ # Multiple formats with TypeScript declarations
205
+ bunup --entry src/index.ts --format esm,cjs --dts
206
+
207
+ # Named entries
208
+ bunup --entry.main src/index.ts --entry.cli src/cli.ts
209
+
210
+ # Watch mode
211
+ bunup --entry src/index.ts --watch
212
+ ```
213
+
214
+ ## Entry Points
215
+
216
+ Bunup supports multiple ways to define entry points:
217
+
218
+ ### Array of Paths
219
+
220
+ ```typescript
221
+ export default defineConfig({
222
+ entry: ['src/index.ts', 'src/cli.ts'],
223
+ });
224
+ ```
225
+
226
+ This will generate output files named after the input files (e.g., `index.js` and `cli.js`).
227
+
228
+ ### Named Entries
229
+
230
+ ```typescript
231
+ export default defineConfig({
232
+ entry: {
233
+ main: 'src/index.ts',
234
+ cli: 'src/cli.ts',
235
+ utils: 'src/utils/index.ts',
236
+ },
237
+ });
238
+ ```
239
+
240
+ This will generate output files with the specified names (e.g., `main.js`, `cli.js`, and `utils.js`).
241
+
242
+ ## Output Formats
243
+
244
+ Bunup supports three output formats:
245
+
246
+ - **esm**: ECMAScript modules (`.mjs` extension)
247
+ - **cjs**: CommonJS modules (`.js` or `.cjs` extension)
248
+ - **iife**: Immediately Invoked Function Expression (`.global.js` extension)
249
+
250
+ ```typescript
251
+ export default defineConfig({
252
+ entry: ['src/index.ts'],
253
+ format: ['esm', 'cjs', 'iife'],
254
+ });
255
+ ```
256
+
257
+ The file extensions are determined automatically based on the format and your package.json `type` field:
258
+
259
+ | Format | package.json type: "module" | package.json type: "commonjs" or unspecified |
260
+ | ------ | --------------------------- | -------------------------------------------- |
261
+ | esm | `.mjs` | `.mjs` |
262
+ | cjs | `.cjs` | `.js` |
263
+ | iife | `.global.js` | `.global.js` |
264
+
265
+ ## TypeScript Declarations
266
+
267
+ Bunup can generate TypeScript declaration files (`.d.ts`) for your code:
268
+
269
+ ```typescript
270
+ export default defineConfig({
271
+ entry: ['src/index.ts'],
272
+ dts: true,
273
+ });
274
+ ```
275
+
276
+ For more control, you can specify custom entry points for declarations:
277
+
278
+ ```typescript
279
+ export default defineConfig({
280
+ entry: ['src/index.ts', 'src/cli.ts'],
281
+ dts: {
282
+ entry: ['src/index.ts'], // Only generate declarations for index.ts
283
+ },
284
+ });
285
+ ```
286
+
287
+ Or use named entries:
288
+
289
+ ```typescript
290
+ export default defineConfig({
291
+ entry: {
292
+ main: 'src/index.ts',
293
+ cli: 'src/cli.ts',
294
+ },
295
+ dts: {
296
+ entry: {
297
+ types: 'src/index.ts', // Generate types.d.ts from index.ts
298
+ },
299
+ },
300
+ });
301
+ ```
302
+
303
+ You can also specify a custom tsconfig file for declaration generation:
304
+
305
+ ```typescript
306
+ export default defineConfig({
307
+ entry: ['src/index.ts'],
308
+ dts: true,
309
+ preferredTsconfigPath: './tsconfig.build.json',
310
+ });
311
+ ```
312
+
313
+ Declaration file extensions follow the same pattern as JavaScript files:
314
+
315
+ | Format | package.json type: "module" | package.json type: "commonjs" or unspecified |
316
+ | ------ | --------------------------- | -------------------------------------------- |
317
+ | esm | `.d.mts` | `.d.mts` |
318
+ | cjs | `.d.cts` | `.d.ts` |
319
+ | iife | `.d.ts` | `.d.ts` |
320
+
321
+ ## External Dependencies
322
+
323
+ By default, Bunup treats all dependencies from your `package.json` (`dependencies` and `peerDependencies`) as external. This means they won't be included in your bundle.
324
+
325
+ You can explicitly mark additional packages as external:
326
+
327
+ ```typescript
328
+ export default defineConfig({
329
+ entry: ['src/index.ts'],
330
+ external: ['lodash', 'react', '@some/package'],
331
+ });
332
+ ```
333
+
334
+ You can also force include specific dependencies that would otherwise be external:
335
+
336
+ ```typescript
337
+ export default defineConfig({
338
+ entry: ['src/index.ts'],
339
+ external: ['lodash'],
340
+ noExternal: ['lodash/merge'], // Include lodash/merge even though lodash is external
341
+ });
342
+ ```
343
+
344
+ Both `external` and `noExternal` support string patterns and regular expressions.
345
+
346
+ ## Code Splitting
347
+
348
+ Bunup supports code splitting for the ESM format:
349
+
350
+ ```typescript
351
+ export default defineConfig({
352
+ entry: ['src/index.ts'],
353
+ format: ['esm'],
354
+ splitting: true, // Default is true for ESM
355
+ });
356
+ ```
357
+
358
+ Code splitting is enabled by default for ESM format and disabled for CJS and IIFE formats. You can explicitly enable or disable it:
359
+
360
+ ```typescript
361
+ export default defineConfig({
362
+ entry: ['src/index.ts'],
363
+ format: ['esm', 'cjs'],
364
+ splitting: false, // Disable code splitting for all formats
365
+ });
366
+ ```
367
+
368
+ ## Minification
369
+
370
+ Bunup provides several minification options:
371
+
372
+ ```typescript
373
+ export default defineConfig({
374
+ entry: ['src/index.ts'],
375
+
376
+ // Enable all minification options
377
+ minify: true,
378
+
379
+ // Or configure individual options
380
+ minifyWhitespace: true,
381
+ minifyIdentifiers: false,
382
+ minifySyntax: true,
383
+ });
384
+ ```
385
+
386
+ The `minify` option is a shorthand that enables all three specific options. If you set individual options, they take precedence over the `minify` setting.
387
+
388
+ ## Watch Mode
389
+
390
+ Bunup can watch your files for changes and rebuild automatically:
391
+
392
+ ```typescript
393
+ export default defineConfig({
394
+ entry: ['src/index.ts'],
395
+ watch: true,
396
+ });
397
+ ```
398
+
399
+ Or use the CLI flag:
400
+
401
+ ```bash
402
+ bunup --entry src/index.ts --watch
403
+ ```
404
+
405
+ In watch mode, Bunup will monitor your source files and their dependencies, rebuilding only what's necessary when files change.
406
+
407
+ ## API Reference
408
+
409
+ ### BunupOptions
410
+
411
+ The complete configuration options interface:
412
+
413
+ ```typescript
414
+ interface BunupOptions {
415
+ /**
416
+ * Name of the build configuration
417
+ * Used for logging and identification purposes
418
+ */
419
+ name?: string;
420
+
421
+ /**
422
+ * Entry point files for the build
423
+ * Can be an array of file paths or an object with named entries
424
+ */
425
+ entry: string[] | Record<string, string>;
426
+
427
+ /**
428
+ * Output directory for the bundled files
429
+ * Defaults to 'dist'
430
+ */
431
+ outDir: string;
432
+
433
+ /**
434
+ * Output formats for the bundle
435
+ * Can include 'esm', 'cjs', and/or 'iife'
436
+ * Defaults to ['cjs']
437
+ */
438
+ format: ('esm' | 'cjs' | 'iife')[];
439
+
440
+ /**
441
+ * Whether to enable all minification options
442
+ */
443
+ minify?: boolean;
444
+
445
+ /**
446
+ * Whether to enable code splitting
447
+ * Defaults to true for ESM format, false for CJS format
448
+ */
449
+ splitting?: boolean;
450
+
451
+ /**
452
+ * Whether to minify whitespace in the output
453
+ */
454
+ minifyWhitespace?: boolean;
455
+
456
+ /**
457
+ * Whether to minify identifiers in the output
458
+ */
459
+ minifyIdentifiers?: boolean;
460
+
461
+ /**
462
+ * Whether to minify syntax in the output
463
+ */
464
+ minifySyntax?: boolean;
465
+
466
+ /**
467
+ * Whether to watch for file changes and rebuild automatically
468
+ */
469
+ watch?: boolean;
470
+
471
+ /**
472
+ * Whether to generate TypeScript declaration files (.d.ts)
473
+ * When set to true, generates declaration files for all entry points
474
+ * Can also be configured with DtsOptions for more control
475
+ */
476
+ dts?:
477
+ | boolean
478
+ | {
479
+ entry: string[] | Record<string, string>;
480
+ };
481
+
482
+ /**
483
+ * Path to a preferred tsconfig.json file to use for declaration generation
484
+ */
485
+ preferredTsconfigPath?: string;
486
+
487
+ /**
488
+ * External packages that should not be bundled
489
+ */
490
+ external?: string[];
491
+
492
+ /**
493
+ * Packages that should be bundled even if they are in external
494
+ */
495
+ noExternal?: string[];
496
+
497
+ /**
498
+ * The target environment for the bundle
499
+ * Can be 'browser', 'bun', 'node'
500
+ * Defaults to 'node'
501
+ */
502
+ target?: 'browser' | 'bun' | 'node';
503
+
504
+ /**
505
+ * Whether to clean the output directory before building
506
+ * Defaults to true
507
+ */
508
+ clean?: boolean;
509
+ }
510
+ ```
511
+
512
+ ### Default Options
513
+
514
+ ```typescript
515
+ const DEFAULT_OPTIONS = {
516
+ entry: [],
517
+ format: ['cjs'],
518
+ outDir: 'dist',
519
+ minify: false,
520
+ watch: false,
521
+ dts: false,
522
+ target: 'node',
523
+ external: [],
524
+ clean: true,
525
+ };
526
+ ```
527
+
528
+ ## Examples
529
+
530
+ ### Basic Library
531
+
532
+ ```typescript
533
+ // bunup.config.ts
534
+ import {defineConfig} from 'bunup';
535
+
536
+ export default defineConfig({
537
+ entry: ['src/index.ts'],
538
+ format: ['esm', 'cjs'],
539
+ dts: true,
540
+ });
541
+ ```
542
+
543
+ ### Multiple Entry Points
544
+
545
+ ```typescript
546
+ // bunup.config.ts
547
+ import {defineConfig} from 'bunup';
548
+
549
+ export default defineConfig({
550
+ entry: {
551
+ index: 'src/index.ts',
552
+ cli: 'src/cli.ts',
553
+ },
554
+ format: ['esm', 'cjs'],
555
+ dts: true,
556
+ });
557
+ ```
558
+
559
+ ### Browser and Node Targets
560
+
561
+ ```typescript
562
+ // bunup.config.ts
563
+ import {defineConfig} from 'bunup';
564
+
565
+ export default defineConfig([
566
+ {
567
+ name: 'node',
568
+ entry: ['src/index.ts'],
569
+ format: ['cjs', 'esm'],
570
+ target: 'node',
571
+ outDir: 'dist/node',
572
+ },
573
+ {
574
+ name: 'browser',
575
+ entry: ['src/index.ts'],
576
+ format: ['esm', 'iife'],
577
+ target: 'browser',
578
+ outDir: 'dist/browser',
579
+ },
580
+ ]);
581
+ ```
582
+
583
+ ### With Minification
584
+
585
+ ```typescript
586
+ // bunup.config.ts
587
+ import {defineConfig} from 'bunup';
588
+
589
+ export default defineConfig({
590
+ entry: ['src/index.ts'],
591
+ format: ['esm', 'cjs'],
592
+ minify: true,
593
+ dts: true,
594
+ });
595
+ ```
package/build/cli.mjs CHANGED
@@ -2,9 +2,9 @@
2
2
  // @bun
3
3
  import Q from"fs";import Vt from"path";import{isMainThread as Zt}from"worker_threads";import{isMainThread as qt,parentPort as W,Worker as Gt,workerData as Xt}from"node:worker_threads";class R extends Error{constructor(t){super(t);this.name="BunupError"}}class $ extends R{constructor(t){super(t);this.name="BunupBuildError"}}class g extends R{constructor(t){super(t);this.name="BunupDTSBuildError"}}class h extends R{constructor(t){super(t);this.name="BunupCLIError"}}class B extends R{constructor(t){super(t);this.name="BunupWatchError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)},St=(t,n)=>{let r=p(t),e=n?`[${n}] `:"",s="ERROR";if(t instanceof $)s="BUILD ERROR";else if(t instanceof g)s="DTS ERROR";else if(t instanceof h)s="CLI ERROR";else if(t instanceof B)s="WATCH ERROR";else if(t instanceof R)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")},Z=(t,n)=>{St(t,n),process.exit(1)};var f={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,n,r){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));return`\x1B[38;5;${t}m[${n}]\x1B[0m ${e}${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){let r=String(t),e=this.colors.default;for(let[s,i]of Object.entries(this.colors.progress))if(r.includes(s)){e=i;break}console.log(this.formatMessage(e,r,n))}};function k(t,n){return`${n?`${n.replace(/-/g,"_")}_`:""}${t}`.toUpperCase()}function T(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function z(t=8){return Math.random().toString(36).substring(2,2+t)}function D(t,n){switch(t){case"esm":return".mjs";case"cjs":return N(n)?".cjs":".js";case"iife":return".global.js"}}function tt(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 I(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function nt(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function rt(t,n){return t===void 0?n==="esm":t}import{loadTsConfig as bt}from"load-tsconfig";function et(t){try{return bt(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import P from"node:path";import{rollup as At}from"rollup";import Nt from"rollup-plugin-dts";import U from"typescript";function st(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${T(n)}($|\\/|\\\\)`):n)}function j(t,n){return st(t.external||[]).concat(nt(n).map((r)=>new RegExp(`^${T(r)}($|\\/|\\\\)`)))}function L(t){return st(t.noExternal||[])}import M from"node:fs";import ot from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0};function it(t,n){return{outdir:`${n}/${t.outDir}`,minify:Bt(t),target:t.target,splitting:t.splitting}}function Bt(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 at(t){let n=[];for(let r of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let e=ot.join(t,`bunup.config${r}`);try{if(!M.existsSync(e))continue;let s;if(r===".json"||r===".jsonc"){let i=M.readFileSync(e,"utf8");s=JSON.parse(i)}else{let i=await import(`file://${e}`);if(s=i.default||i,!s)f.warn(`No default export found in ${e}`),s={}}if(Array.isArray(s))for(let i of s)n.push({options:{...O,...i},rootDir:t});else n.push({options:{...O,...s},rootDir:t});break}catch(s){throw new $(`Failed to load config from ${e}: ${p(s)}`)}if(n.length>0)break}return n}function F(t){let n=ot.join(t,"package.json");try{if(!M.existsSync(n))return null;let r=M.readFileSync(n,"utf8");return JSON.parse(r)}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),null}}var It=()=>{return global.allFilesUsedToBundleDts||C||new Set};async function lt(t,n,r,e,s){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,c=s.data?.compilerOptions,l={name:"bunup:virtual-dts",resolveId(d,y){if(d.startsWith("\x00virtual:"))return d;if(!y?.startsWith("\x00virtual:")||!d.startsWith("."))return null;let x=y.slice(9),S=P.resolve(P.dirname(x),d);if(d==="."){let b=P.join(P.dirname(x),"index.d.ts");if(n.has(b))return`\x00virtual:${b}`;S=P.dirname(x)}if(n.has(S))return`\x00virtual:${S}`;let V=`${S}.d.ts`;if(n.has(V))return`\x00virtual:${V}`;if(d.startsWith(".")){let b=P.join(S,"index.d.ts");if(n.has(b))return`\x00virtual:${b}`}return null},load(d){if(d.startsWith("\x00virtual:")){let y=d.slice(9),x=n.get(y);if(x)return It().add(y),x}return null}},m=F(e),u=j(r,m),E=L(r),v;try{v=await At({input:a,onwarn(y,x){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(y.code??""))return;x(y)},plugins:[l,Nt({tsconfig:s.path,compilerOptions:{...c?U.parseJsonConfigFileContent({compilerOptions:c},U.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:U.ScriptTarget.ESNext}})],external:(y)=>u.some((x)=>x.test(y))&&!E.some((x)=>x.test(y))});let{output:d}=await v.generate({});if(!d[0]?.code)throw new g("Generated bundle is empty");return d[0].code}catch(d){throw new g(`DTS bundling failed: ${p(d)}`)}finally{if(v)await v.close()}}import pt from"node:fs";import ut from"node:path";import H from"node:path";function q(t){let n=H.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?H.resolve(n,t.data.compilerOptions.baseUrl):n}function ct(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=q(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}$`,H.join(e,a))}return n}function ft(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?H.join(r,t):null}var jt=/(?: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 mt(t,n){let r=new Set([t]),e=[t],s=ct(n),i=q(n);while(e.length){let o=e.pop();if(!o)continue;try{let a=await pt.promises.readFile(o,"utf8"),c=Mt(a);for(let l of c){let m=l.startsWith(".")?ut.resolve(ut.dirname(o),l):ft(l,s,i);if(!m)continue;let u=Ft(m);if(u&&!r.has(u))r.add(u),e.push(u)}}catch(a){f.warn(`Error processing ${o}: ${p(a)}`)}}return r}function Mt(t){let n=new Set;for(let r of[jt,Lt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}function Ft(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 Ht from"node:fs";import{isolatedDeclaration as Wt}from"oxc-transform";async function gt(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),s=await Ht.promises.readFile(r,"utf8"),{code:i}=Wt(r,s);if(i)n.set(e,i)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}import X from"node:fs";import G from"node:path";import{isolatedDeclaration as _t}from"oxc-transform";function dt(t,n){let r=G.resolve(t),e=G.resolve(r,n);if(!X.existsSync(r))throw new g(`Root directory does not exist: ${r}`);if(!X.existsSync(e))throw new g(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${e}`);if(G.relative(r,e).startsWith(".."))throw new g(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function xt(t){if(t.size===0)return;let n=!1;if(console.log(`
6
- `),await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.d\.ts$/,".ts"),s=await X.promises.readFile(e,"utf8"),{errors:i}=_t(e,s);i.forEach((o)=>{let a=o.labels[0],c=a?Tt(s,a.start):"",u=`${e.split("/").slice(-3).join("/")}${c}: ${Ut(o.message)}`;f.warn(u),n=!0})}catch{}})),n)f.info(`
5
+ `)+"\x1B[0m")},Z=(t,n)=>{St(t,n),process.exit(1)};var f={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,n,r){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));return`\x1B[38;5;${t}m[${n}]\x1B[0m ${e}${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){let r=String(t),e=this.colors.default;for(let[s,i]of Object.entries(this.colors.progress))if(r.includes(s)){e=i;break}console.log(this.formatMessage(e,r,n))}};function k(t,n){return`${n?`${n.replace(/-/g,"_")}_`:""}${t}`.toUpperCase()}function _(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function z(t=8){return Math.random().toString(36).substring(2,2+t)}function D(t,n){switch(t){case"esm":return".mjs";case"cjs":return N(n)?".cjs":".js";case"iife":return".global.js"}}function tt(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 I(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function nt(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function rt(t,n){return t===void 0?n==="esm":t}import{loadTsConfig as bt}from"load-tsconfig";function et(t){try{return bt(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}import P from"node:path";import{rollup as At}from"rollup";import Nt from"rollup-plugin-dts";import U from"typescript";function st(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${_(n)}($|\\/|\\\\)`):n)}function j(t,n){return st(t.external||[]).concat(nt(n).map((r)=>new RegExp(`^${_(r)}($|\\/|\\\\)`)))}function L(t){return st(t.noExternal||[])}import M from"node:fs";import ot from"node:path";var O={entry:[],format:["cjs"],outDir:"dist",minify:!1,watch:!1,dts:!1,target:"node",external:[],clean:!0};function it(t,n){return{outdir:`${n}/${t.outDir}`,minify:Bt(t),target:t.target,splitting:t.splitting}}function Bt(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 at(t){let n=[];for(let r of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let e=ot.join(t,`bunup.config${r}`);try{if(!M.existsSync(e))continue;let s;if(r===".json"||r===".jsonc"){let i=M.readFileSync(e,"utf8");s=JSON.parse(i)}else{let i=await import(`file://${e}`);if(s=i.default||i,!s)f.warn(`No default export found in ${e}`),s={}}if(Array.isArray(s))for(let i of s)n.push({options:{...O,...i},rootDir:t});else n.push({options:{...O,...s},rootDir:t});break}catch(s){throw new $(`Failed to load config from ${e}: ${p(s)}`)}if(n.length>0)break}return n}function F(t){let n=ot.join(t,"package.json");try{if(!M.existsSync(n))return null;let r=M.readFileSync(n,"utf8");return JSON.parse(r)}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),null}}var It=()=>{return global.allFilesUsedToBundleDts||C||new Set};async function lt(t,n,r,e,s){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,c=s.data?.compilerOptions,l={name:"bunup:virtual-dts",resolveId(d,y){if(d.startsWith("\x00virtual:"))return d;if(!y?.startsWith("\x00virtual:")||!d.startsWith("."))return null;let x=y.slice(9),S=P.resolve(P.dirname(x),d);if(d==="."){let b=P.join(P.dirname(x),"index.d.ts");if(n.has(b))return`\x00virtual:${b}`;S=P.dirname(x)}if(n.has(S))return`\x00virtual:${S}`;let V=`${S}.d.ts`;if(n.has(V))return`\x00virtual:${V}`;if(d.startsWith(".")){let b=P.join(S,"index.d.ts");if(n.has(b))return`\x00virtual:${b}`}return null},load(d){if(d.startsWith("\x00virtual:")){let y=d.slice(9),x=n.get(y);if(x)return It().add(y),x}return null}},m=F(e),u=j(r,m),E=L(r),v;try{v=await At({input:a,onwarn(y,x){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(y.code??""))return;x(y)},plugins:[l,Nt({tsconfig:s.path,compilerOptions:{...c?U.parseJsonConfigFileContent({compilerOptions:c},U.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:U.ScriptTarget.ESNext}})],external:(y)=>u.some((x)=>x.test(y))&&!E.some((x)=>x.test(y))});let{output:d}=await v.generate({});if(!d[0]?.code)throw new g("Generated bundle is empty");return d[0].code}catch(d){throw new g(`DTS bundling failed: ${p(d)}`)}finally{if(v)await v.close()}}import pt from"node:fs";import ut from"node:path";import H from"node:path";function q(t){let n=H.dirname(t.path||"");return t.data?.compilerOptions?.baseUrl?H.resolve(n,t.data.compilerOptions.baseUrl):n}function ct(t){let n=new Map,r=t.data?.compilerOptions?.paths;if(!r)return n;let e=q(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}$`,H.join(e,a))}return n}function ft(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?H.join(r,t):null}var jt=/(?: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 mt(t,n){let r=new Set([t]),e=[t],s=ct(n),i=q(n);while(e.length){let o=e.pop();if(!o)continue;try{let a=await pt.promises.readFile(o,"utf8"),c=Mt(a);for(let l of c){let m=l.startsWith(".")?ut.resolve(ut.dirname(o),l):ft(l,s,i);if(!m)continue;let u=Ft(m);if(u&&!r.has(u))r.add(u),e.push(u)}}catch(a){f.warn(`Error processing ${o}: ${p(a)}`)}}return r}function Mt(t){let n=new Set;for(let r of[jt,Lt]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}function Ft(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 Ht from"node:fs";import{isolatedDeclaration as Wt}from"oxc-transform";async function gt(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),s=await Ht.promises.readFile(r,"utf8"),{code:i}=Wt(r,s);if(i)n.set(e,i)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}import X from"node:fs";import G from"node:path";import{isolatedDeclaration as Tt}from"oxc-transform";function dt(t,n){let r=G.resolve(t),e=G.resolve(r,n);if(!X.existsSync(r))throw new g(`Root directory does not exist: ${r}`);if(!X.existsSync(e))throw new g(`Entry file does not exist: ${e}`);if(!e.endsWith(".ts"))throw new g(`Entry file must be a TypeScript file (.ts): ${e}`);if(G.relative(r,e).startsWith(".."))throw new g(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function xt(t){let n=!1;if(await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.d\.ts$/,".ts"),s=await X.promises.readFile(e,"utf8"),{errors:i}=Tt(e,s);i.forEach((o)=>{if(!n)console.log(`
6
+ `);let a=o.labels[0],c=a?_t(s,a.start):"",u=`${e.split("/").slice(-3).join("/")}${c}: ${Ut(o.message)}`;f.warn(u),n=!0})}catch{}})),n)f.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 Tt(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 Ut(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function ht(t,n,r){let{absoluteRootDir:e,absoluteEntry:s}=dt(t,n),i=et(r.preferredTsconfigPath),o=await mt(s,i),a=await gt(o);return lt(s,a,r,e,i)}async function yt(t,n,r,e,s){return new Promise((i,o)=>{let a={rootDir:t,entries:n,formats:r,options:e,packageType:s},c=new Gt(new URL("./dtsWorker.js",import.meta.url),{workerData:a});c.on("message",async(l)=>{if(l.success){let m=I(l.timeMs);if(f.progress("DTS",`Bundled types in ${m}`),l.filesUsed)l.filesUsed.forEach((u)=>C.add(u));i()}else o(new g(l.error||"Unknown DTS worker error"))}),c.on("error",o),c.on("exit",(l)=>{if(l!==0)o(new g(`DTS worker stopped with exit code ${l}`))})})}if(!qt&&W){let{rootDir:t,entries:n,formats:r,options:e,packageType:s}=Xt,i=performance.now(),o=new Set;global.allFilesUsedToBundleDts=o,f.progress("DTS","Bundling types");try{(async()=>{try{await Promise.all(n.map(async(c)=>{let l=await ht(t,c.path,e);await Promise.all(r.map(async(m)=>{let u=tt(m,s),E=`${e.outDir}/${c.name}${u}`,v=`${t}/${E}`;await Bun.write(v,l),f.progress("DTS",E)}))}));let a=performance.now()-i;W?.postMessage({success:!0,timeMs:a,filesUsed:[...o]})}catch(a){W?.postMessage({success:!1,error:p(a)})}})()}catch(a){W?.postMessage({success:!1,error:p(a)})}}function Yt(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=z();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=Yt(s);e(i,s)}else Object.entries(t).forEach(([s,i])=>{e(s,i)});return n}function $t(t,n){return`[dir]/${t}${n}`}function wt(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 _(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new $("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=performance.now();f.cli("Build started");let e=F(n),s=e?.type,i=j(t,e),o=L(t),a=[wt(i,o)],c=A(t.entry),l=t.format.flatMap((m)=>c.map((u)=>{return Jt(t,n,u,m,s,a)}));try{await Promise.all(l);let m=performance.now()-r,u=I(m);f.cli(`\uD83D\uDCE6 Build success in ${u}`)}catch{throw new $("Build process encountered errors")}if(t.dts){let m=t.format.filter((E)=>{if(E==="iife"&&!N(s)&&t.format.includes("cjs"))return!1;return!0}),u=t.dts===!0?c:A(t.dts.entry);try{await yt(n,u,m,t,s)}catch(E){throw new g("DTS build process encountered errors")}}}async function Jt(t,n,r,e,s,i){let o=D(e,s),a=it(t,n),c=await Bun.build({...a,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:$t(r.name,o)},splitting:rt(t.splitting,e),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((l)=>{if(l.level==="error")f.error(l.message);else if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}),new $(`Build failed for ${r} (${e})`);f.progress(k(e,t.name),`${t.outDir}/${r.name}${o}`)}function w(t){return(n,r)=>{r[t]=n===!0?!0:n==="true"}}function Y(t){return(n,r)=>{if(typeof n==="string")r[t]=n;else throw new h(`Option --${t} requires a string value`)}}function Et(t){return(n,r)=>{if(typeof n==="string")r[t]=n.split(",");else throw new h(`Option --${t} requires a string value`)}}var Kt={name:{flags:["n","name"],handler:Y("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:Y("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},external:{flags:["e","external"],handler:Et("external")},target:{flags:["t","target"],handler:Y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:Et("noExternal")}},J={};for(let t of Object.values(Kt))if(t)for(let n of t.flags)J[n]=t.handler;function Ct(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function vt(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=Ct(o);if(r[a])f.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])f.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=J[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=J[i];if(c)c(a,n);else throw new h(`Unknown option: -${i}`)}else{let i=Ct(s);if(r[i])f.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 K from"node:path";import Qt from"chokidar";async function Rt(t,n){let r=new Set;A(t.entry).forEach((c)=>{let l=K.resolve(n,c.path),m=K.dirname(l);r.add(m)});let s=Qt.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(c)=>{if(o)return;o=!0;try{await _({...t,entry:[c],clean:!1},n)}catch(l){throw new B(`Build failed: ${p(l)}`)}finally{o=!1}};s.on("change",(c)=>{let l=K.relative(n,c);if(f.cli(`File changed: ${l}`),i)clearTimeout(i);i=setTimeout(()=>a(l),300)}),s.on("error",(c)=>{throw new B(`Watcher error: ${p(c)}`)})}var C=new Set;async function kt(t=Bun.argv.slice(2)){let n=vt(t),r=await at(process.cwd()),e=process.cwd();if(n.watch)f.cli("Starting watch mode"),f.cli("Watching for file changes");if(r.length===0){let s={...O,...n};if(s.clean)Pt(e,s.outDir);await Ot(s,e)}else{for(let{options:s,rootDir:i}of r)if(s.clean)Pt(i,s.outDir);await Promise.all(r.map(async({options:s,rootDir:i})=>{let o={...O,...s,...n};await Ot(o,i)}))}if(C.size>0)await xt(C),C.clear();if(!n.watch)process.exit(0)}async function Ot(t,n){if(t.watch)await Rt(t,n);else await _(t,n)}function Pt(t,n){let r=Vt.join(t,n);if(Q.existsSync(r))try{Q.rmSync(r,{recursive:!0,force:!0})}catch(e){throw new $(`Failed to clean output directory: ${e}`)}Q.mkdirSync(r,{recursive:!0})}if(Zt)kt().catch((t)=>Z(t));export{kt as main,C as allFilesUsedToBundleDts};
8
+ `)}function _t(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 Ut(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}async function ht(t,n,r){let{absoluteRootDir:e,absoluteEntry:s}=dt(t,n),i=et(r.preferredTsconfigPath),o=await mt(s,i),a=await gt(o);return lt(s,a,r,e,i)}async function yt(t,n,r,e,s){return new Promise((i,o)=>{let a={rootDir:t,entries:n,formats:r,options:e,packageType:s},c=new Gt(new URL("./dtsWorker.js",import.meta.url),{workerData:a});c.on("message",async(l)=>{if(l.success){let m=I(l.timeMs);if(f.progress("DTS",`Bundled types in ${m}`),l.filesUsed)l.filesUsed.forEach((u)=>C.add(u));i()}else o(new g(l.error||"Unknown DTS worker error"))}),c.on("error",o),c.on("exit",(l)=>{if(l!==0)o(new g(`DTS worker stopped with exit code ${l}`))})})}if(!qt&&W){let{rootDir:t,entries:n,formats:r,options:e,packageType:s}=Xt,i=performance.now(),o=new Set;global.allFilesUsedToBundleDts=o,f.progress("DTS","Bundling types");try{(async()=>{try{await Promise.all(n.map(async(c)=>{let l=await ht(t,c.path,e);await Promise.all(r.map(async(m)=>{let u=tt(m,s),E=`${e.outDir}/${c.name}${u}`,v=`${t}/${E}`;await Bun.write(v,l),f.progress("DTS",E)}))}));let a=performance.now()-i;W?.postMessage({success:!0,timeMs:a,filesUsed:[...o]})}catch(a){W?.postMessage({success:!1,error:p(a)})}})()}catch(a){W?.postMessage({success:!1,error:p(a)})}}function Yt(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=z();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=Yt(s);e(i,s)}else Object.entries(t).forEach(([s,i])=>{e(s,i)});return n}function $t(t,n){return`[dir]/${t}${n}`}function wt(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 T(t,n){if(!t.entry||t.entry.length===0||!t.outDir)throw new $("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=performance.now();f.cli("Build started");let e=F(n),s=e?.type,i=j(t,e),o=L(t),a=[wt(i,o)],c=A(t.entry),l=t.format.flatMap((m)=>c.map((u)=>{return Jt(t,n,u,m,s,a)}));try{await Promise.all(l);let m=performance.now()-r,u=I(m);f.cli(`\uD83D\uDCE6 Build success in ${u}`)}catch{throw new $("Build process encountered errors")}if(t.dts){let m=t.format.filter((E)=>{if(E==="iife"&&!N(s)&&t.format.includes("cjs"))return!1;return!0}),u=t.dts===!0?c:A(t.dts.entry);try{await yt(n,u,m,t,s)}catch(E){throw new g("DTS build process encountered errors")}}}async function Jt(t,n,r,e,s,i){let o=D(e,s),a=it(t,n),c=await Bun.build({...a,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:$t(r.name,o)},splitting:rt(t.splitting,e),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((l)=>{if(l.level==="error")f.error(l.message);else if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}),new $(`Build failed for ${r} (${e})`);f.progress(k(e,t.name),`${t.outDir}/${r.name}${o}`)}function w(t){return(n,r)=>{r[t]=n===!0?!0:n==="true"}}function Y(t){return(n,r)=>{if(typeof n==="string")r[t]=n;else throw new h(`Option --${t} requires a string value`)}}function Et(t){return(n,r)=>{if(typeof n==="string")r[t]=n.split(",");else throw new h(`Option --${t} requires a string value`)}}var Kt={name:{flags:["n","name"],handler:Y("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:Y("outDir")},minify:{flags:["m","minify"],handler:w("minify")},watch:{flags:["w","watch"],handler:w("watch")},dts:{flags:["d","dts"],handler:w("dts")},external:{flags:["e","external"],handler:Et("external")},target:{flags:["t","target"],handler:Y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:w("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:w("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:w("minifySyntax")},clean:{flags:["c","clean"],handler:w("clean")},splitting:{flags:["s","splitting"],handler:w("splitting")},noExternal:{flags:["ne","no-external"],handler:Et("noExternal")}},J={};for(let t of Object.values(Kt))if(t)for(let n of t.flags)J[n]=t.handler;function Ct(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function vt(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=Ct(o);if(r[a])f.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])f.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=J[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=J[i];if(c)c(a,n);else throw new h(`Unknown option: -${i}`)}else{let i=Ct(s);if(r[i])f.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 K from"node:path";import Qt from"chokidar";async function Rt(t,n){let r=new Set;A(t.entry).forEach((c)=>{let l=K.resolve(n,c.path),m=K.dirname(l);r.add(m)});let s=Qt.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(c)=>{if(o)return;o=!0;try{await T({...t,entry:[c],clean:!1},n)}catch(l){throw new B(`Build failed: ${p(l)}`)}finally{o=!1}};s.on("change",(c)=>{let l=K.relative(n,c);if(f.cli(`File changed: ${l}`),i)clearTimeout(i);i=setTimeout(()=>a(l),300)}),s.on("error",(c)=>{throw new B(`Watcher error: ${p(c)}`)})}var C=new Set;async function kt(t=Bun.argv.slice(2)){let n=vt(t),r=await at(process.cwd()),e=process.cwd();if(n.watch)f.cli("Starting watch mode"),f.cli("Watching for file changes");if(r.length===0){let s={...O,...n};if(s.clean)Pt(e,s.outDir);await Ot(s,e)}else{for(let{options:s,rootDir:i}of r)if(s.clean)Pt(i,s.outDir);await Promise.all(r.map(async({options:s,rootDir:i})=>{let o={...O,...s,...n};await Ot(o,i)}))}if(C.size>0)await xt(C),C.clear();if(!n.watch)process.exit(0)}async function Ot(t,n){if(t.watch)await Rt(t,n);else await T(t,n)}function Pt(t,n){let r=Vt.join(t,n);if(Q.existsSync(r))try{Q.rmSync(r,{recursive:!0,force:!0})}catch(e){throw new $(`Failed to clean output directory: ${e}`)}Q.mkdirSync(r,{recursive:!0})}if(Zt)kt().catch((t)=>Z(t));export{kt as main,C as allFilesUsedToBundleDts};
@@ -1,8 +1,8 @@
1
1
  var Jt=require("node:module");var Ut=Object.create;var{getPrototypeOf:qt,defineProperty:N,getOwnPropertyNames:et,getOwnPropertyDescriptor:Gt}=Object,st=Object.prototype.hasOwnProperty;var g=(t,n,r)=>{r=t!=null?Ut(qt(t)):{};let e=n||!t||!t.__esModule?N(r,"default",{value:t,enumerable:!0}):r;for(let s of et(t))if(!st.call(e,s))N(e,s,{get:()=>t[s],enumerable:!0});return e},rt=new WeakMap,Xt=(t)=>{var n=rt.get(t),r;if(n)return n;if(n=N({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")et(t).map((e)=>!st.call(n,e)&&N(n,e,{get:()=>t[e],enumerable:!(r=Gt(t,e))||r.enumerable}));return rt.set(t,n),n};var Yt=(t,n)=>{for(var r in n)N(t,r,{get:n[r],enumerable:!0,configurable:!0,set:(e)=>n[r]=()=>e})};var an={};Yt(an,{runDtsInWorker:()=>V});module.exports=Xt(an);var w=require("node:worker_threads");var Y=g(require("node:fs")),St=g(require("node:path")),bt=require("node:worker_threads");class S extends Error{constructor(t){super(t);this.name="BunupError"}}class E extends S{constructor(t){super(t);this.name="BunupBuildError"}}class d extends S{constructor(t){super(t);this.name="BunupDTSBuildError"}}class y extends S{constructor(t){super(t);this.name="BunupCLIError"}}class I extends S{constructor(t){super(t);this.name="BunupWatchError"}}var p=(t)=>{if(t instanceof Error)return t.message;return String(t)},Kt=(t,n)=>{let r=p(t),e=n?`[${n}] `:"",s="ERROR";if(t instanceof E)s="BUILD ERROR";else if(t instanceof d)s="DTS ERROR";else if(t instanceof y)s="CLI ERROR";else if(t instanceof I)s="WATCH ERROR";else if(t instanceof S)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")},it=(t,n)=>{Kt(t,n),process.exit(1)};function K(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ot(t=8){return Math.random().toString(36).substring(2,2+t)}function at(t,n){switch(t){case"esm":return".mjs";case"cjs":return F(n)?".cjs":".js";case"iife":return".global.js"}}function lt(t,n){switch(t){case"esm":return".d.mts";case"cjs":return F(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function F(t){return t==="module"}function H(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ct(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function ft(t,n){return t===void 0?n==="esm":t}function Qt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set;function e(s,i){if(r.has(s)){let o=ot();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=Qt(s);e(i,s)}else Object.entries(t).forEach(([s,i])=>{e(s,i)});return n}function ut(t,n){return`[dir]/${t}${n}`}function pt(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${K(n)}($|\\/|\\\\)`):n)}function W(t,n){return pt(t.external||[]).concat(ct(n).map((r)=>new RegExp(`^${K(r)}($|\\/|\\\\)`)))}function _(t){return pt(t.noExternal||[])}var L=g(require("node:fs")),Q=g(require("node:path"));var f={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,n,r){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));return`\x1B[38;5;${t}m[${n}]\x1B[0m ${e}${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){let r=String(t),e=this.colors.default;for(let[s,i]of Object.entries(this.colors.progress))if(r.includes(s)){e=i;break}console.log(this.formatMessage(e,r,n))}};function mt(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};function gt(t,n){return{outdir:`${n}/${t.outDir}`,minify:Vt(t),target:t.target,splitting:t.splitting}}function Vt(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 dt(t){let n=[];for(let r of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let e=Q.default.join(t,`bunup.config${r}`);try{if(!L.default.existsSync(e))continue;let s;if(r===".json"||r===".jsonc"){let i=L.default.readFileSync(e,"utf8");s=JSON.parse(i)}else{let i=await import(`file://${e}`);if(s=i.default||i,!s)f.warn(`No default export found in ${e}`),s={}}if(Array.isArray(s))for(let i of s)n.push({options:{...b,...i},rootDir:t});else n.push({options:{...b,...s},rootDir:t});break}catch(s){throw new E(`Failed to load config from ${e}: ${p(s)}`)}if(n.length>0)break}return n}function T(t){let n=Q.default.join(t,"package.json");try{if(!L.default.existsSync(n))return null;let r=L.default.readFileSync(n,"utf8");return JSON.parse(r)}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),null}}function xt(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 E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=performance.now();f.cli("Build started");let e=T(n),s=e?.type,i=W(t,e),o=_(t),a=[xt(i,o)],c=j(t.entry),l=t.format.flatMap((m)=>c.map((u)=>{return Zt(t,n,u,m,s,a)}));try{await Promise.all(l);let m=performance.now()-r,u=H(m);f.cli(`\uD83D\uDCE6 Build success in ${u}`)}catch{throw new E("Build process encountered errors")}if(t.dts){let m=t.format.filter((v)=>{if(v==="iife"&&!F(s)&&t.format.includes("cjs"))return!1;return!0}),u=t.dts===!0?c:j(t.dts.entry);try{await V(n,u,m,t,s)}catch(v){throw new d("DTS build process encountered errors")}}}async function Zt(t,n,r,e,s,i){let o=at(e,s),a=gt(t,n),c=await Bun.build({...a,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:ut(r.name,o)},splitting:ft(t.splitting,e),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((l)=>{if(l.level==="error")f.error(l.message);else if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}),new E(`Build failed for ${r} (${e})`);f.progress(mt(e,t.name),`${t.outDir}/${r.name}${o}`)}function C(t){return(n,r)=>{r[t]=n===!0?!0:n==="true"}}function Z(t){return(n,r)=>{if(typeof n==="string")r[t]=n;else throw new y(`Option --${t} requires a string value`)}}function ht(t){return(n,r)=>{if(typeof n==="string")r[t]=n.split(",");else throw new y(`Option --${t} requires a string value`)}}var kt={name:{flags:["n","name"],handler:Z("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new y("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:Z("outDir")},minify:{flags:["m","minify"],handler:C("minify")},watch:{flags:["w","watch"],handler:C("watch")},dts:{flags:["d","dts"],handler:C("dts")},external:{flags:["e","external"],handler:ht("external")},target:{flags:["t","target"],handler:Z("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:C("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:C("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:C("minifySyntax")},clean:{flags:["c","clean"],handler:C("clean")},splitting:{flags:["s","splitting"],handler:C("splitting")},noExternal:{flags:["ne","no-external"],handler:ht("noExternal")}},k={};for(let t of Object.values(kt))if(t)for(let n of t.flags)k[n]=t.handler;function yt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function $t(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])f.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);r[a]=o}else throw new y("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(r[a])f.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);r[a]=o}else throw new y(`Option --entry.${a} requires a string value`)}else{let a=k[i];if(a)a(o,n);else throw new y(`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=k[i];if(c)c(a,n);else throw new y(`Unknown option: -${i}`)}else{let i=yt(s);if(r[i])f.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 y(`Bunup requires Bun to run.
4
- To install Bun, visit https://bun.sh/docs/installation`)})();var G=g(require("node:fs")),q=g(require("node:path")),wt=require("oxc-transform");function Et(t,n){let r=q.default.resolve(t),e=q.default.resolve(r,n);if(!G.default.existsSync(r))throw new d(`Root directory does not exist: ${r}`);if(!G.default.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(q.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function Ct(t){if(t.size===0)return;let n=!1;if(console.log(`
5
- `),await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.d\.ts$/,".ts"),s=await G.default.promises.readFile(e,"utf8"),{errors:i}=wt.isolatedDeclaration(e,s);i.forEach((o)=>{let a=o.labels[0],c=a?zt(s,a.start):"",u=`${e.split("/").slice(-3).join("/")}${c}: ${Dt(o.message)}`;f.warn(u),n=!0})}catch{}})),n)f.info(`
3
+ `)+"\x1B[0m")},it=(t,n)=>{Kt(t,n),process.exit(1)};function K(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ot(t=8){return Math.random().toString(36).substring(2,2+t)}function at(t,n){switch(t){case"esm":return".mjs";case"cjs":return F(n)?".cjs":".js";case"iife":return".global.js"}}function lt(t,n){switch(t){case"esm":return".d.mts";case"cjs":return F(n)?".d.cts":".d.ts";case"iife":return".d.ts"}}function F(t){return t==="module"}function H(t){return t>=1000?`${(t/1000).toFixed(2)}s`:`${Math.round(t)}ms`}function ct(t){if(!t)return[];return Array.from(new Set([...Object.keys(t.dependencies||{}),...Object.keys(t.peerDependencies||{})]))}function ft(t,n){return t===void 0?n==="esm":t}function Qt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function j(t){let n=[],r=new Set;function e(s,i){if(r.has(s)){let o=ot();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=Qt(s);e(i,s)}else Object.entries(t).forEach(([s,i])=>{e(s,i)});return n}function ut(t,n){return`[dir]/${t}${n}`}function pt(t){return t.map((n)=>typeof n==="string"?new RegExp(`^${K(n)}($|\\/|\\\\)`):n)}function W(t,n){return pt(t.external||[]).concat(ct(n).map((r)=>new RegExp(`^${K(r)}($|\\/|\\\\)`)))}function T(t){return pt(t.noExternal||[])}var L=g(require("node:fs")),Q=g(require("node:path"));var f={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(t,n,r){let e=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-n.length));return`\x1B[38;5;${t}m[${n}]\x1B[0m ${e}${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){let r=String(t),e=this.colors.default;for(let[s,i]of Object.entries(this.colors.progress))if(r.includes(s)){e=i;break}console.log(this.formatMessage(e,r,n))}};function mt(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};function gt(t,n){return{outdir:`${n}/${t.outDir}`,minify:Vt(t),target:t.target,splitting:t.splitting}}function Vt(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 dt(t){let n=[];for(let r of[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"]){let e=Q.default.join(t,`bunup.config${r}`);try{if(!L.default.existsSync(e))continue;let s;if(r===".json"||r===".jsonc"){let i=L.default.readFileSync(e,"utf8");s=JSON.parse(i)}else{let i=await import(`file://${e}`);if(s=i.default||i,!s)f.warn(`No default export found in ${e}`),s={}}if(Array.isArray(s))for(let i of s)n.push({options:{...b,...i},rootDir:t});else n.push({options:{...b,...s},rootDir:t});break}catch(s){throw new E(`Failed to load config from ${e}: ${p(s)}`)}if(n.length>0)break}return n}function _(t){let n=Q.default.join(t,"package.json");try{if(!L.default.existsSync(n))return null;let r=L.default.readFileSync(n,"utf8");return JSON.parse(r)}catch(r){return f.warn(`Failed to load package.json at ${n}: ${p(r)}`),null}}function xt(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 E("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let r=performance.now();f.cli("Build started");let e=_(n),s=e?.type,i=W(t,e),o=T(t),a=[xt(i,o)],c=j(t.entry),l=t.format.flatMap((m)=>c.map((u)=>{return Zt(t,n,u,m,s,a)}));try{await Promise.all(l);let m=performance.now()-r,u=H(m);f.cli(`\uD83D\uDCE6 Build success in ${u}`)}catch{throw new E("Build process encountered errors")}if(t.dts){let m=t.format.filter((v)=>{if(v==="iife"&&!F(s)&&t.format.includes("cjs"))return!1;return!0}),u=t.dts===!0?c:j(t.dts.entry);try{await V(n,u,m,t,s)}catch(v){throw new d("DTS build process encountered errors")}}}async function Zt(t,n,r,e,s,i){let o=at(e,s),a=gt(t,n),c=await Bun.build({...a,entrypoints:[`${n}/${r.path}`],format:e,naming:{entry:ut(r.name,o)},splitting:ft(t.splitting,e),plugins:i,throw:!1});if(!c.success)throw c.logs.forEach((l)=>{if(l.level==="error")f.error(l.message);else if(l.level==="warning")f.warn(l.message);else if(l.level==="info")f.info(l.message)}),new E(`Build failed for ${r} (${e})`);f.progress(mt(e,t.name),`${t.outDir}/${r.name}${o}`)}function C(t){return(n,r)=>{r[t]=n===!0?!0:n==="true"}}function Z(t){return(n,r)=>{if(typeof n==="string")r[t]=n;else throw new y(`Option --${t} requires a string value`)}}function ht(t){return(n,r)=>{if(typeof n==="string")r[t]=n.split(",");else throw new y(`Option --${t} requires a string value`)}}var kt={name:{flags:["n","name"],handler:Z("name")},format:{flags:["f","format"],handler:(t,n)=>{if(typeof t==="string")n.format=t.split(",");else throw new y("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:Z("outDir")},minify:{flags:["m","minify"],handler:C("minify")},watch:{flags:["w","watch"],handler:C("watch")},dts:{flags:["d","dts"],handler:C("dts")},external:{flags:["e","external"],handler:ht("external")},target:{flags:["t","target"],handler:Z("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:C("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:C("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:C("minifySyntax")},clean:{flags:["c","clean"],handler:C("clean")},splitting:{flags:["s","splitting"],handler:C("splitting")},noExternal:{flags:["ne","no-external"],handler:ht("noExternal")}},k={};for(let t of Object.values(kt))if(t)for(let n of t.flags)k[n]=t.handler;function yt(t){return t.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function $t(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])f.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);r[a]=o}else throw new y("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(r[a])f.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);r[a]=o}else throw new y(`Option --entry.${a} requires a string value`)}else{let a=k[i];if(a)a(o,n);else throw new y(`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=k[i];if(c)c(a,n);else throw new y(`Unknown option: -${i}`)}else{let i=yt(s);if(r[i])f.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 y(`Bunup requires Bun to run.
4
+ To install Bun, visit https://bun.sh/docs/installation`)})();var G=g(require("node:fs")),q=g(require("node:path")),wt=require("oxc-transform");function Et(t,n){let r=q.default.resolve(t),e=q.default.resolve(r,n);if(!G.default.existsSync(r))throw new d(`Root directory does not exist: ${r}`);if(!G.default.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(q.default.relative(r,e).startsWith(".."))throw new d(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:r,absoluteEntry:e}}async function Ct(t){let n=!1;if(await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.d\.ts$/,".ts"),s=await G.default.promises.readFile(e,"utf8"),{errors:i}=wt.isolatedDeclaration(e,s);i.forEach((o)=>{if(!n)console.log(`
5
+ `);let a=o.labels[0],c=a?zt(s,a.start):"",u=`${e.split("/").slice(-3).join("/")}${c}: ${Dt(o.message)}`;f.warn(u),n=!0})}catch{}})),n)f.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 zt(t,n){if(n===void 0)return"";let r=t.slice(0,n).split(`
8
- `),e=r.length,s=r[r.length-1].length+1;return` (${e}:${s})`}function Dt(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var X=g(require("node:path")),vt=g(require("chokidar"));async function Rt(t,n){let r=new Set;j(t.entry).forEach((c)=>{let l=X.default.resolve(n,c.path),m=X.default.dirname(l);r.add(m)});let s=vt.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(c)=>{if(o)return;o=!0;try{await U({...t,entry:[c],clean:!1},n)}catch(l){throw new I(`Build failed: ${p(l)}`)}finally{o=!1}};s.on("change",(c)=>{let l=X.default.relative(n,c);if(f.cli(`File changed: ${l}`),i)clearTimeout(i);i=setTimeout(()=>a(l),300)}),s.on("error",(c)=>{throw new I(`Watcher error: ${p(c)}`)})}var R=new Set;async function tn(t=Bun.argv.slice(2)){let n=$t(t),r=await dt(process.cwd()),e=process.cwd();if(n.watch)f.cli("Starting watch mode"),f.cli("Watching for file changes");if(r.length===0){let s={...b,...n};if(s.clean)Pt(e,s.outDir);await Ot(s,e)}else{for(let{options:s,rootDir:i}of r)if(s.clean)Pt(i,s.outDir);await Promise.all(r.map(async({options:s,rootDir:i})=>{let o={...b,...s,...n};await Ot(o,i)}))}if(R.size>0)await Ct(R),R.clear();if(!n.watch)process.exit(0)}async function Ot(t,n){if(t.watch)await Rt(t,n);else await U(t,n)}function Pt(t,n){let r=St.default.join(t,n);if(Y.default.existsSync(r))try{Y.default.rmSync(r,{recursive:!0,force:!0})}catch(e){throw new E(`Failed to clean output directory: ${e}`)}Y.default.mkdirSync(r,{recursive:!0})}if(bt.isMainThread)tn().catch((t)=>it(t));var Bt=require("load-tsconfig");function At(t){try{return Bt.loadTsConfig(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}var O=g(require("node:path")),Nt=require("rollup"),It=g(require("rollup-plugin-dts")),J=g(require("typescript"));var nn=()=>{return global.allFilesUsedToBundleDts||R||new Set};async function jt(t,n,r,e,s){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,c=s.data?.compilerOptions,l={name:"bunup:virtual-dts",resolveId(x,$){if(x.startsWith("\x00virtual:"))return x;if(!$?.startsWith("\x00virtual:")||!x.startsWith("."))return null;let h=$.slice(9),B=O.default.resolve(O.default.dirname(h),x);if(x==="."){let A=O.default.join(O.default.dirname(h),"index.d.ts");if(n.has(A))return`\x00virtual:${A}`;B=O.default.dirname(h)}if(n.has(B))return`\x00virtual:${B}`;let nt=`${B}.d.ts`;if(n.has(nt))return`\x00virtual:${nt}`;if(x.startsWith(".")){let A=O.default.join(B,"index.d.ts");if(n.has(A))return`\x00virtual:${A}`}return null},load(x){if(x.startsWith("\x00virtual:")){let $=x.slice(9),h=n.get($);if(h)return nn().add($),h}return null}},m=T(e),u=W(r,m),v=_(r),P;try{P=await Nt.rollup({input:a,onwarn($,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes($.code??""))return;h($)},plugins:[l,It.default({tsconfig:s.path,compilerOptions:{...c?J.default.parseJsonConfigFileContent({compilerOptions:c},J.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:J.default.ScriptTarget.ESNext}})],external:($)=>u.some((h)=>h.test($))&&!v.some((h)=>h.test($))});let{output:x}=await P.generate({});if(!x[0]?.code)throw new d("Generated bundle is empty");return x[0].code}catch(x){throw new d(`DTS bundling failed: ${p(x)}`)}finally{if(P)await P.close()}}var tt=g(require("node:fs")),D=g(require("node:path"));var M=g(require("node:path"));function z(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=z(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 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?M.default.join(r,t):null}var rn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,en=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Ft(t,n){let r=new Set([t]),e=[t],s=Lt(n),i=z(n);while(e.length){let o=e.pop();if(!o)continue;try{let a=await tt.default.promises.readFile(o,"utf8"),c=sn(a);for(let l of c){let m=l.startsWith(".")?D.default.resolve(D.default.dirname(o),l):Mt(l,s,i);if(!m)continue;let u=on(m);if(u&&!r.has(u))r.add(u),e.push(u)}}catch(a){f.warn(`Error processing ${o}: ${p(a)}`)}}return r}function sn(t){let n=new Set;for(let r of[rn,en]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}function on(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(tt.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}var Ht=g(require("node:fs")),Wt=require("oxc-transform");async function _t(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),s=await Ht.default.promises.readFile(r,"utf8"),{code:i}=Wt.isolatedDeclaration(r,s);if(i)n.set(e,i)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}async function Tt(t,n,r){let{absoluteRootDir:e,absoluteEntry:s}=Et(t,n),i=At(r.preferredTsconfigPath),o=await Ft(s,i),a=await _t(o);return jt(s,a,r,e,i)}async function V(t,n,r,e,s){return new Promise((i,o)=>{let a={rootDir:t,entries:n,formats:r,options:e,packageType:s},c=new w.Worker(new URL("./dtsWorker.js",import.meta.url),{workerData:a});c.on("message",async(l)=>{if(l.success){let m=H(l.timeMs);if(f.progress("DTS",`Bundled types in ${m}`),l.filesUsed)l.filesUsed.forEach((u)=>R.add(u));i()}else o(new d(l.error||"Unknown DTS worker error"))}),c.on("error",o),c.on("exit",(l)=>{if(l!==0)o(new d(`DTS worker stopped with exit code ${l}`))})})}if(!w.isMainThread&&w.parentPort){let{rootDir:t,entries:n,formats:r,options:e,packageType:s}=w.workerData,i=performance.now(),o=new Set;global.allFilesUsedToBundleDts=o,f.progress("DTS","Bundling types");try{(async()=>{try{await Promise.all(n.map(async(c)=>{let l=await Tt(t,c.path,e);await Promise.all(r.map(async(m)=>{let u=lt(m,s),v=`${e.outDir}/${c.name}${u}`,P=`${t}/${v}`;await Bun.write(P,l),f.progress("DTS",v)}))}));let a=performance.now()-i;w.parentPort?.postMessage({success:!0,timeMs:a,filesUsed:[...o]})}catch(a){w.parentPort?.postMessage({success:!1,error:p(a)})}})()}catch(a){w.parentPort?.postMessage({success:!1,error:p(a)})}}
8
+ `),e=r.length,s=r[r.length-1].length+1;return` (${e}:${s})`}function Dt(t){return t.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var X=g(require("node:path")),vt=g(require("chokidar"));async function Rt(t,n){let r=new Set;j(t.entry).forEach((c)=>{let l=X.default.resolve(n,c.path),m=X.default.dirname(l);r.add(m)});let s=vt.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(c)=>{if(o)return;o=!0;try{await U({...t,entry:[c],clean:!1},n)}catch(l){throw new I(`Build failed: ${p(l)}`)}finally{o=!1}};s.on("change",(c)=>{let l=X.default.relative(n,c);if(f.cli(`File changed: ${l}`),i)clearTimeout(i);i=setTimeout(()=>a(l),300)}),s.on("error",(c)=>{throw new I(`Watcher error: ${p(c)}`)})}var R=new Set;async function tn(t=Bun.argv.slice(2)){let n=$t(t),r=await dt(process.cwd()),e=process.cwd();if(n.watch)f.cli("Starting watch mode"),f.cli("Watching for file changes");if(r.length===0){let s={...b,...n};if(s.clean)Pt(e,s.outDir);await Ot(s,e)}else{for(let{options:s,rootDir:i}of r)if(s.clean)Pt(i,s.outDir);await Promise.all(r.map(async({options:s,rootDir:i})=>{let o={...b,...s,...n};await Ot(o,i)}))}if(R.size>0)await Ct(R),R.clear();if(!n.watch)process.exit(0)}async function Ot(t,n){if(t.watch)await Rt(t,n);else await U(t,n)}function Pt(t,n){let r=St.default.join(t,n);if(Y.default.existsSync(r))try{Y.default.rmSync(r,{recursive:!0,force:!0})}catch(e){throw new E(`Failed to clean output directory: ${e}`)}Y.default.mkdirSync(r,{recursive:!0})}if(bt.isMainThread)tn().catch((t)=>it(t));var Bt=require("load-tsconfig");function At(t){try{return Bt.loadTsConfig(".",t)}catch(n){return f.warn(`Failed to load tsconfig: ${p(n)}`),{path:t,data:{},files:[]}}}var O=g(require("node:path")),Nt=require("rollup"),It=g(require("rollup-plugin-dts")),J=g(require("typescript"));var nn=()=>{return global.allFilesUsedToBundleDts||R||new Set};async function jt(t,n,r,e,s){let a=`\x00virtual:${t.replace(/\.tsx?$/,".d.ts")}`,c=s.data?.compilerOptions,l={name:"bunup:virtual-dts",resolveId(x,$){if(x.startsWith("\x00virtual:"))return x;if(!$?.startsWith("\x00virtual:")||!x.startsWith("."))return null;let h=$.slice(9),B=O.default.resolve(O.default.dirname(h),x);if(x==="."){let A=O.default.join(O.default.dirname(h),"index.d.ts");if(n.has(A))return`\x00virtual:${A}`;B=O.default.dirname(h)}if(n.has(B))return`\x00virtual:${B}`;let nt=`${B}.d.ts`;if(n.has(nt))return`\x00virtual:${nt}`;if(x.startsWith(".")){let A=O.default.join(B,"index.d.ts");if(n.has(A))return`\x00virtual:${A}`}return null},load(x){if(x.startsWith("\x00virtual:")){let $=x.slice(9),h=n.get($);if(h)return nn().add($),h}return null}},m=_(e),u=W(r,m),v=T(r),P;try{P=await Nt.rollup({input:a,onwarn($,h){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes($.code??""))return;h($)},plugins:[l,It.default({tsconfig:s.path,compilerOptions:{...c?J.default.parseJsonConfigFileContent({compilerOptions:c},J.default.sys,"./").options:{},declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!1,target:J.default.ScriptTarget.ESNext}})],external:($)=>u.some((h)=>h.test($))&&!v.some((h)=>h.test($))});let{output:x}=await P.generate({});if(!x[0]?.code)throw new d("Generated bundle is empty");return x[0].code}catch(x){throw new d(`DTS bundling failed: ${p(x)}`)}finally{if(P)await P.close()}}var tt=g(require("node:fs")),D=g(require("node:path"));var M=g(require("node:path"));function z(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=z(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 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?M.default.join(r,t):null}var rn=/(?:import|export)(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*|[\s\n]+)(["'`])([^'"]+)\1/g,en=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;async function Ft(t,n){let r=new Set([t]),e=[t],s=Lt(n),i=z(n);while(e.length){let o=e.pop();if(!o)continue;try{let a=await tt.default.promises.readFile(o,"utf8"),c=sn(a);for(let l of c){let m=l.startsWith(".")?D.default.resolve(D.default.dirname(o),l):Mt(l,s,i);if(!m)continue;let u=on(m);if(u&&!r.has(u))r.add(u),e.push(u)}}catch(a){f.warn(`Error processing ${o}: ${p(a)}`)}}return r}function sn(t){let n=new Set;for(let r of[rn,en]){let e;while((e=r.exec(t))!==null)n.add(e[2])}return Array.from(n)}function on(t){let n=["",".ts",".tsx","/index.ts","/index.tsx"];for(let r of n){let e=`${t}${r}`;if(tt.default.existsSync(e)&&(e.endsWith(".ts")||e.endsWith(".tsx")))return e}return null}var Ht=g(require("node:fs")),Wt=require("oxc-transform");async function Tt(t){let n=new Map;return await Promise.all([...t].map(async(r)=>{try{let e=r.replace(/\.tsx?$/,".d.ts"),s=await Ht.default.promises.readFile(r,"utf8"),{code:i}=Wt.isolatedDeclaration(r,s);if(i)n.set(e,i)}catch(e){f.warn(`Failed to generate declaration for ${r}: ${p(e)}`)}})),n}async function _t(t,n,r){let{absoluteRootDir:e,absoluteEntry:s}=Et(t,n),i=At(r.preferredTsconfigPath),o=await Ft(s,i),a=await Tt(o);return jt(s,a,r,e,i)}async function V(t,n,r,e,s){return new Promise((i,o)=>{let a={rootDir:t,entries:n,formats:r,options:e,packageType:s},c=new w.Worker(new URL("./dtsWorker.js",import.meta.url),{workerData:a});c.on("message",async(l)=>{if(l.success){let m=H(l.timeMs);if(f.progress("DTS",`Bundled types in ${m}`),l.filesUsed)l.filesUsed.forEach((u)=>R.add(u));i()}else o(new d(l.error||"Unknown DTS worker error"))}),c.on("error",o),c.on("exit",(l)=>{if(l!==0)o(new d(`DTS worker stopped with exit code ${l}`))})})}if(!w.isMainThread&&w.parentPort){let{rootDir:t,entries:n,formats:r,options:e,packageType:s}=w.workerData,i=performance.now(),o=new Set;global.allFilesUsedToBundleDts=o,f.progress("DTS","Bundling types");try{(async()=>{try{await Promise.all(n.map(async(c)=>{let l=await _t(t,c.path,e);await Promise.all(r.map(async(m)=>{let u=lt(m,s),v=`${e.outDir}/${c.name}${u}`,P=`${t}/${v}`;await Bun.write(P,l),f.progress("DTS",v)}))}));let a=performance.now()-i;w.parentPort?.postMessage({success:!0,timeMs:a,filesUsed:[...o]})}catch(a){w.parentPort?.postMessage({success:!1,error:p(a)})}})()}catch(a){w.parentPort?.postMessage({success:!1,error:p(a)})}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "description": "A extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "@types/bun": "^1.2.5",
19
19
  "@typescript-eslint/eslint-plugin": "^7.3.1",
20
20
  "bumpp": "^10.1.0",
21
- "bunup": "^0.1.25",
21
+ "bunup": "^0.1.27",
22
22
  "eslint": "^8.57.0",
23
23
  "husky": "^9.1.6",
24
24
  "prettier": "^3.2.5",