Skip to content

Commit 6cb49b2

Browse files
committed
Add sortEntryPoints option
Resolves #2393
1 parent 130ba48 commit 6cb49b2

File tree

5 files changed

+58
-23
lines changed

5 files changed

+58
-23
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44

55
- Added `navigationLeaves` option to remove branches from the navigation tree, #2382.
6+
- Added `sortEntryPoints` option (defaults to true) to allow disabling entry point sorting, #2393.
67
- Improved support for multi-word searches, #2400.
78

89
### Bug Fixes

src/lib/converter/plugins/GroupPlugin.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export class GroupPlugin extends ConverterComponent {
2727
@Option("groupOrder")
2828
accessor groupOrder!: string[];
2929

30+
@Option("sortEntryPoints")
31+
accessor sortEntryPoints!: boolean;
32+
3033
usedBoosts = new Set<string>();
3134

3235
static WEIGHTS: string[] = [];
@@ -90,7 +93,14 @@ export class GroupPlugin extends ConverterComponent {
9093
reflection.children.length > 0 &&
9194
!reflection.groups
9295
) {
93-
this.sortFunction(reflection.children);
96+
if (
97+
this.sortEntryPoints ||
98+
!reflection.children.some((c) =>
99+
c.kindOf(ReflectionKind.Module),
100+
)
101+
) {
102+
this.sortFunction(reflection.children);
103+
}
94104
reflection.groups = this.getReflectionGroups(reflection.children);
95105
}
96106
}

src/lib/utils/options/declaration.ts

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export interface TypeDocOptionMap {
176176
categoryOrder: string[];
177177
groupOrder: string[];
178178
sort: SortStrategy[];
179+
sortEntryPoints: boolean;
179180
kindSortOrder: ReflectionKind.KindString[];
180181

181182
// Validation

src/lib/utils/options/sources/typedoc.ts

+6
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
686686
}
687687
},
688688
});
689+
options.addDeclaration({
690+
name: "sortEntryPoints",
691+
help: "If set, entry points will be subject to the same sorting rules as other reflections.",
692+
type: ParameterType.Boolean,
693+
defaultValue: true,
694+
});
689695
options.addDeclaration({
690696
name: "kindSortOrder",
691697
help: "Specify the sort order for reflections when 'kind' is specified.",

src/test/behavior.c2.test.ts

+39-22
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,30 @@ const base = getConverter2Base();
6969
const app = getConverter2App();
7070
const program = getConverter2Program();
7171

72-
function convert(entry: string) {
73-
const entryPoint = [
74-
join(base, `behavior/${entry}.ts`),
75-
join(base, `behavior/${entry}.d.ts`),
76-
join(base, `behavior/${entry}.tsx`),
77-
join(base, `behavior/${entry}.js`),
78-
join(base, "behavior", entry, "index.ts"),
79-
join(base, "behavior", entry, "index.js"),
80-
].find(existsSync);
81-
82-
ok(entryPoint, `No entry point found for ${entry}`);
83-
const sourceFile = program.getSourceFile(entryPoint);
84-
ok(sourceFile, `No source file found for ${entryPoint}`);
85-
86-
app.options.setValue("entryPoints", [entryPoint]);
72+
function convert(...entries: [string, ...string[]]) {
73+
const entryPoints = entries.map((entry) => {
74+
const entryPoint = [
75+
join(base, `behavior/${entry}.ts`),
76+
join(base, `behavior/${entry}.d.ts`),
77+
join(base, `behavior/${entry}.tsx`),
78+
join(base, `behavior/${entry}.js`),
79+
join(base, "behavior", entry, "index.ts"),
80+
join(base, "behavior", entry, "index.js"),
81+
].find(existsSync);
82+
83+
ok(entryPoint, `No entry point found for ${entry}`);
84+
const sourceFile = program.getSourceFile(entryPoint);
85+
ok(sourceFile, `No source file found for ${entryPoint}`);
86+
87+
return { displayName: entry, program, sourceFile, entryPoint };
88+
});
89+
90+
app.options.setValue(
91+
"entryPoints",
92+
entryPoints.map((e) => e.entryPoint),
93+
);
8794
clearCommentCache();
88-
return app.converter.convert([
89-
{
90-
displayName: entry,
91-
program,
92-
sourceFile,
93-
},
94-
]);
95+
return app.converter.convert(entryPoints);
9596
}
9697

9798
describe("Behavior Tests", () => {
@@ -953,4 +954,20 @@ describe("Behavior Tests", () => {
953954
"With Spaces",
954955
]);
955956
});
957+
958+
it("Supports disabling sorting of entry points #2393", () => {
959+
app.options.setValue("sort", ["alphabetical"]);
960+
const project = convert("blockComment", "asConstEnum");
961+
equal(project.children?.map((c) => c.name), [
962+
"asConstEnum",
963+
"blockComment",
964+
]);
965+
966+
app.options.setValue("sortEntryPoints", false);
967+
const project2 = convert("blockComment", "asConstEnum");
968+
equal(project2.children?.map((c) => c.name), [
969+
"blockComment",
970+
"asConstEnum",
971+
]);
972+
});
956973
});

0 commit comments

Comments
 (0)