File size: 1,504 Bytes
fd2c364 | 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 40 41 42 43 44 45 46 47 48 49 50 | import * as os from "node:os";
import * as path from "node:path";
export const WORKSPACE_DIR_NAME = "e2e-folder-workspace-test";
export const TEST_DIR_NAME = "my-test-project";
interface ResolveFolderWorkspacePathsOptions {
env?: NodeJS.ProcessEnv;
tmpDir?: string;
}
export function resolveFolderWorkspacePaths({
env = process.env,
tmpDir = os.tmpdir(),
}: ResolveFolderWorkspacePathsOptions = {}) {
const hostDirBase =
env.MOCK_LLM_FOLDER_WORKSPACE_HOST_DIR ??
joinRuntimePath(tmpDir, WORKSPACE_DIR_NAME);
const containerDirBase =
env.MOCK_LLM_FOLDER_WORKSPACE_CONTAINER_DIR ?? hostDirBase;
return {
hostDirBase,
containerDirBase,
hostDir: joinRuntimePath(hostDirBase, TEST_DIR_NAME),
testDir: joinRuntimePath(containerDirBase, TEST_DIR_NAME),
};
}
export function getFolderBrowserRootPath(targetPath: string): string {
const parser = getRuntimePathParser(targetPath);
return parser.parse(targetPath).root || "/";
}
export function getFolderBrowserPathSegments(targetPath: string): string[] {
const root = getFolderBrowserRootPath(targetPath);
const relativePath = targetPath.slice(root.length);
return relativePath.split(/[\\/]+/).filter(Boolean);
}
function joinRuntimePath(parent: string, child: string): string {
return getRuntimePathParser(parent).join(parent, child);
}
function getRuntimePathParser(targetPath: string) {
return /^[A-Za-z]:[\\/]/.test(targetPath) || targetPath.includes("\\")
? path.win32
: path.posix;
}
|