@@ -6,7 +6,7 @@ const NM = 'node_modules/'
6
6
* For a given full path to a module,
7
7
* return the package name it belongs to and the local path to the module
8
8
* input: '/foo/node_modules/@co/stuff/foo/bar/baz.js'
9
- * output: { pkg: '@co /stuff', path: 'foo/bar/baz.js' }
9
+ * output: { pkg: '@co /stuff', path: 'foo/bar/baz.js', pkgJson: '/foo/node_modules/@co/stuff/package.json' }
10
10
*/
11
11
module . exports = function extractPackageAndModulePath ( fullPath ) {
12
12
const nm = fullPath . lastIndexOf ( NM )
@@ -17,17 +17,20 @@ module.exports = function extractPackageAndModulePath (fullPath) {
17
17
const subPath = fullPath . substring ( nm + NM . length )
18
18
const firstSlash = subPath . indexOf ( '/' )
19
19
20
+ const firstPath = fullPath . substring ( fullPath [ 0 ] , nm + NM . length )
21
+
20
22
if ( subPath [ 0 ] === '@' ) {
21
23
const secondSlash = subPath . substring ( firstSlash + 1 ) . indexOf ( '/' )
22
-
23
24
return {
24
25
pkg : subPath . substring ( 0 , firstSlash + 1 + secondSlash ) ,
25
- path : subPath . substring ( firstSlash + 1 + secondSlash + 1 )
26
+ path : subPath . substring ( firstSlash + 1 + secondSlash + 1 ) ,
27
+ pkgJson : firstPath + subPath . substring ( 0 , firstSlash + 1 + secondSlash ) + '/package.json'
26
28
}
27
29
}
28
30
29
31
return {
30
32
pkg : subPath . substring ( 0 , firstSlash ) ,
31
- path : subPath . substring ( firstSlash + 1 )
33
+ path : subPath . substring ( firstSlash + 1 ) ,
34
+ pkgJson : firstPath + subPath . substring ( 0 , firstSlash ) + '/package.json'
32
35
}
33
36
}
0 commit comments