diff --git a/scripts/list-authorable-fields.ts b/scripts/list-authorable-fields.ts index 61434d74..39a1425c 100644 --- a/scripts/list-authorable-fields.ts +++ b/scripts/list-authorable-fields.ts @@ -329,6 +329,29 @@ function isCallableType(type: ts.Type): boolean { return normalizedType.getCallSignatures().length > 0; } +function isRepoSourceFile(fileName: string): boolean { + const relativePath = path.relative(repoRoot, fileName); + return ( + !relativePath.startsWith("..") && + !path.isAbsolute(relativePath) && + relativePath.startsWith(`src${path.sep}`) + ); +} + +function isExternalObjectType(type: ts.Type): boolean { + const normalizedType = withoutNullish(type); + const symbol = normalizedType.aliasSymbol ?? normalizedType.symbol; + const declarations = symbol?.declarations ?? []; + + if (declarations.length === 0) { + return false; + } + + return declarations.every( + (declaration) => !isRepoSourceFile(declaration.getSourceFile().fileName) + ); +} + function getArrayElementType(type: ts.Type): ts.Type | null { const normalizedType = withoutNullish(type); @@ -513,6 +536,14 @@ function collectFields( return; } + if (isExternalObjectType(normalizedType)) { + entries.push({ + path: currentPath, + condition: options.condition + }); + return; + } + const recordValueType = getRecordValueType(normalizedType); if (recordValueType !== null) {