@hypernym/bundler 0.2.0 → 0.3.1
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/dist/bin/index.mjs +24 -7
- package/dist/types/index.d.ts +192 -36
- package/package.json +4 -4
package/dist/bin/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const externals = [
|
|
|
25
25
|
];
|
|
26
26
|
|
|
27
27
|
const name = "bundler";
|
|
28
|
-
const version = `0.
|
|
28
|
+
const version = `0.3.1`;
|
|
29
29
|
|
|
30
30
|
const cl = console.log;
|
|
31
31
|
const logger = {
|
|
@@ -212,13 +212,13 @@ async function build(cwd, options) {
|
|
|
212
212
|
_format = "cjs";
|
|
213
213
|
const output = entry.output || _output;
|
|
214
214
|
const format = entry.format || _format;
|
|
215
|
-
const
|
|
215
|
+
const _plugins = [esbuild(plugins?.esbuild)];
|
|
216
216
|
if (plugins?.json) {
|
|
217
217
|
const jsonOptions = isObject(plugins.json) ? plugins.json : void 0;
|
|
218
|
-
|
|
218
|
+
_plugins.push(jsonPlugin(jsonOptions));
|
|
219
219
|
}
|
|
220
220
|
if (plugins?.replace) {
|
|
221
|
-
|
|
221
|
+
_plugins.unshift(
|
|
222
222
|
replacePlugin({
|
|
223
223
|
true: true,
|
|
224
224
|
...plugins.replace
|
|
@@ -227,12 +227,20 @@ async function build(cwd, options) {
|
|
|
227
227
|
}
|
|
228
228
|
if (plugins?.resolve) {
|
|
229
229
|
const resolveOptions = isObject(plugins.resolve) ? plugins.resolve : void 0;
|
|
230
|
-
|
|
230
|
+
_plugins.unshift(resolvePlugin(resolveOptions));
|
|
231
|
+
}
|
|
232
|
+
if (hooks?.["rollup:plugins"]) {
|
|
233
|
+
hooks["rollup:plugins"](_plugins, {
|
|
234
|
+
...entry,
|
|
235
|
+
input,
|
|
236
|
+
output,
|
|
237
|
+
format
|
|
238
|
+
});
|
|
231
239
|
}
|
|
232
240
|
const builder = await rollup({
|
|
233
241
|
input: resolve(cwd, input),
|
|
234
242
|
external: externals || options.externals,
|
|
235
|
-
plugins:
|
|
243
|
+
plugins: _plugins,
|
|
236
244
|
onLog: (level, log) => {
|
|
237
245
|
if (logFilter(log))
|
|
238
246
|
buildLogs.push({ level, log });
|
|
@@ -263,10 +271,19 @@ async function build(cwd, options) {
|
|
|
263
271
|
_format = "cjs";
|
|
264
272
|
const output = entry.output || _output;
|
|
265
273
|
const format = entry.format || _format;
|
|
274
|
+
const _plugins = [dts(plugins?.dts)];
|
|
275
|
+
if (hooks?.["rollup:plugins"]) {
|
|
276
|
+
hooks["rollup:plugins"](_plugins, {
|
|
277
|
+
...entry,
|
|
278
|
+
types,
|
|
279
|
+
output,
|
|
280
|
+
format
|
|
281
|
+
});
|
|
282
|
+
}
|
|
266
283
|
const builder = await rollup({
|
|
267
284
|
input: resolve(cwd, types),
|
|
268
285
|
external: externals || options.externals,
|
|
269
|
-
plugins:
|
|
286
|
+
plugins: _plugins,
|
|
270
287
|
onLog: (level, log) => {
|
|
271
288
|
if (logFilter(log))
|
|
272
289
|
buildLogs.push({ level, log });
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OutputOptions, LogLevel, RollupLog } from 'rollup';
|
|
1
|
+
import { OutputOptions, LogLevel, RollupLog, Plugin } 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
5
|
import { TransformOptions } from 'esbuild';
|
|
6
6
|
import { Options as Options$1 } from 'rollup-plugin-dts';
|
|
7
7
|
|
|
8
|
-
interface
|
|
8
|
+
interface PluginsOptions {
|
|
9
9
|
esbuild?: TransformOptions;
|
|
10
10
|
dts?: Options$1;
|
|
11
11
|
resolve?: RollupNodeResolveOptions | true;
|
|
@@ -13,7 +13,7 @@ interface BuildPlugins {
|
|
|
13
13
|
replace?: RollupReplaceOptions;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface
|
|
16
|
+
interface EntryBase {
|
|
17
17
|
/**
|
|
18
18
|
* Specifies the path of the transformed module.
|
|
19
19
|
*
|
|
@@ -56,7 +56,7 @@ interface Entry {
|
|
|
56
56
|
*/
|
|
57
57
|
logFilter?: string[];
|
|
58
58
|
}
|
|
59
|
-
interface EntryInput extends
|
|
59
|
+
interface EntryInput extends EntryBase {
|
|
60
60
|
/**
|
|
61
61
|
* Specifies the path of the module's build source.
|
|
62
62
|
*/
|
|
@@ -66,9 +66,9 @@ interface EntryInput extends Entry {
|
|
|
66
66
|
*
|
|
67
67
|
* @default undefined
|
|
68
68
|
*/
|
|
69
|
-
plugins?:
|
|
69
|
+
plugins?: PluginsOptions;
|
|
70
70
|
}
|
|
71
|
-
interface EntryTypes extends
|
|
71
|
+
interface EntryTypes extends EntryBase {
|
|
72
72
|
/**
|
|
73
73
|
* Specifies the path of the module's build source that contains only TS definitions.
|
|
74
74
|
*/
|
|
@@ -78,23 +78,106 @@ interface EntryTypes extends Entry {
|
|
|
78
78
|
*
|
|
79
79
|
* @default undefined
|
|
80
80
|
*/
|
|
81
|
-
plugins?: Pick<
|
|
81
|
+
plugins?: Pick<PluginsOptions, 'dts'>;
|
|
82
|
+
}
|
|
83
|
+
type EntryOptions = EntryInput | EntryTypes;
|
|
84
|
+
|
|
85
|
+
interface Options {
|
|
86
|
+
/**
|
|
87
|
+
* Specifies the bundle's entry points.
|
|
88
|
+
*
|
|
89
|
+
* It allows you to manually set all build entries and adjust options for each one individually.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* export default defineConfig({
|
|
95
|
+
* entries: [
|
|
96
|
+
* { input: './src/index.ts' }, // => './dist/index.mjs'
|
|
97
|
+
* { types: './src/types.ts' }, // => './dist/types.d.ts'
|
|
98
|
+
* // ...
|
|
99
|
+
* ]
|
|
100
|
+
* })
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
entries: EntryOptions[];
|
|
104
|
+
/**
|
|
105
|
+
* Specifies the output directory for production bundle.
|
|
106
|
+
*
|
|
107
|
+
* @default 'dist'
|
|
108
|
+
*/
|
|
109
|
+
outDir?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Specifies the module IDs, or regular expressions to match module IDs,
|
|
112
|
+
* that should remain external to the bundle.
|
|
113
|
+
*
|
|
114
|
+
* IDs and regexps from this option are applied globally to all entries.
|
|
115
|
+
*
|
|
116
|
+
* Also, it is possible to define externals individually per entry (`entry.externals`).
|
|
117
|
+
*
|
|
118
|
+
* @default [/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]
|
|
119
|
+
*/
|
|
120
|
+
externals?: (string | RegExp)[];
|
|
121
|
+
/**
|
|
122
|
+
* Provides a powerful hooking system to further expand bundling mode.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* export default defineConfig({
|
|
128
|
+
* hooks: {
|
|
129
|
+
* 'build:end': async (options, buildStats) => {
|
|
130
|
+
* // ...
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @default undefined
|
|
137
|
+
*/
|
|
138
|
+
hooks?: HooksOptions;
|
|
82
139
|
}
|
|
83
|
-
type EntriesOptions = EntryInput | EntryTypes;
|
|
84
140
|
|
|
85
141
|
interface BuildLogs {
|
|
86
142
|
level: LogLevel;
|
|
87
143
|
log: RollupLog;
|
|
88
144
|
}
|
|
89
145
|
interface BuildStats {
|
|
146
|
+
/**
|
|
147
|
+
* The root path of the project.
|
|
148
|
+
*/
|
|
90
149
|
cwd: string;
|
|
150
|
+
/**
|
|
151
|
+
* Final bundle size.
|
|
152
|
+
*/
|
|
91
153
|
size: number;
|
|
154
|
+
/**
|
|
155
|
+
* Total bundle build time.
|
|
156
|
+
*/
|
|
92
157
|
buildTime: number;
|
|
158
|
+
/**
|
|
159
|
+
* List of generated bundle modules.
|
|
160
|
+
*/
|
|
93
161
|
files: {
|
|
162
|
+
/**
|
|
163
|
+
* Module output path.
|
|
164
|
+
*/
|
|
94
165
|
path: string;
|
|
166
|
+
/**
|
|
167
|
+
* Module size.
|
|
168
|
+
*/
|
|
95
169
|
size: number;
|
|
170
|
+
/**
|
|
171
|
+
* Build time of individual module.
|
|
172
|
+
*/
|
|
96
173
|
buildTime: number;
|
|
174
|
+
/**
|
|
175
|
+
* Module format.
|
|
176
|
+
*/
|
|
97
177
|
format: string;
|
|
178
|
+
/**
|
|
179
|
+
* List of warnings from build plugins.
|
|
180
|
+
*/
|
|
98
181
|
logs: BuildLogs[];
|
|
99
182
|
}[];
|
|
100
183
|
}
|
|
@@ -102,55 +185,128 @@ interface BuildStats {
|
|
|
102
185
|
interface HooksOptions {
|
|
103
186
|
/**
|
|
104
187
|
* Called just before bundling started.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* export default defineConfig({
|
|
193
|
+
* hooks: {
|
|
194
|
+
* 'bundle:start': async (options) => {
|
|
195
|
+
* // ...
|
|
196
|
+
* }
|
|
197
|
+
* }
|
|
198
|
+
* })
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @default undefined
|
|
105
202
|
*/
|
|
106
203
|
'bundle:start'?: (options?: Options) => void | Promise<void>;
|
|
107
204
|
/**
|
|
108
205
|
* Called just before building started.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* export default defineConfig({
|
|
211
|
+
* hooks: {
|
|
212
|
+
* 'build:start': async (options, buildStats) => {
|
|
213
|
+
* // ...
|
|
214
|
+
* }
|
|
215
|
+
* }
|
|
216
|
+
* })
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @default undefined
|
|
109
220
|
*/
|
|
110
221
|
'build:start'?: (options?: Options, buildStats?: BuildStats) => void | Promise<void>;
|
|
111
222
|
/**
|
|
112
|
-
* Called
|
|
113
|
-
*/
|
|
114
|
-
'build:end'?: (options?: Options, buildStats?: BuildStats) => void | Promise<void>;
|
|
115
|
-
/**
|
|
116
|
-
* Called right after bundling is complete.
|
|
117
|
-
*/
|
|
118
|
-
'bundle:end'?: (options?: Options) => void | Promise<void>;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
interface Options {
|
|
122
|
-
/**
|
|
123
|
-
* Specifies the bundle's entry points.
|
|
223
|
+
* Called just before the initialization of the Rollup plugin.
|
|
124
224
|
*
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
entries: EntriesOptions[];
|
|
128
|
-
/**
|
|
129
|
-
* Specifies the output directory for production bundle.
|
|
225
|
+
* Provides the ability to add and manipulate custom plugins.
|
|
130
226
|
*
|
|
131
|
-
* @
|
|
227
|
+
* @example
|
|
228
|
+
*
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { plugin1, plugin2, plugin3 } from './plugins'
|
|
231
|
+
*
|
|
232
|
+
* export default defineConfig({
|
|
233
|
+
* hooks: {
|
|
234
|
+
* 'rollup:plugins': (plugins, entry) => {
|
|
235
|
+
* // adds a custom plugin before the default bundler plugins
|
|
236
|
+
* plugins.unshift(plugin1())
|
|
237
|
+
* // adds a custom plugin after the default bundler plugins
|
|
238
|
+
* plugins.push(plugin2())
|
|
239
|
+
* // adds a custom plugin for a specific entry only
|
|
240
|
+
* if (entry?.input?.includes('./src/index.ts')) {
|
|
241
|
+
* plugins.push(plugin3())
|
|
242
|
+
* }
|
|
243
|
+
* // returns the final list of plugins
|
|
244
|
+
* return plugins
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* })
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @default undefined
|
|
132
251
|
*/
|
|
133
|
-
|
|
252
|
+
'rollup:plugins'?: (plugins: Plugin[], entry?: Partial<EntryInput> & Partial<Omit<EntryTypes, 'plugins'>>) => Plugin[];
|
|
134
253
|
/**
|
|
135
|
-
*
|
|
136
|
-
* that should remain external to the bundle.
|
|
254
|
+
* Called right after building is complete.
|
|
137
255
|
*
|
|
138
|
-
*
|
|
256
|
+
* @example
|
|
139
257
|
*
|
|
140
|
-
*
|
|
258
|
+
* ```ts
|
|
259
|
+
* export default defineConfig({
|
|
260
|
+
* hooks: {
|
|
261
|
+
* 'build:end': async (options, buildStats) => {
|
|
262
|
+
* // ...
|
|
263
|
+
* }
|
|
264
|
+
* }
|
|
265
|
+
* })
|
|
266
|
+
* ```
|
|
141
267
|
*
|
|
142
|
-
* @default
|
|
268
|
+
* @default undefined
|
|
143
269
|
*/
|
|
144
|
-
|
|
270
|
+
'build:end'?: (options?: Options, buildStats?: BuildStats) => void | Promise<void>;
|
|
145
271
|
/**
|
|
146
|
-
*
|
|
272
|
+
* Called right after bundling is complete.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* export default defineConfig({
|
|
278
|
+
* hooks: {
|
|
279
|
+
* 'bundle:end': async (options) => {
|
|
280
|
+
* // ...
|
|
281
|
+
* }
|
|
282
|
+
* }
|
|
283
|
+
* })
|
|
284
|
+
* ```
|
|
147
285
|
*
|
|
148
286
|
* @default undefined
|
|
149
287
|
*/
|
|
150
|
-
|
|
288
|
+
'bundle:end'?: (options?: Options) => void | Promise<void>;
|
|
151
289
|
}
|
|
152
290
|
|
|
291
|
+
/**
|
|
292
|
+
* List of global defaults for externals.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
*
|
|
296
|
+
* ```ts
|
|
297
|
+
* import { externals } from '@hypernym/bundler'
|
|
298
|
+
*
|
|
299
|
+
* export default defineConfig({
|
|
300
|
+
* entries: [
|
|
301
|
+
* {
|
|
302
|
+
* input: './src/index.ts',
|
|
303
|
+
* externals: [...externals, 'id', /regexp/]
|
|
304
|
+
* },
|
|
305
|
+
* ]
|
|
306
|
+
* })
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
153
309
|
declare const externals: RegExp[];
|
|
154
310
|
declare function defineConfig(options: Options): Options;
|
|
155
311
|
|
|
156
|
-
export { defineConfig, externals };
|
|
312
|
+
export { type BuildLogs, type BuildStats, type EntryBase, type EntryInput, type EntryOptions, type EntryTypes, type HooksOptions, type Options, type PluginsOptions, defineConfig, externals };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypernym/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"author": "Hypernym Studio",
|
|
5
5
|
"description": "ESM & TS module bundler.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
"@hypernym/utils": "^2.1.0",
|
|
63
63
|
"@rollup/plugin-json": "^6.0.1",
|
|
64
64
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
65
|
-
"@rollup/plugin-replace": "^5.0.
|
|
66
|
-
"esbuild": "^0.19.
|
|
67
|
-
"rollup": "^4.1.
|
|
65
|
+
"@rollup/plugin-replace": "^5.0.4",
|
|
66
|
+
"esbuild": "^0.19.5",
|
|
67
|
+
"rollup": "^4.1.4",
|
|
68
68
|
"rollup-plugin-dts": "^6.1.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|