mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
file protocol and abs path (#10493)
This commit is contained in:
@@ -131,49 +131,58 @@ it("should reject missing package", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["file://", "file:/", "file:"])("should accept file protocol with prefix %s", async protocolPrefix => {
|
||||
await writeFile(
|
||||
join(add_dir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "foo",
|
||||
version: "1.2.3",
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(package_dir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "bar",
|
||||
version: "2.3.4",
|
||||
}),
|
||||
);
|
||||
const add_path = relative(package_dir, add_dir);
|
||||
const dep = `${protocolPrefix}${add_path.replace(/\\/g, "/")}`;
|
||||
const { stdout, stderr, exited } = spawn({
|
||||
cmd: [bunExe(), "add", dep],
|
||||
cwd: package_dir,
|
||||
stdout: "pipe",
|
||||
stdin: "pipe",
|
||||
stderr: "pipe",
|
||||
env,
|
||||
});
|
||||
for (const pathType of ["absolute", "relative"]) {
|
||||
it.each(["file:///", "file://", "file:/", "file:", "", "//////"])(
|
||||
`should accept ${pathType} file protocol with prefix "%s"`,
|
||||
async protocolPrefix => {
|
||||
await writeFile(
|
||||
join(add_dir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "foo",
|
||||
version: "1.2.3",
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(package_dir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "bar",
|
||||
version: "2.3.4",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(stderr).toBeDefined();
|
||||
const err = await new Response(stderr).text();
|
||||
expect(err).not.toContain("error:");
|
||||
expect(err).not.toContain("panic:");
|
||||
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([
|
||||
"",
|
||||
` installed foo@${add_path.replace(/\\/g, "/")}`,
|
||||
"",
|
||||
" 1 package installed",
|
||||
]);
|
||||
expect(await exited).toBe(0);
|
||||
});
|
||||
const add_path_rel = relative(package_dir, add_dir);
|
||||
const add_path_abs = add_dir;
|
||||
|
||||
it.each(["fileblah://", "file:///"])("should reject invalid path without segfault: %s", async protocolPrefix => {
|
||||
const add_dep = `${protocolPrefix}${pathType == "relative" && protocolPrefix != "//////" ? add_path_rel : add_path_abs}`;
|
||||
|
||||
const { stdout, stderr, exited } = spawn({
|
||||
cmd: [bunExe(), "add", add_dep],
|
||||
cwd: package_dir,
|
||||
stdout: "pipe",
|
||||
stdin: "pipe",
|
||||
stderr: "pipe",
|
||||
env,
|
||||
});
|
||||
|
||||
expect(stderr).toBeDefined();
|
||||
const err = await new Response(stderr).text();
|
||||
expect(err).not.toContain("error:");
|
||||
expect(err).not.toContain("panic:");
|
||||
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([
|
||||
"",
|
||||
` installed foo@${add_path_rel.replace(/\\/g, "/")}`,
|
||||
"",
|
||||
" 1 package installed",
|
||||
]);
|
||||
expect(await exited).toBe(0);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
it.each(["fileblah://"])("should reject invalid path without segfault: %s", async protocolPrefix => {
|
||||
await writeFile(
|
||||
join(add_dir, "package.json"),
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user