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