Compare commits

...

1 Commits

Author SHA1 Message Date
Meghan Denny
5059489534 cli: add -C as an alias to --cwd 2025-06-06 17:01:25 -07:00
3 changed files with 58 additions and 2 deletions

View File

@@ -175,7 +175,7 @@ pub const Arguments = struct {
const base_params_ = (if (Environment.show_crash_trace) debug_params else [_]ParamType{}) ++ [_]ParamType{
clap.parseParam("--env-file <STR>... Load environment variables from the specified file(s)") catch unreachable,
clap.parseParam("--cwd <STR> Absolute path to resolve files & entry points from. This just changes the process' cwd.") catch unreachable,
clap.parseParam("-C, --cwd <STR> Absolute path to resolve files & entry points from. This just changes the process' cwd.") catch unreachable,
clap.parseParam("-c, --config <PATH>? Specify path to Bun config file. Default <d>$cwd<r>/bunfig.toml") catch unreachable,
clap.parseParam("-h, --help Display this menu and exit") catch unreachable,
} ++ (if (builtin.have_error_return_tracing) [_]ParamType{

View File

@@ -39,7 +39,7 @@ const shared_params = [_]ParamType{
clap.parseParam("--ignore-scripts Skip lifecycle scripts in the project's package.json (dependency scripts are never run)") catch unreachable,
clap.parseParam("--trust Add to trustedDependencies in the project's package.json and install the package(s)") catch unreachable,
clap.parseParam("-g, --global Install globally") catch unreachable,
clap.parseParam("--cwd <STR> Set a specific cwd") catch unreachable,
clap.parseParam("-C, --cwd <STR> Set a specific cwd") catch unreachable,
clap.parseParam("--backend <STR> Platform-specific optimizations for installing dependencies. " ++ platform_specific_backend_label) catch unreachable,
clap.parseParam("--registry <STR> Use a specific registry by default, overriding .npmrc, bunfig.toml and environment variables") catch unreachable,
clap.parseParam("--concurrent-scripts <NUM> Maximum number of concurrent jobs for lifecycle scripts (default 5)") catch unreachable,

View File

@@ -6153,6 +6153,62 @@ it("should handle --cwd", async () => {
});
});
it("should handle -C as an alias to --cwd", async () => {
const urls: string[] = [];
setHandler(dummyRegistry(urls));
const foo_package = JSON.stringify({
name: "foo",
version: "0.1.0",
});
await writeFile(join(package_dir, "package.json"), foo_package);
await mkdir(join(package_dir, "moo"));
await writeFile(join(package_dir, "moo", "bunfig.toml"), await file(join(package_dir, "bunfig.toml")).text());
const moo_package = JSON.stringify({
name: "moo",
version: "0.2.0",
dependencies: {
bar: "^0.0.2",
},
});
await writeFile(join(package_dir, "moo", "package.json"), moo_package);
const { stdout, stderr, exited } = spawn({
cmd: [bunExe(), "install", "-C", "moo"],
cwd: package_dir,
stdout: "pipe",
stdin: "pipe",
stderr: "pipe",
env,
});
const err = await new Response(stderr).text();
expect(err).toContain("Saved lockfile");
const out = await new Response(stdout).text();
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
"+ bar@0.0.2",
"",
"1 package 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(package_dir)).toEqual(["bunfig.toml", "moo", "package.json"]);
expect(await file(join(package_dir, "package.json")).text()).toEqual(foo_package);
expect(await readdirSorted(join(package_dir, "moo"))).toEqual([
"bun.lockb",
"bunfig.toml",
"node_modules",
"package.json",
]);
expect(await file(join(package_dir, "moo", "package.json")).text()).toEqual(moo_package);
expect(await readdirSorted(join(package_dir, "moo", "node_modules"))).toEqual([".cache", "bar"]);
expect(await readdirSorted(join(package_dir, "moo", "node_modules", "bar"))).toEqual(["package.json"]);
expect(await file(join(package_dir, "moo", "node_modules", "bar", "package.json")).json()).toEqual({
name: "bar",
version: "0.0.2",
});
});
it("should handle --frozen-lockfile", async () => {
let urls: string[] = [];
setHandler(dummyRegistry(urls, { "0.0.3": { as: "0.0.3" }, "0.0.5": { as: "0.0.5" } }));