Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,24 @@ async function runChecks(testFile, doSearch, parseQuery) {
return res;
}

function mostRecentMatch(staticFiles, regex) {
const matchingEntries = fs.readdirSync(staticFiles)
.filter(f => f.match(regex))
.map(f => {
const stats = fs.statSync(path.join(staticFiles, f));
return {
path: f,
time: stats.mtimeMs,
};
});
if (matchingEntries.length === 0) {
throw "No static file matching regex";
}
// We sort entries in descending order.
matchingEntries.sort((a, b) => b.time - a.time);
return matchingEntries[0].path;
}

/**
* Load searchNNN.js and search-indexNNN.js.
*
Expand All @@ -417,9 +435,9 @@ async function runChecks(testFile, doSearch, parseQuery) {
*/
async function loadSearchJS(doc_folder, resource_suffix) {
const staticFiles = path.join(doc_folder, "static.files");
const stringdexJs = fs.readdirSync(staticFiles).find(f => f.match(/stringdex.*\.js$/));
const stringdexJs = mostRecentMatch(staticFiles, /stringdex.*\.js$/);
const stringdexModule = require(path.join(staticFiles, stringdexJs));
const searchJs = fs.readdirSync(staticFiles).find(f => f.match(/search.*\.js$/));
const searchJs = mostRecentMatch(staticFiles, /search-[0-9a-f]{8}.*\.js$/);
const searchModule = require(path.join(staticFiles, searchJs));
globalThis.nonnull = (x, msg) => {
if (x === null) {
Expand Down
Loading