Skip to content

Commit fe97be7

Browse files
DeJeuneclaude
andcommitted
refactor(openclaw): remove findNpmPath and hardcoded fallback paths
- Inline findNpmPath into its two call sites (install, uninstall) - Remove possiblePaths filesystem fallback from findOpenClawBinary — openclaw is installed via npm global, so it's always in PATH - findOpenClawBinary now delegates entirely to findExecutableInEnv Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 996daf6 commit fe97be7

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

src/main/services/OpenClawService.ts

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,6 @@ class OpenClawService {
228228
return 'https://git-scm.com/downloads'
229229
}
230230

231-
/**
232-
* Locate the npm binary in the user's shell environment.
233-
* Returns the resolved path, or 'npm' as a fallback for spawn.
234-
*/
235-
private async findNpmPath(): Promise<string> {
236-
const { path: npmPath } = await findExecutableInEnv('npm')
237-
return npmPath || 'npm'
238-
}
239-
240231
/**
241232
* Send install progress to renderer
242233
*/
@@ -255,7 +246,8 @@ class OpenClawService {
255246
const packageName = inChina ? '@qingchencloud/openclaw-zh@latest' : 'openclaw@latest'
256247
const registryArg = inChina ? `--registry=${NPM_MIRROR_CN}` : ''
257248

258-
const npmPath = await this.findNpmPath()
249+
const { path: npmPath_ } = await findExecutableInEnv('npm')
250+
const npmPath = npmPath_ || 'npm'
259251

260252
const npmArgs = ['install', '-g', packageName]
261253
if (registryArg) npmArgs.push(registryArg)
@@ -378,7 +370,8 @@ class OpenClawService {
378370
await this.stopGateway()
379371
}
380372

381-
const npmPath = await this.findNpmPath()
373+
const { path: npmPath_ } = await findExecutableInEnv('npm')
374+
const npmPath = npmPath_ || 'npm'
382375

383376
const npmArgs = ['uninstall', '-g', 'openclaw', '@qingchencloud/openclaw-zh']
384377

@@ -910,37 +903,9 @@ class OpenClawService {
910903
return []
911904
}
912905

913-
/**
914-
* Find OpenClaw binary in PATH or common locations
915-
* On Windows, npm global packages create .cmd wrapper scripts, not .exe files
916-
*/
917906
private async findOpenClawBinary(): Promise<string | null> {
918-
const home = os.homedir()
919-
920907
const { path: binaryPath } = await findExecutableInEnv('openclaw')
921-
if (binaryPath) {
922-
return binaryPath
923-
}
924-
925-
// Check common filesystem locations as fallback
926-
const binaryName = isWin ? 'openclaw.exe' : 'openclaw'
927-
const possiblePaths = isWin
928-
? [path.join(home, 'AppData', 'Local', 'openclaw', binaryName), path.join(home, '.openclaw', 'bin', binaryName)]
929-
: [
930-
path.join(home, '.openclaw', 'bin', binaryName),
931-
path.join(home, '.local', 'bin', binaryName),
932-
`/usr/local/bin/${binaryName}`,
933-
`/opt/homebrew/bin/${binaryName}`
934-
]
935-
936-
for (const p of possiblePaths) {
937-
if (fs.existsSync(p)) {
938-
logger.info('Found OpenClaw binary at: ' + p)
939-
return p
940-
}
941-
}
942-
943-
return null
908+
return binaryPath
944909
}
945910

946911
/**

0 commit comments

Comments
 (0)