@@ -29,55 +29,38 @@ const headerBadge = (conflicts: UnifiedBranchConflict[]): string => {
2929 ) ;
3030} ;
3131
32- const footer = ( ) : string [ ] => {
33- return [
34- '' ,
35- chalk . gray ( 'Please refer to our guide on how to resolve such conflicts:' ) ,
36- chalk . bold . underline . blue ( 'https://orm.drizzle.team/docs/migrations' ) ,
37- '' ,
38- ] ;
39- } ;
40-
41- export const renderSuccess = ( ) : string => {
42- return `\n[${ chalk . green ( '✓' ) } ] All migrations are commutative. No conflicts detected.\n` ;
43- } ;
44-
4532export const renderReportDirectory = (
4633 report : NonCommutativityReport ,
4734) : string => {
4835 const { conflicts } = report ;
4936 const lines : string [ ] = [ '' , headerBadge ( conflicts ) , '' ] ;
5037
51- // Group conflicts by parentId so we can render N branches per parent
52- const byParent = new Map < string , UnifiedBranchConflict [ ] > ( ) ;
38+ // Group conflicts by parentId
39+ const byParent : Record < string , UnifiedBranchConflict [ ] > = { } ;
5340 for ( const c of conflicts ) {
54- const key = c . parentId ;
55- if ( ! byParent . has ( key ) ) byParent . set ( key , [ ] ) ;
56- byParent . get ( key ) ! . push ( c ) ;
41+ ( byParent [ c . parentId ] ??= [ ] ) . push ( c ) ;
5742 }
5843
59- const parentEntries = [ ... byParent . entries ( ) ] ;
44+ const parentEntries = Object . entries ( byParent ) ;
6045
6146 for ( let p = 0 ; p < parentEntries . length ; p ++ ) {
6247 const [ parentId , parentConflicts ] = parentEntries [ p ] ;
6348 const parentLabel = parentConflicts [ 0 ] . parentPath ?? parentId ;
6449
65- // Collect all unique branches ( dedupe by leaf id)
50+ // Collect unique branches, dedupe by leaf id
6651 const branches : { chain : MigrationNode [ ] ; descriptions : string [ ] } [ ] = [ ] ;
67- const seenLeafs = new Map < string , number > ( ) ; // leaf id -> index in branches
52+ const seenLeafs : Record < string , number > = { } ;
6853
6954 for ( const c of parentConflicts ) {
7055 for ( const branch of [ c . branchA , c . branchB ] ) {
7156 const leafId = branch . chain [ branch . chain . length - 1 ] ?. id ?? '' ;
72- if ( seenLeafs . has ( leafId ) ) {
73- const idx = seenLeafs . get ( leafId ) ! ;
74- if (
75- ! branches [ idx ] . descriptions . includes ( branch . statementDescription )
76- ) {
77- branches [ idx ] . descriptions . push ( branch . statementDescription ) ;
57+ if ( leafId in seenLeafs ) {
58+ const descs = branches [ seenLeafs [ leafId ] ] . descriptions ;
59+ if ( ! descs . includes ( branch . statementDescription ) ) {
60+ descs . push ( branch . statementDescription ) ;
7861 }
7962 } else {
80- seenLeafs . set ( leafId , branches . length ) ;
63+ seenLeafs [ leafId ] = branches . length ;
8164 branches . push ( {
8265 chain : branch . chain ,
8366 descriptions : [ branch . statementDescription ] ,
@@ -86,58 +69,43 @@ export const renderReportDirectory = (
8669 }
8770 }
8871
89- // Parent node (root of this group)
9072 lines . push ( ` ${ chalk . white ( parentLabel ) } ` ) ;
9173
9274 for ( let b = 0 ; b < branches . length ; b ++ ) {
93- const branch = branches [ b ] ;
94- const isLastBranch = b === branches . length - 1 ;
95- const branchPrefix = isLastBranch ? ' ' : '│ ' ;
96-
97- // Render each migration in the chain on its own line
98- for ( let m = 0 ; m < branch . chain . length ; m ++ ) {
99- const node = branch . chain [ m ] ;
100- const isFirstInChain = m === 0 ;
101- const isLeaf = m === branch . chain . length - 1 ;
102-
103- const label = isLeaf
104- ? chalk . red . bold ( node . path )
105- : chalk . green ( node . path ) ;
106-
107- if ( isFirstInChain ) {
108- // First migration gets the branch connector (├── or └──)
109- const connector = isLastBranch ? '└──' : '├──' ;
110- lines . push ( ` ${ chalk . gray ( connector ) } ${ label } ` ) ;
111- } else {
112- // Subsequent migrations: plain text under the branch prefix, no connector
113- lines . push ( ` ${ chalk . gray ( branchPrefix ) } ${ label } ` ) ;
114- }
75+ const { chain, descriptions } = branches [ b ] ;
76+ const isLast = b === branches . length - 1 ;
77+ const prefix = isLast ? ' ' : '│ ' ;
78+
79+ for ( let m = 0 ; m < chain . length ; m ++ ) {
80+ const label = m === chain . length - 1
81+ ? chalk . red . bold ( chain [ m ] . path )
82+ : chalk . green ( chain [ m ] . path ) ;
83+
84+ lines . push (
85+ m === 0
86+ ? ` ${ chalk . gray ( isLast ? '└──' : '├──' ) } ${ label } `
87+ : ` ${ chalk . gray ( prefix ) } ${ label } ` ,
88+ ) ;
11589 }
11690
117- // Conflict descriptions beneath the chain with single-dash connectors
118- for ( let d = 0 ; d < branch . descriptions . length ; d ++ ) {
119- const isLastDesc = d === branch . descriptions . length - 1 ;
120- const descConnector = isLastDesc ? '└─' : '├─' ;
91+ for ( let d = 0 ; d < descriptions . length ; d ++ ) {
92+ const connector = d === descriptions . length - 1 ? '└─' : '├─' ;
12193 lines . push (
122- ` ${ chalk . gray ( branchPrefix ) } ${ chalk . gray ( descConnector ) } ${ chalk . yellow ( '⚠' ) } ${
123- chalk . yellow (
124- branch . descriptions [ d ] ,
125- )
126- } `,
94+ ` ${ chalk . gray ( prefix ) } ${ chalk . gray ( connector ) } ${ chalk . yellow ( '⚠' ) } ${ chalk . yellow ( descriptions [ d ] ) } ` ,
12795 ) ;
12896 }
12997 }
13098
131- // Add spacing between parent groups
13299 if ( p < parentEntries . length - 1 ) lines . push ( '' ) ;
133100 }
134101
135- lines . push ( ...footer ( ) ) ;
102+ lines . push (
103+ chalk . gray ( '\nPlease refer to our guide on how to resolve such conflicts:' ) ,
104+ chalk . bold . underline . blue ( 'https://orm.drizzle.team/docs/migrations' ) ,
105+ ) ;
136106 return lines . join ( '\n' ) ;
137107} ;
138108
139- // ─── Handler ─────────────────────────────────────────────────────────────────
140-
141109export const checkHandler = async (
142110 out : string ,
143111 dialect : Dialect ,
@@ -178,7 +146,6 @@ export const checkHandler = async (
178146 try {
179147 const response = await detectNonCommutative ( snapshots , dialect ) ;
180148 if ( response . conflicts . length === 0 ) {
181- // render(renderSuccess());
182149 return ;
183150 }
184151
0 commit comments