function findUp(filename, cwd) {
  let dir = path.resolve(cwd || '');
  const root = path.parse(dir).root;

  /** @type {string[]} */ // @ts-expect-error TS sucks with concat
  const filenames = [].concat(filename);

  // eslint-disable-next-line no-constant-condition
  while (true) {
    const file = filenames.find((el) => fs.existsSync(path.resolve(dir, el)));

    if (file) {
      return path.join(dir, file);
    }
    if (dir === root) {
      return null;
    }

    dir = path.dirname(dir);
  }
}
@type {(filename: string | string[], cwd?: string) => string | null}