Skip to content

Commit c1d4c04

Browse files
HorizonCodematt-aitkennicktrn
authored
add xdg command check for linux servers (#1225)
* add xdg command check for linux * bump version of cli-v3, add changeset * Don't bump the version * lint and log * prettier log message --------- Co-authored-by: Matt Aitken <[email protected]> Co-authored-by: nicktrn <[email protected]>
1 parent 9882d66 commit c1d4c04

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

.changeset/green-pens-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fix automatic opening of login URL on linux-server systems with missing xdg-open

packages/cli-v3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@
131131
"engines": {
132132
"node": ">=18.0.0"
133133
}
134-
}
134+
}

packages/cli-v3/src/commands/login.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { LoginResult } from "../utilities/session.js";
2121
import { whoAmI } from "./whoami.js";
2222
import { logger } from "../utilities/logger.js";
2323
import { spinner } from "../utilities/windows.js";
24+
import { isLinuxServer } from "../utilities/linux.js";
2425

2526
export const LoginCommandOptions = CommonCommandOptions.extend({
2627
apiUrl: z.string(),
@@ -204,10 +205,11 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
204205
`Please visit the following URL to login:\n${chalkLink(authorizationCodeResult.url)}`
205206
);
206207

207-
try {
208-
//this can throw an error on Ubuntu
208+
if (await isLinuxServer()) {
209+
log.message("Please install `xdg-utils` to automatically open the login URL.");
210+
} else {
209211
await open(authorizationCodeResult.url);
210-
} catch (e) {}
212+
}
211213

212214
//poll for personal access token (we need to poll for it)
213215
const getPersonalAccessTokenSpinner = spinner();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { spawn } from "child_process";
2+
import { logger } from "./logger";
3+
4+
export const isLinuxServer = async () => {
5+
if (process.platform !== "linux") {
6+
return false;
7+
}
8+
9+
const xdgAvailable = await new Promise<boolean>((res) => {
10+
const xdg = spawn("xdg-open");
11+
12+
xdg.on("error", (error) => {
13+
logger.debug("Error while checking for xdg-open", error);
14+
res(false);
15+
});
16+
17+
xdg.on("spawn", () => {
18+
res(true);
19+
});
20+
21+
xdg.on("exit", (code) => {
22+
res(code === 0);
23+
});
24+
25+
xdg.unref();
26+
});
27+
28+
logger.debug("xdg-open available:", xdgAvailable);
29+
30+
return !xdgAvailable;
31+
};

0 commit comments

Comments
 (0)