Skip to content

Stop losing colon prefixes from descriptors. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ fn entry_single_descriptor<'a>(input: &'a str) -> Res<&'a str, (&'a str, &'a str
let i = i.strip_prefix('"').unwrap_or(i);

let (_, (name, version)) = context("entry single descriptor", |i: &'a str| {
let version_start_idx = i.rfind('@').map(|idx| {
let idx = idx + 1;
// does it also contains a colon? e.g. foo@workspace:.
i[idx..].rfind(':').map_or(idx, |new_idx| idx + new_idx + 1)
});
let version_start_idx = i.rfind('@').map(|idx| idx + 1);

#[allow(clippy::manual_strip)]
let name_end_idx = if i.starts_with('@') {
Expand Down Expand Up @@ -563,7 +559,10 @@ mod tests {
&Entry {
name: "@babel/code-frame",
version: "7.18.6",
descriptors: vec![("@babel/code-frame", "^7.18.6")],
descriptors: vec![(
"@babel/code-frame",
if with_bug { "^7.18.6" } else { "npm:^7.18.6" }
)],
dependencies: vec![("@babel/highlight", "^7.18.6")],
integrity: if with_bug {
"sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q=="
Expand All @@ -578,7 +577,7 @@ mod tests {
&Entry {
name: "yargs",
version: "17.5.1",
descriptors: vec![("yargs", "^17.5.1")],
descriptors: vec![("yargs", if with_bug { "^17.5.1" } else { "npm:^17.5.1" })],
dependencies: vec![
("cliui", "^7.0.2"),
("escalade", "^3.1.1"),
Expand Down Expand Up @@ -657,21 +656,21 @@ __metadata:
Entry {
name: "@babel/helper-plugin-utils",
version: "7.16.7",
descriptors: vec![("@babel/helper-plugin-utils", "^7.16.7")],
descriptors: vec![("@babel/helper-plugin-utils", "npm:^7.16.7")],
integrity: "d08dd86554a186c2538547cd537552e4029f704994a9201d41d82015c10ed7f58f9036e8d1527c3760f042409163269d308b0b3706589039c5f1884619c6d4ce",
..Default::default()
},
Entry {
name: "@babel/plugin-transform-for-of",
version: "7.16.7",
descriptors: vec![("@babel/plugin-transform-for-of", "^7.12.1")],
descriptors: vec![("@babel/plugin-transform-for-of", "npm:^7.12.1")],
dependencies: vec![("@babel/helper-plugin-utils", "^7.16.7")],
integrity: "35c9264ee4bef814818123d70afe8b2f0a85753a0a9dc7b73f93a71cadc5d7de852f1a3e300a7c69a491705805704611de1e2ccceb5686f7828d6bca2e5a7306",
},
Entry {
name: "@babel/runtime",
version: "7.17.9",
descriptors: vec![("@babel/runtime", "^7.12.5")],
descriptors: vec![("@babel/runtime", "npm:^7.12.5")],
dependencies: vec![("regenerator-runtime", "^0.13.4")],
integrity: "4d56bdb82890f386d5a57c40ef985a0ed7f0a78f789377a2d0c3e8826819e0f7f16ba0fe906d9b2241c5f7ca56630ef0653f5bb99f03771f7b87ff8af4bf5fe3"
},
Expand Down Expand Up @@ -714,7 +713,7 @@ __metadata:
name: "foo",
version: "0.0.0-use.local",
integrity: "",
descriptors: vec![("foo", ".")],
descriptors: vec![("foo", "workspace:.")],
dependencies: vec![("valib-aliased", "1.0.0 || 1.0.1")],
},
Entry {
Expand Down Expand Up @@ -988,16 +987,16 @@ __metadata:
version "2.0.3"
"#,
vec![
("@nodelib/fs.stat", "2.0.3"),
("@nodelib/fs.stat", "^2.0.2"),
("@nodelib/fs.stat", "npm:2.0.3"),
("@nodelib/fs.stat", "npm:^2.0.2"),
],
);

assert(
r#"foolib@npm:1.2.3 || ^2.0.0":
version "1.2.3"
"#,
vec![("foolib", "1.2.3 || ^2.0.0")],
vec![("foolib", "npm:1.2.3 || ^2.0.0")],
);
}

Expand Down Expand Up @@ -1089,4 +1088,24 @@ __metadata:
let res = parse(&content);
assert!(!res.is_err());
}

#[test]
fn supports_git_url_descriptor() {
let content = std::fs::read_to_string("tests/v1_git_url/yarn.lock").unwrap();
let res = parse_str(&content).unwrap();

assert_eq!(
res.entries.last().unwrap(),
&Entry {
name: "minimatch",
version: "10.0.1",
integrity: "",
dependencies: vec![("brace-expansion", "^2.0.1")],
descriptors: vec![(
"minimatch",
"https://github.com/isaacs/minimatch.git#v10.0.1"
)],
}
);
}
}
54 changes: 54 additions & 0 deletions tests/v1_git_url/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"

is-buffer@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-even@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-even/-/is-even-1.0.0.tgz#76b5055fbad8d294a86b6a949015e1c97b717c06"
integrity sha512-LEhnkAdJqic4Dbqn58A0y52IXoHWlsueqQkKfMfdEnIYG8A1sm/GHidKkS6yvXlMoRrkM34csHnXQtOqcb+Jzg==
dependencies:
is-odd "^0.1.2"

is-number@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195"
integrity sha512-4cboCqIpliH+mAvFNegjZQ4kgKc3ZUhQVr3HvWbSh5q3WH2v82ct+T2Y1hdU5Gdtorx/cLifQjqCbL7bpznLTg==
dependencies:
kind-of "^3.0.2"

is-odd@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/is-odd/-/is-odd-0.1.2.tgz#bc573b5ce371ef2aad6e6f49799b72bef13978a7"
integrity sha512-Ri7C2K7o5IrUU9UEI8losXJCCD/UtsaIrkR5sxIcFg4xQ9cRJXlWA5DQvTE0yDc0krvSNLsRGXN11UPS6KyfBw==
dependencies:
is-number "^3.0.0"

kind-of@^3.0.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
integrity sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==
dependencies:
is-buffer "^1.1.5"

"minimatch@https://github.com/isaacs/minimatch.git#v10.0.1":
version "10.0.1"
resolved "https://github.com/isaacs/minimatch.git#0569cd3373408f9d701d3aab187b3f43a24a0db7"
dependencies:
brace-expansion "^2.0.1"
Loading