Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ win:
- target: nsis
arch:
- x64
- target: nsis
arch:
- arm64

nsis:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"@whiskeysockets/baileys",
"electron",
"esbuild",
"node-llama-cpp",
"protobufjs",
"sharp"
]
Expand Down
41 changes: 41 additions & 0 deletions scripts/after-pack.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const PLATFORM_NATIVE_SCOPES = {
'@napi-rs': /^canvas-(darwin|linux|win32)-(x64|arm64)/,
'@img': /^sharp(?:-libvips)?-(darwin|linux|win32)-(x64|arm64)/,
'@mariozechner': /^clipboard-(darwin|linux|win32)-(x64|arm64|universal)/,
'@lydell': /^node-pty-(darwin|linux|win32)-(x64|arm64)/,
};

function cleanupNativePlatformPackages(nodeModulesDir, platform, arch) {
Expand Down Expand Up @@ -128,6 +129,40 @@ function cleanupNativePlatformPackages(nodeModulesDir, platform, arch) {
return removed;
}

// ── Platform-specific: @node-llama-cpp ────────────────────────────────────────
// node-llama-cpp is excluded from the bundle by bundle-openclaw.mjs, but this
// cleanup acts as a safety net in case it ever gets included.
// Package naming: {platform}-{arch}[-variant] where platform is mac|linux|win
// (different from electron's darwin|linux|win32).

const LLAMA_PLATFORM_MAP = { darwin: 'mac', linux: 'linux', win32: 'win' };
const LLAMA_PKG_PATTERN = /^(mac|linux|win)-(x64|arm64|armv7l)(?:-.+)?$/;

function cleanupNodeLlamaCpp(nodeModulesDir, platform, arch) {
const scopeDir = join(nodeModulesDir, '@node-llama-cpp');
if (!existsSync(scopeDir)) return 0;

const llamaPlatform = LLAMA_PLATFORM_MAP[platform] || platform;
let removed = 0;

for (const entry of readdirSync(scopeDir)) {
const match = entry.match(LLAMA_PKG_PATTERN);
if (!match) continue;

const pkgPlatform = match[1];
const pkgArch = match[2];

if (pkgPlatform !== llamaPlatform || pkgArch !== arch) {
try {
rmSync(join(scopeDir, entry), { recursive: true, force: true });
removed++;
} catch { /* */ }
}
}

return removed;
}

// ── Main hook ────────────────────────────────────────────────────────────────

exports.default = async function afterPack(context) {
Expand Down Expand Up @@ -180,4 +215,10 @@ exports.default = async function afterPack(context) {
if (nativeRemoved > 0) {
console.log(`[after-pack] ✅ Removed ${nativeRemoved} non-target native platform packages.`);
}

// 5. Platform-specific: strip wrong-platform/arch @node-llama-cpp packages
const llamaRemoved = cleanupNodeLlamaCpp(dest, platform, arch);
if (llamaRemoved > 0) {
console.log(`[after-pack] ✅ @node-llama-cpp: removed ${llamaRemoved} non-target packages (kept ${LLAMA_PLATFORM_MAP[platform] || platform}-${arch}*).`);
}
};
8 changes: 6 additions & 2 deletions scripts/bundle-openclaw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ const SKIP_PACKAGES = new Set([
'typescript',
'playwright-core',
'@playwright/test',
// node-llama-cpp is an optional peer dep of openclaw used only for local
// embedding generation. It adds ~700 MB of CUDA/Vulkan/Metal binaries.
// ClawX users rely on remote embedding providers (OpenAI, Gemini, etc.)
// and openclaw gracefully handles the missing dependency at runtime.
'node-llama-cpp',
]);
const SKIP_SCOPES = ['@cloudflare/', '@types/'];
const SKIP_SCOPES = ['@cloudflare/', '@types/', '@node-llama-cpp/'];
let skippedDevCount = 0;

while (queue.length > 0) {
Expand Down Expand Up @@ -330,7 +335,6 @@ function cleanupBundle(outputDir) {
const LARGE_REMOVALS = [
'node_modules/pdfjs-dist/legacy',
'node_modules/pdfjs-dist/types',
'node_modules/node-llama-cpp/llama',
'node_modules/koffi/src',
'node_modules/koffi/vendor',
'node_modules/koffi/doc',
Expand Down