Skip to content

Commit 2634c77

Browse files
authored
Merge pull request #17 from JacobLinCool/changeable-bin
feat: changeable bin
2 parents 86027c9 + e0627f0 commit 2634c77

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

.changeset/moody-radios-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cloudflared": patch
3+
---
4+
5+
Make `bin` respect `process.env.CLOUDFLARED_BIN` before choosing the default path, and it can be changed later using `use`.

src/constants.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import path from "node:path";
22

3-
/**
4-
* The path to the cloudflared binary.
5-
*/
6-
export const bin = path.join(
3+
export const DEFAULT_CLOUDFLARED_BIN = path.join(
74
__dirname,
85
"..",
96
"bin",
107
process.platform === "win32" ? "cloudflared.exe" : "cloudflared",
118
);
129

10+
/**
11+
* The path to the cloudflared binary.
12+
* If the `CLOUDFLARED_BIN` environment variable is set, it will be used; otherwise, {@link DEFAULT_CLOUDFLARED_BIN} will be used.
13+
* Can be overridden with {@link use}.
14+
*/
15+
export let bin = process.env.CLOUDFLARED_BIN || DEFAULT_CLOUDFLARED_BIN;
16+
17+
/**
18+
* Override the path to the cloudflared binary.
19+
* @param executable - The path to the cloudflared executable.
20+
*/
21+
export function use(executable: string): void {
22+
bin = executable;
23+
}
24+
1325
export const CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "latest";
1426

1527
export const RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";

0 commit comments

Comments
 (0)