Unverified Commit bee82b47 authored by Lily Foster's avatar Lily Foster Committed by GitHub
Browse files

Merge pull request #240419 from lilyinstarlight/feature/prefetch-npm-deps-isahc

prefetch-npm-deps: use isahc instead of ureq
parents a471203d fb9252fa
Loading
Loading
Loading
Loading
+627 −256

File changed.

Preview size limit exceeded, changes collapsed.

+13 −11
Original line number Diff line number Diff line
@@ -6,15 +6,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.65"
base64 = "0.13.0"
digest = "0.10.5"
rayon = "1.5.3"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.85"
anyhow = "1.0.71"
backoff = "0.4.0"
base64 = "0.21.2"
digest = "0.10.7"
env_logger = "0.10.0"
isahc = { version = "1.7.2", default_features = false }
rayon = "1.7.0"
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.99"
sha1 = "0.10.5"
sha2 = "0.10.6"
tempfile = "3.3.0"
ureq = { version = "2.5.0" }
url = { version = "2.3.1", features = ["serde"] }
walkdir = "2.3.2"
sha2 = "0.10.7"
tempfile = "3.6.0"
url = { version = "2.4.0", features = ["serde"] }
walkdir = "2.3.3"
+9 −3
Original line number Diff line number Diff line
{ lib, stdenvNoCC, rustPlatform, makeWrapper, Security, gnutar, gzip, nix, testers, fetchurl, prefetch-npm-deps, fetchNpmDeps }:
{ lib, stdenvNoCC, rustPlatform, makeWrapper, pkg-config, curl, gnutar, gzip, nix, testers, fetchurl, cacert, prefetch-npm-deps, fetchNpmDeps }:

{
  prefetch-npm-deps = rustPlatform.buildRustPackage {
@@ -16,8 +16,8 @@

    cargoLock.lockFile = ./Cargo.lock;

    nativeBuildInputs = [ makeWrapper ];
    buildInputs = lib.optional stdenvNoCC.isDarwin Security;
    nativeBuildInputs = [ makeWrapper pkg-config ];
    buildInputs = [ curl ];

    postInstall = ''
      wrapProgram "$out/bin/prefetch-npm-deps" --prefix PATH : ${lib.makeBinPath [ gnutar gzip nix ]}
@@ -165,6 +165,12 @@

      dontInstall = true;

      impureEnvVars = lib.fetchers.proxyImpureEnvVars;

      SSL_CERT_FILE = if (hash_.outputHash == "" || hash_.outputHash == lib.fakeSha256 || hash_.outputHash == lib.fakeSha512 || hash_.outputHash == lib.fakeHash)
        then "${cacert}/etc/ssl/certs/ca-bundle.crt"
        else "/no-cert-file.crt";

      outputHashMode = "recursive";
    } // hash_ // forceGitDeps_);
}
+3 −2
Original line number Diff line number Diff line
use base64::prelude::{Engine, BASE64_STANDARD};
use digest::{Digest, Update};
use serde::{Deserialize, Serialize};
use sha1::Sha1;
@@ -52,14 +53,14 @@ impl Cache {
        let (algo, hash, integrity) = if let Some(integrity) = integrity {
            let (algo, hash) = integrity.split_once('-').unwrap();

            (algo.to_string(), base64::decode(hash)?, integrity)
            (algo.to_string(), BASE64_STANDARD.decode(hash)?, integrity)
        } else {
            let hash = Sha512::new().chain(data).finalize();

            (
                String::from("sha512"),
                hash.to_vec(),
                format!("sha512-{}", base64::encode(hash)),
                format!("sha512-{}", BASE64_STANDARD.encode(hash)),
            )
        };

+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ use walkdir::WalkDir;

mod cacache;
mod parse;
mod util;

fn cache_map_path() -> Option<PathBuf> {
    env::var_os("CACHE_MAP_PATH").map(PathBuf::from)
@@ -172,6 +173,8 @@ fn map_cache() -> anyhow::Result<HashMap<Url, String>> {
}

fn main() -> anyhow::Result<()> {
    env_logger::init();

    let args = env::args().collect::<Vec<_>>();

    if args.len() < 2 {
@@ -182,6 +185,18 @@ fn main() -> anyhow::Result<()> {
        process::exit(1);
    }

    if let Ok(jobs) = env::var("NIX_BUILD_CORES") {
        if !jobs.is_empty() {
            rayon::ThreadPoolBuilder::new()
                .num_threads(
                    jobs.parse()
                        .expect("NIX_BUILD_CORES must be a whole number"),
                )
                .build_global()
                .unwrap();
        }
    }

    if args[1] == "--fixup-lockfile" {
        let lock = serde_json::from_str(&fs::read_to_string(&args[2])?)?;

Loading