tools: fix incorrect version history order

This fixes an error in parseYAML(text), the version sorting
coudn't be right as we compared an arrify string
(ie. a = ["v18.11, v16.7.0"]) with an array of strings
(ie. b = ["v18.07", "v16.7.0"]) in versionSort(a, b).

minVersion(a) couldn't find the minimum version with an arrify string
like a = ["v18.11, v16.7.0"].
That's why incorrect version history orders sometimes appeared.

Furthermore, no need to sort the added version as it always comes first.
So, it can be the last one to be pushed in the meta.changes array.

Fixes: https://github.com/nodejs/node/issues/45670

Co-authored-by: Luigi Pinca <luigipinca@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/45728
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Fabien Michel
2022-12-14 10:38:36 +01:00
committed by GitHub
parent cf0a42cf11
commit bfb5ba7776
2 changed files with 10 additions and 9 deletions

View File

@@ -79,10 +79,11 @@ const testData = [
'<div class="api_metadata">' +
'<details class="changelog"><summary>History</summary>' +
'<table><tbody><tr><th>Version</th><th>Changes</th></tr>' +
'<tr><td>v4.2.0</td><td><p>The <code>error</code> parameter can now be' +
'an arrow function.</p></td></tr>' +
'<tr><td>v5.3.0, v4.2.0</td>' +
'<td><p><span>Added in: v5.3.0, v4.2.0</span></p></td></tr>' +
'<tr><td>v4.2.0</td><td><p>The <code>error</code> parameter can now be' +
'an arrow function.</p></td></tr></tbody></table></details></div> ' +
'</tbody></table></details></div> ' +
'<p>Describe <code>Foobar II</code> in more detail here.' +
'<a href="http://man7.org/linux/man-pages/man1/fg.1.html"><code>fg(1)' +
'</code></a></p></section><section>' +

View File

@@ -325,27 +325,27 @@ function parseYAML(text) {
const removed = { description: '' };
if (meta.added) {
added.version = meta.added.join(', ');
added.description = `<span>Added in: ${added.version}</span>`;
added.version = meta.added;
added.description = `<span>Added in: ${added.version.join(', ')}</span>`;
}
if (meta.deprecated) {
deprecated.version = meta.deprecated.join(', ');
deprecated.version = meta.deprecated;
deprecated.description =
`<span>Deprecated since: ${deprecated.version}</span>`;
`<span>Deprecated since: ${deprecated.version.join(', ')}</span>`;
}
if (meta.removed) {
removed.version = meta.removed.join(', ');
removed.description = `<span>Removed in: ${removed.version}</span>`;
removed.version = meta.removed;
removed.description = `<span>Removed in: ${removed.version.join(', ')}</span>`;
}
if (meta.changes.length > 0) {
if (added.description) meta.changes.push(added);
if (deprecated.description) meta.changes.push(deprecated);
if (removed.description) meta.changes.push(removed);
meta.changes.sort((a, b) => versionSort(a.version, b.version));
if (added.description) meta.changes.push(added);
result += '<details class="changelog"><summary>History</summary>\n' +
'<table>\n<tr><th>Version</th><th>Changes</th></tr>\n';