Files
eranos/scripts/patch-cap-config.mjs
T
Alex Gleason 2dc28e98e6 Fix native SandboxPlugin registration on iOS/Android
Capacitor's JS proxy requires plugin headers exported at startup to
route calls to the native bridge. Without a header, calls short-circuit
to UNIMPLEMENTED entirely in JS, never reaching the native lazy-loader.

Since npx cap sync only discovers SPM-packaged plugins for
packageClassList, local plugins like SandboxPlugin are omitted.

Add scripts/patch-cap-config.mjs that appends local plugin class names
to capacitor.config.json after sync. Wire it into:
- npm run cap:sync (new convenience script)
- .gitlab-ci.yml build-apk job
2026-04-08 17:38:20 -05:00

50 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Patch capacitor.config.json to include local (non-SPM) plugin classes.
*
* `npx cap sync` regenerates the `packageClassList` array from SPM packages
* only, so local plugins compiled directly into the app binary (like
* SandboxPlugin) are not included. This script appends them after sync so
* the Capacitor bridge eagerly registers them at startup.
*
* Usage: node scripts/patch-cap-config.mjs
* Typically run after `npx cap sync`.
*/
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
/** Local plugin class names to ensure are registered. */
const LOCAL_PLUGINS = ['SandboxPlugin'];
const platforms = ['ios/App/App', 'android/app/src/main/assets'];
for (const platform of platforms) {
const configPath = resolve(platform, 'capacitor.config.json');
let config;
try {
config = JSON.parse(readFileSync(configPath, 'utf-8'));
} catch {
// Platform may not exist or config not yet generated — skip.
continue;
}
const classList = new Set(config.packageClassList ?? []);
let changed = false;
for (const plugin of LOCAL_PLUGINS) {
if (!classList.has(plugin)) {
classList.add(plugin);
changed = true;
}
}
if (changed) {
config.packageClassList = [...classList];
writeFileSync(configPath, JSON.stringify(config, null, '\t') + '\n');
console.log(`Patched ${configPath}: added ${LOCAL_PLUGINS.join(', ')}`);
}
}