Browse Source

live-fns: (npm) jsdelivr => unpkg

For better catch up with latest npm package release.
docker-size
Amio 6 years ago
parent
commit
a1bb0ce826
  1. 32
      libs/live-fns/npm.js

32
libs/live-fns/npm.js

@ -37,19 +37,31 @@ module.exports = async (topic, ...args) => {
} }
} }
const pkg = async (topic, args) => { /**
let pkg = args[0] * Parse npm name args
let tag = 'latest' *
const isScoped = args[0].charAt(0) === '@' * ['@babel', 'core', 'latest']
* ['@babel', 'core']
if (isScoped) { * ['react', 'next']
pkg = `${args[0]}/${args[1]}` * ['react']
tag = args[2] || tag */
const parseNpmName = (args) => {
if (args[0].charAt(0) === '@') {
return {
pkg: `${args[0]}/${args[1]}`,
tag: args[2]
}
} else { } else {
tag = args[1] || tag return {
pkg: args[0],
tag: args[1]
}
} }
}
const endpoint = `https://cdn.jsdelivr.net/npm/${pkg}@${tag}/package.json` const pkg = async (topic, args) => {
const { pkg, tag = 'latest' } = parseNpmName(args)
const endpoint = `https://unpkg.com/${pkg}@${tag}/package.json`
const meta = await got(endpoint).then(res => res.body) const meta = await got(endpoint).then(res => res.body)
switch (topic) { switch (topic) {

Loading…
Cancel
Save