From 77d6ee0f351b5d058b96f6940e96221515a7acee Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 13 Aug 2025 17:26:16 +0200 Subject: [PATCH 1/2] Fix bug where `rustdoc-js` tester would not pick the right `search.js` file if there is more than one --- src/tools/rustdoc-js/tester.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index a1e632ce74334..063dfa6b5ceac 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -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. * @@ -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.*\.js$/); const searchModule = require(path.join(staticFiles, searchJs)); globalThis.nonnull = (x, msg) => { if (x === null) { From 2ebe679d18359c23e040c47a82451ed9bb38235a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 16 Aug 2025 23:57:15 +0200 Subject: [PATCH 2/2] Strenghten rustdoc js tester file macthing regex --- src/tools/rustdoc-js/tester.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 063dfa6b5ceac..ff809d58e907c 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -437,7 +437,7 @@ async function loadSearchJS(doc_folder, resource_suffix) { const staticFiles = path.join(doc_folder, "static.files"); const stringdexJs = mostRecentMatch(staticFiles, /stringdex.*\.js$/); const stringdexModule = require(path.join(staticFiles, stringdexJs)); - const searchJs = mostRecentMatch(staticFiles, /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) {