astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
46 lines (45 loc) • 1.22 kB
JavaScript
import nodeFs from "node:fs";
import path from "node:path";
const KNOWN_LOCKFILES = [
"pnpm-lock.yaml",
"package-lock.json",
"yarn.lock",
"bun.lock",
"bun.lockb"
];
class LockfileFinder {
constructor(fs = nodeFs, lockfileNames = KNOWN_LOCKFILES) {
this.
this.
}
/**
* Walk upward from `startDir` and return the absolute paths of every known
* lockfile in the first directory that contains at least one. In a workspace
* the lockfile lives above the individual project, so the walk continues until
* a directory yields a match. Returns an empty array if the filesystem root is
* reached without finding one.
*/
find(startDir) {
let dir = path.resolve(startDir);
let previous = "";
while (dir !== previous) {
const found = [];
for (const name of this.
const candidate = path.join(dir, name);
if (this.
found.push(candidate);
}
}
if (found.length > 0) return found;
previous = dir;
dir = path.dirname(dir);
}
return [];
}
}
export {
KNOWN_LOCKFILES,
LockfileFinder
};