@hypernym/bundler 0.10.0 → 0.12.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,29 +1,24 @@
1
- import { OutputOptions, LogLevel, RollupLog, Plugin } from 'rollup';
1
+ import { OutputOptions, Plugin, LogLevel, RollupLog } from 'rollup';
2
2
  import { RollupReplaceOptions } from '@rollup/plugin-replace';
3
3
  import { RollupJsonOptions } from '@rollup/plugin-json';
4
4
  import { RollupNodeResolveOptions } from '@rollup/plugin-node-resolve';
5
+ import { RollupAliasOptions, Alias } from '@rollup/plugin-alias';
5
6
  import { TransformOptions } from 'esbuild';
6
7
  import { Options as Options$1 } from 'rollup-plugin-dts';
7
8
 
8
- interface PluginsInput {
9
+ interface TransformersChunk {
9
10
  esbuild?: TransformOptions;
10
11
  resolve?: RollupNodeResolveOptions | true;
11
- json?: RollupJsonOptions | true;
12
12
  replace?: RollupReplaceOptions;
13
+ json?: RollupJsonOptions | true;
14
+ alias?: RollupAliasOptions;
13
15
  }
14
- interface PluginsTypes {
16
+ interface TransformersDeclaration {
15
17
  dts?: Options$1;
18
+ alias?: RollupAliasOptions;
16
19
  }
17
20
 
18
21
  interface EntryBase {
19
- /**
20
- * Specifies the path of the transformed module.
21
- *
22
- * If not specified, matches the `input` path with the appropriate extension.
23
- *
24
- * @default undefined
25
- */
26
- output?: string;
27
22
  /**
28
23
  * Specifies the format of the generated module.
29
24
  *
@@ -75,18 +70,40 @@ interface EntryBase {
75
70
  * @default undefined
76
71
  */
77
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[];
78
81
  }
79
- interface EntryInput extends EntryBase {
82
+ interface EntryChunk extends EntryBase {
80
83
  /**
81
- * Specifies the path of the module's build source.
84
+ * Specifies the path of the build source.
82
85
  */
83
- input: string;
86
+ input?: string;
84
87
  /**
85
- * Specifies plugin options.
88
+ * Specifies the path of the transformed file.
86
89
  *
87
90
  * @default undefined
88
91
  */
89
- plugins?: PluginsInput;
92
+ output?: string;
93
+ /**
94
+ * Specifies the built-in `transformers` options.
95
+ *
96
+ * Available transformers:
97
+ *
98
+ * - `esbuild`
99
+ * - `resolve`
100
+ * - `replace`
101
+ * - `json`
102
+ * - `alias`
103
+ *
104
+ * @default undefined
105
+ */
106
+ transformers?: TransformersChunk;
90
107
  /**
91
108
  * Specifies the global variable name that representing exported bundle.
92
109
  *
@@ -109,24 +126,68 @@ interface EntryInput extends EntryBase {
109
126
  * Intended for `umd/iife` formats.
110
127
  */
111
128
  extend?: OutputOptions['extend'];
129
+ declaration?: never;
130
+ copy?: never;
131
+ template?: never;
132
+ }
133
+ interface EntryDeclaration extends EntryBase {
134
+ /**
135
+ * Specifies the path of the TypeScript `declaration` build source.
136
+ */
137
+ declaration?: string;
138
+ /**
139
+ * Specifies the path of the TypeScript transformed `declaration` file.
140
+ *
141
+ * @default undefined
142
+ */
143
+ output?: string;
144
+ /**
145
+ * Specifies the built-in `transformers` options.
146
+ *
147
+ * Available transformers:
148
+ *
149
+ * - `dts`
150
+ * - `alias`
151
+ *
152
+ * @default undefined
153
+ */
154
+ transformers?: TransformersDeclaration;
155
+ input?: never;
156
+ copy?: never;
157
+ template?: never;
158
+ name?: never;
159
+ globals?: never;
160
+ extend?: never;
112
161
  }
113
- interface EntryTypes extends EntryBase {
162
+ interface CopyOptions {
163
+ /**
164
+ * Specifies the path of the source.
165
+ */
166
+ input: string | string[];
114
167
  /**
115
- * Specifies the path of the module's build source that contains only TS definitions.
168
+ * Specifies the path of the destination directory.
116
169
  */
117
- types: string;
170
+ output: string;
118
171
  /**
119
- * Specifies plugin options.
172
+ * Copy directories recursively.
173
+ *
174
+ * @default true
175
+ */
176
+ recursive?: boolean;
177
+ /**
178
+ * Filters copied `files/directories`.
179
+ *
180
+ * Returns `true` to copy the item, `false` to ignore it.
120
181
  *
121
182
  * @default undefined
122
183
  */
123
- plugins?: PluginsTypes;
184
+ filter?(source: string, destination: string): boolean;
124
185
  }
125
- interface EntryTemplate extends Pick<EntryBase, 'logFilter'> {
186
+ interface EntryCopy {
126
187
  /**
127
- * Specifies the build entry as a module template.
188
+ * Copies the single `file` or entire `directory` structure from source to destination, including subdirectories and files.
128
189
  *
129
- * Provides the ability to dynamically inject template content during the build phase.
190
+ * This can be very useful for copying some assets that don't need a transformation process, but a simple copy paste feature.
130
191
  *
131
192
  * @example
132
193
  *
@@ -134,25 +195,30 @@ interface EntryTemplate extends Pick<EntryBase, 'logFilter'> {
134
195
  * export default defineConfig({
135
196
  * entries: [
136
197
  * {
137
- * template: true,
138
- * output: './dist/template.ts',
139
- * content: '// TypeScript code...',
140
- * },
198
+ * copy: {
199
+ * input: './src/path/file.ts', // or ['path-dir', 'path-file.ts', ...]
200
+ * output: './dist/out', // path to output dir
201
+ * }
202
+ * }
141
203
  * ]
142
204
  * })
143
205
  * ```
206
+ *
207
+ * @default undefined
144
208
  */
145
- template: true;
146
- /**
147
- * Specifies the path of the transformed module template.
148
- */
149
- output: string;
150
- /**
151
- * Specifies the content of the module template.
152
- */
153
- content: OutputOptions['intro'];
209
+ copy?: CopyOptions;
210
+ input?: never;
211
+ declaration?: never;
212
+ template?: never;
213
+ name?: never;
214
+ globals?: never;
215
+ extend?: never;
216
+ }
217
+ interface EntryTemplate {
154
218
  /**
155
- * Specifies the format of the generated module template.
219
+ * Specifies the content of the `template` file.
220
+ *
221
+ * Provides the ability to dynamically inject template content during the build phase.
156
222
  *
157
223
  * @example
158
224
  *
@@ -160,26 +226,26 @@ interface EntryTemplate extends Pick<EntryBase, 'logFilter'> {
160
226
  * export default defineConfig({
161
227
  * entries: [
162
228
  * {
163
- * template: true,
164
- * output: './dist/template.json',
165
- * content: '{}',
166
- * format: 'json',
229
+ * template: `// TypeScript code...`,
230
+ * output: './dist/template.ts',
167
231
  * },
168
232
  * ]
169
233
  * })
170
234
  * ```
171
- *
172
- * @default 'esm'
173
235
  */
174
- format?: string;
236
+ template: string;
175
237
  /**
176
- * Specifies plugin options.
177
- *
178
- * @default undefined
238
+ * Specifies the path of the transformed `template` file.
179
239
  */
180
- plugins?: Pick<PluginsInput, 'esbuild'>;
240
+ output: string;
241
+ input?: never;
242
+ declaration?: never;
243
+ copy?: never;
244
+ name?: never;
245
+ globals?: never;
246
+ extend?: never;
181
247
  }
182
- type EntryOptions = EntryInput | EntryTypes | EntryTemplate;
248
+ type EntryOptions = EntryChunk | EntryDeclaration | EntryCopy | EntryTemplate;
183
249
 
184
250
  interface Options {
185
251
  /**
@@ -193,7 +259,7 @@ interface Options {
193
259
  * export default defineConfig({
194
260
  * entries: [
195
261
  * { input: './src/index.ts' }, // => './dist/index.mjs'
196
- * { types: './src/types.ts' }, // => './dist/types.d.ts'
262
+ * { declaration: './src/types.ts' }, // => './dist/types.d.ts'
197
263
  * // ...
198
264
  * ]
199
265
  * })
@@ -203,6 +269,14 @@ interface Options {
203
269
  /**
204
270
  * Specifies the output directory for production bundle.
205
271
  *
272
+ * @example
273
+ *
274
+ * ```ts
275
+ * export default defineConfig({
276
+ * outDir: 'output',
277
+ * })
278
+ * ```
279
+ *
206
280
  * @default 'dist'
207
281
  */
208
282
  outDir?: string;
@@ -214,6 +288,14 @@ interface Options {
214
288
  *
215
289
  * Also, it is possible to define externals individually per entry (`entry.externals`).
216
290
  *
291
+ * @example
292
+ *
293
+ * ```ts
294
+ * export default defineConfig({
295
+ * externals: ['id-1', 'id-2', /regexp/],
296
+ * })
297
+ * ```
298
+ *
217
299
  * @default [/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]
218
300
  */
219
301
  externals?: (string | RegExp)[];
@@ -236,23 +318,38 @@ interface Options {
236
318
  */
237
319
  hooks?: HooksOptions;
238
320
  /**
239
- * Specifies global path alias support.
321
+ * Specifies prefixes that will resolve imports with custom paths.
322
+ *
323
+ * Enables these `alias` by default:
240
324
  *
241
- * If true, it enables import prefixes:
325
+ * ```ts
326
+ * // Imports module from './src/utils/index.js'
327
+ * import { module } from '@/utils' // @
328
+ * import { module } from '~/utils' // ~
329
+ * ```
242
330
  *
243
- * - `@/*`
244
- * - `~/*`
331
+ * Also, it is possible to completely override the default aliases by setting custom ones.
245
332
  *
246
333
  * @example
247
334
  *
248
335
  * ```ts
336
+ * export default defineConfig({
337
+ * alias: [
338
+ * { find: /^#/, replacement: resolve('./src') },
339
+ * ]
340
+ * })
341
+ * ```
342
+ *
343
+ * Now imports can be used like this:
344
+ *
345
+ * ```ts
249
346
  * // Imports module from './src/utils/index.js'
250
- * import { module } from '@/utils/index.js'
347
+ * import { module } from '#/utils' // #
251
348
  * ```
252
349
  *
253
350
  * @default undefined
254
351
  */
255
- alias?: true;
352
+ alias?: Alias[];
256
353
  }
257
354
 
258
355
  interface BuildLogs {
@@ -298,17 +395,17 @@ interface BuildStats {
298
395
  logs: BuildLogs[];
299
396
  }[];
300
397
  }
301
- interface BuildEntryOptions extends EntryBase, Partial<Omit<EntryInput, 'plugins'>>, Partial<Omit<EntryTypes, 'plugins'>> {
302
- /**
303
- * Specifies list of plugins.
304
- */
305
- plugins: Plugin[];
398
+ interface BuildEntryOptions extends EntryBase {
306
399
  /**
307
400
  * Specifies options for default plugins.
308
401
  *
309
402
  * @default undefined
310
403
  */
311
- pluginsOptions?: PluginsInput & PluginsTypes;
404
+ transformers?: TransformersChunk & TransformersDeclaration;
405
+ /**
406
+ * Specifies list of default plugins.
407
+ */
408
+ defaultPlugins: Plugin[];
312
409
  }
313
410
 
314
411
  interface HooksOptions {
@@ -356,26 +453,10 @@ interface HooksOptions {
356
453
  * @example
357
454
  *
358
455
  * ```ts
359
- * import { plugin1, plugin2, plugin3 } from './plugins'
360
- *
361
456
  * export default defineConfig({
362
457
  * hooks: {
363
458
  * 'build:entry:start': async (options, stats) => {
364
- * // adds custom plugins for a specific entry only
365
- * if (options.input?.includes('./src/index.ts')) {
366
- * options.plugins = [
367
- * plugin1(), // adds a custom plugin before the default bundler plugins
368
- * ...options.plugins, // list of default bundler plugins
369
- * plugin2(), // adds a custom plugin after the default bundler plugins
370
- * ]
371
- * }
372
- * // adds custom plugins for a specific types only
373
- * if (options.types?.includes('./src/types.ts')) {
374
- * options.plugins = [
375
- * ...options.plugins, // list of default bundler plugins
376
- * plugin3(), // adds a custom plugin designed to work only with TS declarations
377
- * ]
378
- * }
459
+ * // ...
379
460
  * }
380
461
  * }
381
462
  * })
@@ -440,6 +521,11 @@ interface HooksOptions {
440
521
  'bundle:end'?: (options: Options) => void | Promise<void>;
441
522
  }
442
523
 
524
+ interface ConfigLoader {
525
+ options: Options;
526
+ path: string;
527
+ }
528
+
443
529
  /**
444
530
  * List of global defaults for externals.
445
531
  *
@@ -462,26 +548,32 @@ declare const externals: RegExp[];
462
548
  declare function defineConfig(options: Options): Options;
463
549
 
464
550
  /**
465
- * Replaces the external module ID with a custom value.
551
+ * Resolves external module IDs into custom paths.
466
552
  *
467
553
  * @example
468
554
  *
469
555
  * ```ts
470
- * import { defineConfig, replacePath } from '@hypernym/bundler'
556
+ * import { defineConfig, resolvePaths } from '@hypernym/bundler'
471
557
  *
472
558
  * export default defineConfig({
473
559
  * entries: [
474
560
  * {
475
561
  * input: './src/index.ts',
476
- * output: './dist/index.mjs',
477
562
  * externals: [/^@\/path/],
478
- * // replaces `@/path` with `./path/index.mjs`
479
- * paths: (id) => replacePath(/^@\/path/, './easing/index.mjs')(id),
563
+ * paths: resolvePaths([
564
+ * // replaces `@/path` with `./path/index.mjs`
565
+ * { find: /^@\/path/, replacement: './path/index.mjs', }
566
+ * ]),
480
567
  * },
481
568
  * ]
482
569
  * })
483
570
  * ```
484
571
  */
485
- declare function replacePath(path: RegExp | string, replace: string): (id: string) => string;
572
+ declare function resolvePaths(options: ResolvePathsOptions[]): (id: string) => string;
573
+
574
+ interface ResolvePathsOptions {
575
+ find: string | RegExp;
576
+ replacement: string;
577
+ }
486
578
 
487
- export { type BuildLogs, type BuildStats, type EntryBase, type EntryInput, type EntryOptions, type EntryTemplate, type EntryTypes, type HooksOptions, type Options, type PluginsInput, type PluginsTypes, defineConfig, externals, replacePath };
579
+ 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.10.0",
3
+ "version": "0.12.0",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "ESM & TS module bundler.",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  "bundling",
25
25
  "javascript",
26
26
  "typescript",
27
+ "hyperbundler",
27
28
  "bundler",
28
29
  "builder",
29
30
  "package",
@@ -38,13 +39,13 @@
38
39
  },
39
40
  "scripts": {
40
41
  "build": "bun -b run ./src/bin/index.ts",
41
- "lint": "eslint -c .config/eslint.config.js .",
42
- "lint:fix": "eslint -c .config/eslint.config.js --fix .",
43
- "format": "prettier --config .config/prettier.config.js --write .",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint --fix .",
44
+ "format": "prettier --write .",
44
45
  "prepublishOnly": "npm run build"
45
46
  },
46
47
  "sideEffects": false,
47
- "packageManager": "pnpm@9.9.0",
48
+ "packageManager": "pnpm@9.11.0",
48
49
  "engines": {
49
50
  "node": ">=20.0.0",
50
51
  "pnpm": ">=9.0.0"
@@ -62,24 +63,23 @@
62
63
  }
63
64
  },
64
65
  "dependencies": {
65
- "@hypernym/args": "^0.2.1",
66
+ "@hypernym/args": "^0.3.0",
66
67
  "@hypernym/colors": "^1.0.1",
67
- "@hypernym/spinner": "^0.2.0",
68
- "@hypernym/utils": "^3.0.0",
68
+ "@hypernym/utils": "^3.4.0",
69
69
  "@rollup/plugin-alias": "^5.1.0",
70
70
  "@rollup/plugin-json": "^6.1.0",
71
71
  "@rollup/plugin-node-resolve": "^15.2.3",
72
72
  "@rollup/plugin-replace": "^5.0.7",
73
73
  "@rollup/pluginutils": "^5.1.0",
74
74
  "esbuild": "^0.23.1",
75
- "rollup": "^4.21.2",
75
+ "rollup": "^4.22.2",
76
76
  "rollup-plugin-dts": "^6.1.1"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@hypernym/eslint-config": "^3.5.0",
80
80
  "@hypernym/prettier-config": "^3.2.0",
81
- "@hypernym/tsconfig": "^2.2.0",
82
- "@types/node": "^22.5.4",
81
+ "@hypernym/tsconfig": "^2.4.0",
82
+ "@types/node": "^22.5.5",
83
83
  "eslint": "^9.10.0",
84
84
  "prettier": "^3.3.3",
85
85
  "typescript": "^5.5.4"
@@ -1 +0,0 @@
1
- // Generated by @hypernym/bundler