Skip to content

Conversation

@junhoyeo
Copy link
Contributor

@junhoyeo junhoyeo commented Dec 14, 2025

Screenshots

Before After
version-unknown version-fixed

Problem

The startup toast was displaying "unknown" version for local development mode (file:// plugin entries).

Root Causes

  1. Incorrect file:// URL handling

    // Before: naive string replacement (broken on Windows, edge cases)
    return entry.replace("file://", "")
    
    // After: proper URL parsing with fallback
    return fileURLToPath(entry)
  2. Missing JSONC config file check

    • Only checked opencode.json, missed opencode.jsonc files
    • Local dev mode wasn't detected for .jsonc configs
  3. Unsafe JSONC comment stripping

    // Before: corrupts JSON with comment markers inside strings
    json.replace(/\/\*[\s\S]*?\*\//g, "")  // strips "/* text */" from strings
    json.replace(/^\s*\/\/.*$/gm, "")      // strips "http://example.com" URLs
    
    // After: string-aware regex (skips quoted content)
    json.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m)

Changes

1. Fix file:// URL parsing

  • Use fileURLToPath() from node:url for proper cross-platform handling
  • Fallback to string replacement only if URL parsing fails

2. Add JSONC file detection

  • Added USER_OPENCODE_CONFIG_JSONC constant
  • Config path arrays now check both .json and .jsonc files

3. Make stripJsonComments string-aware

  • New regex pattern matches strings first, then comments
  • Only strips actual comments, preserves content inside quoted strings
  • Same pattern used by production projects (codesandbox, better-auth)

4. DRY refactor

  • Extracted getConfigPaths(directory) helper to eliminate duplicated config path arrays
  • Removed dead code (file:// check in findPluginEntry was unreachable)

Testing

Verified stripJsonComments handles edge cases:

✓ line comment: {"a": 1} // comment
✓ block comment: {"a": /* block */ 1}
✓ // in URL string: {"url": "http://example.com"}
✓ /* */ in string: {"text": "/* not a comment */"}
✓ trailing comma: {"a": 1,}

Files Changed

File Description
checker.ts Fix file:// handling, string-aware JSONC parsing, DRY refactor
constants.ts Add USER_OPENCODE_CONFIG_JSONC

Commits

  • 2ced728 fix: resolve unknown version display in startup toast
  • 6c65ac1 refactor: improve config handling and cleanup
  • 8b1232a fix: make stripJsonComments string-aware
  • b57ed42 refactor: remove dead file:// check from findPluginEntry
  • 1671435 chore: restore original log statements

- Use fileURLToPath for proper URL-to-path conversion
- Support both opencode.json and opencode.jsonc config files
- Add debug logging for version detection
- Add block comment handling to stripJsonComments for JSONC

- Extract getConfigPaths helper to fix DRY violation

- Fix findPluginEntry to recognize file:// dev entries

- Remove debug log statements
Use regex that skips comment markers inside quoted strings.

Prevents corruption of URLs like http://example.com or text containing /* */.
…ginEntry

This branch is unreachable because isLocalDevMode() catches file:// entries

first via getLocalDevPath(), causing checkForUpdate() to return early.
@junhoyeo junhoyeo changed the title fix(auto-update-checker): resolve unknown version display and improve JSONC parsing fix(auto-update-checker): resolve unknown version display and improve JSONC parsing Dec 14, 2025
@code-yeongyu code-yeongyu merged commit 5dd4d97 into code-yeongyu:master Dec 14, 2025
1 check passed
@junhoyeo junhoyeo deleted the fix/unknown-version-display branch December 15, 2025 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants