[bun install] Strip leading v in versions

This commit is contained in:
Jarred Sumner
2021-12-20 17:52:50 -08:00
parent 3f32222360
commit 453fae4a5c

View File

@@ -351,6 +351,21 @@ pub const Version = struct {
return .dist_tag;
},
// Dependencies can start with v
// v1.0.0 is the same as 1.0.0
// However, a github repo or a tarball could start with v
'v' => {
if (isTarball(dependency)) {
return .tarball;
}
if (isGithubRepoPath(dependency)) {
return .github;
}
return .npm;
},
// file:
'f' => {
if (isTarball(dependency))
@@ -468,6 +483,13 @@ pub fn parse(allocator: *std.mem.Allocator, dependency_: string, sliced: *const
dependency = dependency[4..];
}
// Strip single leading v
// v1.0.0 -> 1.0.0
// note: "vx" is valid, it becomes "x". "yarn add react@vx" -> "yarn add react@x" -> "yarn add react@17.0.2"
if (tag == .npm and dependency.len > 1 and dependency[0] == 'v') {
dependency = dependency[1..];
}
return parseWithTag(
allocator,
dependency,