@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/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Ivo Dolenc, Hypernym Studio
3
+ Copyright (c) 2025, Ivo Dolenc <https://github.com/ivodolenc>
4
+ Copyright (c) 2025, Hypernym Studio <https://github.com/hypernym-studio>
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -20,11 +20,9 @@
20
20
 
21
21
  ## Features
22
22
 
23
- - Powered by Rollup
24
- - Written in TypeScript
23
+ - Powered by Rolldown
25
24
  - Allows Advanced Customization
26
25
  - Provides a Powerful Hooking System
27
- - Supports All TS Module Resolutions
28
26
  - Exports Fully Optimized Code
29
27
  - Follows Modern Practice
30
28
  - Super Easy to Use
@@ -67,9 +65,13 @@ export default defineConfig({
67
65
  })
68
66
  ```
69
67
 
70
- 3. Build via command:
68
+ 3. Build via commands:
71
69
 
72
70
  ```sh
71
+ # pnpm
72
+ pnpm hyperbundler
73
+
74
+ # npm
73
75
  npx hyperbundler
74
76
  ```
75
77
 
@@ -94,37 +96,41 @@ export default defineConfig({
94
96
  Set a custom config path via the CLI command:
95
97
 
96
98
  ```sh
99
+ # pnpm
100
+ pnpm hyperbundler --config hyper.config.ts
101
+
102
+ # npm
97
103
  npx hyperbundler --config hyper.config.ts
98
104
  ```
99
105
 
100
106
  ## Formats
101
107
 
102
- During transformation, file formats are automatically resolved and in most cases there is no need for additional configuration.
108
+ During transformation, file formats are automatically resolved, and in most cases, no additional configuration is required.
103
109
 
104
- `Hyperbundler` module environment for generated files defaults to `esm`, which means the outputs will have a `.mjs` extension unless otherwise specified. For TypeScript declarations, the appropriate extension will be `.d.mts`.
110
+ The default module environment for generated files is `esm`, which means output files will have a `.mjs` extension unless otherwise specified. For TypeScript declarations, the corresponding extension will be `.d.mts`.
105
111
 
106
- Formats can also be explicitly specified for each entry, if necessary.
112
+ Formats can also be explicitly specified for each entry, if needed.
107
113
 
108
114
  ### Inputs
109
115
 
110
- Default transformation behaviour for all `chunk` entries:
116
+ Default transformation behavior for all `chunk` entries:
111
117
 
112
- - `./srcDir/file.js` resolves to `./outDir/file.mjs`
113
- - `./srcDir/file.mjs` resolves to `./outDir/file.mjs`
114
- - `./srcDir/file.cjs` resolves to `./outDir/file.cjs`
115
- - `./srcDir/file.ts` resolves to `./outDir/file.mjs`
116
- - `./srcDir/file.mts` resolves to `./outDir/file.mjs`
117
- - `./srcDir/file.cts` resolves to `./outDir/file.cjs`
118
+ - `./srcDir/file.js` `./outDir/file.mjs`
119
+ - `./srcDir/file.mjs` `./outDir/file.mjs`
120
+ - `./srcDir/file.cjs` `./outDir/file.cjs`
121
+ - `./srcDir/file.ts` `./outDir/file.mjs`
122
+ - `./srcDir/file.mts` `./outDir/file.mjs`
123
+ - `./srcDir/file.cts` `./outDir/file.cjs`
118
124
 
119
125
  ### Declarations
120
126
 
121
- Default transformation behaviour for all `dts` entries:
127
+ Default transformation behavior for all `dts` entries:
122
128
 
123
- - `./srcDir/file.ts` resolves to `./outDir/file.d.mts`
129
+ - `./srcDir/file.ts` `./outDir/file.d.mts`
124
130
 
125
131
  ## Options
126
132
 
127
- All options are documented with descriptions and examples so auto-completion will be offered as you type. Simply hover over the property and see what it does in the `quickinfo`.
133
+ All options come with descriptions and examples. As you type, you’ll get suggestions and can see quick info by hovering over any property.
128
134
 
129
135
  ### entries
130
136
 
@@ -141,16 +147,14 @@ import { defineConfig } from '@hypernym/bundler'
141
147
 
142
148
  export default defineConfig({
143
149
  entries: [
144
- { input: './src/index.ts' }, // => './dist/index.mjs'
145
- { dts: './src/types.ts' }, // => './dist/types.d.mts'
150
+ { input: './src/index.ts' }, // outputs './dist/index.mjs'
151
+ { dts: './src/types.ts' }, // outputs './dist/types.d.mts'
146
152
  // ...
147
153
  ],
148
154
  })
149
155
  ```
150
156
 
151
- #### Entry Chunk
152
-
153
- - [Types](./src/types/entries.ts)
157
+ ### Entry Chunk
154
158
 
155
159
  Automatically transforms `chunks` for production.
156
160
 
@@ -161,48 +165,38 @@ import { defineConfig } from '@hypernym/bundler'
161
165
 
162
166
  export default defineConfig({
163
167
  entries: [
164
- { input: './src/index.ts' }, // => './dist/index.mjs'
168
+ { input: './src/index.ts' }, // outputs './dist/index.mjs'
169
+ {
170
+ input: './src/index.ts',
171
+ output: './out/index.js', // outputs './out/index.js'
172
+ },
165
173
  ],
166
174
  })
167
175
  ```
168
176
 
169
- #### Entry Declaration
177
+ ### Entry Dts
170
178
 
171
- - [Types](./src/types/entries.ts)
172
-
173
- Builds TypeScript `declaration` files (.d.ts) for production.
179
+ Builds TypeScript `declaration` files (`.d.mts`) for production.
174
180
 
175
181
  ```ts
176
- // bundler.config.ts
177
-
178
182
  import { defineConfig } from '@hypernym/bundler'
179
183
 
180
184
  export default defineConfig({
181
185
  entries: [
182
- { declaration: './src/types.ts' }, // => './dist/types.d.mts'
183
- ],
184
- })
185
- ```
186
-
187
- Also, it is possible to use `dts` alias.
188
-
189
- ```ts
190
- import { defineConfig } from '@hypernym/bundler'
191
-
192
- export default defineConfig({
193
- entries: [
194
- { dts: './src/types.ts' }, // => './dist/types.d.mts'
186
+ { dts: './src/types.ts' }, // outputs './dist/types.d.mts'
187
+ {
188
+ dts: './src/types.ts',
189
+ output: './out/types.d.ts', // outputs './out/types.d.ts'
190
+ },
195
191
  ],
196
192
  })
197
193
  ```
198
194
 
199
- #### Entry Copy
195
+ ### Entry Copy
200
196
 
201
- - [Types](./src/types/entries.ts)
197
+ Copies either a single `file` or an entire `directory` structure from the source to the destination, including all subdirectories and files.
202
198
 
203
- Copies the single `file` or entire `directory` structure from source to destination, including subdirectories and files.
204
-
205
- This can be very useful for copying some assets that don't need a transformation process, but a simple copy paste feature.
199
+ This is especially useful for transferring assets that don't require any transformation, just a straightforward copy-paste operation.
206
200
 
207
201
  ```ts
208
202
  // bundler.config.ts
@@ -212,20 +206,28 @@ import { defineConfig } from '@hypernym/bundler'
212
206
  export default defineConfig({
213
207
  entries: [
214
208
  {
215
- copy: {
216
- input: './src/path/file.ts', // or ['path-dir', 'path-file.ts', ...]
217
- output: './dist/out', // path to output dir
218
- },
209
+ // copies a single file
210
+ copy: './src/path/file.ts', // outputs './dist/path/file.ts'
211
+ },
212
+ {
213
+ // copies a single file
214
+ copy: './src/path/file.ts',
215
+ output: './dist/subdir/custom-file-name.ts',
216
+ },
217
+ {
218
+ // copies the entire directory
219
+ input: './src/path/srcdir',
220
+ output: './dist/outdir',
219
221
  },
220
222
  ],
221
223
  })
222
224
  ```
223
225
 
224
- #### Entry Template
226
+ ### Entry Template
225
227
 
226
- - [Types](./src/types/entries.ts)
228
+ Specifies the content of the `template` file.
227
229
 
228
- Provides the ability to dynamically inject `template` content during the build phase and writes the file to the destination path defined in the output property.
230
+ Provides the ability to dynamically inject template content during the build phase.
229
231
 
230
232
  ```ts
231
233
  // bundler.config.ts
@@ -245,7 +247,7 @@ export default defineConfig({
245
247
 
246
248
  ### outDir
247
249
 
248
- - Type: `string`
250
+ - Type: `string | undefined`
249
251
  - Default: `dist`
250
252
 
251
253
  Specifies the output directory for production bundle.
@@ -256,20 +258,18 @@ Specifies the output directory for production bundle.
256
258
  import { defineConfig } from '@hypernym/bundler'
257
259
 
258
260
  export default defineConfig({
259
- outDir: 'output',
261
+ outDir: './output',
260
262
  })
261
263
  ```
262
264
 
263
265
  ### externals
264
266
 
265
- - Type: `(string | RegExp)[]`
266
- - Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
267
-
268
- Specifies the module IDs, or regular expressions to match module IDs, that should remain external to the bundle.
267
+ - Type: `(string | RegExp)[] | undefined`
268
+ - Default: `[/^node:/, /^@types/, /^@rollup/, /^@rolldown/, /^@hypernym/, /^rollup/, /^rolldown/, ...pkg.dependencies]`
269
269
 
270
- IDs and regexps from this option are applied globally to all entries.
270
+ Specifies the module IDs or regular expressions that match module IDs to be treated as external and excluded from the bundle.
271
271
 
272
- Also, it is possible to define externals individually per entry (`entry.externals`).
272
+ The IDs and regular expressions provided in this option are applied globally across all entries.
273
273
 
274
274
  ```ts
275
275
  // bundler.config.ts
@@ -281,46 +281,30 @@ export default defineConfig({
281
281
  })
282
282
  ```
283
283
 
284
- ### alias
285
-
286
- - Type: `{ find: string | RegExp; replacement: string; }[]`
287
- - Default: `undefined`
288
-
289
- Specifies prefixes that will resolve imports with custom paths.
290
-
291
- Enables these `alias` by default:
284
+ Alternatively, externals can be defined individually for each entry using the `entry.externals` property.
292
285
 
293
286
  ```ts
294
- // Imports module from './src/utils/index.js'
295
- import { module } from '@/utils' // @
296
- import { module } from '~/utils' // ~
297
- ```
298
-
299
- Also, it is possible to completely override the default aliases by setting custom ones.
300
-
301
- ```ts
302
- // bundler.config.ts
303
-
304
- import { defineConfig } from '@hypernym/bundler'
305
-
306
287
  export default defineConfig({
307
- alias: [{ find: /^#/, replacement: resolve('./src') }],
288
+ entries: [
289
+ {
290
+ input: './src/index.ts',
291
+ externals: ['id-1', 'id-2', /regexp/],
292
+ },
293
+ ],
308
294
  })
309
295
  ```
310
296
 
311
- Now imports can be used like this:
312
-
313
- ```ts
314
- // Imports module from './src/utils/index.js'
315
- import { module } from '#/utils' // #
316
- ```
317
-
318
297
  ### minify
319
298
 
320
- - Type: `boolean`
299
+ - Type: `boolean | 'dce-only' | MinifyOptions | undefined`
321
300
  - Default: `undefined`
322
301
 
323
- Specifies the minification for all `chunk` entries.
302
+ Controls code minification for all `chunk` entries.
303
+
304
+ - `true`: Enable full minification including code compression and dead code elimination.
305
+ - `false`: Disable minification (default).
306
+ - `'dce-only'`: Only perform dead code elimination without code compression.
307
+ - `MinifyOptions`: Fine-grained control over minification settings.
324
308
 
325
309
  ```ts
326
310
  // bundler.config.ts
@@ -332,7 +316,7 @@ export default defineConfig({
332
316
  })
333
317
  ```
334
318
 
335
- It can also be set per entry.
319
+ It can also be set per entry:
336
320
 
337
321
  ```ts
338
322
  export default defineConfig({
@@ -360,7 +344,7 @@ List of lifecycle hooks that are called at various phases:
360
344
 
361
345
  ### bundle:start
362
346
 
363
- - Type: `(options: Options) => void | Promise<void>`
347
+ - Type: `(options: Options) => void | Promise<void> | undefined`
364
348
  - Default: `undefined`
365
349
 
366
350
  Called at the beginning of bundling.
@@ -381,7 +365,7 @@ export default defineConfig({
381
365
 
382
366
  ### build:start
383
367
 
384
- - Type: `(options: Options, stats: BuildStats) => void | Promise<void>`
368
+ - Type: `(options: Options, stats: BuildStats) => void | Promise<void> | undefined`
385
369
  - Default: `undefined`
386
370
 
387
371
  Called at the beginning of building.
@@ -402,7 +386,7 @@ export default defineConfig({
402
386
 
403
387
  ### build:entry:start
404
388
 
405
- - Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>`
389
+ - Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void> | undefined`
406
390
  - Default: `undefined`
407
391
 
408
392
  Called on each entry just before the build process.
@@ -418,14 +402,7 @@ import { plugin1, plugin2 } from './src/utils/plugins.js'
418
402
  export default defineConfig({
419
403
  hooks: {
420
404
  'build:entry:start': async (entry, stats) => {
421
- // adds custom plugins for a specific entry only
422
- if (entry.input?.includes('./src/index.ts')) {
423
- entry.defaultPlugins = [
424
- plugin1(), // adds a custom plugin before the default bundler plugins
425
- ...entry.defaultPlugins, // list of default bundler plugins
426
- plugin2(), // adds a custom plugin after the default bundler plugins
427
- ]
428
- }
405
+ // ...
429
406
  },
430
407
  },
431
408
  })
@@ -433,7 +410,7 @@ export default defineConfig({
433
410
 
434
411
  ### build:entry:end
435
412
 
436
- - Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>`
413
+ - Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void> | undefined`
437
414
  - Default: `undefined`
438
415
 
439
416
  Called on each entry right after the build process is completed.
@@ -454,7 +431,7 @@ export default defineConfig({
454
431
 
455
432
  ### build:end
456
433
 
457
- - Type: `(options: Options, stats: BuildStats) => void | Promise<void>`
434
+ - Type: `(options: Options, stats: BuildStats) => void | Promise<void> | undefined`
458
435
  - Default: `undefined`
459
436
 
460
437
  Called right after building is complete.
@@ -475,7 +452,7 @@ export default defineConfig({
475
452
 
476
453
  ### bundle:end
477
454
 
478
- - Type: `(options: Options) => void | Promise<void>`
455
+ - Type: `(options: Options) => void | Promise<void> | undefined`
479
456
  - Default: `undefined`
480
457
 
481
458
  Called right after bundling is complete.
@@ -496,34 +473,92 @@ export default defineConfig({
496
473
 
497
474
  ## Utils
498
475
 
499
- ### resolvePaths
500
-
501
- - Type: `(options: ResolvePathsOptions[]): (id: string) => string`
476
+ ### externals
502
477
 
503
- Resolves external module IDs into custom paths.
478
+ List of global default patterns for external module identifiers.
504
479
 
505
480
  ```ts
506
- import { defineConfig, resolvePaths } from '@hypernym/bundler'
481
+ import { externals } from '@hypernym/bundler'
507
482
 
508
483
  export default defineConfig({
509
484
  entries: [
510
485
  {
511
486
  input: './src/index.ts',
512
- externals: [/^@\/path/],
513
- paths: resolvePaths([
514
- // replaces `@/path` with `./path/index.mjs`
515
- { find: /^@\/path/, replacement: './path/index.mjs' },
516
- ]),
487
+ externals: [...externals, 'id', /regexp/],
517
488
  },
518
489
  ],
519
490
  })
520
491
  ```
521
492
 
522
- ## Community
493
+ ## Plugins
523
494
 
524
- Feel free to ask questions or share new ideas.
495
+ Provides built-in plugins that can be used out of the box and additionally customized as needed.
525
496
 
526
- Use the official [discussions](https://github.com/hypernym-studio/bundler/discussions) to get involved.
497
+ ```ts
498
+ import {
499
+ aliasPlugin,
500
+ jsonPlugin,
501
+ replacePlugin,
502
+ dts,
503
+ outputPaths,
504
+ //...
505
+ } from '@hypernym/bundler/plugins'
506
+ ```
507
+
508
+ ## Programmatic
509
+
510
+ ### build
511
+
512
+ - Type: `function build(options: Options): Promise<BuildStats>`
513
+
514
+ ```ts
515
+ import { build } from '@hypernym/bundler'
516
+
517
+ await build({
518
+ entries: [{ input: './src/index.ts' }],
519
+ // ...
520
+ })
521
+ ```
522
+
523
+ ## CLI
524
+
525
+ ### config
526
+
527
+ Specifies the path to the `bundler` custom config file.
528
+
529
+ ```sh
530
+ # pnpm
531
+ pnpm hyperbundler --config hyper.config.mjs
532
+
533
+ # npm
534
+ npx hyperbundler --config hyper.config.mjs
535
+ ```
536
+
537
+ ### cwd
538
+
539
+ Specifies the path to the project root (current working directory).
540
+
541
+ ```sh
542
+ # pnpm
543
+ pnpm hyperbundler --cwd ./custom-dir
544
+
545
+ # npm
546
+ npx hyperbundler --cwd ./custom-dir
547
+ ```
548
+
549
+ ### tsconfig
550
+
551
+ Specifies the path to the `tsconfig` file.
552
+
553
+ By default, if the file `tsconfig.json` exists in the project root, it will be used as the default config file.
554
+
555
+ ```sh
556
+ # pnpm
557
+ pnpm hyperbundler --tsconfig tsconfig.json
558
+
559
+ # npm
560
+ npx hyperbundler --tsconfig tsconfig.json
561
+ ```
527
562
 
528
563
  ## License
529
564