Skip to content

Commit 9c857a2

Browse files
committed
put events file writing behind env var
1 parent 817a575 commit 9c857a2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

crates/volta-core/src/monitor.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use std::io::Write;
23
use std::path::PathBuf;
34
use std::process::{Child, Stdio};
@@ -13,12 +14,14 @@ use crate::event::Event;
1314
pub fn send_events(command: &str, events: &[Event]) {
1415
match serde_json::to_string_pretty(&events) {
1516
Ok(events_json) => {
16-
if let Some(tempfile_path) = write_events_file(events_json.clone()) {
17-
if let Some(ref mut child_process) = spawn_process(command, tempfile_path) {
18-
if let Some(ref mut p_stdin) = child_process.stdin.as_mut() {
19-
if let Err(error) = writeln!(p_stdin, "{}", events_json) {
20-
debug!("Could not write events to executable stdin: {:?}", error);
21-
}
17+
let tempfile_path = match env::var("VOLTA_WRITE_EVENTS_FILE") {
18+
Ok(_) => write_events_file(events_json.clone()),
19+
Err(_) => None,
20+
};
21+
if let Some(ref mut child_process) = spawn_process(command, tempfile_path) {
22+
if let Some(ref mut p_stdin) = child_process.stdin.as_mut() {
23+
if let Err(error) = writeln!(p_stdin, "{}", events_json) {
24+
debug!("Could not write events to executable stdin: {:?}", error);
2225
}
2326
}
2427
}
@@ -60,12 +63,14 @@ fn write_events_file(events_json: String) -> Option<PathBuf> {
6063
}
6164

6265
// Spawn a child process to receive the events data, setting the path to the events file as an env var
63-
fn spawn_process(command: &str, tempfile_path: PathBuf) -> Option<Child> {
66+
fn spawn_process(command: &str, tempfile_path: Option<PathBuf>) -> Option<Child> {
6467
command.split(' ').take(1).next().and_then(|executable| {
6568
let mut child = create_command(executable);
6669
child.args(command.split(' ').skip(1));
6770
child.stdin(Stdio::piped());
68-
child.env("EVENTS_FILE", tempfile_path);
71+
if let Some(events_file) = tempfile_path {
72+
child.env("EVENTS_FILE", events_file);
73+
}
6974

7075
#[cfg(not(debug_assertions))]
7176
// Hide stdout and stderr of spawned process in release mode

tests/acceptance/hooks.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ fn yarn_hooks_json() -> String {
139139
fn redirects_download() {
140140
let s = sandbox()
141141
.default_hooks(&default_hooks_json())
142+
.env("VOLTA_WRITE_EVENTS_FILE", "true")
142143
.executable_file(SCRIPT_FILENAME, EVENTS_EXECUTABLE)
143144
.build();
144145

@@ -175,6 +176,7 @@ fn merges_project_and_default_hooks() {
175176
.package_json("{}")
176177
.default_hooks(&default_hooks_json())
177178
.project_file(&local_hooks.to_string_lossy(), &project_hooks_json())
179+
.env("VOLTA_WRITE_EVENTS_FILE", "true")
178180
.executable_file(SCRIPT_FILENAME, EVENTS_EXECUTABLE)
179181
.build();
180182

@@ -243,6 +245,7 @@ fn merges_workspace_hooks() {
243245
WORKSPACE_PACKAGE_JSON,
244246
)
245247
.project_file(&workspace_hooks.to_string_lossy(), &workspace_hooks_json())
248+
.env("VOLTA_WRITE_EVENTS_FILE", "true")
246249
.executable_file(SCRIPT_FILENAME, EVENTS_EXECUTABLE)
247250
.build();
248251

tests/acceptance/merged_platform.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ fn uses_project_yarn_if_available() {
244244
.distro_mocks::<NodeFixture>(&NODE_VERSION_FIXTURES)
245245
.distro_mocks::<YarnFixture>(&YARN_VERSION_FIXTURES)
246246
.env("VOLTA_LOGLEVEL", "debug")
247+
.env("VOLTA_WRITE_EVENTS_FILE", "true")
247248
.default_hooks(&events_hooks_json())
248249
.executable_file(SCRIPT_FILENAME, EVENTS_EXECUTABLE)
249250
.build();

0 commit comments

Comments
 (0)