@hypernym/bundler 0.13.0 → 0.13.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.
Files changed (2) hide show
  1. package/dist/bin/index.mjs +67 -38
  2. package/package.json +5 -5
@@ -3,7 +3,7 @@ import process, { cwd } from 'node:process';
3
3
  import { createArgs } from '@hypernym/args';
4
4
  import { resolve, dirname, parse } from 'node:path';
5
5
  import { read, exists, write, copy, readdir } from '@hypernym/utils/fs';
6
- import { dim, cyan, bold, green } from '@hypernym/colors';
6
+ import { dim, cyan } from '@hypernym/colors';
7
7
  import { build as build$1, transform } from 'esbuild';
8
8
  import { stat } from 'node:fs/promises';
9
9
  import { isString, isUndefined, isObject } from '@hypernym/utils';
@@ -25,24 +25,23 @@ const externals = [
25
25
  ];
26
26
 
27
27
  const logo = `\u2726\u2726`;
28
- const name$1 = "hyperbundler";
29
- const logoname = `${logo} ${name$1}`;
30
- const version = `0.13.0`;
28
+ const version = `0.13.1`;
31
29
 
32
- const name = logoname.toUpperCase();
33
30
  const cl = console.log;
31
+ const separator = `/`;
34
32
  const logger = {
35
33
  info: (...args) => {
36
- const time = (/* @__PURE__ */ new Date()).toLocaleTimeString();
37
- return cl(name, dim(`[${time}]`), ...args);
34
+ cl(logo, dim(separator), ...args);
38
35
  },
39
36
  error: (...args) => {
40
- const time = (/* @__PURE__ */ new Date()).toLocaleTimeString();
41
- return cl(name, dim(`[${time}]`), ...args);
37
+ cl();
38
+ cl(logo, dim(separator), ...args);
39
+ cl();
42
40
  },
43
41
  exit: (message) => {
44
- const time = (/* @__PURE__ */ new Date()).toLocaleTimeString();
45
- cl(name, dim(`[${time}]`), message);
42
+ cl();
43
+ cl(logo, dim(separator), message);
44
+ cl();
46
45
  return process.exit();
47
46
  }
48
47
  };
@@ -87,6 +86,28 @@ function getOutputPath(outDir, input, types = false) {
87
86
  return `./${output}`;
88
87
  }
89
88
 
89
+ function getLongestOutput(outDir, entries) {
90
+ const outputs = [];
91
+ for (const entry of entries) {
92
+ if ("copy" in entry && entry.copy) {
93
+ const out = entry.copy.output;
94
+ outputs.push(out);
95
+ }
96
+ if ("input" in entry && entry.input) {
97
+ const out = entry.output || getOutputPath(outDir, entry.input);
98
+ outputs.push(out);
99
+ }
100
+ if ("declaration" in entry && entry.declaration) {
101
+ const out = entry.output || getOutputPath(outDir, entry.declaration, true);
102
+ outputs.push(out);
103
+ }
104
+ if ("template" in entry && entry.template) {
105
+ outputs.push(entry.output);
106
+ }
107
+ }
108
+ return Math.max(...outputs.map((v) => v.length));
109
+ }
110
+
90
111
  async function loadConfig(cwd, filePath, defaults) {
91
112
  const result = await build$1({
92
113
  entryPoints: [resolve(cwd, filePath)],
@@ -186,7 +207,7 @@ function esbuild(options) {
186
207
  };
187
208
  }
188
209
 
189
- function logModuleStats(file) {
210
+ function logModuleStats(file, longestOutput) {
190
211
  const cl = console.log;
191
212
  const base = parse(file.path).base;
192
213
  const path = file.path.replace(base, "");
@@ -194,16 +215,30 @@ function logModuleStats(file) {
194
215
  if (format.includes("system")) format = "sys";
195
216
  if (format === "commonjs") format = "cjs";
196
217
  if (format === "module") format = "esm";
218
+ longestOutput = longestOutput + 2;
219
+ const ansiCode = 9;
220
+ const pathDim = dim(path);
221
+ const output = pathDim + base;
222
+ const pathDimNoAnsi = pathDim.length - ansiCode;
223
+ const difference = longestOutput - pathDimNoAnsi - base.length;
224
+ const padLength = output.length + difference;
197
225
  cl(
198
- dim("\u251C\u2500"),
199
- `+ ${format}`,
200
- dim(path) + base,
201
- dim(`(${formatMs(file.buildTime)})`),
226
+ dim("+"),
227
+ format.padEnd(5),
228
+ output.padEnd(padLength),
229
+ dim("time"),
230
+ formatMs(file.buildTime).padEnd(7),
231
+ dim("size"),
202
232
  formatBytes(file.size)
203
233
  );
204
234
  if (file.logs) {
205
235
  for (const log of file.logs) {
206
- cl(dim("\u251C\u2500"), `! ${log.level}`, dim(path) + base, dim(log.log.message));
236
+ cl(
237
+ dim("!"),
238
+ log.level.padEnd(5),
239
+ output.padEnd(padLength),
240
+ dim(log.log.message)
241
+ );
207
242
  }
208
243
  }
209
244
  }
@@ -218,6 +253,7 @@ async function build(cwd, options) {
218
253
  };
219
254
  await hooks?.["build:start"]?.(options, buildStats);
220
255
  if (options.entries) {
256
+ const longestOutput = getLongestOutput(outDir, options.entries);
221
257
  start = Date.now();
222
258
  const aliasDir = resolve(cwd, "./src");
223
259
  let aliasOptions = {
@@ -273,7 +309,7 @@ async function build(cwd, options) {
273
309
  };
274
310
  buildStats.files.push(fileStats);
275
311
  buildStats.size = buildStats.size + stats.size;
276
- logModuleStats(fileStats);
312
+ logModuleStats(fileStats, longestOutput);
277
313
  }
278
314
  }
279
315
  if (entry.input) {
@@ -356,7 +392,7 @@ async function build(cwd, options) {
356
392
  };
357
393
  buildStats.files.push(file);
358
394
  buildStats.size = buildStats.size + stats.size;
359
- logModuleStats(file);
395
+ logModuleStats(file, longestOutput);
360
396
  await hooks?.["build:entry:end"]?.(_entry, buildStats);
361
397
  }
362
398
  if (entry.declaration) {
@@ -412,7 +448,7 @@ async function build(cwd, options) {
412
448
  };
413
449
  buildStats.files.push(fileStats);
414
450
  buildStats.size = buildStats.size + stats.size;
415
- logModuleStats(fileStats);
451
+ logModuleStats(fileStats, longestOutput);
416
452
  await hooks?.["build:entry:end"]?.(_entry, buildStats);
417
453
  }
418
454
  if (entry.template && entry.output) {
@@ -432,7 +468,7 @@ async function build(cwd, options) {
432
468
  };
433
469
  buildStats.files.push(fileStats);
434
470
  buildStats.size = buildStats.size + stats.size;
435
- logModuleStats(fileStats);
471
+ logModuleStats(fileStats, longestOutput);
436
472
  }
437
473
  }
438
474
  buildStats.buildTime = Date.now() - start;
@@ -446,35 +482,28 @@ async function createBuilder(cwd, config) {
446
482
  const { hooks } = options;
447
483
  const cl = console.log;
448
484
  await hooks?.["bundle:start"]?.(options);
449
- const line = "\u2500".repeat(logoname.length + 2);
450
- cl();
451
- cl(dim(`\u250C${line}\u2510`));
452
- cl(dim("\u2502"), `${logoname.toUpperCase()}`, dim("\u2502"), dim(`v${version}`));
453
- cl(dim(`\u2514${line}\u2518`));
454
- cl(dim(bold("i")), "Config", dim(configPath));
455
- cl(dim(bold("i")), "Bundling started...");
485
+ logger.info(dim(`v${version}`));
486
+ cl("Config", dim(configPath));
487
+ cl("Bundling started...");
456
488
  cl(
457
- dim(bold("*")),
458
489
  "Processing",
459
490
  dim(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}]`),
460
491
  "Transforming files"
461
492
  );
462
- cl(dim("\u2502"));
493
+ cl();
463
494
  await build(cwd, options).then((stats) => {
464
- const check = green(bold("\u2714"));
465
- const buildTime = green(formatMs(stats.buildTime));
466
- const buildSize = green(formatBytes(stats.size));
495
+ const buildTime = dim(formatMs(stats.buildTime));
496
+ const buildSize = dim(formatBytes(stats.size));
467
497
  const totalModules = stats.files.length;
468
- const modules = totalModules > 1 ? `${green(totalModules)} modules` : `${green(totalModules)} module`;
469
- cl(dim("\u2502"));
498
+ const modules = totalModules > 1 ? `${totalModules} modules` : `${totalModules} module`;
499
+ cl();
470
500
  cl(
471
- dim(bold("*")),
472
501
  "Succeeded",
473
502
  dim(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}]`),
474
503
  "Module transformation is done"
475
504
  );
476
- cl(check, `Bundling fully completed in ${buildTime}`);
477
- cl(check, `${modules} transformed. Total size is ${buildSize}`);
505
+ cl(`Bundling fully completed in ${buildTime}`);
506
+ cl(`${modules} transformed. Total size is ${buildSize}`);
478
507
  logger.info(`Bundle is generated and ready for production`);
479
508
  cl();
480
509
  }).catch(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/bundler",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "ESM & TS module bundler.",
6
6
  "license": "MIT",
@@ -65,12 +65,12 @@
65
65
  "@hypernym/args": "^0.3.0",
66
66
  "@hypernym/colors": "^1.0.1",
67
67
  "@hypernym/utils": "^3.4.0",
68
- "@rollup/plugin-alias": "^5.1.0",
68
+ "@rollup/plugin-alias": "^5.1.1",
69
69
  "@rollup/plugin-json": "^6.1.0",
70
- "@rollup/plugin-node-resolve": "^15.2.3",
70
+ "@rollup/plugin-node-resolve": "^15.2.4",
71
71
  "@rollup/plugin-replace": "^5.0.7",
72
- "@rollup/pluginutils": "^5.1.0",
73
- "esbuild": "^0.23.1",
72
+ "@rollup/pluginutils": "^5.1.1",
73
+ "esbuild": "^0.24.0",
74
74
  "rollup": "^4.22.4",
75
75
  "rollup-plugin-dts": "^6.1.1"
76
76
  },