bunup 0.4.74 → 0.4.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +23 -0
- package/dist/index.cjs +16 -0
- package/dist/{index.d.mts → index.d.cts} +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -8
- package/dist/plugins.cjs +2 -0
- package/dist/plugins.d.cts +492 -0
- package/dist/plugins.d.ts +492 -0
- package/dist/plugins.js +2 -0
- package/package.json +7 -6
- package/dist/cli.mjs +0 -23
- package/dist/index.mjs +0 -16
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import _Bun from "bun";
|
|
2
|
+
|
|
3
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/helpers/entry.d.ts
|
|
4
|
+
type ProcessableEntry = {
|
|
5
|
+
fullEntryPath: string
|
|
6
|
+
name: string
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/types.d.ts
|
|
11
|
+
type MaybePromise<T> = Promise<T> | T;
|
|
12
|
+
type Arrayable<T> = T | T[];
|
|
13
|
+
type Bun = typeof _Bun;
|
|
14
|
+
type BunBuildOptions = Parameters<Bun["build"]>[0];
|
|
15
|
+
type BunPlugin = Exclude<BunBuildOptions["plugins"], undefined>[number];
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/options.d.ts
|
|
19
|
+
type Loader = NonNullable<BunBuildOptions["loader"]>[string];
|
|
20
|
+
type Define = BunBuildOptions["define"];
|
|
21
|
+
type Sourcemap = BunBuildOptions["sourcemap"];
|
|
22
|
+
type Format = Exclude<BunBuildOptions["format"], undefined>;
|
|
23
|
+
type Target = BunBuildOptions["target"];
|
|
24
|
+
type External = (string | RegExp)[];
|
|
25
|
+
type Env = BunBuildOptions["env"] | Record<string, string>;
|
|
26
|
+
type Entry = Arrayable<string> | Record<string, string>;
|
|
27
|
+
type ShimOptions = {
|
|
28
|
+
/**
|
|
29
|
+
* Adds __dirname and __filename shims for ESM files when used
|
|
30
|
+
*/
|
|
31
|
+
dirnameFilename?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* Adds import.meta.url shims for CJS files when used
|
|
34
|
+
*/
|
|
35
|
+
importMetaUrl?: boolean
|
|
36
|
+
};
|
|
37
|
+
type Shims = boolean | ShimOptions;
|
|
38
|
+
type DtsResolve = boolean | (string | RegExp)[];
|
|
39
|
+
type DtsOptions = {
|
|
40
|
+
/**
|
|
41
|
+
* Entry point files for TypeScript declaration file generation
|
|
42
|
+
*
|
|
43
|
+
* This can be:
|
|
44
|
+
* - A string path to a file
|
|
45
|
+
* - An array of file paths
|
|
46
|
+
* - An object where keys are output names and values are input file paths
|
|
47
|
+
*
|
|
48
|
+
* The key names are used for the generated declaration files.
|
|
49
|
+
* For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
|
|
50
|
+
*
|
|
51
|
+
* If not specified, the main entry points will be used for declaration file generation.
|
|
52
|
+
*
|
|
53
|
+
* If it's a string or an array of strings, the file name (without extension)
|
|
54
|
+
* will be used as the name for the output declaration file.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Using a string path
|
|
58
|
+
* entry: 'src/index.ts' // Generates index.d.ts
|
|
59
|
+
*
|
|
60
|
+
* // Using string paths in an array
|
|
61
|
+
* entry: ['src/index.ts'] // Generates index.d.ts
|
|
62
|
+
*
|
|
63
|
+
* // Using named outputs as an object
|
|
64
|
+
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
|
|
65
|
+
*
|
|
66
|
+
* // Organizing output with subdirectories
|
|
67
|
+
* entry: { "client/index": "src/client/index.ts", "server/index": "src/server/index.ts" } // Generates client/index.d.ts and server/index.d.ts
|
|
68
|
+
*/
|
|
69
|
+
entry?: Entry
|
|
70
|
+
/**
|
|
71
|
+
* Resolve external types used in dts files from node_modules
|
|
72
|
+
*/
|
|
73
|
+
resolve?: DtsResolve
|
|
74
|
+
};
|
|
75
|
+
interface BuildOptions {
|
|
76
|
+
/**
|
|
77
|
+
* Name of the build configuration
|
|
78
|
+
* Used for logging and identification purposes
|
|
79
|
+
*/
|
|
80
|
+
name?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Entry point files for the build
|
|
83
|
+
*
|
|
84
|
+
* This can be:
|
|
85
|
+
* - A string path to a file
|
|
86
|
+
* - An array of file paths
|
|
87
|
+
* - An object where keys are output names and values are input file paths
|
|
88
|
+
*
|
|
89
|
+
* The key names are used for the generated output files.
|
|
90
|
+
* For example, `{custom: 'src/index.ts'}` will generate `custom.js`
|
|
91
|
+
*
|
|
92
|
+
* If it's a string or an array of strings, the file name (without extension)
|
|
93
|
+
* will be used as the name for the output file.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Using a string path
|
|
97
|
+
* entry: 'src/index.ts' // Generates index.js
|
|
98
|
+
*
|
|
99
|
+
* // Using string paths in an array
|
|
100
|
+
* entry: ['src/index.ts'] // Generates index.js
|
|
101
|
+
*
|
|
102
|
+
* // Using named outputs as an object
|
|
103
|
+
* entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
|
|
104
|
+
*/
|
|
105
|
+
entry: Entry;
|
|
106
|
+
/**
|
|
107
|
+
* Output directory for the bundled files
|
|
108
|
+
* Defaults to 'dist' if not specified
|
|
109
|
+
*/
|
|
110
|
+
outDir: string;
|
|
111
|
+
/**
|
|
112
|
+
* Output formats for the bundle
|
|
113
|
+
* Can include 'esm', 'cjs', and/or 'iife'
|
|
114
|
+
* Defaults to ['cjs'] if not specified
|
|
115
|
+
*/
|
|
116
|
+
format: Format[];
|
|
117
|
+
/**
|
|
118
|
+
* Whether to enable all minification options
|
|
119
|
+
* When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
|
|
120
|
+
*/
|
|
121
|
+
minify?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether to enable code splitting
|
|
124
|
+
* Defaults to true for ESM format, false for CJS format
|
|
125
|
+
*/
|
|
126
|
+
splitting?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Whether to minify whitespace in the output
|
|
129
|
+
* Removes unnecessary whitespace to reduce file size
|
|
130
|
+
*/
|
|
131
|
+
minifyWhitespace?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Whether to minify identifiers in the output
|
|
134
|
+
* Renames variables and functions to shorter names
|
|
135
|
+
*/
|
|
136
|
+
minifyIdentifiers?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Whether to minify syntax in the output
|
|
139
|
+
* Optimizes code structure for smaller file size
|
|
140
|
+
*/
|
|
141
|
+
minifySyntax?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Whether to watch for file changes and rebuild automatically
|
|
144
|
+
*/
|
|
145
|
+
watch?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Whether to generate TypeScript declaration files (.d.ts)
|
|
148
|
+
* When set to true, generates declaration files for all entry points
|
|
149
|
+
* Can also be configured with DtsOptions for more control
|
|
150
|
+
*/
|
|
151
|
+
dts?: boolean | DtsOptions;
|
|
152
|
+
/**
|
|
153
|
+
* Generate only TypeScript declaration files (.d.ts) without any JavaScript output
|
|
154
|
+
* When set to true, bunup will skip the JavaScript bundling process entirely
|
|
155
|
+
* and only generate declaration files for the specified entry points
|
|
156
|
+
*
|
|
157
|
+
* This is useful when you want to use bunup's fast declaration file generation
|
|
158
|
+
* but handle the JavaScript bundling separately or not at all.
|
|
159
|
+
*
|
|
160
|
+
* Note: When this option is true, the `dts` option is implicitly set to true
|
|
161
|
+
* and other bundling-related options are ignored.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* dtsOnly: true
|
|
165
|
+
*/
|
|
166
|
+
dtsOnly?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Path to a preferred tsconfig.json file to use for declaration generation
|
|
169
|
+
*
|
|
170
|
+
* If not specified, the tsconfig.json in the project root will be used.
|
|
171
|
+
* This option allows you to use a different TypeScript configuration
|
|
172
|
+
* specifically for declaration file generation.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* preferredTsconfigPath: './tsconfig.build.json'
|
|
176
|
+
*/
|
|
177
|
+
preferredTsconfigPath?: string;
|
|
178
|
+
/**
|
|
179
|
+
* External packages that should not be bundled
|
|
180
|
+
* Useful for dependencies that should be kept as external imports
|
|
181
|
+
*/
|
|
182
|
+
external?: External;
|
|
183
|
+
/**
|
|
184
|
+
* Packages that should be bundled even if they are in external
|
|
185
|
+
* Useful for dependencies that should be included in the bundle
|
|
186
|
+
*/
|
|
187
|
+
noExternal?: External;
|
|
188
|
+
/**
|
|
189
|
+
* The target environment for the bundle
|
|
190
|
+
* Can be 'browser', 'bun', 'node', etc.
|
|
191
|
+
* Defaults to 'node' if not specified
|
|
192
|
+
*/
|
|
193
|
+
target?: Target;
|
|
194
|
+
/**
|
|
195
|
+
* Whether to clean the output directory before building
|
|
196
|
+
* When true, removes all files in the outDir before starting a new build
|
|
197
|
+
* Defaults to true if not specified
|
|
198
|
+
*/
|
|
199
|
+
clean?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Specifies the type of sourcemap to generate
|
|
202
|
+
* Can be 'none', 'linked', 'external', or 'inline'
|
|
203
|
+
* Can also be a boolean - when true, it will use 'inline'
|
|
204
|
+
*
|
|
205
|
+
* @see https://bun.sh/docs/bundler#sourcemap
|
|
206
|
+
*
|
|
207
|
+
* @default 'none'
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* sourcemap: 'linked'
|
|
211
|
+
* // or
|
|
212
|
+
* sourcemap: true // equivalent to 'inline'
|
|
213
|
+
*/
|
|
214
|
+
sourcemap?: Sourcemap;
|
|
215
|
+
/**
|
|
216
|
+
* Define global constants for the build
|
|
217
|
+
* These values will be replaced at build time
|
|
218
|
+
*
|
|
219
|
+
* @see https://bun.sh/docs/bundler#define
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* define: {
|
|
223
|
+
* 'process.env.NODE_ENV': '"production"',
|
|
224
|
+
* 'PACKAGE_VERSION': '"1.0.0"'
|
|
225
|
+
* }
|
|
226
|
+
*/
|
|
227
|
+
define?: Define;
|
|
228
|
+
/**
|
|
229
|
+
* A callback function that runs after the build process completes
|
|
230
|
+
* This can be used for custom post-build operations like copying files,
|
|
231
|
+
* running additional tools, or logging build information
|
|
232
|
+
*
|
|
233
|
+
* If watch mode is enabled, this callback runs after each rebuild
|
|
234
|
+
*
|
|
235
|
+
* @param options The build options that were used
|
|
236
|
+
*/
|
|
237
|
+
onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* 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.
|
|
240
|
+
*
|
|
241
|
+
* @see https://bun.sh/docs/bundler#banner
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* banner: '"use client";'
|
|
245
|
+
*/
|
|
246
|
+
banner?: string;
|
|
247
|
+
/**
|
|
248
|
+
* 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.
|
|
249
|
+
*
|
|
250
|
+
* @see https://bun.sh/docs/bundler#footer
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* footer: '// built with love in SF'
|
|
254
|
+
*/
|
|
255
|
+
footer?: string;
|
|
256
|
+
/**
|
|
257
|
+
* 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.
|
|
258
|
+
*
|
|
259
|
+
* @see https://bun.sh/docs/bundler#drop
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
|
|
263
|
+
*/
|
|
264
|
+
drop?: string[];
|
|
265
|
+
/**
|
|
266
|
+
* 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.
|
|
267
|
+
*
|
|
268
|
+
* @see https://bun.sh/docs/bundler#loader
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* loader: {
|
|
272
|
+
* ".png": "dataurl",
|
|
273
|
+
* ".txt": "file",
|
|
274
|
+
* }
|
|
275
|
+
*/
|
|
276
|
+
loader?: Record<string, Loader>;
|
|
277
|
+
/**
|
|
278
|
+
* Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
|
|
279
|
+
*
|
|
280
|
+
* Bytecode is currently only supported for CommonJS (format: "cjs").
|
|
281
|
+
*
|
|
282
|
+
* Must be target: "bun"
|
|
283
|
+
*
|
|
284
|
+
* @see https://bun.sh/docs/bundler#bytecode
|
|
285
|
+
*
|
|
286
|
+
* @default false
|
|
287
|
+
*/
|
|
288
|
+
bytecode?: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* Disable logging during the build process. When set to true, no logs will be printed to the console.
|
|
291
|
+
*
|
|
292
|
+
* @default false
|
|
293
|
+
*/
|
|
294
|
+
silent?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* You can specify a prefix to be added to specific import paths in your bundled code
|
|
297
|
+
*
|
|
298
|
+
* Used for assets, external modules, and chunk files when splitting is enabled
|
|
299
|
+
*
|
|
300
|
+
* @see https://bunup.dev/documentation/#public-path for more information
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* publicPath: 'https://cdn.example.com/'
|
|
304
|
+
*/
|
|
305
|
+
publicPath?: string;
|
|
306
|
+
/**
|
|
307
|
+
* Inject Node.js compatibility shims for ESM/CJS interoperability
|
|
308
|
+
*
|
|
309
|
+
* When set to true, automatically injects all shims when needed
|
|
310
|
+
* When set to an object, only injects the specified shims
|
|
311
|
+
*
|
|
312
|
+
* Available shims:
|
|
313
|
+
* - dirnameFilename: Adds __dirname and __filename for ESM files when used
|
|
314
|
+
* - importMetaUrl: Adds import.meta.url for CJS files when used
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* // Enable all shims
|
|
318
|
+
* shims: true
|
|
319
|
+
*
|
|
320
|
+
* // Enable only specific shims
|
|
321
|
+
* shims: { dirnameFilename: true, importMetaUrl: true }
|
|
322
|
+
*/
|
|
323
|
+
shims?: Shims;
|
|
324
|
+
/**
|
|
325
|
+
* Controls how environment variables are handled during bundling.
|
|
326
|
+
*
|
|
327
|
+
* Can be one of:
|
|
328
|
+
* - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
|
|
329
|
+
* of those environment variables at the time the build runs.
|
|
330
|
+
* - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
|
|
331
|
+
* - A string ending in `*`: Only inlines environment variables matching the given prefix.
|
|
332
|
+
* For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
|
|
333
|
+
* - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
|
|
334
|
+
* with the provided values, regardless of the runtime environment.
|
|
335
|
+
*
|
|
336
|
+
* Note: Values are injected at build time. Secrets or private keys should be excluded
|
|
337
|
+
* from inlining when targeting browser environments.
|
|
338
|
+
*
|
|
339
|
+
* @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* // Inline all environment variables available at build time
|
|
343
|
+
* env: "inline"
|
|
344
|
+
*
|
|
345
|
+
* // Disable all environment variable injection
|
|
346
|
+
* env: "disable"
|
|
347
|
+
*
|
|
348
|
+
* // Only inline environment variables with a specific prefix
|
|
349
|
+
* env: "PUBLIC_*"
|
|
350
|
+
*
|
|
351
|
+
* // Provide specific environment variables manually
|
|
352
|
+
* env: { API_URL: "https://api.example.com", DEBUG: "false" }
|
|
353
|
+
*/
|
|
354
|
+
env?: Env;
|
|
355
|
+
/**
|
|
356
|
+
* Plugins to extend the build process functionality
|
|
357
|
+
*
|
|
358
|
+
* The Plugin type uses a discriminated union pattern with the 'type' field
|
|
359
|
+
* to support different plugin systems. Currently, only "bun" plugins are supported,
|
|
360
|
+
* but in the future, this will be extended to include "bunup" plugins as well.
|
|
361
|
+
*
|
|
362
|
+
* Each plugin type has its own specific plugin implementation:
|
|
363
|
+
* - "bun": Uses Bun's native plugin system (BunPlugin)
|
|
364
|
+
* - "bunup": Will use bunup's own plugin system (coming in future versions)
|
|
365
|
+
*
|
|
366
|
+
* This architecture allows for extensibility as more plugin systems are added.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* plugins: [
|
|
370
|
+
* {
|
|
371
|
+
* type: "bun",
|
|
372
|
+
* plugin: myBunPlugin()
|
|
373
|
+
* },
|
|
374
|
+
* // In the future:
|
|
375
|
+
* // {
|
|
376
|
+
* // type: "bunup",
|
|
377
|
+
* // plugin: myBunupPlugin()
|
|
378
|
+
* // }
|
|
379
|
+
* ]
|
|
380
|
+
*/
|
|
381
|
+
plugins?: Plugin[];
|
|
382
|
+
/**
|
|
383
|
+
* Customize the output file extension for each format.
|
|
384
|
+
*
|
|
385
|
+
* @param options Contains format, packageType, options, and entry information
|
|
386
|
+
* @returns Object with js and dts extensions (including the leading dot)
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* outputExtension: ({ format, entry }) => ({
|
|
390
|
+
* js: entry.name === 'worker' ? '.worker.js' : `.${format}.js`,
|
|
391
|
+
* dts: `.${format}.d.ts`
|
|
392
|
+
* })
|
|
393
|
+
*/
|
|
394
|
+
outputExtension?: (options: {
|
|
395
|
+
format: Format
|
|
396
|
+
packageType: string | undefined
|
|
397
|
+
options: BuildOptions
|
|
398
|
+
entry: ProcessableEntry
|
|
399
|
+
}) => {
|
|
400
|
+
js: string
|
|
401
|
+
dts: string
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/plugins/types.d.ts
|
|
407
|
+
/**
|
|
408
|
+
* Represents a Bun plugin that can be used with Bunup
|
|
409
|
+
*/
|
|
410
|
+
type BunupBunPlugin = {
|
|
411
|
+
/** Identifies this as a native Bun plugin */
|
|
412
|
+
type: "bun"
|
|
413
|
+
/** Optional name for the plugin */
|
|
414
|
+
name?: string
|
|
415
|
+
/** The actual Bun plugin implementation */
|
|
416
|
+
plugin: BunPlugin
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Represents the output of a build operation
|
|
420
|
+
*/
|
|
421
|
+
type BuildOutput = {
|
|
422
|
+
/** Array of generated files with their paths and contents */
|
|
423
|
+
files: Array<{
|
|
424
|
+
/** Path to the generated file */
|
|
425
|
+
fullPath: string
|
|
426
|
+
/** Path to the generated file relative to the output directory */
|
|
427
|
+
relativePathToOutputDir: string
|
|
428
|
+
}>
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Context provided to build hooks
|
|
432
|
+
*/
|
|
433
|
+
type BuildContext = {
|
|
434
|
+
/** The build options that were used */
|
|
435
|
+
options: BuildOptions
|
|
436
|
+
/** The output of the build */
|
|
437
|
+
output: BuildOutput
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Hooks that can be implemented by Bunup plugins
|
|
441
|
+
*/
|
|
442
|
+
type BunupPluginHooks = {
|
|
443
|
+
/**
|
|
444
|
+
* Called when a build is successfully completed
|
|
445
|
+
* @param ctx Build context containing options and output
|
|
446
|
+
*/
|
|
447
|
+
onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
|
|
448
|
+
/**
|
|
449
|
+
* Called before a build starts
|
|
450
|
+
* @param options Build options that will be used
|
|
451
|
+
*/
|
|
452
|
+
onBuildStart?: (options: BuildOptions) => MaybePromise<void>
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* Represents a Bunup-specific plugin
|
|
456
|
+
*/
|
|
457
|
+
type BunupPlugin = {
|
|
458
|
+
/** Identifies this as a Bunup-specific plugin */
|
|
459
|
+
type: "bunup"
|
|
460
|
+
/** Optional name for the plugin */
|
|
461
|
+
name?: string
|
|
462
|
+
/** The hooks implemented by this plugin */
|
|
463
|
+
hooks: BunupPluginHooks
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Union type representing all supported plugin types
|
|
467
|
+
*/
|
|
468
|
+
type Plugin = BunupBunPlugin | BunupPlugin;
|
|
469
|
+
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region \0dts:/home/runner/work/bunup/bunup/src/plugins/built-in/report.d.ts
|
|
472
|
+
type ReportPluginOptions = {
|
|
473
|
+
/**
|
|
474
|
+
* The maximum bundle size in bytes.
|
|
475
|
+
* If the bundle size exceeds this limit, a error will be logged without failing the build.
|
|
476
|
+
*/
|
|
477
|
+
maxBundleSize?: number
|
|
478
|
+
/**
|
|
479
|
+
* Whether to show gzip sizes in the report.
|
|
480
|
+
* When enabled, the report will include an additional column with the gzip size of each file.
|
|
481
|
+
* @default true
|
|
482
|
+
*/
|
|
483
|
+
gzip?: boolean
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* A plugin that logs a report of the bundle size.
|
|
487
|
+
* @param options - The options for the report plugin.
|
|
488
|
+
*/
|
|
489
|
+
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
490
|
+
|
|
491
|
+
//#endregion
|
|
492
|
+
export { report };
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var D=Object.create;var{getPrototypeOf:F,defineProperty:O,getOwnPropertyNames:P}=Object;var $=Object.prototype.hasOwnProperty;var E=(r,e,t)=>{t=r!=null?D(F(r)):{};let o=e||!r||!r.__esModule?O(t,"default",{value:r,enumerable:!0}):t;for(let i of P(r))if(!$.call(o,i))O(o,i,{get:()=>r[i],enumerable:!0});return o};var j=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var w=j((U,y)=>{var C=process||{},L=C.argv||[],f=C.env||{},A=!(!!f.NO_COLOR||L.includes("--no-color"))&&(!!f.FORCE_COLOR||L.includes("--color")||C.platform==="win32"||(C.stdout||{}).isTTY&&f.TERM!=="dumb"||!!f.CI),S=(r,e,t=r)=>(o)=>{let i=""+o,a=i.indexOf(e,r.length);return~a?r+N(i,e,t,a)+e:r+i+e},N=(r,e,t,o)=>{let i="",a=0;do i+=r.substring(a,o)+t,a=o+e.length,o=r.indexOf(e,a);while(~o);return i+r.substring(a)},T=(r=A)=>{let e=r?S:()=>String;return{isColorSupported:r,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};y.exports=T();y.exports.createColors=T});var p=E(w(),1);var n=E(w(),1),W=!1;class x{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=n.default.blue;mutedColor=n.default.dim;infoColor=n.default.cyan;warnColor=n.default.yellow;errorColor=n.default.red;defaultColor=n.default.white;progressFgColorMap={ESM:n.default.yellow,CJS:n.default.green,IIFE:n.default.magenta,DTS:n.default.blue};progressBgColorMap={ESM:n.default.bgYellow,CJS:n.default.bgGreen,IIFE:n.default.bgMagenta,DTS:n.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!x.instance)x.instance=new x;return x.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(r){if(!r?.once)return!0;if(this.loggedOnceMessages.has(r.once))return!1;return this.loggedOnceMessages.add(r.once),!0}formatMessage({fgColor:r,bgColor:e,label:t,message:o,identifier:i,muted:a}){let b=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),s=a?this.mutedColor(o):o,g=i?` ${e(n.default.black(` ${i} `))}`:"";return`${r(t)} ${b}${s}${g}`}output(r,e={},t=console.log){if(W||!this.shouldLog(e))return;if(e.verticalSpace)t("");if(t(r),e.verticalSpace)t("")}cli(r,e={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:n.default.bgBlue,label:this.labels.cli,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e)}info(r,e={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:n.default.bgCyan,label:this.labels.info,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e)}warn(r,e={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:n.default.bgYellow,label:this.labels.warn,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e,console.warn)}error(r,e={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:n.default.bgRed,label:this.labels.error,message:r,identifier:e.identifier,muted:e.muted});this.output(t,e,console.error)}getProgressFgColor(r){for(let[e,t]of Object.entries(this.progressFgColorMap))if(r.includes(e))return t;return this.defaultColor}getProgressBgColor(r){for(let[e,t]of Object.entries(this.progressBgColorMap))if(r.includes(e))return t;return n.default.bgWhite}progress(r,e,t={}){let o=this.getProgressFgColor(r),i=this.getProgressBgColor(r),a=this.formatMessage({fgColor:o,bgColor:i,label:r,message:e,identifier:t.identifier,muted:t.muted});this.output(a,t)}}function k(r,e,t){let o={};for(let s of r){let g=s.header.length,l=e.map((m)=>m[s.header]?.length||0),d=t?t[s.header]?.length||0:0;o[s.header]=Math.max(g,...l,d)}let i=(s,g,l)=>{return l==="left"?s.padEnd(g):s.padStart(g)},a=r.map((s)=>i(s.header,o[s.header],s.align)).join(n.default.gray(" | "));console.log(n.default.gray(a));let b=r.map((s)=>"-".repeat(o[s.header])).join(" | ");console.log(n.default.gray(b));for(let s of e){let g=r.map((l)=>{let d=s[l.header]||"",m=i(d,o[l.header],l.align);return l.color?l.color(m):m}).join(n.default.gray(" | "));console.log(g)}if(console.log(n.default.gray(b)),t){let s=r.map((g)=>{let l=t[g.header]||"";return i(l,o[g.header],g.align)}).join(n.default.gray(" | "));console.log(s)}}var _=x.getInstance();var Y=E(w(),1);function h(r){if(r===0)return"0 B";let e=["B","KB","MB","GB"],t=Math.floor(Math.log(r)/Math.log(1024));if(t===0)return`${r} ${e[t]}`;return`${(r/1024**t).toFixed(2)} ${e[t]}`}function z(r={}){let{maxBundleSize:e,gzip:t=!0}=r;return{type:"bunup",name:"report",hooks:{onBuildDone:async({options:o,output:i})=>{if(o.watch)return;let a=await Promise.all(i.files.map(async(c)=>{let u=c.relativePathToOutputDir,B=Bun.file(c.fullPath).size,R,v;if(t){let I=await Bun.file(c.fullPath).text();R=Bun.gzipSync(I).length,v=h(R)}return{name:u,size:B,formattedSize:h(B),gzipSize:R,formattedGzipSize:v}})),b=a.reduce((c,u)=>c+u.size,0),s=h(b),g,l;if(t)g=a.reduce((c,u)=>c+(u.gzipSize||0),0),l=h(g);let d=[{header:"File",align:"left",color:p.default.blue},{header:"Size",align:"right",color:p.default.green}];if(t)d.push({header:"Gzip",align:"right",color:p.default.magenta});let m=a.map((c)=>{let u={File:c.name,Size:c.formattedSize};if(t&&c.formattedGzipSize)u.Gzip=c.formattedGzipSize;return u}),M={File:"Total",Size:s};if(t&&l)M.Gzip=l;if(console.log(""),k(d,m,M),e&&b>e)console.log(""),console.log(p.default.red(`Your bundle size of ${s} exceeds the configured limit of ${h(e)}`));console.log("")}}}}export{z as report};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
3
|
"description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.78",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"maintainers": [
|
|
8
9
|
{
|
|
9
10
|
"name": "Arshad Yaseen",
|
|
@@ -19,11 +20,11 @@
|
|
|
19
20
|
"funding": "https://github.com/sponsors/arshad-yaseen",
|
|
20
21
|
"keywords": ["bun", "bunup", "bun-bundler"],
|
|
21
22
|
"types": "./dist/index.d.ts",
|
|
22
|
-
"main": "./dist/index.
|
|
23
|
-
"module": "./dist/index.
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
24
25
|
"files": ["dist"],
|
|
25
26
|
"bin": {
|
|
26
|
-
"bunup": "./dist/cli.
|
|
27
|
+
"bunup": "./dist/cli.js"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "bunup",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
},
|
|
50
51
|
"lint-staged": {
|
|
51
52
|
"*": "bun run format --no-errors-on-unmatched",
|
|
52
|
-
"src/**/*.(m|c)?(j|t)s
|
|
53
|
+
"src/**/*.(m|c)?(j|t)s": "bun run tsc"
|
|
53
54
|
},
|
|
54
55
|
"workspaces": ["tests", "docs", "benchmarks", "create-bunup"],
|
|
55
56
|
"dependencies": {
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"@biomejs/biome": "^1.9.4",
|
|
75
76
|
"@types/bun": "^1.2.5",
|
|
76
77
|
"bumpp": "^10.1.0",
|
|
77
|
-
"bunup": "^0.4.
|
|
78
|
+
"bunup": "^0.4.74",
|
|
78
79
|
"create-bunup": "create-bunup",
|
|
79
80
|
"husky": "^9.1.7",
|
|
80
81
|
"lint-staged": "^15.5.1",
|
package/dist/cli.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
// @bun
|
|
3
|
-
var kr=Object.create;var{getPrototypeOf:Sr,defineProperty:on,getOwnPropertyNames:Tr}=Object;var $r=Object.prototype.hasOwnProperty;var E=(n,r,t)=>{t=n!=null?kr(Sr(n)):{};let e=r||!n||!n.__esModule?on(t,"default",{value:n,enumerable:!0}):t;for(let i of Tr(n))if(!$r.call(e,i))on(e,i,{get:()=>n[i],enumerable:!0});return e};var Lr=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports);var Rr=(n,r)=>{for(var t in r)on(n,t,{get:r[t],enumerable:!0,configurable:!0,set:(e)=>r[t]=()=>e})};var d=(n,r)=>()=>(n&&(r=n(n=0)),r);var Ir=import.meta.require;var v=Lr((be,sn)=>{var F=process||{},On=F.argv||[],q=F.env||{},Mr=!(!!q.NO_COLOR||On.includes("--no-color"))&&(!!q.FORCE_COLOR||On.includes("--color")||F.platform==="win32"||(F.stdout||{}).isTTY&&q.TERM!=="dumb"||!!q.CI),Ar=(n,r,t=n)=>(e)=>{let i=""+e,o=i.indexOf(r,n.length);return~o?n+jr(i,r,t,o)+r:n+i+r},jr=(n,r,t,e)=>{let i="",o=0;do i+=n.substring(o,e)+t,o=e+r.length,e=n.indexOf(r,o);while(~e);return i+n.substring(o)},kn=(n=Mr)=>{let r=n?Ar:()=>String;return{isColorSupported:n,reset:r("\x1B[0m","\x1B[0m"),bold:r("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:r("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:r("\x1B[3m","\x1B[23m"),underline:r("\x1B[4m","\x1B[24m"),inverse:r("\x1B[7m","\x1B[27m"),hidden:r("\x1B[8m","\x1B[28m"),strikethrough:r("\x1B[9m","\x1B[29m"),black:r("\x1B[30m","\x1B[39m"),red:r("\x1B[31m","\x1B[39m"),green:r("\x1B[32m","\x1B[39m"),yellow:r("\x1B[33m","\x1B[39m"),blue:r("\x1B[34m","\x1B[39m"),magenta:r("\x1B[35m","\x1B[39m"),cyan:r("\x1B[36m","\x1B[39m"),white:r("\x1B[37m","\x1B[39m"),gray:r("\x1B[90m","\x1B[39m"),bgBlack:r("\x1B[40m","\x1B[49m"),bgRed:r("\x1B[41m","\x1B[49m"),bgGreen:r("\x1B[42m","\x1B[49m"),bgYellow:r("\x1B[43m","\x1B[49m"),bgBlue:r("\x1B[44m","\x1B[49m"),bgMagenta:r("\x1B[45m","\x1B[49m"),bgCyan:r("\x1B[46m","\x1B[49m"),bgWhite:r("\x1B[47m","\x1B[49m"),blackBright:r("\x1B[90m","\x1B[39m"),redBright:r("\x1B[91m","\x1B[39m"),greenBright:r("\x1B[92m","\x1B[39m"),yellowBright:r("\x1B[93m","\x1B[39m"),blueBright:r("\x1B[94m","\x1B[39m"),magentaBright:r("\x1B[95m","\x1B[39m"),cyanBright:r("\x1B[96m","\x1B[39m"),whiteBright:r("\x1B[97m","\x1B[39m"),bgBlackBright:r("\x1B[100m","\x1B[49m"),bgRedBright:r("\x1B[101m","\x1B[49m"),bgGreenBright:r("\x1B[102m","\x1B[49m"),bgYellowBright:r("\x1B[103m","\x1B[49m"),bgBlueBright:r("\x1B[104m","\x1B[49m"),bgMagentaBright:r("\x1B[105m","\x1B[49m"),bgCyanBright:r("\x1B[106m","\x1B[49m"),bgWhiteBright:r("\x1B[107m","\x1B[49m")}};sn.exports=kn();sn.exports.createColors=kn});function G(n){Tn=n??!1}class A{static instance;loggedOnceMessages=new Set;MAX_LABEL_LENGTH=3;cliColor=p.default.blue;mutedColor=p.default.dim;infoColor=p.default.cyan;warnColor=p.default.yellow;errorColor=p.default.red;defaultColor=p.default.white;progressFgColorMap={ESM:p.default.yellow,CJS:p.default.green,IIFE:p.default.magenta,DTS:p.default.blue};progressBgColorMap={ESM:p.default.bgYellow,CJS:p.default.bgGreen,IIFE:p.default.bgMagenta,DTS:p.default.bgBlue};labels={cli:"CLI",info:"INFO",warn:"WARN",error:"ERROR"};constructor(){}static getInstance(){if(!A.instance)A.instance=new A;return A.instance}dispose(){this.loggedOnceMessages.clear()}shouldLog(n){if(!n?.once)return!0;if(this.loggedOnceMessages.has(n.once))return!1;return this.loggedOnceMessages.add(n.once),!0}formatMessage({fgColor:n,bgColor:r,label:t,message:e,identifier:i,muted:o}){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length)),c=o?this.mutedColor(e):e,a=i?` ${r(p.default.black(` ${i} `))}`:"";return`${n(t)} ${s}${c}${a}`}output(n,r={},t=console.log){if(Tn||!this.shouldLog(r))return;if(r.verticalSpace)t("");if(t(n),r.verticalSpace)t("")}cli(n,r={}){let t=this.formatMessage({fgColor:this.cliColor,bgColor:p.default.bgBlue,label:this.labels.cli,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}info(n,r={}){let t=this.formatMessage({fgColor:this.infoColor,bgColor:p.default.bgCyan,label:this.labels.info,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r)}warn(n,r={}){let t=this.formatMessage({fgColor:this.warnColor,bgColor:p.default.bgYellow,label:this.labels.warn,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.warn)}error(n,r={}){let t=this.formatMessage({fgColor:this.errorColor,bgColor:p.default.bgRed,label:this.labels.error,message:n,identifier:r.identifier,muted:r.muted});this.output(t,r,console.error)}getProgressFgColor(n){for(let[r,t]of Object.entries(this.progressFgColorMap))if(n.includes(r))return t;return this.defaultColor}getProgressBgColor(n){for(let[r,t]of Object.entries(this.progressBgColorMap))if(n.includes(r))return t;return p.default.bgWhite}progress(n,r,t={}){let e=this.getProgressFgColor(n),i=this.getProgressBgColor(n),o=this.formatMessage({fgColor:e,bgColor:i,label:n,message:r,identifier:t.identifier,muted:t.muted});this.output(o,t)}}var p,Tn=!1,l;var T=d(()=>{p=E(v(),1);l=A.getInstance()});function an(n){return n instanceof Z}var b,R,I,w,C,Q,Z,y=(n)=>{if(n instanceof Error)return n.message;return String(n)},vr,un=(n,r)=>{let t=y(n),e=r?`[${r}] `:"",i=an(n),o="ERROR";if(n instanceof I)o="BUILD ERROR";else if(n instanceof w)o="DTS ERROR";else if(n instanceof C)o="CLI ERROR";else if(n instanceof Q)o="WATCH ERROR";else if(i)o="ISOLATED DECL ERROR";else if(n instanceof R)o="BUNUP ERROR";let s=vr.find((c)=>c.pattern.test(t)&&(c.errorType===o||!c.errorType));if(!s)console.error(`${b.default.red(o)} ${e}${i?b.default.dim(t):t}`);if(s)console.log(`
|
|
4
|
-
`),s.logSolution(t),console.log(`
|
|
5
|
-
`);else if(!i)console.error(b.default.dim(b.default.white("If you think this is a bug, please open an issue at: ")+b.default.cyan("https://github.com/arshad-yaseen/bunup/issues/new")))},$n=(n,r)=>{un(n,r),process.exit(1)};var B=d(()=>{b=E(v(),1);T();R=class R extends Error{constructor(n){super(n);this.name="BunupError"}};I=class I extends R{constructor(n){super(n);this.name="BunupBuildError"}};w=class w extends R{constructor(n){super(n);this.name="BunupDTSBuildError"}};C=class C extends R{constructor(n){super(n);this.name="BunupCLIError"}};Q=class Q extends R{constructor(n){super(n);this.name="BunupWatchError"}};Z=class Z extends R{constructor(n){super(n);this.name="BunupIsolatedDeclError"}};vr=[{pattern:/Could not resolve: "bun"/i,errorType:"BUILD ERROR",logSolution:()=>{l.error(b.default.white("You're trying to build a project that uses Bun. ")+b.default.white("Please set the target option to ")+b.default.cyan("`bun`")+b.default.white(`.
|
|
6
|
-
`)+b.default.white("Example: ")+b.default.green("`bunup --target bun`")+b.default.white(" or in config: ")+b.default.green("{ target: 'bun' }"))}}]});import Ln from"fs/promises";import Ur from"path";function Rn(n,r,t){return Array.isArray(n)?n.map((e)=>({...e,[r]:t})):{...n,[r]:t}}function In(n){return Array.isArray(n)?n:[n]}function Mn(n,r){switch(n){case"esm":return j(r)?".js":".mjs";case"cjs":return j(r)?".cjs":".js";case"iife":return".global.js"}}function An(n,r){switch(n){case"esm":return j(r)?".d.ts":".d.mts";case"cjs":return j(r)?".d.cts":".d.ts";case"iife":return".d.ts"}}function cn(n){return n==="node"||n==="bun"}function j(n){return n==="module"}function z(n){return n>=1000?`${(n/1000).toFixed(2)}s`:`${Math.round(n)}ms`}function jn(n){if(!n)return[];return Array.from(new Set([...Object.keys(n.dependencies||{}),...Object.keys(n.peerDependencies||{})]))}function M(n,r=3){return n.split("/").slice(-r).join("/")}async function En(n,r){let t=Ur.join(n,r);try{await Ln.rm(t,{recursive:!0,force:!0})}catch(e){throw new I(`Failed to clean output directory: ${e}`)}await Ln.mkdir(t,{recursive:!0})}function V(n){return[".ts",".mts",".cts",".tsx"].some((r)=>n.endsWith(r))}var O=d(()=>{B()});import{basename as _r,dirname as Hr,extname as Wr}from"path";function X(n){let r=_r(n),t=Wr(r);return t?r.slice(0,-t.length):r}function U(n){if(typeof n==="string")return[{fullEntryPath:n,name:X(n)}];if(typeof n==="object"&&!Array.isArray(n))return Object.entries(n).map(([e,i])=>({fullEntryPath:i,name:e}));let r=[],t=new Set;for(let e of n){let i=X(e);if(!t.has(i)){r.push({fullEntryPath:e,name:i}),t.add(i);continue}let s=Hr(e).split("/").filter((a)=>a!=="."&&a!=="");if(s.length===0){let a=1,u;do u=`${i}_${a++}`;while(t.has(u));r.push({fullEntryPath:e,name:u}),t.add(u);continue}let c=!1;for(let a=1;a<=s.length&&!c;a++){let m=`${s.slice(-a).join("/")}/${i}`;if(!t.has(m))r.push({fullEntryPath:e,name:m}),t.add(m),c=!0}if(!c){let a=1,u;do u=`${s.join("/")}/${i}_${a++}`;while(t.has(u));r.push({fullEntryPath:e,name:u}),t.add(u)}}return r}function vn(n){return n.filter((r)=>V(r.fullEntryPath))}function Un(n,r){return`[dir]/${n}${r}`}var N=d(()=>{O()});import Fr from"path";import{loadConfig as Wn}from"coffi";async function Dn(n,r,t){return Array.isArray(n)&&"root"in n[0]?n.filter((e)=>t?t.includes(e.name):!0).map((e)=>({rootDir:Fr.resolve(r,e.root),options:Rn(e.config,"name",e.name)})):[{rootDir:r,options:n}]}async function Yn(n){let{config:r,filepath:t}=await Wn({name:"package",cwd:n,extensions:[".json"]});return{packageJson:r,path:t}}async function qn(n,r){let{config:t,filepath:e}=await Wn({name:"tsconfig",cwd:n,extensions:[".json"],preferredPath:r});return{tsconfig:t,path:e}}var mn=d(()=>{O()});function Kr(n){return jn(n).map((r)=>new RegExp(`^${r}($|\\/|\\\\)`))}function Fn(n,r){return typeof r==="string"?r===n:r.test(n)}function nn(n,r,t){let i=Kr(t).some((s)=>s.test(n))||r.external?.some((s)=>Fn(n,s)),o=r.noExternal?.some((s)=>Fn(n,s));return i&&!o}var gn=d(()=>{O()});import{resolveTsImportPath as Gr}from"ts-import-resolver";var H="\x00dts:",Kn=(n,r,t)=>{return{name:"bunup:virtual-dts",async resolveId(e,i){if(fn(e))return e;if(!i||!fn(i))return null;let o=r.tsconfig?Gr({path:e,importer:_(i),tsconfig:r.tsconfig,rootDir:t}):null;if(!o)return null;let s=$(o);if(n.has(s))return rn(s);return null},load(e){if(e.startsWith(H)){let i=_(e),o=n.get(i);if(o)return o}return null}}};var pn=d(()=>{W()});function Gn(n){return n.endsWith(".d.ts")||n.endsWith(".d.mts")||n.endsWith(".d.cts")}function Qn(n){return dn.test(n)&&!Gn(n)}function $(n){if(Gn(n))return n;if(n.endsWith(".mts"))return`${n.slice(0,-4)}.d.mts`;if(n.endsWith(".cts"))return`${n.slice(0,-4)}.d.cts`;if(dn.test(n))return n.replace(dn,".d.ts");return`${n}.d.ts`}function fn(n){return n.startsWith(H)}function _(n){return n.replace(H,"")}function rn(n){return`${H}${n}`}function Zn(n,r){if(r===void 0)return"";let t=n.slice(0,r).split(`
|
|
7
|
-
`),e=t.length,i=t[t.length-1].length+1;return` (${e}:${i})`}function zn(n,r,t,e){if(typeof e==="boolean"&&e)return!1;if(Array.isArray(e)){for(let i of e)if(typeof i==="string"&&n===i)return!1;else if(i instanceof RegExp&&i.test(n))return!1}return nn(n,r,t)}var dn;var W=d(()=>{gn();pn();dn=/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/});import Vn from"path";import{ResolverFactory as Qr}from"oxc-resolver";function Xn(n,r){return{name:"bunup:types-resolve",buildStart(){bn||=new Qr({mainFields:["types","typings","module","main"],conditionNames:["types","typings","import","require"],extensions:[".d.ts",".d.mts",".d.cts",".ts",".mts",".cts"],...n.path&&{tsconfig:{configFile:n.path}},modules:["node_modules","node_modules/@types"]})},async resolveId(t,e){if(r===!1)return;if(t==="bun")return;let i=e?_(e):void 0;if(/\0/.test(t))return;if(Array.isArray(r)){if(!r.some((a)=>typeof a==="string"?a===t:a.test(t)))return}let o=i?Vn.dirname(i):process.cwd(),{path:s}=await bn.async(o,t);if(!s)return;if(Qn(s)){let c=$(s);try{let{path:a}=await bn.async(Vn.dirname(s),c);if(a)return a}catch(a){}return}return s}}}var bn;var Nn=d(()=>{W()});import{build as Zr}from"rolldown";import{dts as zr}from"rolldown-plugin-dts";async function Jn(n,r,t,e,i,o){let s=$(n),c=rn(s),a=typeof t.dts==="object"&&"resolve"in t.dts?t.dts.resolve:void 0;try{let{output:u}=await Zr({input:c,output:{dir:t.outDir},write:!1,...i.path&&{resolve:{tsconfigFilename:i.path}},onwarn(m,g){if(["UNRESOLVED_IMPORT","CIRCULAR_DEPENDENCY","EMPTY_BUNDLE"].includes(m.code??""))return;g(m)},plugins:[Kn(r,i,o),a&&Xn(i,a),zr({dtsInput:!0,emitDtsOnly:!0})],external:(m)=>zn(m,t,e,a)});if(!u[0]?.code)return l.warn(`Generated empty declaration file for entry "${n}"`,{muted:!0}),"";return u[0].code}catch(u){throw new w(`DTS bundling failed for entry "${n}": ${y(u)}`)}}var Pn=d(()=>{B();T();Nn();W();pn()});import{resolveTsImportPath as Vr}from"ts-import-resolver";function te(n){let r=new Set,t=[Xr,Nr,Jr,Pr,ne,re,ee];for(let e of t){let i=n.matchAll(e);for(let o of i)if(o[1])r.add(o[1])}return r}async function nr(n,r,t){let e=new Set([n]),i=[n];while(i.length){let o=i.pop();if(!o)continue;try{let s=await Bun.file(o).text(),c=te(s);for(let a of c){let u=r.tsconfig?Vr({path:a,importer:o,tsconfig:r.tsconfig,rootDir:t}):null;if(!u)continue;if(!e.has(u))e.add(u),i.push(u)}}catch(s){l.warn(`Error processing ${o}: ${y(s)}`)}}return e}var Xr,Nr,Jr,Pr,ne,re,ee;var rr=d(()=>{B();T();Xr=/^\s*import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/gm,Nr=/^\s*export\s+.*from\s+['"]([^'"]+)['"]/gm,Jr=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,Pr=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,ne=/import\s+\w+\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,re=/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)['"]\s*\/>/g,ee=/\/\/\/\s*<reference\s+types\s*=\s*['"]([^'"]+)['"]\s*\/>/g});import{isolatedDeclaration as ie}from"oxc-transform";async function er(n,r){let t=!1,e=new Map;if(await Promise.all([...n].map(async(i)=>{try{let o=$(i);if(!await Bun.file(i).exists())return;let c=await Bun.file(i).text(),{code:a,errors:u}=ie(i,c);if(a)e.set(o,a);for(let m of u){if(!t&&!r)console.log(`
|
|
8
|
-
`);let g=m.labels[0],f=g?Zn(c,g.start):"",h=`${M(i)}${f}: ${oe(m.message)}`;l[r?"warn":"error"](h),t=!0}}catch(o){l.warn(`Failed to generate declaration for ${i}: ${y(o)}`)}})),t&&!r)throw console.log(`
|
|
9
|
-
`),new Z(`TypeScript is asking for explicit type annotations on your exports. This helps ensure better, more reliable type declarations for your library. Bunup uses TypeScript's ${xn.default.blue("isolatedDeclarations")} feature to generate these declarations, which requires each export from your library to be fully typed. You can learn more here: ${xn.default.blue("https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations")}`);return e}function oe(n){return n.replace(" with --isolatedDeclarations","").replace(" with --isolatedDeclaration","")}var xn;var tr=d(()=>{xn=E(v(),1);B();T();O();W()});import ir from"fs/promises";import hn from"path";async function or(n,r){let t=hn.resolve(n),e=hn.resolve(t,r);if(!await ir.exists(t))throw new w(`Root directory does not exist: ${t}`);if(!await Bun.file(e).exists())throw new w(`Entry file does not exist: ${e}`);if(!V(e))throw new w(`Entry file must be a TypeScript file: ${e}`);if(hn.relative(t,e).startsWith(".."))throw new w(`Entry file must be within rootDir: ${e}`);return{absoluteRootDir:t,absoluteEntry:e}}var sr=d(()=>{B();O()});async function ar(n,r,t,e,i){let{absoluteEntry:o}=await or(n,r),s=await nr(o,e,n),c=await er(s,t.watch);return Jn(o,c,t,i,e,n)}var ur=d(()=>{Pn();rr();tr();sr()});function en(n){return{...se,...n}}function cr(n){let{minify:r,minifyWhitespace:t,minifyIdentifiers:e,minifySyntax:i}=n,o=r===!0;return{whitespace:t??o,identifiers:e??o,syntax:i??o}}function lr(n,r){return r==="cjs"?n:void 0}function mr(n,r,t,e){return{...typeof t==="object"&&Object.keys(t).reduce((i,o)=>{let s=JSON.stringify(t[o]);return i[`process.env.${o}`]=s,i[`import.meta.env.${o}`]=s,i},{}),...n,...e==="cjs"&&(r===!0||typeof r==="object"&&r.importMetaUrl)&&{"import.meta.url":"importMetaUrl"}}}function gr(n,r){return n===void 0?r==="esm":n}function fr(n){return typeof n==="string"?n:void 0}var se;var wn=d(()=>{se={entry:[],format:["cjs"],outDir:"dist",target:"node",clean:!0}});function pr(n,r){return{name:"bunup:external-plugin",setup(t){t.onResolve({filter:/.*/},(e)=>{let i=e.path;if(nn(i,n,r))return{path:i,external:!0};return null})}}}var dr=d(()=>{gn()});function br({format:n,target:r,shims:t}){let i=ue(t).map((o)=>yn[o]).filter((o)=>o.appliesTo(n,r));if(i.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:ae},async({path:s})=>{let c=await Bun.file(s).text(),a=i.filter((f)=>f.isNeededInFile(c));if(a.length===0)return;let{shebangLine:u,codeContent:m}=ce(c),g=a.map((f)=>f.generateCode()).join("");return{contents:u+g+m}})}}}function ue(n){if(n===!0)return Object.keys(yn);if(!n)return[];return Object.entries(n).filter(([r,t])=>t&&(r in yn)).map(([r])=>r)}function ce(n){if(!n.startsWith("#!"))return{shebangLine:"",codeContent:n};let r=n.indexOf(`
|
|
10
|
-
`);return r===-1?{shebangLine:"",codeContent:n}:{shebangLine:n.slice(0,r+1),codeContent:n.slice(r+1)}}var ae,yn;var xr=d(()=>{O();ae=/\.(js|ts|jsx|tsx|mts|cts)$/,yn={dirnameFilename:{appliesTo:(n,r)=>n==="esm"&&cn(r),isNeededInFile:(n)=>/\b__dirname\b/.test(n)||/\b__filename\b/.test(n),generateCode:()=>`import { fileURLToPath } from 'url';
|
|
11
|
-
import { dirname } from 'path';
|
|
12
|
-
|
|
13
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
-
const __dirname = dirname(__filename);
|
|
15
|
-
|
|
16
|
-
`},importMetaUrl:{appliesTo:(n,r)=>n==="cjs"&&cn(r),isNeededInFile:(n)=>/\bimport\.meta\.url\b/.test(n),generateCode:()=>`import { pathToFileURL } from 'url';
|
|
17
|
-
|
|
18
|
-
const importMetaUrl = pathToFileURL(__filename).href;
|
|
19
|
-
|
|
20
|
-
`}}});function hr(n){if(!n)return[];return n.filter((r)=>r.type==="bun")}function wr(n){if(!n)return[];return n.filter((r)=>r.type==="bunup")}async function yr(n,r){if(!n)return;for(let t of n)if(t.hooks.onBuildStart)await t.hooks.onBuildStart(r)}async function Cr(n,r,t){if(!n)return;for(let e of n)if(e.hooks.onBuildDone)await e.hooks.onBuildDone({options:r,output:t})}var Br={};Rr(Br,{build:()=>Cn});async function Cn(n,r=process.cwd()){let t={files:[]},e=en(n);if(!e.entry||e.entry.length===0||!e.outDir)throw new I("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(e.clean)En(r,e.outDir);G(e.silent);let{packageJson:i,path:o}=await Yn(r);if(i&&o)l.cli(`Using package.json: ${M(o,2)}`,{muted:!0,identifier:e.name,once:`${o}:${e.name}`});let s=wr(e.plugins);await yr(s,e);let c=U(e.entry),a=i?.type;if(!e.dtsOnly){let u=[pr(e,i),...hr(e.plugins).map((g)=>g.plugin)],m=e.format.flatMap((g)=>c.map(async(f)=>{let L=e.outputExtension?.({format:g,packageType:a,options:e,entry:f}).js??Mn(g,a),h=await Bun.build({entrypoints:[`${r}/${f.fullEntryPath}`],format:g,naming:{entry:Un(f.name,L)},splitting:gr(e.splitting,g),bytecode:lr(e.bytecode,g),define:mr(e.define,e.shims,e.env,g),minify:cr(e),outdir:`${r}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:fr(e.env),plugins:[...u,br({format:g,target:e.target,shims:e.shims})],throw:!1});if(!h.success)for(let S of h.logs){if(S.level==="error")throw new I(S.message);if(S.level==="warning")l.warn(S.message);else if(S.level==="info")l.info(S.message)}let D=`${e.outDir}/${f.name}${L}`,Y=`${r}/${D}`;t.files.push({path:Y}),l.progress(g.toUpperCase(),D,{identifier:e.name})}));await Promise.all(m)}if(e.dts||e.dtsOnly){let u=await qn(r,e.preferredTsconfigPath);if(u.path)l.cli(`Using tsconfig: ${M(u.path,2)}`,{muted:!0,identifier:e.name,once:`${u.path}:${e.name}`});let m=e.format.filter((f)=>{if(f==="iife"&&!j(a)&&e.format.includes("cjs"))return!1;return!0}),g=typeof e.dts==="object"&&e.dts.entry?U(e.dts.entry):vn(c);try{await Promise.all(g.map(async(f)=>{let L=await ar(r,f.fullEntryPath,e,u,i);await Promise.all(m.map(async(h)=>{let D=e.outputExtension?.({format:h,packageType:a,options:e,entry:f}).dts??An(h,a),Y=`${e.outDir}/${f.name}${D}`,S=`${r}/${Y}`;t.files.push({path:S}),await Bun.write(S,L),l.progress("DTS",Y,{identifier:e.name})}))}))}catch(f){if(an(f))throw f;throw new w(y(f))}}if(await Cr(s,e,t),e.onSuccess)await e.onSuccess(e)}var Bn=d(()=>{ur();B();N();mn();T();wn();dr();xr();O()});import{exec as me}from"tinyexec";var ln=E(v(),1);var K="0.4.74";var Sn="https://bunup.dev/cli-options";B();N();T();function x(n){return(r,t)=>{t[n]=r===!0||r==="true"}}function k(n){return(r,t)=>{if(typeof r==="string")t[n]=r;else throw new C(`Option --${n} requires a string value`)}}function J(n){return(r,t)=>{if(typeof r==="string")t[n]=r.split(",");else throw new C(`Option --${n} requires a string value`)}}function Dr(n){return(r,t)=>{if(typeof r==="boolean")t[n]=r;else if(typeof r==="string")if(r.toLowerCase()==="true"||r.toLowerCase()==="false")t[n]=r.toLowerCase()==="true";else t[n]=r;else throw new C(`Option --${n} requires a boolean or string value`)}}function Yr(){console.log(`
|
|
21
|
-
Bunup - \u26A1\uFE0F A blazing-fast build tool for your libraries built with Bun.
|
|
22
|
-
`),console.log("For more information on available options, visit:"),console.log(`${ln.default.cyan(ln.default.underline(Sn))}
|
|
23
|
-
`),process.exit(0)}function qr(){console.log(K),process.exit(0)}var _n={name:{flags:["n","name"],handler:k("name")},format:{flags:["f","format"],handler:J("format")},outDir:{flags:["o","out-dir"],handler:k("outDir")},minify:{flags:["m","minify"],handler:x("minify")},watch:{flags:["w","watch"],handler:x("watch")},dts:{flags:["d","dts"],handler:x("dts")},banner:{flags:["bn","banner"],handler:k("banner")},footer:{flags:["ft","footer"],handler:k("footer")},external:{flags:["e","external"],handler:J("external")},sourcemap:{flags:["sm","sourcemap"],handler:Dr("sourcemap")},target:{flags:["t","target"],handler:k("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:x("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:x("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:x("minifySyntax")},clean:{flags:["c","clean"],handler:x("clean")},splitting:{flags:["s","splitting"],handler:x("splitting")},noExternal:{flags:["ne","no-external"],handler:J("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:k("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:x("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:x("dtsOnly")},silent:{flags:["silent"],handler:x("silent")},config:{flags:["config"],handler:k("config")},publicPath:{flags:["pp","public-path"],handler:k("publicPath")},env:{flags:["env"],handler:k("env")},shims:{flags:["shims"],handler:x("shims")},onSuccess:{flags:["onSuccess"],handler:k("onSuccess")},filter:{flags:["filter"],handler:J("filter")},entry:{flags:["entry"],handler:(n,r,t)=>{if(typeof n!=="string")throw new C(`Entry${t?` --entry.${t}`:""} requires a string value`);let e=r.entry||{};if(t){if(e[t])l.warn(`Duplicate entry name '${t}' provided via --entry.${t}. Overwriting previous entry.`);e[t]=n}else{let i=X(n);if(e[i])l.warn(`Duplicate entry name '${i}' derived from '${n}'. Overwriting previous entry.`);e[i]=n}r.entry=e}},resolveDts:{flags:["rd","resolve-dts"],handler:(n,r)=>{if(!r.dts)r.dts={};if(typeof r.dts==="boolean")r.dts={};if(typeof n==="string")if(n==="true"||n==="false")r.dts.resolve=n==="true";else r.dts.resolve=n.split(",");else r.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>Yr()},version:{flags:["v","version"],handler:()=>qr()}},P={};for(let n of Object.values(_n))for(let r of n.flags)P[r]=n.handler;function Hn(n){let r={};for(let t=0;t<n.length;t++){let e=n[t];if(e.startsWith("--")){let i,o;if(e.includes("=")){let[s,c]=e.slice(2).split("=",2);i=s,o=c}else{i=e.slice(2);let s=n[t+1];if(o=s&&!s.startsWith("-")?s:!0,typeof o==="string")t++}if(i.includes(".")){let[s,c]=i.split(".",2),a=P[s];if(a)a(o,r,c);else throw new C(`Unknown option: --${i}`)}else{let s=P[i];if(s)s(o,r);else throw new C(`Unknown option: --${i}`)}}else if(e.startsWith("-")){let i=e.slice(1),o=n[t+1],s=o&&!o.startsWith("-")?o:!0;if(typeof s==="string")t++;let c=P[i];if(c)c(s,r);else throw new C(`Unknown option: -${i}`)}else _n.entry.handler(e,r,void 0)}return r}B();T();import{loadConfig as ge}from"coffi";mn();O();Bn();B();N();T();wn();O();import tn from"path";async function Or(n,r){let t=new Set,e=en(n),i=U(e.entry);for(let u of i){let m=tn.resolve(r,u.fullEntryPath),g=tn.dirname(m);t.add(g)}let s=(await import("chokidar")).watch(Array.from(t),{persistent:!0,ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,tn.join(r,e.outDir)]}),c=!1,a=async(u=!1)=>{if(c)return;c=!0;try{let m=performance.now();if(await Cn({...e,entry:i.map((g)=>g.fullEntryPath),clean:!1},r),!u)l.cli(`\uD83D\uDCE6 Rebuild finished in ${z(performance.now()-m)}`)}catch(m){un(m)}finally{c=!1}};s.on("change",(u)=>{let m=tn.relative(r,u);l.cli(`File changed: ${m}`,{muted:!0,once:m}),a()}),s.on("error",(u)=>{throw new Q(`Watcher error: ${y(u)}`)}),await a(!0)}async function fe(n=Bun.argv.slice(2)){let r=Hn(n);G(r.silent);let t=process.cwd(),{config:e,filepath:i}=await ge({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:r.config,packageJsonProperty:"bunup"}),o=!e?[{rootDir:t,options:r}]:await Dn(e,t,r.filter);if(l.cli(`Using bunup v${K} and bun v${Bun.version}`,{muted:!0}),i)l.cli(`Using config file: ${M(i,2)}`,{muted:!0});let s=performance.now();l.cli("Build started");let{build:c}=await Promise.resolve().then(() => (Bn(),Br));await Promise.all(o.flatMap(({options:m,rootDir:g})=>{return In(m).map(async(L)=>{let h={...L,...pe(r)};if(h.watch)await Or(h,g);else await c(h,g)})}));let a=performance.now()-s,u=z(a);if(l.cli(`\u26A1\uFE0F Build completed in ${u}`),r.watch)l.cli("\uD83D\uDC40 Watching for file changes");if(r.onSuccess)l.cli(`Running command: ${r.onSuccess}`,{muted:!0}),await me(r.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!r.watch)process.exit(process.exitCode??0)}function pe(n){return{...n,onSuccess:void 0,config:void 0}}fe().catch((n)=>$n(n));
|