Skip to content

Commit d8f10f5

Browse files
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 <[email protected]>
1 parent 4507604 commit d8f10f5

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/hooks/comment-checker/cli.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ function getBinaryName(): string {
2323
function findCommentCheckerPathSync(): string | null {
2424
const binaryName = getBinaryName()
2525

26+
// Check cached binary first (safest path - no module resolution needed)
27+
const cachedPath = getCachedBinaryPath()
28+
if (cachedPath) {
29+
debugLog("found binary in cache:", cachedPath)
30+
return cachedPath
31+
}
32+
33+
// Guard against undefined import.meta.url (can happen on Windows during plugin loading)
34+
if (!import.meta.url) {
35+
debugLog("import.meta.url is undefined, skipping package resolution")
36+
return null
37+
}
38+
2639
try {
2740
const require = createRequire(import.meta.url)
2841
const cliPkgPath = require.resolve("@code-yeongyu/comment-checker/package.json")
@@ -33,14 +46,8 @@ function findCommentCheckerPathSync(): string | null {
3346
debugLog("found binary in main package:", binaryPath)
3447
return binaryPath
3548
}
36-
} catch {
37-
debugLog("main package not installed")
38-
}
39-
40-
const cachedPath = getCachedBinaryPath()
41-
if (cachedPath) {
42-
debugLog("found binary in cache:", cachedPath)
43-
return cachedPath
49+
} catch (err) {
50+
debugLog("main package not installed or resolution failed:", err)
4451
}
4552

4653
debugLog("no binary found in known locations")

src/hooks/comment-checker/downloader.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@ const PLATFORM_MAP: Record<string, PlatformInfo> = {
3232

3333
/**
3434
* Get the cache directory for oh-my-opencode binaries.
35-
* Follows XDG Base Directory Specification.
35+
* On Windows: Uses %LOCALAPPDATA% or %APPDATA% (Windows conventions)
36+
* On Unix: Follows XDG Base Directory Specification
3637
*/
3738
export function getCacheDir(): string {
39+
if (process.platform === "win32") {
40+
const localAppData = process.env.LOCALAPPDATA || process.env.APPDATA
41+
const base = localAppData || join(homedir(), "AppData", "Local")
42+
return join(base, "oh-my-opencode", "bin")
43+
}
44+
3845
const xdgCache = process.env.XDG_CACHE_HOME
3946
const base = xdgCache || join(homedir(), ".cache")
4047
return join(base, "oh-my-opencode", "bin")

0 commit comments

Comments
 (0)