mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[install] support git://github.com/ dependencies (#2059)
This commit is contained in:
@@ -187,7 +187,7 @@ pub const Version = struct {
|
||||
}
|
||||
|
||||
pub fn isLessThan(string_buf: []const u8, lhs: Dependency.Version, rhs: Dependency.Version) bool {
|
||||
if (Environment.allow_assert) std.debug.assert(lhs.tag == rhs.tag);
|
||||
if (comptime Environment.allow_assert) std.debug.assert(lhs.tag == rhs.tag);
|
||||
return strings.cmpStringsAsc({}, lhs.literal.slice(string_buf), rhs.literal.slice(string_buf));
|
||||
}
|
||||
|
||||
@@ -375,7 +375,13 @@ pub const Version = struct {
|
||||
if (url.len > 2) {
|
||||
switch (url[0]) {
|
||||
':' => {
|
||||
if (strings.hasPrefixComptime(url, "://")) return .git;
|
||||
if (strings.hasPrefixComptime(url, "://")) {
|
||||
url = url["://".len..];
|
||||
if (strings.hasPrefixComptime(url, "github.com/")) {
|
||||
if (isGitHubRepoPath(url["github.com/".len..])) return .github;
|
||||
}
|
||||
return .git;
|
||||
}
|
||||
},
|
||||
'+' => {
|
||||
if (strings.hasPrefixComptime(url, "+ssh:") or
|
||||
@@ -670,7 +676,7 @@ pub fn parseWithTag(
|
||||
alias;
|
||||
|
||||
// name should never be empty
|
||||
if (Environment.allow_assert) std.debug.assert(!actual.isEmpty());
|
||||
if (comptime Environment.allow_assert) std.debug.assert(!actual.isEmpty());
|
||||
|
||||
return .{
|
||||
.literal = sliced.value(),
|
||||
@@ -688,6 +694,9 @@ pub fn parseWithTag(
|
||||
var input = dependency;
|
||||
if (strings.hasPrefixComptime(input, "github:")) {
|
||||
input = input["github:".len..];
|
||||
} else if (strings.hasPrefixComptime(input, "git://github.com/")) {
|
||||
input = input["git://github.com/".len..];
|
||||
from_url = true;
|
||||
} else {
|
||||
if (strings.hasPrefixComptime(input, "git+")) {
|
||||
input = input["git+".len..];
|
||||
@@ -716,7 +725,7 @@ pub fn parseWithTag(
|
||||
}
|
||||
}
|
||||
|
||||
if (Environment.allow_assert) std.debug.assert(Version.Tag.isGitHubRepoPath(input));
|
||||
if (comptime Environment.allow_assert) std.debug.assert(Version.Tag.isGitHubRepoPath(input));
|
||||
|
||||
var hash_index: usize = 0;
|
||||
var slash_index: usize = 0;
|
||||
|
||||
@@ -1567,6 +1567,75 @@ it("should handle GitHub URL in dependencies (https://github.com/user/repo.git)"
|
||||
await access(join(package_dir, "bun.lockb"));
|
||||
});
|
||||
|
||||
it("should handle GitHub URL in dependencies (git://github.com/user/repo.git#commit)", async () => {
|
||||
const urls: string[] = [];
|
||||
setHandler(dummyRegistry(urls));
|
||||
await writeFile(
|
||||
join(package_dir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "Foo",
|
||||
version: "0.0.1",
|
||||
dependencies: {
|
||||
uglify: "git://github.com/mishoo/UglifyJS.git#e219a9a",
|
||||
},
|
||||
}),
|
||||
);
|
||||
const { stdout, stderr, exited } = spawn({
|
||||
cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
|
||||
cwd: package_dir,
|
||||
stdout: null,
|
||||
stdin: "pipe",
|
||||
stderr: "pipe",
|
||||
env,
|
||||
});
|
||||
expect(stderr).toBeDefined();
|
||||
const err = await new Response(stderr).text();
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(stdout).toBeDefined();
|
||||
const out = await new Response(stdout).text();
|
||||
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
|
||||
" + uglify@github:mishoo/UglifyJS#e219a9a",
|
||||
"",
|
||||
" 1 packages installed",
|
||||
]);
|
||||
expect(await exited).toBe(0);
|
||||
expect(urls.sort()).toEqual([]);
|
||||
expect(requested).toBe(0);
|
||||
expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "uglify"]);
|
||||
expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["uglifyjs"]);
|
||||
expect(await readlink(join(package_dir, "node_modules", ".bin", "uglifyjs"))).toBe(
|
||||
join("..", "uglify", "bin", "uglifyjs"),
|
||||
);
|
||||
expect(await readdirSorted(join(package_dir, "node_modules", ".cache"))).toEqual([
|
||||
"@GH@mishoo-UglifyJS-e219a9a",
|
||||
"uglify",
|
||||
]);
|
||||
expect(await readdirSorted(join(package_dir, "node_modules", ".cache", "uglify"))).toEqual([
|
||||
"mishoo-UglifyJS-e219a9a",
|
||||
]);
|
||||
expect(await readlink(join(package_dir, "node_modules", ".cache", "uglify", "mishoo-UglifyJS-e219a9a"))).toBe(
|
||||
join(package_dir, "node_modules", ".cache", "@GH@mishoo-UglifyJS-e219a9a"),
|
||||
);
|
||||
expect(await readdirSorted(join(package_dir, "node_modules", "uglify"))).toEqual([
|
||||
".bun-tag",
|
||||
".gitattributes",
|
||||
".github",
|
||||
".gitignore",
|
||||
"CONTRIBUTING.md",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"bin",
|
||||
"lib",
|
||||
"package.json",
|
||||
"test",
|
||||
"tools",
|
||||
]);
|
||||
const package_json = await file(join(package_dir, "node_modules", "uglify", "package.json")).json();
|
||||
expect(package_json.name).toBe("uglify-js");
|
||||
expect(package_json.version).toBe("3.14.1");
|
||||
await access(join(package_dir, "bun.lockb"));
|
||||
});
|
||||
|
||||
it("should handle GitHub URL in dependencies (git+https://github.com/user/repo.git)", async () => {
|
||||
const urls: string[] = [];
|
||||
setHandler(dummyRegistry(urls));
|
||||
|
||||
Reference in New Issue
Block a user