From 9af7cabdf125de3760fab49d8ea4db31b6b4f952 Mon Sep 17 00:00:00 2001 From: "guillem.cordoba" Date: Mon, 23 Sep 2024 11:20:39 +0200 Subject: [PATCH] Return silently if no flake.lock exixts --- crates/sync_npm_git_dependencies_with_nix/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/sync_npm_git_dependencies_with_nix/src/lib.rs b/crates/sync_npm_git_dependencies_with_nix/src/lib.rs index 4db9707..3afbd2d 100644 --- a/crates/sync_npm_git_dependencies_with_nix/src/lib.rs +++ b/crates/sync_npm_git_dependencies_with_nix/src/lib.rs @@ -5,9 +5,9 @@ use parse_flake_lock::{FlakeLock, FlakeLockParseError, Node}; use regex::Regex; use serde_json::Value; use std::{ + env::current_dir, fs::File, io::BufReader, - path::Path, process::{Command, Stdio}, }; use thiserror::Error; @@ -17,7 +17,6 @@ pub enum SynchronizeNpmGitDependenciesWithNixError { #[error(transparent)] FlakeLockParseError(#[from] FlakeLockParseError), - /// std::io::Error #[error("IO error: {0}")] StdIoError(#[from] std::io::Error), @@ -33,7 +32,14 @@ pub enum SynchronizeNpmGitDependenciesWithNixError { pub fn synchronize_npm_git_dependencies_with_nix( ) -> Result<(), SynchronizeNpmGitDependenciesWithNixError> { - let flake_lock = FlakeLock::new(Path::new("flake.lock"))?; + let flake_lock = current_dir()?.join("flake.lock"); + + // Return silently if no "flake.lock" file exists + if !flake_lock.exists() { + return Ok(()); + } + + let flake_lock = FlakeLock::new(flake_lock.as_path())?; let mut announced = false; let mut replaced_some_dep = false;