UNPKG

@netlify/cache-utils

Version:

Utility for caching files in Netlify Build

20 lines (19 loc) 504 B
import { normalize } from 'path'; import process from 'process'; import { pathExists } from 'path-exists'; // Like `process.cwd()` but safer when current directory is wrong export const safeGetCwd = async function (cwdOpt) { try { const cwd = getCwdValue(cwdOpt); if (!(await pathExists(cwd))) { return ''; } return cwd; } catch { return ''; } }; const getCwdValue = function (cwdOpt = process.cwd()) { return normalize(cwdOpt); };