@@ -197,7 +197,7 @@ export interface ReflectionOptions {
197
197
/**
198
198
* External imports to reflect
199
199
*/
200
- external ?: Record < string , '*' | string [ ] > ; // '*' or true?
200
+ inlineExternalImports ?: true | Record < string , true | string [ ] > ;
201
201
}
202
202
203
203
export interface ReflectionConfig {
@@ -537,7 +537,7 @@ export class EmbedDeclarations extends Map<Node, EmbedDeclaration> {
537
537
*/
538
538
export class ReflectionTransformer implements CustomTransformer {
539
539
sourceFile ! : SourceFile ;
540
- public f : NodeFactory ;
540
+ protected f : NodeFactory ;
541
541
protected currentReflectionConfig : ReflectionConfig = { mode : 'never' , options : { } , baseDir : '' } ;
542
542
543
543
public defaultExcluded : string [ ] = [
@@ -594,7 +594,7 @@ export class ReflectionTransformer implements CustomTransformer {
594
594
protected context : TransformationContext ,
595
595
) {
596
596
this . f = context . factory ;
597
- this . nodeConverter = new NodeConverter ( this ) ;
597
+ this . nodeConverter = new NodeConverter ( this . f , this ) ;
598
598
//it is important to not have undefined values like {paths: undefined} because it would override the read tsconfig.json
599
599
this . compilerOptions = filterUndefined ( context . getCompilerOptions ( ) ) ;
600
600
this . host = createCompilerHost ( this . compilerOptions ) ;
@@ -2026,14 +2026,15 @@ export class ReflectionTransformer implements CustomTransformer {
2026
2026
return this . f . createIdentifier ( '__Ω' + joinQualifiedName ( typeName ) ) ;
2027
2027
}
2028
2028
2029
- // TODO: what to do when the external type depends on another external type? should that be automatically resolved, or should the user specify that explicitly as well?
2030
- protected isImportMarkedAsExternal ( importDeclaration : ImportDeclaration , entityName : EntityName , config : ReflectionConfig ) : boolean {
2029
+ // TODO: what to do when the inlineExternalImports type depends on another inlineExternalImports type? should that be automatically resolved, or should the user specify that explicitly as well?
2030
+ protected shouldInlineExternalImport ( importDeclaration : ImportDeclaration , entityName : EntityName , config : ReflectionConfig ) : boolean {
2031
2031
if ( ! ts . isStringLiteral ( importDeclaration . moduleSpecifier ) ) return false ;
2032
- const external = config . options . external ?. [ importDeclaration . moduleSpecifier . text ] ;
2033
- if ( ! external ) return false ;
2034
- if ( external === '*' ) return true ;
2032
+ if ( config . options . inlineExternalImports === true ) return true ;
2033
+ const externalImport = config . options . inlineExternalImports ?. [ importDeclaration . moduleSpecifier . text ] ;
2034
+ if ( ! externalImport ) return false ;
2035
+ if ( externalImport === true ) return true ;
2035
2036
const typeName = getEntityName ( entityName ) ;
2036
- return external . includes ( typeName ) ;
2037
+ return externalImport . includes ( typeName ) ;
2037
2038
}
2038
2039
2039
2040
protected isExcluded ( filePath : string ) : boolean {
@@ -2230,7 +2231,7 @@ export class ReflectionTransformer implements CustomTransformer {
2230
2231
const builtType = isBuiltType ( typeVar , found ) ;
2231
2232
2232
2233
if ( ! builtType ) {
2233
- if ( ! this . isImportMarkedAsExternal ( resolved . importDeclaration , typeName , declarationReflection ) ) return ;
2234
+ if ( ! this . shouldInlineExternalImport ( resolved . importDeclaration , typeName , declarationReflection ) ) return ;
2234
2235
this . embedDeclarations . set ( declaration , {
2235
2236
name : typeName ,
2236
2237
sourceFile : declarationSourceFile
@@ -2307,7 +2308,7 @@ export class ReflectionTransformer implements CustomTransformer {
2307
2308
// //check if typeVar is exported in referenced file
2308
2309
const builtType = isBuiltType ( typeVar , declarationSourceFile ) ;
2309
2310
2310
- if ( ! builtType && this . isImportMarkedAsExternal ( resolved . importDeclaration , typeName , declarationReflection ) ) {
2311
+ if ( ! builtType && this . shouldInlineExternalImport ( resolved . importDeclaration , typeName , declarationReflection ) ) {
2311
2312
this . embedDeclarations . set ( declaration , {
2312
2313
name : typeName ,
2313
2314
sourceFile : declarationSourceFile ,
0 commit comments