diff --git a/src/app/bootstrap.ts b/src/app/bootstrap.ts index e6ed79b2..4cbe2737 100644 --- a/src/app/bootstrap.ts +++ b/src/app/bootstrap.ts @@ -50,7 +50,7 @@ function initDev( exampleFiles: ExampleFilesPayload ): void { ].map( ( filename ) => ( { path: join( exampleFilesDir, 'phylip', filename ), } ) ); - const useFiles = [].concat( useFastaFiles, usePhylipFiles ); + const useFiles = [ ...useFastaFiles, ...usePhylipFiles ]; store.activeRun.addAlignments( useFiles ); store.activeRun.setOutputDir( exampleFiles.outdir ); setTimeout( () => { diff --git a/src/app/paths.ts b/src/app/paths.ts index 75abd603..b6e25111 100644 --- a/src/app/paths.ts +++ b/src/app/paths.ts @@ -12,7 +12,8 @@ const stemOf = ( baseName: string ): string => { const parsed = ( filePath: string ): { base: string; name: string; dir: string } => { const sep = sepOf( filePath ); const chunks = filePath.split( /[/\\]/ ); - const baseName = chunks.pop(); + // split() always returns at least one chunk, so pop() never yields undefined. + const baseName = chunks.pop() ?? ''; let directory = ''; if ( chunks.length === 1 && chunks[0] === '' ) { directory = sep; diff --git a/src/main/modelSelection.ts b/src/main/modelSelection.ts index 7ef2f94e..a463be17 100644 --- a/src/main/modelSelection.ts +++ b/src/main/modelSelection.ts @@ -119,9 +119,12 @@ export async function runModelSelection( // Each '> [program]' is written three times, for BIC, AIC and AICc respectively. Use AICc. const cmdRaxml = commands.filter( ( cmd ) => cmd.startsWith( ' > raxmlHPC-SSE3' ) )[2]; const cmdRaxmlNG = commands.filter( ( cmd ) => cmd.startsWith( ' > raxml-ng' ) )[2]; - const modelRaxml = /-m (\S+)/.exec( cmdRaxml )[1]; + const modelRaxml = /-m (\S+)/.exec( cmdRaxml )?.[1]; const extraFlag = /--(\S+)/.exec( cmdRaxml )?.[0]; - const modelRaxmlNG = /--model (\S+)/.exec( cmdRaxmlNG )[1]; + const modelRaxmlNG = /--model (\S+)/.exec( cmdRaxmlNG )?.[1]; + if ( !modelRaxml || !modelRaxmlNG ) { + throw new Error( 'No best-model command in modeltest-ng output' ); + } console.log( `-> raxml: ${modelRaxml}, extraFlag: ${extraFlag}, raxml-ng: ${modelRaxmlNG}` ); send( event, ipc.ALIGNMENT_MODEL_SELECTION_SUCCESS, { id, diff --git a/src/main/processHelpers.ts b/src/main/processHelpers.ts index fee48079..a7ec9034 100644 --- a/src/main/processHelpers.ts +++ b/src/main/processHelpers.ts @@ -103,14 +103,15 @@ export async function runProcess( let exited = false; // Last stdout only: the binary prints its fatal reason just before exiting. let stdoutTail = ''; - proc.stdout.on( 'data', ( buffer: string | Buffer ) => { + // execFile always opens stdout and stderr pipes; the optional chain only satisfies their nullable type. + proc.stdout?.on( 'data', ( buffer: string | Buffer ) => { const content = String( buffer ); stdoutTail = ( stdoutTail + content ).slice( -8192 ); console.log( 'on stdout:', content ); onStdOut( content ); send( event, ipc.RUN_STDOUT, { id, content } ); } ); - proc.stderr.on( 'data', ( buffer: string | Buffer ) => { + proc.stderr?.on( 'data', ( buffer: string | Buffer ) => { const content = String( buffer ); console.error( 'on stderr:', content ); onStdErr( content );