feat: enhance after-pack script to copy OpenClaw runtime dependencies
- Added a new script `bundle-openclaw.mjs` to bundle OpenClaw runtime dependencies. - Updated `after-pack.cjs` to copy bundled OpenClaw runtime and its node_modules. - Improved cleanup of unnecessary development files in node_modules. - Adjusted paths for resources in the packaging process. style: update loading indicator styles in ChatHistoryPanel - Changed the border radius and padding for the loading indicator in ChatHistoryPanel. fix: improve ProvidersSection to handle provider account syncing - Added logic to sync model configuration to provider accounts. - Introduced error handling and loading states during the sync process. - Enhanced vendor resolution and account management logic. fix: fallback session handling in chat store - Implemented fallback session logic in loadSessions to ensure a valid session is always available on error.
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
* It handles:
|
||||
* 1. Copying and bundling electron/scripts/ directory
|
||||
* 2. Ensuring required dependencies (playwright, chromium-bidi, bytenode) are included
|
||||
* 3. Cleaning up unnecessary development files to reduce package size
|
||||
* 3. Copying bundled OpenClaw runtime dependencies that electron-builder may skip
|
||||
* 4. Cleaning up unnecessary development files to reduce package size
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
@@ -75,15 +76,65 @@ function cleanupNativePlatformPackages(nodeModulesDir, platform, arch) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function resolveResourcesDir(context) {
|
||||
if (context.electronPlatformName === 'darwin') {
|
||||
if (context.appOutDir.endsWith('.app')) {
|
||||
return path.join(context.appOutDir, 'Contents', 'Resources');
|
||||
}
|
||||
|
||||
const appName = context.packager?.appInfo?.productFilename || 'NIANXX';
|
||||
return path.join(context.appOutDir, `${appName}.app`, 'Contents', 'Resources');
|
||||
}
|
||||
|
||||
return path.join(context.appOutDir, 'resources');
|
||||
}
|
||||
|
||||
async function copyBundledOpenClaw(context) {
|
||||
const srcRoot = path.join(__dirname, '..', 'build', 'openclaw');
|
||||
if (!(await fs.pathExists(srcRoot))) {
|
||||
console.warn('[after-pack] build/openclaw not found. Run bundle-openclaw first.');
|
||||
return;
|
||||
}
|
||||
|
||||
const resourcesDir = resolveResourcesDir(context);
|
||||
const destRoot = path.join(resourcesDir, 'openclaw');
|
||||
const srcNodeModules = path.join(srcRoot, 'node_modules');
|
||||
const destNodeModules = path.join(destRoot, 'node_modules');
|
||||
|
||||
await fs.ensureDir(resourcesDir);
|
||||
|
||||
if (!(await fs.pathExists(destRoot))) {
|
||||
await fs.copy(srcRoot, destRoot, {
|
||||
filter: (src) => {
|
||||
const relative = path.relative(srcRoot, src);
|
||||
if (!relative) return true;
|
||||
return relative.split(path.sep)[0] !== 'node_modules';
|
||||
},
|
||||
});
|
||||
console.log('[after-pack] Copied bundled OpenClaw runtime root.');
|
||||
}
|
||||
|
||||
if (!(await fs.pathExists(srcNodeModules))) {
|
||||
console.warn('[after-pack] build/openclaw/node_modules not found. OpenClaw runtime will be incomplete.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(await fs.pathExists(destNodeModules))) {
|
||||
await fs.copy(srcNodeModules, destNodeModules);
|
||||
console.log('[after-pack] Copied bundled OpenClaw node_modules.');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async function afterPack(context) {
|
||||
const { appOutDir, electronPlatformName: platform, arch } = context;
|
||||
const resourcesDir = resolveResourcesDir(context);
|
||||
|
||||
console.log(`Running afterPack hook for ${platform}-${arch}`);
|
||||
console.log(`App output directory: ${appOutDir}`);
|
||||
|
||||
// 1. Handle electron/scripts/ directory
|
||||
const scriptsSrc = path.join(__dirname, '..', 'electron/scripts');
|
||||
const scriptsDest = path.join(appOutDir, 'resources', 'scripts');
|
||||
const scriptsDest = path.join(resourcesDir, 'scripts');
|
||||
|
||||
if (await fs.pathExists(scriptsSrc)) {
|
||||
await fs.ensureDir(scriptsDest);
|
||||
@@ -118,13 +169,15 @@ module.exports = async function afterPack(context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await copyBundledOpenClaw(context);
|
||||
|
||||
// 2. Ensure required dependencies are included
|
||||
// electron-builder may exclude some dependencies due to .gitignore rules
|
||||
|
||||
const ensureDependency = async (depName) => {
|
||||
const src = path.join(__dirname, '..', 'node_modules', depName);
|
||||
const dest = path.join(appOutDir, 'node_modules', depName);
|
||||
const dest = path.join(resourcesDir, 'node_modules', depName);
|
||||
|
||||
if (await fs.pathExists(src)) {
|
||||
await fs.ensureDir(path.dirname(dest));
|
||||
@@ -144,7 +197,7 @@ module.exports = async function afterPack(context) {
|
||||
|
||||
// 3. Clean up unnecessary development files from node_modules (skip if SKIP_AFTERPACK_CLEANUP is set)
|
||||
if (!process.env.SKIP_AFTERPACK_CLEANUP) {
|
||||
const nodeModulesDest = path.join(appOutDir, 'node_modules');
|
||||
const nodeModulesDest = path.join(resourcesDir, 'node_modules');
|
||||
if (await fs.pathExists(nodeModulesDest)) {
|
||||
console.log('Cleaning up development files in node_modules...');
|
||||
const removed = cleanupUnnecessaryFiles(nodeModulesDest);
|
||||
@@ -165,4 +218,4 @@ module.exports = async function afterPack(context) {
|
||||
// cleanupNativePlatformPackages(nodeModulesDest, platform, arch);
|
||||
|
||||
console.log('afterPack hook completed successfully');
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user