function findUpSync(name, { cwd = process.cwd() } = {}) {
    let directory = path.resolve(toPath(cwd) || '');
    const { root } = path.parse(directory);

    while (directory && directory !== root) {
        const filePath = path.isAbsolute(name) ? name : path.join(directory, name);

        try {
            const stats = fs.statSync(filePath, { throwIfNoEntry: false });
            if (stats && stats.isFile()) {
                return filePath;
            }
        } catch (e) {}

        directory = path.dirname(directory);
    }
}
Inlined and simplified version of the package "find-up-simple" (ESM only).

@param {string} name The name of the file to find
@param {object} options
@param {string=} options.cwd The directory to start searching from.
@returns {string|undefined} The path to the file found or undefined if not found.