Skip to content

Commit 0d2c804

Browse files
authored
break: migrate to rolldown (#19)
* break: migrate to rolldown * chore: update dev tools configs * refactor: improve get-output-path util * refactor: improve get-longest-output util * refactor: update config loader * refactor: update main entry * refactor: update default config * refactor: update utils * chore: update dependencies * types: update bundler options * feat: add official plugins * chore: update dependencies and exports subpaths * chore: update bundler main config * refactor: update main entry * types: update bundler options * types: update types main entry * types: update entries options * types: update args interface * types: update options and build types * refactor: improve config loader * refactor: update main entry * refactor: update bin main entry * refactor: update builder * refactor: improve build function * refactor: cleanup unused files * chore: update dependencies * types: improve types * refactor: update build fn * feat: add new outputPaths plugin * docs: update docs * docs: update info * types: update plugins types * chore: update bundler main config
1 parent c2f2bb8 commit 0d2c804

30 files changed

+1131
-2147
lines changed

LICENSE.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

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>
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 119 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020

2121
## Features
2222

23-
- Powered by Rollup
24-
- Written in TypeScript
23+
- Powered by Rolldown
2524
- Allows Advanced Customization
2625
- Provides a Powerful Hooking System
27-
- Supports All TS Module Resolutions
2826
- Exports Fully Optimized Code
2927
- Follows Modern Practice
3028
- Super Easy to Use
@@ -67,9 +65,13 @@ export default defineConfig({
6765
})
6866
```
6967

70-
3. Build via command:
68+
3. Build via commands:
7169

7270
```sh
71+
# pnpm
72+
pnpm hyperbundler
73+
74+
# npm
7375
npx hyperbundler
7476
```
7577

@@ -94,6 +96,10 @@ export default defineConfig({
9496
Set a custom config path via the CLI command:
9597

9698
```sh
99+
# pnpm
100+
pnpm hyperbundler --config hyper.config.ts
101+
102+
# npm
97103
npx hyperbundler --config hyper.config.ts
98104
```
99105

@@ -124,7 +130,7 @@ Default transformation behaviour for all `dts` entries:
124130

125131
## Options
126132

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 are documented with descriptions and examples so autocompletion will be offered as you type. Simply hover over the property and see what it does in the quick info tooltip.
128134

129135
### entries
130136

@@ -141,16 +147,14 @@ import { defineConfig } from '@hypernym/bundler'
141147

142148
export default defineConfig({
143149
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'
146152
// ...
147153
],
148154
})
149155
```
150156

151-
#### Entry Chunk
152-
153-
- [Types](./src/types/entries.ts)
157+
### Entry Chunk
154158

155159
Automatically transforms `chunks` for production.
156160

@@ -161,48 +165,38 @@ import { defineConfig } from '@hypernym/bundler'
161165

162166
export default defineConfig({
163167
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+
},
165173
],
166174
})
167175
```
168176

169-
#### Entry Declaration
177+
### Entry Dts
170178

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.
174180

175181
```ts
176-
// bundler.config.ts
177-
178182
import { defineConfig } from '@hypernym/bundler'
179183

180184
export default defineConfig({
181185
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+
},
195191
],
196192
})
197193
```
198194

199-
#### Entry Copy
195+
### Entry Copy
200196

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.
202198

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.
206200

207201
```ts
208202
// bundler.config.ts
@@ -212,20 +206,28 @@ import { defineConfig } from '@hypernym/bundler'
212206
export default defineConfig({
213207
entries: [
214208
{
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',
219221
},
220222
],
221223
})
222224
```
223225

224-
#### Entry Template
226+
### Entry Template
225227

226-
- [Types](./src/types/entries.ts)
228+
Specifies the content of the `template` file.
227229

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.
229231

230232
```ts
231233
// bundler.config.ts
@@ -265,11 +267,11 @@ export default defineConfig({
265267
- Type: `(string | RegExp)[]`
266268
- Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
267269

268-
Specifies the module IDs, or regular expressions to match module IDs, that should remain external to the bundle.
270+
Specifies the module IDs or regular expressions that match module IDs to be treated as external and excluded from the bundle.
269271

270-
IDs and regexps from this option are applied globally to all entries.
272+
The IDs and regular expressions provided in this option are applied globally across all entries.
271273

272-
Also, it is possible to define externals individually per entry (`entry.externals`).
274+
Alternatively, externals can be defined individually for each entry using the `entry.externals` property.
273275

274276
```ts
275277
// bundler.config.ts
@@ -281,40 +283,6 @@ export default defineConfig({
281283
})
282284
```
283285

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:
292-
293-
```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-
export default defineConfig({
307-
alias: [{ find: /^#/, replacement: resolve('./src') }],
308-
})
309-
```
310-
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-
318286
### minify
319287

320288
- Type: `boolean`
@@ -418,14 +386,7 @@ import { plugin1, plugin2 } from './src/utils/plugins.js'
418386
export default defineConfig({
419387
hooks: {
420388
'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-
}
389+
// ...
429390
},
430391
},
431392
})
@@ -496,34 +457,92 @@ export default defineConfig({
496457

497458
## Utils
498459

499-
### resolvePaths
500-
501-
- Type: `(options: ResolvePathsOptions[]): (id: string) => string`
460+
### externals
502461

503-
Resolves external module IDs into custom paths.
462+
List of global default patterns for external module identifiers.
504463

505464
```ts
506-
import { defineConfig, resolvePaths } from '@hypernym/bundler'
465+
import { externals } from '@hypernym/bundler'
507466

508467
export default defineConfig({
509468
entries: [
510469
{
511470
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-
]),
471+
externals: [...externals, 'id', /regexp/],
517472
},
518473
],
519474
})
520475
```
521476

522-
## Community
477+
## Plugins
523478

524-
Feel free to ask questions or share new ideas.
479+
Provides built-in plugins that can be used out of the box and additionally customized as needed.
525480

526-
Use the official [discussions](https://github.com/hypernym-studio/bundler/discussions) to get involved.
481+
```ts
482+
import {
483+
aliasPlugin,
484+
jsonPlugin,
485+
replacePlugin,
486+
dts,
487+
outputPaths,
488+
//...
489+
} from '@hypernym/bundler/plugins'
490+
```
491+
492+
## Programmatic
493+
494+
### build
495+
496+
- Type: `function build(options: Options): Promise<BuildStats>`
497+
498+
```ts
499+
import { build } from '@hypernym/bundler'
500+
501+
await build({
502+
entries: [{ input: './src/index.ts' }],
503+
// ...
504+
})
505+
```
506+
507+
## CLI
508+
509+
### config
510+
511+
Specifies the path to the `bundler` custom config file.
512+
513+
```sh
514+
# pnpm
515+
pnpm hyperbundler --config hyper.config.mjs
516+
517+
# npm
518+
npx hyperbundler --config hyper.config.mjs
519+
```
520+
521+
### cwd
522+
523+
Specifies the path to the project root (current working directory).
524+
525+
```sh
526+
# pnpm
527+
pnpm hyperbundler --cwd ./custom-dir
528+
529+
# npm
530+
npx hyperbundler --cwd ./custom-dir
531+
```
532+
533+
### tsconfig
534+
535+
Specifies the path to the `tsconfig` file.
536+
537+
By default, if the file `tsconfig.json` exists in the project root, it will be used as the default config file.
538+
539+
```sh
540+
# pnpm
541+
pnpm hyperbundler --tsconfig tsconfig.json
542+
543+
# npm
544+
npx hyperbundler --tsconfig tsconfig.json
545+
```
527546

528547
## License
529548

bundler.config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
import { defineConfig } from '@/config'
1+
import { defineConfig, externals } from '@/config'
2+
import { replacePlugin } from '@/plugins'
23
import { version } from './package.json'
34

45
export default defineConfig({
56
entries: [
6-
{ input: './src/index.ts' },
7-
{ dts: './src/types/index.ts', output: './dist/index.d.mts' },
7+
{
8+
input: './src/bin/build.ts',
9+
output: './dist/build/index.mjs',
10+
externals: [...externals, '@/plugins'],
11+
paths: [{ find: '@/plugins', replacement: '../plugins/index.mjs' }],
12+
},
813
{
914
input: './src/index.ts',
10-
output: './dist/index.cjs',
15+
externals: [...externals, '@/bin/build'],
16+
paths: [{ find: '@/bin/build', replacement: './build/index.mjs' }],
1117
},
18+
{ dts: './src/types/index.ts', output: './dist/index.d.mts' },
19+
{ input: './src/plugins/index.ts' },
1220
{
13-
dts: './src/types/index.ts',
14-
output: './dist/index.d.cts',
21+
dts: './src/plugins/types/index.ts',
22+
output: './dist/plugins/index.d.mts',
1523
},
1624
{
1725
input: './src/bin/index.ts',
18-
transformers: {
19-
replace: {
20-
__version__: version,
21-
},
22-
},
26+
externals: [...externals, './build'],
27+
paths: [{ find: './build', replacement: '../build/index.mjs' }],
28+
plugins: [replacePlugin({ __version__: version })],
2329
},
2430
],
2531
})
File renamed without changes.

0 commit comments

Comments
 (0)