Skip to content

Commit 2b4feba

Browse files
Pick the last version of the different files if there is more than one
1 parent feb6635 commit 2b4feba

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/tools/rustdoc-js-std/tester.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@ const fs = require('fs');
22
const path = require('path');
33
const tools = require('../rustdoc-js-common/lib.js');
44

5+
56
function findFile(dir, name, extension) {
67
var entries = fs.readdirSync(dir);
8+
var matches = [];
79
for (var i = 0; i < entries.length; ++i) {
810
var entry = entries[i];
911
var file_type = fs.statSync(dir + entry);
1012
if (file_type.isDirectory()) {
1113
continue;
1214
}
1315
if (entry.startsWith(name) && entry.endsWith(extension)) {
14-
return entry;
16+
var version = entry.slice(name.length, entry.length - extension.length);
17+
version = version.split(".").map(function(x) {
18+
return parseInt(x);
19+
});
20+
var total = 0;
21+
var mult = 1;
22+
for (var j = version.length - 1; j >= 0; --j) {
23+
total += version[j] * mult;
24+
mult *= 1000;
25+
}
26+
matches.push([entry, total]);
1527
}
1628
}
17-
return null;
29+
if (matches.length === 0) {
30+
return null;
31+
}
32+
// We make a reverse sort to have the "highest" file. Very useful in case you didn't clean up
33+
// you std doc folder...
34+
matches.sort(function(a, b) {
35+
return b[1] - a[1];
36+
});
37+
return matches[0][0];
1838
}
1939

2040
function readFileMatching(dir, name, extension) {

0 commit comments

Comments
 (0)