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

support for scoped registry urls #4

Merged
merged 2 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion lib/getPackageDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const colors = require('colors/safe');
const readline = require('readline');

const packageDetailsCache = {};
const registryUrl = `https://registry.npmjs.org/`;
const npmConfig = require('rc')('npm', {
registry: `https://registry.npmjs.org/`
});

/**
* @param {Response} r
Expand Down Expand Up @@ -70,6 +72,11 @@ module.exports = function getPackageDetails(
return Promise.resolve(null);
}
const key = `${name}@${versionLoose}`;
const scope = (/(@[^\/]+)\/.*/.test(name) && /(@[^\/]+)\/.*/.exec(name)[1]) || ``;
Copy link
Owner

Choose a reason for hiding this comment

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

I suggest to use https://github.com/npm/npm-package-arg (because npm uses it)
or alternatively copy logic from it to be on safe side 😉

this.scope = name[0] === '@' ? name.slice(0, name.indexOf('/')) : undefined
// scoped packages in couch must have slash url-encoded, e.g. @foo%2Fbar
this.escapedName = name.replace('/', '%2f')

It's difficult to say if your regexp works exactly. the same.

Copy link
Author

Choose a reason for hiding this comment

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

just changed the parsing to the same logic, thanks for the hint

var registryUrl = (scope && npmConfig[`${scope}:registry`]) || npmConfig[`registry`];
Copy link
Owner

Choose a reason for hiding this comment

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

let please

Copy link
Author

Choose a reason for hiding this comment

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

fixed together with the remaining eslint errors

if(registryUrl.charAt(registryUrl.length - 1) !== `/`) {
registryUrl += `/`;
}
Copy link
Owner

Choose a reason for hiding this comment

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

👍

const infoUrl = `${registryUrl}${name.replace(`/`, `%2f`)}`;
if (!packageDetailsCache[key]) {
readline.cursorTo(process.stdout, 0);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"promise-queue": "^2.2.3",
"semver": "^5.4.1",
"spdx-correct": "^2.0.4",
"spdx-satisfies": "^0.1.3"
"spdx-satisfies": "^0.1.3",
"rc": "^1.2.8"
}
}