@hypernym/bundler 0.14.3 → 0.20.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.
@@ -1,708 +0,0 @@
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';
8
-
9
- interface TransformersChunk {
10
- esbuild?: TransformOptions;
11
- resolve?: RollupNodeResolveOptions | true;
12
- replace?: RollupReplaceOptions;
13
- json?: RollupJsonOptions | true;
14
- alias?: RollupAliasOptions;
15
- }
16
- interface TransformersDeclaration {
17
- dts?: Options$1;
18
- alias?: RollupAliasOptions;
19
- }
20
-
21
- 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[];
81
- }
82
- 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;
231
- }
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;
255
- }
256
- 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;
288
- }
289
- 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;
321
- }
322
- type EntryOptions = EntryChunk | EntryDeclaration | EntryCopy | EntryTemplate;
323
-
324
- 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;
454
- }
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
-
525
- 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>;
636
- }
637
-
638
- interface ConfigLoader {
639
- options: Options;
640
- path: string;
641
- }
642
-
643
- /**
644
- * List of global defaults for externals.
645
- *
646
- * @example
647
- *
648
- * ```ts
649
- * import { externals } from '@hypernym/bundler'
650
- *
651
- * export default defineConfig({
652
- * entries: [
653
- * {
654
- * input: './src/index.ts',
655
- * externals: [...externals, 'id', /regexp/]
656
- * },
657
- * ]
658
- * })
659
- * ```
660
- */
661
- declare const externals: RegExp[];
662
- /**
663
- * `Hyperbundler` automatically detects custom configuration from the project root that can override or extend the build behavior.
664
- *
665
- * Configuration file also accepts `.js`, `.mjs`, `.ts`, `.mts` formats.
666
- *
667
- * @example
668
- *
669
- * ```ts
670
- * import { defineConfig } from '@hypernym/bundler'
671
- *
672
- * export default defineConfig({
673
- * // ...
674
- * })
675
- * ```
676
- */
677
- declare function defineConfig(options: Options): Options;
678
-
679
- /**
680
- * Resolves external module IDs into custom paths.
681
- *
682
- * @example
683
- *
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
- * ```
700
- */
701
- declare function resolvePaths(options: ResolvePathsOptions[]): (id: string) => string;
702
-
703
- interface ResolvePathsOptions {
704
- find: string | RegExp;
705
- replacement: string;
706
- }
707
-
708
- export { type BuildLogs, type BuildStats, type ConfigLoader, type CopyOptions, type EntryBase, type EntryChunk, type EntryCopy, type EntryDeclaration, type EntryOptions, type EntryTemplate, type HooksOptions, type Options, type ResolvePathsOptions, type TransformersChunk, type TransformersDeclaration, defineConfig, externals, resolvePaths };