Skip to content

Commit

Permalink
Support github: protocol with hash (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Mar 2, 2024
1 parent d60ec4a commit 939ad2c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ where
T: nom::InputTakeAtPosition,
<T as nom::InputTakeAtPosition>::Item: AsChar,
{
let allowed_chars = ['.', '-', '@', ':', '/'];
let allowed_chars = ['.', '-', '@', ':', '/', '#'];
input.split_at_position1_complete(
|item| {
let c: char = item.as_char();
Expand Down Expand Up @@ -867,6 +867,29 @@ __metadata:
entry_version(" version: \"workspace:@bar/baz\"\r\n"),
Ok(("", EntryItem::Version("workspace:@bar/baz")))
);

// github:
assert_eq!(
entry_version(" version \"github:settlemint/node-http-proxy\"\r\n"),
Ok(("", EntryItem::Version("github:settlemint/node-http-proxy")))
);
assert_eq!(
entry_version(" version \"github:settlemint/node-http-proxy#master\"\n"),
Ok((
"",
EntryItem::Version("github:settlemint/node-http-proxy#master")
))
);

// npm:
assert_eq!(
entry_version(" version \"npm:foo-bar\"\r\n"),
Ok(("", EntryItem::Version("npm:foo-bar")))
);
assert_eq!(
entry_version(" version \"npm:@scope/foo-bar\"\r\n"),
Ok(("", EntryItem::Version("npm:@scope/foo-bar")))
);
}

#[test]
Expand Down Expand Up @@ -996,4 +1019,22 @@ __metadata:
assert_eq!(k.0, "bar");
assert_eq!(k.1, "foo\r\n");
}

#[test]
fn supports_github_version_protocol() {
// yarn > 1
let content = std::fs::read_to_string("tests/github_version/yarn.lock").unwrap();
let res = parse(&content);
assert!(!res.is_err());

// yarn 1
let content = std::fs::read_to_string("tests/github_version/yarn1.lock").unwrap();
let res = parse(&content);
assert!(!res.is_err());

// bun
let content = std::fs::read_to_string("tests/github_version/bun.lock").unwrap();
let res = parse(&content);
assert!(!res.is_err());
}
}
27 changes: 27 additions & 0 deletions tests/github_version/bun.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 7F473F5D2B55CA2E-cb32e6eeae8aaed5-4B75F0417FE02D3A-7529672ac3001866


eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

follow-redirects@^1.0.0:
version "1.15.5"
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz"
integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==

"http-proxy@github:settlemint/node-http-proxy#master":
version "github:settlemint/node-http-proxy#a19114f"
resolved "github:settlemint/node-http-proxy#a19114f"
dependencies:
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"

requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz"
integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==
49 changes: 49 additions & 0 deletions tests/github_version/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 6
cacheKey: 8

"eventemitter3@npm:^4.0.0":
version: 4.0.7
resolution: "eventemitter3@npm:4.0.7"
checksum: 1875311c42fcfe9c707b2712c32664a245629b42bb0a5a84439762dd0fd637fc54d078155ea83c2af9e0323c9ac13687e03cfba79b03af9f40c89b4960099374
languageName: node
linkType: hard

"follow-redirects@npm:^1.0.0":
version: 1.15.5
resolution: "follow-redirects@npm:1.15.5"
peerDependenciesMeta:
debug:
optional: true
checksum: 5ca49b5ce6f44338cbfc3546823357e7a70813cecc9b7b768158a1d32c1e62e7407c944402a918ea8c38ae2e78266312d617dc68783fac502cbb55e1047b34ec
languageName: node
linkType: hard

"http-proxy@github:settlemint/node-http-proxy#master":
version: 1.18.1
resolution: "http-proxy@https://github.com/settlemint/node-http-proxy.git#commit=a19114ff99d40de15ef1112fe344e31f2328e521"
dependencies:
eventemitter3: ^4.0.0
follow-redirects: ^1.0.0
requires-port: ^1.0.0
checksum: 97bac218fcc81afc9174c223671812e351b60d4c1610afbb9266bcdd26749c6deecda612bfb120d4bb15a20e47b4165b713ad1199bd09b231e81aa4aa5d5bb36
languageName: node
linkType: hard

"requires-port@npm:^1.0.0":
version: 1.0.0
resolution: "requires-port@npm:1.0.0"
checksum: eee0e303adffb69be55d1a214e415cf42b7441ae858c76dfc5353148644f6fd6e698926fc4643f510d5c126d12a705e7c8ed7e38061113bdf37547ab356797ff
languageName: node
linkType: hard

"test@workspace:.":
version: 0.0.0-use.local
resolution: "test@workspace:."
dependencies:
http-proxy: "github:settlemint/node-http-proxy#master"
languageName: unknown
linkType: soft
26 changes: 26 additions & 0 deletions tests/github_version/yarn1.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

follow-redirects@^1.0.0:
version "1.15.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020"
integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==

"http-proxy@github:settlemint/node-http-proxy#master":
version "1.18.1"
resolved "https://codeload.github.com/settlemint/node-http-proxy/tar.gz/a19114ff99d40de15ef1112fe344e31f2328e521"
dependencies:
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"

requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==

0 comments on commit 939ad2c

Please sign in to comment.