@hypernym/bundler 0.14.4 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,647 +1,642 @@
1
- import { OutputOptions, Plugin, LogLevel, RollupLog } from 'rollup';
2
- import { RollupReplaceOptions } from '@rollup/plugin-replace';
3
- import { RollupJsonOptions } from '@rollup/plugin-json';
4
- import { RollupNodeResolveOptions } from '@rollup/plugin-node-resolve';
5
- import { RollupAliasOptions, Alias } from '@rollup/plugin-alias';
6
- import { TransformOptions } from 'esbuild';
7
- import { Options as Options$1 } from 'rollup-plugin-dts';
1
+ import { InputOptions, LogLevel, LogOrStringHandler, OutputOptions, RolldownPluginOption, RollupLog } from "rolldown";
2
+ import { Options as Options$1 } from "rolldown-plugin-dts";
8
3
 
9
- interface TransformersChunk {
10
- esbuild?: TransformOptions;
11
- resolve?: RollupNodeResolveOptions | true;
12
- replace?: RollupReplaceOptions;
13
- json?: RollupJsonOptions | true;
14
- alias?: RollupAliasOptions;
4
+ //#region src/bin/build.d.ts
5
+ declare function build(options: Options): Promise<BuildStats>;
6
+ //#endregion
7
+ //#region src/types/build.d.ts
8
+ interface BuildLogs {
9
+ level: LogLevel;
10
+ log: RollupLog;
15
11
  }
16
- interface TransformersDeclaration {
17
- dts?: Options$1;
18
- alias?: RollupAliasOptions;
12
+ interface BuildEntryStats {
13
+ /**
14
+ * The root path of the project.
15
+ */
16
+ cwd: string;
17
+ /**
18
+ * Module output path.
19
+ */
20
+ path: string;
21
+ /**
22
+ * Module size.
23
+ */
24
+ size: number;
25
+ /**
26
+ * Build time of individual module.
27
+ */
28
+ buildTime: number;
29
+ /**
30
+ * Module format.
31
+ */
32
+ format: string;
33
+ /**
34
+ * List of warnings from build plugins.
35
+ */
36
+ logs: BuildLogs[];
19
37
  }
20
-
38
+ interface BuildStats {
39
+ /**
40
+ * The root path of the project.
41
+ */
42
+ cwd: string;
43
+ /**
44
+ * Final bundle size.
45
+ */
46
+ size: number;
47
+ /**
48
+ * Total bundle build time.
49
+ */
50
+ buildTime: number;
51
+ /**
52
+ * List of generated bundle modules.
53
+ */
54
+ files: BuildEntryStats[];
55
+ }
56
+ type PickEntryChunkOptions = 'input' | 'name' | 'globals' | 'extend' | 'minify';
57
+ type PickEntryDtsOptions = 'dts' | 'dtsPlugin';
58
+ interface BuildEntryOptions extends EntryBase, Partial<Pick<EntryChunk, PickEntryChunkOptions>>, Partial<Pick<EntryDts, PickEntryDtsOptions>> {
59
+ /**
60
+ * Specifies the path to the processed file.
61
+ *
62
+ * @default undefined
63
+ */
64
+ output?: string;
65
+ }
66
+ //#endregion
67
+ //#region src/types/entries.d.ts
21
68
  interface EntryBase {
22
- /**
23
- * Specifies the format of the generated module.
24
- *
25
- * @default 'esm'
26
- */
27
- format?: OutputOptions['format'];
28
- /**
29
- * Specifies the module IDs, or regular expressions to match module IDs,
30
- * that should remain external to the bundle.
31
- *
32
- * If not specified, infers the IDs from the global `options.externals` option.
33
- *
34
- * @default undefined
35
- */
36
- externals?: (string | RegExp)[];
37
- /**
38
- * Specifies the string to be inserted at the beginning of the module.
39
- *
40
- * @default undefined
41
- */
42
- banner?: OutputOptions['banner'];
43
- /**
44
- * Specifies the string to be inserted at the end of the module.
45
- *
46
- * @default undefined
47
- */
48
- footer?: OutputOptions['footer'];
49
- /**
50
- * Specifies the code at the beginning that goes inside any _format-specific_ wrapper.
51
- *
52
- * @default undefined
53
- */
54
- intro?: OutputOptions['intro'];
55
- /**
56
- * Specifies the code at the end that goes inside any _format-specific_ wrapper.
57
- *
58
- * @default undefined
59
- */
60
- outro?: OutputOptions['outro'];
61
- /**
62
- * Maps external module IDs to paths.
63
- *
64
- * @default undefined
65
- */
66
- paths?: OutputOptions['paths'];
67
- /**
68
- * Specifies custom filters that will display only certain log messages.
69
- *
70
- * @default undefined
71
- */
72
- logFilter?: string[];
73
- /**
74
- * Specifies `rollup` plugins.
75
- *
76
- * Adding custom plugins disables all built-in `transformers` for full customization.
77
- *
78
- * @default undefined
79
- */
80
- plugins?: Plugin[];
69
+ /**
70
+ * Specifies the format of the generated module.
71
+ *
72
+ * - `'es'`, `'esm'` and `'module'` are the same format, all stand for ES module.
73
+ * - `'cjs'` and `'commonjs'` are the same format, all stand for CommonJS module.
74
+ * - `'iife'` stands for [Immediately Invoked Function Expression](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).
75
+ * - `'umd'` stands for [Universal Module Definition](https://github.com/umdjs/umd).
76
+ *
77
+ * @default 'esm'
78
+ */
79
+ format?: OutputOptions['format'];
80
+ /**
81
+ * Specifies the module IDs or regular expressions that match module IDs to be treated as external and excluded from the bundle.
82
+ *
83
+ * The IDs and regular expressions provided in this option are applied globally across all entries.
84
+ *
85
+ * Alternatively, externals can be defined individually for each entry using the `entry.externals` property.
86
+ *
87
+ * @default undefined
88
+ */
89
+ externals?: (string | RegExp)[];
90
+ /**
91
+ * Maps external module IDs to paths.
92
+ *
93
+ * @default undefined
94
+ */
95
+ paths?: {
96
+ find: string | RegExp;
97
+ replacement: string | ((path: string, match: RegExpExecArray | null) => string);
98
+ }[];
99
+ /**
100
+ * Specifies the string to be inserted at the beginning of the module.
101
+ *
102
+ * @default undefined
103
+ */
104
+ banner?: OutputOptions['banner'];
105
+ /**
106
+ * Specifies the string to be inserted at the end of the module.
107
+ *
108
+ * @default undefined
109
+ */
110
+ footer?: OutputOptions['footer'];
111
+ /**
112
+ * Specifies the code at the beginning that goes inside any _format-specific_ wrapper.
113
+ *
114
+ * @default undefined
115
+ */
116
+ intro?: OutputOptions['intro'];
117
+ /**
118
+ * Specifies the code at the end that goes inside any _format-specific_ wrapper.
119
+ *
120
+ * @default undefined
121
+ */
122
+ outro?: OutputOptions['outro'];
123
+ /**
124
+ * Intercepts log messages. If not supplied, logs are printed to the console.
125
+ *
126
+ * @default undefined
127
+ */
128
+ onLog?: (level: LogLevel, log: RollupLog, defaultHandler: LogOrStringHandler, buildLogs: BuildLogs[]) => void;
129
+ /**
130
+ * Specifies Rolldown `resolve` options.
131
+ *
132
+ * @default undefined
133
+ */
134
+ resolve?: InputOptions['resolve'];
135
+ /**
136
+ * Specifies Rolldown `define` options.
137
+ *
138
+ * @default undefined
139
+ */
140
+ define?: InputOptions['define'];
141
+ /**
142
+ * Specifies Rolldown `inject` options.
143
+ *
144
+ * @default undefined
145
+ */
146
+ inject?: InputOptions['inject'];
147
+ /**
148
+ * Specifies Rolldown plugins.
149
+ *
150
+ * @default undefined
151
+ */
152
+ plugins?: RolldownPluginOption;
153
+ /**
154
+ * Specifies the path to the `tsconfig` file.
155
+ *
156
+ * By default, if the file `tsconfig.json` exists in the project root, it will be used as the default config file.
157
+ *
158
+ * @default undefined
159
+ */
160
+ tsconfig?: InputOptions['tsconfig'];
81
161
  }
82
162
  interface EntryChunk extends EntryBase {
83
- /**
84
- * Specifies the path of the build source.
85
- *
86
- * @example
87
- *
88
- * ```ts
89
- * export default defineConfig({
90
- * entries: [
91
- * { input: './src/index.ts' }, // => './dist/index.mjs'
92
- * ]
93
- * })
94
- * ```
95
- */
96
- input?: string;
97
- /**
98
- * Specifies the path of the transformed file.
99
- *
100
- * @example
101
- *
102
- * ```ts
103
- * export default defineConfig({
104
- * entries: [
105
- * {
106
- * input: './src/index.ts',
107
- * output: './out/index.js', // => './out/index.js'
108
- * },
109
- * ]
110
- * })
111
- * ```
112
- *
113
- * @default undefined
114
- */
115
- output?: string;
116
- /**
117
- * Specifies the built-in `transformers` options.
118
- *
119
- * Available transformers:
120
- *
121
- * - `esbuild`
122
- * - `resolve`
123
- * - `replace`
124
- * - `json`
125
- * - `alias`
126
- *
127
- * @default undefined
128
- */
129
- transformers?: TransformersChunk;
130
- /**
131
- * Specifies the global variable name that representing exported bundle.
132
- *
133
- * Intended for `umd/iife` formats.
134
- *
135
- * @default undefined
136
- */
137
- name?: OutputOptions['name'];
138
- /**
139
- * Specifies global _module ID_ and _variable name_ pairs necessary for external imports.
140
- *
141
- * Intended for `umd/iife` formats.
142
- *
143
- * @default undefined
144
- */
145
- globals?: OutputOptions['globals'];
146
- /**
147
- * Specifies whether to extend the global variable defined by the `name` option.
148
- *
149
- * Intended for `umd/iife` formats.
150
- */
151
- extend?: OutputOptions['extend'];
152
- /**
153
- * Minifies the generated code if enabled.
154
- *
155
- * @default undefined
156
- */
157
- minify?: boolean;
158
- declaration?: never;
159
- dts?: never;
160
- copy?: never;
161
- template?: never;
162
- }
163
- interface EntryDeclaration extends EntryBase {
164
- /**
165
- * Specifies the path of the TypeScript `declaration` build source.
166
- *
167
- * @example
168
- *
169
- * ```ts
170
- * export default defineConfig({
171
- * entries: [
172
- * { dts: './src/types.ts' }, // => './dist/types.d.mts'
173
- * ]
174
- * })
175
- * ```
176
- */
177
- dts?: string;
178
- /**
179
- * Specifies the path of the TypeScript `declaration` build source.
180
- *
181
- * Also, it is possible to use `dts` alias.
182
- *
183
- * @example
184
- *
185
- * ```ts
186
- * export default defineConfig({
187
- * entries: [
188
- * { declaration: './src/types.ts' }, // => './dist/types.d.mts'
189
- * ]
190
- * })
191
- * ```
192
- */
193
- declaration?: string;
194
- /**
195
- * Specifies the path of the TypeScript transformed `declaration` file.
196
- *
197
- * @example
198
- *
199
- * ```ts
200
- * export default defineConfig({
201
- * entries: [
202
- * {
203
- * dts: './src/types.ts',
204
- * output: './out/types.d.ts', // => './out/types.d.ts'
205
- * },
206
- * ]
207
- * })
208
- * ```
209
- *
210
- * @default undefined
211
- */
212
- output?: string;
213
- /**
214
- * Specifies the built-in `transformers` options.
215
- *
216
- * Available transformers:
217
- *
218
- * - `dts`
219
- * - `alias`
220
- *
221
- * @default undefined
222
- */
223
- transformers?: TransformersDeclaration;
224
- input?: never;
225
- copy?: never;
226
- template?: never;
227
- name?: never;
228
- globals?: never;
229
- extend?: never;
230
- minify?: never;
163
+ /**
164
+ * Specifies the path to the build source.
165
+ *
166
+ * @example
167
+ *
168
+ * ```ts
169
+ * export default defineConfig({
170
+ * entries: [
171
+ * { input: './src/index.ts' }, // outputs './dist/index.mjs'
172
+ * ]
173
+ * })
174
+ * ```
175
+ */
176
+ input: string;
177
+ /**
178
+ * Specifies the path to the processed file.
179
+ *
180
+ * @example
181
+ *
182
+ * ```ts
183
+ * export default defineConfig({
184
+ * entries: [
185
+ * {
186
+ * input: './src/index.ts',
187
+ * output: './out/index.js', // outputs './out/index.js'
188
+ * },
189
+ * ]
190
+ * })
191
+ * ```
192
+ *
193
+ * @default undefined
194
+ */
195
+ output?: string;
196
+ /**
197
+ * Specifies the global variable name that representing exported bundle.
198
+ *
199
+ * Intended for `umd/iife` formats.
200
+ *
201
+ * @default undefined
202
+ */
203
+ name?: OutputOptions['name'];
204
+ /**
205
+ * Specifies global _module ID_ and _variable name_ pairs necessary for external imports.
206
+ *
207
+ * Intended for `umd/iife` formats.
208
+ *
209
+ * @default undefined
210
+ */
211
+ globals?: OutputOptions['globals'];
212
+ /**
213
+ * Specifies whether to extend the global variable defined by the `name` option.
214
+ *
215
+ * Intended for `umd/iife` formats.
216
+ */
217
+ extend?: OutputOptions['extend'];
218
+ /**
219
+ * Controls code minification.
220
+ *
221
+ * - `true`: Enable full minification including code compression and dead code elimination.
222
+ * - `false`: Disable minification (default).
223
+ * - `'dce-only'`: Only perform dead code elimination without code compression.
224
+ * - `MinifyOptions`: Fine-grained control over minification settings.
225
+ *
226
+ * @default undefined
227
+ */
228
+ minify?: OutputOptions['minify'];
229
+ dts?: never;
230
+ dtsPlugin?: never;
231
+ copy?: never;
232
+ recursive?: never;
233
+ filter?: never;
234
+ template?: never;
231
235
  }
232
- interface CopyOptions {
233
- /**
234
- * Specifies the path of the source.
235
- */
236
- input: string | string[];
237
- /**
238
- * Specifies the path of the destination directory.
239
- */
240
- output: string;
241
- /**
242
- * Copy directories recursively.
243
- *
244
- * @default true
245
- */
246
- recursive?: boolean;
247
- /**
248
- * Filters copied `files/directories`.
249
- *
250
- * Returns `true` to copy the item, `false` to ignore it.
251
- *
252
- * @default undefined
253
- */
254
- filter?(source: string, destination: string): boolean;
236
+ interface EntryDts extends EntryBase {
237
+ /**
238
+ * Specifies the path to the TypeScript `declaration` build source.
239
+ *
240
+ * @example
241
+ *
242
+ * ```ts
243
+ * export default defineConfig({
244
+ * entries: [
245
+ * { dts: './src/types.ts' }, // outputs './dist/types.d.mts'
246
+ * ]
247
+ * })
248
+ * ```
249
+ */
250
+ dts: string;
251
+ /**
252
+ * Specifies the path to the processed file.
253
+ *
254
+ * @example
255
+ *
256
+ * ```ts
257
+ * export default defineConfig({
258
+ * entries: [
259
+ * {
260
+ * dts: './src/types.ts',
261
+ * output: './out/types.d.ts', // outputs './out/types.d.ts'
262
+ * },
263
+ * ]
264
+ * })
265
+ * ```
266
+ *
267
+ * @default undefined
268
+ */
269
+ output?: string;
270
+ /**
271
+ * Specifies options for the `rolldown-plugin-dts` plugin.
272
+ */
273
+ dtsPlugin?: Options$1;
274
+ input?: never;
275
+ name?: never;
276
+ globals?: never;
277
+ extend?: never;
278
+ minify?: never;
279
+ copy?: never;
280
+ recursive?: never;
281
+ filter?: never;
282
+ template?: never;
255
283
  }
256
284
  interface EntryCopy {
257
- /**
258
- * Copies the single `file` or entire `directory` structure from source to destination, including subdirectories and files.
259
- *
260
- * This can be very useful for copying some assets that don't need a transformation process, but a simple copy paste feature.
261
- *
262
- * @example
263
- *
264
- * ```ts
265
- * export default defineConfig({
266
- * entries: [
267
- * {
268
- * copy: {
269
- * input: './src/path/file.ts', // or ['path-dir', 'path-file.ts', ...]
270
- * output: './dist/out', // path to output dir
271
- * }
272
- * }
273
- * ]
274
- * })
275
- * ```
276
- *
277
- * @default undefined
278
- */
279
- copy?: CopyOptions;
280
- input?: never;
281
- declaration?: never;
282
- dts?: never;
283
- template?: never;
284
- name?: never;
285
- globals?: never;
286
- extend?: never;
287
- minify?: never;
285
+ /**
286
+ * Copies either a single `file` or an entire `directory` structure from the source to the destination, including all subdirectories and files.
287
+ *
288
+ * This is especially useful for transferring assets that don't require any transformation, just a straightforward copy-paste operation.
289
+ *
290
+ * @example
291
+ *
292
+ * ```ts
293
+ * export default defineConfig({
294
+ * entries: [
295
+ * {
296
+ * // copies a single file
297
+ * copy: './src/path/file.ts', // outputs './dist/path/file.ts'
298
+ * },
299
+ * {
300
+ * // copies a single file
301
+ * copy: './src/path/file.ts',
302
+ * output: './dist/subdir/custom-file-name.ts',
303
+ * },
304
+ * {
305
+ * // copies the entire directory
306
+ * input: './src/path/srcdir',
307
+ * output: './dist/outdir',
308
+ * },
309
+ * ]
310
+ * })
311
+ * ```
312
+ *
313
+ * @default undefined
314
+ */
315
+ copy: string;
316
+ /**
317
+ * Specifies the path to the destination file or directory.
318
+ */
319
+ output?: string;
320
+ /**
321
+ * Copy directories recursively.
322
+ *
323
+ * @default true
324
+ */
325
+ recursive?: boolean;
326
+ /**
327
+ * Filters copied `files/directories`.
328
+ *
329
+ * Returns `true` to copy the item, `false` to ignore it.
330
+ *
331
+ * @default undefined
332
+ */
333
+ filter?(source: string, destination: string): boolean;
334
+ input?: never;
335
+ name?: never;
336
+ globals?: never;
337
+ extend?: never;
338
+ minify?: never;
339
+ dts?: never;
340
+ dtsPlugin?: never;
341
+ template?: never;
288
342
  }
289
343
  interface EntryTemplate {
290
- /**
291
- * Specifies the content of the `template` file.
292
- *
293
- * Provides the ability to dynamically inject template content during the build phase.
294
- *
295
- * @example
296
- *
297
- * ```ts
298
- * export default defineConfig({
299
- * entries: [
300
- * {
301
- * template: `// TypeScript code...`,
302
- * output: './dist/template.ts',
303
- * },
304
- * ]
305
- * })
306
- * ```
307
- */
308
- template: string;
309
- /**
310
- * Specifies the path of the transformed `template` file.
311
- */
312
- output: string;
313
- input?: never;
314
- declaration?: never;
315
- dts?: never;
316
- copy?: never;
317
- name?: never;
318
- globals?: never;
319
- extend?: never;
320
- minify?: never;
344
+ /**
345
+ * Specifies the content of the `template` file.
346
+ *
347
+ * Provides the ability to dynamically inject template content during the build phase.
348
+ *
349
+ * @example
350
+ *
351
+ * ```ts
352
+ * import { name, version } from './package.json'
353
+ *
354
+ * export default defineConfig({
355
+ * entries: [
356
+ * {
357
+ * template: `// Package ${name} v${version} ...`,
358
+ * output: './dist/template.ts',
359
+ * },
360
+ * ]
361
+ * })
362
+ * ```
363
+ */
364
+ template: string;
365
+ /**
366
+ * Specifies the path to the destination file.
367
+ */
368
+ output: string;
369
+ input?: never;
370
+ name?: never;
371
+ globals?: never;
372
+ extend?: never;
373
+ minify?: never;
374
+ dts?: never;
375
+ dtsPlugin?: never;
376
+ copy?: never;
377
+ recursive?: never;
378
+ filter?: never;
321
379
  }
322
- type EntryOptions = EntryChunk | EntryDeclaration | EntryCopy | EntryTemplate;
323
-
380
+ type EntryOptions = EntryChunk | EntryDts | EntryCopy | EntryTemplate;
381
+ //#endregion
382
+ //#region src/types/options.d.ts
324
383
  interface Options {
325
- /**
326
- * Specifies the bundle's entry points.
327
- *
328
- * It allows you to manually set all build entries and adjust options for each one individually.
329
- *
330
- * @example
331
- *
332
- * ```ts
333
- * export default defineConfig({
334
- * entries: [
335
- * { input: './src/index.ts' }, // => './dist/index.mjs'
336
- * { dts: './src/types.ts' }, // => './dist/types.d.mts'
337
- * // ...
338
- * ]
339
- * })
340
- * ```
341
- */
342
- entries: EntryOptions[];
343
- /**
344
- * Specifies the output directory for production bundle.
345
- *
346
- * @example
347
- *
348
- * ```ts
349
- * export default defineConfig({
350
- * outDir: 'output',
351
- * })
352
- * ```
353
- *
354
- * @default 'dist'
355
- */
356
- outDir?: string;
357
- /**
358
- * Specifies the module IDs, or regular expressions to match module IDs,
359
- * that should remain external to the bundle.
360
- *
361
- * IDs and regexps from this option are applied globally to all entries.
362
- *
363
- * Also, it is possible to define externals individually per entry (`entry.externals`).
364
- *
365
- * @example
366
- *
367
- * ```ts
368
- * export default defineConfig({
369
- * externals: ['id-1', 'id-2', /regexp/],
370
- * })
371
- * ```
372
- *
373
- * @default [/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]
374
- */
375
- externals?: (string | RegExp)[];
376
- /**
377
- * Provides a powerful hooking system to further expand bundling mode.
378
- *
379
- * @example
380
- *
381
- * ```ts
382
- * export default defineConfig({
383
- * hooks: {
384
- * 'build:end': async (options, buildStats) => {
385
- * // ...
386
- * }
387
- * }
388
- * })
389
- * ```
390
- *
391
- * @default undefined
392
- */
393
- hooks?: HooksOptions;
394
- /**
395
- * Specifies prefixes that will resolve imports with custom paths.
396
- *
397
- * Enables these `alias` by default:
398
- *
399
- * ```ts
400
- * // Imports module from './src/utils/index.js'
401
- * import { module } from '@/utils' // @
402
- * import { module } from '~/utils' // ~
403
- * ```
404
- *
405
- * Also, it is possible to completely override the default aliases by setting custom ones.
406
- *
407
- * @example
408
- *
409
- * ```ts
410
- * export default defineConfig({
411
- * alias: [
412
- * { find: /^#/, replacement: resolve('./src') },
413
- * ]
414
- * })
415
- * ```
416
- *
417
- * Now imports can be used like this:
418
- *
419
- * ```ts
420
- * // Imports module from './src/utils/index.js'
421
- * import { module } from '#/utils' // #
422
- * ```
423
- *
424
- * @default undefined
425
- */
426
- alias?: Alias[];
427
- /**
428
- * Specifies the minification for all `chunk` entries.
429
- *
430
- * @example
431
- *
432
- * ```ts
433
- * export default defineConfig({
434
- * minify: true,
435
- * })
436
- * ```
437
- *
438
- * It can also be set per entry.
439
- *
440
- * ```ts
441
- * export default defineConfig({
442
- * entries: [
443
- * {
444
- * input: './src/index.ts',
445
- * minify: true,
446
- * },
447
- * ],
448
- * })
449
- * ```
450
- *
451
- * @default undefined
452
- */
453
- minify?: boolean;
384
+ /**
385
+ * Specifies the bundle's entry points.
386
+ *
387
+ * It allows you to manually set all build entries and adjust options for each one individually.
388
+ *
389
+ * @example
390
+ *
391
+ * ```ts
392
+ * export default defineConfig({
393
+ * entries: [
394
+ * { input: './src/index.ts' }, // outputs './dist/index.mjs'
395
+ * { dts: './src/types.ts' }, // outputs './dist/types.d.mts'
396
+ * // ...
397
+ * ]
398
+ * })
399
+ * ```
400
+ */
401
+ entries: EntryOptions[];
402
+ /**
403
+ * Specifies the output directory for production bundle.
404
+ *
405
+ * @example
406
+ *
407
+ * ```ts
408
+ * export default defineConfig({
409
+ * outDir: './output',
410
+ * })
411
+ * ```
412
+ *
413
+ * @default 'dist'
414
+ */
415
+ outDir?: string;
416
+ /**
417
+ * Specifies the module IDs, or regular expressions to match module IDs,
418
+ * that should remain external to the bundle.
419
+ *
420
+ * IDs and regexps from this option are applied globally to all entries.
421
+ *
422
+ * Also, it is possible to define externals individually per entry (`entry.externals`).
423
+ *
424
+ * @example
425
+ *
426
+ * ```ts
427
+ * export default defineConfig({
428
+ * externals: ['id-1', 'id-2', /regexp/],
429
+ * })
430
+ * ```
431
+ *
432
+ * @default [/^node:/,/^@types/,/^@rollup/,/^@rolldown/,/^@hypernym/,/^rollup/,/^rolldown/,...pkg.dependencies]
433
+ */
434
+ externals?: (string | RegExp)[];
435
+ /**
436
+ * Provides a powerful hooking system to further expand bundling mode.
437
+ *
438
+ * @example
439
+ *
440
+ * ```ts
441
+ * export default defineConfig({
442
+ * hooks: {
443
+ * 'build:end': async (options, buildStats) => {
444
+ * // ...
445
+ * }
446
+ * }
447
+ * })
448
+ * ```
449
+ *
450
+ * @default undefined
451
+ */
452
+ hooks?: HooksOptions;
453
+ /**
454
+ * Controls code minification for all `chunk` entries.
455
+ *
456
+ * - `true`: Enable full minification including code compression and dead code elimination.
457
+ * - `false`: Disable minification (default).
458
+ * - `'dce-only'`: Only perform dead code elimination without code compression.
459
+ * - `MinifyOptions`: Fine-grained control over minification settings.
460
+ *
461
+ * @example
462
+ *
463
+ * ```ts
464
+ * export default defineConfig({
465
+ * minify: true,
466
+ * })
467
+ * ```
468
+ *
469
+ * It can also be set per entry.
470
+ *
471
+ * ```ts
472
+ * export default defineConfig({
473
+ * entries: [
474
+ * {
475
+ * input: './src/index.ts',
476
+ * minify: true,
477
+ * },
478
+ * ],
479
+ * })
480
+ * ```
481
+ *
482
+ * @default undefined
483
+ */
484
+ minify?: OutputOptions['minify'];
485
+ /**
486
+ * Specifies the path to the project root (current working directory).
487
+ *
488
+ * @example
489
+ *
490
+ * ```ts
491
+ * export default defineConfig({
492
+ * cwd: './dir',
493
+ * })
494
+ * ```
495
+ *
496
+ * @default undefined
497
+ */
498
+ cwd?: string;
499
+ /**
500
+ * Specifies the path to the `tsconfig` file.
501
+ *
502
+ * By default, if the file `tsconfig.json` exists in the project root, it will be used as the default config file.
503
+ *
504
+ * @example
505
+ *
506
+ * ```ts
507
+ * export default defineConfig({
508
+ * tsconfig: './path/to/tsconfig.json',
509
+ * })
510
+ * ```
511
+ *
512
+ * @default undefined
513
+ */
514
+ tsconfig?: string;
454
515
  }
455
-
456
- interface BuildLogs {
457
- level: LogLevel;
458
- log: RollupLog;
459
- }
460
- interface BuildEntryStats {
461
- /**
462
- * The root path of the project.
463
- */
464
- cwd: string;
465
- /**
466
- * Module output path.
467
- */
468
- path: string;
469
- /**
470
- * Module size.
471
- */
472
- size: number;
473
- /**
474
- * Build time of individual module.
475
- */
476
- buildTime: number;
477
- /**
478
- * Module format.
479
- */
480
- format: string;
481
- /**
482
- * List of warnings from build plugins.
483
- */
484
- logs: BuildLogs[];
485
- }
486
- interface BuildStats {
487
- /**
488
- * The root path of the project.
489
- */
490
- cwd: string;
491
- /**
492
- * Final bundle size.
493
- */
494
- size: number;
495
- /**
496
- * Total bundle build time.
497
- */
498
- buildTime: number;
499
- /**
500
- * List of generated bundle modules.
501
- */
502
- files: BuildEntryStats[];
503
- }
504
- type PickEntryChunkOptions = 'input' | 'name' | 'globals' | 'extend' | 'minify' | 'transformers';
505
- type PickEntryDtsOptions = 'declaration' | 'dts' | 'transformers';
506
- interface BuildEntryOptions extends EntryBase, Pick<EntryChunk, PickEntryChunkOptions>, Pick<EntryDeclaration, PickEntryDtsOptions> {
507
- /**
508
- * Specifies the path of the transformed file.
509
- *
510
- * @default undefined
511
- */
512
- output?: string;
513
- /**
514
- * Specifies options for default plugins.
515
- *
516
- * @default undefined
517
- */
518
- transformers?: TransformersChunk & TransformersDeclaration;
519
- /**
520
- * Specifies list of default plugins.
521
- */
522
- defaultPlugins: Plugin[];
523
- }
524
-
516
+ //#endregion
517
+ //#region src/types/hooks.d.ts
525
518
  interface HooksOptions {
526
- /**
527
- * Called at the beginning of bundling.
528
- *
529
- * @example
530
- *
531
- * ```ts
532
- * export default defineConfig({
533
- * hooks: {
534
- * 'bundle:start': async (options) => {
535
- * // ...
536
- * }
537
- * }
538
- * })
539
- * ```
540
- *
541
- * @default undefined
542
- */
543
- 'bundle:start'?: (options: Options) => void | Promise<void>;
544
- /**
545
- * Called at the beginning of building.
546
- *
547
- * @example
548
- *
549
- * ```ts
550
- * export default defineConfig({
551
- * hooks: {
552
- * 'build:start': async (options, stats) => {
553
- * // ...
554
- * }
555
- * }
556
- * })
557
- * ```
558
- *
559
- * @default undefined
560
- */
561
- 'build:start'?: (options: Options, stats: BuildStats) => void | Promise<void>;
562
- /**
563
- * Called on each entry just before the build process.
564
- *
565
- * Provides the ability to customize entry options before they are passed to the next phase.
566
- *
567
- * @example
568
- *
569
- * ```ts
570
- * export default defineConfig({
571
- * hooks: {
572
- * 'build:entry:start': async (entry, stats) => {
573
- * // ...
574
- * }
575
- * }
576
- * })
577
- * ```
578
- *
579
- * @default undefined
580
- */
581
- 'build:entry:start'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
582
- /**
583
- * Called on each entry right after the build process is completed.
584
- *
585
- * @example
586
- *
587
- * ```ts
588
- * export default defineConfig({
589
- * hooks: {
590
- * 'build:entry:end': async (entry, stats) => {
591
- * // ...
592
- * }
593
- * }
594
- * })
595
- * ```
596
- *
597
- * @default undefined
598
- */
599
- 'build:entry:end'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
600
- /**
601
- * Called right after building is complete.
602
- *
603
- * @example
604
- *
605
- * ```ts
606
- * export default defineConfig({
607
- * hooks: {
608
- * 'build:end': async (options, stats) => {
609
- * // ...
610
- * }
611
- * }
612
- * })
613
- * ```
614
- *
615
- * @default undefined
616
- */
617
- 'build:end'?: (options: Options, stats: BuildStats) => void | Promise<void>;
618
- /**
619
- * Called right after bundling is complete.
620
- *
621
- * @example
622
- *
623
- * ```ts
624
- * export default defineConfig({
625
- * hooks: {
626
- * 'bundle:end': async (options) => {
627
- * // ...
628
- * }
629
- * }
630
- * })
631
- * ```
632
- *
633
- * @default undefined
634
- */
635
- 'bundle:end'?: (options: Options) => void | Promise<void>;
519
+ /**
520
+ * Called at the beginning of bundling.
521
+ *
522
+ * @example
523
+ *
524
+ * ```ts
525
+ * export default defineConfig({
526
+ * hooks: {
527
+ * 'bundle:start': async (options) => {
528
+ * // ...
529
+ * }
530
+ * }
531
+ * })
532
+ * ```
533
+ *
534
+ * @default undefined
535
+ */
536
+ 'bundle:start'?: (options: Options) => void | Promise<void>;
537
+ /**
538
+ * Called at the beginning of building.
539
+ *
540
+ * @example
541
+ *
542
+ * ```ts
543
+ * export default defineConfig({
544
+ * hooks: {
545
+ * 'build:start': async (options, stats) => {
546
+ * // ...
547
+ * }
548
+ * }
549
+ * })
550
+ * ```
551
+ *
552
+ * @default undefined
553
+ */
554
+ 'build:start'?: (options: Options, stats: BuildStats) => void | Promise<void>;
555
+ /**
556
+ * Called on each entry just before the build process.
557
+ *
558
+ * Provides the ability to customize entry options before they are passed to the next phase.
559
+ *
560
+ * @example
561
+ *
562
+ * ```ts
563
+ * export default defineConfig({
564
+ * hooks: {
565
+ * 'build:entry:start': async (entry, stats) => {
566
+ * // ...
567
+ * }
568
+ * }
569
+ * })
570
+ * ```
571
+ *
572
+ * @default undefined
573
+ */
574
+ 'build:entry:start'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
575
+ /**
576
+ * Called on each entry right after the build process is completed.
577
+ *
578
+ * @example
579
+ *
580
+ * ```ts
581
+ * export default defineConfig({
582
+ * hooks: {
583
+ * 'build:entry:end': async (entry, stats) => {
584
+ * // ...
585
+ * }
586
+ * }
587
+ * })
588
+ * ```
589
+ *
590
+ * @default undefined
591
+ */
592
+ 'build:entry:end'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
593
+ /**
594
+ * Called right after building is complete.
595
+ *
596
+ * @example
597
+ *
598
+ * ```ts
599
+ * export default defineConfig({
600
+ * hooks: {
601
+ * 'build:end': async (options, stats) => {
602
+ * // ...
603
+ * }
604
+ * }
605
+ * })
606
+ * ```
607
+ *
608
+ * @default undefined
609
+ */
610
+ 'build:end'?: (options: Options, stats: BuildStats) => void | Promise<void>;
611
+ /**
612
+ * Called right after bundling is complete.
613
+ *
614
+ * @example
615
+ *
616
+ * ```ts
617
+ * export default defineConfig({
618
+ * hooks: {
619
+ * 'bundle:end': async (options) => {
620
+ * // ...
621
+ * }
622
+ * }
623
+ * })
624
+ * ```
625
+ *
626
+ * @default undefined
627
+ */
628
+ 'bundle:end'?: (options: Options) => void | Promise<void>;
636
629
  }
637
-
630
+ //#endregion
631
+ //#region src/types/loader.d.ts
638
632
  interface ConfigLoader {
639
- options: Options;
640
- path: string;
633
+ options: Options;
634
+ path: string;
641
635
  }
642
-
636
+ //#endregion
637
+ //#region src/config.d.ts
643
638
  /**
644
- * List of global defaults for externals.
639
+ * List of global default patterns for external module identifiers.
645
640
  *
646
641
  * @example
647
642
  *
@@ -660,7 +655,9 @@ interface ConfigLoader {
660
655
  */
661
656
  declare const externals: RegExp[];
662
657
  /**
663
- * `Hyperbundler` automatically detects custom configuration from the project root that can override or extend the build behavior.
658
+ * ESM & TS module bundler.
659
+ *
660
+ * Automatically detects a custom configuration file at the project root, which can override or extend the build behavior.
664
661
  *
665
662
  * Configuration file also accepts `.js`, `.mjs`, `.ts`, `.mts` formats.
666
663
  *
@@ -673,37 +670,9 @@ declare const externals: RegExp[];
673
670
  * // ...
674
671
  * })
675
672
  * ```
676
- */
677
- declare function defineConfig(options: Options): Options;
678
-
679
- /**
680
- * Resolves external module IDs into custom paths.
681
- *
682
- * @example
683
673
  *
684
- * ```ts
685
- * import { defineConfig, resolvePaths } from '@hypernym/bundler'
686
- *
687
- * export default defineConfig({
688
- * entries: [
689
- * {
690
- * input: './src/index.ts',
691
- * externals: [/^@\/path/],
692
- * paths: resolvePaths([
693
- * // replaces `@/path` with `./path/index.mjs`
694
- * { find: /^@\/path/, replacement: './path/index.mjs', }
695
- * ]),
696
- * },
697
- * ]
698
- * })
699
- * ```
674
+ * @see [Repository](https://github.com/hypernym-studio/bundler)
700
675
  */
701
- declare function resolvePaths(options: ResolvePathsOptions[]): (id: string) => string;
702
-
703
- interface ResolvePathsOptions {
704
- find: string | RegExp;
705
- replacement: string;
706
- }
707
-
708
- export { defineConfig, externals, resolvePaths };
709
- export type { BuildLogs, BuildStats, ConfigLoader, CopyOptions, EntryBase, EntryChunk, EntryCopy, EntryDeclaration, EntryOptions, EntryTemplate, HooksOptions, Options, ResolvePathsOptions, TransformersChunk, TransformersDeclaration };
676
+ declare function defineConfig(options: Options): Options;
677
+ //#endregion
678
+ export { BuildEntryOptions, BuildEntryStats, BuildLogs, BuildStats, ConfigLoader, EntryBase, EntryChunk, EntryCopy, EntryDts, EntryOptions, EntryTemplate, HooksOptions, Options, build, defineConfig, externals };