/** * after-pack.cjs * * electron-builder afterPack hook. * * Problem: electron-builder respects .gitignore when copying extraResources. * Since .gitignore contains "node_modules/", the openclaw bundle's * node_modules directory is silently skipped during the extraResources copy. * * Solution: This hook runs AFTER electron-builder finishes packing. It manually * copies build/openclaw/node_modules/ into the output resources directory, * bypassing electron-builder's glob filtering entirely. */ const { cpSync, existsSync, readdirSync } = require('fs'); const { join } = require('path'); exports.default = async function afterPack(context) { const appOutDir = context.appOutDir; const platform = context.electronPlatformName; // 'win32' | 'darwin' | 'linux' const src = join(__dirname, '..', 'build', 'openclaw', 'node_modules'); // On macOS, resources live inside the .app bundle let resourcesDir; if (platform === 'darwin') { const appName = context.packager.appInfo.productFilename; resourcesDir = join(appOutDir, `${appName}.app`, 'Contents', 'Resources'); } else { resourcesDir = join(appOutDir, 'resources'); } const dest = join(resourcesDir, 'openclaw', 'node_modules'); if (!existsSync(src)) { console.warn('[after-pack] ⚠️ build/openclaw/node_modules not found. Run "pnpm run bundle:openclaw" first.'); return; } const depCount = readdirSync(src, { withFileTypes: true }) .filter(d => d.isDirectory() && d.name !== '.bin') .length; console.log(`[after-pack] Copying ${depCount} openclaw dependencies to ${dest} ...`); cpSync(src, dest, { recursive: true }); console.log('[after-pack] ✅ openclaw node_modules copied successfully.'); };