-
-
Notifications
You must be signed in to change notification settings - Fork 197
fix: read npm registry from npm config #3882
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
fix: read npm registry from npm config #3882
Conversation
run ci |
@@ -120,7 +120,8 @@ export class NodePackageManager implements INodePackageManager { | |||
} | |||
|
|||
public async getRegistryPackageData(packageName: string): Promise<any> { | |||
const url = `https://registry.npmjs.org/${packageName}`; | |||
const registry = await this.$childProcess.exec(`npm config get registry`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about falling back to registry.npmjs.org in case npm config get registry
fails for some reason?
For example:
let registry = "https://registry.npmjs.org/";
try {
registry = await this.$childProcess.exec(`npm config get registry`);
} catch (err) {
this.$logger.trace("Unable to get information for current npm registry", err);
}
const url = registry.trim() + packageName;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this as well - defensive programming FTW ;-) But even if I wipe my .npmrc
file, the value npm defaults to is always https://registry.npmjs.org/
Plus, if npm config get registry
fails, then something is foul with npm installation in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the explanation. We'll run our tests now and if the build is green, I'll merge this PR.
@lambourn thanks a lot for your Contribution! We've merged the suggested fix and it will be included in our 5.0.0 release. The fix will be available soon in CLI's next version - you can install it by executing |
Even though this does fetch the URL for the registry, this does not properly use the authentication specified in |
PR Checklist
What is the current behavior?
nativescript-cli assumes that npmjs.org is used. If another (local) repo like artifactory is used,
tns add platform
(and probably other steps) fails as it hard-wired tries to pull packages from npmjs.orgWhat is the new behavior?
read npm registry from npm config instead of hard-wiring it to npmjs.org, fixes #3866