@@ -4,6 +4,7 @@ const {default: babelTraverse} = require("@babel/traverse");
4
4
const { default : generator } = require ( "@babel/generator" ) ;
5
5
const { getRelativePath} = require ( "./files" ) ;
6
6
const fs = require ( "fs" ) . promises ;
7
+ const _ = require ( "lodash" ) ;
7
8
8
9
9
10
function replaceRequirePaths ( code , currentPath , testFilePath ) {
@@ -52,13 +53,21 @@ async function getAstFromFilePath(filePath) {
52
53
}
53
54
54
55
async function getModuleTypeFromFilePath ( ast ) {
55
- let moduleType = 'unknown ' ;
56
+ let moduleType = 'CommonJS ' ;
56
57
57
58
babelTraverse ( ast , {
58
59
ImportDeclaration ( path ) {
59
60
moduleType = 'ES6' ;
60
61
path . stop ( ) ; // Stop traversal when an ESM statement is found
61
62
} ,
63
+ ExportNamedDeclaration ( path ) {
64
+ moduleType = 'ES6' ;
65
+ path . stop ( ) ; // Stop traversal when an ESM statement is found
66
+ } ,
67
+ ExportDefaultDeclaration ( path ) {
68
+ moduleType = 'ES6' ;
69
+ path . stop ( ) ; // Stop traversal when an ESM statement is found
70
+ } ,
62
71
CallExpression ( path ) {
63
72
if ( path . node . callee . name === 'require' ) {
64
73
moduleType = 'CommonJS' ;
@@ -138,10 +147,9 @@ function getRelatedFunctions(node, ast, filePath, functionList) {
138
147
}
139
148
let functionFromList = functionList [ requiredPath + ':' + funcName ] ;
140
149
if ( functionFromList ) {
141
- relatedFunctions . push ( {
142
- fileName : requiredPath ,
143
- funcName
144
- } ) ;
150
+ relatedFunctions . push ( _ . extend ( functionFromList , {
151
+ fileName : requiredPath
152
+ } ) ) ;
145
153
}
146
154
}
147
155
0 commit comments