Skip to content

Commit 121695d

Browse files
authored
fix(install): handle postinstall node_modules cleanup and remove stale contextEngine slot (#1399)
## Summary - **Remove stale `contextEngine` slot**: The install scripts no longer write `plugins.slots.contextEngine` into `openclaw.json`. Instead, they clean up this deprecated field left by previous versions. - **Handle postinstall `node_modules` cleanup**: After `npm install`, if `node_modules` was emptied by a postinstall hook (e.g. during version upgrade), the scripts automatically re-run `npm install`. ## Changed files - `apps/memos-local-openclaw/install.sh` - `apps/memos-local-openclaw/install.ps1` ## Test plan - [ ] Run `bash install.sh --version <version>` on macOS/Linux, verify plugin installs correctly - [ ] Run `install.ps1 --version <version>` on Windows, verify plugin installs correctly - [ ] Verify `openclaw.json` no longer contains `plugins.slots.contextEngine` after installation - [ ] Simulate postinstall clearing `node_modules` — confirm the re-install logic triggers Made with [Cursor](https://cursor.com)
2 parents 245aef4 + ac01aa6 commit 121695d

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

apps/memos-local-openclaw/install.ps1

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ if (!config.plugins.allow.includes(pluginId)) {
184184
config.plugins.allow.push(pluginId);
185185
}
186186
187-
if (!config.plugins.slots || typeof config.plugins.slots !== "object") {
188-
config.plugins.slots = {};
187+
// Clean up stale contextEngine slot from previous versions
188+
if (config.plugins.slots && config.plugins.slots.contextEngine) {
189+
delete config.plugins.slots.contextEngine;
190+
if (Object.keys(config.plugins.slots).length === 0) {
191+
delete config.plugins.slots;
192+
}
189193
}
190-
config.plugins.slots.contextEngine = "memos-local-openclaw-plugin";
191194
192195
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
193196
'@
@@ -298,6 +301,20 @@ finally {
298301
Pop-Location
299302
}
300303

304+
$nodeModulesDir = Join-Path $ExtensionDir "node_modules"
305+
if (-not (Test-Path $nodeModulesDir) -or @(Get-ChildItem -Path $nodeModulesDir -ErrorAction SilentlyContinue).Count -eq 0) {
306+
Write-Warn "node_modules was cleaned by postinstall (version upgrade detected), re-installing..."
307+
Push-Location $ExtensionDir
308+
try {
309+
$env:MEMOS_SKIP_SETUP = "1"
310+
& npm install --omit=dev --no-fund --no-audit --loglevel=error 2>&1
311+
}
312+
finally {
313+
Remove-Item Env:\MEMOS_SKIP_SETUP -ErrorAction SilentlyContinue
314+
Pop-Location
315+
}
316+
}
317+
301318
if (-not (Test-Path $ExtensionDir)) {
302319
Write-Err "Plugin directory not found after install: $ExtensionDir"
303320
exit 1

apps/memos-local-openclaw/install.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ if (!config.plugins.allow.includes(pluginId)) {
246246
config.plugins.allow.push(pluginId);
247247
}
248248
249-
if (!config.plugins.slots || typeof config.plugins.slots !== 'object') {
250-
config.plugins.slots = {};
249+
// Clean up stale contextEngine slot from previous versions
250+
if (config.plugins.slots && config.plugins.slots.contextEngine) {
251+
delete config.plugins.slots.contextEngine;
252+
if (Object.keys(config.plugins.slots).length === 0) {
253+
delete config.plugins.slots;
254+
}
251255
}
252-
config.plugins.slots.contextEngine = 'memos-local-openclaw-plugin';
253256
254257
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
255258
NODE
@@ -305,6 +308,14 @@ info "Install dependencies, 安装依赖..."
305308
MEMOS_SKIP_SETUP=1 npm install --omit=dev --no-fund --no-audit --loglevel=error 2>&1
306309
)
307310

311+
if [[ ! -d "${EXTENSION_DIR}/node_modules" ]] || [[ -z "$(ls -A "${EXTENSION_DIR}/node_modules" 2>/dev/null)" ]]; then
312+
warn "node_modules was cleaned by postinstall (version upgrade detected), re-installing..."
313+
(
314+
cd "${EXTENSION_DIR}"
315+
MEMOS_SKIP_SETUP=1 npm install --omit=dev --no-fund --no-audit --loglevel=error 2>&1
316+
)
317+
fi
318+
308319
if [[ ! -d "$EXTENSION_DIR" ]]; then
309320
error "Plugin directory not found after install, 安装后未找到插件目录: ${EXTENSION_DIR}"
310321
exit 1

0 commit comments

Comments
 (0)