dsh-remote 1.4.0 → 1.5.0
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/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/boot.js +1 -0
- package/lib/client.js +156 -12
- package/lib/detect-platform.js +142 -0
- package/lib/index.js +1 -0
- package/lib/main.js +45 -4
- package/lib/openssh.js +19 -54
- package/lib/pool.js +25 -79
- package/lib/registry.js +4 -0
- package/lib/remote-shell-child.cjs +9 -1
- package/lib/routes-fs.js +137 -1
- package/lib/routes-machines.js +16 -8
- package/lib/web-attach.js +47 -2
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -18,7 +18,7 @@ Use the normal layout or choose the optional **three-column IDE layout** to view
|
|
|
18
18
|
|
|
19
19
|
<img src="https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png" alt="DSH remote IDE with file tree, native code editor and agent conversation" width="1200"/>
|
|
20
20
|
|
|
21
|
-
[1.
|
|
21
|
+
[1.5.0 release notes](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.5.0.md): attach tunnels self-heal after link flaps, downloads can land on the machine running the browser, 6x faster commands on high-RTT links, a plain-login terminal mode for bastion gateways.
|
|
22
22
|
|
|
23
23
|
## Install
|
|
24
24
|
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ dsh plugin --profile web add dsh-remote
|
|
|
26
26
|
|
|
27
27
|
安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。
|
|
28
28
|
|
|
29
|
-
[1.
|
|
29
|
+
[1.5.0 更新说明](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.5.0.md):Web 隧道断链自愈、下载到浏览器所在机器、高 RTT 提速 6 倍、堡垒机终端纯登录模式。
|
|
30
30
|
|
|
31
31
|
## 3 步开始
|
|
32
32
|
|
package/lib/boot.js
CHANGED
|
@@ -10,6 +10,7 @@ export const win32FolderPickScript = main.win32FolderPickScript
|
|
|
10
10
|
export const LOCAL_BOOTSTRAP_TOOLS = main.LOCAL_BOOTSTRAP_TOOLS
|
|
11
11
|
export const normalizeLocalTools = main.normalizeLocalTools
|
|
12
12
|
export const pickWorkspaceNextStep = main.pickWorkspaceNextStep
|
|
13
|
+
export const pickWorkspaceRebindNote = main.pickWorkspaceRebindNote
|
|
13
14
|
export const inject = main.inject
|
|
14
15
|
export const Config = main.Config
|
|
15
16
|
export const apply = main.apply
|
package/lib/client.js
CHANGED
|
@@ -27,7 +27,7 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
|
|
28
28
|
const React = require('react')
|
|
29
29
|
const name = 'dsh-remote'
|
|
30
|
-
const CLIENT_VERSION = '1.
|
|
30
|
+
const CLIENT_VERSION = '1.5.0'
|
|
31
31
|
|
|
32
32
|
// ── optional host primitives ────────────────────────────────────────────
|
|
33
33
|
// Issue #74: a remote session's .md link must open over SFTP, NOT via the
|
|
@@ -405,6 +405,16 @@ window.__ModuleLoader__.load({
|
|
|
405
405
|
'settings.backendOpensshAliasOk': '已勾选「使用 ssh_config 别名」:主机名原样交给 ssh,端口/用户/私钥/跳板机一律由 ~/.ssh/config 的 Host 块决定,对应的输入框在 openssh 后端下填了也不生效(这就是「配置唯一来源」,issue #50)。密码/Passphrase 仍会通过 askpass 交给 ssh,仅当 Host 块里没有可用认证时才用得上。',
|
|
406
406
|
'settings.sshBinary': 'ssh 路径',
|
|
407
407
|
'settings.sshBinaryPlaceholder': '留空 = 用 PATH 里的 ssh',
|
|
408
|
+
// Issue #206: the per-machine shell was only reachable by hand-editing
|
|
409
|
+
// machines.json — and applyMachine dropped it anyway. It is an ordinary
|
|
410
|
+
// machine field with an input now.
|
|
411
|
+
'settings.shell': '远端 Shell',
|
|
412
|
+
'settings.shellPlaceholder': '留空 = 自动探测(where bash)',
|
|
413
|
+
'settings.shellHint': 'Windows 远端专用:指定 bash.exe 的路径或包装脚本,覆盖自动探测。例如自动探测到的是 WSL 启动器 stub、或 Git Bash 需要包装才能在 sshd 的 stdio 下存活时使用。POSIX 远端留空即可。',
|
|
414
|
+
// Issue #212: JumpServer 类网关对带命令的会话不分配远端 PTY。
|
|
415
|
+
'settings.terminalNoCommand': '终端纯登录',
|
|
416
|
+
'settings.terminalNoCommandLabel': '终端用纯登录(堡垒机 / 网关适用)',
|
|
417
|
+
'settings.terminalNoCommandHint': 'JumpServer 类网关只给「不带命令的登录」分配远端 PTY:带命令时(即使 -tt)没有行纪律,回车不生效、按键看似无响应。勾选后生成的终端 launcher 只发纯登录,不再自动 cd 到工作区,但拿到真 PTY(zsh 行编辑、窗口缩放正常)。直连普通 sshd 的机器不要勾。',
|
|
408
418
|
// Issue #54: the README told users to point `webAttachCommand` at a
|
|
409
419
|
// private-prefix dsh, but the settings UI offered nowhere to type it —
|
|
410
420
|
// it could only be written by the deploy flow or by hand-editing
|
|
@@ -695,6 +705,13 @@ window.__ModuleLoader__.load({
|
|
|
695
705
|
'explorer.menuExpand': '📂 展开/收起',
|
|
696
706
|
'explorer.menuOpen': '📄 打开文件',
|
|
697
707
|
'explorer.menuDownload': '⬇ 下载到本地镜像',
|
|
708
|
+
'explorer.menuDownloadLocal': '⬇ 下载到本机',
|
|
709
|
+
'explorer.downloadLocal': '下载到本机',
|
|
710
|
+
// Issue #207: mirror downloads are invisible without a picker — say
|
|
711
|
+
// where the file landed and offer to reveal it.
|
|
712
|
+
'explorer.downloadedNote': '已下载到本地镜像:{path}',
|
|
713
|
+
'explorer.showInFolder': '在文件夹中显示',
|
|
714
|
+
'explorer.dismissNote': '关闭提示',
|
|
698
715
|
'explorer.menuCopyRel': '📋 复制相对地址',
|
|
699
716
|
'explorer.menuCopyAbs': '📋 复制绝对地址',
|
|
700
717
|
'explorer.menuRename': '✏ 重命名',
|
|
@@ -724,6 +741,7 @@ window.__ModuleLoader__.load({
|
|
|
724
741
|
'file.dirty': '未保存',
|
|
725
742
|
'file.saveHint': 'Ctrl/⌘+S 保存',
|
|
726
743
|
'file.downloaded': '已下载到本地镜像{local}',
|
|
744
|
+
'file.downloadedToComputer': '已开始下载到本机',
|
|
727
745
|
'file.downloadedAt': ': {path}',
|
|
728
746
|
'file.localCopyMissing': '远端没有此文件,但本地镜像中有同名副本。',
|
|
729
747
|
'file.localCopyHelp': '可先只读查看,确认后上传到远端。上传仅创建新文件,不覆盖已有文件。',
|
|
@@ -1033,6 +1051,14 @@ window.__ModuleLoader__.load({
|
|
|
1033
1051
|
'settings.backendOpensshAliasOk': '"Use a ~/.ssh/config alias" is on: the name is handed to ssh verbatim, and Port/User/IdentityFile/ProxyJump come from that Host block — the matching fields below have no effect (this is the "one source of truth" case, issue #50). A password/passphrase is still offered to ssh through askpass, and is only used if the Host block has no usable authentication.',
|
|
1034
1052
|
'settings.sshBinary': 'ssh path',
|
|
1035
1053
|
'settings.sshBinaryPlaceholder': 'Empty = the ssh on PATH',
|
|
1054
|
+
// Issue #206: the per-machine shell gets a settings input.
|
|
1055
|
+
'settings.shell': 'Remote shell',
|
|
1056
|
+
'settings.shellPlaceholder': 'Empty = auto-detect (where bash)',
|
|
1057
|
+
'settings.shellHint': 'Windows remotes only: the bash.exe path (or a wrapper script) to use as the remote shell, overriding auto-detection — e.g. when auto-detect finds the WSL launcher stub, or your Git Bash needs a wrapper to survive sshd. Leave empty on POSIX remotes.',
|
|
1058
|
+
// Issue #212: gateways that allocate a remote PTY only for plain logins.
|
|
1059
|
+
'settings.terminalNoCommand': 'Plain-login terminal',
|
|
1060
|
+
'settings.terminalNoCommandLabel': 'Terminal dials a plain login (bastion / gateway hosts)',
|
|
1061
|
+
'settings.terminalNoCommandHint': 'JumpServer-class gateways allocate a remote PTY only for logins WITHOUT a command: with one (even with -tt) there is no line discipline — Return does nothing and keys look dead. When checked, the generated terminal launcher sends a plain login instead of the cd-and-exec line: you get a real PTY (zsh line editing, window resize) at the cost of the automatic cd into the workspace. Leave unchecked for direct sshd hosts.',
|
|
1036
1062
|
// Issue #54: the README documented `webAttachCommand` but the settings
|
|
1037
1063
|
// UI had no field for it.
|
|
1038
1064
|
'settings.webAttachCmd': 'Remote dsh command',
|
|
@@ -1318,6 +1344,13 @@ window.__ModuleLoader__.load({
|
|
|
1318
1344
|
'explorer.menuExpand': '📂 Expand/collapse',
|
|
1319
1345
|
'explorer.menuOpen': '📄 Open file',
|
|
1320
1346
|
'explorer.menuDownload': '⬇ Download to local mirror',
|
|
1347
|
+
'explorer.menuDownloadLocal': '⬇ Download to this computer',
|
|
1348
|
+
'explorer.downloadLocal': 'Download to this computer',
|
|
1349
|
+
// Issue #207: mirror downloads are invisible without a picker — say
|
|
1350
|
+
// where the file landed and offer to reveal it.
|
|
1351
|
+
'explorer.downloadedNote': 'Downloaded to the local mirror: {path}',
|
|
1352
|
+
'explorer.showInFolder': 'Show in folder',
|
|
1353
|
+
'explorer.dismissNote': 'Dismiss',
|
|
1321
1354
|
'explorer.menuCopyRel': '📋 Copy relative path',
|
|
1322
1355
|
'explorer.menuCopyAbs': '📋 Copy absolute path',
|
|
1323
1356
|
'explorer.menuRename': '✏ Rename',
|
|
@@ -1347,6 +1380,7 @@ window.__ModuleLoader__.load({
|
|
|
1347
1380
|
'file.dirty': 'unsaved',
|
|
1348
1381
|
'file.saveHint': 'Ctrl/⌘+S to save',
|
|
1349
1382
|
'file.downloaded': 'Downloaded to local mirror{local}',
|
|
1383
|
+
'file.downloadedToComputer': 'Download started on this computer',
|
|
1350
1384
|
'file.downloadedAt': ': {path}',
|
|
1351
1385
|
'file.localCopyMissing': 'This file is missing remotely. A copy exists in the local mirror.',
|
|
1352
1386
|
'file.localCopyHelp': 'Preview the local copy, then upload it. Upload creates a new remote file and never replaces an existing file.',
|
|
@@ -1492,6 +1526,41 @@ window.__ModuleLoader__.load({
|
|
|
1492
1526
|
return Object.assign({}, body || {}, { sessionId }, localWorkspaceSession(sessionId) ? { workspace: 'local' } : {})
|
|
1493
1527
|
}
|
|
1494
1528
|
|
|
1529
|
+
/**
|
|
1530
|
+
* Save a remote (or local-workspace) file on the machine running the BROWSER.
|
|
1531
|
+
*
|
|
1532
|
+
* The mirror download (POST /dsh-remote/fs op=download) only writes on the
|
|
1533
|
+
* DSH host, so a user who opens the page from their own desktop had no way to
|
|
1534
|
+
* get the file. The host streams it from /dsh-remote/download and the browser
|
|
1535
|
+
* saves it; failures (too large, gone, wrong session) reject instead of
|
|
1536
|
+
* silently saving a JSON error as if it were the file.
|
|
1537
|
+
*/
|
|
1538
|
+
function downloadRemoteFileToClient(sessionId, filePath) {
|
|
1539
|
+
const url = withSessionQuery(apiPath('/dsh-remote/download') + '?path=' + encodeURIComponent(filePath), sessionId)
|
|
1540
|
+
return fetch(url, { credentials: 'same-origin' }).then(async (res) => {
|
|
1541
|
+
if (!res.ok) {
|
|
1542
|
+
const data = await res.json().catch(() => ({}))
|
|
1543
|
+
throw new Error(trHostError((data && (data.error || data.message))) || 'HTTP ' + res.status)
|
|
1544
|
+
}
|
|
1545
|
+
const named = res.headers.get('X-Dsh-Download-Name') || ''
|
|
1546
|
+
let name = String(filePath).split(/[\\/]/).filter(Boolean).pop() || 'download'
|
|
1547
|
+
if (named) { try { name = decodeURIComponent(named) } catch { /* keep the basename */ } }
|
|
1548
|
+
const blob = await res.blob()
|
|
1549
|
+
const href = URL.createObjectURL(blob)
|
|
1550
|
+
try {
|
|
1551
|
+
const anchor = document.createElement('a')
|
|
1552
|
+
anchor.href = href
|
|
1553
|
+
anchor.download = name
|
|
1554
|
+
anchor.rel = 'noopener'
|
|
1555
|
+
anchor.style.display = 'none'
|
|
1556
|
+
document.body.appendChild(anchor)
|
|
1557
|
+
anchor.click()
|
|
1558
|
+
window.setTimeout(() => { try { anchor.remove(); URL.revokeObjectURL(href) } catch { /* ignore */ } }, 1000)
|
|
1559
|
+
} catch (err) { URL.revokeObjectURL(href); throw err }
|
|
1560
|
+
return name
|
|
1561
|
+
})
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1495
1564
|
async function api(method, path, body, signal) {
|
|
1496
1565
|
const opts = { method, headers: {}, ...(signal ? { signal } : {}) }
|
|
1497
1566
|
if (body) { opts.headers['Content-Type'] = 'application/json'; opts.body = JSON.stringify(body) }
|
|
@@ -2350,6 +2419,10 @@ window.__ModuleLoader__.load({
|
|
|
2350
2419
|
proxyUser: (m.proxy && m.proxy.username) || '', proxyPassword: '', proxyKey: (m.proxy && m.proxy.privateKeyPath) || '',
|
|
2351
2420
|
// Issue #51: the transport backend is per machine.
|
|
2352
2421
|
backend: m.backend === 'openssh' ? 'openssh' : 'native', sshBinary: m.sshBinary || '',
|
|
2422
|
+
// Issue #206: the per-machine remote shell (Windows remotes).
|
|
2423
|
+
shell: m.shell || '',
|
|
2424
|
+
// Issue #212: plain-login terminal for PTY-stingy gateways.
|
|
2425
|
+
terminalNoCommand: !!m.terminalNoCommand,
|
|
2353
2426
|
// Issue #54: the per-machine remote-dsh command for Web UI attach.
|
|
2354
2427
|
webAttachCommand: m.webAttachCommand || '',
|
|
2355
2428
|
// Issue #125: its resident-instance discover sibling.
|
|
@@ -2366,7 +2439,7 @@ window.__ModuleLoader__.load({
|
|
|
2366
2439
|
setForm(next)
|
|
2367
2440
|
setFormOpen(true)
|
|
2368
2441
|
// 编辑时若该机器用了高级配置(私钥/agent/跳板/钥匙串/系统 OpenSSH 后端),自动展开折叠区
|
|
2369
|
-
setAdvOpen(!!(m.privateKeyPath || m.useAgent || m.keyboardInteractive || (m.proxy && m.proxy.host) || m.backend === 'openssh' || m.webAttachCommand || m.webAttachDiscoverCommand || (m.credentialBackend && m.credentialBackend !== 'plain')))
|
|
2442
|
+
setAdvOpen(!!(m.privateKeyPath || m.useAgent || m.keyboardInteractive || (m.proxy && m.proxy.host) || m.backend === 'openssh' || m.shell || m.webAttachCommand || m.webAttachDiscoverCommand || (m.credentialBackend && m.credentialBackend !== 'plain')))
|
|
2370
2443
|
}
|
|
2371
2444
|
const startEdit = (machine) => {
|
|
2372
2445
|
if (busy) return
|
|
@@ -2383,7 +2456,7 @@ window.__ModuleLoader__.load({
|
|
|
2383
2456
|
}
|
|
2384
2457
|
const clearForm = () => {
|
|
2385
2458
|
setFormOpen(false)
|
|
2386
|
-
setForm({ name: '', host: '', port: '22', username: 'root', password: '', privateKeyPath: '', passphrase: '', workspace: '', hostKeyMode: '', useAgent: false, keyboardInteractive: false, encryptPassword: false, proxyHost: '', proxyPort: '22', proxyUser: '', proxyPassword: '', proxyKey: '', backend: 'native', sshBinary: '', webAttachCommand: '', webAttachDiscoverCommand: '', id: '', useSshConfig: false, passwordSet: false, passphraseSet: false, proxyPasswordSet: false })
|
|
2459
|
+
setForm({ name: '', host: '', port: '22', username: 'root', password: '', privateKeyPath: '', passphrase: '', workspace: '', hostKeyMode: '', useAgent: false, keyboardInteractive: false, encryptPassword: false, proxyHost: '', proxyPort: '22', proxyUser: '', proxyPassword: '', proxyKey: '', backend: 'native', sshBinary: '', shell: '', terminalNoCommand: false, webAttachCommand: '', webAttachDiscoverCommand: '', id: '', useSshConfig: false, passwordSet: false, passphraseSet: false, proxyPasswordSet: false })
|
|
2387
2460
|
}
|
|
2388
2461
|
const save = (action) => {
|
|
2389
2462
|
if (busy) return
|
|
@@ -2400,6 +2473,10 @@ window.__ModuleLoader__.load({
|
|
|
2400
2473
|
encryptPassword: form.encryptPassword, useSshConfig: !!form.useSshConfig,
|
|
2401
2474
|
// Issue #51: the transport backend (and, for `openssh`, the executable).
|
|
2402
2475
|
backend: form.backend || 'native', sshBinary: form.sshBinary || '',
|
|
2476
|
+
// Issue #206: the per-machine remote shell (Windows remotes).
|
|
2477
|
+
shell: form.shell || '',
|
|
2478
|
+
// Issue #212: plain-login terminal for PTY-stingy gateways.
|
|
2479
|
+
terminalNoCommand: !!form.terminalNoCommand,
|
|
2403
2480
|
// Issue #54: the per-machine remote-dsh command for Web UI attach.
|
|
2404
2481
|
webAttachCommand: form.webAttachCommand || '',
|
|
2405
2482
|
// Issue #125: the per-machine resident-instance discover command.
|
|
@@ -2932,6 +3009,11 @@ window.__ModuleLoader__.load({
|
|
|
2932
3009
|
(form.backend === 'openssh')
|
|
2933
3010
|
? row(tr('settings.sshBinary'), React.createElement('input', { value: form.sshBinary || '', onChange: setF('sshBinary'), placeholder: tr('settings.sshBinaryPlaceholder'), style: inputS }), 'sb')
|
|
2934
3011
|
: null,
|
|
3012
|
+
// Issue #206: where the Git Bash wrapper comes from on Windows
|
|
3013
|
+
// remotes (empty = auto-detect). Both backends' detection reads it,
|
|
3014
|
+
// so it renders for either backend, right after sshBinary.
|
|
3015
|
+
row(tr('settings.shell'), React.createElement('input', { 'data-testid': 'machine-shell', value: form.shell || '', onChange: setF('shell'), placeholder: tr('settings.shellPlaceholder'), style: inputS }), 'msh'),
|
|
3016
|
+
React.createElement('div', { style: { paddingLeft: LABEL_W + 12, marginBottom: 8, fontSize: 11, lineHeight: 1.5, opacity: 0.7 } }, tr('settings.shellHint')),
|
|
2935
3017
|
row(tr('settings.privateKey'), React.createElement('input', { value: form.privateKeyPath, onChange: setF('privateKeyPath'), placeholder: 'Empty = password or agent', style: inputS }), 'k'),
|
|
2936
3018
|
row(tr('settings.passphrase'), React.createElement('input', { type: 'password', value: form.passphrase, onChange: setF('passphrase'), placeholder: form.passphraseSet ? tr('settings.secretSavedPlaceholder') : 'Encrypted private key passphrase', style: inputS, title: form.passphraseSet ? tr('settings.secretSavedHint') : '' }), 'pp'),
|
|
2937
3019
|
form.passphraseSet
|
|
@@ -2942,6 +3024,12 @@ window.__ModuleLoader__.load({
|
|
|
2942
3024
|
React.createElement(RwCheckbox, { checked: form.useAgent, onChange: setB('useAgent'), label: tr('settings.agent') }),
|
|
2943
3025
|
React.createElement(RwCheckbox, { checked: form.keyboardInteractive, onChange: setB('keyboardInteractive'), label: tr('settings.keyboardInteractive') }),
|
|
2944
3026
|
React.createElement(RwCheckbox, { checked: form.encryptPassword, onChange: setB('encryptPassword'), label: tr('settings.encryptPassword') })),
|
|
3027
|
+
// Issue #212: gateways (JumpServer-class bastions) that allocate a
|
|
3028
|
+
// remote PTY only for plain logins need the terminal launcher to
|
|
3029
|
+
// dial WITHOUT the cd-and-exec command; otherwise the shell has no
|
|
3030
|
+
// line discipline and keys look dead.
|
|
3031
|
+
row(tr('settings.terminalNoCommand'), React.createElement(RwCheckbox, { 'data-testid': 'terminal-no-command', checked: !!form.terminalNoCommand, onChange: () => setForm((f) => ({ ...f, terminalNoCommand: !f.terminalNoCommand })), label: tr('settings.terminalNoCommandLabel') }), 'tnc'),
|
|
3032
|
+
React.createElement('div', { style: { paddingLeft: LABEL_W + 12, marginBottom: 8, fontSize: 11, lineHeight: 1.5, opacity: 0.7 } }, tr('settings.terminalNoCommandHint')),
|
|
2945
3033
|
row(tr('settings.proxyHost'), React.createElement('input', { value: form.proxyHost, onChange: setF('proxyHost'), placeholder: 'Route through this host (optional)', style: inputS }), 'ph'),
|
|
2946
3034
|
row(tr('settings.proxyPortUser'), React.createElement('div', { style: { display: 'flex', gap: 6, flex: 1, flexWrap: 'wrap' } },
|
|
2947
3035
|
React.createElement('input', { value: form.proxyPort, onChange: setF('proxyPort'), placeholder: 'Port (22)', style: { ...inputS, minWidth: 90, maxWidth: 120 } }),
|
|
@@ -4972,6 +5060,7 @@ window.__ModuleLoader__.load({
|
|
|
4972
5060
|
right: 'm6 4 4 4-4 4',
|
|
4973
5061
|
left: 'm10 4-4 4 4 4',
|
|
4974
5062
|
more: 'M3 8h.01M8 8h.01M13 8h.01',
|
|
5063
|
+
download: 'M8 2v8m0 0 3.2-3.2M8 10 4.8 6.8M2.5 13h11',
|
|
4975
5064
|
}
|
|
4976
5065
|
return React.createElement('svg', { width: size, height: size, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.25, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, className, style: { flexShrink: 0 } }, React.createElement('path', { d: paths[name] || paths.file }))
|
|
4977
5066
|
}
|
|
@@ -5110,6 +5199,11 @@ window.__ModuleLoader__.load({
|
|
|
5110
5199
|
const dataRef = React.useRef(data)
|
|
5111
5200
|
const [err, setErr] = React.useState('')
|
|
5112
5201
|
const [busy, setBusy] = React.useState('')
|
|
5202
|
+
// Issue #207: the local path of the last mirror download from the tree's
|
|
5203
|
+
// context menu — shown with a "show in folder" action, because the
|
|
5204
|
+
// download itself is invisible (no path picker is involved by design).
|
|
5205
|
+
const [dlNote, setDlNote] = React.useState(null)
|
|
5206
|
+
const revealDlNote = (p) => api('POST', '/dsh-remote/fs', withSessionBody({ op: 'revealLocal', path: p }, sessionId)).catch(() => { /* best-effort; the path is still shown */ })
|
|
5113
5207
|
const [picker, setPicker] = React.useState(false)
|
|
5114
5208
|
// Issue #180: the remote root the user EXPLICITLY picked in this panel.
|
|
5115
5209
|
// It only ever overrides what this session's explorer shows — it is never
|
|
@@ -5307,6 +5401,7 @@ window.__ModuleLoader__.load({
|
|
|
5307
5401
|
if (!m) return
|
|
5308
5402
|
if (id === 'open') { if (m.isDir) { if (props.onToggleDir) props.onToggleDir(m.path) } else openFile(m.path); return }
|
|
5309
5403
|
if (id === 'download') { doFs('download', { path: m.path }); return }
|
|
5404
|
+
if (id === 'download-client') { downloadToComputer(m.path); return }
|
|
5310
5405
|
if (id === 'copy-rel') { copyPath(relPath(m.path), m.path); return }
|
|
5311
5406
|
if (id === 'copy-abs') { copyPath(m.path, m.path); return }
|
|
5312
5407
|
if (id === 'rename') { setNamePrompt({ kind: 'rename', path: m.path, name: m.name }); return }
|
|
@@ -5332,7 +5427,8 @@ window.__ModuleLoader__.load({
|
|
|
5332
5427
|
return d
|
|
5333
5428
|
}
|
|
5334
5429
|
box.appendChild(mkItem(menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen'), false, () => runMenuAction('open', menu)))
|
|
5335
|
-
if (!
|
|
5430
|
+
if (!menu.isDir) box.appendChild(mkItem(tr('explorer.menuDownloadLocal'), false, () => runMenuAction('download-client', menu)))
|
|
5431
|
+
if (!menu.isDir && !localWorkspaceSession(sessionId)) box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => runMenuAction('download', menu)))
|
|
5336
5432
|
box.appendChild(mkItem(tr('explorer.menuCopyRel'), false, () => runMenuAction('copy-rel', menu)))
|
|
5337
5433
|
box.appendChild(mkItem(tr('explorer.menuCopyAbs'), false, () => runMenuAction('copy-abs', menu)))
|
|
5338
5434
|
box.appendChild(mkItem(tr('explorer.menuRename'), false, () => runMenuAction('rename', menu)))
|
|
@@ -5392,9 +5488,13 @@ window.__ModuleLoader__.load({
|
|
|
5392
5488
|
const view = viewRef.current
|
|
5393
5489
|
setBusy(op)
|
|
5394
5490
|
return api('POST', '/dsh-remote/fs', withSessionBody({ op, ...payload }, sessionId))
|
|
5395
|
-
.then(() => {
|
|
5491
|
+
.then((r) => {
|
|
5396
5492
|
if (viewRef.current !== view) return
|
|
5397
5493
|
setErr('')
|
|
5494
|
+
// Issue #207: the explorer used to discard the download response —
|
|
5495
|
+
// the file landed in the local mirror with zero feedback, reading
|
|
5496
|
+
// as "the download did nothing".
|
|
5497
|
+
if (op === 'download' && r && r.local) setDlNote({ path: String(r.local) })
|
|
5398
5498
|
if (refreshParent) {
|
|
5399
5499
|
if (root) loadDir(root, { force: true })
|
|
5400
5500
|
for (const dir of expanded) if (dir !== root) loadDir(dir, { force: true })
|
|
@@ -5440,6 +5540,12 @@ window.__ModuleLoader__.load({
|
|
|
5440
5540
|
? React.createElement('span', { style: { fontSize: 11, opacity: 0.75, flexShrink: 0, color: T.ok } }, tr('explorer.copied'))
|
|
5441
5541
|
: null)
|
|
5442
5542
|
|
|
5543
|
+
// Fetch the file through the host and let the browser save it.
|
|
5544
|
+
const downloadToComputer = (p) => {
|
|
5545
|
+
setErr('')
|
|
5546
|
+
downloadRemoteFileToClient(sessionId, p).catch((e) => setErr(String((e && e.message) || e)))
|
|
5547
|
+
}
|
|
5548
|
+
|
|
5443
5549
|
// One tree row (dir toggles via the framework's onToggleDir; file opens).
|
|
5444
5550
|
// Text uses the normal foreground (theme-following) — no accent green.
|
|
5445
5551
|
const treeKeyDown = (e) => {
|
|
@@ -5520,6 +5626,16 @@ window.__ModuleLoader__.load({
|
|
|
5520
5626
|
React.createElement('span', { style: { flexShrink: 0, display: 'inline-flex' } }, IconFile(entry.name)),
|
|
5521
5627
|
React.createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', flex: 1 } }, entry.name),
|
|
5522
5628
|
copiedMark(entry.path),
|
|
5629
|
+
hovered ? React.createElement('span', {
|
|
5630
|
+
className: 'dsh-rw-row-download',
|
|
5631
|
+
role: 'button',
|
|
5632
|
+
tabIndex: -1,
|
|
5633
|
+
title: tr('explorer.downloadLocal'),
|
|
5634
|
+
'aria-label': tr('explorer.downloadLocal'),
|
|
5635
|
+
onClick: (e) => { e.preventDefault(); e.stopPropagation(); downloadToComputer(entry.path) },
|
|
5636
|
+
onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); downloadToComputer(entry.path) } },
|
|
5637
|
+
style: { flexShrink: 0, display: 'inline-flex', alignItems: 'center', color: T.muted, cursor: 'pointer', padding: '0 2px' },
|
|
5638
|
+
}, React.createElement(WorkbenchIcon, { name: 'download', size: 13 })) : null,
|
|
5523
5639
|
(entry.size != null || entry.mtime)
|
|
5524
5640
|
? React.createElement('span', { className: 'dsh-rw-row-meta', style: { fontSize: 10, flexShrink: 0, fontFamily: 'monospace' }, title: entry.mtime ? fmtTime(entry.mtime) : '' }, humanSize(entry.size))
|
|
5525
5641
|
: null,
|
|
@@ -5601,6 +5717,10 @@ window.__ModuleLoader__.load({
|
|
|
5601
5717
|
connectionState === 'interrupted' && root ? React.createElement('div', { role: 'status', style: { padding: '6px 10px', display: 'flex', gap: 6, fontSize: 11, color: T.warn, background: T.bg } },
|
|
5602
5718
|
React.createElement('span', { style: { flex: 1 } }, tr('explorer.connection.interrupted')),
|
|
5603
5719
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => refreshStatus({ force: true }) }, tr('project.retry'))) : null,
|
|
5720
|
+
dlNote ? React.createElement('div', { role: 'status', style: { padding: '6px 10px', display: 'flex', gap: 6, fontSize: 11, alignItems: 'center', background: T.bg } },
|
|
5721
|
+
React.createElement('span', { style: { flex: 1, wordBreak: 'break-all' }, title: dlNote.path }, tr('explorer.downloadedNote', { path: dlNote.path })),
|
|
5722
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => revealDlNote(dlNote.path) }, tr('explorer.showInFolder')),
|
|
5723
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => setDlNote(null), 'aria-label': tr('explorer.dismissNote') }, '✕')) : null,
|
|
5604
5724
|
remoteTerminal.error ? React.createElement('div', { role: 'alert', style: { padding: '6px 10px', color: T.danger, fontSize: 12 } }, remoteTerminal.error) : null,
|
|
5605
5725
|
picker ? React.createElement('div', { style: { padding: 8 } }, React.createElement(DirPicker, {
|
|
5606
5726
|
open: true, busy: false, registerWorkspace: false, initialTab: 'remote',
|
|
@@ -5658,7 +5778,8 @@ window.__ModuleLoader__.load({
|
|
|
5658
5778
|
contextual: true,
|
|
5659
5779
|
items: [
|
|
5660
5780
|
{ id: 'open', label: menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen') },
|
|
5661
|
-
...(
|
|
5781
|
+
...(menu.isDir ? [] : [{ id: 'download-client', label: tr('explorer.menuDownloadLocal') }]),
|
|
5782
|
+
...(!menu.isDir && !localWorkspaceSession(sessionId) ? [{ id: 'download', label: tr('explorer.menuDownload') }] : []),
|
|
5662
5783
|
{ id: 'copy-rel', label: tr('explorer.menuCopyRel') },
|
|
5663
5784
|
{ id: 'copy-abs', label: tr('explorer.menuCopyAbs') },
|
|
5664
5785
|
{ id: 'rename', label: tr('explorer.menuRename') },
|
|
@@ -6205,6 +6326,10 @@ window.__ModuleLoader__.load({
|
|
|
6205
6326
|
const [findIndex, setFindIndex] = React.useState(0)
|
|
6206
6327
|
const [cursor, setCursor] = React.useState({ line: 1, col: 1 })
|
|
6207
6328
|
const [copyNote, setCopyNote] = React.useState('')
|
|
6329
|
+
// Issue #207: the local path of the last mirror download (shown with a
|
|
6330
|
+
// "show in folder" action; dismissible).
|
|
6331
|
+
const [dlLocal, setDlLocal] = React.useState('')
|
|
6332
|
+
const revealLocal = (p) => api('POST', '/dsh-remote/fs', withSessionBody({ op: 'revealLocal', path: p }, fileSessionId)).catch(() => { /* revealing is best-effort; the path is still shown */ })
|
|
6208
6333
|
const scrollRef = React.useRef(null)
|
|
6209
6334
|
const editorRef = React.useRef(null)
|
|
6210
6335
|
const findRef = React.useRef(null)
|
|
@@ -6370,7 +6495,22 @@ window.__ModuleLoader__.load({
|
|
|
6370
6495
|
const downloadMirror = () => {
|
|
6371
6496
|
setSaving(true); setErr('')
|
|
6372
6497
|
api('POST', '/dsh-remote/fs', withSessionBody({ op: 'download', path }, fileSessionId))
|
|
6373
|
-
.then((r) => {
|
|
6498
|
+
.then((r) => {
|
|
6499
|
+
if (fileViewRef.current !== draftKey) return
|
|
6500
|
+
setCopyNote(tr('file.downloaded', { local: (r && r.local ? tr('file.downloadedAt', { path: r.local }) : '') }))
|
|
6501
|
+
// Issue #207: the file lands in the local mirror — make that
|
|
6502
|
+
// actionable instead of a transient note the user never connects
|
|
6503
|
+
// to a place on disk.
|
|
6504
|
+
setDlLocal(r && r.local ? String(r.local) : '')
|
|
6505
|
+
})
|
|
6506
|
+
.catch((e) => { if (fileViewRef.current === draftKey) setErr(String((e && e.message) || e)) })
|
|
6507
|
+
.finally(() => { if (fileViewRef.current === draftKey) setSaving(false) })
|
|
6508
|
+
}
|
|
6509
|
+
|
|
6510
|
+
const downloadToBrowser = () => {
|
|
6511
|
+
setSaving(true); setErr('')
|
|
6512
|
+
downloadRemoteFileToClient(fileSessionId, path)
|
|
6513
|
+
.then(() => { if (fileViewRef.current !== draftKey) return; setCopyNote(tr('file.downloadedToComputer')) })
|
|
6374
6514
|
.catch((e) => { if (fileViewRef.current === draftKey) setErr(String((e && e.message) || e)) })
|
|
6375
6515
|
.finally(() => { if (fileViewRef.current === draftKey) setSaving(false) })
|
|
6376
6516
|
}
|
|
@@ -6421,6 +6561,7 @@ window.__ModuleLoader__.load({
|
|
|
6421
6561
|
React.createElement(WorkbenchAction, { icon: 'search', label: tr('workbench.find'), pressed: findOpen, disabled: !data || data.binary || data.image, onClick: () => { setFindOpen((v) => !v); setSourceMode(true); keepView({ sourceMode: true }) } }),
|
|
6422
6562
|
React.createElement(WorkbenchAction, { icon: 'wrap', label: tr('workbench.wrap'), pressed: wrap, onClick: () => { setWrap(!wrap); keepView({ wrap: !wrap }) } }),
|
|
6423
6563
|
React.createElement(WorkbenchAction, { icon: 'copy', label: tr('workbench.copyContent'), disabled: !data || data.binary || data.image, onClick: () => copy(edit ? draft : originalText) }),
|
|
6564
|
+
React.createElement(WorkbenchAction, { icon: 'download', label: tr('file.download'), disabled: loading || saving || !path || !!localCopy, onClick: downloadToBrowser }),
|
|
6424
6565
|
React.createElement(WorkbenchAction, { icon: 'terminal', label: tr('workbench.openTerminal'), disabled: remoteTerminal.pending, onClick: remoteTerminal.open }),
|
|
6425
6566
|
edit ? React.createElement(React.Fragment, null,
|
|
6426
6567
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: { ...primaryBtnS, padding: '4px 10px', fontSize: 12 }, onClick: saveRemote, disabled: saving || !dirty || saveConflict, title: tr('file.saveHint') }, saving ? tr('file.saving') : tr('file.saveToRemote')),
|
|
@@ -6516,7 +6657,10 @@ window.__ModuleLoader__.load({
|
|
|
6516
6657
|
React.createElement('span', {}, data && data.size != null ? humanSize(data.size) : ''),
|
|
6517
6658
|
React.createElement('span', {}, baseName.includes('.') ? baseName.split('.').pop().toUpperCase() : 'TEXT'),
|
|
6518
6659
|
data?.eol ? React.createElement('span', {}, data.eol === 'crlf' ? 'CRLF' : data.eol === 'mixed' ? tr('file.mixedEol') : 'LF') : null,
|
|
6519
|
-
React.createElement('span', { style: { marginLeft: 'auto', color: copyNote ? T.ok : T.muted } }, copyNote || (localPreview ? tr('file.localCopySource') : loading && data ? tr('workbench.refreshing') : edit ? tr('file.editing') : tr('file.readonly')))
|
|
6660
|
+
React.createElement('span', { style: { marginLeft: 'auto', color: copyNote ? T.ok : T.muted } }, copyNote || (localPreview ? tr('file.localCopySource') : loading && data ? tr('workbench.refreshing') : edit ? tr('file.editing') : tr('file.readonly'))),
|
|
6661
|
+
dlLocal ? React.createElement('span', { style: { display: 'flex', gap: 6, alignItems: 'center' } },
|
|
6662
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', onClick: () => revealLocal(dlLocal), title: dlLocal }, tr('explorer.showInFolder')),
|
|
6663
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', onClick: () => setDlLocal(''), 'aria-label': tr('explorer.dismissNote') }, '✕')) : null),
|
|
6520
6664
|
)
|
|
6521
6665
|
}
|
|
6522
6666
|
|
|
@@ -7375,8 +7519,8 @@ window.__ModuleLoader__.load({
|
|
|
7375
7519
|
React.createElement('path', { d: 'M6 3v14M13 3v14' })), tr('ide.enter'))
|
|
7376
7520
|
}
|
|
7377
7521
|
const REMOTE_IDE_CSS = `
|
|
7378
|
-
[data-rw-ide-shell]{position:fixed;inset:var(--dsh-windows-titlebar-height,0px) 0 0;z-index:24;background:var(--dsw-alias-bg-base,#fff);color:var(--dsw-alias-label-primary,#222);display:flex;flex-direction:column;min-width:0;min-height:0;font-size:12px}
|
|
7379
|
-
[data-rw-ide-header]{height:38px;min-height:38px;display:flex;align-items:center;gap:10px;padding:0 12px;border-bottom:1px solid var(--dsw-alias-border-l2,#ddd);background:var(--dsw-specific-sidebar-fill,var(--dsw-alias-bg-base,#fff))}
|
|
7522
|
+
[data-rw-ide-shell]{position:fixed;inset:var(--dsh-windows-titlebar-height,0px) 0 0;z-index:24;background:linear-gradient(var(--dsw-alias-bg-base,#fff),var(--dsw-alias-bg-base,#fff)),var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#222);display:flex;flex-direction:column;min-width:0;min-height:0;font-size:12px}
|
|
7523
|
+
[data-rw-ide-header]{height:38px;min-height:38px;display:flex;align-items:center;gap:10px;padding:0 12px;border-bottom:1px solid var(--dsw-alias-border-l2,#ddd);background:linear-gradient(var(--dsw-specific-sidebar-fill,var(--dsw-alias-bg-base,#fff)),var(--dsw-specific-sidebar-fill,var(--dsw-alias-bg-base,#fff))),var(--dsw-alias-bg-layer-1,#fff)}
|
|
7380
7524
|
[data-rw-ide-title]{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;flex:1}
|
|
7381
7525
|
[data-rw-ide-body]{flex:1;min-height:0;min-width:0;display:grid}
|
|
7382
7526
|
[data-rw-ide-tree]{min-width:0;min-height:0;overflow:hidden;display:flex;flex-direction:column;border-right:1px solid var(--dsw-alias-border-l2,#ddd)}
|
|
@@ -7385,9 +7529,9 @@ window.__ModuleLoader__.load({
|
|
|
7385
7529
|
[data-rw-ide-tree] [data-rw-explorer-title]{flex-basis:100%!important}
|
|
7386
7530
|
[data-rw-ide-seat]{min-width:0;min-height:0;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden}
|
|
7387
7531
|
[data-rw-ide-placeholder]{max-width:320px;padding:24px;line-height:1.7;text-align:center;color:var(--dsw-alias-label-tertiary,#777)}
|
|
7388
|
-
[data-rw-ide-divider]{width:6px;cursor:col-resize;touch-action:none;position:relative;outline:none;z-index:1;background:var(--dsw-alias-bg-base,#fff)}
|
|
7532
|
+
[data-rw-ide-divider]{width:6px;cursor:col-resize;touch-action:none;position:relative;outline:none;z-index:1;background:linear-gradient(var(--dsw-alias-bg-base,#fff),var(--dsw-alias-bg-base,#fff)),var(--dsw-alias-bg-layer-1,#fff)}
|
|
7389
7533
|
[data-rw-ide-divider]:hover,[data-rw-ide-divider]:focus-visible{background:var(--dsw-static-blue-500,#3b82f6)}
|
|
7390
|
-
[data-rw-ide-editor],[data-rw-ide-chat]{position:fixed!important;top:var(--rw-ide-y)!important;left:var(--rw-ide-x)!important;right:auto!important;bottom:auto!important;width:var(--rw-ide-w)!important;height:var(--rw-ide-h)!important;max-width:none!important;max-height:none!important;margin:0!important;z-index:36!important;box-sizing:border-box!important;background:var(--dsw-alias-bg-base,#fff);border-radius:0!important;overflow:hidden!important;transition:none!important}
|
|
7534
|
+
[data-rw-ide-editor],[data-rw-ide-chat]{position:fixed!important;top:var(--rw-ide-y)!important;left:var(--rw-ide-x)!important;right:auto!important;bottom:auto!important;width:var(--rw-ide-w)!important;height:var(--rw-ide-h)!important;max-width:none!important;max-height:none!important;margin:0!important;z-index:36!important;box-sizing:border-box!important;background:linear-gradient(var(--dsw-alias-bg-base,#fff),var(--dsw-alias-bg-base,#fff)),var(--dsw-alias-bg-layer-1,#fff);border-radius:0!important;overflow:hidden!important;transition:none!important}
|
|
7391
7535
|
[data-rw-ide-editor]{--dsh-sidebar-width:var(--rw-ide-w)!important;border-right:1px solid var(--dsw-alias-border-l2,#ddd)}
|
|
7392
7536
|
[data-rw-ide-editor] [data-sidebar-right-mode],[data-rw-ide-editor] [data-sidebar-right-toggle]{display:none!important}
|
|
7393
7537
|
[data-rw-ide-chat]{--dsh-chat-user-width:calc(var(--rw-ide-w) - 48px)!important;--dsh-conversation-column-width:var(--rw-ide-w)!important;border-left:1px solid var(--dsw-alias-border-l2,#ddd)}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Shared remote platform / shell detection — the single implementation both
|
|
2
|
+
// backends (SshPool native ssh2 and SystemOpenSshPool) route through, the same
|
|
3
|
+
// way sftp-surface.js owns the SFTP surface. It replaced two verbatim copies
|
|
4
|
+
// that had already drifted (openssh lacked the %LOCALAPPDATA% Git Bash
|
|
5
|
+
// candidate), and centralized three fixes:
|
|
6
|
+
//
|
|
7
|
+
// · issue #197 — a POSIX default shell (Git Bash / MSYS / Cygwin set as the
|
|
8
|
+
// sshd DefaultShell) must be recognized BEFORE the cmd.exe probe:
|
|
9
|
+
// `cmd /c ver` succeeds through Git Bash too, and the old order then picked
|
|
10
|
+
// the Windows-path bash wrapper, which a POSIX default shell cannot exec
|
|
11
|
+
// (quoted backslash paths arrive mangled). On such hosts bash is located
|
|
12
|
+
// POSIX-style (`command -v bash` → /usr/bin/bash) so the `"bash" -s`
|
|
13
|
+
// wrapper survives the default shell's own quoting.
|
|
14
|
+
// · issue #199 — the token after `cmd /c` MUST be quoted: Windows OpenSSH
|
|
15
|
+
// re-wraps the client command as `cmd.exe /c "…"`, and a bare `cmd /c ver`
|
|
16
|
+
// reaches the inner cmd with a stray trailing quote (`'ver"' is not
|
|
17
|
+
// recognized…`), which misdetected healthy cmd.exe hosts as POSIX.
|
|
18
|
+
// · `uname` answering MINGW is ambiguous — it can also mean "cmd.exe default
|
|
19
|
+
// shell with Git's usr/bin on PATH" — so `echo $0` disambiguates: a POSIX
|
|
20
|
+
// shell prints its own name, cmd.exe echoes the literal "$0", PowerShell
|
|
21
|
+
// prints nothing.
|
|
22
|
+
//
|
|
23
|
+
// The contract: `run(cmd, timeoutMs)` executes ONE raw command (no detection,
|
|
24
|
+
// no Git Bash wrapper) and resolves { code, stdout, stderr }; a REJECTED
|
|
25
|
+
// promise means the transport itself is broken (a failed command resolves with
|
|
26
|
+
// a non-zero code instead).
|
|
27
|
+
|
|
28
|
+
const PROBE_TIMEOUT_MS = 8000
|
|
29
|
+
|
|
30
|
+
/** Detect platform + shell mode + the Git Bash path. Resolves
|
|
31
|
+
* { platform: 'windows'|'posix'|'unknown', shellMode, gitBashPath }. */
|
|
32
|
+
export async function detectPlatform(run, config = {}) {
|
|
33
|
+
const cap = () => Math.min(config.commandTimeoutMs || PROBE_TIMEOUT_MS, PROBE_TIMEOUT_MS)
|
|
34
|
+
const shellCfg = String(config.shell || '').trim()
|
|
35
|
+
|
|
36
|
+
// 1. A POSIX default shell answers `uname` itself; probe it FIRST (#197).
|
|
37
|
+
let uname = null
|
|
38
|
+
try {
|
|
39
|
+
uname = await run('uname -s', cap())
|
|
40
|
+
} catch {
|
|
41
|
+
// The transport failed, not the command — everything below would too.
|
|
42
|
+
return { platform: 'unknown', shellMode: 'native', gitBashPath: '' }
|
|
43
|
+
}
|
|
44
|
+
const unameOut = String((uname && uname.stdout) || '').trim()
|
|
45
|
+
|
|
46
|
+
if (/mingw|msys|cygwin/i.test(unameOut)) {
|
|
47
|
+
let posixDefaultShell = false
|
|
48
|
+
try {
|
|
49
|
+
const e = await run('echo $0', cap())
|
|
50
|
+
const v = String((e && e.stdout) || '').trim()
|
|
51
|
+
posixDefaultShell = v !== '' && !v.includes('$')
|
|
52
|
+
} catch { /* conservative: treat as a non-POSIX default shell */ }
|
|
53
|
+
if (posixDefaultShell) {
|
|
54
|
+
return { platform: 'windows', ...(await resolveGitBashPosixDefault(run, shellCfg, cap)) }
|
|
55
|
+
}
|
|
56
|
+
// MSYS tools on PATH but a cmd.exe/PowerShell default shell: the regular
|
|
57
|
+
// Windows resolution applies (a Windows-path bash that shell CAN exec).
|
|
58
|
+
return { platform: 'windows', ...(await resolveGitBashWindows(run, shellCfg, cap)) }
|
|
59
|
+
}
|
|
60
|
+
// A uname that answered with anything else means a working POSIX shell —
|
|
61
|
+
// no Windows probe needed (and `cmd` would only exist under Wine).
|
|
62
|
+
if (uname && uname.code === 0 && unameOut) {
|
|
63
|
+
return { platform: 'posix', shellMode: 'native', gitBashPath: '' }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 2. cmd.exe / PowerShell default shell. The token after /c is quoted
|
|
67
|
+
// because of the sshd re-wrapping (#199) — see the header comment.
|
|
68
|
+
let res = null
|
|
69
|
+
try {
|
|
70
|
+
res = await run('cmd /c "ver"', cap())
|
|
71
|
+
} catch {
|
|
72
|
+
return { platform: 'unknown', shellMode: 'native', gitBashPath: '' }
|
|
73
|
+
}
|
|
74
|
+
const out = String((res && res.stdout) || '') + '\n' + String((res && res.stderr) || '')
|
|
75
|
+
if (res && res.code === 0 && /microsoft windows/i.test(out)) {
|
|
76
|
+
return { platform: 'windows', ...(await resolveGitBashWindows(run, shellCfg, cap)) }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 3. Nothing Windows answered — the historical POSIX default.
|
|
80
|
+
return { platform: 'posix', shellMode: 'native', gitBashPath: '' }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Git Bash resolution for a cmd.exe/PowerShell default shell: every probe is
|
|
84
|
+
* a `cmd /c …` form, and the resolved path stays Windows-style because the
|
|
85
|
+
* wrapper is exec'd BY that shell. */
|
|
86
|
+
async function resolveGitBashWindows(run, shellCfg, cap) {
|
|
87
|
+
const exists = async (p) => {
|
|
88
|
+
try {
|
|
89
|
+
const r = await run(`cmd /c if exist "${p}" (echo Y) else (echo N)`, cap())
|
|
90
|
+
return /Y/.test(String((r && r.stdout) || ''))
|
|
91
|
+
} catch {
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (shellCfg && shellCfg !== 'git-bash' && shellCfg !== 'native') {
|
|
96
|
+
if (await exists(shellCfg)) return { shellMode: 'git-bash', gitBashPath: shellCfg }
|
|
97
|
+
}
|
|
98
|
+
if (shellCfg === 'native') return { shellMode: 'native', gitBashPath: '' }
|
|
99
|
+
try {
|
|
100
|
+
const r = await run('cmd /c where bash', cap())
|
|
101
|
+
const first = String((r && r.stdout) || '').trim().split(/\r?\n/)[0].trim()
|
|
102
|
+
if (first) return { shellMode: 'git-bash', gitBashPath: first }
|
|
103
|
+
} catch { /* fall through to the candidate list */ }
|
|
104
|
+
const candidates = [
|
|
105
|
+
'C:\\Program Files\\Git\\bin\\bash.exe',
|
|
106
|
+
'C:\\Program Files (x86)\\Git\\bin\\bash.exe',
|
|
107
|
+
'%LOCALAPPDATA%\\Programs\\Git\\bin\\bash.exe',
|
|
108
|
+
]
|
|
109
|
+
for (const c of candidates) {
|
|
110
|
+
if (await exists(c)) return { shellMode: 'git-bash', gitBashPath: c }
|
|
111
|
+
}
|
|
112
|
+
return { shellMode: 'git-bash', gitBashPath: '' } // wanted but not found — commands fall back to raw
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Git Bash resolution when the DEFAULT SHELL is already POSIX (#197): every
|
|
116
|
+
* path must come out POSIX-style, because the default shell execs the
|
|
117
|
+
* `"bash" -s` wrapper itself and cannot parse quoted backslash paths. */
|
|
118
|
+
async function resolveGitBashPosixDefault(run, shellCfg, cap) {
|
|
119
|
+
if (shellCfg === 'native') return { shellMode: 'native', gitBashPath: '' }
|
|
120
|
+
const locate = async (p) => {
|
|
121
|
+
// Quote only when needed (spaces etc.) — a bare `command -v bash` reads
|
|
122
|
+
// cleaner in logs and behaves identically.
|
|
123
|
+
const argv = /^[\w./%~:-]+$/.test(p) ? p : JSON.stringify(p)
|
|
124
|
+
try {
|
|
125
|
+
const r = await run(`command -v ${argv}`, cap())
|
|
126
|
+
if (r && r.code === 0) {
|
|
127
|
+
const first = String(r.stdout || '').trim().split(/\r?\n/)[0].trim()
|
|
128
|
+
if (first) return first
|
|
129
|
+
}
|
|
130
|
+
} catch { /* try the next form */ }
|
|
131
|
+
return ''
|
|
132
|
+
}
|
|
133
|
+
// A configured path is honored but normalized to forward slashes first.
|
|
134
|
+
if (shellCfg && shellCfg !== 'git-bash') {
|
|
135
|
+
const found = await locate(shellCfg.replace(/\\/g, '/'))
|
|
136
|
+
if (found) return { shellMode: 'git-bash', gitBashPath: found }
|
|
137
|
+
}
|
|
138
|
+
const found = await locate('bash')
|
|
139
|
+
if (found) return { shellMode: 'git-bash', gitBashPath: found }
|
|
140
|
+
// No bash located: the default shell is POSIX anyway, so raw commands work.
|
|
141
|
+
return { shellMode: 'native', gitBashPath: '' }
|
|
142
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export const win32FolderPickScript = main.win32FolderPickScript
|
|
|
15
15
|
export const LOCAL_BOOTSTRAP_TOOLS = main.LOCAL_BOOTSTRAP_TOOLS
|
|
16
16
|
export const normalizeLocalTools = main.normalizeLocalTools
|
|
17
17
|
export const pickWorkspaceNextStep = main.pickWorkspaceNextStep
|
|
18
|
+
export const pickWorkspaceRebindNote = main.pickWorkspaceRebindNote
|
|
18
19
|
export const inject = main.inject
|
|
19
20
|
export const Config = main.Config
|
|
20
21
|
export const apply = main.apply
|