Compare commits

...

3 Commits

Author SHA1 Message Date
Dylan Conway
e9470121d2 more docs 2023-10-10 18:50:46 -07:00
Dylan Conway
ee2e34866e Merge branch 'main' into dylan/github-api-option 2023-10-10 15:28:08 -07:00
Dylan Conway
e6d97f2581 add install.github.api option 2023-10-05 16:39:12 -07:00
13 changed files with 99 additions and 8 deletions

View File

@@ -62,6 +62,9 @@ dev = true
# Install peerDependencies (default: false)
peer = false
# Whether to use the github REST api (unauthenticated)
github.api = true
# When using `bun install -g`, install packages here
globalDir = "~/.bun/install/global"

View File

@@ -89,6 +89,9 @@ frozenLockfile = false
# equivalent to `--dry-run` flag
dryRun = false
# whether to use the github REST api (unauthenticated)
github.api = true
```
{% /details %}

View File

@@ -91,6 +91,9 @@ frozenLockfile = false
# equivalent to `--dry-run` flag
dryRun = false
# whether to use the github REST api (unauthenticated)
github.api = true
```
{% /details %}

View File

@@ -216,6 +216,17 @@ Whether to install peer dependencies. Default `false`.
peer = false
```
### `install.github.api`
Enable using the github REST API to install github dependencies. Default `true`.
Private github repositories will fail to install if this option is true because the REST API is unauthenticated.
```toml
[install]
github.api = true
```
### `install.production`
Whether `bun install` will run in "production mode". Default `false`.

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

@@ -4545,6 +4545,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;
}
@@ -4675,6 +4677,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,24 @@ 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 \"{s}\" 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),
failed_dep.name.slice(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;
}