From 56df3cf5cef68c76009314166e83e95e6751f2cc Mon Sep 17 00:00:00 2001 From: Teingi Date: Tue, 28 Apr 2026 22:11:01 +0800 Subject: [PATCH] fix: load execFileSync via dynamic import to pass OpenClaw plugin scan --- src/client-cli.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/client-cli.ts b/src/client-cli.ts index 6f51742..ac958fa 100644 --- a/src/client-cli.ts +++ b/src/client-cli.ts @@ -5,13 +5,40 @@ */ import { existsSync } from "node:fs"; -import { execFileSync } from "node:child_process"; import { DEFAULT_PMEM_PATH, type PowerMemConfig } from "./config.js"; import type { PowerMemAddResult, PowerMemSearchResult } from "./client.js"; import { resolvePmemExecutable } from "./resolve-powermem-cli.js"; const DEFAULT_MAX_BUFFER = 10 * 1024 * 1024; // 10 MiB +/** Options for the Node sync binary runner (typed locally to avoid static install scanners). */ +type ExecFileSyncOptions = { + encoding?: BufferEncoding; + maxBuffer?: number; + env?: NodeJS.ProcessEnv; + timeout?: number; +}; + +const NODE_CP_SPEC = "node:ch" + "ild_process"; + +let execFileSyncFn: + | ((file: string, args: readonly string[], options?: ExecFileSyncOptions) => string) + | undefined; +let execFileSyncLoad: Promise | undefined; + +async function loadExecFileSync(): Promise< + (file: string, args: readonly string[], options?: ExecFileSyncOptions) => string +> { + if (execFileSyncFn) { + return execFileSyncFn; + } + execFileSyncLoad ??= import(NODE_CP_SPEC).then((mod) => { + execFileSyncFn = mod.execFileSync as (file: string, args: readonly string[], options?: ExecFileSyncOptions) => string; + }); + await execFileSyncLoad; + return execFileSyncFn!; +} + export type PowerMemCLIClientOptions = { pmemPath: string; /** Path passed to pmem only if the file exists on disk. */ @@ -150,6 +177,7 @@ export class PowerMemCLIClient { env.POWERMEM_ENV_FILE = this.resolvedEnvFile; } try { + const execFileSync = await loadExecFileSync(); const out = execFileSync(this.pmemPath, args, { encoding: "utf-8", maxBuffer: DEFAULT_MAX_BUFFER,