Skip to content

Commit 7033ae9

Browse files
committed
Add support to CODER_BINARY_DESTINATION environment variable
1 parent 2c7974c commit 7033ae9

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
- Support for `CODER_BINARY_DESTINATION` environment variable to set CLI download location (overridden by extension setting `coder.binaryDestination` if configured).
8+
59
## [v1.11.0](https://github.com/coder/vscode-coder/releases/tag/v1.11.0) 2025-09-24
610

711
### Changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"default": ""
5757
},
5858
"coder.binaryDestination": {
59-
"markdownDescription": "The full path of the directory into which the Coder CLI will be downloaded. Defaults to the extension's global storage directory.",
59+
"markdownDescription": "The full path of the directory into which the Coder CLI will be downloaded. Defaults to the value of `CODER_BINARY_DESTINATION` if not set, otherwise the extension's global storage directory.",
6060
"type": "string",
6161
"default": ""
6262
},

src/core/pathResolver.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from "path";
2-
import { describe, it, expect, beforeEach } from "vitest";
2+
import { describe, it, expect, beforeEach, vi } from "vitest";
33
import { MockConfigurationProvider } from "../__mocks__/testHelpers";
44
import { PathResolver } from "./pathResolver";
55

@@ -11,6 +11,7 @@ describe("PathResolver", () => {
1111
let mockConfig: MockConfigurationProvider;
1212

1313
beforeEach(() => {
14+
vi.unstubAllEnvs();
1415
pathResolver = new PathResolver(basePath, codeLogPath);
1516
mockConfig = new MockConfigurationProvider();
1617
});
@@ -32,6 +33,7 @@ describe("PathResolver", () => {
3233
});
3334

3435
it("should use default path when custom destination is empty or whitespace", () => {
36+
vi.stubEnv("CODER_BINARY_DESTINATION", " ");
3537
mockConfig.set("coder.binaryDestination", " ");
3638
expect(pathResolver.getBinaryCachePath("deployment")).toBe(
3739
path.join(basePath, "deployment", "bin"),
@@ -41,7 +43,28 @@ describe("PathResolver", () => {
4143
it("should normalize custom paths", () => {
4244
mockConfig.set("coder.binaryDestination", "/custom/../binary/./path");
4345
expect(pathResolver.getBinaryCachePath("deployment")).toBe(
44-
path.normalize("/custom/../binary/./path"),
46+
"/binary/path",
47+
);
48+
});
49+
50+
it("should use CODER_BINARY_DESTINATION environment variable with proper precedence", () => {
51+
// Use the global storage when the environment variable and setting are unset/blank
52+
vi.stubEnv("CODER_BINARY_DESTINATION", "");
53+
mockConfig.set("coder.binaryDestination", "");
54+
expect(pathResolver.getBinaryCachePath("deployment")).toBe(
55+
path.join(basePath, "deployment", "bin"),
56+
);
57+
58+
// Test environment variable takes precedence over global storage
59+
vi.stubEnv("CODER_BINARY_DESTINATION", " /env/binary/path ");
60+
expect(pathResolver.getBinaryCachePath("deployment")).toBe(
61+
"/env/binary/path",
62+
);
63+
64+
// Test setting takes precedence over environment variable
65+
mockConfig.set("coder.binaryDestination", " /setting/path ");
66+
expect(pathResolver.getBinaryCachePath("deployment")).toBe(
67+
"/setting/path",
4568
);
4669
});
4770
});

src/core/pathResolver.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ export class PathResolver {
2828
* The caller must ensure this directory exists before use.
2929
*/
3030
public getBinaryCachePath(label: string): string {
31-
const configPath = vscode.workspace
31+
const settingPath = vscode.workspace
3232
.getConfiguration()
33-
.get<string>("coder.binaryDestination");
34-
return configPath && configPath.trim().length > 0
35-
? path.normalize(configPath)
33+
.get<string>("coder.binaryDestination")
34+
?.trim();
35+
const binaryPath =
36+
settingPath || process.env.CODER_BINARY_DESTINATION?.trim();
37+
return binaryPath
38+
? path.normalize(binaryPath)
3639
: path.join(this.getGlobalConfigDir(label), "bin");
3740
}
3841

0 commit comments

Comments
 (0)