fix(plugins): prefer dist plugin-sdk in tests
This commit is contained in:
@@ -101,12 +101,17 @@ const normalizePluginsConfig = (config?: ClawdbotConfig["plugins"]): NormalizedP
|
|||||||
|
|
||||||
const resolvePluginSdkAlias = (): string | null => {
|
const resolvePluginSdkAlias = (): string | null => {
|
||||||
try {
|
try {
|
||||||
|
const preferDist = process.env.VITEST || process.env.NODE_ENV === "test";
|
||||||
let cursor = path.dirname(fileURLToPath(import.meta.url));
|
let cursor = path.dirname(fileURLToPath(import.meta.url));
|
||||||
for (let i = 0; i < 6; i += 1) {
|
for (let i = 0; i < 6; i += 1) {
|
||||||
const srcCandidate = path.join(cursor, "src", "plugin-sdk", "index.ts");
|
const srcCandidate = path.join(cursor, "src", "plugin-sdk", "index.ts");
|
||||||
if (fs.existsSync(srcCandidate)) return srcCandidate;
|
|
||||||
const distCandidate = path.join(cursor, "dist", "plugin-sdk", "index.js");
|
const distCandidate = path.join(cursor, "dist", "plugin-sdk", "index.js");
|
||||||
if (fs.existsSync(distCandidate)) return distCandidate;
|
const orderedCandidates = preferDist
|
||||||
|
? [distCandidate, srcCandidate]
|
||||||
|
: [srcCandidate, distCandidate];
|
||||||
|
for (const candidate of orderedCandidates) {
|
||||||
|
if (fs.existsSync(candidate)) return candidate;
|
||||||
|
}
|
||||||
const parent = path.dirname(cursor);
|
const parent = path.dirname(cursor);
|
||||||
if (parent === cursor) break;
|
if (parent === cursor) break;
|
||||||
cursor = parent;
|
cursor = parent;
|
||||||
|
|||||||
Reference in New Issue
Block a user