Skip to content

Commit 9734333

Browse files
committed
tidy: put node_modules under build
1 parent f50898d commit 9734333

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,39 @@
44
use std::ffi::OsStr;
55
use std::path::{Path, PathBuf};
66
use std::process::Command;
7+
use std::fs;
78

89
use build_helper::ci::CiEnv;
910
use ignore::DirEntry;
1011

1112
use crate::walk::walk_no_read;
1213

14+
fn node_module_bin(name: &str) -> String {
15+
format!("build/node_modules/.bin/{name}")
16+
}
17+
1318
/// install all js dependencies from package.json.
1419
pub(super) fn npm_install() -> Result<(), super::Error> {
15-
// disable a bunch of things we don't want.
16-
// this makes tidy output less noisy, and also significantly improves runtime
17-
// of repeated tidy invokations.
20+
// will error if already exists, so ignore the error.
21+
// if there is a filesystem permission issue,
22+
// later commands will error.
23+
let _ = fs::create_dir("build");
24+
// copy stuff to build/ to make node_modules get put there.
25+
fs::copy("package.json", "build/package.json")?;
26+
fs::copy("package-lock.json", "build/package-lock.json")?;
27+
1828
let mut cmd = Command::new("npm");
1929
if CiEnv::is_ci() {
2030
// `npm ci` redownloads every time and thus is too slow for local development.
2131
cmd.arg("ci");
2232
} else {
2333
cmd.arg("install");
2434
}
35+
// disable a bunch of things we don't want.
36+
// this makes tidy output less noisy, and also significantly improves runtime
37+
// of repeated tidy invokations.
2538
cmd.args(&["--audit=false", "--save=false", "--fund=false"]);
39+
cmd.current_dir("build");
2640
let mut child = cmd.spawn()?;
2741
match child.wait() {
2842
Ok(exit_status) => {
@@ -48,7 +62,7 @@ fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
4862
}
4963

5064
fn run_eslint(args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> {
51-
let mut child = Command::new("node_modules/.bin/eslint")
65+
let mut child = Command::new(node_module_bin("eslint"))
5266
.arg("-c")
5367
.arg(config_folder.join(".eslintrc.js"))
5468
.args(args)
@@ -130,7 +144,7 @@ pub(super) fn lint(
130144

131145
pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
132146
// use npx to ensure correct version
133-
let mut child = Command::new("node_modules/.bin/tsc")
147+
let mut child = Command::new(node_module_bin("tsc"))
134148
.arg("-p")
135149
.arg(librustdoc_path.join("html/static/js/tsconfig.json"))
136150
.spawn()?;
@@ -147,7 +161,7 @@ pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
147161

148162
pub(super) fn es_check(librustdoc_path: &Path) -> Result<(), super::Error> {
149163
let files_to_check = rustdoc_js_files(librustdoc_path);
150-
let mut cmd = Command::new("node_modules/.bin/es-check");
164+
let mut cmd = Command::new(node_module_bin("es-check"));
151165
cmd.arg("es2019");
152166
for f in files_to_check {
153167
cmd.arg(f);

0 commit comments

Comments
 (0)