mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:20:42 +00:00
fix: package plugin SDK alias wrappers
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user