GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — refactor: replace BunProc with Npm module using @npmcli/arborist by thdxr · Pull Request #18308 · anomalyco/opencode Conversation
|
| Filename | Overview |
|---|---|
| packages/opencode/src/npm/index.ts | New Npm namespace replacing BunProc; contains a TDZ ReferenceError on line 163 where unscoped is used before its const declaration, crashing which() for packages with a string bin field in multi-binary scenarios. |
| packages/opencode/src/format/formatter.ts | Critical brace mismatch in prettier.enabled(): duplicated if condition consumes the original for-loop close brace, leaving the prettier object declaration unclosed and causing a parse/type error that likely prevents the entire formatter module from loading. |
| packages/opencode/src/format/index.ts | Updated to consume `string[] |
| packages/opencode/src/lsp/server.ts | Migrated from BunProc to Npm.which() for TypeScript-language-server, Vue, Pyright, and Biome LSPs; ESLint server now uses node directly (correct). Pyright now relies on Npm.which("pyright") which correctly resolves from package.json bin — if the TDZ bug in npm/index.ts is fixed. |
| packages/opencode/src/plugin/index.ts | Uses Npm.add(plugin) for plugin installation; error handling logs and skips failed plugins. Acceptable. |
| packages/opencode/src/provider/provider.ts | Replaces BunProc.install(pkg, "latest") with Npm.add(pkg); note that Npm.add no longer enforces the "latest" version constraint — any previously cached version is reused regardless of the requested version tag. |
| packages/opencode/src/mcp/index.ts | Removes BUN_BE_BUN env var and adds as any cast to silence the TypeScript env type error. Minor but the as any suppresses potentially legitimate type checking. |
| packages/opencode/test/bun.test.ts | BunProc tests removed; this is expected given the migration. |
packages/opencode/src/format/formatter.ts, line 66-82 (link)
Brace mismatch in
prettier.enabled() — prettier object never closed
The refactor introduced a duplicated if block with mismatched indentation, which shifts all the original closing braces one level inward. Counting the braces:
if {if {} closes the inner if} (the original for-loop close) now closes the outer if} from }, closes the for loop (leaving return false on line 80 inside it)} closes enabled() function bodyThe export const prettier: Info = { opened on line 36 has no matching closing brace, so TypeScript/Bun treats all subsequent formatter exports (oxfmt, biome, etc.) as properties of the prettier object, producing a parse or type error.
The fix is to remove the duplicated condition and restore the intended structure:
Last reviewed commit: "sync"
Greptile also left 2 inline comments on this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Greptile SummaryThis PR replaces the Key issues found:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as Caller (formatter/plugin/lsp)
participant Npm as Npm module
participant Lock as Lock
participant Arborist as @npmcli/arborist
participant Registry as npm registry
participant FS as Filesystem
Note over Caller,FS: Npm.which(pkg)
Caller->>Npm: which(pkg)
Npm->>FS: readdir(.bin/)
FS-->>Npm: files[]
alt files.length == 1
Npm-->>Caller: binDir/files[0]
else files.length > 1
Npm->>FS: readJson(node_modules/pkg/package.json)
FS-->>Npm: { bin: string | Record }
Npm-->>Caller: binDir/resolvedName
else no files
Npm->>FS: rm(package-lock.json)
Npm->>Npm: add(pkg)
Note over Npm,Arborist: Npm.add(pkg)
Npm->>Lock: write(npm-install:pkg)
Npm->>Arborist: loadVirtual()
alt lockfile exists & node in tree
Arborist-->>Npm: tree (early return)
Npm-->>Caller: first.path ⚠️ no disk check
else fresh install
Npm->>Arborist: reify({add:[pkg]})
Arborist->>Registry: fetch package
Registry-->>Arborist: tarball
Arborist->>FS: extract to cache/packages/pkg/
Arborist-->>Npm: result tree
Npm-->>Caller: first.path
end
end
Note over Caller,FS: Npm.install(dir)
Caller->>Npm: install(dir)
Npm->>Lock: write(npm-install:dir)
Npm->>FS: exists(node_modules)
alt node_modules missing
Npm->>Arborist: reify() [errors silently swallowed]
else check lock vs package.json
Npm->>FS: readJson(package.json + package-lock.json)
alt dependency not in lockfile
Npm->>Arborist: reify() [errors silently swallowed]
end
end
Last reviewed commit: "fix: force reinstall..." |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
4dd891c to
d5bb559
Compare
d5bb559 to
ca2099e
Compare
|
@greptile try again |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Use npm-install:${pkg} instead of a global npm-install lock so
concurrent installs of different packages can run in parallel.
When the lockfile exists but .bin is empty or absent, add() would read the lockfile via loadVirtual() and return early without calling reify(). Delete the lockfile before calling add() so it proceeds with a full install.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Replace tsx dependency with explicit 'node' invocation for the compiled ESLint server. Remove all BUN_BE_BUN env var references which are no longer needed after the Bun-to-Node migration.
…interface The formatter Info interface uses enabled(): Promise<string[] | false> but user configs provide a command property. Added explicit return type to the arrow function that transforms command into the enabled() return value. Also added test to verify custom formatters with command property work.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Multiple binaries — resolve from package.json bin field like npx does | ||
| const pkgJson = await Filesystem.readJson<{ bin?: string | Record<string, string> }>( | ||
| path.join(dir, "node_modules", pkg, "package.json"), | ||
| ).catch(() => undefined) | ||
| if (pkgJson?.bin) { | ||
| const unscoped = pkg.startsWith("@") ? pkg.split("/")[1] : pkg | ||
| const bin = pkgJson.bin | ||
| if (typeof bin === "string") return unscoped | ||
| const keys = Object.keys(bin) | ||
| if (keys.length === 1) return keys[0] | ||
| return bin[unscoped] ? unscoped : keys[0] | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
unscoped referenced before its const declaration (TDZ ReferenceError)
On line 163 return unscoped references a variable that is declared with const on line 166. In JavaScript/TypeScript, const bindings are in the Temporal Dead Zone until their declaration is reached, so accessing unscoped here throws a ReferenceError at runtime.
This means Npm.which() will always crash for any installed package whose package.json declares bin as a bare string (e.g., "bin": "./cli.js") when the .bin directory contains more than one file.
| // Multiple binaries — resolve from package.json bin field like npx does | |
| const pkgJson = await Filesystem.readJson<{ bin?: string | Record<string, string> }>( | |
| path.join(dir, "node_modules", pkg, "package.json"), | |
| ).catch(() => undefined) | |
| if (pkgJson?.bin) { | |
| const unscoped = pkg.startsWith("@") ? pkg.split("/")[1] : pkg | |
| const bin = pkgJson.bin | |
| if (typeof bin === "string") return unscoped | |
| const keys = Object.keys(bin) | |
| if (keys.length === 1) return keys[0] | |
| return bin[unscoped] ? unscoped : keys[0] | |
| } | |
| if (pkgJson?.bin) { | |
| const bin = pkgJson.bin | |
| const unscoped = pkg.startsWith("@") ? pkg.split("/")[1] : pkg | |
| if (typeof bin === "string") return unscoped | |
| const keys = Object.keys(bin) | |
| if (keys.length === 1) return keys[0] | |
| return bin[unscoped] ? unscoped : keys[0] | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return [await Npm.which("oxfmt"), "$FILE"] | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Npm.which("oxfmt") can throw uncaught inside enabled()
Unlike the prettier formatter (which wraps Npm.which in .catch(() => null)), oxfmt.enabled() calls await Npm.which("oxfmt") without any error handling. If the package fails to install (network error, InstallFailedError, etc.) the exception propagates up through isEnabled() in format/index.ts and breaks all subsequent formatting for the session.
| return [await Npm.which("oxfmt"), "$FILE"] | |
| } | |
| } | |
| return [await Npm.which("oxfmt").catch(() => null) ?? "", "$FILE"] |
Or better, bail out early if which fails:
const bin = await Npm.which("oxfmt").catch(() => null) if (!bin) return false return [bin, "$FILE"]
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR cannot be merged into the beta branch due to: Merge conflicts with dev branch Please resolve this issue to include this PR in the next beta release. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR cannot be merged into the beta branch due to: Merge conflicts with dev branch Please resolve this issue to include this PR in the next beta release. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR cannot be merged into the beta branch due to: Merge conflicts with dev branch Please resolve this issue to include this PR in the next beta release. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR cannot be merged into the beta branch due to: Merge conflicts with dev branch Please resolve this issue to include this PR in the next beta release. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
# Conflicts: # packages/opencode/src/bun/index.ts # packages/opencode/test/bun.test.ts
…st.ts - update resolvePluginTarget to use Npm.add instead of Npm.install - replace BunProc.install with Npm.add in provider.ts - update all tests to use Npm.add/Npm.install instead of BunProc
…tatic import instead of dynamic import
…ackage.json Npm.add was returning the package directory path, but dynamic import() requires the actual entry file path. Added resolveEntryPoint helper to read package.json and resolve the correct ESM entry point (via exports.import, module, or main fields) before returning the path.
…t from package.json" This reverts commit 0a8e3df.
Changed Npm.add() to return an object with both the package directory and resolved entrypoint. This allows callers to choose which they need - plugins use the directory for path resolution while providers use the entrypoint for loading.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.