Skip to content

Commit 3c76b67

Browse files
Fix bug where rustdoc-js tester would not pick the right search.js file if there is more than one
1 parent a6620a4 commit 3c76b67

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/tools/rustdoc-js/tester.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,21 @@ async function runChecks(testFile, doSearch, parseQuery, getCorrections) {
409409
return res;
410410
}
411411

412+
function mostRecentMatch(staticFiles, regex) {
413+
const matchingEntries = fs.readdirSync(staticFiles)
414+
.filter(f => f.match(regex))
415+
.map(f => {
416+
const stats = fs.statSync(path.join(staticFiles, f));
417+
return {
418+
path: f,
419+
time: stats.mtimeMs,
420+
};
421+
});
422+
// We sort entries in descending order.
423+
matchingEntries.sort((a, b) => b.time - a.time);
424+
return matchingEntries[0].path;
425+
}
426+
412427
/**
413428
* Load searchNNN.js and search-indexNNN.js.
414429
*
@@ -452,7 +467,7 @@ function loadSearchJS(doc_folder, resource_suffix) {
452467
};
453468

454469
const staticFiles = path.join(doc_folder, "static.files");
455-
const searchJs = fs.readdirSync(staticFiles).find(f => f.match(/search.*\.js$/));
470+
const searchJs = mostRecentMatch(staticFiles, /search.*\.js$/);
456471
const searchModule = require(path.join(staticFiles, searchJs));
457472
searchModule.initSearch(searchIndex.searchIndex);
458473
const docSearch = searchModule.docSearch;

0 commit comments

Comments
 (0)