@@ -16,16 +16,32 @@ async function cabalConfig(): Promise<string> {
1616 silent : true ,
1717 listeners : { stdout : append , stderr : append }
1818 } ) ;
19- // The last line of the cabal help text is printing the config file, e.g.:
20- //
21- // > You can edit the cabal configuration file to set defaults:
22- // > <<HOME>>/.cabal/config
23- //
24- // So trimming the last line will give us the name of the config file.
25- //
26- // Needless to say this is very brittle, but we secure this by a test
27- // in Cabal's testsuite: https://github.com/haskell/cabal/pull/9614
28- return out . toString ( ) . trim ( ) . split ( '\n' ) . slice ( - 1 ) [ 0 ] . trim ( ) ;
19+ return configFileFromHelpText ( out . toString ( ) ) ;
20+ }
21+
22+ // The end of the cabal help text is printing the config file, e.g.:
23+ //
24+ // > You can edit the cabal configuration file to set defaults:
25+ // > <<HOME>>/.cabal/config
26+ // > This file will be generated with sensible defaults if you run 'cabal update'.
27+ //
28+ // The last line here is only printed if the file does not exist yet.
29+ //
30+ // So trimming last following "You can edit..." will give us the name of the config file.
31+ //
32+ // Needless to say this is very brittle, but we secure this by a test
33+ // in Cabal's testsuite: https://github.com/haskell/cabal/pull/9614
34+ //
35+ function configFileFromHelpText ( txt : string ) : string {
36+ const marker = 'You can edit the cabal configuration file to set defaults:' ;
37+ const lines = txt . split ( '\n' ) . map ( line => line . trim ( ) ) ;
38+ const foundIndex = lines . findLastIndex ( line => line === marker ) ;
39+
40+ if ( foundIndex !== - 1 && foundIndex + 1 < lines . length ) {
41+ return lines [ foundIndex + 1 ] ;
42+ } else {
43+ return '' ;
44+ }
2945}
3046
3147export default async function run (
0 commit comments