From 4862d349257a796f0519e5eaa17975ddc0167917 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 19 Apr 2026 02:28:28 +0100 Subject: [PATCH] fix: package plugin SDK alias wrappers --- scripts/stage-bundled-plugin-runtime.mjs | 17 ++++--- .../stage-bundled-plugin-runtime.test.ts | 46 +++++++++++++++++-- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/scripts/stage-bundled-plugin-runtime.mjs b/scripts/stage-bundled-plugin-runtime.mjs index 65531b75fae..59d7f7e7051 100644 --- a/scripts/stage-bundled-plugin-runtime.mjs +++ b/scripts/stage-bundled-plugin-runtime.mjs @@ -111,12 +111,17 @@ function ensureOpenClawExtensionAlias(params) { "./plugin-sdk/*": "./plugin-sdk/*.js", }, }); - ensureSymlink( - relativeSymlinkTarget(pluginSdkDir, pluginSdkAliasPath), - pluginSdkAliasPath, - symlinkType(), - pluginSdkDir, - ); + removePathIfExists(pluginSdkAliasPath); + fs.mkdirSync(pluginSdkAliasPath, { recursive: true }); + for (const dirent of fs.readdirSync(pluginSdkDir, { withFileTypes: true })) { + if (!dirent.isFile() || path.extname(dirent.name) !== ".js") { + continue; + } + writeRuntimeModuleWrapper( + path.join(pluginSdkDir, dirent.name), + path.join(pluginSdkAliasPath, dirent.name), + ); + } } function shouldWrapRuntimeJsFile(sourcePath) { diff --git a/src/plugins/stage-bundled-plugin-runtime.test.ts b/src/plugins/stage-bundled-plugin-runtime.test.ts index ff6c7aa30ee..7af5ad29bfc 100644 --- a/src/plugins/stage-bundled-plugin-runtime.test.ts +++ b/src/plugins/stage-bundled-plugin-runtime.test.ts @@ -85,6 +85,10 @@ describe("stageBundledPluginRuntime", () => { recursive: true, }); setupRepoFiles(repoRoot, { + "dist/plugin-sdk/index.js": "export const sdk = true;\n", + "dist/plugin-sdk/channel-entry-contract.js": + "export { contract } from '../channel-entry-contract-abc.js';\n", + "dist/channel-entry-contract-abc.js": "export const contract = true;\n", [bundledDistPluginFile("diffs", "index.js")]: "export default {}\n", [bundledDistPluginFile("diffs", "node_modules/@pierre/diffs/index.js")]: "export default {}\n", @@ -109,7 +113,7 @@ describe("stageBundledPluginRuntime", () => { path.join(repoRoot, "dist", "extensions", "node_modules", "openclaw", "plugin-sdk"), ) .isSymbolicLink(), - ).toBe(true); + ).toBe(false); expect( fs.readFileSync( path.join(repoRoot, "dist", "extensions", "node_modules", "openclaw", "package.json"), @@ -123,13 +127,47 @@ describe("stageBundledPluginRuntime", () => { ), ).toContain('"./plugin-sdk/*": "./plugin-sdk/*.js"'); expect( - fs.realpathSync( - path.join(repoRoot, "dist", "extensions", "node_modules", "openclaw", "plugin-sdk"), + fs.readFileSync( + path.join( + repoRoot, + "dist", + "extensions", + "node_modules", + "openclaw", + "plugin-sdk", + "channel-entry-contract.js", + ), + "utf8", ), - ).toBe(fs.realpathSync(path.join(repoRoot, "dist", "plugin-sdk"))); + ).toContain("../../../../plugin-sdk/channel-entry-contract.js"); expect(fs.existsSync(path.join(runtimePluginDir, "node_modules", "openclaw"))).toBe(false); }); + it("keeps extension-local plugin-sdk wrappers resolving canonical dist chunks", async () => { + const repoRoot = makeRepoRoot("openclaw-stage-bundled-runtime-sdk-wrapper-"); + createDistPluginDir(repoRoot, "diffs"); + setupRepoFiles(repoRoot, { + "dist/plugin-sdk/channel-entry-contract.js": + "export { contract } from '../channel-entry-contract-abc.js';\n", + "dist/channel-entry-contract-abc.js": "export const contract = true;\n", + [bundledDistPluginFile("diffs", "index.js")]: "export default {}\n", + }); + + stageBundledPluginRuntime({ repoRoot }); + + const wrapperPath = path.join( + repoRoot, + "dist", + "extensions", + "node_modules", + "openclaw", + "plugin-sdk", + "channel-entry-contract.js", + ); + const wrapperModule = await import(`${pathToFileURL(wrapperPath).href}?t=${Date.now()}`); + expect(wrapperModule.contract).toBe(true); + }); + it("writes wrappers that forward plugin entry imports into canonical dist files", async () => { const repoRoot = makeRepoRoot("openclaw-stage-bundled-runtime-chunks-"); createDistPluginDir(repoRoot, "diffs");