src/install-peerdeps.js
function getPackageData({ encodedPackageName, registry, auth, proxy }) {
  const requestHeaders = {};
  if (auth) {
    requestHeaders.Authorization = `Bearer ${auth}`;
  }

  const options = {
    uri: `${registry}/${encodedPackageName}`,
    resolveWithFullResponse: true,
    // When simple is true, all non-200 status codes throw an
    // error. However, we want to handle status code errors in
    // the .then(), so we make simple false.
    simple: false,
    headers: requestHeaders
  };

  // If any proxy setting were passed then include the http proxy agent.
  const requestProxy =
    process.env.HTTP_PROXY || process.env.http_proxy || `${proxy}`;
  if (requestProxy !== "undefined") {
    options.agent = new HttpsProxyAgent(requestProxy);
  }

  return request(options).then(response => {
    const { statusCode } = response;
    if (statusCode === 404) {
      throw new Error(
        "That package doesn't exist. Did you mean to specify a custom registry?"
      );
    }
    // If the statusCode not 200 or 404, assume that something must
    // have gone wrong with the connection
    if (statusCode !== 200) {
      throw new Error("There was a problem connecting to the registry.");
    }
    const { body } = response;
    const parsedData = JSON.parse(body);
    return parsedData;
  });
}
function getPackageData({ encodedPackageName, registry, auth, proxy }) {
  const requestHeaders = {};
  if (auth) {
    requestHeaders.Authorization = `Bearer ${auth}`;
  }

  const options = {
    uri: `${registry}/${encodedPackageName}`,
    resolveWithFullResponse: true,
    // When simple is true, all non-200 status codes throw an
    // error. However, we want to handle status code errors in
    // the .then(), so we make simple false.
    simple: false,
    headers: requestHeaders
  };

  // If any proxy setting were passed then include the http proxy agent.
  const requestProxy =
    process.env.HTTP_PROXY || process.env.http_proxy || `${proxy}`;
  if (requestProxy !== "undefined") {
    options.agent = new HttpsProxyAgent(requestProxy);
  }

  return request(options).then(response => {
    const { statusCode } = response;
    if (statusCode === 404) {
      throw new Error(
        "That package doesn't exist. Did you mean to specify a custom registry?"
      );
    }
    // If the statusCode not 200 or 404, assume that something must
    // have gone wrong with the connection
    if (statusCode !== 200) {
      throw new Error("There was a problem connecting to the registry.");
    }
    const { body } = response;
    const parsedData = JSON.parse(body);
    return parsedData;
  });
}
function getPackageData ( { encodedPackageName , registry , auth , proxy } ) { const requestHeaders = { } ; if ( auth ) { requestHeaders . Authorization = ` ${ auth } ` ; } const options = { uri : ` ${ registry } ${ encodedPackageName } ` , resolveWithFullResponse : true , // When simple is true, all non-200 status codes throw an // error. However, we want to handle status code errors in // the .then(), so we make simple false. simple : false , headers : requestHeaders } ; // If any proxy setting were passed then include the http proxy agent. const requestProxy = process . env . HTTP_PROXY || process . env . http_proxy || ` ${ proxy } ` ; if ( requestProxy !== "undefined" ) { options . agent = new HttpsProxyAgent ( requestProxy ) ; } return request ( options ) . then ( response => { const { statusCode } = response ; if ( statusCode === 404 ) { throw new Error ( "That package doesn't exist. Did you mean to specify a custom registry?" ) ; } // If the statusCode not 200 or 404, assume that something must // have gone wrong with the connection if ( statusCode !== 200 ) { throw new Error ( "There was a problem connecting to the registry." ) ; } const { body } = response ; const parsedData = JSON . parse ( body ) ; return parsedData ; } ) ; }
Gets metadata about the package from the provided registry
@param {Object} requestInfo - information needed to make the request for the data
@param {string} requestInfo.encodedPackageName - the urlencoded name of the package
@param {string} requestInfo.registry - the URI of the registry on which the package is hosted
@returns {Promise<Object>} - a Promise which resolves to the JSON response from the registry
Gets metadata about the package from the provided registry