@@ -96,6 +96,7 @@ export function resolveNodePackage(cwd: string, packageFullPath: string): Object
96
96
if ( packageJsonInfo ) {
97
97
// The +1 is for the / after the node_modules, we didn't enter it into the NODE_MODULES const because it makes problems on windows
98
98
const packageRelativePath = packageFullPath . substring ( packageFullPath . lastIndexOf ( NODE_MODULES ) + NODE_MODULES . length + 1 , packageFullPath . length ) ;
99
+
99
100
const packageName = resolvePackageNameByPath ( packageRelativePath ) ;
100
101
const packageVersion = R . path ( [ 'dependencies' , packageName ] , packageJsonInfo ) ||
101
102
R . path ( [ 'devDependencies' , packageName ] , packageJsonInfo ) ||
@@ -105,9 +106,20 @@ export function resolveNodePackage(cwd: string, packageFullPath: string): Object
105
106
return result ;
106
107
}
107
108
}
108
- // Get the package relative path to the node_modules dir
109
109
110
- const packageInfo = PackageJson . findPackage ( packageFullPath ) ;
110
+ // Get the package relative path to the node_modules dir
111
+ let packageDir = packageFullPath ;
112
+ // Check if the full path is path to the index file and not only to the directory
113
+ const stats = fs . statSync ( packageFullPath ) ;
114
+ if ( stats . isFile ( ) ) {
115
+ packageDir = path . dirname ( packageFullPath ) ;
116
+ }
117
+ // don't propagate here since loading a package.json of another folder and taking the version from it will result wrong version
118
+ // This for example happen in the following case:
119
+ // if you have 2 authored component which one dependet on the other
120
+ // we will look for the package.json on the dependency but won't find it
121
+ // if we propagate we will take the version from the root's package json which has nothing with the component version
122
+ const packageInfo = PackageJson . loadSync ( packageDir , false ) ;
111
123
if ( ! packageInfo ) return null ; // when running 'bitjs get-dependencies' command, packageInfo is sometimes empty
112
124
result [ packageInfo . name ] = packageInfo . version ;
113
125
return result ;
0 commit comments