Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

get-pkg

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-pkg - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+27
-13
index.js

@@ -10,3 +10,3 @@ /*!

const request = require('axios');
const axios = require('axios');

@@ -26,15 +26,29 @@ module.exports = function getPkg(name, version, cb) {

const promise = request.get(`https://registry.npmjs.org/${name}/${version}`)
.then(res => res.data)
function request(url) {
return axios.get(`${url}/${name}/${version}`)
.then(res => res.data)
.catch(err => {
if (err.response.status === 500) {
return Promise.reject(new Error(err.response.status));
}
if (err.response.status === 404) {
const error = new Error('document not found');
error.code = err.response.status;
error.pkgName = name;
return Promise.reject(error);
}
return Promise.reject(err);
});
}
// the following code hits the yarn CNAME (they call it a "proxy")
// when npm's registry fails. In practice, this usually won't make a
// difference since yarn is pseudo-proxying npm's registry in the
// first place, but in the case of CDN failure, it might help.
const promise = request('https://registry.npmjs.org')
.catch(err => {
if (err.response.status === 500) {
return Promise.reject(new Error(err.response.status));
}
if (err.response.status === 404) {
const error = new Error('document not found');
error.code = err.response.status;
error.pkgName = name;
return Promise.reject(error);
}
return Promise.reject(err);
return request('https://registry.yarnpkg.com')
.catch(() => {
return Promise.reject(err);
})
});

@@ -41,0 +55,0 @@

{
"name": "get-pkg",
"description": "Get the package.json for a project from npm.",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/jonschlinkert/get-pkg",

@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",