@@ -25,7 +25,7 @@ export class TypeDocReader implements OptionsReader {
25
25
*/
26
26
read ( container : Options , logger : Logger ) : void {
27
27
const path = container . getValue ( 'options' ) ;
28
- const file = this . findTypedocFile ( path , logger ) ;
28
+ const file = this . findTypedocFile ( path ) ;
29
29
30
30
if ( ! file ) {
31
31
if ( ! container . isDefault ( 'options' ) ) {
@@ -34,15 +34,43 @@ export class TypeDocReader implements OptionsReader {
34
34
return ;
35
35
}
36
36
37
- let data : any = require ( file ) ;
38
- if ( typeof data !== 'object' ) {
37
+ const seen = new Set < string > ( ) ;
38
+ this . readFile ( file , container , logger , seen ) ;
39
+ }
40
+
41
+ /**
42
+ * Read the given options file + any extended files.
43
+ * @param file
44
+ * @param container
45
+ * @param logger
46
+ */
47
+ private readFile ( file : string , container : Options , logger : Logger , seen : Set < string > ) {
48
+ if ( seen . has ( file ) ) {
49
+ logger . error ( `Tried to load the options file ${ file } multiple times.` ) ;
50
+ return ;
51
+ }
52
+ seen . add ( file ) ;
53
+
54
+ const data : unknown = require ( file ) ;
55
+
56
+ if ( typeof data !== 'object' || ! data ) {
39
57
logger . error ( `The file ${ file } is not an object.` ) ;
40
58
return ;
41
59
}
60
+
61
+ if ( 'extends' in data ) {
62
+ const extended : string [ ] = getStringArray ( data [ 'extends' ] ) ;
63
+ for ( const extendedFile of extended ) {
64
+ // Extends is relative to the file it appears in.
65
+ this . readFile ( Path . resolve ( Path . dirname ( file ) , extendedFile ) , container , logger , seen ) ;
66
+ }
67
+ delete data [ 'extends' ] ;
68
+ }
69
+
42
70
// deprecate: data.src is alias to inputFiles as of 0.16, warn in 0.17, remove in 0.19
43
71
if ( 'src' in data && ! ( 'inputFiles' in data ) ) {
44
- data . inputFiles = Array . isArray ( data . src ) ? data . src : [ data . src ] ;
45
- delete data . src ;
72
+ data [ ' inputFiles' ] = getStringArray ( data [ ' src' ] ) ;
73
+ delete data [ ' src' ] ;
46
74
}
47
75
48
76
container . setValues ( data ) . match ( {
@@ -63,7 +91,7 @@ export class TypeDocReader implements OptionsReader {
63
91
* @param logger
64
92
* @return the typedoc.(js|json) file path or undefined
65
93
*/
66
- private findTypedocFile ( path : string , logger : Logger ) : string | undefined {
94
+ private findTypedocFile ( path : string ) : string | undefined {
67
95
path = Path . resolve ( path ) ;
68
96
69
97
return [
@@ -73,3 +101,7 @@ export class TypeDocReader implements OptionsReader {
73
101
] . find ( path => FS . existsSync ( path ) && FS . statSync ( path ) . isFile ( ) ) ;
74
102
}
75
103
}
104
+
105
+ function getStringArray ( arg : unknown ) : string [ ] {
106
+ return Array . isArray ( arg ) ? arg . map ( String ) : [ String ( arg ) ] ;
107
+ }
0 commit comments