收口 Makelore 客户端变更
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-08-12 22:35:06 +08:00
parent 253bad8b40
commit f4113a872f
232 changed files with 4617 additions and 20121 deletions

View File

@@ -1,5 +1,6 @@
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { existsSync, readFileSync, realpathSync } from 'node:fs';
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
export interface RuntimePathInput {
isPackaged: boolean;
@@ -47,11 +48,31 @@ function getNativeOpencodeBinName(platform: NodeJS.Platform): string {
return platform === 'win32' ? 'opencode.exe' : 'opencode';
}
function resolveDevelopmentNativeBinPath(input: RuntimePathInput): string | undefined {
function resolveNativePackageRoot(runtimeDir: string, packageName: string): string | undefined {
try {
const resolvedRuntimeDir = realpathSync(runtimeDir);
const runtimeRequire = createRequire(join(resolvedRuntimeDir, 'package.json'));
return dirname(runtimeRequire.resolve(`${packageName}/package.json`));
} catch {
return undefined;
}
}
function resolveDevelopmentNativeBinPath(
input: RuntimePathInput,
runtimeDir: string,
): string | undefined {
const arch = input.arch ?? process.arch;
for (const packageName of getDevelopmentNativePackageCandidates(input.platform, arch)) {
const binPath = join(input.appPath, 'node_modules', packageName, 'bin', getNativeOpencodeBinName(input.platform));
if (existsSync(binPath)) return binPath;
const binaryName = getNativeOpencodeBinName(input.platform);
const hoistedBinPath = join(input.appPath, 'node_modules', packageName, 'bin', binaryName);
if (existsSync(hoistedBinPath)) return hoistedBinPath;
const nativePackageRoot = resolveNativePackageRoot(runtimeDir, packageName);
if (!nativePackageRoot) continue;
const virtualStoreBinPath = join(nativePackageRoot, 'bin', binaryName);
if (existsSync(virtualStoreBinPath)) return virtualStoreBinPath;
}
return undefined;
}
@@ -73,7 +94,7 @@ export function resolveOpencodeRuntimePaths(input: RuntimePathInput): OpencodeRu
: join(input.appPath, 'node_modules', OPENCODE_RUNTIME_PACKAGE);
const developmentNativeBinPath = input.isPackaged
? undefined
: resolveDevelopmentNativeBinPath(input);
: resolveDevelopmentNativeBinPath(input, runtimeDir);
return {
runtimeDir,