add install.github.api option

This commit is contained in:
Dylan Conway
2023-10-05 16:39:12 -07:00
parent 4a2e1574e4
commit e6d97f2581
10 changed files with 80 additions and 10 deletions

1
src/api/schema.d.ts generated vendored
View File

@@ -719,6 +719,7 @@ export interface BunInstall {
global_bin_dir?: string;
frozen_lockfile?: boolean;
exact?: boolean;
use_github_api?: boolean;
}
export interface ClientServerModule {

10
src/api/schema.js generated
View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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();
}
};

View File

@@ -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);

View File

@@ -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,
);

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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",