feat: prepare Zhinian desktop pilot
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-05-07 21:49:20 +08:00
parent cddaf37016
commit 0abc48189c
103 changed files with 10975 additions and 2049 deletions

View File

@@ -199,6 +199,46 @@ function cleanupNativePlatformPackages(nodeModulesDir, platform, arch) {
return removed;
}
function removeOptionalNativeClipboard(nodeModulesDir) {
const scopeDir = join(nodeModulesDir, '@mariozechner');
if (!existsSync(scopeDir)) return 0;
let removed = 0;
for (const entry of readdirSync(scopeDir)) {
if (entry === 'clipboard' || entry.startsWith('clipboard-')) {
try {
rmSync(join(scopeDir, entry), { recursive: true, force: true });
removed++;
} catch { /* */ }
}
}
return removed;
}
function copyNianxxPlayNodeModules(resourcesDir, platform, arch) {
const src = join(__dirname, '..', 'build', 'apps', 'nianxx-play', 'node_modules');
const nianxxPlayRoot = join(resourcesDir, 'resources', 'nianxx-play');
const dest = join(nianxxPlayRoot, 'node_modules');
if (!existsSync(nianxxPlayRoot)) return;
if (!existsSync(src)) {
console.warn('[after-pack] ⚠️ build/apps/nianxx-play/node_modules not found. Run prepare:nianxx-play first.');
return;
}
const depCount = readdirSync(src, { withFileTypes: true })
.filter(d => d.isDirectory() && d.name !== '.bin')
.length;
console.log(`[after-pack] Copying ${depCount} NianxxPlay dependencies to ${dest} ...`);
rmSync(dest, { recursive: true, force: true });
cpSync(src, dest, { recursive: true, dereference: true });
cleanupUnnecessaryFiles(dest);
cleanupKoffi(dest, platform, arch);
cleanupNativePlatformPackages(dest, platform, arch);
console.log('[after-pack] ✅ NianxxPlay node_modules copied.');
}
// ── Broken module patcher ─────────────────────────────────────────────────────
// Some bundled packages have transpiled CJS that sets `module.exports = exports.default`
// without ever assigning `exports.default`, leaving module.exports === undefined.
@@ -371,13 +411,10 @@ function patchBrokenModules(nodeModulesDir) {
}
// ── Plugin ID mismatch patcher ───────────────────────────────────────────────
// Some plugins (e.g. wecom) have a compiled JS entry that hardcodes a different
// ID than what openclaw.plugin.json declares. The Gateway rejects mismatches,
// so we fix them after copying.
// Some plugins have a compiled JS entry that hardcodes a different ID than what
// openclaw.plugin.json declares. Keep this hook for future bundled plugins.
const PLUGIN_ID_FIXES = {
'wecom-openclaw-plugin': 'wecom',
};
const PLUGIN_ID_FIXES = {};
function patchPluginIds(pluginDir, expectedId) {
const { readFileSync, writeFileSync } = require('fs');
@@ -563,6 +600,15 @@ exports.default = async function afterPack(context) {
cpSync(src, dest, { recursive: true });
console.log('[after-pack] ✅ openclaw node_modules copied.');
const clipboardRemoved = removeOptionalNativeClipboard(dest);
if (clipboardRemoved > 0) {
console.log(`[after-pack] ✅ Removed optional native clipboard packages (${clipboardRemoved}) to avoid macOS Gatekeeper prompts.`);
}
// 1.0 Copy bundled large-app runtime deps that electron-builder skips because
// node_modules/ is ignored globally.
copyNianxxPlayNodeModules(resourcesDir, platform, arch);
// Patch broken modules whose CJS transpiled output sets module.exports = undefined,
// causing TypeError in Node.js 22+ ESM interop.
patchBrokenModules(dest);
@@ -573,9 +619,6 @@ exports.default = async function afterPack(context) {
// directory doesn't exist (build/openclaw-plugins/ may not be pre-generated)
// - node_modules/ is excluded by .gitignore so the deps copy must be manual
const BUNDLED_PLUGINS = [
{ npmName: '@soimy/dingtalk', pluginId: 'dingtalk' },
{ npmName: '@wecom/wecom-openclaw-plugin', pluginId: 'wecom' },
{ npmName: '@larksuite/openclaw-lark', pluginId: 'feishu-openclaw-plugin' },
{ npmName: '@tencent-weixin/openclaw-weixin', pluginId: 'openclaw-weixin' },
];