mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
Merge pull request #267912 from reinismu/fetch-npm-deps-fix-bug
prefetch-npm-deps: add support for npm alias schema in version spec
This commit is contained in:
commit
63fabdebd0
@ -246,7 +246,9 @@ fn main() -> anyhow::Result<()> {
|
|||||||
packages.into_par_iter().try_for_each(|package| {
|
packages.into_par_iter().try_for_each(|package| {
|
||||||
eprintln!("{}", package.name);
|
eprintln!("{}", package.name);
|
||||||
|
|
||||||
let tarball = package.tarball()?;
|
let tarball = package
|
||||||
|
.tarball()
|
||||||
|
.map_err(|e| anyhow!("couldn't fetch {} at {}: {e:?}", package.name, package.url))?;
|
||||||
let integrity = package.integrity().map(ToString::to_string);
|
let integrity = package.integrity().map(ToString::to_string);
|
||||||
|
|
||||||
cache
|
cache
|
||||||
|
@ -214,29 +214,35 @@ fn to_new_packages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let UrlOrString::Url(v) = &package.version {
|
if let UrlOrString::Url(v) = &package.version {
|
||||||
for (scheme, host) in [
|
if v.scheme() == "npm" {
|
||||||
("github", "github.com"),
|
if let Some(UrlOrString::Url(ref url)) = &package.resolved {
|
||||||
("bitbucket", "bitbucket.org"),
|
package.version = UrlOrString::Url(url.clone());
|
||||||
("gitlab", "gitlab.com"),
|
}
|
||||||
] {
|
} else {
|
||||||
if v.scheme() == scheme {
|
for (scheme, host) in [
|
||||||
package.version = {
|
("github", "github.com"),
|
||||||
let mut new_url = initial_url.clone();
|
("bitbucket", "bitbucket.org"),
|
||||||
|
("gitlab", "gitlab.com"),
|
||||||
|
] {
|
||||||
|
if v.scheme() == scheme {
|
||||||
|
package.version = {
|
||||||
|
let mut new_url = initial_url.clone();
|
||||||
|
|
||||||
new_url.set_host(Some(host))?;
|
new_url.set_host(Some(host))?;
|
||||||
|
|
||||||
if v.path().ends_with(".git") {
|
if v.path().ends_with(".git") {
|
||||||
new_url.set_path(v.path());
|
new_url.set_path(v.path());
|
||||||
} else {
|
} else {
|
||||||
new_url.set_path(&format!("{}.git", v.path()));
|
new_url.set_path(&format!("{}.git", v.path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
new_url.set_fragment(v.fragment());
|
new_url.set_fragment(v.fragment());
|
||||||
|
|
||||||
UrlOrString::Url(new_url)
|
UrlOrString::Url(new_url)
|
||||||
};
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,7 +272,8 @@ fn get_initial_url() -> anyhow::Result<Url> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
get_initial_url, to_new_packages, Hash, HashCollection, OldPackage, Package, UrlOrString,
|
get_initial_url, packages, to_new_packages, Hash, HashCollection, OldPackage, Package,
|
||||||
|
UrlOrString,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
@ -328,4 +335,36 @@ mod tests {
|
|||||||
Some(Hash(String::from("sha512-foo")))
|
Some(Hash(String::from("sha512-foo")))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_lockfile_correctly() {
|
||||||
|
let packages = packages(
|
||||||
|
r#"{
|
||||||
|
"name": "node-ddr",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"string-width-cjs": {
|
||||||
|
"version": "npm:string-width@4.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
|
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||||
|
"requires": {
|
||||||
|
"emoji-regex": "^8.0.0",
|
||||||
|
"is-fullwidth-code-point": "^3.0.0",
|
||||||
|
"strip-ansi": "^6.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"#).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(packages.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
packages[0].resolved,
|
||||||
|
Some(UrlOrString::Url(
|
||||||
|
Url::parse("https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz")
|
||||||
|
.unwrap()
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user