收口 Makelore 客户端变更
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user