use std::path::Path;
const LOCKFILE_NAMES: &[&str] = &[
"package-lock.json", "yarn.lock", "pnpm-lock.yaml", "npm-shrinkwrap.json", "bun.lockb", "deno.lock", "composer.lock",
"gemfile.lock", "poetry.lock", "pipfile.lock", "pdm.lock", "uv.lock", "conda-lock.yml", ".req.lock",
"go.sum", "gopkg.lock", "glide.lock", "gradle.lockfile", "pom.xml.lock", "dependency-lock.json",
"packages.lock.json", "paket.lock", "project.assets.json", "package.resolved", "podfile.lock", "cartfile.resolved", "mix.lock",
"rebar.lock",
"pubspec.lock",
"stack.yaml.lock", "cabal.project.freeze", "cargo.lock",
"flake.lock",
"cpanfile.snapshot", "MYMETA.yml", "MYMETA.json", "renv.lock", "packrat/packrat.lock", "manifest.toml",
".terraform.lock.hcl", "Pulumi.lock.yaml", "Chart.lock", "Berksfile.lock", "Puppetfile.lock",
"shard.lock",
"conan.lock", "cpm.cmake.lock", "subprojects/packagecache.json",
"platformio.lock", "luarocks.lock", "elm-stuff/exact-dependencies.json",
"esy.lock/index.json", "opam.lock", "*.opam.locked", "nimble.lock",
"dub.selections.json",
"zig.lock", "haxelib.lock", "v.lock", "qlfile.lock",
"module.bazel.lock", "Brewfile.lock.json", ];
pub fn is_lockfile(path: &Path) -> bool {
let path_str_lower = path.to_string_lossy().to_lowercase().replace('\\', "/");
LOCKFILE_NAMES
.iter()
.any(|&lockfile| path_str_lower.ends_with(lockfile))
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn test_is_lockfile_matches() {
assert!(is_lockfile(&PathBuf::from("path/to/Cargo.lock")));
assert!(is_lockfile(&PathBuf::from("package-lock.json")));
assert!(is_lockfile(&PathBuf::from("Yarn.lock"))); assert!(is_lockfile(&PathBuf::from("PNPM-LOCK.YAML"))); assert!(is_lockfile(&PathBuf::from("go.sum")));
assert!(is_lockfile(&PathBuf::from("Gemfile.lock"))); assert!(is_lockfile(&PathBuf::from("gemfile.lock"))); assert!(is_lockfile(&PathBuf::from("Pipfile.lock"))); assert!(is_lockfile(&PathBuf::from("pipfile.lock"))); assert!(is_lockfile(&PathBuf::from("Manifest.toml"))); assert!(is_lockfile(&PathBuf::from("manifest.toml"))); }
#[test]
fn test_is_lockfile_no_match() {
assert!(!is_lockfile(&PathBuf::from("src/main.rs")));
assert!(!is_lockfile(&PathBuf::from("Cargo.toml")));
assert!(!is_lockfile(&PathBuf::from("lockfile.txt")));
assert!(!is_lockfile(&PathBuf::from("noextension")));
assert!(!is_lockfile(&PathBuf::from("path/to/"))); }
#[test]
fn test_is_lockfile_root() {
assert!(is_lockfile(&PathBuf::from("Cargo.lock")));
}
}