Skip to content

Commit 940b73d

Browse files
jlaramieexogen
authored andcommitted
Fixed CWD 'node_modules' check for namespaced packages (#26)
* Fixed CWD 'node_modules' check for namespaced packages * Cleaned up the CWD 'node_modules' parent check
1 parent f157e8f commit 940b73d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ function postinstallBuild () {
177177
// dependency, we should always prune. Unfortunately, npm doesn't set
178178
// any helpful environment variables to indicate whether we're being
179179
// installed as a dependency or not. The best we can do is check whether
180-
// the parent directory is `node_modules`.
181-
var isDependency = path.basename(path.dirname(CWD)) === 'node_modules'
180+
// the parent directory is `node_modules` but the package can be nested
181+
// in multiple parent directories so we split apart the name of the module.
182+
var parentDirs = CWD.split(path.sep)
183+
var isDependency = parentDirs.indexOf('node_modules') !== -1
182184

183185
if (flags.onlyAsDependency && !isDependency) {
184186
log.info(

0 commit comments

Comments
 (0)