fixing locale wip#14
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
📝 WalkthroughWalkthroughThe CLI initialization in 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opencode/src/index.ts`:
- Line 57: The .locale("en") call only changes yargs help language but doesn't
stop y18n from reading locale files; locate where the yargs instance is created
(the code that calls .locale("en") in packages/opencode/src/index.ts) and
prevent y18n filesystem access by replacing or reconfiguring the internal y18n
instance: after creating the yargs instance, access its internal y18n (or
replace it) and initialize it with safe options such as { directory: null } or {
updateFiles: false }, or swap in a no-op i18n implementation so no file reads
occur; ensure the change happens right after the yargs creation where
.locale("en") is set so bundled Windows executables no longer attempt to open
locales.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5fc76fc3-cad3-40c9-be1a-0644c861924d
📒 Files selected for processing (1)
packages/opencode/src/index.ts
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/opencode/script/build.ts (2)
9-29: String replacement is fragile and lacks validation.The patch relies on an exact string match of y18n's import statement. If y18n updates this line (even whitespace changes), the replacement silently fails and the Windows crash will resurface. Consider adding a check to warn or fail if the patch didn't apply:
♻️ Proposed improvement to validate the patch
const y18nPatchPlugin = { name: "y18n-eunknown-fix", setup(build: { onLoad: Function }) { build.onLoad({ filter: /y18n.*platform-shims[/\\\\]node/ }, async (args: { path: string }) => { const src = await Bun.file(args.path).text() + const target = "import { readFileSync, statSync, writeFile } from 'fs';" + if (!src.includes(target)) { + console.warn(`[y18n-eunknown-fix] Expected import not found in ${args.path}; patch may be outdated`) + return { contents: src, loader: "js" } + } const patched = src.replace( - "import { readFileSync, statSync, writeFile } from 'fs';", + target, `import { readFileSync as _readFileSync, statSync, writeFile } from 'fs'; function readFileSync(p, o) { try { return _readFileSync(p, o) } catch (e) { if (e.code === 'EUNKNOWN') e.code = 'ENOENT'; throw e } }`, ) return { contents: patched, loader: "js" } }) }, }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/script/build.ts` around lines 9 - 29, The current y18nPatchPlugin applies a fragile string.replace on the platform-shims file and doesn't verify the patch succeeded; update the onLoad handler in y18nPatchPlugin (setup -> build.onLoad) to read the source into src, perform the replacement into patched, then check if patched differs from src and if not emit a clear warning or throw an error (including args.path and a hint to update the matcher) so the build fails fast; if the patch did apply, continue returning { contents: patched, loader: "js" } as before.
15-16: UseBunPlugintype for improved type safety and IDE support.The inline type annotations
{ onLoad: Function }and{ path: string }are loosely typed. Since the project already extends@tsconfig/bun, theBunPlugintype from the"bun"module is accessible and provides proper typing for the plugin setup method, as shown in Bun's documentation.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/script/build.ts` around lines 15 - 16, Replace the loose inline types with Bun's proper plugin types: update the setup signature to use the BunPlugin type for its parameter and use the appropriate Bun type for the onLoad callback argument (instead of { onLoad: Function } and { path: string }). Locate the setup method (setup(build: { onLoad: Function })) and the build.onLoad handler and change their parameter types to the BunPlugin types imported from "bun" so the setup method and the onLoad callback use the official Bun types for stronger type safety and IDE support.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/opencode/script/build.ts`:
- Around line 9-29: The current y18nPatchPlugin applies a fragile string.replace
on the platform-shims file and doesn't verify the patch succeeded; update the
onLoad handler in y18nPatchPlugin (setup -> build.onLoad) to read the source
into src, perform the replacement into patched, then check if patched differs
from src and if not emit a clear warning or throw an error (including args.path
and a hint to update the matcher) so the build fails fast; if the patch did
apply, continue returning { contents: patched, loader: "js" } as before.
- Around line 15-16: Replace the loose inline types with Bun's proper plugin
types: update the setup signature to use the BunPlugin type for its parameter
and use the appropriate Bun type for the onLoad callback argument (instead of {
onLoad: Function } and { path: string }). Locate the setup method (setup(build:
{ onLoad: Function })) and the build.onLoad handler and change their parameter
types to the BunPlugin types imported from "bun" so the setup method and the
onLoad callback use the official Bun types for stronger type safety and IDE
support.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e5613389-1684-49d3-938f-fa003a353051
📒 Files selected for processing (1)
packages/opencode/script/build.ts
Issue for this PR
Closes #8
Type of change
What does this PR do?
Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist
If you do not follow this template your PR will be automatically rejected.