diff options
author | 2023-02-18 00:46:07 +0200 | |
---|---|---|
committer | 2023-02-17 14:46:07 -0800 | |
commit | 79f7d29d034586b352a44a71bd10ffc47112545f (patch) | |
tree | e4c5e05d503776e7daaa341b9d7a54788e945312 | |
parent | 56b75dbac32233b49b33c12ce25a07c9e9083dee (diff) | |
download | bun-79f7d29d034586b352a44a71bd10ffc47112545f.tar.gz bun-79f7d29d034586b352a44a71bd10ffc47112545f.tar.zst bun-79f7d29d034586b352a44a71bd10ffc47112545f.zip |
allow `bun add` of packages with capital letters (#2095)
-rw-r--r-- | src/string_immutable.zig | 4 | ||||
-rw-r--r-- | test/bun.js/install/bun-add.test.ts | 49 | ||||
-rw-r--r-- | test/bun.js/install/dummy.registry.ts | 2 |
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, */*", |