@@ -405,6 +405,24 @@ async function runChecks(testFile, doSearch, parseQuery) {
405
405
return res ;
406
406
}
407
407
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
+
408
426
/**
409
427
* Load searchNNN.js and search-indexNNN.js.
410
428
*
@@ -417,9 +435,9 @@ async function runChecks(testFile, doSearch, parseQuery) {
417
435
*/
418
436
async function loadSearchJS ( doc_folder , resource_suffix ) {
419
437
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 $ / ) ;
421
439
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 $ / ) ;
423
441
const searchModule = require ( path . join ( staticFiles , searchJs ) ) ;
424
442
globalThis . nonnull = ( x , msg ) => {
425
443
if ( x === null ) {
0 commit comments