Skip to content

fix(desktop): avoid main util ts import#160

Merged
Astro-Han merged 2 commits into
devfrom
fix/i159-main-util-ts-import
Apr 22, 2026
Merged

fix(desktop): avoid main util ts import#160
Astro-Han merged 2 commits into
devfrom
fix/i159-main-util-ts-import

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Summary

Avoid importing @opencode-ai/util/file-extensions from the Electron main process by moving the attachment MIME lookup into desktop main code. Bump release packages to 0.2.7 for the startup-crash hotfix.

Why

The published v0.2.6 packaged app crashes on startup because the main process loads node_modules/@opencode-ai/util/src/file-extensions.ts, and Node refuses TypeScript stripping for files under node_modules. The broken v0.2.6 GitHub Release has been deleted to prevent accidental downloads; v0.2.7 should replace it as the latest stable release.

Related Issue

Closes #159.

How To Verify

bun --cwd packages/desktop-electron test src/main/attachment-mime.test.ts
bun --cwd packages/desktop-electron typecheck
bun --cwd packages/desktop-electron build
rg -n "@opencode-ai/util/file-extensions|node_modules/@opencode-ai/util/src/file-extensions" packages/desktop-electron/out || true
bun install --frozen-lockfile

Screenshots or Recordings

Not applicable. No visible UI changes.

Checklist

  • I linked the related issue, or stated why there is no issue
  • This PR has type, scope, and priority labels, or I requested maintainer labeling
  • I listed the relevant verification steps, including tests when behavior changed
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for desktop, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, or generated/local file changes when relevant
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

Summary by CodeRabbit

  • Chores

    • Bumped package versions to 0.2.7 across the monorepo.
  • New Features

    • Added attachment file type → MIME detection to improve file handling and validation.
  • Tests

    • Added tests covering attachment MIME detection, extension handling, and unsupported/edge cases.

@Astro-Han Astro-Han added bug Something isn't working P1 High priority platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions labels Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 21c98475-2283-41ec-8965-c4187216cd0d

📥 Commits

Reviewing files that changed from the base of the PR and between dc5f55c and 7baf949.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • packages/app/package.json
  • packages/desktop-electron/package.json
  • packages/desktop-electron/src/main/attachment-mime.test.ts
  • packages/desktop-electron/src/main/attachment-mime.ts
  • packages/desktop-electron/src/main/ipc.ts
  • packages/opencode/package.json
  • packages/util/package.json

📝 Walkthrough

Walkthrough

Version bumps across four packages (0.2.6 → 0.2.7), addition of a local MIME-detection module with tests in desktop-electron, and refactor of the main IPC to use the new module instead of importing image-extension data from the util package.

Changes

Cohort / File(s) Summary
Version Bumps
packages/app/package.json, packages/desktop-electron/package.json, packages/opencode/package.json, packages/util/package.json
Package version fields updated from 0.2.60.2.7. No other manifest changes.
MIME Type Detection Module + Tests
packages/desktop-electron/src/main/attachment-mime.ts, packages/desktop-electron/src/main/attachment-mime.test.ts
New MIME_BY_EXTENSION map and attachmentPathMime(filepath, extname?) exported; tests added to validate supported image/pdf extensions, case-insensitivity, custom extname callback, and unsupported/no-extension behavior.
IPC Refactor
packages/desktop-electron/src/main/ipc.ts
Removed inline attachmentPathMime and IMAGE_EXTS import from @opencode-ai/util/file-extensions; now imports and uses the new attachment-mime module in the "read-file-data-url" handler.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #162 — Packaged app startup crash due to runtime import of @opencode-ai/util TypeScript sources: This PR removes the file-extensions import from main IPC and adds a local MIME module, which addresses the root cause described in #162.

Poem

🐰 I hopped through files with nimble feet,
Found MIME strings and made them neat.
Pulled them close, no more stray import fright,
The app packs snug and launches right. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: moving MIME attachment logic to avoid importing TypeScript source from util in the Electron main process.
Description check ✅ Passed The PR description comprehensively covers summary, rationale, linked issue, verification steps, UI impact, and all checklist items completed.
Linked Issues check ✅ Passed All code changes directly address issue #159: the new attachment-mime module replaces the problematic util import, preventing TypeScript source loading from node_modules.
Out of Scope Changes check ✅ Passed All changes are in scope: version bumps to 0.2.7 align with the hotfix objective, and no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/i159-main-util-ts-import

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates several package versions to 0.2.7 and refactors the attachmentPathMime utility into a dedicated module with new unit tests. Feedback suggests consolidating the MIME type lookup into a single map and making the path extension logic injectable to improve maintainability and support cross-platform testing.

Comment thread packages/desktop-electron/src/main/attachment-mime.ts Outdated

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three nits on the hotfix. Approach is fine — moving the narrow slice into main's source tree sidesteps the Node-refuses-TS-in-node_modules failure. Flagging drift risk and test gaps below.

One alternative worth a thought for a follow-up (not this PR): externalizeDeps: { exclude: ["@opencode-ai/util"] } in electron.vite.config.ts would bundle the util module into main at build time, keeping a single source of truth with the renderer. Current approach is defensible for a hotfix.

Comment thread packages/desktop-electron/src/main/attachment-mime.ts
Comment thread packages/desktop-electron/src/main/attachment-mime.test.ts
Comment thread packages/desktop-electron/src/main/attachment-mime.test.ts
@Astro-Han Astro-Han force-pushed the fix/i159-main-util-ts-import branch from dc5f55c to 7baf949 Compare April 22, 2026 18:24
@Astro-Han Astro-Han merged commit 109aa92 into dev Apr 22, 2026
25 checks passed
@Astro-Han Astro-Han deleted the fix/i159-main-util-ts-import branch April 22, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working P1 High priority platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Packaged app crashes on startup when main process loads @opencode-ai/util TypeScript source

1 participant