import { join } from 'path';
import { createHash } from 'crypto';
import { CACHE_DIR, EMULSIFY_PROJECT_CONFIG_FILE, } from '../../lib/constants.js';
import findFileInCurrentPath from '../fs/findFileInCurrentPath.js';
export default function getCachedItemPath(bucket, itemPath, checkout) {
    const projectPath = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
    if (!projectPath) {
        throw new Error(`Unable to find ${EMULSIFY_PROJECT_CONFIG_FILE}`);
    }
    if (!checkout || typeof checkout === 'undefined') {
        checkout = '';
    }
    return join(CACHE_DIR, bucket, createHash('md5')
        .update(`MBR${String(projectPath)}${String(checkout)}`)
        .digest('hex'), ...itemPath);
}
