Skip to content

Instantly share code, notes, and snippets.

@KevSlashNull
Created October 25, 2020 09:22
Show Gist options
  • Save KevSlashNull/7ac9f02ee7dc1fdff029f4ad7a886d3c to your computer and use it in GitHub Desktop.
Save KevSlashNull/7ac9f02ee7dc1fdff029f4ad7a886d3c to your computer and use it in GitHub Desktop.
// yarn add request
const request = {
get (uri, opts) {
// lazy require
const request = require('util').promisify(require('request'))
const reqOpts = {
method: 'GET',
timeout: 30000,
resolveWithFullResponse: true,
json: true,
uri,
...opts
}
return request(reqOpts)
}
}
const registries = {
npm: 'https://registry.npmjs.org',
yarn: 'https://registry.yarnpkg.com',
taobao: 'https://registry.npm.taobao.org',
pnpm: 'https://registry.npmjs.org',
}
const packages = ['vue-cli-version-marker', 'siegegg-api', 'express', 'request', 'ts-node', 'axios', 'bootstrap', 'jquery']
async function ping(registry, pkg) {
console.time(registry)
await request.get(`${registry}/${pkg}/latest`)
console.timeEnd(registry)
return registry
}
async function main(pkg) {
console.log('Using', pkg);
let faster = await Promise.all([
ping(registries.yarn, pkg),
ping(registries.taobao, pkg),
])
}
(async () => {
for (let pkg of packages) {
await main(pkg);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment