Skip to content

Commit 4862d34

Browse files
committed
fix: package plugin SDK alias wrappers
1 parent e39af95 commit 4862d34

2 files changed

Lines changed: 53 additions & 10 deletions

File tree

scripts/stage-bundled-plugin-runtime.mjs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,17 @@ function ensureOpenClawExtensionAlias(params) {
111111
"./plugin-sdk/*": "./plugin-sdk/*.js",
112112
},
113113
});
114-
ensureSymlink(
115-
relativeSymlinkTarget(pluginSdkDir, pluginSdkAliasPath),
116-
pluginSdkAliasPath,
117-
symlinkType(),
118-
pluginSdkDir,
119-
);
114+
removePathIfExists(pluginSdkAliasPath);
115+
fs.mkdirSync(pluginSdkAliasPath, { recursive: true });
116+
for (const dirent of fs.readdirSync(pluginSdkDir, { withFileTypes: true })) {
117+
if (!dirent.isFile() || path.extname(dirent.name) !== ".js") {
118+
continue;
119+
}
120+
writeRuntimeModuleWrapper(
121+
path.join(pluginSdkDir, dirent.name),
122+
path.join(pluginSdkAliasPath, dirent.name),
123+
);
124+
}
120125
}
121126

122127
function shouldWrapRuntimeJsFile(sourcePath) {

src/plugins/stage-bundled-plugin-runtime.test.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ describe("stageBundledPluginRuntime", () => {
8585
recursive: true,
8686
});
8787
setupRepoFiles(repoRoot, {
88+
"dist/plugin-sdk/index.js": "export const sdk = true;\n",
89+
"dist/plugin-sdk/channel-entry-contract.js":
90+
"export { contract } from '../channel-entry-contract-abc.js';\n",
91+
"dist/channel-entry-contract-abc.js": "export const contract = true;\n",
8892
[bundledDistPluginFile("diffs", "index.js")]: "export default {}\n",
8993
[bundledDistPluginFile("diffs", "node_modules/@pierre/diffs/index.js")]:
9094
"export default {}\n",
@@ -109,7 +113,7 @@ describe("stageBundledPluginRuntime", () => {
109113
path.join(repoRoot, "dist", "extensions", "node_modules", "openclaw", "plugin-sdk"),
110114
)
111115
.isSymbolicLink(),
112-
).toBe(true);
116+
).toBe(false);
113117
expect(
114118
fs.readFileSync(
115119
path.join(repoRoot, "dist", "extensions", "node_modules", "openclaw", "package.json"),
@@ -123,13 +127,47 @@ describe("stageBundledPluginRuntime", () => {
123127
),
124128
).toContain('"./plugin-sdk/*": "./plugin-sdk/*.js"');
125129
expect(
126-
fs.realpathSync(
127-
path.join(repoRoot, "dist", "extensions", "node_modules", "openclaw", "plugin-sdk"),
130+
fs.readFileSync(
131+
path.join(
132+
repoRoot,
133+
"dist",
134+
"extensions",
135+
"node_modules",
136+
"openclaw",
137+
"plugin-sdk",
138+
"channel-entry-contract.js",
139+
),
140+
"utf8",
128141
),
129-
).toBe(fs.realpathSync(path.join(repoRoot, "dist", "plugin-sdk")));
142+
).toContain("../../../../plugin-sdk/channel-entry-contract.js");
130143
expect(fs.existsSync(path.join(runtimePluginDir, "node_modules", "openclaw"))).toBe(false);
131144
});
132145

146+
it("keeps extension-local plugin-sdk wrappers resolving canonical dist chunks", async () => {
147+
const repoRoot = makeRepoRoot("openclaw-stage-bundled-runtime-sdk-wrapper-");
148+
createDistPluginDir(repoRoot, "diffs");
149+
setupRepoFiles(repoRoot, {
150+
"dist/plugin-sdk/channel-entry-contract.js":
151+
"export { contract } from '../channel-entry-contract-abc.js';\n",
152+
"dist/channel-entry-contract-abc.js": "export const contract = true;\n",
153+
[bundledDistPluginFile("diffs", "index.js")]: "export default {}\n",
154+
});
155+
156+
stageBundledPluginRuntime({ repoRoot });
157+
158+
const wrapperPath = path.join(
159+
repoRoot,
160+
"dist",
161+
"extensions",
162+
"node_modules",
163+
"openclaw",
164+
"plugin-sdk",
165+
"channel-entry-contract.js",
166+
);
167+
const wrapperModule = await import(`${pathToFileURL(wrapperPath).href}?t=${Date.now()}`);
168+
expect(wrapperModule.contract).toBe(true);
169+
});
170+
133171
it("writes wrappers that forward plugin entry imports into canonical dist files", async () => {
134172
const repoRoot = makeRepoRoot("openclaw-stage-bundled-runtime-chunks-");
135173
createDistPluginDir(repoRoot, "diffs");

0 commit comments

Comments
 (0)