fix(windows): resolve paths[0] TypeError crash on Windows startup (#351)

- Fix comment-checker/downloader.ts to use Windows-appropriate cache paths (%LOCALAPPDATA% or %APPDATA%) instead of Unix-style ~/.cache
- Guard against undefined import.meta.url in cli.ts which can occur during Windows plugin loading
- Reorder cache check before module resolution for safer fallback behavior

Fixes #347

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
This commit is contained in:
Sisyphus
2025-12-30 22:14:04 +09:00
committed by GitHub
parent 45076041af
commit d8f10f53d4
2 changed files with 23 additions and 9 deletions

View File

@@ -23,6 +23,19 @@ function getBinaryName(): string {
function findCommentCheckerPathSync(): string | null {
const binaryName = getBinaryName()
// Check cached binary first (safest path - no module resolution needed)
const cachedPath = getCachedBinaryPath()
if (cachedPath) {
debugLog("found binary in cache:", cachedPath)
return cachedPath
}
// Guard against undefined import.meta.url (can happen on Windows during plugin loading)
if (!import.meta.url) {
debugLog("import.meta.url is undefined, skipping package resolution")
return null
}
try {
const require = createRequire(import.meta.url)
const cliPkgPath = require.resolve("@code-yeongyu/comment-checker/package.json")
@@ -33,14 +46,8 @@ function findCommentCheckerPathSync(): string | null {
debugLog("found binary in main package:", binaryPath)
return binaryPath
}
} catch {
debugLog("main package not installed")
}
const cachedPath = getCachedBinaryPath()
if (cachedPath) {
debugLog("found binary in cache:", cachedPath)
return cachedPath
} catch (err) {
debugLog("main package not installed or resolution failed:", err)
}
debugLog("no binary found in known locations")

View File

@@ -32,9 +32,16 @@ const PLATFORM_MAP: Record<string, PlatformInfo> = {
/**
* Get the cache directory for oh-my-opencode binaries.
* Follows XDG Base Directory Specification.
* On Windows: Uses %LOCALAPPDATA% or %APPDATA% (Windows conventions)
* On Unix: Follows XDG Base Directory Specification
*/
export function getCacheDir(): string {
if (process.platform === "win32") {
const localAppData = process.env.LOCALAPPDATA || process.env.APPDATA
const base = localAppData || join(homedir(), "AppData", "Local")
return join(base, "oh-my-opencode", "bin")
}
const xdgCache = process.env.XDG_CACHE_HOME
const base = xdgCache || join(homedir(), ".cache")
return join(base, "oh-my-opencode", "bin")