@@ -44,32 +44,35 @@ export function extractReason(source: string) {
4444 return ret
4545}
4646
47- const esbuildTestDir = path . join (
48- import . meta. dirname ,
49- '../../crates/rolldown/tests/esbuild' ,
50- )
51-
5247const workspaceDir = path . join ( import . meta. dirname , '../..' )
48+
5349export type AggregateReasonEntries = [ string , string [ ] ] [ ]
50+
5451export function aggregateReason ( ) : AggregateReasonEntries {
55- const entries = fg . globSync ( [ `${ esbuildTestDir } /**/diff.md` ] , { dot : false } )
52+ const entries = fg . globSync ( [ 'crates/rolldown/tests/esbuild/**/diff.md' ] , {
53+ dot : false ,
54+ cwd : workspaceDir ,
55+ } )
5656 // a map for each directory to its diff reasons
57- let reasonMap : Record < string , string [ ] > = { }
58- let reverseMap : Record < string , string [ ] > = { }
57+ let reasonToCaseDirMap : Record < string , string [ ] > = { }
5958 for ( let entry of entries ) {
60- let content = fs . readFileSync ( entry , 'utf-8' )
59+ const entryAbPath = path . resolve ( workspaceDir , entry )
60+ let content = fs . readFileSync ( entryAbPath , 'utf-8' )
6161 let reasons = extractReason ( content )
62- let dirname = path . relative ( workspaceDir , path . dirname ( entry ) )
62+ let dirname = path . relative ( workspaceDir , path . dirname ( entryAbPath ) )
63+ const posixPath = dirname . replaceAll ( '\\' , '/' )
6364
64- reasonMap [ dirname ] = reasons
6565 for ( let reason of reasons ) {
66- if ( ! reverseMap [ reason ] ) {
67- reverseMap [ reason ] = [ ]
66+ if ( ! reasonToCaseDirMap [ reason ] ) {
67+ reasonToCaseDirMap [ reason ] = [ ]
6868 }
69- reverseMap [ reason ] . push ( dirname )
69+ reasonToCaseDirMap [ reason ] . push ( posixPath )
7070 }
7171 }
72- let reverseMapEntries = Object . entries ( reverseMap )
72+ let reverseMapEntries = Object . entries ( reasonToCaseDirMap )
73+ for ( let [ _ , dirs ] of reverseMapEntries ) {
74+ dirs . sort ( )
75+ }
7376 reverseMapEntries . sort ( ( a , b ) => {
7477 return b [ 1 ] . length - a [ 1 ] . length
7578 } )
0 commit comments