Bug: npq doesn't support the npm alias convention
lirantal opened this issue · 9 comments
Expectated
This should work fine by parsing properly the jquery@2
as a package name
npq install jquery2@npm:jquery@2
Actual
This throws an error on the console, related to fetching an incorrect package information from the npmjs registry api.
Hi @lirantal, hope you are doing well.
What you think about introducing library npm-package-arg
const npa = require("npm-package-arg");
...
class cliCommons {
static getInstallCommand() {
return {
command: 'install [package...]',
aliases: ['i', 'add'],
desc: 'install a package',
handler: (argv) => {
if (argv && argv.package && argv.package[0]) {
argv.package[0] = npa(argv.package[0]).name;
}
}
}
}
...
Adding this handler function for yargs that will use the library npm-package-arg to get the name from the input.
@salesh does that mean it will actually be able to parse the package well too (with the alias use-case) ?
@lirantal
Yes, for example, this is the output of calling this library for jquery2@npm:jquery@2
We get name
there.
Result {
type: 'alias',
registry: true,
where: undefined,
raw: 'jquery2@npm:jquery@2',
name: 'jquery2',
escapedName: 'jquery2',
scope: undefined,
rawSpec: 'npm:jquery@2',
saveSpec: null,
fetchSpec: null,
gitRange: undefined,
gitCommittish: undefined,
hosted: undefined,
subSpec: Result {
type: 'range',
registry: true,
where: undefined,
raw: 'jquery@2',
name: 'jquery',
escapedName: 'jquery',
scope: undefined,
rawSpec: '2',
saveSpec: null,
fetchSpec: '2',
gitRange: undefined,
gitCommittish: undefined,
hosted: undefined
}
}
Looks great. Would you like to send a PR?
Really sorry for this additional pull request @lirantal and for wasting your time :/ I totally forgot to support the case when somebody enters more than one package and when our alias package is somewhere after the first spot...
For example:
npq install express axios jquery2@npm:jquery@2
Gotcha, thanks for the quick PR!
Thank you @lirantal for patience and support, I hope I will contribute more in the future. :)
Much appreciation for your contributions!