-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (35 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var fs = require('fs')
var path = require('path')
var glob = require('glob')
/**
* @param {string} pathToRoot path to root of project
* @param {function} cb callback executed when a linked package is found
* @param {string} pkgName name of found linked package
* @param {string} foundPath (full) of found linked package
*/
module.exports = function npmLinkCheck (pathToRoot, cb) {
globNodeModules(pathToRoot, cb)
}
function globNodeModules (startPath, cb) {
var pathToNodeModules
// if we have a scope we should check if the modules inside the folder is linked
if (startPath.includes('@')) {
pathToNodeModules = startPath
} else {
pathToNodeModules = path.join(startPath, 'node_modules')
}
glob(pathToNodeModules + '/*', function (err, foundPaths) {
if (err) console.warn(err)
foundPaths.forEach(function (foundPath) {
fs.lstat(foundPath, function (err, stats) {
if (err) console.warn(err)
if (stats.isDirectory()) {
globNodeModules(foundPath, cb)
} else if (stats.isSymbolicLink()) {
var pkgName = path.basename(foundPath)
cb(pkgName, foundPath)
}
})
})
})
}