@@ -38,7 +38,7 @@ export async function mirror(
38
38
registryApi ?: string
39
39
cwd ?: string
40
40
logger ?: Logger
41
- patches ?: { inject ?: record < string > ; aliases ?: { [ key : string ] : { [ key : string ] : Nullable < string > } } }
41
+ patches ?: { inject ?: record < string > ; types ?: { [ key : string ] : boolean } ; aliases ?: { [ key : string ] : { [ key : string ] : Nullable < string > } } }
42
42
} ,
43
43
) : Promise < { files : record < string > ; exports : record < string > } > {
44
44
// List packages
@@ -103,7 +103,7 @@ export async function mirror(
103
103
] )
104
104
} // Handle regular exports
105
105
else {
106
- const symbols = await generate ( jsr )
106
+ const symbols = await generate ( jsr , { path : paths . b , patches } )
107
107
output . files [ path ] = [ ...symbols . values ( ) ] . map ( ( { content } ) => content ) . join ( "\n" )
108
108
if ( patches ?. inject ?. [ paths . b ] ) {
109
109
output . files [ path ] = `${ patches . inject [ paths . b ] } \n${ output . files [ path ] } `
@@ -169,13 +169,18 @@ export async function mirror(
169
169
* This is computed by extracting `deno doc` information and re-attaching documentation and type information.
170
170
* This is to ensure that it is properly documented once published back on the registry.
171
171
*/
172
- async function generate ( jsr : string ) {
172
+ async function generate ( jsr : string , { path , patches } : { path : string ; patches ?: { types ?: { [ key : string ] : boolean } } } ) {
173
173
const temp = await Deno . makeTempFile ( )
174
174
const symbols = new Map < string , { type : boolean ; content : string } > ( )
175
175
try {
176
176
await Deno . writeTextFile ( temp , `export * from "${ jsr } "\n` )
177
177
const ast = await parseDoc ( temp )
178
- for ( const { kind, name, jsDoc, ..._ } of ast ) {
178
+ for ( let { kind, name, jsDoc, ..._ } of ast ) {
179
+ let forced = false
180
+ if ( patches ?. types ?. [ `${ path } #${ name } ` ] ) {
181
+ kind = "typeAlias"
182
+ forced = true
183
+ }
179
184
const { stdout } = await command ( "deno" , [ "doc" , "--filter" , name , temp ] )
180
185
const signature = stripAnsiCode ( stdout ) . split ( "\n" ) [ 2 ]
181
186
const type = [ "interface" , "typeAlias" ] . includes ( kind )
@@ -206,7 +211,7 @@ async function generate(jsr: string) {
206
211
break
207
212
}
208
213
}
209
- if ( ( ! type ) || ( type && ( ! ast . some ( ( node : { name : string ; kind : string } ) => node . name === name && node . kind !== kind ) ) ) ) {
214
+ if ( ( ! type ) || forced || ( type && ( ! ast . some ( ( node : { name : string ; kind : string } ) => node . name === name && node . kind !== kind ) ) ) ) {
210
215
lines . push ( `export ${ type ? "type " : "" } { ${ name } }` , "" )
211
216
}
212
217
symbols . set ( name , { type, content : lines . join ( "\n" ) } )
0 commit comments