@mutmutco/installer-launcher 1.1.0 → 1.2.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/dist/launcher.js +39 -6
- package/dist/launcher.sea.cjs +36 -3
- package/package.json +1 -1
package/dist/launcher.js
CHANGED
|
@@ -676,7 +676,7 @@ async function installAcquisition(dir, candidate, version, acquisition, options)
|
|
|
676
676
|
}
|
|
677
677
|
|
|
678
678
|
// src/index.ts
|
|
679
|
-
import { spawn as spawn2, spawnSync as
|
|
679
|
+
import { spawn as spawn2, spawnSync as spawnSync4 } from "node:child_process";
|
|
680
680
|
import { existsSync as existsSync8, readFileSync as readFileSync8, statSync, mkdtempSync as mkdtempSync2, unlinkSync as unlinkSync2, rmdirSync, mkdirSync as mkdirSync6, renameSync as renameSync5, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
681
681
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
682
682
|
import { dirname as dirname4, join as join7, resolve as resolve2 } from "node:path";
|
|
@@ -1898,7 +1898,7 @@ async function refreshLauncher(target, options = {}) {
|
|
|
1898
1898
|
}
|
|
1899
1899
|
|
|
1900
1900
|
// src/login-github.ts
|
|
1901
|
-
import { spawn } from "node:child_process";
|
|
1901
|
+
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
1902
1902
|
var realSleep = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1903
1903
|
function openBrowser(url) {
|
|
1904
1904
|
if (process.env.LAUNCHER_NO_OPEN === "1") return;
|
|
@@ -2015,7 +2015,33 @@ async function refreshAccessToken(config, refreshToken, fetchImpl = fetch) {
|
|
|
2015
2015
|
if (typeof data.access_token !== "string" || typeof data.expires_in !== "number") {
|
|
2016
2016
|
throw new Error("the sign-in server returned a malformed refresh");
|
|
2017
2017
|
}
|
|
2018
|
-
return {
|
|
2018
|
+
return {
|
|
2019
|
+
accessToken: data.access_token,
|
|
2020
|
+
expiresIn: data.expires_in,
|
|
2021
|
+
...typeof data.refresh_token === "string" ? { refreshToken: data.refresh_token } : {}
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
function readGhToken() {
|
|
2025
|
+
try {
|
|
2026
|
+
const result = spawnSync3("gh", ["auth", "token", "--hostname", "github.com"], { encoding: "utf8", timeout: 1e4, windowsHide: true });
|
|
2027
|
+
const token = result.status === 0 ? String(result.stdout).trim() : "";
|
|
2028
|
+
return token && !/\s/u.test(token) ? token : null;
|
|
2029
|
+
} catch {
|
|
2030
|
+
return null;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
async function loginWithGhToken(config, fetchImpl = fetch, readToken = readGhToken) {
|
|
2034
|
+
const token = readToken();
|
|
2035
|
+
if (!token) return null;
|
|
2036
|
+
try {
|
|
2037
|
+
const response = await postJson(`${config.host}/gate/github-token`, { token }, fetchImpl);
|
|
2038
|
+
if (!response.ok) return null;
|
|
2039
|
+
const data = await response.json();
|
|
2040
|
+
if (typeof data.access_token !== "string" || typeof data.refresh_token !== "string" || typeof data.expires_in !== "number") return null;
|
|
2041
|
+
return { accessToken: data.access_token, refreshToken: data.refresh_token, expiresIn: data.expires_in };
|
|
2042
|
+
} catch {
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
2019
2045
|
}
|
|
2020
2046
|
|
|
2021
2047
|
// src/login-google.ts
|
|
@@ -2132,7 +2158,7 @@ function page(title, body) {
|
|
|
2132
2158
|
}
|
|
2133
2159
|
|
|
2134
2160
|
// src/index.ts
|
|
2135
|
-
var LAUNCHER_VERSION = true ? "1.1
|
|
2161
|
+
var LAUNCHER_VERSION = true ? "1.2.1" : readVersionFromPackage();
|
|
2136
2162
|
function defaultPrint(message) {
|
|
2137
2163
|
process.stdout.write(`${message}
|
|
2138
2164
|
`);
|
|
@@ -2368,7 +2394,7 @@ async function ensureFreshToken(config, dir, fetchImpl = fetch) {
|
|
|
2368
2394
|
}
|
|
2369
2395
|
writeTokens(dir, {
|
|
2370
2396
|
accessToken: refreshed2.accessToken,
|
|
2371
|
-
refreshToken: stored.refreshToken,
|
|
2397
|
+
refreshToken: refreshed2.refreshToken ?? stored.refreshToken,
|
|
2372
2398
|
expiresAt: Date.now() + refreshed2.expiresIn * 1e3
|
|
2373
2399
|
});
|
|
2374
2400
|
return refreshed2.accessToken;
|
|
@@ -2423,6 +2449,13 @@ async function fetchAccessTokenOrLogin(config, dir, options, installer) {
|
|
|
2423
2449
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
2424
2450
|
const fresh = await ensureFreshToken(config, dir, fetchImpl);
|
|
2425
2451
|
if (fresh) return fresh;
|
|
2452
|
+
if (config.loginKind === "github") {
|
|
2453
|
+
const reused = await loginWithGhToken(config, fetchImpl, options.readGhToken ?? (isSea() ? readGhToken : () => null));
|
|
2454
|
+
if (reused) {
|
|
2455
|
+
writeTokens(dir, { accessToken: reused.accessToken, refreshToken: reused.refreshToken, expiresAt: Date.now() + reused.expiresIn * 1e3 });
|
|
2456
|
+
return reused.accessToken;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2426
2459
|
await doLogin(config, dir, options, (line) => installer.relay(line), installer);
|
|
2427
2460
|
const after = readTokens(dir);
|
|
2428
2461
|
if (!after) throw new Error("sign-in did not produce a token");
|
|
@@ -2501,7 +2534,7 @@ function defaultRunEntry(entry2, cwd, env) {
|
|
|
2501
2534
|
const [command2, ...args] = entry2;
|
|
2502
2535
|
const shell = needsShell(command2);
|
|
2503
2536
|
const commandLine = shell ? [command2, ...args].map(quoteForShell).join(" ") : command2;
|
|
2504
|
-
const spawnEntry = (progress2) =>
|
|
2537
|
+
const spawnEntry = (progress2) => spawnSync4(commandLine, shell ? [] : args, {
|
|
2505
2538
|
cwd,
|
|
2506
2539
|
stdio: progress2 ? ["inherit", "inherit", "inherit", "pipe"] : "inherit",
|
|
2507
2540
|
shell,
|
package/dist/launcher.sea.cjs
CHANGED
|
@@ -2049,7 +2049,33 @@ async function refreshAccessToken(config, refreshToken, fetchImpl = fetch) {
|
|
|
2049
2049
|
if (typeof data.access_token !== "string" || typeof data.expires_in !== "number") {
|
|
2050
2050
|
throw new Error("the sign-in server returned a malformed refresh");
|
|
2051
2051
|
}
|
|
2052
|
-
return {
|
|
2052
|
+
return {
|
|
2053
|
+
accessToken: data.access_token,
|
|
2054
|
+
expiresIn: data.expires_in,
|
|
2055
|
+
...typeof data.refresh_token === "string" ? { refreshToken: data.refresh_token } : {}
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
function readGhToken() {
|
|
2059
|
+
try {
|
|
2060
|
+
const result = (0, import_node_child_process5.spawnSync)("gh", ["auth", "token", "--hostname", "github.com"], { encoding: "utf8", timeout: 1e4, windowsHide: true });
|
|
2061
|
+
const token = result.status === 0 ? String(result.stdout).trim() : "";
|
|
2062
|
+
return token && !/\s/u.test(token) ? token : null;
|
|
2063
|
+
} catch {
|
|
2064
|
+
return null;
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
async function loginWithGhToken(config, fetchImpl = fetch, readToken = readGhToken) {
|
|
2068
|
+
const token = readToken();
|
|
2069
|
+
if (!token) return null;
|
|
2070
|
+
try {
|
|
2071
|
+
const response = await postJson(`${config.host}/gate/github-token`, { token }, fetchImpl);
|
|
2072
|
+
if (!response.ok) return null;
|
|
2073
|
+
const data = await response.json();
|
|
2074
|
+
if (typeof data.access_token !== "string" || typeof data.refresh_token !== "string" || typeof data.expires_in !== "number") return null;
|
|
2075
|
+
return { accessToken: data.access_token, refreshToken: data.refresh_token, expiresIn: data.expires_in };
|
|
2076
|
+
} catch {
|
|
2077
|
+
return null;
|
|
2078
|
+
}
|
|
2053
2079
|
}
|
|
2054
2080
|
|
|
2055
2081
|
// src/login-google.ts
|
|
@@ -2166,7 +2192,7 @@ function page(title, body) {
|
|
|
2166
2192
|
}
|
|
2167
2193
|
|
|
2168
2194
|
// src/index.ts
|
|
2169
|
-
var LAUNCHER_VERSION = true ? "1.1
|
|
2195
|
+
var LAUNCHER_VERSION = true ? "1.2.1" : readVersionFromPackage();
|
|
2170
2196
|
function defaultPrint(message) {
|
|
2171
2197
|
process.stdout.write(`${message}
|
|
2172
2198
|
`);
|
|
@@ -2402,7 +2428,7 @@ async function ensureFreshToken(config, dir, fetchImpl = fetch) {
|
|
|
2402
2428
|
}
|
|
2403
2429
|
writeTokens(dir, {
|
|
2404
2430
|
accessToken: refreshed2.accessToken,
|
|
2405
|
-
refreshToken: stored.refreshToken,
|
|
2431
|
+
refreshToken: refreshed2.refreshToken ?? stored.refreshToken,
|
|
2406
2432
|
expiresAt: Date.now() + refreshed2.expiresIn * 1e3
|
|
2407
2433
|
});
|
|
2408
2434
|
return refreshed2.accessToken;
|
|
@@ -2457,6 +2483,13 @@ async function fetchAccessTokenOrLogin(config, dir, options, installer) {
|
|
|
2457
2483
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
2458
2484
|
const fresh = await ensureFreshToken(config, dir, fetchImpl);
|
|
2459
2485
|
if (fresh) return fresh;
|
|
2486
|
+
if (config.loginKind === "github") {
|
|
2487
|
+
const reused = await loginWithGhToken(config, fetchImpl, options.readGhToken ?? ((0, import_node_sea2.isSea)() ? readGhToken : () => null));
|
|
2488
|
+
if (reused) {
|
|
2489
|
+
writeTokens(dir, { accessToken: reused.accessToken, refreshToken: reused.refreshToken, expiresAt: Date.now() + reused.expiresIn * 1e3 });
|
|
2490
|
+
return reused.accessToken;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2460
2493
|
await doLogin(config, dir, options, (line) => installer.relay(line), installer);
|
|
2461
2494
|
const after = readTokens(dir);
|
|
2462
2495
|
if (!after) throw new Error("sign-in did not produce a token");
|
package/package.json
CHANGED