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 <matt@mattaitken.com>
Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com>
This commit is contained in:
Quetzalcoatl
2024-07-30 16:15:06 +02:00
committed by GitHub
parent 9882d66f87
commit c1d4c04e89
4 changed files with 42 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---
Fix automatic opening of login URL on linux-server systems with missing xdg-open
+1 -1
View File
@@ -131,4 +131,4 @@
"engines": {
"node": ">=18.0.0"
}
}
}
+5 -3
View File
@@ -21,6 +21,7 @@ import { LoginResult } from "../utilities/session.js";
import { whoAmI } from "./whoami.js";
import { logger } from "../utilities/logger.js";
import { spinner } from "../utilities/windows.js";
import { isLinuxServer } from "../utilities/linux.js";
export const LoginCommandOptions = CommonCommandOptions.extend({
apiUrl: z.string(),
@@ -204,10 +205,11 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
`Please visit the following URL to login:\n${chalkLink(authorizationCodeResult.url)}`
);
try {
//this can throw an error on Ubuntu
if (await isLinuxServer()) {
log.message("Please install `xdg-utils` to automatically open the login URL.");
} else {
await open(authorizationCodeResult.url);
} catch (e) {}
}
//poll for personal access token (we need to poll for it)
const getPersonalAccessTokenSpinner = spinner();
+31
View File
@@ -0,0 +1,31 @@
import { spawn } from "child_process";
import { logger } from "./logger";
export const isLinuxServer = async () => {
if (process.platform !== "linux") {
return false;
}
const xdgAvailable = await new Promise<boolean>((res) => {
const xdg = spawn("xdg-open");
xdg.on("error", (error) => {
logger.debug("Error while checking for xdg-open", error);
res(false);
});
xdg.on("spawn", () => {
res(true);
});
xdg.on("exit", (code) => {
res(code === 0);
});
xdg.unref();
});
logger.debug("xdg-open available:", xdgAvailable);
return !xdgAvailable;
};