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

Conversation

jlaramie
Copy link
Contributor

No description provided.

index.js Outdated
path.basename(path.join.apply(path, [CWD].concat(
splitName.map(function () {
return '..'
})))) === 'node_modules')
Copy link
Owner

@exogen exogen Jul 7, 2017

Choose a reason for hiding this comment

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

Thanks for writing this! I find the condition a bit difficult to read and it would be nice to consolidate the === 'node_modules' check into one place so it's not repeated. What about something like this?

  var splitName = (process.env.npm_package_name || '').split('/')
  var parentDirs = CWD.split(path.sep).slice(-splitName.length - 1, -1)
  var isDependency = parentDirs.indexOf('node_modules') !== -1

(That is, check the directory names – from immediate parent to the parent indicated by the number of /s in the package name – for node_modules.)

If you have time to update this PR I'll get it merged ASAP!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks to me like with your changes we don't need to keep track of splitName anymore. Your isDependency check is based off of splitting the the CWD apart instead of the package_name.

@exogen
Copy link
Owner

exogen commented Jul 7, 2017

Sorry that review took so long! Went on a camping trip.

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?

@jlaramie
Copy link
Contributor Author

jlaramie commented Jul 7, 2017 via email

@exogen
Copy link
Owner

exogen commented Jul 7, 2017

@jlaramie Sounds fine to me! Might also fix some issues when npm builds in a .staging subdirectory or whatever newer versions do differently.

Regarding detecting different executables, we'll have to do some experimentation – I think attempting to run the equivalent prune command on other user agents could break more than it fixes, but we'll have to test it. (Since postinstall-build attempts to leave no trace of the temporary install anyhow, it might not be worthwhile to try other commands.)

@exogen exogen merged commit 940b73d into exogen:master Jul 7, 2017
@jlaramie
Copy link
Contributor Author

jlaramie commented Jul 7, 2017 via email

@exogen
Copy link
Owner

exogen commented Jul 7, 2017

@jlaramie Another thing you may want to explore is a migration path to npm v5's new prepare command handling, which basically does what postinstall-build set out to accomplish. It would be neat if postinstall-build users had an easy migration path where they could start adding prepare and they wouldn't conflict! (Of course that depends on people upgrading to npm v5)

@jlaramie
Copy link
Contributor Author

jlaramie commented Jul 7, 2017 via email

@exogen
Copy link
Owner

exogen commented Jul 7, 2017

Now published in 5.0.1, thanks for the PR!

@jlaramie
Copy link
Contributor Author

jlaramie commented Jul 7, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants