Spaces:
Runtime error
Runtime error
File size: 1,106 Bytes
fb38ec5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import fs from "fs";
import path, { dirname } from "path";
import { fileURLToPath } from "url";
export async function getExtensionPaths(extensionNames: string[]): Promise<string[]> {
const extensionsDir = path.join(
dirname(fileURLToPath(import.meta.url)),
"..",
"..",
"extensions",
);
try {
await fs.promises.access(extensionsDir);
} catch {
console.warn("Extensions directory does not exist");
return [];
}
const allExtensions = await fs.promises.readdir(extensionsDir);
const candidatePaths = extensionNames
.filter((name) => allExtensions.includes(name))
.map((dir) => path.join(extensionsDir, dir));
const validationResults = await Promise.all(
candidatePaths.map(async (fullPath) => {
try {
await fs.promises.access(fullPath);
return { path: fullPath, valid: true };
} catch {
console.warn(`Extension directory ${fullPath} does not exist`);
return { path: fullPath, valid: false };
}
}),
);
return validationResults.filter((result) => result.valid).map((result) => result.path);
}
|