bunup 0.5.11 → 0.5.13
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 +1 -1
- package/bin/bunup.mjs +3 -0
- package/dist/cli.js +66 -13
- package/dist/index.cjs +24 -0
- package/dist/index.d.cts +491 -0
- package/dist/index.d.ts +24 -6
- package/dist/index.js +15 -8
- package/dist/plugins.cjs +2 -0
- package/dist/plugins.d.cts +498 -0
- package/dist/plugins.d.ts +27 -5
- package/package.json +52 -23
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import _Bun from "bun";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/entry.d.ts
|
|
4
|
+
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
|
+
*/
|
|
22
|
+
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;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Represents the output of a build operation
|
|
32
|
+
*/
|
|
33
|
+
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
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Context provided to build hooks
|
|
44
|
+
*/
|
|
45
|
+
type BuildContext = {
|
|
46
|
+
/** The build options that were used */
|
|
47
|
+
options: BuildOptions;
|
|
48
|
+
/** The output of the build */
|
|
49
|
+
output: BuildOutput;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Hooks that can be implemented by Bunup plugins
|
|
53
|
+
*/
|
|
54
|
+
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>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Represents a Bunup-specific plugin
|
|
68
|
+
*/
|
|
69
|
+
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;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Union type representing all supported plugin types
|
|
79
|
+
*/
|
|
80
|
+
type Plugin = BunupBunPlugin | BunupPlugin; //#endregion
|
|
81
|
+
//#region src/options.d.ts
|
|
82
|
+
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
83
|
+
type Define = BunBuildOptions["define"];
|
|
84
|
+
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
85
|
+
type Format = Exclude<BunBuildOptions["format"], undefined>;
|
|
86
|
+
type Target = BunBuildOptions["target"];
|
|
87
|
+
type External = (string | RegExp)[];
|
|
88
|
+
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
89
|
+
type Entry = Arrayable<string> | Record<string, string>;
|
|
90
|
+
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;
|
|
99
|
+
};
|
|
100
|
+
type Shims = boolean | ShimOptions;
|
|
101
|
+
type DtsResolve = boolean | (string | RegExp)[];
|
|
102
|
+
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;
|
|
137
|
+
};
|
|
138
|
+
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
|
|
468
|
+
type MaybePromise<T> = Promise<T> | T;
|
|
469
|
+
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
470
|
+
type Arrayable<T> = T | T[];
|
|
471
|
+
type Bun = typeof _Bun;
|
|
472
|
+
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
473
|
+
type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
|
|
474
|
+
type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
|
|
475
|
+
type DefineWorkspaceItem = {
|
|
476
|
+
name: string;
|
|
477
|
+
root: string;
|
|
478
|
+
config: DefineConfigItem | DefineConfigItem[];
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/define.d.ts
|
|
483
|
+
declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
|
|
484
|
+
declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
|
|
485
|
+
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/build.d.ts
|
|
488
|
+
declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
|
|
489
|
+
|
|
490
|
+
//#endregion
|
|
491
|
+
export { BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin, build, defineConfig, defineWorkspace };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _Bun from "bun";
|
|
2
2
|
|
|
3
|
-
//#region
|
|
3
|
+
//#region src/helpers/entry.d.ts
|
|
4
4
|
type ProcessableEntry = {
|
|
5
5
|
fullPath: string;
|
|
6
6
|
/**
|
|
@@ -15,7 +15,10 @@ type ProcessableEntry = {
|
|
|
15
15
|
*/
|
|
16
16
|
outputBasePath: string;
|
|
17
17
|
}; //#endregion
|
|
18
|
-
//#region
|
|
18
|
+
//#region src/plugins/types.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
21
|
+
*/
|
|
19
22
|
type BunupBunPlugin = {
|
|
20
23
|
/** Identifies this as a native Bun plugin */
|
|
21
24
|
type: "bun";
|
|
@@ -24,6 +27,9 @@ type BunupBunPlugin = {
|
|
|
24
27
|
/** The actual Bun plugin implementation */
|
|
25
28
|
plugin: BunPlugin;
|
|
26
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Represents the output of a build operation
|
|
32
|
+
*/
|
|
27
33
|
type BuildOutput = {
|
|
28
34
|
/** Array of generated files with their paths and contents */
|
|
29
35
|
files: Array<{
|
|
@@ -33,12 +39,18 @@ type BuildOutput = {
|
|
|
33
39
|
relativePathToRootDir: string;
|
|
34
40
|
}>;
|
|
35
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Context provided to build hooks
|
|
44
|
+
*/
|
|
36
45
|
type BuildContext = {
|
|
37
46
|
/** The build options that were used */
|
|
38
47
|
options: BuildOptions;
|
|
39
48
|
/** The output of the build */
|
|
40
49
|
output: BuildOutput;
|
|
41
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Hooks that can be implemented by Bunup plugins
|
|
53
|
+
*/
|
|
42
54
|
type BunupPluginHooks = {
|
|
43
55
|
/**
|
|
44
56
|
* Called when a build is successfully completed
|
|
@@ -51,6 +63,9 @@ type BunupPluginHooks = {
|
|
|
51
63
|
*/
|
|
52
64
|
onBuildStart?: (options: BuildOptions) => MaybePromise<void>;
|
|
53
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Represents a Bunup-specific plugin
|
|
68
|
+
*/
|
|
54
69
|
type BunupPlugin = {
|
|
55
70
|
/** Identifies this as a Bunup-specific plugin */
|
|
56
71
|
type: "bunup";
|
|
@@ -59,8 +74,11 @@ type BunupPlugin = {
|
|
|
59
74
|
/** The hooks implemented by this plugin */
|
|
60
75
|
hooks: BunupPluginHooks;
|
|
61
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Union type representing all supported plugin types
|
|
79
|
+
*/
|
|
62
80
|
type Plugin = BunupBunPlugin | BunupPlugin; //#endregion
|
|
63
|
-
//#region
|
|
81
|
+
//#region src/options.d.ts
|
|
64
82
|
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
65
83
|
type Define = BunBuildOptions["define"];
|
|
66
84
|
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
@@ -446,7 +464,7 @@ interface BuildOptions {
|
|
|
446
464
|
dts: string;
|
|
447
465
|
};
|
|
448
466
|
} //#endregion
|
|
449
|
-
//#region
|
|
467
|
+
//#region src/types.d.ts
|
|
450
468
|
type MaybePromise<T> = Promise<T> | T;
|
|
451
469
|
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
452
470
|
type Arrayable<T> = T | T[];
|
|
@@ -461,12 +479,12 @@ type DefineWorkspaceItem = {
|
|
|
461
479
|
};
|
|
462
480
|
|
|
463
481
|
//#endregion
|
|
464
|
-
//#region
|
|
482
|
+
//#region src/define.d.ts
|
|
465
483
|
declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
|
|
466
484
|
declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
|
|
467
485
|
|
|
468
486
|
//#endregion
|
|
469
|
-
//#region
|
|
487
|
+
//#region src/build.d.ts
|
|
470
488
|
declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
|
|
471
489
|
|
|
472
490
|
//#endregion
|