@deepseek-ai/dsh-native-command 0.1.3-alpha.2 → 0.1.5-alpha.2
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.i18n.yaml +2 -2
- package/README.md +2 -0
- package/README.zh.md +2 -0
- package/lib/index.js +56 -2
- package/lib/types/index.d.ts +2 -2
- package/lib/types/path-opener.d.ts +16 -0
- package/package.json +1 -1
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/util/native-command/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: b0b1963a97c6d528c123d4900db529bd3dc38332
|
|
6
|
+
README.zh.md: 6a245e3473a4e4dd9944dc53898e04be2fcba2e4
|
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ The `NativeCommandRunner` type is the injectable command boundary for host integ
|
|
|
47
47
|
|
|
48
48
|
`openNativePath(path, signal)` hands a path to the default application and prefers the named default browser for HTML and SVG where the platform can identify one. `openNativeTextFile(path, signal)` selects text-editor intent; on macOS it uses `open -t`. WSL paths are translated with `wslpath -w` before the Windows desktop receives them. `canOpenNativePath()` reports whether the current Host plausibly has a desktop target.
|
|
49
49
|
|
|
50
|
+
`revealNativePath(path, signal)` selects the file in Finder or Explorer, including WSL path translation, and opens its parent directory through `xdg-open` on desktop Linux. `nativeFileManager()` identifies that action for Host-derived UI labels; desktop availability remains a separate `canOpenNativePath()` check. Callers must authorize the absolute file path before invoking either operation. Platform dispatch is covered by injected-runner tests; native desktop verification belongs to the corresponding platform. Explorer receives an encoded file URI as a separate argument. Its exit code 1 is accepted as a delegated handoff; cancellation, missing executables, and other exit codes still reject. This acknowledgement does not prove that a desktop window selected the file.
|
|
51
|
+
|
|
50
52
|
-----
|
|
51
53
|
|
|
52
54
|
<a id="understand-the-implementation"></a>
|
package/README.zh.md
CHANGED
|
@@ -47,6 +47,8 @@ const { stdout, stderr } = await runNativeCommand('osascript', ['-e', script], s
|
|
|
47
47
|
|
|
48
48
|
`openNativePath(path, signal)` 将路径交给默认应用;平台能够确定默认浏览器时,HTML 与 SVG 会优先交给该浏览器。`openNativeTextFile(path, signal)` 选择文本编辑器意图;macOS 使用 `open -t`。WSL 路径先通过 `wslpath -w` 转换,再交给 Windows 桌面。`canOpenNativePath()` 报告当前 Host 是否可能具备桌面目标。
|
|
49
49
|
|
|
50
|
+
`revealNativePath(path, signal)` 在 Finder 或文件资源管理器中选中文件,包含 WSL 路径转换;在桌面 Linux 上通过 `xdg-open` 打开上层目录。`nativeFileManager()` 标识该操作,供 UI 根据 Host 选择文案;桌面是否可用仍由独立的 `canOpenNativePath()` 检查决定。调用方必须先授权绝对文件路径,再执行操作。平台分派由注入运行器的测试覆盖;原生桌面验证由对应平台负责。 Explorer 接收独立参数中的编码文件 URI。退出码 1 按已转交请求处理;取消、找不到可执行文件和其他退出码仍然报错。该确认不能证明桌面窗口已选中文件。
|
|
51
|
+
|
|
50
52
|
-----
|
|
51
53
|
|
|
52
54
|
<a id="understand-the-implementation"></a>
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { release } from "node:os";
|
|
3
|
-
import { extname } from "node:path";
|
|
3
|
+
import { dirname, extname } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
4
5
|
//#region lib/types/runner.js
|
|
5
6
|
/**
|
|
6
7
|
* Shared no-shell `execFile` runner for host-native OS integrations.
|
|
@@ -186,5 +187,58 @@ function openNativePath(path, signal, internals = {}) {
|
|
|
186
187
|
function openNativeTextFile(path, signal, internals = {}) {
|
|
187
188
|
return openNativePathWithIntent(path, signal, "text-editor", internals);
|
|
188
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Identify the native file-manager action without inspecting the browser's platform.
|
|
192
|
+
* @param internals - platform and WSL facts.
|
|
193
|
+
* @returns the supported file-manager action, or null on unsupported platforms.
|
|
194
|
+
*/
|
|
195
|
+
function nativeFileManager(internals = {}) {
|
|
196
|
+
const platform = internals.platform ?? process.platform;
|
|
197
|
+
if (platform === "darwin") return "finder";
|
|
198
|
+
if (platform === "win32" || platform === "linux" && isWsl(internals)) return "explorer";
|
|
199
|
+
return platform === "linux" ? "directory" : null;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Reveal a file in Finder or Explorer, or open its parent in the Linux default file manager.
|
|
203
|
+
* @param path - absolute file path already authorized by the caller.
|
|
204
|
+
* @param signal - caller lifetime; abort terminates the native command.
|
|
205
|
+
* @param internals - platform, environment, and command runner for adapter tests.
|
|
206
|
+
* @returns after command completion; Explorer exit 1 is accepted as a delegated handoff, not proof of selection.
|
|
207
|
+
*/
|
|
208
|
+
async function revealNativePath(path, signal, internals = {}) {
|
|
209
|
+
signal.throwIfAborted();
|
|
210
|
+
const platform = internals.platform ?? process.platform;
|
|
211
|
+
const run = internals.run ?? runNativeCommand;
|
|
212
|
+
const manager = nativeFileManager({
|
|
213
|
+
...internals,
|
|
214
|
+
platform
|
|
215
|
+
});
|
|
216
|
+
if (manager === "finder") {
|
|
217
|
+
await run("open", ["-R", path], signal);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (manager === "explorer") {
|
|
221
|
+
let windowsPath = path;
|
|
222
|
+
if (platform === "linux") {
|
|
223
|
+
const translated = await run("wslpath", ["-w", path], signal);
|
|
224
|
+
signal.throwIfAborted();
|
|
225
|
+
windowsPath = translated.stdout.replace(/[\r\n]+$/, "");
|
|
226
|
+
if (windowsPath === "") throw new Error("wslpath returned no Windows path");
|
|
227
|
+
}
|
|
228
|
+
const target = pathToFileURL(windowsPath, { windows: true }).href.replaceAll(",", "%2C");
|
|
229
|
+
try {
|
|
230
|
+
await run("explorer.exe", ["/select,", target], signal);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
signal.throwIfAborted();
|
|
233
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== 1) throw error;
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (manager === "directory") {
|
|
238
|
+
await run("xdg-open", [dirname(path)], signal);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
throw new Error(`native file manager is unsupported on ${platform}`);
|
|
242
|
+
}
|
|
189
243
|
//#endregion
|
|
190
|
-
export { canOpenNativePath, openNativePath, openNativeTextFile, runNativeCommand };
|
|
244
|
+
export { canOpenNativePath, nativeFileManager, openNativePath, openNativeTextFile, revealNativePath, runNativeCommand };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { runNativeCommand } from './runner.ts';
|
|
6
6
|
export type { NativeCommandRunner } from './runner.ts';
|
|
7
|
-
export { canOpenNativePath, openNativePath, openNativeTextFile, } from './path-opener.ts';
|
|
8
|
-
export type { PathOpenerInternals, PathOpenerRunner, } from './path-opener.ts';
|
|
7
|
+
export { canOpenNativePath, nativeFileManager, revealNativePath, openNativePath, openNativeTextFile, } from './path-opener.ts';
|
|
8
|
+
export type { NativeFileManager, PathOpenerInternals, PathOpenerRunner, } from './path-opener.ts';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -48,4 +48,20 @@ export declare function openNativePath(path: string, signal: AbortSignal, intern
|
|
|
48
48
|
* @param internals - Platform and runner hooks for deterministic tests.
|
|
49
49
|
*/
|
|
50
50
|
export declare function openNativeTextFile(path: string, signal: AbortSignal, internals?: PathOpenerInternals): Promise<void>;
|
|
51
|
+
/** File-manager behavior available on the serving Host, including WSL's Windows desktop. */
|
|
52
|
+
export type NativeFileManager = 'finder' | 'explorer' | 'directory';
|
|
53
|
+
/**
|
|
54
|
+
* Identify the native file-manager action without inspecting the browser's platform.
|
|
55
|
+
* @param internals - platform and WSL facts.
|
|
56
|
+
* @returns the supported file-manager action, or null on unsupported platforms.
|
|
57
|
+
*/
|
|
58
|
+
export declare function nativeFileManager(internals?: PathOpenerInternals): NativeFileManager | null;
|
|
59
|
+
/**
|
|
60
|
+
* Reveal a file in Finder or Explorer, or open its parent in the Linux default file manager.
|
|
61
|
+
* @param path - absolute file path already authorized by the caller.
|
|
62
|
+
* @param signal - caller lifetime; abort terminates the native command.
|
|
63
|
+
* @param internals - platform, environment, and command runner for adapter tests.
|
|
64
|
+
* @returns after command completion; Explorer exit 1 is accepted as a delegated handoff, not proof of selection.
|
|
65
|
+
*/
|
|
66
|
+
export declare function revealNativePath(path: string, signal: AbortSignal, internals?: PathOpenerInternals): Promise<void>;
|
|
51
67
|
//# sourceMappingURL=path-opener.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-native-command",
|
|
3
3
|
"description": "Host-native command and path-opening utilities with shell-free execution, cancellation, desktop detection, and WSL handoff",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5-alpha.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|