@@ -16,7 +16,7 @@ const NODE_MODULES_PATH_PATTERN = /node_modules(?:\/\.pnpm)?\/(.*)/
16
16
17
17
interface ModuleBuildTimeAnalyzerOptions {
18
18
compilerType : CompilerNameValues
19
- slowModuleThresholdMs : number
19
+ buildTimeThresholdMs : number
20
20
}
21
21
22
22
const getModuleIdentifier = ( module : Module ) : string => {
@@ -45,28 +45,15 @@ const getModuleDisplayName = (module: Module): string | undefined => {
45
45
}
46
46
47
47
/**
48
- * Truncates a given path to a maximum length defined by PATH_TRUNCATION_LENGTH.
49
- * If the path exceeds this length, it will be truncated in the middle and replaced with '...'.
50
- *
51
- * @param {string } path - The file path to be truncated.
52
- * @returns {string } - The truncated path if it exceeds the maximum length, otherwise the original path.
53
- *
54
- * @example
55
- * // Given a path shorter than the truncation length
56
- * truncatePath('src/components/Button.js');
57
- * // Returns: 'src/components/Button.js'
58
- *
59
- * @example
60
- * // Given a path longer than the truncation length
61
- * truncatePath('/Users/username/projects/my-app/src/components/Button.js');
62
- * // Returns: '/Users/username/proj...components/Button.js'
48
+ * Truncates a path to a maximum length. If the path exceeds this length,
49
+ * it will be truncated in the middle and replaced with '...'.
63
50
*/
64
- function truncatePath ( path : string ) : string {
51
+ function truncatePath ( path : string , maxLength : number ) : string {
65
52
// If the path length is within the limit, return it as is
66
- if ( path . length <= PATH_TRUNCATION_LENGTH ) return path
53
+ if ( path . length <= maxLength ) return path
67
54
68
55
// Calculate the available length for the start and end segments after accounting for '...'
69
- const availableLength = PATH_TRUNCATION_LENGTH - 3
56
+ const availableLength = maxLength - 3
70
57
const startSegmentLength = Math . ceil ( availableLength / 2 )
71
58
const endSegmentLength = Math . floor ( availableLength / 2 )
72
59
@@ -84,11 +71,11 @@ class ModuleBuildTimeAnalyzer {
84
71
private moduleParents = new Map < Module , Module > ( )
85
72
private moduleChildren = new Map < Module , Map < string , Module > > ( )
86
73
private isFinalized = false
87
- private slowModuleThresholdMs : number
74
+ private buildTimeThresholdMs : number
88
75
private moduleBuildTimes = new WeakMap < Module , number > ( )
89
76
90
77
constructor ( private options : ModuleBuildTimeAnalyzerOptions ) {
91
- this . slowModuleThresholdMs = options . slowModuleThresholdMs
78
+ this . buildTimeThresholdMs = options . buildTimeThresholdMs
92
79
}
93
80
94
81
recordModuleBuildTime ( module : Module , duration : number ) {
@@ -100,7 +87,7 @@ class ModuleBuildTimeAnalyzer {
100
87
)
101
88
}
102
89
103
- if ( duration < this . slowModuleThresholdMs ) {
90
+ if ( duration < this . buildTimeThresholdMs ) {
104
91
return // Skip fast modules
105
92
}
106
93
@@ -179,25 +166,24 @@ class ModuleBuildTimeAnalyzer {
179
166
const formatModuleNode = ( node : Module , depth : number ) : string => {
180
167
const moduleName = getModuleDisplayName ( node ) || ''
181
168
182
- // Skip internal/unnamed modules but continue processing their children
183
- // This keeps the report focused on meaningful source files and node_modules
184
169
if ( ! moduleName ) {
185
170
return formatChildModules ( node , depth )
186
171
}
187
172
188
- const buildTimeMs = this . moduleBuildTimes . get ( node )
173
+ const prefix =
174
+ ' ' + TreeSymbols . VERTICAL_LINE . repeat ( depth ) + TreeSymbols . BRANCH
189
175
190
- const duration =
191
- buildTimeMs && buildTimeMs > 0
192
- ? yellow ( ` (${ Math . ceil ( buildTimeMs ) } ms)` )
193
- : ''
176
+ const moduleText = blue (
177
+ truncatePath ( moduleName , PATH_TRUNCATION_LENGTH - prefix . length )
178
+ )
194
179
195
- const indentation = ' ' + TreeSymbols . VERTICAL_LINE . repeat ( depth )
196
- const moduleText = blue ( truncatePath ( moduleName ) )
180
+ const buildTimeMs = this . moduleBuildTimes . get ( node )
181
+ const duration = buildTimeMs
182
+ ? yellow ( ` (${ Math . ceil ( buildTimeMs ) } ms)` )
183
+ : ''
197
184
198
185
return (
199
- indentation +
200
- TreeSymbols . BRANCH +
186
+ prefix +
201
187
moduleText +
202
188
duration +
203
189
'\n' +
0 commit comments