Skip to content

Commit 1e602f3

Browse files
committed
tidy: use a lockfile for js tools instead of npx
this makes us less vulnerable to MITM and supply chain attacks. it also means that the CI scripts are no longer responsible for tracking the versions of these tools. it should also avoid the situation where local tsc and CI disagree on the presense of errors due to them being different versions.
1 parent 36cd096 commit 1e602f3

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ __pycache__/
8585

8686
## Node
8787
node_modules
88-
package-lock.json
89-
package.json
9088
/src/doc/rustc-dev-guide/mermaid.min.js
9189

9290
## Rustdoc GUI tests

src/ci/docker/host-x86_64/mingw-check-1/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ COPY scripts/nodejs.sh /scripts/
2727
RUN sh /scripts/nodejs.sh /node
2828
ENV PATH="/node/bin:${PATH}"
2929

30-
# Install es-check
31-
# Pin its version to prevent unrelated CI failures due to future es-check versions.
32-
RUN npm install es-check@6.1.1 eslint@8.6.0 typescript@5.7.3 -g
33-
3430
COPY scripts/sccache.sh /scripts/
3531
RUN sh /scripts/sccache.sh
3632

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ fn check_impl(
248248
shellcheck_runner(&merge_args(&cfg_args, &file_args_shc))?;
249249
}
250250

251+
if js_lint || js_typecheck || js_es_check {
252+
rustdoc_js::npm_install()?;
253+
}
254+
251255
if js_lint {
252256
rustdoc_js::lint(librustdoc_path, tools_path, src_path)?;
253257
}

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ use ignore::DirEntry;
99

1010
use crate::walk::walk_no_read;
1111

12+
/// install all js dependencies from package.json.
13+
pub(super) fn npm_install() -> Result<(), super::Error> {
14+
// disable a bunch of things we don't want.
15+
// this makes tidy output less noisy, and also significantly improves runtime
16+
// of repeated tidy invokations.
17+
let mut child = Command::new("npm")
18+
.args(&["install", "--audit=false", "--save=false", "--fund=false"])
19+
.spawn()?;
20+
match child.wait() {
21+
Ok(exit_status) => {
22+
if exit_status.success() {
23+
return Ok(());
24+
}
25+
Err(super::Error::FailedCheck("npm install failed"))
26+
}
27+
Err(error) => Err(super::Error::Generic(format!("npm install failed: {error:?}"))),
28+
}
29+
}
30+
1231
fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
1332
let mut files = Vec::new();
1433
walk_no_read(
@@ -22,8 +41,7 @@ fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
2241
}
2342

2443
fn run_eslint(args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> {
25-
let mut child = Command::new("npx")
26-
.arg("eslint")
44+
let mut child = Command::new("node_modules/.bin/eslint")
2745
.arg("-c")
2846
.arg(config_folder.join(".eslintrc.js"))
2947
.args(args)
@@ -106,8 +124,7 @@ pub(super) fn lint(
106124

107125
pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
108126
// use npx to ensure correct version
109-
let mut child = Command::new("npx")
110-
.arg("tsc")
127+
let mut child = Command::new("node_modules/.bin/tsc")
111128
.arg("-p")
112129
.arg(librustdoc_path.join("html/static/js/tsconfig.json"))
113130
.spawn()?;
@@ -124,9 +141,8 @@ pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
124141

125142
pub(super) fn es_check(librustdoc_path: &Path) -> Result<(), super::Error> {
126143
let files_to_check = rustdoc_js_files(librustdoc_path);
127-
// use npx to ensure correct version
128-
let mut cmd = Command::new("npx");
129-
cmd.arg("es-check").arg("es2019");
144+
let mut cmd = Command::new("node_modules/.bin/es-check");
145+
cmd.arg("es2019");
130146
for f in files_to_check {
131147
cmd.arg(f);
132148
}

0 commit comments

Comments
 (0)