Skip to content

Commit 98b1a89

Browse files
authored
chore: fix documentComponents functions signature (#61)
1 parent 671bd2c commit 98b1a89

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

src/components/index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,41 @@ function componentNameFromPath(componentPath: string) {
1616
}
1717

1818
export interface DocumenterOptions {
19+
tsconfigPath: string;
20+
publicFilesGlob: string;
1921
extraExports?: Record<string, Array<string>>;
2022
}
21-
2223
export function documentComponents(
2324
tsconfigPath: string,
2425
publicFilesGlob: string,
2526
// deprecated, now unused
2627
additionalInputFilePaths?: Array<string>,
2728
options?: DocumenterOptions
29+
): Array<ComponentDefinition>;
30+
export function documentComponents(options: DocumenterOptions): Array<ComponentDefinition>;
31+
export function documentComponents(
32+
...args:
33+
| [
34+
tsconfigPath: string,
35+
publicFilesGlob: string,
36+
additionalInputFilePaths?: Array<string>,
37+
options?: DocumenterOptions
38+
]
39+
| [options: DocumenterOptions]
2840
): Array<ComponentDefinition> {
29-
const program = bootstrapTypescriptProject(tsconfigPath);
41+
const options =
42+
args.length === 1
43+
? args[0]
44+
: {
45+
tsconfigPath: args[0],
46+
publicFilesGlob: args[1],
47+
additionalInputFilePaths: args[2],
48+
...args[3],
49+
};
50+
const program = bootstrapTypescriptProject(options.tsconfigPath);
3051
const checker = program.getTypeChecker();
3152

32-
const isMatch = matcher(pathe.resolve(publicFilesGlob));
53+
const isMatch = matcher(pathe.resolve(options.publicFilesGlob));
3354

3455
return program
3556
.getSourceFiles()

test/components/legacy.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { documentComponents } from '../../src';
4+
5+
test('legacy API works', () => {
6+
const definitions = documentComponents(
7+
require.resolve(`../../fixtures/components/simple/tsconfig.json`),
8+
`fixtures/components/simple/*/index.tsx`
9+
);
10+
expect(definitions).toHaveLength(1);
11+
});

test/components/test-helpers.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import ts from 'typescript';
44
import { ProjectReflection } from 'typedoc';
5-
import { ComponentDefinition, documentComponents, documentTestUtils } from '../../src';
5+
import { documentComponents, documentTestUtils } from '../../src';
66
import { bootstrapProject } from '../../src/bootstrap';
77
import { TestUtilsDoc } from '../../src/test-utils/interfaces';
88
import { DocumenterOptions } from '../../src/components';
99

10-
export function buildProject(name: string, options?: DocumenterOptions): ComponentDefinition[] {
11-
return documentComponents(
12-
require.resolve(`../../fixtures/components/${name}/tsconfig.json`),
13-
`fixtures/components/${name}/*/index.tsx`,
14-
undefined,
15-
options
16-
);
10+
export function buildProject(name: string, options?: Partial<DocumenterOptions>) {
11+
return documentComponents({
12+
tsconfigPath: require.resolve(`../../fixtures/components/${name}/tsconfig.json`),
13+
publicFilesGlob: `fixtures/components/${name}/*/index.tsx`,
14+
...options,
15+
});
1716
}
1817

1918
export function buildTestUtilsProject(name: string, testGlob?: string): TestUtilsDoc[] {

0 commit comments

Comments
 (0)