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