Skip to content

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

Merged
merged 1 commit into from
Sep 11, 2018
Merged

fix: read npm registry from npm config #3882

merged 1 commit into from
Sep 11, 2018

Conversation

lambourn
Copy link

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.org

What is the new behavior?

read npm registry from npm config instead of hard-wiring it to npmjs.org, fixes #3866

@rosen-vladimirov
Copy link
Contributor

run ci

@rosen-vladimirov rosen-vladimirov added this to the 5.0.0 milestone Sep 11, 2018
@rosen-vladimirov rosen-vladimirov self-assigned this Sep 11, 2018
@rosen-vladimirov rosen-vladimirov self-requested a review September 11, 2018 09:56
@@ -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`);
Copy link
Contributor

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;

Copy link
Author

@lambourn lambourn Sep 11, 2018

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.

Copy link
Contributor

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.

@rosen-vladimirov rosen-vladimirov merged commit 6b34fa7 into NativeScript:master Sep 11, 2018
@rosen-vladimirov
Copy link
Contributor

@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 npm i -g nativescript@next (it may take 15-20 minutes to publish the next version with the fix).

@facetious
Copy link

Even though this does fetch the URL for the registry, this does not properly use the authentication specified in .npmrc. It is unclear to me why nativescript is rewriting npm in the first place, but I insist that the ability to authenticate needs to be present here.

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

Successfully merging this pull request may close these issues.

Read registry from npm config instead of hard-wiring to npmjs.org in node-package-manager
3 participants