Skip to content

Commit 37f834f

Browse files
committed
Update some code to use a guaranteed stable sort
1 parent 0c73d1d commit 37f834f

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
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
}

0 commit comments

Comments
 (0)