Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CWD 'node_modules' check for namespaced packages #26

Merged
merged 2 commits into from
Jul 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ function postinstallBuild () {
// dependency, we should always prune. Unfortunately, npm doesn't set
// any helpful environment variables to indicate whether we're being
// installed as a dependency or not. The best we can do is check whether
// the parent directory is `node_modules`.
var isDependency = path.basename(path.dirname(CWD)) === 'node_modules'
// the parent directory is `node_modules` but the package can be nested
// in multiple parent directories so we split apart the name of the module.
var parentDirs = CWD.split(path.sep)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the splitName length check was still useful for only checking the last few relevant directories in CWD (just to be somewhat cautious), but it might be fine to check every ancestor anyway like this. Do you think it matters?

var isDependency = parentDirs.indexOf('node_modules') !== -1

if (flags.onlyAsDependency && !isDependency) {
log.info(
Expand Down