fix(whats-app): resolve OpenClaw paths and package resolution (#33)
This commit is contained in:
committed by
GitHub
Unverified
parent
518b5f6323
commit
a5ba7512a3
@@ -5,6 +5,7 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, statSync, rmSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { getOpenClawResolvedDir } from './paths';
|
||||
|
||||
const OPENCLAW_DIR = join(homedir(), '.openclaw');
|
||||
const CONFIG_FILE = join(OPENCLAW_DIR, 'openclaw.json');
|
||||
@@ -494,8 +495,6 @@ async function validateTelegramCredentials(
|
||||
*/
|
||||
export async function validateChannelConfig(channelType: string): Promise<ValidationResult> {
|
||||
const { execSync } = await import('child_process');
|
||||
const { join } = await import('path');
|
||||
const { app } = await import('electron');
|
||||
|
||||
const result: ValidationResult = {
|
||||
valid: true,
|
||||
@@ -505,9 +504,7 @@ export async function validateChannelConfig(channelType: string): Promise<Valida
|
||||
|
||||
try {
|
||||
// Get OpenClaw path
|
||||
const openclawPath = app.isPackaged
|
||||
? join(process.resourcesPath, 'openclaw')
|
||||
: join(__dirname, '../../openclaw');
|
||||
const openclawPath = getOpenClawResolvedDir();
|
||||
|
||||
// Run openclaw doctor command to validate config
|
||||
const output = execSync(
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { app } from 'electron';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { existsSync, mkdirSync, readFileSync } from 'fs';
|
||||
import { existsSync, mkdirSync, readFileSync, realpathSync } from 'fs';
|
||||
import { logger } from './logger';
|
||||
|
||||
/**
|
||||
@@ -85,6 +85,22 @@ export function getOpenClawDir(): string {
|
||||
return join(__dirname, '../../node_modules/openclaw');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get OpenClaw package directory resolved to a real path.
|
||||
* Useful when consumers need deterministic module resolution under pnpm symlinks.
|
||||
*/
|
||||
export function getOpenClawResolvedDir(): string {
|
||||
const dir = getOpenClawDir();
|
||||
if (!existsSync(dir)) {
|
||||
return dir;
|
||||
}
|
||||
try {
|
||||
return realpathSync(dir);
|
||||
} catch {
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get OpenClaw entry script path (openclaw.mjs)
|
||||
*/
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
import { join, resolve } from 'path';
|
||||
import { dirname, join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { createRequire } from 'module';
|
||||
import { app } from 'electron';
|
||||
import { EventEmitter } from 'events';
|
||||
import { existsSync, mkdirSync, rmSync } from 'fs';
|
||||
import { deflateSync } from 'zlib';
|
||||
import { getOpenClawDir, getOpenClawResolvedDir } from './paths';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Resolve paths to dependencies in openclaw/node_modules
|
||||
const openclawPath = app.isPackaged
|
||||
? join(process.resourcesPath, 'openclaw')
|
||||
: resolve(__dirname, '../../openclaw');
|
||||
// Resolve dependencies from OpenClaw package context (pnpm-safe)
|
||||
const openclawPath = getOpenClawDir();
|
||||
const openclawResolvedPath = getOpenClawResolvedDir();
|
||||
const openclawRequire = createRequire(join(openclawResolvedPath, 'package.json'));
|
||||
|
||||
const baileysPath = resolve(openclawPath, 'node_modules', '@whiskeysockets', 'baileys');
|
||||
const qrcodeTerminalPath = resolve(openclawPath, 'node_modules', 'qrcode-terminal');
|
||||
function resolveOpenClawPackageJson(packageName: string): string {
|
||||
const specifier = `${packageName}/package.json`;
|
||||
try {
|
||||
return openclawRequire.resolve(specifier);
|
||||
} catch (err) {
|
||||
const reason = err instanceof Error ? err.message : String(err);
|
||||
throw new Error(
|
||||
`Failed to resolve "${packageName}" from OpenClaw context. ` +
|
||||
`openclawPath=${openclawPath}, resolvedPath=${openclawResolvedPath}. ${reason}`,
|
||||
{ cause: err }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const baileysPath = dirname(resolveOpenClawPackageJson('@whiskeysockets/baileys'));
|
||||
const qrcodeTerminalPath = dirname(resolveOpenClawPackageJson('qrcode-terminal'));
|
||||
|
||||
// Load Baileys dependencies dynamically
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user