@hypernym/bundler 0.20.0 → 0.30.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 +38 -33
- package/dist/bin/{index.mjs → index.js} +11 -15
- package/dist/build/{index.mjs → index.js} +71 -129
- package/dist/{index.d.mts → index.d.ts} +33 -9
- package/dist/{index.mjs → index.js} +1 -1
- package/package.json +10 -10
- /package/dist/plugins/{index.d.mts → index.d.ts} +0 -0
- /package/dist/plugins/{index.mjs → index.js} +0 -0
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ export default defineConfig({
|
|
|
57
57
|
{ dts: './src/types/index.ts' },
|
|
58
58
|
{
|
|
59
59
|
input: './src/utils/index.ts',
|
|
60
|
-
output: './dist/utils/utils.min.
|
|
60
|
+
output: './dist/utils/utils.min.js',
|
|
61
61
|
minify: true,
|
|
62
62
|
},
|
|
63
63
|
// ...
|
|
@@ -105,32 +105,32 @@ npx hyperbundler --config hyper.config.ts
|
|
|
105
105
|
|
|
106
106
|
## Formats
|
|
107
107
|
|
|
108
|
-
During transformation, file formats are automatically resolved and in most cases
|
|
108
|
+
During transformation, file formats are automatically resolved, and in most cases, no additional configuration is required.
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
The default module environment for generated files is `esm`, which means output files will have a `.js` extension unless otherwise specified. For TypeScript declarations, the corresponding extension will be `.d.ts`.
|
|
111
111
|
|
|
112
|
-
Formats can also be explicitly specified for each entry, if
|
|
112
|
+
Formats can also be explicitly specified for each entry, if needed.
|
|
113
113
|
|
|
114
114
|
### Inputs
|
|
115
115
|
|
|
116
|
-
Default transformation
|
|
116
|
+
Default transformation behavior for all `chunk` entries:
|
|
117
117
|
|
|
118
|
-
- `./srcDir/file.js`
|
|
119
|
-
- `./srcDir/file.mjs`
|
|
120
|
-
- `./srcDir/file.cjs`
|
|
121
|
-
- `./srcDir/file.ts`
|
|
122
|
-
- `./srcDir/file.mts`
|
|
123
|
-
- `./srcDir/file.cts`
|
|
118
|
+
- `./srcDir/file.js` → `./outDir/file.js`
|
|
119
|
+
- `./srcDir/file.mjs` → `./outDir/file.js`
|
|
120
|
+
- `./srcDir/file.cjs` → `./outDir/file.cjs`
|
|
121
|
+
- `./srcDir/file.ts` → `./outDir/file.js`
|
|
122
|
+
- `./srcDir/file.mts` → `./outDir/file.js`
|
|
123
|
+
- `./srcDir/file.cts` → `./outDir/file.cjs`
|
|
124
124
|
|
|
125
125
|
### Declarations
|
|
126
126
|
|
|
127
|
-
Default transformation
|
|
127
|
+
Default transformation behavior for all `dts` entries:
|
|
128
128
|
|
|
129
|
-
- `./srcDir/file.ts`
|
|
129
|
+
- `./srcDir/file.ts` → `./outDir/file.d.ts`
|
|
130
130
|
|
|
131
131
|
## Options
|
|
132
132
|
|
|
133
|
-
All options
|
|
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.
|
|
134
134
|
|
|
135
135
|
### entries
|
|
136
136
|
|
|
@@ -147,8 +147,8 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
147
147
|
|
|
148
148
|
export default defineConfig({
|
|
149
149
|
entries: [
|
|
150
|
-
{ input: './src/index.ts' }, // outputs './dist/index.
|
|
151
|
-
{ dts: './src/types.ts' }, // outputs './dist/types.d.
|
|
150
|
+
{ input: './src/index.ts' }, // outputs './dist/index.js'
|
|
151
|
+
{ dts: './src/types.ts' }, // outputs './dist/types.d.ts'
|
|
152
152
|
// ...
|
|
153
153
|
],
|
|
154
154
|
})
|
|
@@ -165,7 +165,7 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
165
165
|
|
|
166
166
|
export default defineConfig({
|
|
167
167
|
entries: [
|
|
168
|
-
{ input: './src/index.ts' }, // outputs './dist/index.
|
|
168
|
+
{ input: './src/index.ts' }, // outputs './dist/index.js'
|
|
169
169
|
{
|
|
170
170
|
input: './src/index.ts',
|
|
171
171
|
output: './out/index.js', // outputs './out/index.js'
|
|
@@ -176,14 +176,14 @@ export default defineConfig({
|
|
|
176
176
|
|
|
177
177
|
### Entry Dts
|
|
178
178
|
|
|
179
|
-
Builds TypeScript `declaration` files (`.d.
|
|
179
|
+
Builds TypeScript `declaration` files (`.d.ts`) for production.
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
182
|
import { defineConfig } from '@hypernym/bundler'
|
|
183
183
|
|
|
184
184
|
export default defineConfig({
|
|
185
185
|
entries: [
|
|
186
|
-
{ dts: './src/types.ts' }, // outputs './dist/types.d.
|
|
186
|
+
{ dts: './src/types.ts' }, // outputs './dist/types.d.ts'
|
|
187
187
|
{
|
|
188
188
|
dts: './src/types.ts',
|
|
189
189
|
output: './out/types.d.ts', // outputs './out/types.d.ts'
|
|
@@ -247,7 +247,7 @@ export default defineConfig({
|
|
|
247
247
|
|
|
248
248
|
### outDir
|
|
249
249
|
|
|
250
|
-
- Type: `string`
|
|
250
|
+
- Type: `string | undefined`
|
|
251
251
|
- Default: `dist`
|
|
252
252
|
|
|
253
253
|
Specifies the output directory for production bundle.
|
|
@@ -258,14 +258,14 @@ Specifies the output directory for production bundle.
|
|
|
258
258
|
import { defineConfig } from '@hypernym/bundler'
|
|
259
259
|
|
|
260
260
|
export default defineConfig({
|
|
261
|
-
outDir: 'output',
|
|
261
|
+
outDir: './output',
|
|
262
262
|
})
|
|
263
263
|
```
|
|
264
264
|
|
|
265
265
|
### externals
|
|
266
266
|
|
|
267
|
-
- Type: `(string | RegExp)[]`
|
|
268
|
-
- Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
|
|
267
|
+
- Type: `(string | RegExp)[] | undefined`
|
|
268
|
+
- Default: `[/^node:/, /^@types/, /^@rollup/, /^@rolldown/, /^@hypernym/, /^rollup/, /^rolldown/, ...pkg.dependencies]`
|
|
269
269
|
|
|
270
270
|
Specifies the module IDs or regular expressions that match module IDs to be treated as external and excluded from the bundle.
|
|
271
271
|
|
|
@@ -296,10 +296,15 @@ export default defineConfig({
|
|
|
296
296
|
|
|
297
297
|
### minify
|
|
298
298
|
|
|
299
|
-
- Type: `boolean`
|
|
299
|
+
- Type: `boolean | 'dce-only' | MinifyOptions | undefined`
|
|
300
300
|
- Default: `undefined`
|
|
301
301
|
|
|
302
|
-
|
|
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.
|
|
303
308
|
|
|
304
309
|
```ts
|
|
305
310
|
// bundler.config.ts
|
|
@@ -339,7 +344,7 @@ List of lifecycle hooks that are called at various phases:
|
|
|
339
344
|
|
|
340
345
|
### bundle:start
|
|
341
346
|
|
|
342
|
-
- Type: `(options: Options) => void | Promise<void
|
|
347
|
+
- Type: `(options: Options) => void | Promise<void> | undefined`
|
|
343
348
|
- Default: `undefined`
|
|
344
349
|
|
|
345
350
|
Called at the beginning of bundling.
|
|
@@ -360,7 +365,7 @@ export default defineConfig({
|
|
|
360
365
|
|
|
361
366
|
### build:start
|
|
362
367
|
|
|
363
|
-
- Type: `(options: Options, stats: BuildStats) => void | Promise<void
|
|
368
|
+
- Type: `(options: Options, stats: BuildStats) => void | Promise<void> | undefined`
|
|
364
369
|
- Default: `undefined`
|
|
365
370
|
|
|
366
371
|
Called at the beginning of building.
|
|
@@ -381,7 +386,7 @@ export default defineConfig({
|
|
|
381
386
|
|
|
382
387
|
### build:entry:start
|
|
383
388
|
|
|
384
|
-
- Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void
|
|
389
|
+
- Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void> | undefined`
|
|
385
390
|
- Default: `undefined`
|
|
386
391
|
|
|
387
392
|
Called on each entry just before the build process.
|
|
@@ -405,7 +410,7 @@ export default defineConfig({
|
|
|
405
410
|
|
|
406
411
|
### build:entry:end
|
|
407
412
|
|
|
408
|
-
- Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void
|
|
413
|
+
- Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void> | undefined`
|
|
409
414
|
- Default: `undefined`
|
|
410
415
|
|
|
411
416
|
Called on each entry right after the build process is completed.
|
|
@@ -426,7 +431,7 @@ export default defineConfig({
|
|
|
426
431
|
|
|
427
432
|
### build:end
|
|
428
433
|
|
|
429
|
-
- Type: `(options: Options, stats: BuildStats) => void | Promise<void
|
|
434
|
+
- Type: `(options: Options, stats: BuildStats) => void | Promise<void> | undefined`
|
|
430
435
|
- Default: `undefined`
|
|
431
436
|
|
|
432
437
|
Called right after building is complete.
|
|
@@ -447,7 +452,7 @@ export default defineConfig({
|
|
|
447
452
|
|
|
448
453
|
### bundle:end
|
|
449
454
|
|
|
450
|
-
- Type: `(options: Options) => void | Promise<void
|
|
455
|
+
- Type: `(options: Options) => void | Promise<void> | undefined`
|
|
451
456
|
- Default: `undefined`
|
|
452
457
|
|
|
453
458
|
Called right after bundling is complete.
|
|
@@ -523,10 +528,10 @@ Specifies the path to the `bundler` custom config file.
|
|
|
523
528
|
|
|
524
529
|
```sh
|
|
525
530
|
# pnpm
|
|
526
|
-
pnpm hyperbundler --config hyper.config.
|
|
531
|
+
pnpm hyperbundler --config hyper.config.js
|
|
527
532
|
|
|
528
533
|
# npm
|
|
529
|
-
npx hyperbundler --config hyper.config.
|
|
534
|
+
npx hyperbundler --config hyper.config.js
|
|
530
535
|
```
|
|
531
536
|
|
|
532
537
|
### cwd
|
|
@@ -5,11 +5,11 @@ import { cyan, dim } from "@hypernym/colors";
|
|
|
5
5
|
import { isAbsolute, resolve } from "node:path";
|
|
6
6
|
import { exists, read, write } from "@hypernym/utils/fs";
|
|
7
7
|
import { build } from "rolldown";
|
|
8
|
-
import { build as build$1 } from "../build/index.
|
|
8
|
+
import { build as build$1 } from "../build/index.js";
|
|
9
9
|
|
|
10
10
|
//#region src/bin/meta.ts
|
|
11
11
|
const name = `Hyperbundler`;
|
|
12
|
-
const version = `0.
|
|
12
|
+
const version = `0.30.0`;
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/utils/logger.ts
|
|
@@ -105,8 +105,7 @@ const externals = [
|
|
|
105
105
|
//#region src/bin/loader.ts
|
|
106
106
|
async function getTSConfigPath(cwd$1, filePath = "tsconfig.json") {
|
|
107
107
|
const tsconfigPath = resolve(cwd$1, filePath);
|
|
108
|
-
|
|
109
|
-
if (tsconfigFile) return tsconfigPath;
|
|
108
|
+
if (await exists(tsconfigPath)) return tsconfigPath;
|
|
110
109
|
}
|
|
111
110
|
async function loadConfig(filePath, defaults) {
|
|
112
111
|
const cwd$1 = defaults.cwd;
|
|
@@ -114,18 +113,17 @@ async function loadConfig(filePath, defaults) {
|
|
|
114
113
|
input: resolve(cwd$1, filePath),
|
|
115
114
|
write: false,
|
|
116
115
|
external: (id) => !(isAbsolute(id) || /^(\.|@\/|~\/)/.test(id)),
|
|
117
|
-
|
|
116
|
+
tsconfig: defaults.tsconfig,
|
|
118
117
|
output: { format: "esm" }
|
|
119
118
|
});
|
|
120
|
-
const tempConfig = resolve(cwd$1, "node_modules/.hypernym/bundler/config.
|
|
119
|
+
const tempConfig = resolve(cwd$1, "node_modules/.hypernym/bundler/config.js");
|
|
121
120
|
await write(tempConfig, result.output[0].code);
|
|
122
121
|
const config = (await import(tempConfig)).default;
|
|
123
|
-
const options = {
|
|
124
|
-
...defaults,
|
|
125
|
-
...config
|
|
126
|
-
};
|
|
127
122
|
return {
|
|
128
|
-
options
|
|
123
|
+
options: {
|
|
124
|
+
...defaults,
|
|
125
|
+
...config
|
|
126
|
+
},
|
|
129
127
|
path: filePath
|
|
130
128
|
};
|
|
131
129
|
}
|
|
@@ -144,8 +142,7 @@ async function createConfigLoader(args) {
|
|
|
144
142
|
const warnMessage = `Missing required configuration. To start bundling, add the ${cyan(`'bundler.config.{js,mjs,ts,mts}'`)} file to the project's root.`;
|
|
145
143
|
if (args.config) {
|
|
146
144
|
const path = resolve(args.config);
|
|
147
|
-
|
|
148
|
-
if (isConfig) return await loadConfig(path, defaults);
|
|
145
|
+
if (await exists(path)) return await loadConfig(path, defaults);
|
|
149
146
|
else return logger.exit(warnMessage);
|
|
150
147
|
}
|
|
151
148
|
const configName = "bundler.config";
|
|
@@ -157,8 +154,7 @@ async function createConfigLoader(args) {
|
|
|
157
154
|
];
|
|
158
155
|
for (const ext of configExts) {
|
|
159
156
|
const path = resolve(cwdir, `${configName}${ext}`);
|
|
160
|
-
|
|
161
|
-
if (isConfig) return await loadConfig(path, defaults);
|
|
157
|
+
if (await exists(path)) return await loadConfig(path, defaults);
|
|
162
158
|
}
|
|
163
159
|
return logger.exit(warnMessage);
|
|
164
160
|
}
|
|
@@ -6,7 +6,7 @@ import { isUndefined } from "@hypernym/utils";
|
|
|
6
6
|
import { copy, readdir, write } from "@hypernym/utils/fs";
|
|
7
7
|
import { rolldown } from "rolldown";
|
|
8
8
|
import { dts } from "rolldown-plugin-dts";
|
|
9
|
-
import { outputPaths } from "../plugins/index.
|
|
9
|
+
import { outputPaths } from "../plugins/index.js";
|
|
10
10
|
|
|
11
11
|
//#region src/bin/meta.ts
|
|
12
12
|
const name = `Hyperbundler`;
|
|
@@ -86,12 +86,17 @@ function getOutputPath(outDir, input, { extension = "auto" } = {}) {
|
|
|
86
86
|
];
|
|
87
87
|
const legacy = [".cjs", ".cts"];
|
|
88
88
|
let newExt = "";
|
|
89
|
-
if (esm.includes(ext)) newExt = extension === "dts" ? ".d.
|
|
89
|
+
if (esm.includes(ext)) newExt = extension === "dts" ? ".d.ts" : ".js";
|
|
90
90
|
else if (legacy.includes(ext)) newExt = extension === "dts" ? ".d.cts" : ".cjs";
|
|
91
91
|
if (newExt) output = `${output.slice(0, -ext.length)}${newExt}`;
|
|
92
92
|
}
|
|
93
93
|
return outDir.startsWith("./") || outDir.startsWith("../") ? output : `./${output}`;
|
|
94
94
|
}
|
|
95
|
+
function parseOutputPath(path) {
|
|
96
|
+
if (!path) return;
|
|
97
|
+
if (path.startsWith("./")) return path;
|
|
98
|
+
else return `./${path}`;
|
|
99
|
+
}
|
|
95
100
|
|
|
96
101
|
//#endregion
|
|
97
102
|
//#region src/bin/build.ts
|
|
@@ -102,14 +107,13 @@ function logEntryStats(stats) {
|
|
|
102
107
|
let format = stats.format;
|
|
103
108
|
if (format === "commonjs") format = "cjs";
|
|
104
109
|
if (format === "es" || format === "module") format = "esm";
|
|
105
|
-
const
|
|
106
|
-
const output = pathDim + base;
|
|
110
|
+
const output = dim(path) + base;
|
|
107
111
|
const outputLength = output.length + 2;
|
|
108
|
-
cl$1("
|
|
112
|
+
cl$1(dim("+"), format.padEnd(5), output.padEnd(outputLength), dim(`[${formatBytes(stats.size)}, ${formatMs(stats.buildTime)}]`));
|
|
109
113
|
if (stats.logs) for (const log of stats.logs) cl$1("!", log.level.padEnd(5), output.padEnd(outputLength), dim(log.log.message));
|
|
110
114
|
}
|
|
111
115
|
async function build(options) {
|
|
112
|
-
const { cwd: cwdir = cwd(), outDir = "dist", tsconfig, hooks } = options;
|
|
116
|
+
const { cwd: cwdir = cwd(), outDir = "dist", entries, externals, tsconfig, hooks, minify } = options;
|
|
113
117
|
let start = 0;
|
|
114
118
|
const buildStats = {
|
|
115
119
|
cwd: cwdir,
|
|
@@ -118,164 +122,100 @@ async function build(options) {
|
|
|
118
122
|
files: []
|
|
119
123
|
};
|
|
120
124
|
await hooks?.["build:start"]?.(options, buildStats);
|
|
121
|
-
if (
|
|
125
|
+
if (entries) {
|
|
122
126
|
start = Date.now();
|
|
123
|
-
for (const entry of
|
|
127
|
+
for (const entry of entries) {
|
|
124
128
|
const entryStart = Date.now();
|
|
125
|
-
if (entry.input) {
|
|
129
|
+
if (entry.input || entry.dts) {
|
|
126
130
|
const buildLogs = [];
|
|
127
|
-
const
|
|
131
|
+
const isChunk = !isUndefined(entry.input);
|
|
132
|
+
const outputRawPath = parseOutputPath(entry.output) || getOutputPath(outDir, entry.input || entry.dts, { extension: isChunk ? "auto" : "dts" });
|
|
133
|
+
const outputResolvePath = resolve(cwdir, outputRawPath);
|
|
128
134
|
let format = entry.format || "esm";
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
};
|
|
138
|
-
const input = resolve(cwdir, _entry.input);
|
|
139
|
-
const output = resolve(cwdir, _entry.output);
|
|
140
|
-
const entryStats = {
|
|
141
|
-
cwd: cwdir,
|
|
142
|
-
path: _entry.output,
|
|
143
|
-
size: 0,
|
|
144
|
-
buildTime: entryStart,
|
|
145
|
-
format,
|
|
146
|
-
logs: buildLogs
|
|
147
|
-
};
|
|
148
|
-
await hooks?.["build:entry:start"]?.(_entry, entryStats);
|
|
149
|
-
const bundle = await rolldown({
|
|
150
|
-
input,
|
|
151
|
-
external: _entry.externals,
|
|
152
|
-
plugins: _entry.plugins,
|
|
135
|
+
if (outputRawPath.endsWith(".cjs")) format = "cjs";
|
|
136
|
+
const entryInput = {
|
|
137
|
+
input: resolve(cwdir, entry.input || entry.dts),
|
|
138
|
+
external: entry.externals || externals,
|
|
139
|
+
plugins: isChunk ? entry.plugins : entry.plugins || [dts({
|
|
140
|
+
...entry.dtsPlugin,
|
|
141
|
+
emitDtsOnly: true
|
|
142
|
+
})],
|
|
153
143
|
onLog: (level, log, handler) => {
|
|
154
|
-
if (
|
|
144
|
+
if (entry.onLog) entry.onLog(level, log, handler, buildLogs);
|
|
155
145
|
else buildLogs.push({
|
|
156
146
|
level,
|
|
157
147
|
log
|
|
158
148
|
});
|
|
159
149
|
},
|
|
160
|
-
resolve:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
entryStats.logs = buildLogs;
|
|
183
|
-
buildStats.files.push(entryStats);
|
|
184
|
-
buildStats.size = buildStats.size + stats.size;
|
|
185
|
-
logEntryStats(entryStats);
|
|
186
|
-
await hooks?.["build:entry:end"]?.(_entry, entryStats);
|
|
187
|
-
}
|
|
188
|
-
if (entry.dts) {
|
|
189
|
-
const buildLogs = [];
|
|
190
|
-
const _entry = {
|
|
191
|
-
...entry,
|
|
192
|
-
output: entry.output || getOutputPath(outDir, entry.dts, { extension: "dts" }),
|
|
193
|
-
externals: entry.externals || options.externals,
|
|
194
|
-
format: entry.format || "esm",
|
|
195
|
-
plugins: [dts({
|
|
196
|
-
...entry.dtsPlugin,
|
|
197
|
-
emitDtsOnly: true
|
|
198
|
-
})]
|
|
150
|
+
resolve: entry.resolve,
|
|
151
|
+
define: entry.define,
|
|
152
|
+
inject: entry.inject,
|
|
153
|
+
tsconfig: entry.tsconfig || tsconfig
|
|
154
|
+
};
|
|
155
|
+
const entryOutput = {
|
|
156
|
+
file: isChunk ? outputResolvePath : void 0,
|
|
157
|
+
minify: isChunk ? !isUndefined(entry.minify) ? entry.minify : minify : void 0,
|
|
158
|
+
format,
|
|
159
|
+
banner: entry.banner,
|
|
160
|
+
footer: entry.footer,
|
|
161
|
+
intro: entry.intro,
|
|
162
|
+
outro: entry.outro,
|
|
163
|
+
name: entry.name,
|
|
164
|
+
globals: entry.globals,
|
|
165
|
+
extend: entry.extend,
|
|
166
|
+
plugins: entry.paths ? [outputPaths(entry.paths)] : void 0
|
|
167
|
+
};
|
|
168
|
+
const entryOptions = {
|
|
169
|
+
...entryInput,
|
|
170
|
+
...entryOutput,
|
|
171
|
+
externals: entryInput.external
|
|
199
172
|
};
|
|
200
|
-
const input = resolve(cwdir, _entry.dts);
|
|
201
|
-
const output = resolve(cwdir, _entry.output);
|
|
202
173
|
const entryStats = {
|
|
203
174
|
cwd: cwdir,
|
|
204
|
-
path:
|
|
175
|
+
path: outputRawPath,
|
|
205
176
|
size: 0,
|
|
206
177
|
buildTime: entryStart,
|
|
207
|
-
format: "dts",
|
|
178
|
+
format: isChunk ? format : "dts",
|
|
208
179
|
logs: buildLogs
|
|
209
180
|
};
|
|
210
|
-
await hooks?.["build:entry:start"]?.(
|
|
211
|
-
const bundle = await rolldown(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
level,
|
|
219
|
-
log
|
|
220
|
-
});
|
|
221
|
-
},
|
|
222
|
-
resolve: {
|
|
223
|
-
..._entry.resolve,
|
|
224
|
-
tsconfigFilename: _entry.resolve?.tsconfigFilename || tsconfig
|
|
225
|
-
},
|
|
226
|
-
define: _entry.define
|
|
227
|
-
});
|
|
228
|
-
const generated = await bundle.generate({
|
|
229
|
-
format: _entry.format,
|
|
230
|
-
banner: _entry.banner,
|
|
231
|
-
footer: _entry.footer,
|
|
232
|
-
intro: _entry.intro,
|
|
233
|
-
outro: _entry.outro,
|
|
234
|
-
name: _entry.name,
|
|
235
|
-
globals: _entry.globals,
|
|
236
|
-
extend: _entry.extend,
|
|
237
|
-
plugins: _entry.paths ? [outputPaths(_entry.paths)] : void 0
|
|
238
|
-
});
|
|
239
|
-
await write(_entry.output, generated.output[0].code);
|
|
240
|
-
const stats = await stat(output);
|
|
181
|
+
await hooks?.["build:entry:start"]?.(entryOptions, entryStats);
|
|
182
|
+
const bundle = await rolldown(entryInput);
|
|
183
|
+
if (isChunk) await bundle.write(entryOutput);
|
|
184
|
+
else {
|
|
185
|
+
const generated = await bundle.generate(entryOutput);
|
|
186
|
+
await write(outputResolvePath, generated.output[0].code);
|
|
187
|
+
}
|
|
188
|
+
const stats = await stat(outputResolvePath);
|
|
241
189
|
entryStats.size = stats.size;
|
|
242
190
|
entryStats.buildTime = Date.now() - entryStart;
|
|
243
191
|
entryStats.logs = buildLogs;
|
|
244
192
|
buildStats.files.push(entryStats);
|
|
245
193
|
buildStats.size = buildStats.size + stats.size;
|
|
246
194
|
logEntryStats(entryStats);
|
|
247
|
-
await hooks?.["build:entry:end"]?.(
|
|
195
|
+
await hooks?.["build:entry:end"]?.(entryOptions, entryStats);
|
|
248
196
|
}
|
|
249
197
|
if (entry.copy) {
|
|
250
|
-
const
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
};
|
|
255
|
-
const input = resolve(cwdir, _entry.input);
|
|
256
|
-
const output = resolve(cwdir, _entry.output);
|
|
257
|
-
await copy(input, output, {
|
|
198
|
+
const inputResolvePath = resolve(cwdir, entry.copy);
|
|
199
|
+
const outputRawPath = parseOutputPath(entry.output) || getOutputPath(outDir, entry.copy, { extension: "original" });
|
|
200
|
+
const outputResolvePath = resolve(cwdir, outputRawPath);
|
|
201
|
+
await copy(inputResolvePath, outputResolvePath, {
|
|
258
202
|
recursive: entry.recursive || true,
|
|
259
203
|
filter: entry.filter
|
|
260
204
|
}).catch(error);
|
|
261
|
-
const stats = await stat(
|
|
205
|
+
const stats = await stat(outputResolvePath);
|
|
262
206
|
let totalSize = 0;
|
|
263
207
|
if (!stats.isDirectory()) totalSize = stats.size;
|
|
264
208
|
else {
|
|
265
|
-
const files = await readdir(
|
|
209
|
+
const files = await readdir(outputResolvePath);
|
|
266
210
|
for (const file of files) {
|
|
267
|
-
const filePath = resolve(
|
|
211
|
+
const filePath = resolve(outputResolvePath, file);
|
|
268
212
|
const fileStat = await stat(filePath);
|
|
269
213
|
totalSize = totalSize + fileStat.size;
|
|
270
214
|
}
|
|
271
215
|
}
|
|
272
|
-
const parseOutput = (path) => {
|
|
273
|
-
if (path.startsWith("./")) return path;
|
|
274
|
-
else return `./${path}`;
|
|
275
|
-
};
|
|
276
216
|
const entryStats = {
|
|
277
217
|
cwd: cwdir,
|
|
278
|
-
path:
|
|
218
|
+
path: outputRawPath,
|
|
279
219
|
size: totalSize,
|
|
280
220
|
buildTime: Date.now() - entryStart,
|
|
281
221
|
format: "copy",
|
|
@@ -286,11 +226,13 @@ async function build(options) {
|
|
|
286
226
|
logEntryStats(entryStats);
|
|
287
227
|
}
|
|
288
228
|
if (entry.template && entry.output) {
|
|
289
|
-
|
|
290
|
-
const
|
|
229
|
+
const outputRawPath = parseOutputPath(entry.output);
|
|
230
|
+
const outputResolvePath = resolve(cwdir, outputRawPath);
|
|
231
|
+
await write(outputResolvePath, entry.template);
|
|
232
|
+
const stats = await stat(outputResolvePath);
|
|
291
233
|
const entryStats = {
|
|
292
234
|
cwd: cwdir,
|
|
293
|
-
path:
|
|
235
|
+
path: outputRawPath,
|
|
294
236
|
size: stats.size,
|
|
295
237
|
buildTime: Date.now() - entryStart,
|
|
296
238
|
format: "tmp",
|
|
@@ -138,12 +138,26 @@ interface EntryBase {
|
|
|
138
138
|
* @default undefined
|
|
139
139
|
*/
|
|
140
140
|
define?: InputOptions['define'];
|
|
141
|
+
/**
|
|
142
|
+
* Specifies Rolldown `inject` options.
|
|
143
|
+
*
|
|
144
|
+
* @default undefined
|
|
145
|
+
*/
|
|
146
|
+
inject?: InputOptions['inject'];
|
|
141
147
|
/**
|
|
142
148
|
* Specifies Rolldown plugins.
|
|
143
149
|
*
|
|
144
150
|
* @default undefined
|
|
145
151
|
*/
|
|
146
152
|
plugins?: RolldownPluginOption;
|
|
153
|
+
/**
|
|
154
|
+
* Specifies the path to the `tsconfig` file.
|
|
155
|
+
*
|
|
156
|
+
* By default, if the file `tsconfig.json` exists in the project root, it will be used as the default config file.
|
|
157
|
+
*
|
|
158
|
+
* @default undefined
|
|
159
|
+
*/
|
|
160
|
+
tsconfig?: InputOptions['tsconfig'];
|
|
147
161
|
}
|
|
148
162
|
interface EntryChunk extends EntryBase {
|
|
149
163
|
/**
|
|
@@ -154,7 +168,7 @@ interface EntryChunk extends EntryBase {
|
|
|
154
168
|
* ```ts
|
|
155
169
|
* export default defineConfig({
|
|
156
170
|
* entries: [
|
|
157
|
-
* { input: './src/index.ts' }, // outputs './dist/index.
|
|
171
|
+
* { input: './src/index.ts' }, // outputs './dist/index.js'
|
|
158
172
|
* ]
|
|
159
173
|
* })
|
|
160
174
|
* ```
|
|
@@ -202,11 +216,16 @@ interface EntryChunk extends EntryBase {
|
|
|
202
216
|
*/
|
|
203
217
|
extend?: OutputOptions['extend'];
|
|
204
218
|
/**
|
|
205
|
-
*
|
|
219
|
+
* Controls code minification.
|
|
220
|
+
*
|
|
221
|
+
* - `true`: Enable full minification including code compression and dead code elimination.
|
|
222
|
+
* - `false`: Disable minification (default).
|
|
223
|
+
* - `'dce-only'`: Only perform dead code elimination without code compression.
|
|
224
|
+
* - `MinifyOptions`: Fine-grained control over minification settings.
|
|
206
225
|
*
|
|
207
226
|
* @default undefined
|
|
208
227
|
*/
|
|
209
|
-
minify?:
|
|
228
|
+
minify?: OutputOptions['minify'];
|
|
210
229
|
dts?: never;
|
|
211
230
|
dtsPlugin?: never;
|
|
212
231
|
copy?: never;
|
|
@@ -223,7 +242,7 @@ interface EntryDts extends EntryBase {
|
|
|
223
242
|
* ```ts
|
|
224
243
|
* export default defineConfig({
|
|
225
244
|
* entries: [
|
|
226
|
-
* { dts: './src/types.ts' }, // outputs './dist/types.d.
|
|
245
|
+
* { dts: './src/types.ts' }, // outputs './dist/types.d.ts'
|
|
227
246
|
* ]
|
|
228
247
|
* })
|
|
229
248
|
* ```
|
|
@@ -372,8 +391,8 @@ interface Options {
|
|
|
372
391
|
* ```ts
|
|
373
392
|
* export default defineConfig({
|
|
374
393
|
* entries: [
|
|
375
|
-
* { input: './src/index.ts' }, // outputs './dist/index.
|
|
376
|
-
* { dts: './src/types.ts' }, // outputs './dist/types.d.
|
|
394
|
+
* { input: './src/index.ts' }, // outputs './dist/index.js'
|
|
395
|
+
* { dts: './src/types.ts' }, // outputs './dist/types.d.ts'
|
|
377
396
|
* // ...
|
|
378
397
|
* ]
|
|
379
398
|
* })
|
|
@@ -387,7 +406,7 @@ interface Options {
|
|
|
387
406
|
*
|
|
388
407
|
* ```ts
|
|
389
408
|
* export default defineConfig({
|
|
390
|
-
* outDir: 'output',
|
|
409
|
+
* outDir: './output',
|
|
391
410
|
* })
|
|
392
411
|
* ```
|
|
393
412
|
*
|
|
@@ -432,7 +451,12 @@ interface Options {
|
|
|
432
451
|
*/
|
|
433
452
|
hooks?: HooksOptions;
|
|
434
453
|
/**
|
|
435
|
-
*
|
|
454
|
+
* Controls code minification for all `chunk` entries.
|
|
455
|
+
*
|
|
456
|
+
* - `true`: Enable full minification including code compression and dead code elimination.
|
|
457
|
+
* - `false`: Disable minification (default).
|
|
458
|
+
* - `'dce-only'`: Only perform dead code elimination without code compression.
|
|
459
|
+
* - `MinifyOptions`: Fine-grained control over minification settings.
|
|
436
460
|
*
|
|
437
461
|
* @example
|
|
438
462
|
*
|
|
@@ -457,7 +481,7 @@ interface Options {
|
|
|
457
481
|
*
|
|
458
482
|
* @default undefined
|
|
459
483
|
*/
|
|
460
|
-
minify?:
|
|
484
|
+
minify?: OutputOptions['minify'];
|
|
461
485
|
/**
|
|
462
486
|
* Specifies the path to the project root (current working directory).
|
|
463
487
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypernym/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"author": "Hypernym Studio",
|
|
5
5
|
"description": "ESM & TS module bundler.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"types": "./dist/index.d.
|
|
17
|
-
"import": "./dist/index.
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
18
|
},
|
|
19
19
|
"./plugins": {
|
|
20
|
-
"types": "./dist/plugins/index.d.
|
|
21
|
-
"import": "./dist/plugins/index.
|
|
20
|
+
"types": "./dist/plugins/index.d.ts",
|
|
21
|
+
"import": "./dist/plugins/index.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dts"
|
|
41
41
|
],
|
|
42
42
|
"bin": {
|
|
43
|
-
"hyperbundler": "./dist/bin/index.
|
|
43
|
+
"hyperbundler": "./dist/bin/index.js"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@types/node": ">=20.0.0",
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
"@hypernym/args": "^0.3.3",
|
|
59
59
|
"@hypernym/colors": "^1.0.5",
|
|
60
60
|
"@hypernym/utils": "^3.4.5",
|
|
61
|
-
"rolldown": "1.0.0-beta.
|
|
62
|
-
"rolldown-plugin-dts": "^0.
|
|
61
|
+
"rolldown": "^1.0.0-beta.37",
|
|
62
|
+
"rolldown-plugin-dts": "^0.16.5"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@hypernym/eslint-config": "^3.6.3",
|
|
66
66
|
"@hypernym/prettier-config": "^3.2.6",
|
|
67
67
|
"@hypernym/tsconfig": "^2.6.2",
|
|
68
|
-
"@types/node": "^24.
|
|
69
|
-
"eslint": "^9.
|
|
68
|
+
"@types/node": "^24.4.0",
|
|
69
|
+
"eslint": "^9.35.0",
|
|
70
70
|
"prettier": "^3.6.2",
|
|
71
71
|
"typescript": "^5.9.2"
|
|
72
72
|
},
|
|
File without changes
|
|
File without changes
|