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/README.md +11 -11
- package/dist/cli.js +36 -45
- package/dist/index.cjs +6 -15
- package/dist/index.d.cts +336 -453
- package/dist/index.d.ts +336 -453
- package/dist/index.js +6 -15
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.d.cts +340 -463
- package/dist/plugins.d.ts +340 -463
- package/dist/plugins.js +1 -1
- package/package.json +7 -12
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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<
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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 };
|