aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/string_immutable.zig4
-rw-r--r--test/bun.js/install/bun-add.test.ts49
-rw-r--r--test/bun.js/install/dummy.registry.ts2
3 files changed, 53 insertions, 2 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 5f5b943d6..869235fcb 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -94,13 +94,15 @@ pub inline fn isNPMPackageName(target: string) bool {
if (target.len > 214) return false;
const scoped = switch (target[0]) {
- 'a'...'z', '0'...'9', '$', '-' => false,
+ // Old packages may have capital letters
+ 'A'...'Z', 'a'...'z', '0'...'9', '$', '-' => false,
'@' => true,
else => return false,
};
var slash_index: usize = 0;
for (target[1..]) |c, i| {
switch (c) {
+ // Old packages may have capital letters
'A'...'Z', 'a'...'z', '0'...'9', '$', '-', '_', '.' => {},
'/' => {
if (!scoped) return false;
diff --git a/test/bun.js/install/bun-add.test.ts b/test/bun.js/install/bun-add.test.ts
index 22974a82c..ef8025a6a 100644
--- a/test/bun.js/install/bun-add.test.ts
+++ b/test/bun.js/install/bun-add.test.ts
@@ -239,6 +239,55 @@ it("should handle @scoped names", async () => {
}
});
+it("should add dependency with capital letters", async () => {
+ const urls: string[] = [];
+ setHandler(dummyRegistry(urls));
+ await writeFile(
+ join(package_dir, "package.json"),
+ JSON.stringify({
+ name: "foo",
+ version: "0.0.1",
+ }),
+ );
+ const { stdout, stderr, exited } = spawn({
+ cmd: [bunExe(), "add", "BaR", "--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([
+ "",
+ " installed BaR@0.0.2",
+ "",
+ "",
+ " 1 packages installed",
+ ]);
+ expect(await exited).toBe(0);
+ expect(urls.sort()).toEqual([`${root_url}/BaR`, `${root_url}/BaR-0.0.2.tgz`]);
+ expect(requested).toBe(2);
+ expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "BaR"]);
+ expect(await readdirSorted(join(package_dir, "node_modules", "BaR"))).toEqual(["package.json"]);
+ expect(await file(join(package_dir, "node_modules", "BaR", "package.json")).json()).toEqual({
+ name: "bar",
+ version: "0.0.2",
+ });
+ expect(await file(join(package_dir, "package.json")).json()).toEqual({
+ name: "foo",
+ version: "0.0.1",
+ dependencies: {
+ BaR: "^0.0.2",
+ },
+ });
+ await access(join(package_dir, "bun.lockb"));
+});
+
it("should add dependency with specified semver", async () => {
const urls: string[] = [];
setHandler(
diff --git a/test/bun.js/install/dummy.registry.ts b/test/bun.js/install/dummy.registry.ts
index fd6e652a8..bc4554a47 100644
--- a/test/bun.js/install/dummy.registry.ts
+++ b/test/bun.js/install/dummy.registry.ts
@@ -12,7 +12,7 @@ export function dummyRegistry(urls, info: any = { "0.0.2": {} }) {
urls.push(request.url);
expect(request.method).toBe("GET");
if (request.url.endsWith(".tgz")) {
- return new Response(file(join(import.meta.dir, basename(request.url))));
+ return new Response(file(join(import.meta.dir, basename(request.url).toLowerCase())));
}
expect(request.headers.get("accept")).toBe(
"application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*",