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:
@@ -23,6 +23,19 @@ function getBinaryName(): string {
|
|||||||
function findCommentCheckerPathSync(): string | null {
|
function findCommentCheckerPathSync(): string | null {
|
||||||
const binaryName = getBinaryName()
|
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 {
|
try {
|
||||||
const require = createRequire(import.meta.url)
|
const require = createRequire(import.meta.url)
|
||||||
const cliPkgPath = require.resolve("@code-yeongyu/comment-checker/package.json")
|
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)
|
debugLog("found binary in main package:", binaryPath)
|
||||||
return binaryPath
|
return binaryPath
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
debugLog("main package not installed")
|
debugLog("main package not installed or resolution failed:", err)
|
||||||
}
|
|
||||||
|
|
||||||
const cachedPath = getCachedBinaryPath()
|
|
||||||
if (cachedPath) {
|
|
||||||
debugLog("found binary in cache:", cachedPath)
|
|
||||||
return cachedPath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog("no binary found in known locations")
|
debugLog("no binary found in known locations")
|
||||||
|
|||||||
@@ -32,9 +32,16 @@ const PLATFORM_MAP: Record<string, PlatformInfo> = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cache directory for oh-my-opencode binaries.
|
* 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 {
|
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 xdgCache = process.env.XDG_CACHE_HOME
|
||||||
const base = xdgCache || join(homedir(), ".cache")
|
const base = xdgCache || join(homedir(), ".cache")
|
||||||
return join(base, "oh-my-opencode", "bin")
|
return join(base, "oh-my-opencode", "bin")
|
||||||
|
|||||||
Reference in New Issue
Block a user