synthesisui 0.4.12 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/login.js +14 -3
- package/package.json +1 -1
package/dist/commands/login.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { release } from "node:os";
|
|
2
3
|
import { resolveRegistry, writeToken } from "../config.js";
|
|
3
4
|
import { RegistryError } from "../registry.js";
|
|
4
5
|
const CLIENT_ID = "synthesisui-cli";
|
|
5
6
|
const GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
6
7
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
8
|
+
/** True inside WSL, where xdg-open usually does nothing - the Windows host
|
|
9
|
+
* must open the browser instead. */
|
|
10
|
+
function isWsl() {
|
|
11
|
+
return process.platform === "linux" && /microsoft/i.test(release());
|
|
12
|
+
}
|
|
7
13
|
/** Tries to open the OS browser; silent if it fails. */
|
|
8
14
|
function openBrowser(url) {
|
|
9
15
|
const [cmd, args] = process.platform === "darwin"
|
|
10
16
|
? ["open", [url]]
|
|
11
17
|
: process.platform === "win32"
|
|
12
18
|
? ["cmd", ["/c", "start", "", url]]
|
|
13
|
-
:
|
|
19
|
+
: isWsl()
|
|
20
|
+
? ["powershell.exe", ["-NoProfile", "Start-Process", `"${url}"`]]
|
|
21
|
+
: ["xdg-open", [url]];
|
|
14
22
|
try {
|
|
15
23
|
const child = spawn(cmd, args, {
|
|
16
24
|
stdio: "ignore",
|
|
@@ -38,9 +46,12 @@ export async function login(opts) {
|
|
|
38
46
|
: ". Check the URL and your connection."));
|
|
39
47
|
}
|
|
40
48
|
const code = (await codeRes.json());
|
|
49
|
+
// The manual path prints the COMPLETE url (code embedded) - on machines
|
|
50
|
+
// where the browser cannot auto-open (WSL, ssh, containers) the user
|
|
51
|
+
// copies ONE link and lands with the code pre-filled, Vercel-style.
|
|
41
52
|
console.log("\nTo connect the CLI to your account:");
|
|
42
|
-
console.log(` 1. open: ${code.
|
|
43
|
-
console.log(` 2.
|
|
53
|
+
console.log(` 1. open: ${code.verification_uri_complete}`);
|
|
54
|
+
console.log(` 2. it should show the code: ${code.user_code} - confirm.\n`);
|
|
44
55
|
console.log("(trying to open the browser…)");
|
|
45
56
|
openBrowser(code.verification_uri_complete);
|
|
46
57
|
let interval = (code.interval || 5) * 1000;
|
package/package.json
CHANGED