fix wecom channel (#530)
This commit is contained in:
committed by
GitHub
Unverified
parent
7e54aad9e6
commit
f1e2e9fa01
@@ -204,6 +204,48 @@ 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.
|
||||
|
||||
const PLUGIN_ID_FIXES = {
|
||||
'wecom-openclaw-plugin': 'wecom',
|
||||
};
|
||||
|
||||
function patchPluginIds(pluginDir, expectedId) {
|
||||
const { readFileSync, writeFileSync } = require('fs');
|
||||
|
||||
const pkgJsonPath = join(pluginDir, 'package.json');
|
||||
if (!existsSync(pkgJsonPath)) return;
|
||||
|
||||
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
||||
const entryFiles = [pkg.main, pkg.module].filter(Boolean);
|
||||
|
||||
for (const entry of entryFiles) {
|
||||
const entryPath = join(pluginDir, entry);
|
||||
if (!existsSync(entryPath)) continue;
|
||||
|
||||
let content = readFileSync(entryPath, 'utf8');
|
||||
let patched = false;
|
||||
|
||||
for (const [wrongId, correctId] of Object.entries(PLUGIN_ID_FIXES)) {
|
||||
if (correctId !== expectedId) continue;
|
||||
const pattern = new RegExp(`(\\bid\\s*:\\s*)(["'])${wrongId.replace(/-/g, '\\-')}\\2`, 'g');
|
||||
const replaced = content.replace(pattern, `$1$2${correctId}$2`);
|
||||
if (replaced !== content) {
|
||||
content = replaced;
|
||||
patched = true;
|
||||
console.log(`[after-pack] 🩹 Patching plugin ID in ${entry}: "${wrongId}" → "${correctId}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (patched) {
|
||||
writeFileSync(entryPath, content, 'utf8');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Plugin bundler ───────────────────────────────────────────────────────────
|
||||
// Bundles a single OpenClaw plugin (and its transitive deps) from node_modules
|
||||
// directly into the packaged resources directory. Mirrors the logic in
|
||||
@@ -383,6 +425,8 @@ exports.default = async function afterPack(context) {
|
||||
cleanupKoffi(pluginNM, platform, arch);
|
||||
cleanupNativePlatformPackages(pluginNM, platform, arch);
|
||||
}
|
||||
// Fix hardcoded plugin ID mismatches in compiled JS
|
||||
patchPluginIds(pluginDestDir, pluginId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,9 +171,68 @@ function bundleOnePlugin({ npmName, pluginId }) {
|
||||
throw new Error(`Missing openclaw.plugin.json in bundled plugin output: ${pluginId}`);
|
||||
}
|
||||
|
||||
// 4) Patch plugin ID mismatch: some npm packages hardcode a different ID in
|
||||
// their JS output than what openclaw.plugin.json declares. The Gateway
|
||||
// validates that these match, so we fix it post-copy.
|
||||
patchPluginId(outputDir, pluginId);
|
||||
|
||||
echo` ✅ ${pluginId}: copied ${copiedCount} deps (skipped dupes: ${skippedDupes})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch plugin entry JS files so the exported `id` matches openclaw.plugin.json.
|
||||
* Some plugins (e.g. wecom) ship with a hardcoded ID in their compiled output
|
||||
* that differs from the manifest, causing a Gateway "plugin id mismatch" error.
|
||||
*/
|
||||
function patchPluginId(pluginDir, expectedId) {
|
||||
const manifestPath = path.join(pluginDir, 'openclaw.plugin.json');
|
||||
if (!fs.existsSync(manifestPath)) return;
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
||||
const manifestId = manifest.id;
|
||||
if (manifestId !== expectedId) {
|
||||
echo` ⚠️ Manifest ID "${manifestId}" doesn't match expected "${expectedId}", skipping patch`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the package.json to find the main entry point
|
||||
const pkgJsonPath = path.join(pluginDir, 'package.json');
|
||||
if (!fs.existsSync(pkgJsonPath)) return;
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
||||
const entryFiles = [pkg.main, pkg.module].filter(Boolean);
|
||||
|
||||
// Known ID mismatches to patch. Keys are the wrong ID found in compiled JS,
|
||||
// values are the correct ID (must match openclaw.plugin.json).
|
||||
const ID_FIXES = {
|
||||
'wecom-openclaw-plugin': 'wecom',
|
||||
};
|
||||
|
||||
for (const entry of entryFiles) {
|
||||
const entryPath = path.join(pluginDir, entry);
|
||||
if (!fs.existsSync(entryPath)) continue;
|
||||
|
||||
let content = fs.readFileSync(entryPath, 'utf8');
|
||||
let patched = false;
|
||||
|
||||
for (const [wrongId, correctId] of Object.entries(ID_FIXES)) {
|
||||
if (correctId !== expectedId) continue;
|
||||
// Replace id: "wecom-openclaw-plugin" or id: 'wecom-openclaw-plugin'
|
||||
const pattern = new RegExp(`(\\bid\\s*:\\s*)(["'])${wrongId.replace(/-/g, '\\-')}\\2`, 'g');
|
||||
const replaced = content.replace(pattern, `$1$2${correctId}$2`);
|
||||
if (replaced !== content) {
|
||||
content = replaced;
|
||||
patched = true;
|
||||
echo` 🩹 Patching plugin ID in ${entry}: "${wrongId}" → "${correctId}"`;
|
||||
}
|
||||
}
|
||||
|
||||
if (patched) {
|
||||
fs.writeFileSync(entryPath, content, 'utf8');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo`📦 Bundling OpenClaw plugin mirrors...`;
|
||||
fs.mkdirSync(OUTPUT_ROOT, { recursive: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user