diff options
| author | binarycat <binarycat@envs.net> | 2025-07-19 14:56:42 -0500 |
|---|---|---|
| committer | binarycat <binarycat@envs.net> | 2025-07-19 14:56:42 -0500 |
| commit | c6d50eaa497ef0c3013d21f23cd85e6e97c32c2c (patch) | |
| tree | 92b3db0bc1f482fa78b11c635e44f7dcb5721392 /src | |
| parent | ca39010d3e7d3c512d5d8df8094862ffa146837f (diff) | |
| download | rust-c6d50eaa497ef0c3013d21f23cd85e6e97c32c2c.tar.gz rust-c6d50eaa497ef0c3013d21f23cd85e6e97c32c2c.zip | |
integrate build_helper::npm into js checks and package.json usage
Diffstat (limited to 'src')
| -rw-r--r-- | src/build_helper/src/npm.rs | 43 | ||||
| -rw-r--r-- | src/tools/rustdoc-gui-test/src/main.rs | 6 | ||||
| -rw-r--r-- | src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs | 39 |
3 files changed, 34 insertions, 54 deletions
diff --git a/src/build_helper/src/npm.rs b/src/build_helper/src/npm.rs index dedef40978d..86cf6183bd0 100644 --- a/src/build_helper/src/npm.rs +++ b/src/build_helper/src/npm.rs @@ -3,23 +3,34 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::{fs, io}; -/// Install an exact package version, and return the path of `node_modules`. -pub fn install_one( - out_dir: &Path, - npm_bin: &Path, - pkg_name: &str, - pkg_version: &str, -) -> Result<PathBuf, io::Error> { +use crate::ci::CiEnv; + +/// Install all the npm deps, and return the path of `node_modules`. +pub fn install(src_root_path: &Path, out_dir: &Path, npm: &Path) -> Result<PathBuf, io::Error> { let nm_path = out_dir.join("node_modules"); - let _ = fs::create_dir(&nm_path); - let mut child = Command::new(npm_bin) - .arg("install") - .arg("--audit=false") - .arg("--fund=false") - .arg(format!("{pkg_name}@{pkg_version}")) - .current_dir(out_dir) - .spawn()?; - let exit_status = child.wait()?; + let copy_to_build = |p| { + fs::copy(src_root_path.join(p), out_dir.join(p)).map_err(|e| { + eprintln!("unable to copy {p:?} to build directory: {e:?}"); + e + }) + }; + // copy stuff to the output directory to make node_modules get put there. + copy_to_build("package.json")?; + copy_to_build("package-lock.json")?; + + let mut cmd = Command::new(npm); + if CiEnv::is_ci() { + // `npm ci` redownloads every time and thus is too slow for local development. + cmd.arg("ci"); + } else { + cmd.arg("install"); + } + // disable a bunch of things we don't want. + // this makes tidy output less noisy, and also significantly improves runtime + // of repeated tidy invokations. + cmd.args(&["--audit=false", "--save=false", "--fund=false"]); + cmd.current_dir(out_dir); + let exit_status = cmd.spawn()?.wait()?; if !exit_status.success() { eprintln!("npm install did not exit successfully"); return Err(io::Error::other(Box::<dyn Error + Send + Sync>::from(format!( diff --git a/src/tools/rustdoc-gui-test/src/main.rs b/src/tools/rustdoc-gui-test/src/main.rs index 5b86bea8932..42feae8c208 100644 --- a/src/tools/rustdoc-gui-test/src/main.rs +++ b/src/tools/rustdoc-gui-test/src/main.rs @@ -65,10 +65,8 @@ fn main() -> Result<(), ()> { } } - // FIXME(binarycat): once we get package.json in version control, this should be updated to install via that instead - let local_node_modules = - npm::install_one(&config.out_dir, &config.npm, "browser-ui-test", "0.21.1") - .expect("unable to install browser-ui-test"); + let local_node_modules = npm::install(&config.rust_src, &config.out_dir, &config.npm) + .expect("unable to install browser-ui-test"); let mut command = Command::new(&config.nodejs); diff --git a/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs b/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs index f96c9612a8e..c1a62cedd33 100644 --- a/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs +++ b/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs @@ -2,11 +2,11 @@ //! characters. use std::ffi::OsStr; +use std::io; use std::path::{Path, PathBuf}; use std::process::{Child, Command}; -use std::{fs, io}; -use build_helper::ci::CiEnv; +use build_helper::npm; use ignore::DirEntry; use crate::walk::walk_no_read; @@ -24,38 +24,9 @@ fn spawn_cmd(cmd: &mut Command) -> Result<Child, io::Error> { /// install all js dependencies from package.json. pub(super) fn npm_install(root_path: &Path, outdir: &Path) -> Result<(), super::Error> { - let copy_to_build = |p| { - fs::copy(root_path.join(p), outdir.join(p)).map_err(|e| { - eprintln!("unable to copy {p:?} to build directory: {e:?}"); - e - }) - }; - // copy stuff to the output directory to make node_modules get put there. - copy_to_build("package.json")?; - copy_to_build("package-lock.json")?; - - let mut cmd = Command::new("npm"); - if CiEnv::is_ci() { - // `npm ci` redownloads every time and thus is too slow for local development. - cmd.arg("ci"); - } else { - cmd.arg("install"); - } - // disable a bunch of things we don't want. - // this makes tidy output less noisy, and also significantly improves runtime - // of repeated tidy invokations. - cmd.args(&["--audit=false", "--save=false", "--fund=false"]); - cmd.current_dir(outdir); - let mut child = spawn_cmd(&mut cmd)?; - match child.wait() { - Ok(exit_status) => { - if exit_status.success() { - return Ok(()); - } - Err(super::Error::FailedCheck("npm install")) - } - Err(error) => Err(super::Error::Generic(format!("npm install failed: {error:?}"))), - } + // FIXME(lolbinarycat): make this obey build.npm bootstrap option + npm::install(root_path, outdir, Path::new("npm"))?; + Ok(()) } fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> { |
