@heybox/hb-sdk 0.9.1-alpha.8 → 0.9.1-alpha.9
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/CHANGELOG.md +21 -0
- package/README.md +7 -7
- package/dist/cli-chunks/_commonjs-dynamic-modules-DUamuDzp.cjs +7 -0
- package/dist/cli-chunks/browser-RAy8e8cV.cjs +635 -0
- package/dist/cli-chunks/{build-CQkpLf81.cjs → build-mIRvG3a8.cjs} +10 -14
- package/dist/cli-chunks/{context-CqJDNtEi.cjs → context-0uq4_H2M.cjs} +2 -2
- package/dist/cli-chunks/{create-BRuR2M7y.cjs → create-DDPUUzi1.cjs} +7 -12
- package/dist/cli-chunks/{dev-KJAFHEg_.cjs → dev-BOrmDVzH.cjs} +9 -9
- package/dist/cli-chunks/{doctor-DhiUViwk.cjs → doctor-BtOKr1SN.cjs} +9 -13
- package/dist/cli-chunks/{index-rxAV5dza.cjs → index-DYqbUZfk.cjs} +9 -10
- package/dist/cli-chunks/{index-9trmrUtW.cjs → index-MMLoNdeZ.cjs} +13591 -10542
- package/dist/cli-chunks/{index.esm-Cv9FlhXy.cjs → index.esm-DYKzLyvN.cjs} +43 -43
- package/dist/cli-chunks/{login-5DEcU9eL.cjs → login-Be95cDi7.cjs} +13 -12
- package/dist/cli-chunks/{project-vite-CXWFwbEz.cjs → project-vite-Si5Tyi7Q.cjs} +1 -1
- package/dist/cli-chunks/{remote-laUZaGpI.cjs → remote-D2XvKzs6.cjs} +20 -61
- package/dist/cli-chunks/{runtime-gate-DmJhPcNQ.cjs → runtime-gate-B0YPKxEd.cjs} +9 -13
- package/dist/cli-chunks/{runtime-permission-env-Gy2dH17F.cjs → runtime-permission-env-CzhGcDRj.cjs} +7 -2792
- package/dist/cli-chunks/{skill--mZIZkyn.cjs → skill-7n-Yn9ny.cjs} +10 -14
- package/dist/cli-chunks/{version-BMp9qmtC.cjs → version-B1aYSptt.cjs} +1 -1
- package/dist/cli.cjs +11 -16
- package/dist/devtools/browser-dev-host/assets/{browser-dev-host-COdk-39n.js → browser-dev-host-Iyo4aIMO.js} +1 -1
- package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-BU-vzcs0.js → desktop-app-launch-DzaVQPma.js} +1 -1
- package/dist/devtools/browser-dev-host/assets/{index-BZBZfB4t.js → index-hh0NzK3n.js} +3 -3
- package/dist/devtools/browser-dev-host/index.html +2 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.esm.js +1 -1
- package/package.json +6 -5
- package/skill/skill.json +4 -4
- package/dist/cli-chunks/browser-YVckob3g.cjs +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
本文件随 `@heybox/hb-sdk` npm 包公开分发,只记录外部小程序开发者可观察到的变化。
|
|
4
4
|
|
|
5
|
+
## 0.9.1-alpha.9 - 2026-10-16
|
|
6
|
+
|
|
7
|
+
### 新增能力
|
|
8
|
+
|
|
9
|
+
- 反馈新建与追加回复支持上传本地图片和 GIF,图片和 GIF 合计最多 10 张,日志不占图片额度;普通图片单张 20 MiB、GIF 单张 10 MiB,暂不支持视频附件。
|
|
10
|
+
- 新建和追加回复统一通过 `--log` 提供日志:支持本地 `.log`、ZIP 日志包,字符串自动包装成 `.log` 文件;单份上传最多 10 MiB,ZIP 内最多 50 份非空 UTF-8 `.log`,解压后合计最多 20 MiB,日志独立于图片额度,正文仅保留上传返回的日志下载链接。
|
|
11
|
+
- 新建反馈强制校验至少 5 个字符的问题描述、问题项目的 SDK 版本、运行平台、非空日志和至少一张截图;追加回复的描述同步至少 5 个字符。
|
|
12
|
+
- 移除重复的 `feedback submit` 子命令,统一使用 `hb-sdk feedback` 提交;工单列表保留分页以查看超过五条的历史记录。
|
|
13
|
+
- 反馈命令仅直接提交工单,不再打开或输出反馈提交页面地址;缺少问题描述时提示补充。
|
|
14
|
+
|
|
15
|
+
- 反馈提交与追加回复增加检查、上传和提交阶段提示,进度不混入 JSON 结果;附件按顺序串行上传,全部成功后才提交工单;结果不明确时提示在 App 核对,不自动重试,也不保存本地恢复缓存。
|
|
16
|
+
|
|
17
|
+
### 问题修复
|
|
18
|
+
|
|
19
|
+
- 修复反馈附件上传授权请求缺少表单类型,导致服务端无法读取上传范围并返回“参数错误:1000”的问题。
|
|
20
|
+
- 反馈日志上传前校验 ZIP 目录、结束记录和 CRC,拒绝损坏或未写完的压缩包;修复普通日志末尾残缺 UTF-8 字符被漏检的问题。
|
|
21
|
+
|
|
22
|
+
### 文档与工具
|
|
23
|
+
|
|
24
|
+
- 移除开放平台与文档中的反馈页面直达入口,保留 App 帮助与反馈入口及 CLI 提交说明。
|
|
25
|
+
|
|
5
26
|
## 0.9.1-alpha.8 - 2026-10-16
|
|
6
27
|
|
|
7
28
|
### 问题修复
|
package/README.md
CHANGED
|
@@ -521,18 +521,18 @@ Controller 使用 `@heybox/hb-sdk/card-controller` 编写,普通页面使用
|
|
|
521
521
|
小程序工坊开发者反馈统一进入现有私有客服工单。登录后只能查看自己的反馈,客服通过现有后台派单和回复。
|
|
522
522
|
|
|
523
523
|
```bash
|
|
524
|
-
hb-sdk feedback
|
|
525
|
-
hb-sdk feedback --
|
|
526
|
-
hb-sdk feedback submit --desc "调用失败" --app-id app123 --api hb.network.request
|
|
527
|
-
hb-sdk feedback submit --desc "调用失败" --screenshot https://cdn.example.com/error.png --json
|
|
524
|
+
hb-sdk feedback --desc "调用接口时发生异常" --sdk-version 0.9.1-alpha.7 --platform ios --log ./error.log --screenshot ./error.png --app-id app123 --api hb.network.request
|
|
525
|
+
hb-sdk feedback --desc "页面运行时出现崩溃" --sdk-version 0.9.1-alpha.7 --platform android --log ./error.log --screenshot ./error.png --json
|
|
528
526
|
hb-sdk feedback list --json # 先查看本人已有的小程序工坊工单
|
|
529
527
|
hb-sdk feedback detail 9527 --json # 查看内容和客服回复
|
|
530
|
-
hb-sdk feedback reply 9527 --desc "补充复现步骤" --json
|
|
528
|
+
hb-sdk feedback reply 9527 --desc "补充复现步骤" --screenshot ./error.png --log "Error: retry failed" --json
|
|
531
529
|
```
|
|
532
530
|
|
|
533
|
-
|
|
531
|
+
CLI 仅直接提交工单,不打开或输出反馈提交页面地址。新建反馈必须提供至少 5 个字符的问题描述、问题项目实际使用的 SDK 版本、问题发生的平台、非空报错日志和至少一张截图。使用 `--sdk-version` 填写有效版本号,不能用 CLI 自身版本代替;使用 `--platform` 指定 `ios`、`android`、`windows`、`macos`、`linux` 或 `web`,不会把执行 CLI 的电脑平台当作问题平台。日志统一通过 `--log` 提供,可传本地 `.log`、ZIP 日志包路径或日志文本,提交前请脱敏。缺少或填写无效时在登录、上传和提交前拒绝。AppID、关联 API、补充运行环境、复现步骤选填。追加回复只要求至少 5 个字符的补充描述,日志和附件可选,不重复要求原工单的 SDK 版本与平台。使用 `--scene` 补充复现步骤。`--log ./error.log` 上传非空 UTF-8 `.log` 文件;`--log "Error: request failed"` 将原始文本包装成 `feedback-text.log` 后上传。`--log ./logs.zip` 支持多个日志文件打包上传:只允许非空 UTF-8 `.log` 文件,最多 50 份,解压后合计不超过 20 MiB;不接受其他附件或嵌套压缩包。日志文件或压缩包单个不超过 10 MiB;日志全文不写入正文,正文只记录日志下载链接。完整正文最多 5000 字符;使用 `--screenshot` 传本地图片路径或已上传的 HTTP(S) 图片链接,可重复,图片和 GIF 合计最多 10 张,日志不占图片额度。普通图片单张不超过 20 MiB,GIF 单张不超过 10 MiB。暂不支持视频附件。图片沿用帮助与反馈的上传流程。
|
|
534
532
|
|
|
535
|
-
提交时从现有分类接口查找“小程序工坊”分类(兼容原“小程序工坊开发者”和“小程序工坊开发者反馈”名称)及“开发中的常见问题”问题项,再调用 `/bbs/web/feedback/user/post
|
|
533
|
+
提交时从现有分类接口查找“小程序工坊”分类(兼容原“小程序工坊开发者”和“小程序工坊开发者反馈”名称)及“开发中的常见问题”问题项,再调用 `/bbs/web/feedback/user/post`。分类未配置时拒绝提交;回复前先检查原工单属于本人小程序工坊且尚未关闭。所有本地附件先校验,再使用同一登录账号上传并提交,上传失败不会继续提交工单;附件不会单独作为上传命令对外提供。日志复用现有上传接口,正文使用接口返回的完整下载链接,不要求下载地址保留 `.log` 后缀。上线前需配置分类、问题项,并绑定客服组和派单优先级。提交结果包含原有工单 ID 和详情链接,不再创建独立 SDK 反馈记录。提交前会明确提示将创建私有反馈工单;使用提交时的同一小黑盒账号,在 App「设置 → 帮助与反馈 → 我的反馈」查看进展、客服回复或补充信息,也可打开返回的工单详情链接。`--json` 的成功结果包含 `message` 和 `follow_up` 说明,提交前提示输出到 stderr,不影响 stdout JSON 解析。
|
|
534
|
+
|
|
535
|
+
反馈命令会显示检查文件、上传附件和提交工单的阶段提示,附件按顺序串行上传,全部上传成功后才提交工单;上传失败会提示具体文件和阶段,不继续提交。进度输出到 stderr,`--json` 的 stdout 只输出最终结果。不保存本地上传进度或提交缓存。提交超时、连接中断或响应不明确时,不自动查询或重试,请先到 App「帮助与反馈 → 我的反馈」核对结果,确认未成功后再重试。
|
|
536
536
|
|
|
537
537
|
列表支持 `--offset` 和 `--limit`(最多 50 条),详情和回复只允许访问当前登录账号在小程序工坊分类 `71` 下的工单。回复复用原工单,不占新建额度;已解决或关闭的工单不能继续回复。新能力需要后端支持范围隔离;服务未更新时会明确报错,不回退为读取全部工单。
|
|
538
538
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function commonjsRequire(path) {
|
|
4
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
exports.commonjsRequire = commonjsRequire;
|
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var process = require('node:process');
|
|
4
|
+
var node_buffer = require('node:buffer');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var node_url = require('node:url');
|
|
7
|
+
var node_util = require('node:util');
|
|
8
|
+
var childProcess = require('node:child_process');
|
|
9
|
+
var fs$1 = require('node:fs/promises');
|
|
10
|
+
var os = require('node:os');
|
|
11
|
+
var fs = require('node:fs');
|
|
12
|
+
|
|
13
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
14
|
+
let isDockerCached;
|
|
15
|
+
|
|
16
|
+
function hasDockerEnv() {
|
|
17
|
+
try {
|
|
18
|
+
fs.statSync('/.dockerenv');
|
|
19
|
+
return true;
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function hasDockerCGroup() {
|
|
26
|
+
try {
|
|
27
|
+
return fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isDocker() {
|
|
34
|
+
// TODO: Use `??=` when targeting Node.js 16.
|
|
35
|
+
if (isDockerCached === undefined) {
|
|
36
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return isDockerCached;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let cachedResult;
|
|
43
|
+
|
|
44
|
+
// Podman detection
|
|
45
|
+
const hasContainerEnv = () => {
|
|
46
|
+
try {
|
|
47
|
+
fs.statSync('/run/.containerenv');
|
|
48
|
+
return true;
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function isInsideContainer() {
|
|
55
|
+
// TODO: Use `??=` when targeting Node.js 16.
|
|
56
|
+
if (cachedResult === undefined) {
|
|
57
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return cachedResult;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const isWsl = () => {
|
|
64
|
+
if (process.platform !== 'linux') {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (os.release().toLowerCase().includes('microsoft')) {
|
|
69
|
+
if (isInsideContainer()) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
if (fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')) {
|
|
78
|
+
return !isInsideContainer();
|
|
79
|
+
}
|
|
80
|
+
} catch {}
|
|
81
|
+
|
|
82
|
+
// Fallback for custom kernels: check WSL-specific paths.
|
|
83
|
+
if (
|
|
84
|
+
fs.existsSync('/proc/sys/fs/binfmt_misc/WSLInterop')
|
|
85
|
+
|| fs.existsSync('/run/WSL')
|
|
86
|
+
) {
|
|
87
|
+
return !isInsideContainer();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
var isWsl$1 = process.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
94
|
+
|
|
95
|
+
const wslDrivesMountPoint = (() => {
|
|
96
|
+
// Default value for "root" param
|
|
97
|
+
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
|
|
98
|
+
const defaultMountPoint = '/mnt/';
|
|
99
|
+
|
|
100
|
+
let mountPoint;
|
|
101
|
+
|
|
102
|
+
return async function () {
|
|
103
|
+
if (mountPoint) {
|
|
104
|
+
// Return memoized mount point value
|
|
105
|
+
return mountPoint;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const configFilePath = '/etc/wsl.conf';
|
|
109
|
+
|
|
110
|
+
let isConfigFileExists = false;
|
|
111
|
+
try {
|
|
112
|
+
await fs$1.access(configFilePath, fs$1.constants.F_OK);
|
|
113
|
+
isConfigFileExists = true;
|
|
114
|
+
} catch {}
|
|
115
|
+
|
|
116
|
+
if (!isConfigFileExists) {
|
|
117
|
+
return defaultMountPoint;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const configContent = await fs$1.readFile(configFilePath, {encoding: 'utf8'});
|
|
121
|
+
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
122
|
+
|
|
123
|
+
if (!configMountPoint) {
|
|
124
|
+
return defaultMountPoint;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
128
|
+
mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
|
|
129
|
+
|
|
130
|
+
return mountPoint;
|
|
131
|
+
};
|
|
132
|
+
})();
|
|
133
|
+
|
|
134
|
+
const powerShellPathFromWsl = async () => {
|
|
135
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
136
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const powerShellPath = async () => {
|
|
140
|
+
if (isWsl$1) {
|
|
141
|
+
return powerShellPathFromWsl();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return `${process.env.SYSTEMROOT || process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
148
|
+
const define = value => Object.defineProperty(object, propertyName, {value, enumerable: true, writable: true});
|
|
149
|
+
|
|
150
|
+
Object.defineProperty(object, propertyName, {
|
|
151
|
+
configurable: true,
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get() {
|
|
154
|
+
const result = valueGetter();
|
|
155
|
+
define(result);
|
|
156
|
+
return result;
|
|
157
|
+
},
|
|
158
|
+
set(value) {
|
|
159
|
+
define(value);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return object;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const execFileAsync$3 = node_util.promisify(childProcess.execFile);
|
|
167
|
+
|
|
168
|
+
async function defaultBrowserId() {
|
|
169
|
+
if (process.platform !== 'darwin') {
|
|
170
|
+
throw new Error('macOS only');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const {stdout} = await execFileAsync$3('defaults', ['read', 'com.apple.LaunchServices/com.apple.launchservices.secure', 'LSHandlers']);
|
|
174
|
+
|
|
175
|
+
// `(?!-)` is to prevent matching `LSHandlerRoleAll = "-";`.
|
|
176
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
177
|
+
|
|
178
|
+
const browserId = match?.groups.id ?? 'com.apple.Safari';
|
|
179
|
+
|
|
180
|
+
// Correct the case for Safari's bundle identifier
|
|
181
|
+
if (browserId === 'com.apple.safari') {
|
|
182
|
+
return 'com.apple.Safari';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return browserId;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const execFileAsync$2 = node_util.promisify(childProcess.execFile);
|
|
189
|
+
|
|
190
|
+
async function runAppleScript(script, {humanReadableOutput = true, signal} = {}) {
|
|
191
|
+
if (process.platform !== 'darwin') {
|
|
192
|
+
throw new Error('macOS only');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const outputArguments = humanReadableOutput ? [] : ['-ss'];
|
|
196
|
+
|
|
197
|
+
const execOptions = {};
|
|
198
|
+
if (signal) {
|
|
199
|
+
execOptions.signal = signal;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const {stdout} = await execFileAsync$2('osascript', ['-e', script, outputArguments], execOptions);
|
|
203
|
+
return stdout.trim();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function bundleName(bundleId) {
|
|
207
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const execFileAsync$1 = node_util.promisify(childProcess.execFile);
|
|
211
|
+
|
|
212
|
+
// TODO: Fix the casing of bundle identifiers in the next major version.
|
|
213
|
+
|
|
214
|
+
// Windows doesn't have browser IDs in the same way macOS/Linux does so we give fake
|
|
215
|
+
// ones that look real and match the macOS/Linux versions for cross-platform apps.
|
|
216
|
+
const windowsBrowserProgIds = {
|
|
217
|
+
MSEdgeHTM: {name: 'Edge', id: 'com.microsoft.edge'}, // The missing `L` is correct.
|
|
218
|
+
MSEdgeBHTML: {name: 'Edge Beta', id: 'com.microsoft.edge.beta'},
|
|
219
|
+
MSEdgeDHTML: {name: 'Edge Dev', id: 'com.microsoft.edge.dev'},
|
|
220
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {name: 'Edge', id: 'com.microsoft.edge.old'},
|
|
221
|
+
ChromeHTML: {name: 'Chrome', id: 'com.google.chrome'},
|
|
222
|
+
ChromeBHTML: {name: 'Chrome Beta', id: 'com.google.chrome.beta'},
|
|
223
|
+
ChromeDHTML: {name: 'Chrome Dev', id: 'com.google.chrome.dev'},
|
|
224
|
+
ChromiumHTM: {name: 'Chromium', id: 'org.chromium.Chromium'},
|
|
225
|
+
BraveHTML: {name: 'Brave', id: 'com.brave.Browser'},
|
|
226
|
+
BraveBHTML: {name: 'Brave Beta', id: 'com.brave.Browser.beta'},
|
|
227
|
+
BraveDHTML: {name: 'Brave Dev', id: 'com.brave.Browser.dev'},
|
|
228
|
+
BraveSSHTM: {name: 'Brave Nightly', id: 'com.brave.Browser.nightly'},
|
|
229
|
+
FirefoxURL: {name: 'Firefox', id: 'org.mozilla.firefox'},
|
|
230
|
+
OperaStable: {name: 'Opera', id: 'com.operasoftware.Opera'},
|
|
231
|
+
VivaldiHTM: {name: 'Vivaldi', id: 'com.vivaldi.Vivaldi'},
|
|
232
|
+
'IE.HTTP': {name: 'Internet Explorer', id: 'com.microsoft.ie'},
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
new Map(Object.entries(windowsBrowserProgIds));
|
|
236
|
+
|
|
237
|
+
class UnknownBrowserError extends Error {}
|
|
238
|
+
|
|
239
|
+
async function defaultBrowser$1(_execFileAsync = execFileAsync$1) {
|
|
240
|
+
const {stdout} = await _execFileAsync('reg', [
|
|
241
|
+
'QUERY',
|
|
242
|
+
' HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice',
|
|
243
|
+
'/v',
|
|
244
|
+
'ProgId',
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
248
|
+
if (!match) {
|
|
249
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const {id} = match.groups;
|
|
253
|
+
|
|
254
|
+
// Windows can append a hash suffix to ProgIds using a dot or hyphen
|
|
255
|
+
// (e.g., `ChromeHTML.ABC123`, `FirefoxURL-6F193CCC56814779`).
|
|
256
|
+
// Try exact match first, then try without the suffix.
|
|
257
|
+
const dotIndex = id.lastIndexOf('.');
|
|
258
|
+
const hyphenIndex = id.lastIndexOf('-');
|
|
259
|
+
const baseIdByDot = dotIndex === -1 ? undefined : id.slice(0, dotIndex);
|
|
260
|
+
const baseIdByHyphen = hyphenIndex === -1 ? undefined : id.slice(0, hyphenIndex);
|
|
261
|
+
|
|
262
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? {name: id, id};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const execFileAsync = node_util.promisify(childProcess.execFile);
|
|
266
|
+
|
|
267
|
+
// Inlined: https://github.com/sindresorhus/titleize/blob/main/index.js
|
|
268
|
+
const titleize = string => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, x => x.toUpperCase());
|
|
269
|
+
|
|
270
|
+
async function defaultBrowser() {
|
|
271
|
+
if (process.platform === 'darwin') {
|
|
272
|
+
const id = await defaultBrowserId();
|
|
273
|
+
const name = await bundleName(id);
|
|
274
|
+
return {name, id};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (process.platform === 'linux') {
|
|
278
|
+
const {stdout} = await execFileAsync('xdg-mime', ['query', 'default', 'x-scheme-handler/http']);
|
|
279
|
+
const id = stdout.trim();
|
|
280
|
+
const name = titleize(id.replace(/.desktop$/, '').replace('-', ' '));
|
|
281
|
+
return {name, id};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (process.platform === 'win32') {
|
|
285
|
+
return defaultBrowser$1();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
throw new Error('Only macOS, Linux, and Windows are supported');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const execFile = node_util.promisify(childProcess.execFile);
|
|
292
|
+
|
|
293
|
+
// Path to included `xdg-open`.
|
|
294
|
+
const __dirname$1 = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/browser-RAy8e8cV.cjs', document.baseURI).href))));
|
|
295
|
+
const localXdgOpenPath = path.join(__dirname$1, 'xdg-open');
|
|
296
|
+
|
|
297
|
+
const {platform, arch} = process;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
Get the default browser name in Windows from WSL.
|
|
301
|
+
|
|
302
|
+
@returns {Promise<string>} Browser name.
|
|
303
|
+
*/
|
|
304
|
+
async function getWindowsDefaultBrowserFromWsl() {
|
|
305
|
+
const powershellPath = await powerShellPath();
|
|
306
|
+
const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
307
|
+
const encodedCommand = node_buffer.Buffer.from(rawCommand, 'utf16le').toString('base64');
|
|
308
|
+
|
|
309
|
+
const {stdout} = await execFile(
|
|
310
|
+
powershellPath,
|
|
311
|
+
[
|
|
312
|
+
'-NoProfile',
|
|
313
|
+
'-NonInteractive',
|
|
314
|
+
'-ExecutionPolicy',
|
|
315
|
+
'Bypass',
|
|
316
|
+
'-EncodedCommand',
|
|
317
|
+
encodedCommand,
|
|
318
|
+
],
|
|
319
|
+
{encoding: 'utf8'},
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const progId = stdout.trim();
|
|
323
|
+
|
|
324
|
+
// Map ProgId to browser IDs
|
|
325
|
+
const browserMap = {
|
|
326
|
+
ChromeHTML: 'com.google.chrome',
|
|
327
|
+
BraveHTML: 'com.brave.Browser',
|
|
328
|
+
MSEdgeHTM: 'com.microsoft.edge',
|
|
329
|
+
FirefoxURL: 'org.mozilla.firefox',
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
return browserMap[progId] ? {id: browserMap[progId]} : {};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const pTryEach = async (array, mapper) => {
|
|
336
|
+
let latestError;
|
|
337
|
+
|
|
338
|
+
for (const item of array) {
|
|
339
|
+
try {
|
|
340
|
+
return await mapper(item); // eslint-disable-line no-await-in-loop
|
|
341
|
+
} catch (error) {
|
|
342
|
+
latestError = error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
throw latestError;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// eslint-disable-next-line complexity
|
|
350
|
+
const baseOpen = async options => {
|
|
351
|
+
options = {
|
|
352
|
+
wait: false,
|
|
353
|
+
background: false,
|
|
354
|
+
newInstance: false,
|
|
355
|
+
allowNonzeroExitCode: false,
|
|
356
|
+
...options,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
if (Array.isArray(options.app)) {
|
|
360
|
+
return pTryEach(options.app, singleApp => baseOpen({
|
|
361
|
+
...options,
|
|
362
|
+
app: singleApp,
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
let {name: app, arguments: appArguments = []} = options.app ?? {};
|
|
367
|
+
appArguments = [...appArguments];
|
|
368
|
+
|
|
369
|
+
if (Array.isArray(app)) {
|
|
370
|
+
return pTryEach(app, appName => baseOpen({
|
|
371
|
+
...options,
|
|
372
|
+
app: {
|
|
373
|
+
name: appName,
|
|
374
|
+
arguments: appArguments,
|
|
375
|
+
},
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (app === 'browser' || app === 'browserPrivate') {
|
|
380
|
+
// IDs from default-browser for macOS and windows are the same
|
|
381
|
+
const ids = {
|
|
382
|
+
'com.google.chrome': 'chrome',
|
|
383
|
+
'google-chrome.desktop': 'chrome',
|
|
384
|
+
'com.brave.Browser': 'brave',
|
|
385
|
+
'org.mozilla.firefox': 'firefox',
|
|
386
|
+
'firefox.desktop': 'firefox',
|
|
387
|
+
'com.microsoft.msedge': 'edge',
|
|
388
|
+
'com.microsoft.edge': 'edge',
|
|
389
|
+
'com.microsoft.edgemac': 'edge',
|
|
390
|
+
'microsoft-edge.desktop': 'edge',
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// Incognito flags for each browser in `apps`.
|
|
394
|
+
const flags = {
|
|
395
|
+
chrome: '--incognito',
|
|
396
|
+
brave: '--incognito',
|
|
397
|
+
firefox: '--private-window',
|
|
398
|
+
edge: '--inPrivate',
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const browser = isWsl$1 ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser();
|
|
402
|
+
if (browser.id in ids) {
|
|
403
|
+
const browserName = ids[browser.id];
|
|
404
|
+
|
|
405
|
+
if (app === 'browserPrivate') {
|
|
406
|
+
appArguments.push(flags[browserName]);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return baseOpen({
|
|
410
|
+
...options,
|
|
411
|
+
app: {
|
|
412
|
+
name: apps[browserName],
|
|
413
|
+
arguments: appArguments,
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let command;
|
|
422
|
+
const cliArguments = [];
|
|
423
|
+
const childProcessOptions = {};
|
|
424
|
+
|
|
425
|
+
if (platform === 'darwin') {
|
|
426
|
+
command = 'open';
|
|
427
|
+
|
|
428
|
+
if (options.wait) {
|
|
429
|
+
cliArguments.push('--wait-apps');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (options.background) {
|
|
433
|
+
cliArguments.push('--background');
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (options.newInstance) {
|
|
437
|
+
cliArguments.push('--new');
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (app) {
|
|
441
|
+
cliArguments.push('-a', app);
|
|
442
|
+
}
|
|
443
|
+
} else if (platform === 'win32' || (isWsl$1 && !isInsideContainer() && !app)) {
|
|
444
|
+
command = await powerShellPath();
|
|
445
|
+
|
|
446
|
+
cliArguments.push(
|
|
447
|
+
'-NoProfile',
|
|
448
|
+
'-NonInteractive',
|
|
449
|
+
'-ExecutionPolicy',
|
|
450
|
+
'Bypass',
|
|
451
|
+
'-EncodedCommand',
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
if (!isWsl$1) {
|
|
455
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const encodedArguments = ['Start'];
|
|
459
|
+
|
|
460
|
+
if (options.wait) {
|
|
461
|
+
encodedArguments.push('-Wait');
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (app) {
|
|
465
|
+
// Double quote with double quotes to ensure the inner quotes are passed through.
|
|
466
|
+
// Inner quotes are delimited for PowerShell interpretation with backticks.
|
|
467
|
+
encodedArguments.push(`"\`"${app}\`""`);
|
|
468
|
+
if (options.target) {
|
|
469
|
+
appArguments.push(options.target);
|
|
470
|
+
}
|
|
471
|
+
} else if (options.target) {
|
|
472
|
+
encodedArguments.push(`"${options.target}"`);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (appArguments.length > 0) {
|
|
476
|
+
appArguments = appArguments.map(argument => `"\`"${argument}\`""`);
|
|
477
|
+
encodedArguments.push('-ArgumentList', appArguments.join(','));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Using Base64-encoded command, accepted by PowerShell, to allow special characters.
|
|
481
|
+
options.target = node_buffer.Buffer.from(encodedArguments.join(' '), 'utf16le').toString('base64');
|
|
482
|
+
} else {
|
|
483
|
+
if (app) {
|
|
484
|
+
command = app;
|
|
485
|
+
} else {
|
|
486
|
+
// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
|
|
487
|
+
const isBundled = !__dirname$1 || __dirname$1 === '/';
|
|
488
|
+
|
|
489
|
+
// Check if local `xdg-open` exists and is executable.
|
|
490
|
+
let exeLocalXdgOpen = false;
|
|
491
|
+
try {
|
|
492
|
+
await fs$1.access(localXdgOpenPath, fs$1.constants.X_OK);
|
|
493
|
+
exeLocalXdgOpen = true;
|
|
494
|
+
} catch {}
|
|
495
|
+
|
|
496
|
+
const useSystemXdgOpen = process.versions.electron
|
|
497
|
+
?? (platform === 'android' || isBundled || !exeLocalXdgOpen);
|
|
498
|
+
command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (appArguments.length > 0) {
|
|
502
|
+
cliArguments.push(...appArguments);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (!options.wait) {
|
|
506
|
+
// `xdg-open` will block the process unless stdio is ignored
|
|
507
|
+
// and it's detached from the parent even if it's unref'd.
|
|
508
|
+
childProcessOptions.stdio = 'ignore';
|
|
509
|
+
childProcessOptions.detached = true;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (platform === 'darwin' && appArguments.length > 0) {
|
|
514
|
+
cliArguments.push('--args', ...appArguments);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// This has to come after `--args`.
|
|
518
|
+
if (options.target) {
|
|
519
|
+
cliArguments.push(options.target);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
523
|
+
|
|
524
|
+
if (options.wait) {
|
|
525
|
+
return new Promise((resolve, reject) => {
|
|
526
|
+
subprocess.once('error', reject);
|
|
527
|
+
|
|
528
|
+
subprocess.once('close', exitCode => {
|
|
529
|
+
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
530
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
resolve(subprocess);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
subprocess.unref();
|
|
540
|
+
|
|
541
|
+
return subprocess;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
const open = (target, options) => {
|
|
545
|
+
if (typeof target !== 'string') {
|
|
546
|
+
throw new TypeError('Expected a `target`');
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return baseOpen({
|
|
550
|
+
...options,
|
|
551
|
+
target,
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
function detectArchBinary(binary) {
|
|
556
|
+
if (typeof binary === 'string' || Array.isArray(binary)) {
|
|
557
|
+
return binary;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const {[arch]: archBinary} = binary;
|
|
561
|
+
|
|
562
|
+
if (!archBinary) {
|
|
563
|
+
throw new Error(`${arch} is not supported`);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return archBinary;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function detectPlatformBinary({[platform]: platformBinary}, {wsl}) {
|
|
570
|
+
if (wsl && isWsl$1) {
|
|
571
|
+
return detectArchBinary(wsl);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (!platformBinary) {
|
|
575
|
+
throw new Error(`${platform} is not supported`);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return detectArchBinary(platformBinary);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const apps = {};
|
|
582
|
+
|
|
583
|
+
defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({
|
|
584
|
+
darwin: 'google chrome',
|
|
585
|
+
win32: 'chrome',
|
|
586
|
+
linux: ['google-chrome', 'google-chrome-stable', 'chromium'],
|
|
587
|
+
}, {
|
|
588
|
+
wsl: {
|
|
589
|
+
ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
|
590
|
+
x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'],
|
|
591
|
+
},
|
|
592
|
+
}));
|
|
593
|
+
|
|
594
|
+
defineLazyProperty(apps, 'brave', () => detectPlatformBinary({
|
|
595
|
+
darwin: 'brave browser',
|
|
596
|
+
win32: 'brave',
|
|
597
|
+
linux: ['brave-browser', 'brave'],
|
|
598
|
+
}, {
|
|
599
|
+
wsl: {
|
|
600
|
+
ia32: '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe',
|
|
601
|
+
x64: ['/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe', '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'],
|
|
602
|
+
},
|
|
603
|
+
}));
|
|
604
|
+
|
|
605
|
+
defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({
|
|
606
|
+
darwin: 'firefox',
|
|
607
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
608
|
+
linux: 'firefox',
|
|
609
|
+
}, {
|
|
610
|
+
wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe',
|
|
611
|
+
}));
|
|
612
|
+
|
|
613
|
+
defineLazyProperty(apps, 'edge', () => detectPlatformBinary({
|
|
614
|
+
darwin: 'microsoft edge',
|
|
615
|
+
win32: 'msedge',
|
|
616
|
+
linux: ['microsoft-edge', 'microsoft-edge-dev'],
|
|
617
|
+
}, {
|
|
618
|
+
wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
|
|
619
|
+
}));
|
|
620
|
+
|
|
621
|
+
defineLazyProperty(apps, 'browser', () => 'browser');
|
|
622
|
+
|
|
623
|
+
defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate');
|
|
624
|
+
|
|
625
|
+
async function openExternalUrl(url) {
|
|
626
|
+
try {
|
|
627
|
+
await open(url);
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
catch {
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
exports.openExternalUrl = openExternalUrl;
|