fix(install): dont replace git urls when already present (#6607)

* fix: dont replace git urls when already present

* fix: set request e_string

* test: add test for git url duplication
This commit is contained in:
Liz
2023-10-20 06:28:59 +02:00
committed by GitHub
parent bb623196a3
commit f6b694ee2c
2 changed files with 56 additions and 0 deletions

View File

@@ -5221,6 +5221,19 @@ pub const PackageManager = struct {
}
}
break;
} else {
if (request.version.tag == .github or request.version.tag == .git) {
for (query.expr.data.e_object.properties.slice()) |item| {
if (item.value) |v| {
const url = request.version.literal.slice(request.version_buf);
if (v.data == .e_string and v.data.e_string.eql(string, url)) {
request.e_string = v.data.e_string;
remaining -= 1;
break;
}
}
}
}
}
}
}

View File

@@ -1114,6 +1114,49 @@ it("should handle Git URL in dependencies (SCP-style)", async () => {
expect(requested).toBe(0);
}, 20000);
it("should not save git urls twice", async () => {
const urls: string[] = [];
setHandler(dummyRegistry(urls));
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "foo",
version: "0.0.1",
}),
);
const { exited: exited1 } = spawn({
cmd: [bunExe(), "add", "https://github.com/liz3/bun-ui.git"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});
expect(await exited1).toBe(0);
const package_json_content = await file(join(package_dir, "package.json")).json();
expect(package_json_content.dependencies).toEqual({
"bun-ui": "https://github.com/liz3/bun-ui.git",
});
const { exited: exited2 } = spawn({
cmd: [bunExe(), "add", "https://github.com/liz3/bun-ui.git"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});
expect(await exited2).toBe(0);
const package_json_content2 = await file(join(package_dir, "package.json")).json();
expect(package_json_content2.dependencies).toEqual({
"bun-ui": "https://github.com/liz3/bun-ui.git",
});
}, 20000);
it("should prefer optionalDependencies over dependencies of the same name", async () => {
const urls: string[] = [];
setHandler(