@@ -34,6 +34,7 @@ if (snapshotArg === "--snapshot=") {
3434
3535const ver = raw . replace ( / ^ v / , "" )
3636const root = path . resolve ( import . meta. dir , ".." )
37+ const lockfile = path . join ( root , "bun.lock" )
3738const skip = new Set ( [ ".git" , ".opencode" , ".turbo" , "dist" , "node_modules" ] )
3839const keys = [ "@opentui/core" , "@opentui/keymap" , "@opentui/solid" ] as const
3940
@@ -115,11 +116,77 @@ const out = (
115116) . filter ( ( item ) : item is string => item !== null )
116117
117118if ( out . length === 0 ) {
118- console . log ( "No opentui deps found" )
119- process . exit ( 0 )
119+ console . log ( `No opentui manifest updates needed for ${ ver } ` )
120+ }
121+
122+ if ( out . length > 0 ) {
123+ console . log ( `Updated opentui${ snapshot ? " snapshot" : "" } to ${ ver } in:` )
124+ for ( const file of out ) {
125+ console . log ( `- ${ file } ` )
126+ }
127+ }
128+
129+ console . log ( "Running bun install to update bun.lock..." )
130+ const install = Bun . spawn ( [ process . execPath , "install" ] , {
131+ cwd : root ,
132+ stdout : "inherit" ,
133+ stderr : "inherit" ,
134+ } )
135+ const installCode = await install . exited
136+ if ( installCode !== 0 ) process . exit ( installCode )
137+
138+ const fixed = await fixKnownLockfileIssues ( )
139+ if ( fixed . length > 0 ) {
140+ console . log ( "Removed stale opentui-spinner peer lockfile entries:" )
141+ for ( const item of fixed ) {
142+ console . log ( `- ${ item } ` )
143+ }
144+ }
145+
146+ const stale = await findStaleLockfileEntries ( )
147+ if ( stale . length > 0 ) {
148+ console . error ( `bun.lock still contains stale opentui versions after upgrading to ${ ver } :` )
149+ for ( const item of stale ) {
150+ console . error ( `- ${ item . entry } : ${ item . pkg } @${ item . version } ` )
151+ }
152+ process . exit ( 1 )
153+ }
154+
155+ console . log ( "bun.lock opentui versions are consistent" )
156+
157+ async function fixKnownLockfileIssues ( ) {
158+ const txt = await Bun . file ( lockfile ) . text ( )
159+ const stale = findStaleLockfileEntriesInText ( txt )
160+ if ( stale . length === 0 ) return [ ]
161+ if ( stale . some ( ( item ) => ! item . entry . startsWith ( "opentui-spinner/@opentui/" ) ) ) return [ ]
162+
163+ const removed = txt
164+ . split ( "\n" )
165+ . map ( ( line ) => line . match ( / ^ " ( o p e n t u i - s p i n n e r \/ @ o p e n t u i \/ [ ^ \" ] + ) " : / ) ?. [ 1 ] )
166+ . filter ( ( item ) : item is string => item !== undefined )
167+
168+ if ( removed . length === 0 ) return [ ]
169+
170+ await Bun . write (
171+ lockfile ,
172+ txt
173+ . split ( "\n" )
174+ . filter ( ( line ) => ! line . match ( / ^ " o p e n t u i - s p i n n e r \/ @ o p e n t u i \/ / ) )
175+ . join ( "\n" ) ,
176+ )
177+ return removed
178+ }
179+
180+ async function findStaleLockfileEntries ( ) {
181+ return findStaleLockfileEntriesInText ( await Bun . file ( lockfile ) . text ( ) )
120182}
121183
122- console . log ( `Updated opentui${ snapshot ? " snapshot" : "" } to ${ ver } in:` )
123- for ( const file of out ) {
124- console . log ( `- ${ file } ` )
184+ function findStaleLockfileEntriesInText ( txt : string ) {
185+ return Array . from ( txt . matchAll ( / ^ " ( [ ^ " ] + ) " : \[ " ( @ o p e n t u i \/ (?: c o r e (?: - [ ^ @ " ] + ) ? | k e y m a p | s o l i d ) ) @ ( [ ^ " ] + ) " / gm) )
186+ . map ( ( match ) => ( {
187+ entry : match [ 1 ] ! ,
188+ pkg : match [ 2 ] ! ,
189+ version : match [ 3 ] ! ,
190+ } ) )
191+ . filter ( ( item ) => item . version !== ver )
125192}
0 commit comments