fix: package plugin SDK alias wrappers

This commit is contained in:
Peter Steinberger
2026-04-19 02:28:28 +01:00
parent e39af9545f
commit 4862d34925
2 changed files with 53 additions and 10 deletions

View File

@@ -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) {

View File

@@ -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");