tools: fix doc tool behavior for version arrays
Even though the doc tool supports version arrays in theory, it fails to sort them properly causing the tool to crash. PR-URL: https://github.com/nodejs/node/pull/22766 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
b36c581d5b
commit
1f5261b7c8
@ -43,4 +43,4 @@ function extractAndParseYAML(text) {
|
|||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { isYAMLBlock, extractAndParseYAML };
|
module.exports = { arrify, isYAMLBlock, extractAndParseYAML };
|
||||||
|
@ -308,7 +308,9 @@ function parseYAML(text) {
|
|||||||
.use(htmlStringify)
|
.use(htmlStringify)
|
||||||
.processSync(change.description).toString();
|
.processSync(change.description).toString();
|
||||||
|
|
||||||
result += `<tr><td>${change.version}</td>\n` +
|
const version = common.arrify(change.version).join(', ');
|
||||||
|
|
||||||
|
result += `<tr><td>${version}</td>\n` +
|
||||||
`<td>${description}</td></tr>\n`;
|
`<td>${description}</td></tr>\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -326,10 +328,16 @@ function parseYAML(text) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function minVersion(a) {
|
||||||
|
return common.arrify(a).reduce((min, e) => {
|
||||||
|
return !min || versionSort(min, e) < 0 ? e : min;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const numberRe = /^\d*/;
|
const numberRe = /^\d*/;
|
||||||
function versionSort(a, b) {
|
function versionSort(a, b) {
|
||||||
a = a.trim();
|
a = minVersion(a).trim();
|
||||||
b = b.trim();
|
b = minVersion(b).trim();
|
||||||
let i = 0; // Common prefix length.
|
let i = 0; // Common prefix length.
|
||||||
while (i < a.length && i < b.length && a[i] === b[i]) i++;
|
while (i < a.length && i < b.length && a[i] === b[i]) i++;
|
||||||
a = a.substr(i);
|
a = a.substr(i);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user