bunup 0.13.0 → 0.13.5

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/dist/plugins.d.ts CHANGED
@@ -1,4 +1,457 @@
1
- import { BuildContext, BunupPlugin, BunupPluginHooks, MaybePromise } from "./shared/bunup-s6gfzz2v";
1
+ import { GenerateDtsOptions } from "@bunup/dts";
2
+ import { BunPlugin } from "bun";
3
+ type MaybePromise<T> = Promise<T> | T;
4
+ type Loader = "js" | "jsx" | "ts" | "tsx" | "json" | "toml" | "file" | "napi" | "wasm" | "text" | "css" | "html";
5
+ type Define = Record<string, string>;
6
+ type Sourcemap = "none" | "linked" | "inline" | "external" | "linked" | boolean;
7
+ type Format = "esm" | "cjs" | "iife";
8
+ type Target = "bun" | "node" | "browser";
9
+ type External = (string | RegExp)[];
10
+ type Env = "inline" | "disable" | `${string}*` | Record<string, string>;
11
+ type CSSOptions = {
12
+ /**
13
+ * Generate TypeScript definitions for CSS modules.
14
+ *
15
+ * @see https://bunup.dev/docs/guide/css#css-modules-and-typescript
16
+ */
17
+ typedModules?: boolean
18
+ };
19
+ type OnSuccess = ((options: Partial<BuildOptions>) => MaybePromise<void> | (() => void)) | string | {
20
+ /**
21
+ * The shell command to execute after a successful build
22
+ */
23
+ cmd: string
24
+ /**
25
+ * Additional options for the command execution
26
+ */
27
+ options?: {
28
+ /**
29
+ * Working directory for the command
30
+ */
31
+ cwd?: string
32
+ /**
33
+ * Environment variables to pass to the command
34
+ * @default process.env
35
+ */
36
+ env?: Record<string, string | undefined>
37
+ /**
38
+ * Maximum time in milliseconds the command is allowed to run
39
+ */
40
+ timeout?: number
41
+ /**
42
+ * Signal to use when killing the process
43
+ * @default 'SIGTERM'
44
+ */
45
+ killSignal?: NodeJS.Signals | number
46
+ }
47
+ };
48
+ type ReportOptions = {
49
+ /**
50
+ * Enable gzip compression size calculation.
51
+ *
52
+ * Note: For huge output files, this may slow down the build process. In this case, consider disabling this option.
53
+ *
54
+ * @default true
55
+ */
56
+ gzip?: boolean
57
+ /**
58
+ * Enable brotli compression size calculation.
59
+ *
60
+ * Note: For huge output files, this may slow down the build process. In this case, consider disabling this option.
61
+ *
62
+ * @default false
63
+ */
64
+ brotli?: boolean
65
+ /**
66
+ * Maximum bundle size in bytes. Will warn if exceeded.
67
+ *
68
+ * @default undefined
69
+ */
70
+ maxBundleSize?: number
71
+ };
72
+ interface BuildOptions {
73
+ /**
74
+ * Name of the build configuration
75
+ * Used for logging and identification purposes
76
+ */
77
+ name?: string;
78
+ /**
79
+ * Entry point files for the build
80
+ *
81
+ * This can be:
82
+ * - A string path to a file
83
+ * - An array of file paths
84
+ *
85
+ * @see https://bunup.dev/docs/guide/options#entry-points
86
+ */
87
+ entry: string | string[];
88
+ /**
89
+ * Output directory for the bundled files
90
+ * Defaults to 'dist' if not specified
91
+ */
92
+ outDir: string;
93
+ /**
94
+ * Output formats for the bundle
95
+ * Can include 'esm', 'cjs', and/or 'iife'
96
+ * Defaults to 'esm' if not specified
97
+ */
98
+ format: Format | Format[];
99
+ /**
100
+ * Whether to enable all minification options
101
+ * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
102
+ */
103
+ minify?: boolean;
104
+ /**
105
+ * Whether to enable code splitting
106
+ * Defaults to true for ESM format, false for CJS format
107
+ */
108
+ splitting?: boolean;
109
+ /**
110
+ * Whether to minify whitespace in the output
111
+ * Removes unnecessary whitespace to reduce file size
112
+ */
113
+ minifyWhitespace?: boolean;
114
+ /**
115
+ * Whether to minify identifiers in the output
116
+ * Renames variables and functions to shorter names
117
+ */
118
+ minifyIdentifiers?: boolean;
119
+ /**
120
+ * Whether to minify syntax in the output
121
+ * Optimizes code structure for smaller file size
122
+ */
123
+ minifySyntax?: boolean;
124
+ /**
125
+ * Whether to watch for file changes and rebuild automatically
126
+ */
127
+ watch?: boolean;
128
+ /**
129
+ * package.json `exports` conditions used when resolving imports
130
+ *
131
+ * Equivalent to `--conditions` in `bun build` or `bun run`.
132
+ *
133
+ * https://nodejs.org/api/packages.html#exports
134
+ */
135
+ conditions?: string | string[];
136
+ /**
137
+ * Whether to generate TypeScript declaration files (.d.ts)
138
+ * When set to true, generates declaration files for all entry points
139
+ * Can also be configured with GenerateDtsOptions for more control
140
+ */
141
+ dts?: boolean | (Pick<GenerateDtsOptions, "resolve" | "splitting" | "minify"> & {
142
+ entry?: string | string[]
143
+ });
144
+ /**
145
+ * Path to a preferred tsconfig.json file to use for declaration generation
146
+ *
147
+ * If not specified, the tsconfig.json in the project root will be used.
148
+ * This option allows you to use a different TypeScript configuration
149
+ * specifically for declaration file generation.
150
+ *
151
+ * @example
152
+ * preferredTsconfigPath: './tsconfig.build.json'
153
+ */
154
+ preferredTsconfigPath?: string;
155
+ /**
156
+ * External packages that should not be bundled
157
+ * Useful for dependencies that should be kept as external imports
158
+ */
159
+ external?: External;
160
+ /**
161
+ * Packages that should be bundled even if they are in external
162
+ * Useful for dependencies that should be included in the bundle
163
+ */
164
+ noExternal?: External;
165
+ /**
166
+ * The target environment for the bundle.
167
+ * Can be 'browser', 'bun', 'node', etc.
168
+ * Defaults to 'node' if not specified.
169
+ *
170
+ * Bun target is for generating bundles that are intended to be run by the Bun runtime. In many cases,
171
+ * it isn't necessary to bundle server-side code; you can directly execute the source code
172
+ * without modification. However, bundling your server code can reduce startup times and
173
+ * improve running performance.
174
+ *
175
+ * All bundles generated with `target: "bun"` are marked with a special `// @bun` pragma, which
176
+ * indicates to the Bun runtime that there's no need to re-transpile the file before execution.
177
+ */
178
+ target?: Target;
179
+ /**
180
+ * Whether to clean the output directory before building
181
+ * When true, removes all files in the outDir before starting a new build
182
+ * Defaults to true if not specified
183
+ */
184
+ clean?: boolean;
185
+ /**
186
+ * Specifies the type of sourcemap to generate
187
+ * Can be 'none', 'linked', 'external', or 'inline'
188
+ * Can also be a boolean - when true, it will use 'inline'
189
+ *
190
+ * @see https://bun.sh/docs/bundler#sourcemap
191
+ *
192
+ * @default 'none'
193
+ *
194
+ * @example
195
+ * sourcemap: 'linked'
196
+ * // or
197
+ * sourcemap: true // equivalent to 'inline'
198
+ */
199
+ sourcemap?: Sourcemap;
200
+ /**
201
+ * Define global constants for the build
202
+ * These values will be replaced at build time
203
+ *
204
+ * @see https://bun.sh/docs/bundler#define
205
+ *
206
+ * @example
207
+ * define: {
208
+ * 'process.env.NODE_ENV': '"production"',
209
+ * 'PACKAGE_VERSION': '"1.0.0"'
210
+ * }
211
+ */
212
+ define?: Define;
213
+ /**
214
+ * A callback or command to run after a successful build.
215
+ *
216
+ * If a function is provided, it can optionally return a cleanup function
217
+ * that will be called when the operation is cancelled.
218
+ *
219
+ * @example
220
+ * onSuccess: (options) => {
221
+ * const server = startServer();
222
+ * return () => server.close();
223
+ * }
224
+ *
225
+ * @example
226
+ * onSuccess: "echo Build completed!"
227
+ *
228
+ * @example
229
+ * onSuccess: {
230
+ * cmd: "bun run dist/server.js",
231
+ * options: { env: { ...process.env, FOO: "bar" } }
232
+ * }
233
+ */
234
+ onSuccess?: OnSuccess;
235
+ /**
236
+ * A banner to be added to the final bundle, this can be a directive like "use client" for react or a comment block such as a license for the code.
237
+ *
238
+ * @see https://bun.sh/docs/bundler#banner
239
+ *
240
+ * @example
241
+ * banner: '"use client";'
242
+ */
243
+ banner?: string;
244
+ /**
245
+ * A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
246
+ *
247
+ * @see https://bun.sh/docs/bundler#footer
248
+ *
249
+ * @example
250
+ * footer: '// built with love in SF'
251
+ */
252
+ footer?: string;
253
+ /**
254
+ * Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
255
+ *
256
+ * @see https://bun.sh/docs/bundler#drop
257
+ *
258
+ * @example
259
+ * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
260
+ */
261
+ drop?: string[];
262
+ /**
263
+ * A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
264
+ *
265
+ * @see https://bun.sh/docs/bundler#loader
266
+ *
267
+ * @example
268
+ * loader: {
269
+ * ".png": "dataurl",
270
+ * ".txt": "file",
271
+ * }
272
+ */
273
+ loader?: { [k in string] : Loader };
274
+ /**
275
+ * Disable logging during the build process. When set to true, no logs will be printed to the console.
276
+ *
277
+ * @default false
278
+ */
279
+ silent?: boolean;
280
+ /**
281
+ * You can specify a prefix to be added to specific import paths in your bundled code
282
+ *
283
+ * Used for assets, external modules, and chunk files when splitting is enabled
284
+ *
285
+ * @see https://bunup.dev/docs/guide/options#public-path for more information
286
+ *
287
+ * @example
288
+ * publicPath: 'https://cdn.example.com/'
289
+ */
290
+ publicPath?: string;
291
+ /**
292
+ * Controls how environment variables are handled during bundling.
293
+ *
294
+ * Can be one of:
295
+ * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
296
+ * of those environment variables at the time the build runs.
297
+ * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
298
+ * - A string ending in `*`: Only inlines environment variables matching the given prefix.
299
+ * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
300
+ * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
301
+ * with the provided values, regardless of the runtime environment.
302
+ *
303
+ * Note: Values are injected at build time. Secrets or private keys should be excluded
304
+ * from inlining when targeting browser environments.
305
+ *
306
+ * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
307
+ *
308
+ * @example
309
+ * // Inline all environment variables available at build time
310
+ * env: "inline"
311
+ *
312
+ * // Disable all environment variable injection
313
+ * env: "disable"
314
+ *
315
+ * // Only inline environment variables with a specific prefix
316
+ * env: "PUBLIC_*"
317
+ *
318
+ * // Provide specific environment variables manually
319
+ * env: { API_URL: "https://api.example.com", DEBUG: "false" }
320
+ */
321
+ env?: Env;
322
+ /**
323
+ * Whether to enable shims for Node.js globals and ESM/CJS interoperability.
324
+ *
325
+ * @default false
326
+ */
327
+ shims?: boolean;
328
+ /**
329
+ * Configuration for the build report that shows file sizes and compression stats.
330
+ */
331
+ report?: ReportOptions;
332
+ /**
333
+ * Ignore dead code elimination/tree-shaking annotations such as @__PURE__ and package.json
334
+ * "sideEffects" fields. This should only be used as a temporary workaround for incorrect
335
+ * annotations in libraries.
336
+ */
337
+ ignoreDCEAnnotations?: boolean;
338
+ /**
339
+ * Force emitting @__PURE__ annotations even if minify.whitespace is true.
340
+ */
341
+ emitDCEAnnotations?: boolean;
342
+ /**
343
+ * Plugins to extend the build process functionality
344
+ *
345
+ * The Plugin type uses a discriminated union pattern with the 'type' field
346
+ * to support different plugin systems. Both "bun" and "bunup" plugins are supported.
347
+ *
348
+ * Each plugin type has its own specific plugin implementation:
349
+ * - "bun": Uses Bun's native plugin system (BunPlugin)
350
+ * - "bunup": Uses bunup's own plugin system with lifecycle hooks
351
+ *
352
+ * This architecture allows for extensibility as more plugin systems are added.
353
+ *
354
+ * @see https://bunup.dev/docs/advanced/plugin-development for more information on plugins
355
+ *
356
+ * @example
357
+ * plugins: [
358
+ * myBunPlugin(),
359
+ * {
360
+ * name: "my-bunup-plugin",
361
+ * hooks: {
362
+ * onBuildStart: (options) => {
363
+ * console.log('Build started with options:', options)
364
+ * },
365
+ * onBuildDone: ({ options, output }) => {
366
+ * console.log('Build completed with output:', output)
367
+ * }
368
+ * }
369
+ * }
370
+ * ]
371
+ */
372
+ plugins?: (BunupPlugin | BunPlugin)[];
373
+ /**
374
+ * Options for CSS handling in the build process.
375
+ */
376
+ css?: CSSOptions;
377
+ }
378
+ type PackageJson = {
379
+ /** The parsed content of the package.json file */
380
+ data: Record<string, any> | null
381
+ /** The path to the package.json file */
382
+ path: string | null
383
+ };
384
+ /**
385
+ * Represents the meta data of the build
386
+ */
387
+ type BuildMeta = {
388
+ /** The package.json file */
389
+ packageJson: PackageJson
390
+ /** The root directory of the build */
391
+ rootDir: string
392
+ };
393
+ type BuildOutputFile = {
394
+ /**
395
+ * The entry point for which this file was generated
396
+ *
397
+ * Undefined for non-entry point files (e.g., assets, sourcemaps, chunks)
398
+ */
399
+ entrypoint: string | undefined
400
+ /** The kind of the file */
401
+ kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode"
402
+ /** Absolute path to the generated file */
403
+ fullPath: string
404
+ /** Path to the generated file relative to the root directory */
405
+ pathRelativeToRootDir: string
406
+ /** Path to the generated file relative to the output directory */
407
+ pathRelativeToOutdir: string
408
+ /** Whether the file is a dts file */
409
+ dts: boolean
410
+ /** The format of the output file */
411
+ format: Format
412
+ };
413
+ /**
414
+ * Represents the output of a build operation
415
+ */
416
+ type BuildOutput = {
417
+ /** Array of generated files with their paths and contents */
418
+ files: BuildOutputFile[]
419
+ };
420
+ /**
421
+ * Context provided to build hooks
422
+ */
423
+ type BuildContext = {
424
+ /** The build options that were used */
425
+ options: BuildOptions
426
+ /** The output of the build */
427
+ output: BuildOutput
428
+ /** The meta data of the build */
429
+ meta: BuildMeta
430
+ };
431
+ /**
432
+ * Hooks that can be implemented by Bunup plugins
433
+ */
434
+ type BunupPluginHooks = {
435
+ /**
436
+ * Called when a build is successfully completed
437
+ * @param ctx Build context containing options and output
438
+ */
439
+ onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
440
+ /**
441
+ * Called before a build starts
442
+ * @param options Build options that will be used
443
+ */
444
+ onBuildStart?: (options: BuildOptions) => MaybePromise<void>
445
+ };
446
+ /**
447
+ * Represents a Bunup-specific plugin
448
+ */
449
+ type BunupPlugin = {
450
+ /** Optional name for the plugin */
451
+ name?: string
452
+ /** The hooks implemented by this plugin */
453
+ hooks: BunupPluginHooks
454
+ };
2
455
  type CopyOptions = {
3
456
  /** Whether to follow symbolic links when copying files. */
4
457
  followSymlinks?: boolean
@@ -29,7 +482,7 @@ declare class CopyBuilder {
29
482
  get hooks(): BunupPluginHooks;
30
483
  }
31
484
  type CustomExports = Record<string, string | Record<string, string | Record<string, string>>>;
32
- type Exclude = ((ctx: BuildContext) => string[] | undefined) | string[];
485
+ type Exclude2 = ((ctx: BuildContext) => string[] | undefined) | string[];
33
486
  interface ExportsPluginOptions {
34
487
  /**
35
488
  * Additional export fields to preserve alongside automatically generated exports
@@ -42,7 +495,7 @@ interface ExportsPluginOptions {
42
495
  *
43
496
  * @see https://bunup.dev/docs/builtin-plugins/exports#exclude
44
497
  */
45
- exclude?: Exclude;
498
+ exclude?: Exclude2;
46
499
  /**
47
500
  * Whether to exclude CSS files from being added to the exports field
48
501
  *
@@ -73,7 +526,7 @@ interface ExportsPluginOptions {
73
526
  * @see https://bunup.dev/docs/builtin-plugins/exports
74
527
  */
75
528
  declare function exports(options?: ExportsPluginOptions): BunupPlugin;
76
- import { BunPlugin } from "bun";
529
+ import { BunPlugin as BunPlugin2 } from "bun";
77
530
  type InjectStylesPluginOptions = {
78
531
  /**
79
532
  * Custom function to inject CSS into the document head.
@@ -115,12 +568,12 @@ type InjectStylesPluginOptions = {
115
568
  *
116
569
  * @see https://bunup.dev/docs/builtin-plugins/inject-styles
117
570
  */
118
- declare function injectStyles(options?: InjectStylesPluginOptions): BunPlugin;
119
- import { BunPlugin as BunPlugin2 } from "bun";
571
+ declare function injectStyles(options?: InjectStylesPluginOptions): BunPlugin2;
572
+ import { BunPlugin as BunPlugin3 } from "bun";
120
573
  /**
121
574
  * A plugin that provides shims for Node.js globals and ESM/CJS interoperability.
122
575
  */
123
- declare function shims(): BunPlugin2;
576
+ declare function shims(): BunPlugin3;
124
577
  interface UnusedOptions {
125
578
  /**
126
579
  * The level of reporting for unused dependencies
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.13.0",
4
+ "version": "0.13.5",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -47,7 +47,7 @@
47
47
  "bunup": "dist/cli/index.js"
48
48
  },
49
49
  "dependencies": {
50
- "@bunup/dts": "0.11.30",
50
+ "@bunup/dts": "0.13.2",
51
51
  "chokidar": "^4.0.3",
52
52
  "coffi": "^0.1.35",
53
53
  "lightningcss": "^1.30.1",
@@ -55,7 +55,7 @@
55
55
  "tinyexec": "^1.0.1",
56
56
  "tree-kill": "^1.2.2",
57
57
  "zlye": "^0.4.4",
58
- "@bunup/shared": "0.11.30"
58
+ "@bunup/shared": "0.13.2"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "typescript": ">=4.5.0"