@@ -236,32 +236,30 @@ export function extractAllTopLevelSymbols(filePath: string) {
236
236
* Extract exports of a module
237
237
*/
238
238
export function extractExports ( filePath : string ) {
239
- const input = tmp . fileSync ( { } ) . name + '.js' ;
240
- const exportStatement = `export * from '${ path . resolve (
241
- filePath
242
- ) } ';`;
243
- fs . writeFileSync ( input , exportStatement ) ;
244
- const program = ts . createProgram ( [ input ] , {
239
+ const exportDeclarations : MemberList = {
240
+ functions : [ ] ,
241
+ classes : [ ] ,
242
+ variables : [ ] ,
243
+ enums : [ ]
244
+ } ;
245
+
246
+ const program = ts . createProgram ( [ filePath ] , {
245
247
allowJs : true ,
246
248
baseUrl : path . resolve ( `${ projectRoot } /node_modules` )
247
249
} ) ;
248
250
const checker = program . getTypeChecker ( ) ;
249
- const sourceFile = program . getSourceFile ( input ) ;
250
- const module = checker . getSymbolAtLocation ( ( sourceFile ?. statements [ 0 ] as ts . ExportDeclaration ) . moduleSpecifier ! ) ! ;
251
+ const sourceFile = program . getSourceFile ( filePath ) ! ;
252
+ const module = checker . getSymbolAtLocation ( sourceFile ) ;
253
+ // no export from the file
254
+ if ( ! module ) {
255
+ return exportDeclarations ;
256
+ }
257
+
251
258
const exports = checker . getExportsOfModule ( module ) ;
252
259
253
- let exportDeclarations : MemberList = {
254
- functions : [ ] ,
255
- classes : [ ] ,
256
- variables : [ ] ,
257
- enums : [ ]
258
- } ;
259
260
260
261
for ( const expt of exports ) {
261
262
// get the source declaration where we can determine the type of the export. e.g. class vs function
262
- if ( expt . name === 'Config' ) {
263
- console . log ( 'stop' ) ;
264
- }
265
263
let sourceSymbol = expt ;
266
264
if ( sourceSymbol . declarations [ 0 ] . kind === ts . SyntaxKind . ExportSpecifier ) {
267
265
sourceSymbol = checker . getAliasedSymbol ( expt ) ;
@@ -280,7 +278,7 @@ export function extractExports(filePath: string) {
280
278
} else if ( ts . isVariableDeclaration ( sourceDeclaration ) ) {
281
279
exportDeclarations . variables . push ( expt . name ) ;
282
280
} else {
283
- console . log ( 'unhandled export type ' , expt . name ) ;
281
+ console . log ( 'unhandled export: ' , expt . name ) ;
284
282
}
285
283
}
286
284
@@ -658,6 +656,7 @@ export async function generateReport(
658
656
throw new Error ( ErrorCode . INPUT_BUNDLE_FILE_DOES_NOT_EXIST ) ;
659
657
}
660
658
659
+ console . log ( 'generating report for ' , name ) ;
661
660
const publicAPI = extractExports ( resolvedBundleFile ) ;
662
661
const map : Map < string , string > = buildMap ( publicAPI ) ;
663
662
return buildJsonReport ( name , publicAPI , bundleFile , map ) ;
0 commit comments