diff options
author | 2023-09-20 11:14:55 -0700 | |
---|---|---|
committer | 2023-09-20 11:14:55 -0700 | |
commit | 67defd95afb8f19259b2bde9be10e1a76a8137b5 (patch) | |
tree | 19354b3323951e16b03b414adbf53bf0c627a94e | |
parent | aa3355dc823b9166c162094bad55c90bf15d144c (diff) | |
download | bun-67defd95afb8f19259b2bde9be10e1a76a8137b5.tar.gz bun-67defd95afb8f19259b2bde9be10e1a76a8137b5.tar.zst bun-67defd95afb8f19259b2bde9be10e1a76a8137b5.zip |
[bun install] Add `-E` as alias of `--exact` (#5104)
* [bun install] Add `-E` as alias of `--exact`
* Add test for -E flag
-rw-r--r-- | src/install/install.zig | 4 | ||||
-rw-r--r-- | test/cli/install/bun-add.test.ts | 55 |
2 files changed, 57 insertions, 2 deletions
diff --git a/src/install/install.zig b/src/install/install.zig index 28a96643d..128534191 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -5828,7 +5828,7 @@ pub const PackageManager = struct { clap.parseParam("-d, --dev Add dependency to \"devDependencies\"") catch unreachable, clap.parseParam("-D, --development") catch unreachable, clap.parseParam("--optional Add dependency to \"optionalDependencies\"") catch unreachable, - clap.parseParam("--exact Add the exact version instead of the ^range") catch unreachable, + clap.parseParam("-E, --exact Add the exact version instead of the ^range") catch unreachable, clap.parseParam("<POS> ... ") catch unreachable, }; @@ -5844,7 +5844,7 @@ pub const PackageManager = struct { clap.parseParam("-d, --dev Add dependency to \"devDependencies\"") catch unreachable, clap.parseParam("-D, --development") catch unreachable, clap.parseParam("--optional Add dependency to \"optionalDependencies\"") catch unreachable, - clap.parseParam("--exact Add the exact version instead of the ^range") catch unreachable, + clap.parseParam("-E, --exact Add the exact version instead of the ^range") catch unreachable, clap.parseParam("<POS> ... \"name\" or \"name@version\" of packages to install") catch unreachable, }; diff --git a/test/cli/install/bun-add.test.ts b/test/cli/install/bun-add.test.ts index 14ae44f73..eff7fa843 100644 --- a/test/cli/install/bun-add.test.ts +++ b/test/cli/install/bun-add.test.ts @@ -360,6 +360,61 @@ it("should add exact version", async () => { await access(join(package_dir, "bun.lockb")); }); +it("should add exact version with -E", 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", "-E", "BaR"], + 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")).text()).toEqual( + JSON.stringify( + { + name: "foo", + version: "0.0.1", + dependencies: { + BaR: "0.0.2", + }, + }, + null, + 2, + ), + ); + await access(join(package_dir, "bun.lockb")); +}); + it("should add dependency with specified semver", async () => { const urls: string[] = []; setHandler( |