From b2c241c3d86932be0e2c62740bae20eb6a210b4b Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Mon, 12 Aug 2024 20:24:05 +0100 Subject: [PATCH] Run npm install as part of build.rs too --- .github/workflows/test.yml | 6 ------ crates/librqbit/build.rs | 44 +++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecf2b5b..725931f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,6 @@ jobs: rustup toolchain install ${{ matrix.rust_version }} - uses: actions/checkout@v4 - run: rustup override set ${{ matrix.rust_version }} - - name: npm install (librqbit/webui) - working-directory: crates/librqbit/webui - run: npm install - name: cargo check run: cargo check test: @@ -32,8 +29,5 @@ jobs: - uses: actions/checkout@v4 - run: rustup toolchain install stable --profile minimal - uses: Swatinem/rust-cache@v2 - - name: npm install (librqbit/webui) - working-directory: crates/librqbit/webui - run: npm install - name: Run tests run: cargo test diff --git a/crates/librqbit/build.rs b/crates/librqbit/build.rs index aca3ebf..ff4bba4 100644 --- a/crates/librqbit/build.rs +++ b/crates/librqbit/build.rs @@ -9,22 +9,36 @@ fn main() { println!("cargo:rerun-if-changed={}", webui_src_dir.to_str().unwrap()); - // Run "npm run build" in the webui directory - let output = Command::new("npm") - .arg("run") - .arg("build") - .current_dir(webui_dir) - .output() - .expect("Failed to execute npm run build"); + // Run "npm install && npm run build" in the webui directory + for (cmd, args) in [ + ("npm", ["install"].as_slice()), + ("npm", ["run", "build"].as_slice()), + ] { + // Run "npm install" in the webui directory + let output = Command::new(cmd) + .args(args) + .current_dir(webui_dir) + .output() + .unwrap_or_else(|_| { + panic!( + "Failed to execute {} {} in {:?}", + cmd, + args.join(" "), + webui_dir + ) + }); - if !output.status.success() { - panic!( - "npm run build failed with output: {}", - String::from_utf8_lossy(&output.stderr) - ); + if !output.status.success() { + panic!( + "{} {} failed with output: {}", + cmd, + args.join(" "), + String::from_utf8_lossy(&output.stderr) + ); + } + + // Optionally print the stdout output if you want to see the build logs + println!("{}", String::from_utf8_lossy(&output.stdout)); } - - // Optionally print the stdout output if you want to see the build logs - println!("{}", String::from_utf8_lossy(&output.stdout)); } }