@hypernym/bundler 0.11.0 → 0.13.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/README.md +63 -47
- package/dist/bin/index.mjs +15 -10
- package/dist/index.mjs +6 -3
- package/dist/types/index.d.ts +64 -6
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
<pre align="center">pnpm add -D @hypernym/bundler</pre>
|
|
16
16
|
|
|
17
|
-
<
|
|
17
|
+
<p align="center">
|
|
18
|
+
<strong>Hypernym Studio</strong>
|
|
19
|
+
</p>
|
|
18
20
|
|
|
19
21
|
<br>
|
|
20
22
|
|
|
@@ -34,10 +36,6 @@
|
|
|
34
36
|
|
|
35
37
|
1. Create a `bundler.config.ts` file at the root of your project:
|
|
36
38
|
|
|
37
|
-
> [!NOTE]
|
|
38
|
-
>
|
|
39
|
-
> Configuration also accepts `.js`, `.mjs`, `.ts`, `.mts` formats.
|
|
40
|
-
|
|
41
39
|
```ts
|
|
42
40
|
// bundler.config.ts
|
|
43
41
|
|
|
@@ -64,9 +62,7 @@ export default defineConfig({
|
|
|
64
62
|
{
|
|
65
63
|
input: './src/utils/index.ts',
|
|
66
64
|
output: './dist/utils/utils.min.mjs',
|
|
67
|
-
|
|
68
|
-
esbuild: { minify: true },
|
|
69
|
-
},
|
|
65
|
+
minify: true,
|
|
70
66
|
},
|
|
71
67
|
// ...
|
|
72
68
|
],
|
|
@@ -79,35 +75,33 @@ export default defineConfig({
|
|
|
79
75
|
npx hyperbundler
|
|
80
76
|
```
|
|
81
77
|
|
|
82
|
-
|
|
83
|
-
<summary>CLI Output</summary>
|
|
78
|
+
## Config
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
├─ + dts ./dist/types/index.d.ts (1.23s) 13.61 KB
|
|
98
|
-
├─ + esm ./dist/bin/index.mjs (119ms) 16.53 KB
|
|
99
|
-
│
|
|
100
|
-
* Succeeded [8:07:28 PM] Module transformation is done
|
|
101
|
-
✔ Bundling fully completed in 1.40s
|
|
102
|
-
✔ 3 modules transformed. Total size is 30.45 KB
|
|
103
|
-
✦✦ HYPERBUNDLER [8:07:28 PM] Bundle is generated and ready for production
|
|
80
|
+
`Hyperbundler` automatically detects custom configuration from the project root that can override or extend the build behavior.
|
|
81
|
+
|
|
82
|
+
Configuration file also accepts `.js`, `.mjs`, `.ts`, `.mts` formats.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// bundler.config.{js,mjs,ts,mts}
|
|
86
|
+
|
|
87
|
+
import { defineConfig } from '@hypernym/bundler'
|
|
88
|
+
|
|
89
|
+
export default defineConfig({
|
|
90
|
+
// ...
|
|
91
|
+
})
|
|
104
92
|
```
|
|
105
93
|
|
|
106
|
-
|
|
94
|
+
### Custom path
|
|
95
|
+
|
|
96
|
+
Set a custom config path via the CLI command:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
npx hyperbundler --config hyper.config.ts
|
|
100
|
+
```
|
|
107
101
|
|
|
108
102
|
## Options
|
|
109
103
|
|
|
110
|
-
All options are documented with descriptions and examples
|
|
104
|
+
All options are documented with descriptions and examples so auto-completion will be offered as you type.
|
|
111
105
|
|
|
112
106
|
Simply hover over the property and see what it does in the `quickinfo`.
|
|
113
107
|
|
|
@@ -292,6 +286,36 @@ Now imports can be used like this:
|
|
|
292
286
|
import { module } from '#/utils' // #
|
|
293
287
|
```
|
|
294
288
|
|
|
289
|
+
### minify
|
|
290
|
+
|
|
291
|
+
- Type: `boolean`
|
|
292
|
+
- Default: `undefined`
|
|
293
|
+
|
|
294
|
+
Specifies the minification for all `chunk` entries.
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
// bundler.config.ts
|
|
298
|
+
|
|
299
|
+
import { defineConfig } from '@hypernym/bundler'
|
|
300
|
+
|
|
301
|
+
export default defineConfig({
|
|
302
|
+
minify: true,
|
|
303
|
+
})
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
It can also be set per entry.
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
export default defineConfig({
|
|
310
|
+
entries: [
|
|
311
|
+
{
|
|
312
|
+
input: './src/index.ts',
|
|
313
|
+
minify: true,
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
})
|
|
317
|
+
```
|
|
318
|
+
|
|
295
319
|
## Hooks
|
|
296
320
|
|
|
297
321
|
List of lifecycle hooks that are called at various phases:
|
|
@@ -443,37 +467,29 @@ export default defineConfig({
|
|
|
443
467
|
|
|
444
468
|
## Utils
|
|
445
469
|
|
|
446
|
-
###
|
|
470
|
+
### resolvePaths
|
|
447
471
|
|
|
448
|
-
- Type: `(
|
|
472
|
+
- Type: `(options: ResolvePathsOptions[]): (id: string) => string`
|
|
449
473
|
|
|
450
|
-
|
|
474
|
+
Resolves external module IDs into custom paths.
|
|
451
475
|
|
|
452
476
|
```ts
|
|
453
|
-
import { defineConfig,
|
|
477
|
+
import { defineConfig, resolvePaths } from '@hypernym/bundler'
|
|
454
478
|
|
|
455
479
|
export default defineConfig({
|
|
456
480
|
entries: [
|
|
457
481
|
{
|
|
458
482
|
input: './src/index.ts',
|
|
459
483
|
externals: [/^@\/path/],
|
|
460
|
-
|
|
461
|
-
|
|
484
|
+
paths: resolvePaths([
|
|
485
|
+
// replaces `@/path` with `./path/index.mjs`
|
|
486
|
+
{ find: /^@\/path/, replacement: './path/index.mjs' },
|
|
487
|
+
]),
|
|
462
488
|
},
|
|
463
489
|
],
|
|
464
490
|
})
|
|
465
491
|
```
|
|
466
492
|
|
|
467
|
-
## CLI
|
|
468
|
-
|
|
469
|
-
### Custom Config
|
|
470
|
-
|
|
471
|
-
Set a custom config path via the CLI command:
|
|
472
|
-
|
|
473
|
-
```sh
|
|
474
|
-
npx hyperbundler --config hyper.config.ts
|
|
475
|
-
```
|
|
476
|
-
|
|
477
493
|
## Community
|
|
478
494
|
|
|
479
495
|
Feel free to ask questions or share new ideas.
|
package/dist/bin/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import process, { cwd } from 'node:process';
|
|
3
3
|
import { createArgs } from '@hypernym/args';
|
|
4
4
|
import { resolve, dirname, parse } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import { exists, writeFile } from '@hypernym/utils/fs';
|
|
5
|
+
import { read, exists, write, copy, readdir } from '@hypernym/utils/fs';
|
|
7
6
|
import { dim, cyan, bold, green } from '@hypernym/colors';
|
|
8
7
|
import { build as build$1, transform } from 'esbuild';
|
|
9
|
-
import {
|
|
8
|
+
import { stat } from 'node:fs/promises';
|
|
9
|
+
import { isString, isUndefined, isObject } from '@hypernym/utils';
|
|
10
10
|
import { rollup } from 'rollup';
|
|
11
11
|
import { getLogFilter } from 'rollup/getLogFilter';
|
|
12
12
|
import replacePlugin from '@rollup/plugin-replace';
|
|
@@ -27,7 +27,7 @@ const externals = [
|
|
|
27
27
|
const logo = `\u2726\u2726`;
|
|
28
28
|
const name$1 = "hyperbundler";
|
|
29
29
|
const logoname = `${logo} ${name$1}`;
|
|
30
|
-
const version = `0.
|
|
30
|
+
const version = `0.13.0`;
|
|
31
31
|
|
|
32
32
|
const name = logoname.toUpperCase();
|
|
33
33
|
const cl = console.log;
|
|
@@ -98,7 +98,7 @@ async function loadConfig(cwd, filePath, defaults) {
|
|
|
98
98
|
});
|
|
99
99
|
const code = result.outputFiles[0].text;
|
|
100
100
|
const tempConfig = resolve(cwd, "node_modules/.hypernym/bundler/config.mjs");
|
|
101
|
-
await
|
|
101
|
+
await write(tempConfig, code);
|
|
102
102
|
const content = await import(tempConfig);
|
|
103
103
|
const config = {
|
|
104
104
|
...defaults,
|
|
@@ -108,7 +108,7 @@ async function loadConfig(cwd, filePath, defaults) {
|
|
|
108
108
|
}
|
|
109
109
|
async function createConfigLoader(cwd, args) {
|
|
110
110
|
const pkgPath = resolve(cwd, "package.json");
|
|
111
|
-
const pkg = await
|
|
111
|
+
const pkg = await read(pkgPath).catch(error);
|
|
112
112
|
const { dependencies } = JSON.parse(pkg);
|
|
113
113
|
const warnMessage = `Missing required configuration. To start bundling, add the ${cyan(
|
|
114
114
|
`'bundler.config.{js,mjs,ts,mts}'`
|
|
@@ -241,7 +241,7 @@ async function build(cwd, options) {
|
|
|
241
241
|
for (const copyInput of _entry.input) {
|
|
242
242
|
const fileSrc = resolve(cwd, copyInput);
|
|
243
243
|
const fileDist = resolve(cwd, _entry.output, copyInput);
|
|
244
|
-
await
|
|
244
|
+
await copy(fileSrc, fileDist, {
|
|
245
245
|
recursive: _entry.recursive,
|
|
246
246
|
filter: _entry.filter
|
|
247
247
|
}).catch(error);
|
|
@@ -249,7 +249,7 @@ async function build(cwd, options) {
|
|
|
249
249
|
let totalSize = 0;
|
|
250
250
|
if (!stats.isDirectory()) totalSize = stats.size;
|
|
251
251
|
else {
|
|
252
|
-
const files = await readdir(fileDist
|
|
252
|
+
const files = await readdir(fileDist);
|
|
253
253
|
for (const file of files) {
|
|
254
254
|
const filePath = resolve(fileDist, file);
|
|
255
255
|
const fileStat = await stat(filePath);
|
|
@@ -288,7 +288,12 @@ async function build(cwd, options) {
|
|
|
288
288
|
externals: entry.externals || options.externals,
|
|
289
289
|
format: entry.format || _format,
|
|
290
290
|
transformers: entry.transformers,
|
|
291
|
-
defaultPlugins: [
|
|
291
|
+
defaultPlugins: [
|
|
292
|
+
esbuild({
|
|
293
|
+
minify: !isUndefined(entry.minify) ? entry.minify : options.minify,
|
|
294
|
+
...entry.transformers?.esbuild
|
|
295
|
+
})
|
|
296
|
+
],
|
|
292
297
|
plugins: entry.plugins,
|
|
293
298
|
banner: entry.banner,
|
|
294
299
|
footer: entry.footer,
|
|
@@ -416,7 +421,7 @@ async function build(cwd, options) {
|
|
|
416
421
|
template: entry.template,
|
|
417
422
|
output: entry.output
|
|
418
423
|
};
|
|
419
|
-
await
|
|
424
|
+
await write(_entry.output, _entry.template);
|
|
420
425
|
const stats = await stat(resolve(cwd, _entry.output));
|
|
421
426
|
const fileStats = {
|
|
422
427
|
path: _entry.output,
|
package/dist/index.mjs
CHANGED
|
@@ -9,11 +9,14 @@ function defineConfig(options) {
|
|
|
9
9
|
return options;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function
|
|
12
|
+
function resolvePaths(options) {
|
|
13
13
|
return (id) => {
|
|
14
|
-
|
|
14
|
+
for (const resolver of options) {
|
|
15
|
+
const { find, replacement } = resolver;
|
|
16
|
+
if (id.match(find)) id = replacement;
|
|
17
|
+
}
|
|
15
18
|
return id;
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
export { defineConfig, externals,
|
|
22
|
+
export { defineConfig, externals, resolvePaths };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -126,6 +126,12 @@ interface EntryChunk extends EntryBase {
|
|
|
126
126
|
* Intended for `umd/iife` formats.
|
|
127
127
|
*/
|
|
128
128
|
extend?: OutputOptions['extend'];
|
|
129
|
+
/**
|
|
130
|
+
* Minifies the generated code if enabled.
|
|
131
|
+
*
|
|
132
|
+
* @default undefined
|
|
133
|
+
*/
|
|
134
|
+
minify?: boolean;
|
|
129
135
|
declaration?: never;
|
|
130
136
|
copy?: never;
|
|
131
137
|
template?: never;
|
|
@@ -158,6 +164,7 @@ interface EntryDeclaration extends EntryBase {
|
|
|
158
164
|
name?: never;
|
|
159
165
|
globals?: never;
|
|
160
166
|
extend?: never;
|
|
167
|
+
minify?: never;
|
|
161
168
|
}
|
|
162
169
|
interface CopyOptions {
|
|
163
170
|
/**
|
|
@@ -213,6 +220,7 @@ interface EntryCopy {
|
|
|
213
220
|
name?: never;
|
|
214
221
|
globals?: never;
|
|
215
222
|
extend?: never;
|
|
223
|
+
minify?: never;
|
|
216
224
|
}
|
|
217
225
|
interface EntryTemplate {
|
|
218
226
|
/**
|
|
@@ -244,6 +252,7 @@ interface EntryTemplate {
|
|
|
244
252
|
name?: never;
|
|
245
253
|
globals?: never;
|
|
246
254
|
extend?: never;
|
|
255
|
+
minify?: never;
|
|
247
256
|
}
|
|
248
257
|
type EntryOptions = EntryChunk | EntryDeclaration | EntryCopy | EntryTemplate;
|
|
249
258
|
|
|
@@ -350,6 +359,33 @@ interface Options {
|
|
|
350
359
|
* @default undefined
|
|
351
360
|
*/
|
|
352
361
|
alias?: Alias[];
|
|
362
|
+
/**
|
|
363
|
+
* Specifies the minification for all `chunk` entries.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
*
|
|
367
|
+
* ```ts
|
|
368
|
+
* export default defineConfig({
|
|
369
|
+
* minify: true,
|
|
370
|
+
* })
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* It can also be set per entry.
|
|
374
|
+
*
|
|
375
|
+
* ```ts
|
|
376
|
+
* export default defineConfig({
|
|
377
|
+
* entries: [
|
|
378
|
+
* {
|
|
379
|
+
* input: './src/index.ts',
|
|
380
|
+
* minify: true,
|
|
381
|
+
* },
|
|
382
|
+
* ],
|
|
383
|
+
* })
|
|
384
|
+
* ```
|
|
385
|
+
*
|
|
386
|
+
* @default undefined
|
|
387
|
+
*/
|
|
388
|
+
minify?: boolean;
|
|
353
389
|
}
|
|
354
390
|
|
|
355
391
|
interface BuildLogs {
|
|
@@ -545,28 +581,50 @@ interface ConfigLoader {
|
|
|
545
581
|
* ```
|
|
546
582
|
*/
|
|
547
583
|
declare const externals: RegExp[];
|
|
584
|
+
/**
|
|
585
|
+
* `Hyperbundler` automatically detects custom configuration from the project root that can override or extend the build behavior.
|
|
586
|
+
*
|
|
587
|
+
* Configuration file also accepts `.js`, `.mjs`, `.ts`, `.mts` formats.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
*
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { defineConfig } from '@hypernym/bundler'
|
|
593
|
+
*
|
|
594
|
+
* export default defineConfig({
|
|
595
|
+
* // ...
|
|
596
|
+
* })
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
548
599
|
declare function defineConfig(options: Options): Options;
|
|
549
600
|
|
|
550
601
|
/**
|
|
551
|
-
*
|
|
602
|
+
* Resolves external module IDs into custom paths.
|
|
552
603
|
*
|
|
553
604
|
* @example
|
|
554
605
|
*
|
|
555
606
|
* ```ts
|
|
556
|
-
* import { defineConfig,
|
|
607
|
+
* import { defineConfig, resolvePaths } from '@hypernym/bundler'
|
|
557
608
|
*
|
|
558
609
|
* export default defineConfig({
|
|
559
610
|
* entries: [
|
|
560
611
|
* {
|
|
561
612
|
* input: './src/index.ts',
|
|
562
613
|
* externals: [/^@\/path/],
|
|
563
|
-
*
|
|
564
|
-
*
|
|
614
|
+
* paths: resolvePaths([
|
|
615
|
+
* // replaces `@/path` with `./path/index.mjs`
|
|
616
|
+
* { find: /^@\/path/, replacement: './path/index.mjs', }
|
|
617
|
+
* ]),
|
|
565
618
|
* },
|
|
566
619
|
* ]
|
|
567
620
|
* })
|
|
568
621
|
* ```
|
|
569
622
|
*/
|
|
570
|
-
declare function
|
|
623
|
+
declare function resolvePaths(options: ResolvePathsOptions[]): (id: string) => string;
|
|
624
|
+
|
|
625
|
+
interface ResolvePathsOptions {
|
|
626
|
+
find: string | RegExp;
|
|
627
|
+
replacement: string;
|
|
628
|
+
}
|
|
571
629
|
|
|
572
|
-
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 TransformersChunk, type TransformersDeclaration, defineConfig, externals,
|
|
630
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypernym/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "Hypernym Studio",
|
|
5
5
|
"description": "ESM & TS module bundler.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,14 +20,13 @@
|
|
|
20
20
|
],
|
|
21
21
|
"keywords": [
|
|
22
22
|
"module",
|
|
23
|
-
"modules",
|
|
24
23
|
"bundling",
|
|
25
24
|
"javascript",
|
|
26
25
|
"typescript",
|
|
27
26
|
"hyperbundler",
|
|
27
|
+
"declarations",
|
|
28
28
|
"bundler",
|
|
29
29
|
"builder",
|
|
30
|
-
"package",
|
|
31
30
|
"bundle",
|
|
32
31
|
"types",
|
|
33
32
|
"build",
|
|
@@ -45,7 +44,7 @@
|
|
|
45
44
|
"prepublishOnly": "npm run build"
|
|
46
45
|
},
|
|
47
46
|
"sideEffects": false,
|
|
48
|
-
"packageManager": "pnpm@9.
|
|
47
|
+
"packageManager": "pnpm@9.11.0",
|
|
49
48
|
"engines": {
|
|
50
49
|
"node": ">=20.0.0",
|
|
51
50
|
"pnpm": ">=9.0.0"
|
|
@@ -65,22 +64,22 @@
|
|
|
65
64
|
"dependencies": {
|
|
66
65
|
"@hypernym/args": "^0.3.0",
|
|
67
66
|
"@hypernym/colors": "^1.0.1",
|
|
68
|
-
"@hypernym/utils": "^3.0
|
|
67
|
+
"@hypernym/utils": "^3.4.0",
|
|
69
68
|
"@rollup/plugin-alias": "^5.1.0",
|
|
70
69
|
"@rollup/plugin-json": "^6.1.0",
|
|
71
70
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
72
71
|
"@rollup/plugin-replace": "^5.0.7",
|
|
73
72
|
"@rollup/pluginutils": "^5.1.0",
|
|
74
73
|
"esbuild": "^0.23.1",
|
|
75
|
-
"rollup": "^4.
|
|
74
|
+
"rollup": "^4.22.4",
|
|
76
75
|
"rollup-plugin-dts": "^6.1.1"
|
|
77
76
|
},
|
|
78
77
|
"devDependencies": {
|
|
79
78
|
"@hypernym/eslint-config": "^3.5.0",
|
|
80
79
|
"@hypernym/prettier-config": "^3.2.0",
|
|
81
|
-
"@hypernym/tsconfig": "^2.
|
|
80
|
+
"@hypernym/tsconfig": "^2.4.0",
|
|
82
81
|
"@types/node": "^22.5.5",
|
|
83
|
-
"eslint": "^9.
|
|
82
|
+
"eslint": "^9.11.0",
|
|
84
83
|
"prettier": "^3.3.3",
|
|
85
84
|
"typescript": "^5.5.4"
|
|
86
85
|
}
|