Skip to content

Commit

Permalink
refactor: don't read package again when serializing to environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Jan 24, 2024
1 parent 59fac25 commit 97b61c3
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/run_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use nix::{
};
use which::which;

use std::{env, ffi::OsString, path::Path};
use tokio::process::Command;

use color_eyre::Result;
use owo_colors::OwoColorize;
use std::{env, ffi::OsString, path::Path};
use tokio::{fs, process::Command};

#[cfg(unix)]
use tokio::signal::ctrl_c;
Expand Down Expand Up @@ -137,17 +138,12 @@ pub async fn run_script(
}

if let Some(CompatMode::Yarn | CompatMode::Pnpm) = compat_mode {
if let Ok(Ok(package_data_raw)) = fs::read_to_string(package_path)
.await
.map(|txt| serde_json::from_str::<serde_json::Value>(&txt))
{
subproc.envs(serialize_package_json_env(&package_data_raw));
}
let package_value = serde_json::to_value(package_data)?;
subproc.envs(serialize_package_json_env(&package_value));
} else {
if let Some(p_name) = &package_data.name {
subproc.env("npm_package_name", p_name);
}

if let Some(p_version) = &package_data.version {
subproc.env("npm_package_version", p_version);
}
Expand Down

0 comments on commit 97b61c3

Please sign in to comment.