bunup 0.5.14 → 0.5.17

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/index.d.cts CHANGED
@@ -1,84 +1,53 @@
1
1
  import _Bun from "bun";
2
-
3
- //#region src/helpers/entry.d.ts
4
2
  type ProcessableEntry = {
5
- fullPath: string;
6
- /**
7
- * The relative path to the output directory.
8
- *
9
- * This is the path that will be used to name the output file.
10
- *
11
- * Examples:
12
- * - "src/index.ts" → "index"
13
- * - "src/plugins/index.ts" → "plugins/index"
14
- * - etc.
15
- */
16
- outputBasePath: string;
17
- }; //#endregion
18
- //#region src/plugins/types.d.ts
19
- /**
20
- * Represents a Bun plugin that can be used with Bunup
21
- */
3
+ fullPath: string
4
+ outputBasePath: string | null
5
+ dts: boolean
6
+ };
22
7
  type BunupBunPlugin = {
23
- /** Identifies this as a native Bun plugin */
24
- type: "bun";
25
- /** Optional name for the plugin */
26
- name?: string;
27
- /** The actual Bun plugin implementation */
28
- plugin: BunPlugin;
8
+ /** Identifies this as a native Bun plugin */
9
+ type: "bun"
10
+ /** Optional name for the plugin */
11
+ name?: string
12
+ /** The actual Bun plugin implementation */
13
+ plugin: BunPlugin
29
14
  };
30
- /**
31
- * Represents the output of a build operation
32
- */
33
15
  type BuildOutput = {
34
- /** Array of generated files with their paths and contents */
35
- files: Array<{
36
- /** Path to the generated file */
37
- fullPath: string;
38
- /** Path to the generated file relative to the root directory */
39
- relativePathToRootDir: string;
40
- }>;
16
+ /** Array of generated files with their paths and contents */
17
+ files: Array<{
18
+ /** Path to the generated file */
19
+ fullPath: string
20
+ /** Path to the generated file relative to the root directory */
21
+ relativePathToRootDir: string
22
+ }>
41
23
  };
42
- /**
43
- * Context provided to build hooks
44
- */
45
24
  type BuildContext = {
46
- /** The build options that were used */
47
- options: BuildOptions;
48
- /** The output of the build */
49
- output: BuildOutput;
25
+ /** The build options that were used */
26
+ options: BuildOptions
27
+ /** The output of the build */
28
+ output: BuildOutput
50
29
  };
51
- /**
52
- * Hooks that can be implemented by Bunup plugins
53
- */
54
30
  type BunupPluginHooks = {
55
- /**
56
- * Called when a build is successfully completed
57
- * @param ctx Build context containing options and output
58
- */
59
- onBuildDone?: (ctx: BuildContext) => MaybePromise<void>;
60
- /**
61
- * Called before a build starts
62
- * @param options Build options that will be used
63
- */
64
- onBuildStart?: (options: BuildOptions) => MaybePromise<void>;
31
+ /**
32
+ * Called when a build is successfully completed
33
+ * @param ctx Build context containing options and output
34
+ */
35
+ onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
36
+ /**
37
+ * Called before a build starts
38
+ * @param options Build options that will be used
39
+ */
40
+ onBuildStart?: (options: BuildOptions) => MaybePromise<void>
65
41
  };
66
- /**
67
- * Represents a Bunup-specific plugin
68
- */
69
42
  type BunupPlugin = {
70
- /** Identifies this as a Bunup-specific plugin */
71
- type: "bunup";
72
- /** Optional name for the plugin */
73
- name?: string;
74
- /** The hooks implemented by this plugin */
75
- hooks: BunupPluginHooks;
43
+ /** Identifies this as a Bunup-specific plugin */
44
+ type: "bunup"
45
+ /** Optional name for the plugin */
46
+ name?: string
47
+ /** The hooks implemented by this plugin */
48
+ hooks: BunupPluginHooks
76
49
  };
77
- /**
78
- * Union type representing all supported plugin types
79
- */
80
- type Plugin = BunupBunPlugin | BunupPlugin; //#endregion
81
- //#region src/options.d.ts
50
+ type Plugin = BunupBunPlugin | BunupPlugin;
82
51
  type Loader = NonNullable<BunBuildOptions["loader"]>[string];
83
52
  type Define = BunBuildOptions["define"];
84
53
  type Sourcemap = BunBuildOptions["sourcemap"];
@@ -88,404 +57,318 @@ type External = (string | RegExp)[];
88
57
  type Env = BunBuildOptions["env"] | Record<string, string>;
89
58
  type Entry = Arrayable<string> | Record<string, string>;
90
59
  type ShimOptions = {
91
- /**
92
- * Adds __dirname and __filename shims for ESM files when used
93
- */
94
- dirnameFilename?: boolean;
95
- /**
96
- * Adds import.meta.url shims for CJS files when used
97
- */
98
- importMetaUrl?: boolean;
60
+ /**
61
+ * Adds __dirname and __filename shims for ESM files when used
62
+ */
63
+ dirnameFilename?: boolean
64
+ /**
65
+ * Adds import.meta.url shims for CJS files when used
66
+ */
67
+ importMetaUrl?: boolean
99
68
  };
100
69
  type Shims = boolean | ShimOptions;
101
70
  type DtsResolve = boolean | (string | RegExp)[];
102
71
  type DtsOptions = {
103
- /**
104
- * Entry point files for TypeScript declaration file generation
105
- *
106
- * This can be:
107
- * - A string path to a file
108
- * - An array of file paths
109
- * - An object where keys are output names and values are input file paths
110
- *
111
- * The key names are used for the generated declaration files.
112
- * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
113
- *
114
- * If not specified, the main entry points will be used for declaration file generation.
115
- *
116
- * If it's a string or an array of strings, the file name (without extension)
117
- * will be used as the name for the output declaration file.
118
- *
119
- * @example
120
- * // Using a string path
121
- * entry: 'src/index.ts' // Generates index.d.ts
122
- *
123
- * // Using string paths in an array
124
- * entry: ['src/index.ts'] // Generates index.d.ts
125
- *
126
- * // Using named outputs as an object
127
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
128
- *
129
- * // Organizing output with subdirectories
130
- * entry: { "client/index": "src/client/index.ts", "server/index": "src/server/index.ts" } // Generates client/index.d.ts and server/index.d.ts
131
- */
132
- entry?: Entry;
133
- /**
134
- * Resolve external types used in dts files from node_modules
135
- */
136
- resolve?: DtsResolve;
72
+ /**
73
+ * Entry point files for TypeScript declaration file generation
74
+ *
75
+ * This can be:
76
+ * - A string path to a file
77
+ * - An array of file paths
78
+ * - An object where keys are output names and values are input file paths
79
+ *
80
+ * The key names are used for the generated declaration files.
81
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
82
+ *
83
+ * If not specified, the main entry points will be used for declaration file generation.
84
+ *
85
+ * If it's a string or an array of strings, the file name (without extension)
86
+ * will be used as the name for the output declaration file.
87
+ *
88
+ * @see https://bunup.dev/docs/guide/typescript-declarations#custom-entry-points
89
+ * @see https://bunup.dev/docs/guide/typescript-declarations#named-entries
90
+ */
91
+ entry?: Entry
92
+ /**
93
+ * Resolve external types used in dts files from node_modules
94
+ */
95
+ resolve?: DtsResolve
137
96
  };
138
97
  interface BuildOptions {
139
- /**
140
- * Name of the build configuration
141
- * Used for logging and identification purposes
142
- */
143
- name?: string;
144
- /**
145
- * Entry point files for the build
146
- *
147
- * This can be:
148
- * - A string path to a file
149
- * - An array of file paths
150
- * - An object where keys are output names and values are input file paths
151
- *
152
- * The key names are used for the generated output files.
153
- * For example, `{custom: 'src/index.ts'}` will generate `custom.js`
154
- *
155
- * If it's a string or an array of strings, the file name (without extension)
156
- * will be used as the name for the output file.
157
- *
158
- * @example
159
- * // Using a string path
160
- * entry: 'src/index.ts' // Generates index.js
161
- *
162
- * // Using string paths in an array
163
- * entry: ['src/index.ts'] // Generates index.js
164
- *
165
- * // Using named outputs as an object
166
- * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
167
- */
168
- entry: Entry;
169
- /**
170
- * Output directory for the bundled files
171
- * Defaults to 'dist' if not specified
172
- */
173
- outDir: string;
174
- /**
175
- * Output formats for the bundle
176
- * Can include 'esm', 'cjs', and/or 'iife'
177
- * Defaults to ['cjs'] if not specified
178
- */
179
- format: Format[];
180
- /**
181
- * Whether to enable all minification options
182
- * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
183
- */
184
- minify?: boolean;
185
- /**
186
- * Whether to enable code splitting
187
- * Defaults to true for ESM format, false for CJS format
188
- */
189
- splitting?: boolean;
190
- /**
191
- * Whether to minify whitespace in the output
192
- * Removes unnecessary whitespace to reduce file size
193
- */
194
- minifyWhitespace?: boolean;
195
- /**
196
- * Whether to minify identifiers in the output
197
- * Renames variables and functions to shorter names
198
- */
199
- minifyIdentifiers?: boolean;
200
- /**
201
- * Whether to minify syntax in the output
202
- * Optimizes code structure for smaller file size
203
- */
204
- minifySyntax?: boolean;
205
- /**
206
- * Whether to watch for file changes and rebuild automatically
207
- */
208
- watch?: boolean;
209
- /**
210
- * Whether to generate TypeScript declaration files (.d.ts)
211
- * When set to true, generates declaration files for all entry points
212
- * Can also be configured with DtsOptions for more control
213
- */
214
- dts?: boolean | DtsOptions;
215
- /**
216
- * Generate only TypeScript declaration files (.d.ts) without any JavaScript output
217
- * When set to true, bunup will skip the JavaScript bundling process entirely
218
- * and only generate declaration files for the specified entry points
219
- *
220
- * This is useful when you want to use bunup's fast declaration file generation
221
- * but handle the JavaScript bundling separately or not at all.
222
- *
223
- * Note: When this option is true, the `dts` option is implicitly set to true
224
- * and other bundling-related options are ignored.
225
- *
226
- * @example
227
- * dtsOnly: true
228
- */
229
- dtsOnly?: boolean;
230
- /**
231
- * Path to a preferred tsconfig.json file to use for declaration generation
232
- *
233
- * If not specified, the tsconfig.json in the project root will be used.
234
- * This option allows you to use a different TypeScript configuration
235
- * specifically for declaration file generation.
236
- *
237
- * @example
238
- * preferredTsconfigPath: './tsconfig.build.json'
239
- */
240
- preferredTsconfigPath?: string;
241
- /**
242
- * External packages that should not be bundled
243
- * Useful for dependencies that should be kept as external imports
244
- */
245
- external?: External;
246
- /**
247
- * Packages that should be bundled even if they are in external
248
- * Useful for dependencies that should be included in the bundle
249
- */
250
- noExternal?: External;
251
- /**
252
- * The target environment for the bundle
253
- * Can be 'browser', 'bun', 'node', etc.
254
- * Defaults to 'node' if not specified
255
- */
256
- target?: Target;
257
- /**
258
- * Whether to clean the output directory before building
259
- * When true, removes all files in the outDir before starting a new build
260
- * Defaults to true if not specified
261
- */
262
- clean?: boolean;
263
- /**
264
- * Specifies the type of sourcemap to generate
265
- * Can be 'none', 'linked', 'external', or 'inline'
266
- * Can also be a boolean - when true, it will use 'inline'
267
- *
268
- * @see https://bun.sh/docs/bundler#sourcemap
269
- *
270
- * @default 'none'
271
- *
272
- * @example
273
- * sourcemap: 'linked'
274
- * // or
275
- * sourcemap: true // equivalent to 'inline'
276
- */
277
- sourcemap?: Sourcemap;
278
- /**
279
- * Define global constants for the build
280
- * These values will be replaced at build time
281
- *
282
- * @see https://bun.sh/docs/bundler#define
283
- *
284
- * @example
285
- * define: {
286
- * 'process.env.NODE_ENV': '"production"',
287
- * 'PACKAGE_VERSION': '"1.0.0"'
288
- * }
289
- */
290
- define?: Define;
291
- /**
292
- * A callback function that runs after the build process completes
293
- * This can be used for custom post-build operations like copying files,
294
- * running additional tools, or logging build information
295
- *
296
- * If watch mode is enabled, this callback runs after each rebuild
297
- *
298
- * @param options The build options that were used
299
- */
300
- onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
301
- /**
302
- * 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.
303
- *
304
- * @see https://bun.sh/docs/bundler#banner
305
- *
306
- * @example
307
- * banner: '"use client";'
308
- */
309
- banner?: string;
310
- /**
311
- * 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.
312
- *
313
- * @see https://bun.sh/docs/bundler#footer
314
- *
315
- * @example
316
- * footer: '// built with love in SF'
317
- */
318
- footer?: string;
319
- /**
320
- * 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.
321
- *
322
- * @see https://bun.sh/docs/bundler#drop
323
- *
324
- * @example
325
- * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
326
- */
327
- drop?: string[];
328
- /**
329
- * 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.
330
- *
331
- * @see https://bun.sh/docs/bundler#loader
332
- *
333
- * @example
334
- * loader: {
335
- * ".png": "dataurl",
336
- * ".txt": "file",
337
- * }
338
- */
339
- loader?: Record<string, Loader>;
340
- /**
341
- * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
342
- *
343
- * Bytecode is currently only supported for CommonJS (format: "cjs").
344
- *
345
- * Must be target: "bun"
346
- *
347
- * @see https://bun.sh/docs/bundler#bytecode
348
- *
349
- * @default false
350
- */
351
- bytecode?: boolean;
352
- /**
353
- * Disable logging during the build process. When set to true, no logs will be printed to the console.
354
- *
355
- * @default false
356
- */
357
- silent?: boolean;
358
- /**
359
- * You can specify a prefix to be added to specific import paths in your bundled code
360
- *
361
- * Used for assets, external modules, and chunk files when splitting is enabled
362
- *
363
- * @see https://bunup.dev/docs#public-path for more information
364
- *
365
- * @example
366
- * publicPath: 'https://cdn.example.com/'
367
- */
368
- publicPath?: string;
369
- /**
370
- * Inject Node.js compatibility shims for ESM/CJS interoperability
371
- *
372
- * When set to true, automatically injects all shims when needed
373
- * When set to an object, only injects the specified shims
374
- *
375
- * Available shims:
376
- * - dirnameFilename: Adds __dirname and __filename for ESM files when used
377
- * - importMetaUrl: Adds import.meta.url for CJS files when used
378
- *
379
- * @example
380
- * // Enable all shims
381
- * shims: true
382
- *
383
- * // Enable only specific shims
384
- * shims: { dirnameFilename: true, importMetaUrl: true }
385
- */
386
- shims?: Shims;
387
- /**
388
- * Controls how environment variables are handled during bundling.
389
- *
390
- * Can be one of:
391
- * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
392
- * of those environment variables at the time the build runs.
393
- * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
394
- * - A string ending in `*`: Only inlines environment variables matching the given prefix.
395
- * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
396
- * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
397
- * with the provided values, regardless of the runtime environment.
398
- *
399
- * Note: Values are injected at build time. Secrets or private keys should be excluded
400
- * from inlining when targeting browser environments.
401
- *
402
- * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
403
- *
404
- * @example
405
- * // Inline all environment variables available at build time
406
- * env: "inline"
407
- *
408
- * // Disable all environment variable injection
409
- * env: "disable"
410
- *
411
- * // Only inline environment variables with a specific prefix
412
- * env: "PUBLIC_*"
413
- *
414
- * // Provide specific environment variables manually
415
- * env: { API_URL: "https://api.example.com", DEBUG: "false" }
416
- */
417
- env?: Env;
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. Currently, only "bun" plugins are supported,
423
- * but in the future, this will be extended to include "bunup" plugins as well.
424
- *
425
- * Each plugin type has its own specific plugin implementation:
426
- * - "bun": Uses Bun's native plugin system (BunPlugin)
427
- * - "bunup": Will use bunup's own plugin system (coming in future versions)
428
- *
429
- * This architecture allows for extensibility as more plugin systems are added.
430
- *
431
- * @example
432
- * plugins: [
433
- * {
434
- * type: "bun",
435
- * plugin: myBunPlugin()
436
- * },
437
- * // In the future:
438
- * // {
439
- * // type: "bunup",
440
- * // plugin: myBunupPlugin()
441
- * // }
442
- * ]
443
- */
444
- plugins?: Plugin[];
445
- /**
446
- * Customize the output file extension for each format.
447
- *
448
- * @param options Contains format, packageType, options, and entry information
449
- * @returns Object with js and dts extensions (including the leading dot)
450
- *
451
- * @example
452
- * outputExtension: ({ format, entry }) => ({
453
- * js: entry.outputBasePath === 'worker' ? '.worker.js' : `.${format}.js`,
454
- * dts: `.${format}.d.ts`
455
- * })
456
- */
457
- outputExtension?: (options: {
458
- format: Format;
459
- packageType: string | undefined;
460
- options: BuildOptions;
461
- entry: ProcessableEntry;
462
- }) => {
463
- js: string;
464
- dts: string;
465
- };
466
- } //#endregion
467
- //#region src/types.d.ts
98
+ /**
99
+ * Name of the build configuration
100
+ * Used for logging and identification purposes
101
+ */
102
+ name?: string;
103
+ /**
104
+ * Entry point files for the build
105
+ *
106
+ * This can be:
107
+ * - A string path to a file
108
+ * - An array of file paths
109
+ * - An object where keys are output names and values are input file paths
110
+ *
111
+ * The key names are used for the generated output files.
112
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.js`
113
+ *
114
+ * If it's a string or an array of strings, the file name (without extension)
115
+ * will be used as the name for the output file.
116
+ *
117
+ * @see https://bunup.dev/docs/#entry-points
118
+ */
119
+ entry: Entry;
120
+ /**
121
+ * Output directory for the bundled files
122
+ * Defaults to 'dist' if not specified
123
+ */
124
+ outDir: string;
125
+ /**
126
+ * Output formats for the bundle
127
+ * Can include 'esm', 'cjs', and/or 'iife'
128
+ * Defaults to ['cjs'] if not specified
129
+ */
130
+ format: Format[];
131
+ /**
132
+ * Whether to enable all minification options
133
+ * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
134
+ */
135
+ minify?: boolean;
136
+ /**
137
+ * Whether to enable code splitting
138
+ * Defaults to true for ESM format, false for CJS format
139
+ */
140
+ splitting?: boolean;
141
+ /**
142
+ * Whether to minify whitespace in the output
143
+ * Removes unnecessary whitespace to reduce file size
144
+ */
145
+ minifyWhitespace?: boolean;
146
+ /**
147
+ * Whether to minify identifiers in the output
148
+ * Renames variables and functions to shorter names
149
+ */
150
+ minifyIdentifiers?: boolean;
151
+ /**
152
+ * Whether to minify syntax in the output
153
+ * Optimizes code structure for smaller file size
154
+ */
155
+ minifySyntax?: boolean;
156
+ /**
157
+ * Whether to watch for file changes and rebuild automatically
158
+ */
159
+ watch?: boolean;
160
+ /**
161
+ * Whether to generate TypeScript declaration files (.d.ts)
162
+ * When set to true, generates declaration files for all entry points
163
+ * Can also be configured with DtsOptions for more control
164
+ */
165
+ dts?: boolean | DtsOptions;
166
+ /**
167
+ * Path to a preferred tsconfig.json file to use for declaration generation
168
+ *
169
+ * If not specified, the tsconfig.json in the project root will be used.
170
+ * This option allows you to use a different TypeScript configuration
171
+ * specifically for declaration file generation.
172
+ *
173
+ * @example
174
+ * preferredTsconfigPath: './tsconfig.build.json'
175
+ */
176
+ preferredTsconfigPath?: string;
177
+ /**
178
+ * External packages that should not be bundled
179
+ * Useful for dependencies that should be kept as external imports
180
+ */
181
+ external?: External;
182
+ /**
183
+ * Packages that should be bundled even if they are in external
184
+ * Useful for dependencies that should be included in the bundle
185
+ */
186
+ noExternal?: External;
187
+ /**
188
+ * The target environment for the bundle
189
+ * Can be 'browser', 'bun', 'node', etc.
190
+ * Defaults to 'node' if not specified
191
+ */
192
+ target?: Target;
193
+ /**
194
+ * Whether to clean the output directory before building
195
+ * When true, removes all files in the outDir before starting a new build
196
+ * Defaults to true if not specified
197
+ */
198
+ clean?: boolean;
199
+ /**
200
+ * Specifies the type of sourcemap to generate
201
+ * Can be 'none', 'linked', 'external', or 'inline'
202
+ * Can also be a boolean - when true, it will use 'inline'
203
+ *
204
+ * @see https://bun.sh/docs/bundler#sourcemap
205
+ *
206
+ * @default 'none'
207
+ *
208
+ * @example
209
+ * sourcemap: 'linked'
210
+ * // or
211
+ * sourcemap: true // equivalent to 'inline'
212
+ */
213
+ sourcemap?: Sourcemap;
214
+ define?: Define;
215
+ /**
216
+ * A callback function that runs after the build process completes
217
+ * This can be used for custom post-build operations like copying files,
218
+ * running additional tools, or logging build information
219
+ *
220
+ * If watch mode is enabled, this callback runs after each rebuild
221
+ *
222
+ * @param options The build options that were used
223
+ */
224
+ onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
225
+ banner?: string;
226
+ /**
227
+ * 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.
228
+ *
229
+ * @see https://bun.sh/docs/bundler#footer
230
+ *
231
+ * @example
232
+ * footer: '// built with love in SF'
233
+ */
234
+ footer?: string;
235
+ /**
236
+ * 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.
237
+ *
238
+ * @see https://bun.sh/docs/bundler#drop
239
+ *
240
+ * @example
241
+ * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
242
+ */
243
+ drop?: string[];
244
+ /**
245
+ * 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.
246
+ *
247
+ * @see https://bun.sh/docs/bundler#loader
248
+ *
249
+ * @example
250
+ * loader: {
251
+ * ".png": "dataurl",
252
+ * ".txt": "file",
253
+ * }
254
+ */
255
+ loader?: Record<string, Loader>;
256
+ /**
257
+ * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
258
+ *
259
+ * Bytecode is currently only supported for CommonJS (format: "cjs").
260
+ *
261
+ * Must be target: "bun"
262
+ *
263
+ * @see https://bun.sh/docs/bundler#bytecode
264
+ *
265
+ * @default false
266
+ */
267
+ bytecode?: boolean;
268
+ /**
269
+ * Disable logging during the build process. When set to true, no logs will be printed to the console.
270
+ *
271
+ * @default false
272
+ */
273
+ silent?: boolean;
274
+ /**
275
+ * You can specify a prefix to be added to specific import paths in your bundled code
276
+ *
277
+ * Used for assets, external modules, and chunk files when splitting is enabled
278
+ *
279
+ * @see https://bunup.dev/docs#public-path for more information
280
+ *
281
+ * @example
282
+ * publicPath: 'https://cdn.example.com/'
283
+ */
284
+ publicPath?: string;
285
+ /**
286
+ * Inject Node.js compatibility shims for ESM/CJS interoperability
287
+ *
288
+ * When set to true, automatically injects all shims when needed
289
+ * When set to an object, only injects the specified shims
290
+ *
291
+ * Available shims:
292
+ * - dirnameFilename: Adds __dirname and __filename for ESM files when used
293
+ * - importMetaUrl: Adds import.meta.url for CJS files when used
294
+ *
295
+ * @example
296
+ * // Enable all shims
297
+ * shims: true
298
+ *
299
+ * // Enable only specific shims
300
+ * shims: { dirnameFilename: true, importMetaUrl: true }
301
+ */
302
+ shims?: Shims;
303
+ /**
304
+ * Controls how environment variables are handled during bundling.
305
+ *
306
+ * Can be one of:
307
+ * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
308
+ * of those environment variables at the time the build runs.
309
+ * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
310
+ * - A string ending in `*`: Only inlines environment variables matching the given prefix.
311
+ * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
312
+ * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
313
+ * with the provided values, regardless of the runtime environment.
314
+ *
315
+ * Note: Values are injected at build time. Secrets or private keys should be excluded
316
+ * from inlining when targeting browser environments.
317
+ *
318
+ * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
319
+ *
320
+ * @example
321
+ * // Inline all environment variables available at build time
322
+ * env: "inline"
323
+ *
324
+ * // Disable all environment variable injection
325
+ * env: "disable"
326
+ *
327
+ * // Only inline environment variables with a specific prefix
328
+ * env: "PUBLIC_*"
329
+ *
330
+ * // Provide specific environment variables manually
331
+ * env: { API_URL: "https://api.example.com", DEBUG: "false" }
332
+ */
333
+ env?: Env;
334
+ plugins?: Plugin[];
335
+ /**
336
+ * Customize the output file extension for each format.
337
+ *
338
+ * @param options Contains format, packageType, options, and entry information
339
+ * @returns Object with js extension (including the leading dot). If dts is true, the dts file extension will be automatically derived from the js extension
340
+ *
341
+ * @example
342
+ * outputExtension: ({ format, entry }) => ({
343
+ * js: entry.outputBasePath === 'worker' ? '.worker.js' : `.${format}.js`
344
+ * // For example, if js is '.worker.js', the dts will automatically be '.worker.d.ts'
345
+ * })
346
+ */
347
+ outputExtension?: (options: {
348
+ format: Format
349
+ packageType: string | undefined
350
+ options: BuildOptions
351
+ entry: ProcessableEntry
352
+ }) => {
353
+ js: string
354
+ };
355
+ }
468
356
  type MaybePromise<T> = Promise<T> | T;
469
- type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
357
+ type WithOptional<
358
+ T,
359
+ K extends keyof T
360
+ > = Omit<T, K> & Partial<Pick<T, K>>;
470
361
  type Arrayable<T> = T | T[];
471
362
  type Bun = typeof _Bun;
472
363
  type BunBuildOptions = Parameters<Bun["build"]>[0];
473
364
  type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
474
365
  type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
475
366
  type DefineWorkspaceItem = {
476
- name: string;
477
- root: string;
478
- config: DefineConfigItem | DefineConfigItem[];
367
+ name: string
368
+ root: string
369
+ config: DefineConfigItem | DefineConfigItem[]
479
370
  };
480
-
481
- //#endregion
482
- //#region src/define.d.ts
483
371
  declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
484
372
  declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
485
-
486
- //#endregion
487
- //#region src/build.d.ts
488
373
  declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
489
-
490
- //#endregion
491
- export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin, build, defineConfig, defineWorkspace };
374
+ export { defineWorkspace, defineConfig, build, Plugin, DefineWorkspaceItem, DefineConfigItem, BuildOptions };