npm / npm-registry-client

http://npm.im/npm-registry-client
ISC License
264 stars 108 forks source link

Use the last part of URL path if _rewrite does not exist #158

Closed wheelerlaw closed 7 years ago

wheelerlaw commented 7 years ago

If npm is configured to point to a custom registry whose registry path has multiple components to it (e.g. Artifactory: http://artifactory-hostname/artifactory/api/npm/) and you try to install a package that does not exist (e.g. some-nonexistent-package-name), it will use the first component in the path as the package name in the 404 error.

npm ERR! code E404
npm ERR! 404 Not Found: artifactory
npm ERR! 404 
npm ERR! 404  'artifactory' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

Instead, it should read:

npm ERR! code E404
npm ERR! 404 Not Found: some-package-name
npm ERR! 404 
npm ERR! 404  'some-package-name' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

In line 282 request.js tries to use the part of the path that follows _rewrite as the name of the package that failed the installation. However, if _rewrite does not exist, it will default to using the first part, which for registries with multi-part paths, will not be correct, since it is the last part of the path that is the package name.

This pr builds off of #156 by still permitting the search for _rewrite and defaulting to the last part of the URL path.

justastefan commented 7 years ago

looks great, when is this being reviewed/release? :+1:

zkat commented 7 years ago

@justastefan see https://github.com/npm/npm/pull/16244 and https://github.com/npm/npm/issues/16510 for details

iarna commented 7 years ago

This was released in v8.4.0 as f095e58.