Skip to content

Commit

Permalink
Add sortEntryPoints option
Browse files Browse the repository at this point in the history
Resolves #2393
  • Loading branch information
Gerrit0 committed Oct 8, 2023
1 parent 130ba48 commit 6cb49b2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

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

### Bug Fixes
Expand Down
12 changes: 11 additions & 1 deletion src/lib/converter/plugins/GroupPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class GroupPlugin extends ConverterComponent {
@Option("groupOrder")
accessor groupOrder!: string[];

@Option("sortEntryPoints")
accessor sortEntryPoints!: boolean;

usedBoosts = new Set<string>();

static WEIGHTS: string[] = [];
Expand Down Expand Up @@ -90,7 +93,14 @@ export class GroupPlugin extends ConverterComponent {
reflection.children.length > 0 &&
!reflection.groups
) {
this.sortFunction(reflection.children);
if (
this.sortEntryPoints ||
!reflection.children.some((c) =>
c.kindOf(ReflectionKind.Module),
)
) {
this.sortFunction(reflection.children);
}
reflection.groups = this.getReflectionGroups(reflection.children);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export interface TypeDocOptionMap {
categoryOrder: string[];
groupOrder: string[];
sort: SortStrategy[];
sortEntryPoints: boolean;
kindSortOrder: ReflectionKind.KindString[];

// Validation
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
}
},
});
options.addDeclaration({
name: "sortEntryPoints",
help: "If set, entry points will be subject to the same sorting rules as other reflections.",
type: ParameterType.Boolean,
defaultValue: true,
});
options.addDeclaration({
name: "kindSortOrder",
help: "Specify the sort order for reflections when 'kind' is specified.",
Expand Down
61 changes: 39 additions & 22 deletions src/test/behavior.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,30 @@ const base = getConverter2Base();
const app = getConverter2App();
const program = getConverter2Program();

function convert(entry: string) {
const entryPoint = [
join(base, `behavior/${entry}.ts`),
join(base, `behavior/${entry}.d.ts`),
join(base, `behavior/${entry}.tsx`),
join(base, `behavior/${entry}.js`),
join(base, "behavior", entry, "index.ts"),
join(base, "behavior", entry, "index.js"),
].find(existsSync);

ok(entryPoint, `No entry point found for ${entry}`);
const sourceFile = program.getSourceFile(entryPoint);
ok(sourceFile, `No source file found for ${entryPoint}`);

app.options.setValue("entryPoints", [entryPoint]);
function convert(...entries: [string, ...string[]]) {
const entryPoints = entries.map((entry) => {
const entryPoint = [
join(base, `behavior/${entry}.ts`),
join(base, `behavior/${entry}.d.ts`),
join(base, `behavior/${entry}.tsx`),
join(base, `behavior/${entry}.js`),
join(base, "behavior", entry, "index.ts"),
join(base, "behavior", entry, "index.js"),
].find(existsSync);

ok(entryPoint, `No entry point found for ${entry}`);
const sourceFile = program.getSourceFile(entryPoint);
ok(sourceFile, `No source file found for ${entryPoint}`);

return { displayName: entry, program, sourceFile, entryPoint };
});

app.options.setValue(
"entryPoints",
entryPoints.map((e) => e.entryPoint),
);
clearCommentCache();
return app.converter.convert([
{
displayName: entry,
program,
sourceFile,
},
]);
return app.converter.convert(entryPoints);
}

describe("Behavior Tests", () => {
Expand Down Expand Up @@ -953,4 +954,20 @@ describe("Behavior Tests", () => {
"With Spaces",
]);
});

it("Supports disabling sorting of entry points #2393", () => {
app.options.setValue("sort", ["alphabetical"]);
const project = convert("blockComment", "asConstEnum");
equal(project.children?.map((c) => c.name), [
"asConstEnum",
"blockComment",
]);

app.options.setValue("sortEntryPoints", false);
const project2 = convert("blockComment", "asConstEnum");
equal(project2.children?.map((c) => c.name), [
"blockComment",
"asConstEnum",
]);
});
});

0 comments on commit 6cb49b2

Please sign in to comment.