@@ -11,19 +11,16 @@ use ignore::DirEntry;
11
11
12
12
use crate :: walk:: walk_no_read;
13
13
14
- fn node_module_bin ( name : & str ) -> String {
15
- format ! ( "build/node_modules/.bin/{ name}" )
14
+ fn node_module_bin ( outdir : & Path , name : & str ) -> PathBuf {
15
+ outdir . join ( name)
16
16
}
17
17
18
18
/// install all js dependencies from package.json.
19
- pub ( super ) fn npm_install ( ) -> Result < ( ) , super :: Error > {
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" ) ?;
19
+ pub ( super ) fn npm_install ( outdir : & Path ) -> Result < ( ) , super :: Error > {
20
+ let copy_to_build = |p| fs:: copy ( p, outdir. join ( p) ) ;
21
+ // copy stuff to the output directory to make node_modules get put there.
22
+ copy_to_build ( "package.json" ) ?;
23
+ copy_to_build ( "package-lock.json" ) ?;
27
24
28
25
let mut cmd = Command :: new ( "npm" ) ;
29
26
if CiEnv :: is_ci ( ) {
@@ -36,7 +33,7 @@ pub(super) fn npm_install() -> Result<(), super::Error> {
36
33
// this makes tidy output less noisy, and also significantly improves runtime
37
34
// of repeated tidy invokations.
38
35
cmd. args ( & [ "--audit=false" , "--save=false" , "--fund=false" ] ) ;
39
- cmd. current_dir ( "build" ) ;
36
+ cmd. current_dir ( outdir ) ;
40
37
let mut child = cmd. spawn ( ) ?;
41
38
match child. wait ( ) {
42
39
Ok ( exit_status) => {
@@ -61,8 +58,8 @@ fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
61
58
return files;
62
59
}
63
60
64
- fn run_eslint ( args : & [ PathBuf ] , config_folder : PathBuf ) -> Result < ( ) , super :: Error > {
65
- let mut child = Command :: new ( node_module_bin ( "eslint" ) )
61
+ fn run_eslint ( outdir : & Path , args : & [ PathBuf ] , config_folder : PathBuf ) -> Result < ( ) , super :: Error > {
62
+ let mut child = Command :: new ( node_module_bin ( outdir , "eslint" ) )
66
63
. arg ( "-c" )
67
64
. arg ( config_folder. join ( ".eslintrc.js" ) )
68
65
. args ( args)
@@ -94,6 +91,7 @@ fn get_eslint_version() -> Option<String> {
94
91
}
95
92
96
93
pub ( super ) fn lint (
94
+ outdir : & Path ,
97
95
librustdoc_path : & Path ,
98
96
tools_path : & Path ,
99
97
src_path : & Path ,
@@ -135,16 +133,20 @@ pub(super) fn lint(
135
133
}
136
134
let files_to_check = rustdoc_js_files ( librustdoc_path) ;
137
135
println ! ( "Running eslint on rustdoc JS files" ) ;
138
- run_eslint ( & files_to_check, librustdoc_path. join ( "html/static" ) ) ?;
136
+ run_eslint ( outdir , & files_to_check, librustdoc_path. join ( "html/static" ) ) ?;
139
137
140
- run_eslint ( & [ tools_path. join ( "rustdoc-js/tester.js" ) ] , tools_path. join ( "rustdoc-js" ) ) ?;
141
- run_eslint ( & [ tools_path. join ( "rustdoc-gui/tester.js" ) ] , tools_path. join ( "rustdoc-gui" ) ) ?;
138
+ run_eslint ( outdir, & [ tools_path. join ( "rustdoc-js/tester.js" ) ] , tools_path. join ( "rustdoc-js" ) ) ?;
139
+ run_eslint (
140
+ outdir,
141
+ & [ tools_path. join ( "rustdoc-gui/tester.js" ) ] ,
142
+ tools_path. join ( "rustdoc-gui" ) ,
143
+ ) ?;
142
144
Ok ( ( ) )
143
145
}
144
146
145
- pub ( super ) fn typecheck ( librustdoc_path : & Path ) -> Result < ( ) , super :: Error > {
147
+ pub ( super ) fn typecheck ( outdir : & Path , librustdoc_path : & Path ) -> Result < ( ) , super :: Error > {
146
148
// use npx to ensure correct version
147
- let mut child = Command :: new ( node_module_bin ( "tsc" ) )
149
+ let mut child = Command :: new ( node_module_bin ( outdir , "tsc" ) )
148
150
. arg ( "-p" )
149
151
. arg ( librustdoc_path. join ( "html/static/js/tsconfig.json" ) )
150
152
. spawn ( ) ?;
@@ -159,9 +161,9 @@ pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
159
161
}
160
162
}
161
163
162
- pub ( super ) fn es_check ( librustdoc_path : & Path ) -> Result < ( ) , super :: Error > {
164
+ pub ( super ) fn es_check ( outdir : & Path , librustdoc_path : & Path ) -> Result < ( ) , super :: Error > {
163
165
let files_to_check = rustdoc_js_files ( librustdoc_path) ;
164
- let mut cmd = Command :: new ( node_module_bin ( "es-check" ) ) ;
166
+ let mut cmd = Command :: new ( node_module_bin ( outdir , "es-check" ) ) ;
165
167
cmd. arg ( "es2019" ) ;
166
168
for f in files_to_check {
167
169
cmd. arg ( f) ;
0 commit comments