fix(windows): address native CI review findings

This commit is contained in:
Tianyi Cui
2026-08-09 13:57:50 +08:00
parent eb9e7c19eb
commit 3b5ee1dce1
10 changed files with 41 additions and 21 deletions
+16 -6
View File
@@ -4,7 +4,7 @@
* @module @deepseek-ai/dsh-paths
*/
import { realpath } from 'node:fs/promises'
import { opendir, realpath } from 'node:fs/promises'
import { homedir } from 'node:os'
import { basename, dirname, join, resolve } from 'node:path'
@@ -20,19 +20,29 @@ export const DSH_HOME_ENV = 'DSH_HOME'
/**
* Give a native filesystem watcher one canonical spelling of a path, even
* when its final components do not exist yet. The deepest existing ancestor
* is resolved through {@link realpath}; the missing suffix is then restored.
* This prevents Windows short-name aliases from being mixed with long paths
* emitted by the native watcher backend.
* is resolved through {@link realpath}; when a suffix is missing, that
* ancestor is also proved to be an enumerable directory before the suffix is
* restored. This prevents Windows from treating a regular-file ancestor as
* ordinary absence, and prevents short-name aliases from being mixed with
* long paths emitted by the native watcher backend.
* @param path - Watch target or root, resolved against the current directory.
* @returns the target with its existing ancestor canonicalized.
* @throws when ancestor traversal encounters an error other than absence.
* @throws when ancestor traversal encounters an error other than absence, or
* the existing ancestor of a missing suffix is not an enumerable directory.
*/
export async function canonicalizeWatchPath(path: string): Promise<string> {
let current = resolve(path)
const missing: string[] = []
while (true) {
try {
return join(await realpath(current), ...missing.reverse())
const canonical = await realpath(current)
if (missing.length > 0) {
// A Windows file-as-parent probe reports ENOENT. Opening the resolved
// ancestor preserves the cross-platform directory requirement.
const directory = await opendir(canonical)
await directory.close()
}
return join(canonical, ...missing.reverse())
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
const parent = dirname(current)