7
7
import { Project , Type , TypeFormatFlags } from 'ts-morph' ;
8
8
import * as path from 'path' ;
9
9
import {
10
+ getResultNameFromMethod ,
10
11
getTypeInNamespaceOrThrow ,
11
12
type MappingInterface ,
12
13
type SpecType ,
13
14
} from './utils.ts' ;
14
15
15
16
const rootDir = path . resolve ( import . meta. dirname , '..' ) ;
16
17
18
+ const MAIN_SPEC_PREFIX = 'Bidi' ;
19
+
17
20
const specs : SpecType [ ] = [
18
21
{
19
22
inputFile : './main.ts' ,
20
23
commandType : 'CommandData' ,
21
- modulePrefix : 'Bidi' ,
24
+ modulePrefix : MAIN_SPEC_PREFIX ,
22
25
} ,
23
26
{
24
27
inputFile : './permissions.ts' ,
@@ -76,7 +79,17 @@ for (const spec of specs) {
76
79
TypeFormatFlags . None ,
77
80
) ;
78
81
79
- let expectedResultTypeName = paramsTypeString . replace ( 'Params' , 'Result' ) ;
82
+ let prefix = spec . modulePrefix ;
83
+ let expectedResultTypeName = paramsTypeString . replace (
84
+ 'Parameters' ,
85
+ 'Result' ,
86
+ ) ;
87
+
88
+ // We need to infer from methods
89
+ // TODO: See if this is needed as a fallback always
90
+ if ( paramsTypeString . includes ( 'Extensible' ) ) {
91
+ expectedResultTypeName = getResultNameFromMethod ( methodString ) ;
92
+ }
80
93
81
94
try {
82
95
// Usually we get something like `BrowsingContext.GetTreeResult`
@@ -86,6 +99,8 @@ for (const spec of specs) {
86
99
// Maybe it was not inside an Namespace try on the module scope
87
100
apiIndexFile . getTypeAliasOrThrow ( expectedResultTypeName ) ;
88
101
} catch {
102
+ // The EmptyResult is only available on the main spec
103
+ prefix = MAIN_SPEC_PREFIX ;
89
104
// Default to EmptyResult
90
105
expectedResultTypeName = `EmptyResult` ;
91
106
}
@@ -94,7 +109,7 @@ for (const spec of specs) {
94
109
commandMappingEntries . push ( {
95
110
method : methodString ,
96
111
params : `${ spec . modulePrefix } .${ paramsTypeString } ` ,
97
- resultType : `${ spec . modulePrefix } .${ expectedResultTypeName } ` ,
112
+ resultType : `${ prefix } .${ expectedResultTypeName } ` ,
98
113
} ) ;
99
114
}
100
115
}
0 commit comments