@@ -11,18 +11,27 @@ import resolvePlugin from '@rollup/plugin-node-resolve'
1111import aliasPlugin from '@rollup/plugin-alias'
1212import { dts as dtsPlugin } from 'rollup-plugin-dts'
1313import { esbuild as esbuildPlugin } from '@/utils/plugins/esbuild'
14- import { getOutputPath , formatMs , formatBytes , error } from '@/utils'
14+ import {
15+ getOutputPath ,
16+ getLongestOutput ,
17+ formatMs ,
18+ formatBytes ,
19+ error ,
20+ } from '@/utils'
1521import type { ModuleFormat } from 'rollup'
1622import type { RollupAliasOptions } from '@rollup/plugin-alias'
1723import type { Options , BuildStats , BuildLogs } from '@/types'
1824
19- function logModuleStats ( file : {
20- format : string
21- path : string
22- buildTime : number
23- size : number
24- logs : BuildLogs [ ]
25- } ) {
25+ function logModuleStats (
26+ file : {
27+ format : string
28+ path : string
29+ buildTime : number
30+ size : number
31+ logs : BuildLogs [ ]
32+ } ,
33+ longestOutput : number ,
34+ ) {
2635 const cl = console . log
2736 const base = parse ( file . path ) . base
2837 const path = file . path . replace ( base , '' )
@@ -32,17 +41,32 @@ function logModuleStats(file: {
3241 if ( format === 'commonjs' ) format = 'cjs'
3342 if ( format === 'module' ) format = 'esm'
3443
44+ longestOutput = longestOutput + 2
45+ const ansiCode = 9
46+ const pathDim = dim ( path )
47+ const output = pathDim + base
48+ const pathDimNoAnsi = pathDim . length - ansiCode
49+ const difference = longestOutput - pathDimNoAnsi - base . length
50+ const padLength = output . length + difference
51+
3552 cl (
36- dim ( '├─' ) ,
37- `+ ${ format } ` ,
38- dim ( path ) + base ,
39- dim ( `(${ formatMs ( file . buildTime ) } )` ) ,
53+ dim ( '+' ) ,
54+ format . padEnd ( 5 ) ,
55+ output . padEnd ( padLength ) ,
56+ dim ( 'time' ) ,
57+ formatMs ( file . buildTime ) . padEnd ( 7 ) ,
58+ dim ( 'size' ) ,
4059 formatBytes ( file . size ) ,
4160 )
4261
4362 if ( file . logs ) {
4463 for ( const log of file . logs ) {
45- cl ( dim ( '├─' ) , `! ${ log . level } ` , dim ( path ) + base , dim ( log . log . message ) )
64+ cl (
65+ dim ( '!' ) ,
66+ log . level . padEnd ( 5 ) ,
67+ output . padEnd ( padLength ) ,
68+ dim ( log . log . message ) ,
69+ )
4670 }
4771 }
4872}
@@ -64,6 +88,8 @@ export async function build(
6488 await hooks ?. [ 'build:start' ] ?.( options , buildStats )
6589
6690 if ( options . entries ) {
91+ const longestOutput = getLongestOutput ( outDir , options . entries )
92+
6793 start = Date . now ( )
6894
6995 const aliasDir = resolve ( cwd , './src' )
@@ -133,7 +159,7 @@ export async function build(
133159 buildStats . files . push ( fileStats )
134160 buildStats . size = buildStats . size + stats . size
135161
136- logModuleStats ( fileStats )
162+ logModuleStats ( fileStats , longestOutput )
137163 }
138164 }
139165
@@ -234,7 +260,7 @@ export async function build(
234260 buildStats . files . push ( file )
235261 buildStats . size = buildStats . size + stats . size
236262
237- logModuleStats ( file )
263+ logModuleStats ( file , longestOutput )
238264
239265 await hooks ?. [ 'build:entry:end' ] ?.( _entry , buildStats )
240266 }
@@ -300,7 +326,7 @@ export async function build(
300326 buildStats . files . push ( fileStats )
301327 buildStats . size = buildStats . size + stats . size
302328
303- logModuleStats ( fileStats )
329+ logModuleStats ( fileStats , longestOutput )
304330
305331 await hooks ?. [ 'build:entry:end' ] ?.( _entry , buildStats )
306332 }
@@ -328,7 +354,7 @@ export async function build(
328354 buildStats . files . push ( fileStats )
329355 buildStats . size = buildStats . size + stats . size
330356
331- logModuleStats ( fileStats )
357+ logModuleStats ( fileStats , longestOutput )
332358 }
333359 }
334360
0 commit comments