@@ -405,6 +405,24 @@ async function runChecks(testFile, doSearch, parseQuery) {
405405 return res ;
406406}
407407
408+ function mostRecentMatch ( staticFiles , regex ) {
409+ const matchingEntries = fs . readdirSync ( staticFiles )
410+ . filter ( f => f . match ( regex ) )
411+ . map ( f => {
412+ const stats = fs . statSync ( path . join ( staticFiles , f ) ) ;
413+ return {
414+ path : f ,
415+ time : stats . mtimeMs ,
416+ } ;
417+ } ) ;
418+ if ( matchingEntries . length === 0 ) {
419+ throw "No static file matching regex" ;
420+ }
421+ // We sort entries in descending order.
422+ matchingEntries . sort ( ( a , b ) => b . time - a . time ) ;
423+ return matchingEntries [ 0 ] . path ;
424+ }
425+
408426/**
409427 * Load searchNNN.js and search-indexNNN.js.
410428 *
@@ -417,9 +435,9 @@ async function runChecks(testFile, doSearch, parseQuery) {
417435 */
418436async function loadSearchJS ( doc_folder , resource_suffix ) {
419437 const staticFiles = path . join ( doc_folder , "static.files" ) ;
420- const stringdexJs = fs . readdirSync ( staticFiles ) . find ( f => f . match ( / s t r i n g d e x .* \. j s $ / ) ) ;
438+ const stringdexJs = mostRecentMatch ( staticFiles , / s t r i n g d e x .* \. j s $ / ) ;
421439 const stringdexModule = require ( path . join ( staticFiles , stringdexJs ) ) ;
422- const searchJs = fs . readdirSync ( staticFiles ) . find ( f => f . match ( / s e a r c h .* \. j s $ / ) ) ;
440+ const searchJs = mostRecentMatch ( staticFiles , / s e a r c h .* \. j s $ / ) ;
423441 const searchModule = require ( path . join ( staticFiles , searchJs ) ) ;
424442 globalThis . nonnull = ( x , msg ) => {
425443 if ( x === null ) {
0 commit comments