diff options
author | 2023-10-05 16:39:12 -0700 | |
---|---|---|
committer | 2023-10-05 16:39:12 -0700 | |
commit | e6d97f2581959d77a5b486faefbfdf094abedf9b (patch) | |
tree | 6298631c63ab9f0e0ca2248ca04676fd62376370 | |
parent | 4a2e1574e4d4001b60c96a315491dd622d7d54b6 (diff) | |
download | bun-e6d97f2581959d77a5b486faefbfdf094abedf9b.tar.gz bun-e6d97f2581959d77a5b486faefbfdf094abedf9b.tar.zst bun-e6d97f2581959d77a5b486faefbfdf094abedf9b.zip |
add `install.github.api` option
-rw-r--r-- | src/api/schema.d.ts | 1 | ||||
-rw-r--r-- | src/api/schema.js | 10 | ||||
-rw-r--r-- | src/api/schema.peechy | 1 | ||||
-rw-r--r-- | src/api/schema.zig | 10 | ||||
-rw-r--r-- | src/bunfig.zig | 8 | ||||
-rw-r--r-- | src/install/dependency.zig | 7 | ||||
-rw-r--r-- | src/install/install.zig | 5 | ||||
-rw-r--r-- | src/install/lockfile.zig | 24 | ||||
-rw-r--r-- | src/install/repository.zig | 20 | ||||
-rw-r--r-- | test/cli/install/bun-install.test.ts | 4 |
10 files changed, 80 insertions, 10 deletions
diff --git a/src/api/schema.d.ts b/src/api/schema.d.ts index 3ec03e213..c481b8fed 100644 --- a/src/api/schema.d.ts +++ b/src/api/schema.d.ts @@ -719,6 +719,7 @@ export interface BunInstall { global_bin_dir?: string; frozen_lockfile?: boolean; exact?: boolean; + use_github_api?: boolean; } export interface ClientServerModule { diff --git a/src/api/schema.js b/src/api/schema.js index 6fb4b1d8d..38f30156b 100644 --- a/src/api/schema.js +++ b/src/api/schema.js @@ -3038,6 +3038,10 @@ function decodeBunInstall(bb) { result["exact"] = !!bb.readByte(); break; + case 21: + result["use_github_api"] = !!bb.readByte(); + break; + default: throw new Error("Attempted to parse invalid message"); } @@ -3170,6 +3174,12 @@ function encodeBunInstall(message, bb) { bb.writeByte(20); bb.writeByte(value); } + + var value = message["use_github_api"]; + if (value != null) { + bb.writeByte(21); + bb.writeByte(value); + } bb.writeByte(0); } diff --git a/src/api/schema.peechy b/src/api/schema.peechy index 8185733c9..91d4f682c 100644 --- a/src/api/schema.peechy +++ b/src/api/schema.peechy @@ -588,6 +588,7 @@ message BunInstall { string global_bin_dir = 18; bool frozen_lockfile = 19; bool exact = 20; + bool use_github_api = 21; } struct ClientServerModule { diff --git a/src/api/schema.zig b/src/api/schema.zig index 79a98cfa8..ca3c66e67 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -2882,6 +2882,9 @@ pub const Api = struct { /// exact exact: ?bool = null, + /// use_github_api + use_github_api: ?bool = null, + pub fn decode(reader: anytype) anyerror!BunInstall { var this = std.mem.zeroes(BunInstall); @@ -2951,6 +2954,9 @@ pub const Api = struct { 20 => { this.exact = try reader.readValue(bool); }, + 21 => { + this.use_github_api = try reader.readValue(bool); + }, else => { return error.InvalidMessage; }, @@ -3040,6 +3046,10 @@ pub const Api = struct { try writer.writeFieldID(20); try writer.writeInt(@as(u8, @intFromBool(exact))); } + if (this.use_github_api) |use_github_api| { + try writer.writeFieldID(21); + try writer.writeInt(@as(u8, @intFromBool(use_github_api))); + } try writer.endMessage(); } }; diff --git a/src/bunfig.zig b/src/bunfig.zig index a777475da..3acdf8929 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -340,6 +340,14 @@ pub const Bunfig = struct { install.default_registry = try this.parseRegistry(registry); } + if (_bun.get("github")) |github| { + if (github.get("api")) |api| { + if (api.asBool()) |use_api| { + install.use_github_api = use_api; + } + } + } + if (_bun.get("scopes")) |scopes| { var registry_map = install.scoped orelse std.mem.zeroes(Api.NpmRegistryMap); try this.expect(scopes, .e_object); diff --git a/src/install/dependency.zig b/src/install/dependency.zig index cb73c04e1..c070a368b 100644 --- a/src/install/dependency.zig +++ b/src/install/dependency.zig @@ -13,6 +13,7 @@ const String = Semver.String; const std = @import("std"); const string = @import("../string_types.zig").string; const strings = @import("../string_immutable.zig"); +const PackageManager = @import("./install.zig").PackageManager; const Dependency = @This(); const URI = union(Tag) { @@ -686,7 +687,11 @@ pub fn parseWithOptionalTag( allocator, alias, dep, - tag orelse Version.Tag.infer(dep), + tag orelse brk: { + const t = Version.Tag.infer(dep); + if (t == .github) break :brk if (PackageManager.instance.options.use_github_api) .github else .git; + break :brk t; + }, sliced, log, ); diff --git a/src/install/install.zig b/src/install/install.zig index cee080116..0c9f44ccc 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -4536,6 +4536,8 @@ pub const PackageManager = struct { max_retry_count: u16 = 5, min_simultaneous_requests: usize = 4, + use_github_api: bool = true, + pub fn shouldPrintCommandName(this: *const Options) bool { return this.log_level != .silent and this.do.summary; } @@ -4666,6 +4668,9 @@ pub const PackageManager = struct { if (bun_install.default_registry) |registry| { base = registry; } + if (bun_install.use_github_api) |use_github_api| { + this.use_github_api = use_github_api; + } } if (base.url.len == 0) base.url = Npm.Registry.default_url; this.scope = try Npm.Registry.Scope.fromAPI("", base, allocator, env); diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index acd40b42e..4b04c5f2d 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -1505,13 +1505,23 @@ pub fn verifyResolutions(this: *Lockfile, local_features: Features, remote_featu }, ); } else { - Output.prettyErrorln( - "<r><red>error<r><d>:<r> <b>{s}<r><d>@<b>{}<r><d> failed to resolve<r>\n", - .{ - failed_dep.name.slice(string_buf), - failed_dep.version.literal.fmt(string_buf), - }, - ); + if (failed_dep.version.tag == .github) { + Output.prettyErrorln( + "<r><red>error<r><d>:<r> <b>{s}<r><d>@<b>{}<r><d> failed to resolve<r>\nIf this is a private repository set install.github.api to false in bunfig.toml\n\n", + .{ + failed_dep.name.slice(string_buf), + failed_dep.version.literal.fmt(string_buf), + }, + ); + } else { + Output.prettyErrorln( + "<r><red>error<r><d>:<r> <b>{s}<r><d>@<b>{}<r><d> failed to resolve<r>\n", + .{ + failed_dep.name.slice(string_buf), + failed_dep.version.literal.fmt(string_buf), + }, + ); + } } } // track this so we can log each failure instead of just the first diff --git a/src/install/repository.zig b/src/install/repository.zig index 17afec079..6dcdc2646 100644 --- a/src/install/repository.zig +++ b/src/install/repository.zig @@ -156,6 +156,26 @@ pub const Repository = extern struct { return final_path_buf[0 .. url.len + "https://".len]; } + { + var i: usize = 0; + while (i < url.len) { + switch (url[i]) { + '/' => { + if (i < url.len - 1) { + // username/repo-name + final_path_buf[0.."https://github.com/".len].* = "https://github.com/".*; + bun.copy(u8, final_path_buf["https://github.com/".len..], url); + return final_path_buf[0 .. url.len + "https://github.com/".len]; + } + }, + '@', ':', '+' => return null, + else => {}, + } + + i += 1; + } + } + return null; } diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index 8f922a0e0..2277ee61b 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -2685,7 +2685,7 @@ it("should handle bitbucket git dependencies", async () => { expect(stdout).toBeDefined(); const out = await new Response(stdout).text(); expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ - ` + public-install-test@git+ssh://${dep}#56ee8a7e167c6ab10b672203f2ab6fbcb752788d`, + ` + public-install-test@git+ssh://${dep}#79265e2d9754c60b60f97cc8d859fb6da073b5d2`, "", " 1 packages installed", ]); @@ -2722,7 +2722,7 @@ it("should handle bitbucket git dependencies", async () => { const out = await new Response(stdout).text(); expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ "", - ` installed publicinstalltest@git+ssh://${dep}#56ee8a7e167c6ab10b672203f2ab6fbcb752788d`, + ` installed publicinstalltest@git+ssh://${dep}#79265e2d9754c60b60f97cc8d859fb6da073b5d2`, "", "", " 1 packages installed", |