aboutsummaryrefslogtreecommitdiff
path: root/src/install/repository.zig
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
commit7458b969c5d9971e89d187b687e1924e78da427e (patch)
treeee3dbf95c728cf407bf49a27826b541e9264a8bd /src/install/repository.zig
parentd4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff)
parente91436e5248d947b50f90b4a7402690be8a41f39 (diff)
downloadbun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz
bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst
bun-7458b969c5d9971e89d187b687e1924e78da427e.zip
Merge branch 'main' into postinstall_3
Diffstat (limited to 'src/install/repository.zig')
-rw-r--r--src/install/repository.zig28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/install/repository.zig b/src/install/repository.zig
index 564306733..17afec079 100644
--- a/src/install/repository.zig
+++ b/src/install/repository.zig
@@ -27,6 +27,12 @@ pub const Repository = extern struct {
resolved: GitSHA = .{},
package_name: String = .{},
+ pub const Hosts = bun.ComptimeStringMap(string, .{
+ .{ "bitbucket", ".org" },
+ .{ "github", ".com" },
+ .{ "gitlab", ".com" },
+ });
+
pub fn verify(this: *const Repository) void {
this.owner.assertDefined();
this.repo.assertDefined();
@@ -125,15 +131,31 @@ pub const Repository = extern struct {
if (strings.hasPrefixComptime(url, "ssh://")) {
final_path_buf[0.."https".len].* = "https".*;
bun.copy(u8, final_path_buf["https".len..], url["ssh".len..]);
- return final_path_buf[0..(url.len - "ssh".len + "https".len)];
+ return final_path_buf[0 .. url.len - "ssh".len + "https".len];
}
+
if (Dependency.isSCPLikePath(url)) {
final_path_buf[0.."https://".len].* = "https://".*;
var rest = final_path_buf["https://".len..];
+
+ const colon_index = strings.indexOfChar(url, ':');
+
+ if (colon_index) |colon| {
+ // make sure known hosts have `.com` or `.org`
+ if (Hosts.get(url[0..colon])) |tld| {
+ bun.copy(u8, rest, url[0..colon]);
+ bun.copy(u8, rest[colon..], tld);
+ rest[colon + tld.len] = '/';
+ bun.copy(u8, rest[colon + tld.len + 1 ..], url[colon + 1 ..]);
+ return final_path_buf[0 .. url.len + "https://".len + tld.len];
+ }
+ }
+
bun.copy(u8, rest, url);
- if (strings.indexOfChar(rest, ':')) |colon| rest[colon] = '/';
- return final_path_buf[0..(url.len + "https://".len)];
+ if (colon_index) |colon| rest[colon] = '/';
+ return final_path_buf[0 .. url.len + "https://".len];
}
+
return null;
}