mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:30:44 +00:00
fix(plugin-sdk): align root alias scoped sdk map
This commit is contained in:
@@ -7,6 +7,7 @@ let monolithicSdk = null;
|
||||
let diagnosticEventsModule = null;
|
||||
const jitiLoaders = new Map();
|
||||
const pluginSdkSubpathsCache = new Map();
|
||||
const pluginSdkPackageNames = ["openclaw/plugin-sdk", "@openclaw/plugin-sdk"];
|
||||
const isDistRootAlias = __filename.includes(
|
||||
`${path.sep}dist${path.sep}plugin-sdk${path.sep}root-alias.cjs`,
|
||||
);
|
||||
@@ -127,14 +128,16 @@ function buildPluginSdkAliasMap(useDist) {
|
||||
const ext = useDist ? ".js" : ".ts";
|
||||
const normalizeTarget = (target) =>
|
||||
process.platform === "win32" ? target.replace(/\\/g, "/") : target;
|
||||
const aliasMap = {
|
||||
"openclaw/plugin-sdk": normalizeTarget(__filename),
|
||||
};
|
||||
const aliasMap = Object.fromEntries(
|
||||
pluginSdkPackageNames.map((packageName) => [packageName, normalizeTarget(__filename)]),
|
||||
);
|
||||
|
||||
for (const subpath of listPluginSdkExportedSubpaths()) {
|
||||
const candidate = path.join(pluginSdkDir, `${subpath}${ext}`);
|
||||
if (fs.existsSync(candidate)) {
|
||||
aliasMap[`openclaw/plugin-sdk/${subpath}`] = normalizeTarget(candidate);
|
||||
for (const packageName of pluginSdkPackageNames) {
|
||||
aliasMap[`${packageName}/${subpath}`] = normalizeTarget(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,6 +253,27 @@ describe("plugin-sdk root alias", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("builds scoped and unscoped plugin-sdk aliases for jiti loads", () => {
|
||||
const lazyModule = loadRootAliasWithStubs({
|
||||
distExists: true,
|
||||
monolithicExports: {
|
||||
slowHelper: (): string => "loaded",
|
||||
},
|
||||
});
|
||||
|
||||
expect((lazyModule.moduleExports.slowHelper as () => string)()).toBe("loaded");
|
||||
expect(lazyModule.createJitiOptions.at(-1)?.alias).toMatchObject({
|
||||
"openclaw/plugin-sdk": rootAliasPath,
|
||||
"@openclaw/plugin-sdk": rootAliasPath,
|
||||
"openclaw/plugin-sdk/group-access": expect.stringContaining(
|
||||
path.join("src", "plugin-sdk", "group-access.ts"),
|
||||
),
|
||||
"@openclaw/plugin-sdk/group-access": expect.stringContaining(
|
||||
path.join("src", "plugin-sdk", "group-access.ts"),
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers hashed dist diagnostic events chunks before falling back to src", () => {
|
||||
const packageRoot = createPackageRoot();
|
||||
const distAliasPath = createDistAliasPath();
|
||||
|
||||
Reference in New Issue
Block a user