bunup 0.8.12 → 0.8.13
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/cli.js +176 -51
- package/dist/index.cjs +145 -32
- package/dist/index.js +145 -32
- package/dist/plugins.cjs +64 -77
- package/dist/plugins.d.cts +6 -18
- package/dist/plugins.d.ts +6 -18
- package/dist/plugins.js +64 -77
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -216,6 +216,11 @@ class Logger {
|
|
|
216
216
|
});
|
|
217
217
|
this.output(formattedMessage, options, console.error);
|
|
218
218
|
}
|
|
219
|
+
space() {
|
|
220
|
+
if (silent)
|
|
221
|
+
return;
|
|
222
|
+
console.log("");
|
|
223
|
+
}
|
|
219
224
|
getProgressFgColor(label) {
|
|
220
225
|
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
221
226
|
if (label.includes(key))
|
|
@@ -244,6 +249,41 @@ class Logger {
|
|
|
244
249
|
this.output(formattedMessage, options);
|
|
245
250
|
}
|
|
246
251
|
}
|
|
252
|
+
function logTable(columns, data, footer) {
|
|
253
|
+
if (silent)
|
|
254
|
+
return;
|
|
255
|
+
const widths = {};
|
|
256
|
+
for (const col of columns) {
|
|
257
|
+
const headerLength = col.header.length;
|
|
258
|
+
const dataLengths = data.map((row) => row[col.header]?.length || 0);
|
|
259
|
+
const footerLength = footer ? footer[col.header]?.length || 0 : 0;
|
|
260
|
+
widths[col.header] = Math.max(headerLength, ...dataLengths, footerLength);
|
|
261
|
+
}
|
|
262
|
+
const pad = (str, width, align) => {
|
|
263
|
+
return align === "left" ? str.padEnd(width) : str.padStart(width);
|
|
264
|
+
};
|
|
265
|
+
const headerRow = columns.map((col) => pad(col.header, widths[col.header], col.align)).join(import_picocolors.default.gray(" | "));
|
|
266
|
+
console.log(import_picocolors.default.gray(headerRow));
|
|
267
|
+
const separator = columns.map((col) => "-".repeat(widths[col.header])).join(" | ");
|
|
268
|
+
console.log(import_picocolors.default.gray(separator));
|
|
269
|
+
for (const row of data) {
|
|
270
|
+
const rowStr = columns.map((col) => {
|
|
271
|
+
const value = row[col.header] || "";
|
|
272
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
273
|
+
return col.color ? col.color(padded) : padded;
|
|
274
|
+
}).join(import_picocolors.default.gray(" | "));
|
|
275
|
+
console.log(rowStr);
|
|
276
|
+
}
|
|
277
|
+
console.log(import_picocolors.default.gray(separator));
|
|
278
|
+
if (footer) {
|
|
279
|
+
const footerRow = columns.map((col) => {
|
|
280
|
+
const value = footer[col.header] || "";
|
|
281
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
282
|
+
return padded;
|
|
283
|
+
}).join(import_picocolors.default.gray(" | "));
|
|
284
|
+
console.log(footerRow);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
247
287
|
var import_picocolors, silent = false, logger;
|
|
248
288
|
var init_logger = __esm(() => {
|
|
249
289
|
import_picocolors = __toESM(require_picocolors(), 1);
|
|
@@ -393,6 +433,15 @@ function getPackageDeps(packageJson) {
|
|
|
393
433
|
...Object.keys(packageJson.peerDependencies || {})
|
|
394
434
|
]));
|
|
395
435
|
}
|
|
436
|
+
function formatFileSize(bytes) {
|
|
437
|
+
if (bytes === 0)
|
|
438
|
+
return "0 B";
|
|
439
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
440
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
441
|
+
if (i === 0)
|
|
442
|
+
return `${bytes} ${units[i]}`;
|
|
443
|
+
return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
|
|
444
|
+
}
|
|
396
445
|
function getShortFilePath(filePath, maxLength = 3) {
|
|
397
446
|
const fileParts = filePath.split("/");
|
|
398
447
|
const shortPath = fileParts.slice(-maxLength).join("/");
|
|
@@ -448,20 +497,20 @@ function displayBunupGradientArt() {
|
|
|
448
497
|
`.trim();
|
|
449
498
|
const lines = art.split(`
|
|
450
499
|
`);
|
|
451
|
-
|
|
500
|
+
logger.space();
|
|
452
501
|
for (const line of lines) {
|
|
453
|
-
|
|
502
|
+
logger.output(import_picocolors7.default.cyan(line));
|
|
454
503
|
}
|
|
455
|
-
|
|
504
|
+
logger.space();
|
|
456
505
|
}
|
|
457
506
|
async function newProject() {
|
|
458
507
|
displayBunupGradientArt();
|
|
459
|
-
intro(
|
|
508
|
+
intro(import_picocolors7.default.bgCyan(import_picocolors7.default.black(" Scaffold a new project with Bunup ")));
|
|
460
509
|
const selectedTemplateDir = await select({
|
|
461
510
|
message: "Select a template",
|
|
462
511
|
options: TEMPLATES.map((template2) => ({
|
|
463
512
|
value: template2.dir,
|
|
464
|
-
label:
|
|
513
|
+
label: import_picocolors7.default.blue(template2.name)
|
|
465
514
|
}))
|
|
466
515
|
});
|
|
467
516
|
const template = TEMPLATES.find((t) => t.dir === selectedTemplateDir);
|
|
@@ -545,23 +594,24 @@ async function newProject() {
|
|
|
545
594
|
}
|
|
546
595
|
]);
|
|
547
596
|
outro(`
|
|
548
|
-
${
|
|
597
|
+
${import_picocolors7.default.green("\u2728 Project scaffolded successfully! \u2728")}
|
|
549
598
|
|
|
550
|
-
${
|
|
599
|
+
${import_picocolors7.default.bold("Ready to launch your awesome new project?")}
|
|
551
600
|
|
|
552
|
-
${
|
|
553
|
-
${
|
|
554
|
-
${
|
|
601
|
+
${import_picocolors7.default.cyan("cd")} ${projectName}
|
|
602
|
+
${import_picocolors7.default.cyan("bun install")}
|
|
603
|
+
${import_picocolors7.default.cyan("bun run dev")}
|
|
555
604
|
|
|
556
|
-
${
|
|
605
|
+
${import_picocolors7.default.yellow("Happy coding!")} \uD83D\uDE80
|
|
557
606
|
`);
|
|
558
607
|
}
|
|
559
608
|
function getProjectPath(projectName) {
|
|
560
609
|
return path5.join(process.cwd(), projectName);
|
|
561
610
|
}
|
|
562
|
-
var
|
|
611
|
+
var import_picocolors7, TEMPLATE_OWNER = "arshad-yaseen", TEMPLATE_REPO = "bunup-new", GITHUB_USERNAME_PLACEHOLDER = "username", GITHUB_REPO_PLACEHOLDER = "repo-name", MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER = "package-1", MONOREPO_PACKAGES_DIR = "packages", TEMPLATES;
|
|
563
612
|
var init_new = __esm(() => {
|
|
564
|
-
|
|
613
|
+
import_picocolors7 = __toESM(require_picocolors(), 1);
|
|
614
|
+
init_logger();
|
|
565
615
|
init_utils();
|
|
566
616
|
TEMPLATES = [
|
|
567
617
|
{
|
|
@@ -581,7 +631,7 @@ var init_new = __esm(() => {
|
|
|
581
631
|
// src/cli/index.ts
|
|
582
632
|
import { exec } from "tinyexec";
|
|
583
633
|
// package.json
|
|
584
|
-
var version = "0.8.
|
|
634
|
+
var version = "0.8.13";
|
|
585
635
|
|
|
586
636
|
// src/cli/index.ts
|
|
587
637
|
init_errors();
|
|
@@ -812,7 +862,7 @@ function parseCliOptions(argv) {
|
|
|
812
862
|
}
|
|
813
863
|
|
|
814
864
|
// src/cli/index.ts
|
|
815
|
-
var
|
|
865
|
+
var import_picocolors8 = __toESM(require_picocolors(), 1);
|
|
816
866
|
import { loadConfig as loadConfig2 } from "coffi";
|
|
817
867
|
|
|
818
868
|
// src/build.ts
|
|
@@ -886,6 +936,109 @@ async function loadPackageJson(cwd) {
|
|
|
886
936
|
// src/build.ts
|
|
887
937
|
init_logger();
|
|
888
938
|
|
|
939
|
+
// src/constants/re.ts
|
|
940
|
+
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
941
|
+
var TS_RE = /\.(ts|tsx|mts|cts)$/;
|
|
942
|
+
var DTS_RE = /\.(d\.(ts|mts|cts))$/;
|
|
943
|
+
var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
|
|
944
|
+
var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
|
|
945
|
+
// src/plugins/built-in/productivity/exports.ts
|
|
946
|
+
init_logger();
|
|
947
|
+
init_utils();
|
|
948
|
+
// src/plugins/built-in/css/inject-styles.ts
|
|
949
|
+
init_logger();
|
|
950
|
+
|
|
951
|
+
// src/plugins/utils.ts
|
|
952
|
+
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
953
|
+
init_errors();
|
|
954
|
+
function filterBunupBunPlugins(plugins) {
|
|
955
|
+
if (!plugins)
|
|
956
|
+
return [];
|
|
957
|
+
return plugins.filter((p) => p.type === "bun");
|
|
958
|
+
}
|
|
959
|
+
function filterBunupPlugins(plugins) {
|
|
960
|
+
if (!plugins)
|
|
961
|
+
return [];
|
|
962
|
+
return plugins.filter((p) => p.type === "bunup");
|
|
963
|
+
}
|
|
964
|
+
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
965
|
+
if (!bunupPlugins)
|
|
966
|
+
return;
|
|
967
|
+
for (const plugin of bunupPlugins) {
|
|
968
|
+
if (plugin.hooks.onBuildStart) {
|
|
969
|
+
await plugin.hooks.onBuildStart(options);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
974
|
+
if (!bunupPlugins)
|
|
975
|
+
return;
|
|
976
|
+
for (const plugin of bunupPlugins) {
|
|
977
|
+
if (plugin.hooks.onBuildDone) {
|
|
978
|
+
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
// src/plugins/built-in/productivity/copy.ts
|
|
983
|
+
init_utils();
|
|
984
|
+
// src/plugins/internal/report.ts
|
|
985
|
+
var import_picocolors5 = __toESM(require_picocolors(), 1);
|
|
986
|
+
init_logger();
|
|
987
|
+
init_logger();
|
|
988
|
+
init_utils();
|
|
989
|
+
function report() {
|
|
990
|
+
return {
|
|
991
|
+
type: "bunup",
|
|
992
|
+
name: "report",
|
|
993
|
+
hooks: {
|
|
994
|
+
onBuildDone: async ({ options, output }) => {
|
|
995
|
+
if (options.watch)
|
|
996
|
+
return;
|
|
997
|
+
const files = await Promise.all(output.files.map(async (file) => {
|
|
998
|
+
const name = file.relativePathToRootDir;
|
|
999
|
+
const size = Bun.file(file.fullPath).size;
|
|
1000
|
+
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
1001
|
+
const formattedGzipSize = formatFileSize(gzipSize);
|
|
1002
|
+
return {
|
|
1003
|
+
name,
|
|
1004
|
+
size,
|
|
1005
|
+
formattedSize: formatFileSize(size),
|
|
1006
|
+
gzipSize,
|
|
1007
|
+
formattedGzipSize
|
|
1008
|
+
};
|
|
1009
|
+
}));
|
|
1010
|
+
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
1011
|
+
const formattedTotalSize = formatFileSize(totalSize);
|
|
1012
|
+
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
1013
|
+
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
1014
|
+
const columns = [
|
|
1015
|
+
{ header: "File", align: "left", color: import_picocolors5.default.blue },
|
|
1016
|
+
{ header: "Size", align: "right", color: import_picocolors5.default.green },
|
|
1017
|
+
{
|
|
1018
|
+
header: "Gzip",
|
|
1019
|
+
align: "right",
|
|
1020
|
+
color: import_picocolors5.default.magenta
|
|
1021
|
+
}
|
|
1022
|
+
];
|
|
1023
|
+
const data = files.map((file) => {
|
|
1024
|
+
return {
|
|
1025
|
+
File: file.name,
|
|
1026
|
+
Size: file.formattedSize,
|
|
1027
|
+
Gzip: file.formattedGzipSize
|
|
1028
|
+
};
|
|
1029
|
+
});
|
|
1030
|
+
const footer = {
|
|
1031
|
+
File: "Total",
|
|
1032
|
+
Size: formattedTotalSize,
|
|
1033
|
+
Gzip: formattedTotalGzipSize
|
|
1034
|
+
};
|
|
1035
|
+
logger.space();
|
|
1036
|
+
logTable(columns, data, footer);
|
|
1037
|
+
logger.space();
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
889
1042
|
// src/plugins/internal/use-client.ts
|
|
890
1043
|
function useClient() {
|
|
891
1044
|
return {
|
|
@@ -924,7 +1077,11 @@ function createBuildOptions(partialOptions) {
|
|
|
924
1077
|
};
|
|
925
1078
|
return {
|
|
926
1079
|
...options,
|
|
927
|
-
plugins: [
|
|
1080
|
+
plugins: [
|
|
1081
|
+
...options.plugins?.filter((p) => p.name !== "report") ?? [],
|
|
1082
|
+
useClient(),
|
|
1083
|
+
report()
|
|
1084
|
+
]
|
|
928
1085
|
};
|
|
929
1086
|
}
|
|
930
1087
|
function getResolvedMinify(options) {
|
|
@@ -997,38 +1154,6 @@ function externalOptionPlugin(options, packageJson) {
|
|
|
997
1154
|
};
|
|
998
1155
|
}
|
|
999
1156
|
|
|
1000
|
-
// src/plugins/utils.ts
|
|
1001
|
-
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
1002
|
-
init_errors();
|
|
1003
|
-
function filterBunupBunPlugins(plugins) {
|
|
1004
|
-
if (!plugins)
|
|
1005
|
-
return [];
|
|
1006
|
-
return plugins.filter((p) => p.type === "bun");
|
|
1007
|
-
}
|
|
1008
|
-
function filterBunupPlugins(plugins) {
|
|
1009
|
-
if (!plugins)
|
|
1010
|
-
return [];
|
|
1011
|
-
return plugins.filter((p) => p.type === "bunup");
|
|
1012
|
-
}
|
|
1013
|
-
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
1014
|
-
if (!bunupPlugins)
|
|
1015
|
-
return;
|
|
1016
|
-
for (const plugin of bunupPlugins) {
|
|
1017
|
-
if (plugin.hooks.onBuildStart) {
|
|
1018
|
-
await plugin.hooks.onBuildStart(options);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
1023
|
-
if (!bunupPlugins)
|
|
1024
|
-
return;
|
|
1025
|
-
for (const plugin of bunupPlugins) {
|
|
1026
|
-
if (plugin.hooks.onBuildDone) {
|
|
1027
|
-
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
1157
|
// src/build.ts
|
|
1033
1158
|
init_utils();
|
|
1034
1159
|
async function build(partialOptions, rootDir = process.cwd()) {
|
|
@@ -1172,7 +1297,7 @@ function getRelativePathToRootDir(filePath, rootDir) {
|
|
|
1172
1297
|
init_utils();
|
|
1173
1298
|
|
|
1174
1299
|
// src/watch.ts
|
|
1175
|
-
var
|
|
1300
|
+
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
1176
1301
|
import path4 from "path";
|
|
1177
1302
|
init_errors();
|
|
1178
1303
|
init_logger();
|
|
@@ -1213,7 +1338,7 @@ async function watch(partialOptions, rootDir) {
|
|
|
1213
1338
|
const start = performance.now();
|
|
1214
1339
|
await build(options, rootDir);
|
|
1215
1340
|
if (!initial) {
|
|
1216
|
-
logger.cli(`\uD83D\uDCE6 Rebuild finished in ${
|
|
1341
|
+
logger.cli(`\uD83D\uDCE6 Rebuild finished in ${import_picocolors6.default.green(formatTime(performance.now() - start))}`);
|
|
1217
1342
|
}
|
|
1218
1343
|
} catch (error) {
|
|
1219
1344
|
handleError(error);
|
|
@@ -1279,7 +1404,7 @@ async function main(args = Bun.argv.slice(2)) {
|
|
|
1279
1404
|
}));
|
|
1280
1405
|
const buildTimeMs = performance.now() - startTime;
|
|
1281
1406
|
const timeDisplay = formatTime(buildTimeMs);
|
|
1282
|
-
logger.cli(`\u26A1\uFE0F Build completed in ${
|
|
1407
|
+
logger.cli(`\u26A1\uFE0F Build completed in ${import_picocolors8.default.green(timeDisplay)}`);
|
|
1283
1408
|
if (cliOptions.watch) {
|
|
1284
1409
|
logger.cli("\uD83D\uDC40 Watching for file changes");
|
|
1285
1410
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -253,6 +253,11 @@ class Logger {
|
|
|
253
253
|
});
|
|
254
254
|
this.output(formattedMessage, options, console.error);
|
|
255
255
|
}
|
|
256
|
+
space() {
|
|
257
|
+
if (silent)
|
|
258
|
+
return;
|
|
259
|
+
console.log("");
|
|
260
|
+
}
|
|
256
261
|
getProgressFgColor(label) {
|
|
257
262
|
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
258
263
|
if (label.includes(key))
|
|
@@ -281,6 +286,41 @@ class Logger {
|
|
|
281
286
|
this.output(formattedMessage, options);
|
|
282
287
|
}
|
|
283
288
|
}
|
|
289
|
+
function logTable(columns, data, footer) {
|
|
290
|
+
if (silent)
|
|
291
|
+
return;
|
|
292
|
+
const widths = {};
|
|
293
|
+
for (const col of columns) {
|
|
294
|
+
const headerLength = col.header.length;
|
|
295
|
+
const dataLengths = data.map((row) => row[col.header]?.length || 0);
|
|
296
|
+
const footerLength = footer ? footer[col.header]?.length || 0 : 0;
|
|
297
|
+
widths[col.header] = Math.max(headerLength, ...dataLengths, footerLength);
|
|
298
|
+
}
|
|
299
|
+
const pad = (str, width, align) => {
|
|
300
|
+
return align === "left" ? str.padEnd(width) : str.padStart(width);
|
|
301
|
+
};
|
|
302
|
+
const headerRow = columns.map((col) => pad(col.header, widths[col.header], col.align)).join(import_picocolors.default.gray(" | "));
|
|
303
|
+
console.log(import_picocolors.default.gray(headerRow));
|
|
304
|
+
const separator = columns.map((col) => "-".repeat(widths[col.header])).join(" | ");
|
|
305
|
+
console.log(import_picocolors.default.gray(separator));
|
|
306
|
+
for (const row of data) {
|
|
307
|
+
const rowStr = columns.map((col) => {
|
|
308
|
+
const value = row[col.header] || "";
|
|
309
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
310
|
+
return col.color ? col.color(padded) : padded;
|
|
311
|
+
}).join(import_picocolors.default.gray(" | "));
|
|
312
|
+
console.log(rowStr);
|
|
313
|
+
}
|
|
314
|
+
console.log(import_picocolors.default.gray(separator));
|
|
315
|
+
if (footer) {
|
|
316
|
+
const footerRow = columns.map((col) => {
|
|
317
|
+
const value = footer[col.header] || "";
|
|
318
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
319
|
+
return padded;
|
|
320
|
+
}).join(import_picocolors.default.gray(" | "));
|
|
321
|
+
console.log(footerRow);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
284
324
|
var logger = Logger.getInstance();
|
|
285
325
|
|
|
286
326
|
// src/errors.ts
|
|
@@ -338,6 +378,15 @@ function getPackageDeps(packageJson) {
|
|
|
338
378
|
...Object.keys(packageJson.peerDependencies || {})
|
|
339
379
|
]));
|
|
340
380
|
}
|
|
381
|
+
function formatFileSize(bytes) {
|
|
382
|
+
if (bytes === 0)
|
|
383
|
+
return "0 B";
|
|
384
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
385
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
386
|
+
if (i === 0)
|
|
387
|
+
return `${bytes} ${units[i]}`;
|
|
388
|
+
return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
|
|
389
|
+
}
|
|
341
390
|
function getShortFilePath(filePath, maxLength = 3) {
|
|
342
391
|
const fileParts = filePath.split("/");
|
|
343
392
|
const shortPath = fileParts.slice(-maxLength).join("/");
|
|
@@ -400,6 +449,97 @@ async function loadPackageJson(cwd) {
|
|
|
400
449
|
};
|
|
401
450
|
}
|
|
402
451
|
|
|
452
|
+
// src/constants/re.ts
|
|
453
|
+
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
454
|
+
var TS_RE = /\.(ts|tsx|mts|cts)$/;
|
|
455
|
+
var DTS_RE = /\.(d\.(ts|mts|cts))$/;
|
|
456
|
+
var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
|
|
457
|
+
var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
|
|
458
|
+
// src/plugins/utils.ts
|
|
459
|
+
var import_picocolors3 = __toESM(require_picocolors());
|
|
460
|
+
function filterBunupBunPlugins(plugins) {
|
|
461
|
+
if (!plugins)
|
|
462
|
+
return [];
|
|
463
|
+
return plugins.filter((p) => p.type === "bun");
|
|
464
|
+
}
|
|
465
|
+
function filterBunupPlugins(plugins) {
|
|
466
|
+
if (!plugins)
|
|
467
|
+
return [];
|
|
468
|
+
return plugins.filter((p) => p.type === "bunup");
|
|
469
|
+
}
|
|
470
|
+
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
471
|
+
if (!bunupPlugins)
|
|
472
|
+
return;
|
|
473
|
+
for (const plugin of bunupPlugins) {
|
|
474
|
+
if (plugin.hooks.onBuildStart) {
|
|
475
|
+
await plugin.hooks.onBuildStart(options);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
480
|
+
if (!bunupPlugins)
|
|
481
|
+
return;
|
|
482
|
+
for (const plugin of bunupPlugins) {
|
|
483
|
+
if (plugin.hooks.onBuildDone) {
|
|
484
|
+
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
// src/plugins/internal/report.ts
|
|
489
|
+
var import_picocolors4 = __toESM(require_picocolors());
|
|
490
|
+
function report() {
|
|
491
|
+
return {
|
|
492
|
+
type: "bunup",
|
|
493
|
+
name: "report",
|
|
494
|
+
hooks: {
|
|
495
|
+
onBuildDone: async ({ options, output }) => {
|
|
496
|
+
if (options.watch)
|
|
497
|
+
return;
|
|
498
|
+
const files = await Promise.all(output.files.map(async (file) => {
|
|
499
|
+
const name = file.relativePathToRootDir;
|
|
500
|
+
const size = Bun.file(file.fullPath).size;
|
|
501
|
+
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
502
|
+
const formattedGzipSize = formatFileSize(gzipSize);
|
|
503
|
+
return {
|
|
504
|
+
name,
|
|
505
|
+
size,
|
|
506
|
+
formattedSize: formatFileSize(size),
|
|
507
|
+
gzipSize,
|
|
508
|
+
formattedGzipSize
|
|
509
|
+
};
|
|
510
|
+
}));
|
|
511
|
+
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
512
|
+
const formattedTotalSize = formatFileSize(totalSize);
|
|
513
|
+
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
514
|
+
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
515
|
+
const columns = [
|
|
516
|
+
{ header: "File", align: "left", color: import_picocolors4.default.blue },
|
|
517
|
+
{ header: "Size", align: "right", color: import_picocolors4.default.green },
|
|
518
|
+
{
|
|
519
|
+
header: "Gzip",
|
|
520
|
+
align: "right",
|
|
521
|
+
color: import_picocolors4.default.magenta
|
|
522
|
+
}
|
|
523
|
+
];
|
|
524
|
+
const data = files.map((file) => {
|
|
525
|
+
return {
|
|
526
|
+
File: file.name,
|
|
527
|
+
Size: file.formattedSize,
|
|
528
|
+
Gzip: file.formattedGzipSize
|
|
529
|
+
};
|
|
530
|
+
});
|
|
531
|
+
const footer = {
|
|
532
|
+
File: "Total",
|
|
533
|
+
Size: formattedTotalSize,
|
|
534
|
+
Gzip: formattedTotalGzipSize
|
|
535
|
+
};
|
|
536
|
+
logger.space();
|
|
537
|
+
logTable(columns, data, footer);
|
|
538
|
+
logger.space();
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
403
543
|
// src/plugins/internal/use-client.ts
|
|
404
544
|
function useClient() {
|
|
405
545
|
return {
|
|
@@ -438,7 +578,11 @@ function createBuildOptions(partialOptions) {
|
|
|
438
578
|
};
|
|
439
579
|
return {
|
|
440
580
|
...options,
|
|
441
|
-
plugins: [
|
|
581
|
+
plugins: [
|
|
582
|
+
...options.plugins?.filter((p) => p.name !== "report") ?? [],
|
|
583
|
+
useClient(),
|
|
584
|
+
report()
|
|
585
|
+
]
|
|
442
586
|
};
|
|
443
587
|
}
|
|
444
588
|
function getResolvedMinify(options) {
|
|
@@ -510,37 +654,6 @@ function externalOptionPlugin(options, packageJson) {
|
|
|
510
654
|
};
|
|
511
655
|
}
|
|
512
656
|
|
|
513
|
-
// src/plugins/utils.ts
|
|
514
|
-
var import_picocolors3 = __toESM(require_picocolors());
|
|
515
|
-
function filterBunupBunPlugins(plugins) {
|
|
516
|
-
if (!plugins)
|
|
517
|
-
return [];
|
|
518
|
-
return plugins.filter((p) => p.type === "bun");
|
|
519
|
-
}
|
|
520
|
-
function filterBunupPlugins(plugins) {
|
|
521
|
-
if (!plugins)
|
|
522
|
-
return [];
|
|
523
|
-
return plugins.filter((p) => p.type === "bunup");
|
|
524
|
-
}
|
|
525
|
-
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
526
|
-
if (!bunupPlugins)
|
|
527
|
-
return;
|
|
528
|
-
for (const plugin of bunupPlugins) {
|
|
529
|
-
if (plugin.hooks.onBuildStart) {
|
|
530
|
-
await plugin.hooks.onBuildStart(options);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
535
|
-
if (!bunupPlugins)
|
|
536
|
-
return;
|
|
537
|
-
for (const plugin of bunupPlugins) {
|
|
538
|
-
if (plugin.hooks.onBuildDone) {
|
|
539
|
-
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
657
|
// src/build.ts
|
|
545
658
|
async function build(partialOptions, rootDir = process.cwd()) {
|
|
546
659
|
const buildOutput = {
|
package/dist/index.js
CHANGED
|
@@ -220,6 +220,11 @@ class Logger {
|
|
|
220
220
|
});
|
|
221
221
|
this.output(formattedMessage, options, console.error);
|
|
222
222
|
}
|
|
223
|
+
space() {
|
|
224
|
+
if (silent)
|
|
225
|
+
return;
|
|
226
|
+
console.log("");
|
|
227
|
+
}
|
|
223
228
|
getProgressFgColor(label) {
|
|
224
229
|
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
225
230
|
if (label.includes(key))
|
|
@@ -248,6 +253,41 @@ class Logger {
|
|
|
248
253
|
this.output(formattedMessage, options);
|
|
249
254
|
}
|
|
250
255
|
}
|
|
256
|
+
function logTable(columns, data, footer) {
|
|
257
|
+
if (silent)
|
|
258
|
+
return;
|
|
259
|
+
const widths = {};
|
|
260
|
+
for (const col of columns) {
|
|
261
|
+
const headerLength = col.header.length;
|
|
262
|
+
const dataLengths = data.map((row) => row[col.header]?.length || 0);
|
|
263
|
+
const footerLength = footer ? footer[col.header]?.length || 0 : 0;
|
|
264
|
+
widths[col.header] = Math.max(headerLength, ...dataLengths, footerLength);
|
|
265
|
+
}
|
|
266
|
+
const pad = (str, width, align) => {
|
|
267
|
+
return align === "left" ? str.padEnd(width) : str.padStart(width);
|
|
268
|
+
};
|
|
269
|
+
const headerRow = columns.map((col) => pad(col.header, widths[col.header], col.align)).join(import_picocolors.default.gray(" | "));
|
|
270
|
+
console.log(import_picocolors.default.gray(headerRow));
|
|
271
|
+
const separator = columns.map((col) => "-".repeat(widths[col.header])).join(" | ");
|
|
272
|
+
console.log(import_picocolors.default.gray(separator));
|
|
273
|
+
for (const row of data) {
|
|
274
|
+
const rowStr = columns.map((col) => {
|
|
275
|
+
const value = row[col.header] || "";
|
|
276
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
277
|
+
return col.color ? col.color(padded) : padded;
|
|
278
|
+
}).join(import_picocolors.default.gray(" | "));
|
|
279
|
+
console.log(rowStr);
|
|
280
|
+
}
|
|
281
|
+
console.log(import_picocolors.default.gray(separator));
|
|
282
|
+
if (footer) {
|
|
283
|
+
const footerRow = columns.map((col) => {
|
|
284
|
+
const value = footer[col.header] || "";
|
|
285
|
+
const padded = pad(value, widths[col.header], col.align);
|
|
286
|
+
return padded;
|
|
287
|
+
}).join(import_picocolors.default.gray(" | "));
|
|
288
|
+
console.log(footerRow);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
251
291
|
var logger = Logger.getInstance();
|
|
252
292
|
|
|
253
293
|
// src/errors.ts
|
|
@@ -305,6 +345,15 @@ function getPackageDeps(packageJson) {
|
|
|
305
345
|
...Object.keys(packageJson.peerDependencies || {})
|
|
306
346
|
]));
|
|
307
347
|
}
|
|
348
|
+
function formatFileSize(bytes) {
|
|
349
|
+
if (bytes === 0)
|
|
350
|
+
return "0 B";
|
|
351
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
352
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
353
|
+
if (i === 0)
|
|
354
|
+
return `${bytes} ${units[i]}`;
|
|
355
|
+
return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
|
|
356
|
+
}
|
|
308
357
|
function getShortFilePath(filePath, maxLength = 3) {
|
|
309
358
|
const fileParts = filePath.split("/");
|
|
310
359
|
const shortPath = fileParts.slice(-maxLength).join("/");
|
|
@@ -367,6 +416,97 @@ async function loadPackageJson(cwd) {
|
|
|
367
416
|
};
|
|
368
417
|
}
|
|
369
418
|
|
|
419
|
+
// src/constants/re.ts
|
|
420
|
+
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
421
|
+
var TS_RE = /\.(ts|tsx|mts|cts)$/;
|
|
422
|
+
var DTS_RE = /\.(d\.(ts|mts|cts))$/;
|
|
423
|
+
var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
|
|
424
|
+
var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
|
|
425
|
+
// src/plugins/utils.ts
|
|
426
|
+
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
427
|
+
function filterBunupBunPlugins(plugins) {
|
|
428
|
+
if (!plugins)
|
|
429
|
+
return [];
|
|
430
|
+
return plugins.filter((p) => p.type === "bun");
|
|
431
|
+
}
|
|
432
|
+
function filterBunupPlugins(plugins) {
|
|
433
|
+
if (!plugins)
|
|
434
|
+
return [];
|
|
435
|
+
return plugins.filter((p) => p.type === "bunup");
|
|
436
|
+
}
|
|
437
|
+
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
438
|
+
if (!bunupPlugins)
|
|
439
|
+
return;
|
|
440
|
+
for (const plugin of bunupPlugins) {
|
|
441
|
+
if (plugin.hooks.onBuildStart) {
|
|
442
|
+
await plugin.hooks.onBuildStart(options);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
447
|
+
if (!bunupPlugins)
|
|
448
|
+
return;
|
|
449
|
+
for (const plugin of bunupPlugins) {
|
|
450
|
+
if (plugin.hooks.onBuildDone) {
|
|
451
|
+
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
// src/plugins/internal/report.ts
|
|
456
|
+
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
457
|
+
function report() {
|
|
458
|
+
return {
|
|
459
|
+
type: "bunup",
|
|
460
|
+
name: "report",
|
|
461
|
+
hooks: {
|
|
462
|
+
onBuildDone: async ({ options, output }) => {
|
|
463
|
+
if (options.watch)
|
|
464
|
+
return;
|
|
465
|
+
const files = await Promise.all(output.files.map(async (file) => {
|
|
466
|
+
const name = file.relativePathToRootDir;
|
|
467
|
+
const size = Bun.file(file.fullPath).size;
|
|
468
|
+
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
469
|
+
const formattedGzipSize = formatFileSize(gzipSize);
|
|
470
|
+
return {
|
|
471
|
+
name,
|
|
472
|
+
size,
|
|
473
|
+
formattedSize: formatFileSize(size),
|
|
474
|
+
gzipSize,
|
|
475
|
+
formattedGzipSize
|
|
476
|
+
};
|
|
477
|
+
}));
|
|
478
|
+
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
479
|
+
const formattedTotalSize = formatFileSize(totalSize);
|
|
480
|
+
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
481
|
+
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
482
|
+
const columns = [
|
|
483
|
+
{ header: "File", align: "left", color: import_picocolors4.default.blue },
|
|
484
|
+
{ header: "Size", align: "right", color: import_picocolors4.default.green },
|
|
485
|
+
{
|
|
486
|
+
header: "Gzip",
|
|
487
|
+
align: "right",
|
|
488
|
+
color: import_picocolors4.default.magenta
|
|
489
|
+
}
|
|
490
|
+
];
|
|
491
|
+
const data = files.map((file) => {
|
|
492
|
+
return {
|
|
493
|
+
File: file.name,
|
|
494
|
+
Size: file.formattedSize,
|
|
495
|
+
Gzip: file.formattedGzipSize
|
|
496
|
+
};
|
|
497
|
+
});
|
|
498
|
+
const footer = {
|
|
499
|
+
File: "Total",
|
|
500
|
+
Size: formattedTotalSize,
|
|
501
|
+
Gzip: formattedTotalGzipSize
|
|
502
|
+
};
|
|
503
|
+
logger.space();
|
|
504
|
+
logTable(columns, data, footer);
|
|
505
|
+
logger.space();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
}
|
|
370
510
|
// src/plugins/internal/use-client.ts
|
|
371
511
|
function useClient() {
|
|
372
512
|
return {
|
|
@@ -405,7 +545,11 @@ function createBuildOptions(partialOptions) {
|
|
|
405
545
|
};
|
|
406
546
|
return {
|
|
407
547
|
...options,
|
|
408
|
-
plugins: [
|
|
548
|
+
plugins: [
|
|
549
|
+
...options.plugins?.filter((p) => p.name !== "report") ?? [],
|
|
550
|
+
useClient(),
|
|
551
|
+
report()
|
|
552
|
+
]
|
|
409
553
|
};
|
|
410
554
|
}
|
|
411
555
|
function getResolvedMinify(options) {
|
|
@@ -477,37 +621,6 @@ function externalOptionPlugin(options, packageJson) {
|
|
|
477
621
|
};
|
|
478
622
|
}
|
|
479
623
|
|
|
480
|
-
// src/plugins/utils.ts
|
|
481
|
-
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
482
|
-
function filterBunupBunPlugins(plugins) {
|
|
483
|
-
if (!plugins)
|
|
484
|
-
return [];
|
|
485
|
-
return plugins.filter((p) => p.type === "bun");
|
|
486
|
-
}
|
|
487
|
-
function filterBunupPlugins(plugins) {
|
|
488
|
-
if (!plugins)
|
|
489
|
-
return [];
|
|
490
|
-
return plugins.filter((p) => p.type === "bunup");
|
|
491
|
-
}
|
|
492
|
-
async function runPluginBuildStartHooks(bunupPlugins, options) {
|
|
493
|
-
if (!bunupPlugins)
|
|
494
|
-
return;
|
|
495
|
-
for (const plugin of bunupPlugins) {
|
|
496
|
-
if (plugin.hooks.onBuildStart) {
|
|
497
|
-
await plugin.hooks.onBuildStart(options);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
|
|
502
|
-
if (!bunupPlugins)
|
|
503
|
-
return;
|
|
504
|
-
for (const plugin of bunupPlugins) {
|
|
505
|
-
if (plugin.hooks.onBuildDone) {
|
|
506
|
-
await plugin.hooks.onBuildDone({ options, output, meta });
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
624
|
// src/build.ts
|
|
512
625
|
async function build(partialOptions, rootDir = process.cwd()) {
|
|
513
626
|
const buildOutput = {
|
package/dist/plugins.cjs
CHANGED
|
@@ -300,6 +300,11 @@ class Logger {
|
|
|
300
300
|
});
|
|
301
301
|
this.output(formattedMessage, options, console.error);
|
|
302
302
|
}
|
|
303
|
+
space() {
|
|
304
|
+
if (silent)
|
|
305
|
+
return;
|
|
306
|
+
console.log("");
|
|
307
|
+
}
|
|
303
308
|
getProgressFgColor(label) {
|
|
304
309
|
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
305
310
|
if (label.includes(key))
|
|
@@ -329,6 +334,8 @@ class Logger {
|
|
|
329
334
|
}
|
|
330
335
|
}
|
|
331
336
|
function logTable(columns, data, footer) {
|
|
337
|
+
if (silent)
|
|
338
|
+
return;
|
|
332
339
|
const widths = {};
|
|
333
340
|
for (const col of columns) {
|
|
334
341
|
const headerLength = col.header.length;
|
|
@@ -491,92 +498,17 @@ function exportFieldToEntryPoint(exportField, dts) {
|
|
|
491
498
|
function formatToExportField(format, dts) {
|
|
492
499
|
return dts ? "types" : format === "esm" ? "import" : "require";
|
|
493
500
|
}
|
|
494
|
-
// src/plugins/built-in/productivity/report.ts
|
|
495
|
-
var import_picocolors3 = __toESM(require_picocolors());
|
|
496
|
-
function report(options = {}) {
|
|
497
|
-
const { maxBundleSize, gzip = true } = options;
|
|
498
|
-
return {
|
|
499
|
-
type: "bunup",
|
|
500
|
-
name: "report",
|
|
501
|
-
hooks: {
|
|
502
|
-
onBuildDone: async ({ options: options2, output }) => {
|
|
503
|
-
if (options2.watch)
|
|
504
|
-
return;
|
|
505
|
-
const files = await Promise.all(output.files.map(async (file) => {
|
|
506
|
-
const name = file.relativePathToRootDir;
|
|
507
|
-
const size = Bun.file(file.fullPath).size;
|
|
508
|
-
let gzipSize;
|
|
509
|
-
let formattedGzipSize;
|
|
510
|
-
if (gzip) {
|
|
511
|
-
gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
512
|
-
formattedGzipSize = formatFileSize(gzipSize);
|
|
513
|
-
}
|
|
514
|
-
return {
|
|
515
|
-
name,
|
|
516
|
-
size,
|
|
517
|
-
formattedSize: formatFileSize(size),
|
|
518
|
-
gzipSize,
|
|
519
|
-
formattedGzipSize
|
|
520
|
-
};
|
|
521
|
-
}));
|
|
522
|
-
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
523
|
-
const formattedTotalSize = formatFileSize(totalSize);
|
|
524
|
-
let totalGzipSize;
|
|
525
|
-
let formattedTotalGzipSize;
|
|
526
|
-
if (gzip) {
|
|
527
|
-
totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
528
|
-
formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
529
|
-
}
|
|
530
|
-
const columns = [
|
|
531
|
-
{ header: "File", align: "left", color: import_picocolors3.default.blue },
|
|
532
|
-
{ header: "Size", align: "right", color: import_picocolors3.default.green }
|
|
533
|
-
];
|
|
534
|
-
if (gzip) {
|
|
535
|
-
columns.push({
|
|
536
|
-
header: "Gzip",
|
|
537
|
-
align: "right",
|
|
538
|
-
color: import_picocolors3.default.magenta
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
const data = files.map((file) => {
|
|
542
|
-
const row = {
|
|
543
|
-
File: file.name,
|
|
544
|
-
Size: file.formattedSize
|
|
545
|
-
};
|
|
546
|
-
if (gzip && file.formattedGzipSize) {
|
|
547
|
-
row.Gzip = file.formattedGzipSize;
|
|
548
|
-
}
|
|
549
|
-
return row;
|
|
550
|
-
});
|
|
551
|
-
const footer = {
|
|
552
|
-
File: "Total",
|
|
553
|
-
Size: formattedTotalSize
|
|
554
|
-
};
|
|
555
|
-
if (gzip && formattedTotalGzipSize) {
|
|
556
|
-
footer.Gzip = formattedTotalGzipSize;
|
|
557
|
-
}
|
|
558
|
-
console.log("");
|
|
559
|
-
logTable(columns, data, footer);
|
|
560
|
-
if (maxBundleSize && totalSize > maxBundleSize) {
|
|
561
|
-
console.log("");
|
|
562
|
-
console.log(import_picocolors3.default.red(`Your bundle size of ${formattedTotalSize} exceeds the configured limit of ${formatFileSize(maxBundleSize)}`));
|
|
563
|
-
}
|
|
564
|
-
console.log("");
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
501
|
// src/plugins/built-in/css/inject-styles.ts
|
|
570
502
|
var import_node_path2 = __toESM(require("path"));
|
|
571
503
|
|
|
572
504
|
// src/plugins/utils.ts
|
|
573
|
-
var
|
|
505
|
+
var import_picocolors3 = __toESM(require_picocolors());
|
|
574
506
|
async function getPackageForPlugin(name, pluginName) {
|
|
575
507
|
let pkg;
|
|
576
508
|
try {
|
|
577
509
|
pkg = await import(name);
|
|
578
510
|
} catch {
|
|
579
|
-
throw new BunupPluginError(`[${
|
|
511
|
+
throw new BunupPluginError(`[${import_picocolors3.default.cyan(name)}] is required for the ${pluginName} plugin. Please install it with: ${import_picocolors3.default.blue(`bun add ${name} --dev`)}`);
|
|
580
512
|
}
|
|
581
513
|
return pkg;
|
|
582
514
|
}
|
|
@@ -663,4 +595,59 @@ function copy(patterns, outPath) {
|
|
|
663
595
|
}
|
|
664
596
|
};
|
|
665
597
|
}
|
|
598
|
+
// src/plugins/internal/report.ts
|
|
599
|
+
var import_picocolors4 = __toESM(require_picocolors());
|
|
600
|
+
function report() {
|
|
601
|
+
return {
|
|
602
|
+
type: "bunup",
|
|
603
|
+
name: "report",
|
|
604
|
+
hooks: {
|
|
605
|
+
onBuildDone: async ({ options, output }) => {
|
|
606
|
+
if (options.watch)
|
|
607
|
+
return;
|
|
608
|
+
const files = await Promise.all(output.files.map(async (file) => {
|
|
609
|
+
const name = file.relativePathToRootDir;
|
|
610
|
+
const size = Bun.file(file.fullPath).size;
|
|
611
|
+
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
612
|
+
const formattedGzipSize = formatFileSize(gzipSize);
|
|
613
|
+
return {
|
|
614
|
+
name,
|
|
615
|
+
size,
|
|
616
|
+
formattedSize: formatFileSize(size),
|
|
617
|
+
gzipSize,
|
|
618
|
+
formattedGzipSize
|
|
619
|
+
};
|
|
620
|
+
}));
|
|
621
|
+
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
622
|
+
const formattedTotalSize = formatFileSize(totalSize);
|
|
623
|
+
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
624
|
+
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
625
|
+
const columns = [
|
|
626
|
+
{ header: "File", align: "left", color: import_picocolors4.default.blue },
|
|
627
|
+
{ header: "Size", align: "right", color: import_picocolors4.default.green },
|
|
628
|
+
{
|
|
629
|
+
header: "Gzip",
|
|
630
|
+
align: "right",
|
|
631
|
+
color: import_picocolors4.default.magenta
|
|
632
|
+
}
|
|
633
|
+
];
|
|
634
|
+
const data = files.map((file) => {
|
|
635
|
+
return {
|
|
636
|
+
File: file.name,
|
|
637
|
+
Size: file.formattedSize,
|
|
638
|
+
Gzip: file.formattedGzipSize
|
|
639
|
+
};
|
|
640
|
+
});
|
|
641
|
+
const footer = {
|
|
642
|
+
File: "Total",
|
|
643
|
+
Size: formattedTotalSize,
|
|
644
|
+
Gzip: formattedTotalGzipSize
|
|
645
|
+
};
|
|
646
|
+
logger.space();
|
|
647
|
+
logTable(columns, data, footer);
|
|
648
|
+
logger.space();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
}
|
|
666
653
|
})
|
package/dist/plugins.d.cts
CHANGED
|
@@ -385,24 +385,6 @@ declare function shims(): Plugin;
|
|
|
385
385
|
*/
|
|
386
386
|
declare function exports(): BunupPlugin;
|
|
387
387
|
declare function filterJsDtsFiles(files: BuildOutputFile[]): BuildOutputFile[];
|
|
388
|
-
type ReportPluginOptions = {
|
|
389
|
-
/**
|
|
390
|
-
* The maximum bundle size in bytes.
|
|
391
|
-
* If the bundle size exceeds this limit, a error will be logged without failing the build.
|
|
392
|
-
*/
|
|
393
|
-
maxBundleSize?: number
|
|
394
|
-
/**
|
|
395
|
-
* Whether to show gzip sizes in the report.
|
|
396
|
-
* When enabled, the report will include an additional column with the gzip size of each file.
|
|
397
|
-
* @default true
|
|
398
|
-
*/
|
|
399
|
-
gzip?: boolean
|
|
400
|
-
};
|
|
401
|
-
/**
|
|
402
|
-
* A plugin that logs a report of the bundle size.
|
|
403
|
-
* @param options - The options for the report plugin.
|
|
404
|
-
*/
|
|
405
|
-
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
406
388
|
type InjectStylesPluginOptions = Pick<import("lightningcss").TransformOptions<import("lightningcss").CustomAtRules>, "sourceMap" | "inputSourceMap" | "targets" | "nonStandard" | "minify" | "pseudoClasses" | "unusedSymbols" | "errorRecovery" | "visitor" | "customAtRules" | "include" | "exclude" | "drafts"> & {
|
|
407
389
|
inject?: (css: string, filePath: string) => MaybePromise<string>
|
|
408
390
|
};
|
|
@@ -420,4 +402,10 @@ declare function injectStyles(options?: InjectStylesPluginOptions): Plugin;
|
|
|
420
402
|
* @see https://bunup.dev/docs/plugins/productivity#copy
|
|
421
403
|
*/
|
|
422
404
|
declare function copy(patterns: string[], outPath?: string): BunupPlugin;
|
|
405
|
+
/**
|
|
406
|
+
* A plugin that logs a report of the bundle size.
|
|
407
|
+
*
|
|
408
|
+
* @deprecated This plugin is enabled by default. Bundle size reports are automatically logged without needing to use this plugin.
|
|
409
|
+
*/
|
|
410
|
+
declare function report(): BunupPlugin;
|
|
423
411
|
export { shims, report, injectStyles, filterJsDtsFiles, exports, copy };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -385,24 +385,6 @@ declare function shims(): Plugin;
|
|
|
385
385
|
*/
|
|
386
386
|
declare function exports(): BunupPlugin;
|
|
387
387
|
declare function filterJsDtsFiles(files: BuildOutputFile[]): BuildOutputFile[];
|
|
388
|
-
type ReportPluginOptions = {
|
|
389
|
-
/**
|
|
390
|
-
* The maximum bundle size in bytes.
|
|
391
|
-
* If the bundle size exceeds this limit, a error will be logged without failing the build.
|
|
392
|
-
*/
|
|
393
|
-
maxBundleSize?: number
|
|
394
|
-
/**
|
|
395
|
-
* Whether to show gzip sizes in the report.
|
|
396
|
-
* When enabled, the report will include an additional column with the gzip size of each file.
|
|
397
|
-
* @default true
|
|
398
|
-
*/
|
|
399
|
-
gzip?: boolean
|
|
400
|
-
};
|
|
401
|
-
/**
|
|
402
|
-
* A plugin that logs a report of the bundle size.
|
|
403
|
-
* @param options - The options for the report plugin.
|
|
404
|
-
*/
|
|
405
|
-
declare function report(options?: ReportPluginOptions): BunupPlugin;
|
|
406
388
|
type InjectStylesPluginOptions = Pick<import("lightningcss").TransformOptions<import("lightningcss").CustomAtRules>, "sourceMap" | "inputSourceMap" | "targets" | "nonStandard" | "minify" | "pseudoClasses" | "unusedSymbols" | "errorRecovery" | "visitor" | "customAtRules" | "include" | "exclude" | "drafts"> & {
|
|
407
389
|
inject?: (css: string, filePath: string) => MaybePromise<string>
|
|
408
390
|
};
|
|
@@ -420,4 +402,10 @@ declare function injectStyles(options?: InjectStylesPluginOptions): Plugin;
|
|
|
420
402
|
* @see https://bunup.dev/docs/plugins/productivity#copy
|
|
421
403
|
*/
|
|
422
404
|
declare function copy(patterns: string[], outPath?: string): BunupPlugin;
|
|
405
|
+
/**
|
|
406
|
+
* A plugin that logs a report of the bundle size.
|
|
407
|
+
*
|
|
408
|
+
* @deprecated This plugin is enabled by default. Bundle size reports are automatically logged without needing to use this plugin.
|
|
409
|
+
*/
|
|
410
|
+
declare function report(): BunupPlugin;
|
|
423
411
|
export { shims, report, injectStyles, filterJsDtsFiles, exports, copy };
|
package/dist/plugins.js
CHANGED
|
@@ -264,6 +264,11 @@ class Logger {
|
|
|
264
264
|
});
|
|
265
265
|
this.output(formattedMessage, options, console.error);
|
|
266
266
|
}
|
|
267
|
+
space() {
|
|
268
|
+
if (silent)
|
|
269
|
+
return;
|
|
270
|
+
console.log("");
|
|
271
|
+
}
|
|
267
272
|
getProgressFgColor(label) {
|
|
268
273
|
for (const [key, colorFn] of Object.entries(this.progressFgColorMap)) {
|
|
269
274
|
if (label.includes(key))
|
|
@@ -293,6 +298,8 @@ class Logger {
|
|
|
293
298
|
}
|
|
294
299
|
}
|
|
295
300
|
function logTable(columns, data, footer) {
|
|
301
|
+
if (silent)
|
|
302
|
+
return;
|
|
296
303
|
const widths = {};
|
|
297
304
|
for (const col of columns) {
|
|
298
305
|
const headerLength = col.header.length;
|
|
@@ -455,92 +462,17 @@ function exportFieldToEntryPoint(exportField, dts) {
|
|
|
455
462
|
function formatToExportField(format, dts) {
|
|
456
463
|
return dts ? "types" : format === "esm" ? "import" : "require";
|
|
457
464
|
}
|
|
458
|
-
// src/plugins/built-in/productivity/report.ts
|
|
459
|
-
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
460
|
-
function report(options = {}) {
|
|
461
|
-
const { maxBundleSize, gzip = true } = options;
|
|
462
|
-
return {
|
|
463
|
-
type: "bunup",
|
|
464
|
-
name: "report",
|
|
465
|
-
hooks: {
|
|
466
|
-
onBuildDone: async ({ options: options2, output }) => {
|
|
467
|
-
if (options2.watch)
|
|
468
|
-
return;
|
|
469
|
-
const files = await Promise.all(output.files.map(async (file) => {
|
|
470
|
-
const name = file.relativePathToRootDir;
|
|
471
|
-
const size = Bun.file(file.fullPath).size;
|
|
472
|
-
let gzipSize;
|
|
473
|
-
let formattedGzipSize;
|
|
474
|
-
if (gzip) {
|
|
475
|
-
gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
476
|
-
formattedGzipSize = formatFileSize(gzipSize);
|
|
477
|
-
}
|
|
478
|
-
return {
|
|
479
|
-
name,
|
|
480
|
-
size,
|
|
481
|
-
formattedSize: formatFileSize(size),
|
|
482
|
-
gzipSize,
|
|
483
|
-
formattedGzipSize
|
|
484
|
-
};
|
|
485
|
-
}));
|
|
486
|
-
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
487
|
-
const formattedTotalSize = formatFileSize(totalSize);
|
|
488
|
-
let totalGzipSize;
|
|
489
|
-
let formattedTotalGzipSize;
|
|
490
|
-
if (gzip) {
|
|
491
|
-
totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
492
|
-
formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
493
|
-
}
|
|
494
|
-
const columns = [
|
|
495
|
-
{ header: "File", align: "left", color: import_picocolors3.default.blue },
|
|
496
|
-
{ header: "Size", align: "right", color: import_picocolors3.default.green }
|
|
497
|
-
];
|
|
498
|
-
if (gzip) {
|
|
499
|
-
columns.push({
|
|
500
|
-
header: "Gzip",
|
|
501
|
-
align: "right",
|
|
502
|
-
color: import_picocolors3.default.magenta
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
const data = files.map((file) => {
|
|
506
|
-
const row = {
|
|
507
|
-
File: file.name,
|
|
508
|
-
Size: file.formattedSize
|
|
509
|
-
};
|
|
510
|
-
if (gzip && file.formattedGzipSize) {
|
|
511
|
-
row.Gzip = file.formattedGzipSize;
|
|
512
|
-
}
|
|
513
|
-
return row;
|
|
514
|
-
});
|
|
515
|
-
const footer = {
|
|
516
|
-
File: "Total",
|
|
517
|
-
Size: formattedTotalSize
|
|
518
|
-
};
|
|
519
|
-
if (gzip && formattedTotalGzipSize) {
|
|
520
|
-
footer.Gzip = formattedTotalGzipSize;
|
|
521
|
-
}
|
|
522
|
-
console.log("");
|
|
523
|
-
logTable(columns, data, footer);
|
|
524
|
-
if (maxBundleSize && totalSize > maxBundleSize) {
|
|
525
|
-
console.log("");
|
|
526
|
-
console.log(import_picocolors3.default.red(`Your bundle size of ${formattedTotalSize} exceeds the configured limit of ${formatFileSize(maxBundleSize)}`));
|
|
527
|
-
}
|
|
528
|
-
console.log("");
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
465
|
// src/plugins/built-in/css/inject-styles.ts
|
|
534
466
|
import path2 from "path";
|
|
535
467
|
|
|
536
468
|
// src/plugins/utils.ts
|
|
537
|
-
var
|
|
469
|
+
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
538
470
|
async function getPackageForPlugin(name, pluginName) {
|
|
539
471
|
let pkg;
|
|
540
472
|
try {
|
|
541
473
|
pkg = await import(name);
|
|
542
474
|
} catch {
|
|
543
|
-
throw new BunupPluginError(`[${
|
|
475
|
+
throw new BunupPluginError(`[${import_picocolors3.default.cyan(name)}] is required for the ${pluginName} plugin. Please install it with: ${import_picocolors3.default.blue(`bun add ${name} --dev`)}`);
|
|
544
476
|
}
|
|
545
477
|
return pkg;
|
|
546
478
|
}
|
|
@@ -627,6 +559,61 @@ function copy(patterns, outPath) {
|
|
|
627
559
|
}
|
|
628
560
|
};
|
|
629
561
|
}
|
|
562
|
+
// src/plugins/internal/report.ts
|
|
563
|
+
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
564
|
+
function report() {
|
|
565
|
+
return {
|
|
566
|
+
type: "bunup",
|
|
567
|
+
name: "report",
|
|
568
|
+
hooks: {
|
|
569
|
+
onBuildDone: async ({ options, output }) => {
|
|
570
|
+
if (options.watch)
|
|
571
|
+
return;
|
|
572
|
+
const files = await Promise.all(output.files.map(async (file) => {
|
|
573
|
+
const name = file.relativePathToRootDir;
|
|
574
|
+
const size = Bun.file(file.fullPath).size;
|
|
575
|
+
const gzipSize = Bun.gzipSync(new Uint8Array(await Bun.file(file.fullPath).arrayBuffer())).length;
|
|
576
|
+
const formattedGzipSize = formatFileSize(gzipSize);
|
|
577
|
+
return {
|
|
578
|
+
name,
|
|
579
|
+
size,
|
|
580
|
+
formattedSize: formatFileSize(size),
|
|
581
|
+
gzipSize,
|
|
582
|
+
formattedGzipSize
|
|
583
|
+
};
|
|
584
|
+
}));
|
|
585
|
+
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
586
|
+
const formattedTotalSize = formatFileSize(totalSize);
|
|
587
|
+
const totalGzipSize = files.reduce((sum, file) => sum + (file.gzipSize || 0), 0);
|
|
588
|
+
const formattedTotalGzipSize = formatFileSize(totalGzipSize);
|
|
589
|
+
const columns = [
|
|
590
|
+
{ header: "File", align: "left", color: import_picocolors4.default.blue },
|
|
591
|
+
{ header: "Size", align: "right", color: import_picocolors4.default.green },
|
|
592
|
+
{
|
|
593
|
+
header: "Gzip",
|
|
594
|
+
align: "right",
|
|
595
|
+
color: import_picocolors4.default.magenta
|
|
596
|
+
}
|
|
597
|
+
];
|
|
598
|
+
const data = files.map((file) => {
|
|
599
|
+
return {
|
|
600
|
+
File: file.name,
|
|
601
|
+
Size: file.formattedSize,
|
|
602
|
+
Gzip: file.formattedGzipSize
|
|
603
|
+
};
|
|
604
|
+
});
|
|
605
|
+
const footer = {
|
|
606
|
+
File: "Total",
|
|
607
|
+
Size: formattedTotalSize,
|
|
608
|
+
Gzip: formattedTotalGzipSize
|
|
609
|
+
};
|
|
610
|
+
logger.space();
|
|
611
|
+
logTable(columns, data, footer);
|
|
612
|
+
logger.space();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
630
617
|
export {
|
|
631
618
|
shims,
|
|
632
619
|
report,
|