@wwkit/cft 1.0.28 → 1.0.29
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/LICENSE +20 -20
- package/README.md +67 -67
- package/bin/index.js +74 -74
- package/package.json +3 -3
- package/scripts/postinstall.js +49 -49
- package/src/config.js +54 -54
- package/src/config.json5 +4 -4
- package/src/depchecker.js +175 -175
- package/src/env.js +84 -84
- package/src/exefinder.js +109 -109
- package/src/index.js +3 -3
- package/src/installer.js +368 -368
- package/src/platform.js +31 -31
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 bluesliu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 bluesliu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
# @wwkit/cft
|
|
2
|
-
|
|
3
|
-
Chrome for Testing (CFT) 安装器 — 下载、解压、chmod、Linux 依赖检查。
|
|
4
|
-
|
|
5
|
-
## 用法
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
cft install # 下载并安装 Chrome for Testing(已装同版本则跳过)
|
|
9
|
-
cft status # 显示安装状态
|
|
10
|
-
cft clear # 删除安装产物(~/.config/cft/)
|
|
11
|
-
cft help # 显示帮助
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## 安装目录
|
|
15
|
-
|
|
16
|
-
`~/.config/cft/`(或 `$XDG_CONFIG_HOME/cft/`)
|
|
17
|
-
|
|
18
|
-
## installed.json
|
|
19
|
-
|
|
20
|
-
安装完成后生成 `~/.config/cft/installed.json`:
|
|
21
|
-
|
|
22
|
-
```json
|
|
23
|
-
{
|
|
24
|
-
"location": "~/.config/cft",
|
|
25
|
-
"version": "141.0.7390.54",
|
|
26
|
-
"os": "mac-arm64",
|
|
27
|
-
"chrome_path": ".../chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
|
|
28
|
-
"driver_path": ".../chromedriver-mac-arm64/chromedriver"
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## 配置
|
|
33
|
-
|
|
34
|
-
版本和镜像源硬编码在包内,不接受外部参数。
|
|
35
|
-
|
|
36
|
-
- 默认版本: `141.0.7390.54`
|
|
37
|
-
- 默认镜像: `https://npmmirror.com/mirrors/chrome-for-testing`
|
|
38
|
-
|
|
39
|
-
## 本地开发
|
|
40
|
-
|
|
41
|
-
### 环境要求
|
|
42
|
-
|
|
43
|
-
- Node.js >= 18
|
|
44
|
-
- pnpm(workspace 根目录 `pnpm install` 自动链接 `@wwkit/shared`)
|
|
45
|
-
|
|
46
|
-
### 直接调用命令
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
# 通过 bin 入口(推荐,模拟 npm 全局安装后的行为)
|
|
50
|
-
node bin status
|
|
51
|
-
node bin install
|
|
52
|
-
node bin help
|
|
53
|
-
|
|
54
|
-
# 或通过 pnpm script
|
|
55
|
-
pnpm start install
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### 运行测试
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pnpm run ut # 单元测试(pnpm test 为其别名)
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### 发布
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
pnpm release # pnpm version patch && pnpm publish
|
|
1
|
+
# @wwkit/cft
|
|
2
|
+
|
|
3
|
+
Chrome for Testing (CFT) 安装器 — 下载、解压、chmod、Linux 依赖检查。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
cft install # 下载并安装 Chrome for Testing(已装同版本则跳过)
|
|
9
|
+
cft status # 显示安装状态
|
|
10
|
+
cft clear # 删除安装产物(~/.config/cft/)
|
|
11
|
+
cft help # 显示帮助
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 安装目录
|
|
15
|
+
|
|
16
|
+
`~/.config/cft/`(或 `$XDG_CONFIG_HOME/cft/`)
|
|
17
|
+
|
|
18
|
+
## installed.json
|
|
19
|
+
|
|
20
|
+
安装完成后生成 `~/.config/cft/installed.json`:
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"location": "~/.config/cft",
|
|
25
|
+
"version": "141.0.7390.54",
|
|
26
|
+
"os": "mac-arm64",
|
|
27
|
+
"chrome_path": ".../chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
|
|
28
|
+
"driver_path": ".../chromedriver-mac-arm64/chromedriver"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 配置
|
|
33
|
+
|
|
34
|
+
版本和镜像源硬编码在包内,不接受外部参数。
|
|
35
|
+
|
|
36
|
+
- 默认版本: `141.0.7390.54`
|
|
37
|
+
- 默认镜像: `https://npmmirror.com/mirrors/chrome-for-testing`
|
|
38
|
+
|
|
39
|
+
## 本地开发
|
|
40
|
+
|
|
41
|
+
### 环境要求
|
|
42
|
+
|
|
43
|
+
- Node.js >= 18
|
|
44
|
+
- pnpm(workspace 根目录 `pnpm install` 自动链接 `@wwkit/shared`)
|
|
45
|
+
|
|
46
|
+
### 直接调用命令
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 通过 bin 入口(推荐,模拟 npm 全局安装后的行为)
|
|
50
|
+
node bin status
|
|
51
|
+
node bin install
|
|
52
|
+
node bin help
|
|
53
|
+
|
|
54
|
+
# 或通过 pnpm script
|
|
55
|
+
pnpm start install
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 运行测试
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pnpm run ut # 单元测试(pnpm test 为其别名)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 发布
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pnpm release # pnpm version patch && pnpm publish
|
|
68
68
|
```
|
package/bin/index.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { execSync } from 'node:child_process'
|
|
4
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
5
|
-
import { parseFlags } from '@wwkit/shared'
|
|
6
|
-
import { install, status, clear, showConfig, showEnv, getProxy, USER_CONFIG_FILE, mergeBuiltinConfig } from '../src/index.js'
|
|
7
|
-
|
|
8
|
-
// Lazy-init: if user config doesn't exist (postinstall skipped), create it now
|
|
9
|
-
if (!existsSync(USER_CONFIG_FILE)) {
|
|
10
|
-
if (mergeBuiltinConfig()) {
|
|
11
|
-
console.log(`cft: config initialized at ${USER_CONFIG_FILE}`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const pkgVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
16
|
-
|
|
17
|
-
const args = process.argv.slice(2)
|
|
18
|
-
const cmd = args[0] ?? 'help'
|
|
19
|
-
|
|
20
|
-
if (cmd === 'install') {
|
|
21
|
-
const { flags } = parseFlags(args.slice(1))
|
|
22
|
-
let proxy = flags.proxy || flags.p || ''
|
|
23
|
-
if (proxy === 'true') proxy = ''
|
|
24
|
-
install(proxy ? { proxy } : {})
|
|
25
|
-
.then(() => {
|
|
26
|
-
console.log()
|
|
27
|
-
console.log(' ✓ CFT 安装完成')
|
|
28
|
-
process.exit(0)
|
|
29
|
-
})
|
|
30
|
-
.catch((err) => {
|
|
31
|
-
console.error(` ✗ CFT 安装失败: ${err.message}`)
|
|
32
|
-
process.exit(1)
|
|
33
|
-
})
|
|
34
|
-
} else if (cmd === 'status') {
|
|
35
|
-
const info = status()
|
|
36
|
-
process.exit(info ? 0 : 1)
|
|
37
|
-
} else if (cmd === 'clear') {
|
|
38
|
-
clear()
|
|
39
|
-
process.exit(0)
|
|
40
|
-
} else if (cmd === 'config') {
|
|
41
|
-
showConfig()
|
|
42
|
-
} else if (cmd === 'env') {
|
|
43
|
-
showEnv()
|
|
44
|
-
} else if (cmd === 'upgrade') {
|
|
45
|
-
const proxy = getProxy()
|
|
46
|
-
const npmArgs = ['install', '-g', '@wwkit/cft@latest']
|
|
47
|
-
if (proxy) npmArgs.push('--proxy', proxy)
|
|
48
|
-
execSync(`npm ${npmArgs.join(' ')}`, { stdio: 'inherit', shell: true })
|
|
49
|
-
} else if (cmd === 'version') {
|
|
50
|
-
console.log(pkgVersion)
|
|
51
|
-
} else if (cmd === 'help' || cmd === '-h' || cmd === '--help' || cmd === undefined) {
|
|
52
|
-
console.log(`cft - Chrome for Testing 安装器
|
|
53
|
-
|
|
54
|
-
用法:
|
|
55
|
-
cft install 下载并安装 Chrome for Testing(已装同版本则跳过)
|
|
56
|
-
cft install -p <proxy> 指定代理下载安装(socks5://host:port|http://host:port),覆盖配置
|
|
57
|
-
cft status 显示安装状态
|
|
58
|
-
cft config 显示用户配置(~/.config/cft/config.json5)
|
|
59
|
-
cft env 显示 cft 创建的全局环境变量
|
|
60
|
-
cft clear 删除安装产物(~/.config/cft/)
|
|
61
|
-
cft upgrade 升级 cft 自身(npm install -g @wwkit/cft@latest)
|
|
62
|
-
cft version 显示版本号
|
|
63
|
-
cft help 显示本帮助
|
|
64
|
-
|
|
65
|
-
Options:
|
|
66
|
-
-p, --proxy <url> 代理地址(install 时覆盖配置)
|
|
67
|
-
-h, --help 显示帮助
|
|
68
|
-
|
|
69
|
-
安装目录: ~/.config/cft/`)
|
|
70
|
-
} else {
|
|
71
|
-
console.error(`未知命令: ${cmd}`)
|
|
72
|
-
console.error('运行 cft help 查看用法')
|
|
73
|
-
process.exit(1)
|
|
74
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { parseFlags } from '@wwkit/shared'
|
|
6
|
+
import { install, status, clear, showConfig, showEnv, getProxy, USER_CONFIG_FILE, mergeBuiltinConfig } from '../src/index.js'
|
|
7
|
+
|
|
8
|
+
// Lazy-init: if user config doesn't exist (postinstall skipped), create it now
|
|
9
|
+
if (!existsSync(USER_CONFIG_FILE)) {
|
|
10
|
+
if (mergeBuiltinConfig()) {
|
|
11
|
+
console.log(`cft: config initialized at ${USER_CONFIG_FILE}`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const pkgVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2)
|
|
18
|
+
const cmd = args[0] ?? 'help'
|
|
19
|
+
|
|
20
|
+
if (cmd === 'install') {
|
|
21
|
+
const { flags } = parseFlags(args.slice(1))
|
|
22
|
+
let proxy = flags.proxy || flags.p || ''
|
|
23
|
+
if (proxy === 'true') proxy = ''
|
|
24
|
+
install(proxy ? { proxy } : {})
|
|
25
|
+
.then(() => {
|
|
26
|
+
console.log()
|
|
27
|
+
console.log(' ✓ CFT 安装完成')
|
|
28
|
+
process.exit(0)
|
|
29
|
+
})
|
|
30
|
+
.catch((err) => {
|
|
31
|
+
console.error(` ✗ CFT 安装失败: ${err.message}`)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
})
|
|
34
|
+
} else if (cmd === 'status') {
|
|
35
|
+
const info = status()
|
|
36
|
+
process.exit(info ? 0 : 1)
|
|
37
|
+
} else if (cmd === 'clear') {
|
|
38
|
+
clear()
|
|
39
|
+
process.exit(0)
|
|
40
|
+
} else if (cmd === 'config') {
|
|
41
|
+
showConfig()
|
|
42
|
+
} else if (cmd === 'env') {
|
|
43
|
+
showEnv()
|
|
44
|
+
} else if (cmd === 'upgrade') {
|
|
45
|
+
const proxy = getProxy()
|
|
46
|
+
const npmArgs = ['install', '-g', '@wwkit/cft@latest']
|
|
47
|
+
if (proxy) npmArgs.push('--proxy', proxy)
|
|
48
|
+
execSync(`npm ${npmArgs.join(' ')}`, { stdio: 'inherit', shell: true })
|
|
49
|
+
} else if (cmd === 'version') {
|
|
50
|
+
console.log(pkgVersion)
|
|
51
|
+
} else if (cmd === 'help' || cmd === '-h' || cmd === '--help' || cmd === undefined) {
|
|
52
|
+
console.log(`cft - Chrome for Testing 安装器
|
|
53
|
+
|
|
54
|
+
用法:
|
|
55
|
+
cft install 下载并安装 Chrome for Testing(已装同版本则跳过)
|
|
56
|
+
cft install -p <proxy> 指定代理下载安装(socks5://host:port|http://host:port),覆盖配置
|
|
57
|
+
cft status 显示安装状态
|
|
58
|
+
cft config 显示用户配置(~/.config/cft/config.json5)
|
|
59
|
+
cft env 显示 cft 创建的全局环境变量
|
|
60
|
+
cft clear 删除安装产物(~/.config/cft/)
|
|
61
|
+
cft upgrade 升级 cft 自身(npm install -g @wwkit/cft@latest)
|
|
62
|
+
cft version 显示版本号
|
|
63
|
+
cft help 显示本帮助
|
|
64
|
+
|
|
65
|
+
Options:
|
|
66
|
+
-p, --proxy <url> 代理地址(install 时覆盖配置)
|
|
67
|
+
-h, --help 显示帮助
|
|
68
|
+
|
|
69
|
+
安装目录: ~/.config/cft/`)
|
|
70
|
+
} else {
|
|
71
|
+
console.error(`未知命令: ${cmd}`)
|
|
72
|
+
console.error('运行 cft help 查看用法')
|
|
73
|
+
process.exit(1)
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwkit/cft",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"author": "bluesliu <langcai163@163.com>",
|
|
5
5
|
"description": "Chrome for Testing (CFT) installer — download, extract, chmod, dep-check",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"@wwkit/shared": "1.0.29",
|
|
39
|
+
"extract-zip": "^2.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"jest": "^29.7.0"
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawnSync } from 'node:child_process'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import { fileURLToPath } from 'node:url'
|
|
6
|
-
import { Shell } from '@wwkit/shared'
|
|
7
|
-
import { getLocation, getOs, getProxy } from '../src/index.js'
|
|
8
|
-
|
|
9
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
-
const bin = path.join(__dirname, '..', 'bin', 'index.js')
|
|
11
|
-
|
|
12
|
-
// 回退链:npm 安装参数 --proxy(npm_config_proxy)> cft 配置 proxy
|
|
13
|
-
const proxy = process.env.npm_config_proxy || getProxy()
|
|
14
|
-
const args = [bin, 'install']
|
|
15
|
-
if (proxy) args.push('-p', proxy)
|
|
16
|
-
|
|
17
|
-
const result = spawnSync('node', args, { stdio: 'inherit' })
|
|
18
|
-
if (result.status !== 0) {
|
|
19
|
-
console.error('cft: postinstall (cft install) failed')
|
|
20
|
-
process.exit(1)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 参考 harness postinstall:将 cft 安装相关目录写入环境变量。
|
|
24
|
-
// 安装目录由 getXdgConfigDir('cft') 决定(~/.config/cft 或 $XDG_CONFIG_HOME/cft),
|
|
25
|
-
// 不走 config.json5,保持 location 不可配置的设计一致。
|
|
26
|
-
// chrome/driver 目录与 installer.js 的计算逻辑一致:
|
|
27
|
-
// chrome-${osType} / chromedriver-${osType}(osType 来自 getOs())。
|
|
28
|
-
// setEnvVar 自带 marker 块幂等:值相同则跳过,值变化则原地替换。
|
|
29
|
-
const installDir = getLocation()
|
|
30
|
-
const osType = getOs()
|
|
31
|
-
const chromeDir = path.join(installDir, `chrome-${osType}`)
|
|
32
|
-
const driverDir = path.join(installDir, `chromedriver-${osType}`)
|
|
33
|
-
const shell = new Shell()
|
|
34
|
-
|
|
35
|
-
function setEnv(name, value) {
|
|
36
|
-
try {
|
|
37
|
-
const wrote = shell.setEnvVar(name, value)
|
|
38
|
-
console.log(
|
|
39
|
-
wrote
|
|
40
|
-
? `cft: set ${name}=${value}`
|
|
41
|
-
: `cft: ${name} already set to ${value}`
|
|
42
|
-
)
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.warn(`cft: failed to set ${name} — ${e.message}`)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
setEnv('SELENIUM_CFT_DIR', installDir)
|
|
49
|
-
setEnv('SELENIUM_CFT_CHROME_DIR', chromeDir)
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { Shell } from '@wwkit/shared'
|
|
7
|
+
import { getLocation, getOs, getProxy } from '../src/index.js'
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
const bin = path.join(__dirname, '..', 'bin', 'index.js')
|
|
11
|
+
|
|
12
|
+
// 回退链:npm 安装参数 --proxy(npm_config_proxy)> cft 配置 proxy
|
|
13
|
+
const proxy = process.env.npm_config_proxy || getProxy()
|
|
14
|
+
const args = [bin, 'install']
|
|
15
|
+
if (proxy) args.push('-p', proxy)
|
|
16
|
+
|
|
17
|
+
const result = spawnSync('node', args, { stdio: 'inherit' })
|
|
18
|
+
if (result.status !== 0) {
|
|
19
|
+
console.error('cft: postinstall (cft install) failed')
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 参考 harness postinstall:将 cft 安装相关目录写入环境变量。
|
|
24
|
+
// 安装目录由 getXdgConfigDir('cft') 决定(~/.config/cft 或 $XDG_CONFIG_HOME/cft),
|
|
25
|
+
// 不走 config.json5,保持 location 不可配置的设计一致。
|
|
26
|
+
// chrome/driver 目录与 installer.js 的计算逻辑一致:
|
|
27
|
+
// chrome-${osType} / chromedriver-${osType}(osType 来自 getOs())。
|
|
28
|
+
// setEnvVar 自带 marker 块幂等:值相同则跳过,值变化则原地替换。
|
|
29
|
+
const installDir = getLocation()
|
|
30
|
+
const osType = getOs()
|
|
31
|
+
const chromeDir = path.join(installDir, `chrome-${osType}`)
|
|
32
|
+
const driverDir = path.join(installDir, `chromedriver-${osType}`)
|
|
33
|
+
const shell = new Shell()
|
|
34
|
+
|
|
35
|
+
function setEnv(name, value) {
|
|
36
|
+
try {
|
|
37
|
+
const wrote = shell.setEnvVar(name, value)
|
|
38
|
+
console.log(
|
|
39
|
+
wrote
|
|
40
|
+
? `cft: set ${name}=${value}`
|
|
41
|
+
: `cft: ${name} already set to ${value}`
|
|
42
|
+
)
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.warn(`cft: failed to set ${name} — ${e.message}`)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setEnv('SELENIUM_CFT_DIR', installDir)
|
|
49
|
+
setEnv('SELENIUM_CFT_CHROME_DIR', chromeDir)
|
|
50
50
|
setEnv('SELENIUM_CFT_DRIVER_DIR', driverDir)
|
package/src/config.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
3
|
-
import { createConfigLoader, getXdgConfigDir } from '@wwkit/shared'
|
|
4
|
-
|
|
5
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
6
|
-
|
|
7
|
-
const INSTALL_DIR = getXdgConfigDir('cft')
|
|
8
|
-
|
|
9
|
-
const _loader = createConfigLoader({
|
|
10
|
-
builtinConfigPath: path.join(__dirname, 'config.json5'),
|
|
11
|
-
userConfigDir: INSTALL_DIR,
|
|
12
|
-
envContentVar: 'CFT_CONFIG_CONTENT',
|
|
13
|
-
envDirVar: 'CFT_CONFIG_DIR',
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
export const INSTALL_LOCATION = INSTALL_DIR
|
|
17
|
-
export const USER_CONFIG_FILE = path.join(INSTALL_DIR, 'config.json5')
|
|
18
|
-
|
|
19
|
-
export function getConfig() {
|
|
20
|
-
return _loader.getConfig()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function copyBuiltinConfig() {
|
|
24
|
-
return _loader.copyBuiltinConfig()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 合并内置配置到用户配置文件(追加缺失 key,不覆盖已有值)
|
|
29
|
-
* @returns {boolean} 是否写入了文件
|
|
30
|
-
*/
|
|
31
|
-
export function mergeBuiltinConfig() {
|
|
32
|
-
return _loader.mergeBuiltinConfig()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function getVersion() {
|
|
36
|
-
return getConfig().version
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function getRegistry() {
|
|
40
|
-
return getConfig().registry
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getProxy() {
|
|
44
|
-
return getConfig().proxy || ''
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getLocation() {
|
|
48
|
-
return INSTALL_LOCATION
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function showConfig() {
|
|
52
|
-
console.log(`用户配置文件: ${USER_CONFIG_FILE}`)
|
|
53
|
-
console.log()
|
|
54
|
-
console.log(JSON.stringify(getConfig(), null, 2))
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { createConfigLoader, getXdgConfigDir } from '@wwkit/shared'
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
6
|
+
|
|
7
|
+
const INSTALL_DIR = getXdgConfigDir('cft')
|
|
8
|
+
|
|
9
|
+
const _loader = createConfigLoader({
|
|
10
|
+
builtinConfigPath: path.join(__dirname, 'config.json5'),
|
|
11
|
+
userConfigDir: INSTALL_DIR,
|
|
12
|
+
envContentVar: 'CFT_CONFIG_CONTENT',
|
|
13
|
+
envDirVar: 'CFT_CONFIG_DIR',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const INSTALL_LOCATION = INSTALL_DIR
|
|
17
|
+
export const USER_CONFIG_FILE = path.join(INSTALL_DIR, 'config.json5')
|
|
18
|
+
|
|
19
|
+
export function getConfig() {
|
|
20
|
+
return _loader.getConfig()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function copyBuiltinConfig() {
|
|
24
|
+
return _loader.copyBuiltinConfig()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 合并内置配置到用户配置文件(追加缺失 key,不覆盖已有值)
|
|
29
|
+
* @returns {boolean} 是否写入了文件
|
|
30
|
+
*/
|
|
31
|
+
export function mergeBuiltinConfig() {
|
|
32
|
+
return _loader.mergeBuiltinConfig()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getVersion() {
|
|
36
|
+
return getConfig().version
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getRegistry() {
|
|
40
|
+
return getConfig().registry
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getProxy() {
|
|
44
|
+
return getConfig().proxy || ''
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getLocation() {
|
|
48
|
+
return INSTALL_LOCATION
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function showConfig() {
|
|
52
|
+
console.log(`用户配置文件: ${USER_CONFIG_FILE}`)
|
|
53
|
+
console.log()
|
|
54
|
+
console.log(JSON.stringify(getConfig(), null, 2))
|
|
55
55
|
}
|
package/src/config.json5
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
version: "141.0.7390.54",
|
|
3
|
-
registry: "http://deepbluenet.com/mirrors/chrome-for-testing",
|
|
4
|
-
proxy: "",
|
|
1
|
+
{
|
|
2
|
+
version: "141.0.7390.54",
|
|
3
|
+
registry: "http://deepbluenet.com/mirrors/chrome-for-testing",
|
|
4
|
+
proxy: "",
|
|
5
5
|
}
|