From c0c701465ea7c8a6e205a2ca9dda215da0a8d758 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 16 Nov 2021 08:36:22 +0000 Subject: [PATCH] Better support for ancient distros with ancient Yarn --- server-core/build.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server-core/build.rs b/server-core/build.rs index d0d509a..511e1ba 100644 --- a/server-core/build.rs +++ b/server-core/build.rs @@ -70,6 +70,12 @@ fn main() { } } + if !check_command( "nodejs" ) { + if !check_command( "node" ) { + panic!( "Node.js not found; you need to install it before you can build the WebUI" ); + } + } + if !webui_dir.join( "node_modules" ).exists() { let mut child = Command::new( yarn ) .args( &[ "install" ] ) @@ -90,8 +96,21 @@ fn main() { assert!( webui_dir.join( "node_modules" ).exists() ); + let mut bin_path = format!( "$({} bin)", yarn ); + let yarn_supports_bin = Command::new( "/bin/sh" ) + .args( &[ String::from( "-c" ), bin_path.clone() ] ) + .current_dir( &webui_dir ) + .status() + .expect( "cannot launch a child process to check whether Yarn supports the 'bin' subcommand" ) + .success(); + + if !yarn_supports_bin { + println!( "cargo:warning=You're using an ancient version of Yarn; this is unsupported" ); + bin_path = "node_modules/.bin".into(); + } + let mut parcel_build_cmd = OsString::new(); - parcel_build_cmd.push( format!( "$({} bin)/parcel build src/index.html -d ", yarn ) ); + parcel_build_cmd.push( format!( "{}/parcel build src/index.html -d ", bin_path ) ); parcel_build_cmd.push( &webui_out_dir ); let mut child = Command::new( "/bin/sh" )