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