X Tutup
Skip to content

Commit 7263c1a

Browse files
authored
Merge pull request microsoft#1613 from microsoft/octogonz/stable-sort
[api-extractor] Fix inconsistent sorting of APIs on older NodeJS versions
2 parents 50ee00f + 07a99db commit 7263c1a

File tree

13 files changed

+262
-157
lines changed

13 files changed

+262
-157
lines changed

apps/api-extractor-model/src/mixins/ApiItemContainerMixin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '../items/ApiItem';
1212
import { ApiNameMixin } from './ApiNameMixin';
1313
import { DeserializerContext } from '../model/DeserializerContext';
14-
import { InternalError } from '@microsoft/node-core-library';
14+
import { InternalError, LegacyAdapters } from '@microsoft/node-core-library';
1515

1616
/**
1717
* Constructor options for {@link (ApiItemContainerMixin:interface)}.
@@ -145,7 +145,7 @@ export function ApiItemContainerMixin<TBaseClass extends IApiItemConstructor>(ba
145145

146146
public get members(): ReadonlyArray<ApiItem> {
147147
if (!this[_membersSorted]) {
148-
this[_members].sort((x, y) => x.getSortKey().localeCompare(y.getSortKey()));
148+
LegacyAdapters.sortStable(this[_members], (x, y) => x.getSortKey().localeCompare(y.getSortKey()));
149149
this[_membersSorted] = true;
150150
}
151151

apps/api-extractor/src/collector/MessageRouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as colors from 'colors';
55
import * as ts from 'typescript';
66
import * as tsdoc from '@microsoft/tsdoc';
7-
import { Sort, InternalError } from '@microsoft/node-core-library';
7+
import { Sort, InternalError, LegacyAdapters } from '@microsoft/node-core-library';
88
import { AedocDefinitions } from '@microsoft/api-extractor-model';
99

1010
import { TypeScriptMessageFormatter } from '../analyzer/TypeScriptMessageFormatter';
@@ -563,7 +563,7 @@ export class MessageRouter {
563563
* Sorts an array of messages according to a reasonable ordering
564564
*/
565565
private _sortMessagesForOutput(messages: ExtractorMessage[]): void {
566-
messages.sort((a, b) => {
566+
LegacyAdapters.sortStable(messages, (a, b) => {
567567
let diff: number;
568568
// First sort by file name
569569
diff = Sort.compareByValue(a.sourceFilePath, b.sourceFilePath);

apps/rush-lib/src/logic/taskRunner/TaskCollection.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import {
55
Terminal,
6-
ConsoleTerminalProvider
6+
ConsoleTerminalProvider,
7+
Sort
78
} from '@microsoft/node-core-library';
89

910
import { ITask, ITaskDefinition } from './ITask';
@@ -105,9 +106,7 @@ export class TaskCollection {
105106
});
106107

107108
// Sort the queue in descending order, nothing will mess with the order
108-
buildQueue.sort((taskA: ITask, taskB: ITask): number => {
109-
return taskB.criticalPathLength! - taskA.criticalPathLength!;
110-
});
109+
Sort.sortBy(buildQueue, (task: ITask): number => -task.criticalPathLength!);
111110

112111
return buildQueue;
113112
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor-model",
5+
"comment": "Fix an issue where API reports sometimes were ordered differently depending on the version of NodeJS (GitHub #1552)",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor-model",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fix an issue where API reports sometimes were ordered differently depending on the version of NodeJS (GitHub #1552)",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/node-core-library",
5+
"comment": "Add new API LegacyAdapters.stableSort(), and update the Sort API to be stable",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/node-core-library",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Fix an issue where certain operations did not use a stable sort when executed on older versions of NodeJS",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}

common/config/rush/nonbrowser-approved-packages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"name": "@microsoft/api-documenter",
77
"allowedCategories": [ "libraries", "tests" ]
88
},
9+
{
10+
"name": "timsort",
11+
"allowedCategories": [ "libraries" ]
12+
},
913
{
1014
"name": "@microsoft/api-extractor",
1115
"allowedCategories": [ "libraries", "tests" ]

0 commit comments

Comments
 (0)
X Tutup