Because it may be slow, it may crash and what not. While developing Badgen.net Service, we concluded to just switch to https://unpkg.com/${name}@${tag}/package.json.
Not to mention how confusing this npm API can be. It's total madness, seriously. This comment in the current master of get-pkg is one of many things. With Unpkg we everything is a whole lot easier and faster - you have scoped support, versions for all scoped/non-scoped, versions for tagged/non-tagged and etc.
Examples:
@foo/bar
@foo/bar@1.2.3
@foo/bar@next
bar
bar@1.2.3
bar@next
Or at least, we can allow it through some option, so it will unpkg and fallback to yarn.
I end up with this in few minutes (because non of the other packages does it well or are by Sindre, or are too old), before even realizing that get-pkg exist (i started to forget this good ol' packages - you are everywhere 🤣 ).
const parsePackage = require('parse-package-name')
const axios = require('axios')
// packageName: String, endpoint: (name: String, tag: String = 'latest'): String => {}
export default async function packageJson(packageName, endpoint) {
const { name, version } = parsePackage(packageName)
const tag = version === '' ? 'latest' : version
const url = typeof endpoint === 'function'
? endpoint(name, tag)
: `https://unpkg.com/${name}@${tag}/package.json`
return axios.get(url).then((res) => res.data)
}
/cc @jonschlinkert @doowb
Because it may be slow, it may crash and what not. While developing Badgen.net Service, we concluded to just switch to
https://unpkg.com/${name}@${tag}/package.json.Not to mention how confusing this npm API can be. It's total madness, seriously. This comment in the current master of
get-pkgis one of many things. With Unpkg we everything is a whole lot easier and faster - you have scoped support, versions for all scoped/non-scoped, versions for tagged/non-tagged and etc.Examples:
Or at least, we can allow it through some option, so it will
unpkgand fallback to yarn.I end up with this in few minutes (because non of the other packages does it well or are by Sindre, or are too old), before even realizing that
get-pkgexist (i started to forget this good ol' packages - you are everywhere 🤣 )./cc @jonschlinkert @doowb