@dreamor/atlas-cli 0.7.3 → 0.7.4
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { createRequire } from 'module';
|
|
1
3
|
import { writeCookies, readCookies, fetchCookiesFromDaemon } from './session.js';
|
|
2
4
|
import { isJsonMode, jsonOk, log } from '../util/output.js';
|
|
3
5
|
import { AtlasError } from '../util/errors.js';
|
|
6
|
+
const _require = createRequire(import.meta.url);
|
|
4
7
|
const BANMA_HOST = 'banma-yuntu.alibaba-inc.com';
|
|
5
8
|
// 白名单:只保存 getBanmaIdentity 真正需要的 cookies,避免整域 cookies 落盘
|
|
6
9
|
const WANT_COOKIES = new Set(['access_token', 'buc_username', 'buc_userinfo']);
|
|
@@ -16,15 +19,44 @@ async function loadFirefox() {
|
|
|
16
19
|
return pw.firefox;
|
|
17
20
|
}
|
|
18
21
|
catch {
|
|
19
|
-
throw new Error("未安装 playwright
|
|
22
|
+
throw new Error("未安装 playwright。请执行: npm i -g playwright && npx playwright install");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 检测 launch 错误是否为"浏览器二进制未安装",自动用内置 playwright 下载。
|
|
27
|
+
*/
|
|
28
|
+
async function ensureBrowserInstalled() {
|
|
29
|
+
const pwPath = _require.resolve('playwright/package.json');
|
|
30
|
+
const cliJs = pwPath.replace(/package\.json$/, 'cli.js');
|
|
31
|
+
log('首次运行,正在自动安装 Firefox 浏览器...');
|
|
32
|
+
try {
|
|
33
|
+
execSync(`node "${cliJs}" install firefox`, {
|
|
34
|
+
stdio: 'inherit',
|
|
35
|
+
timeout: 300_000,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new Error('Firefox 浏览器自动安装失败。请手动执行: npx playwright install firefox');
|
|
20
40
|
}
|
|
21
41
|
}
|
|
22
42
|
export async function login(_port) {
|
|
23
43
|
log('正在打开浏览器进行 Banma SSO 登录...');
|
|
24
44
|
const firefox = await loadFirefox();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
45
|
+
let browser;
|
|
46
|
+
try {
|
|
47
|
+
browser = await firefox.launch({
|
|
48
|
+
headless: false,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if (e instanceof Error && e.message.includes('Executable doesn\'t exist')) {
|
|
53
|
+
await ensureBrowserInstalled();
|
|
54
|
+
browser = await firefox.launch({ headless: false });
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
28
60
|
const page = await browser.newPage();
|
|
29
61
|
log('请在浏览器中完成 SSO 登录...');
|
|
30
62
|
log('登录成功后页面会自动跳转,CLI 会自动捕获 cookies');
|
|
@@ -74,8 +74,6 @@ export async function updateCmd(opts) {
|
|
|
74
74
|
log(`当前版本 ${ATLAS_VERSION}`);
|
|
75
75
|
log('通过 npm 安装的 atlas 由 npm registry 管理升级,请运行:');
|
|
76
76
|
log(` ${npmCmd}`);
|
|
77
|
-
log('');
|
|
78
|
-
log('指定的 NPM_TOKEN 拥有 Publish 权限时,npm 会从 registry 自动拉取最新版。');
|
|
79
77
|
if (opts.json || isJsonMode()) {
|
|
80
78
|
jsonOk({
|
|
81
79
|
mode: 'npm',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ATLAS_VERSION = '0.7.
|
|
1
|
+
export const ATLAS_VERSION = '0.7.4';
|