fix(windows): canonicalize native watch paths

This commit is contained in:
Tianyi Cui
2026-08-08 19:29:43 +08:00
parent a6c129a3c6
commit 702e2d024a
21 changed files with 157 additions and 36 deletions
+21 -1
View File
@@ -1,9 +1,11 @@
import { homedir } from 'node:os'
import { mkdir, mkdtemp, realpath, rm, symlink, writeFile } from 'node:fs/promises'
import { homedir, tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import {
DEFAULT_DSH_HOME_DISPLAY,
DSH_HOME_DIR_NAME,
canonicalizeWatchPath,
defaultDshHome,
dshHomeDisplay,
dshHomePath,
@@ -53,4 +55,22 @@ describe('dsh path helpers', () => {
expect(dshHomeDisplay(resolve(defaultDshHome()))).toBe('~/.dsh')
expect(dshHomeDisplay('/some/other/root')).toBe('$DSH_HOME')
})
it('canonicalizes a watcher ancestor while preserving a missing suffix', async () => {
const root = await mkdtemp(join(tmpdir(), 'dsh-watch-path-'))
const target = join(root, 'target')
const alias = join(root, 'alias')
try {
await mkdir(target)
await symlink(target, alias, process.platform === 'win32' ? 'junction' : 'dir')
await expect(canonicalizeWatchPath(join(alias, 'later', 'config.yml'))).resolves.toBe(
join(await realpath(target), 'later', 'config.yml'),
)
const file = join(root, 'file')
await writeFile(file, 'not a directory')
await expect(canonicalizeWatchPath(join(file, 'child'))).rejects.toMatchObject({ code: 'ENOTDIR' })
} finally {
await rm(root, { recursive: true, force: true })
}
})
})