juas.dev 1.1.0 → 1.1.1
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/package.json +3 -3
- package/src/commands/login.js +69 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juas.dev",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Official CLI for juas.dev — install beautiful UI components directly into your React project as source files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "https://github.com/dhiluxui/juas.dev"
|
|
47
|
+
"url": "git+https://github.com/dhiluxui/juas.dev.git"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://juas.dev"
|
|
50
|
-
}
|
|
50
|
+
}
|
package/src/commands/login.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// ============================================================
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
5
|
import crypto from "crypto";
|
|
6
|
+
import fs from "fs";
|
|
6
7
|
import http from "http";
|
|
8
|
+
import path from "path";
|
|
7
9
|
import readline from "readline/promises";
|
|
8
10
|
import ora from "ora";
|
|
9
11
|
import pc from "picocolors";
|
|
@@ -27,33 +29,80 @@ function timingSafeStateEqual(a, b) {
|
|
|
27
29
|
return crypto.timingSafeEqual(bufA, bufB);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
function trySpawnDetached(command, args, spawnFn = spawn) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
let settled = false;
|
|
35
|
+
const finish = (ok) => {
|
|
36
|
+
if (settled) return;
|
|
37
|
+
settled = true;
|
|
38
|
+
resolve(ok);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const child = spawnFn(command, args, {
|
|
34
43
|
detached: true,
|
|
35
44
|
stdio: "ignore",
|
|
45
|
+
windowsHide: true,
|
|
36
46
|
});
|
|
37
|
-
child.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
child.once("error", () => finish(false));
|
|
48
|
+
child.once("spawn", () => {
|
|
49
|
+
try {
|
|
50
|
+
child.unref();
|
|
51
|
+
} catch {
|
|
52
|
+
// Ignore unref failures on mocked/exited child processes
|
|
53
|
+
}
|
|
54
|
+
finish(true);
|
|
44
55
|
});
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
} catch {
|
|
57
|
+
finish(false);
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Safely opens the Juas CLI authorization URL in the user's default browser.
|
|
64
|
+
* Always handles async `error` (e.g. ENOENT) without crashing Node, and avoids
|
|
65
|
+
* shell-splitting `&` query parameters on Windows.
|
|
66
|
+
*/
|
|
67
|
+
export async function openExternalUrl(targetUrl, options = {}) {
|
|
68
|
+
const platform = options.platform || process.platform;
|
|
69
|
+
const spawnFn = options.spawnFn || spawn;
|
|
70
|
+
const existsFn = options.existsFn || fs.existsSync;
|
|
71
|
+
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = new URL(targetUrl);
|
|
54
75
|
} catch {
|
|
55
76
|
return false;
|
|
56
77
|
}
|
|
78
|
+
|
|
79
|
+
const isLocal =
|
|
80
|
+
parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
81
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && isLocal)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (platform === "win32") {
|
|
86
|
+
const systemRoot = process.env.SystemRoot || process.env.WINDIR || "C:\\Windows";
|
|
87
|
+
const rundll32 = path.join(systemRoot, "System32", "rundll32.exe");
|
|
88
|
+
if (existsFn(rundll32)) {
|
|
89
|
+
if (await trySpawnDetached(rundll32, ["url.dll,FileProtocolHandler", parsed.href], spawnFn)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const comspec = process.env.ComSpec || path.join(systemRoot, "System32", "cmd.exe");
|
|
95
|
+
const cmdExe = existsFn(comspec) ? comspec : "cmd.exe";
|
|
96
|
+
const escapedUrl = parsed.href.replace(/&/g, "^&");
|
|
97
|
+
return trySpawnDetached(cmdExe, ["/d", "/c", "start", '""', escapedUrl], spawnFn);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (platform === "darwin") {
|
|
101
|
+
const macOpen = existsFn("/usr/bin/open") ? "/usr/bin/open" : "open";
|
|
102
|
+
return trySpawnDetached(macOpen, [parsed.href], spawnFn);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return trySpawnDetached("xdg-open", [parsed.href], spawnFn);
|
|
57
106
|
}
|
|
58
107
|
|
|
59
108
|
function isAllowedLoopbackOrigin(originHeader, expectedOrigin) {
|
|
@@ -331,7 +380,7 @@ export async function cmdLogin(options = {}) {
|
|
|
331
380
|
logger.info(pc.dim(`Waiting for approval on 127.0.0.1:${listener.port} (timeout: 3m)`));
|
|
332
381
|
logger.blank();
|
|
333
382
|
|
|
334
|
-
const opened = openExternalUrl(authUrl);
|
|
383
|
+
const opened = await openExternalUrl(authUrl);
|
|
335
384
|
if (!opened) {
|
|
336
385
|
logger.warn("Could not open browser automatically. Open the URL above manually.");
|
|
337
386
|
}
|