4
4
use std:: ffi:: OsStr ;
5
5
use std:: path:: { Path , PathBuf } ;
6
6
use std:: process:: Command ;
7
+ use std:: fs;
7
8
8
9
use build_helper:: ci:: CiEnv ;
9
10
use ignore:: DirEntry ;
10
11
11
12
use crate :: walk:: walk_no_read;
12
13
14
+ fn node_module_bin ( name : & str ) -> String {
15
+ format ! ( "build/node_modules/.bin/{name}" )
16
+ }
17
+
13
18
/// install all js dependencies from package.json.
14
19
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
+
18
28
let mut cmd = Command :: new ( "npm" ) ;
19
29
if CiEnv :: is_ci ( ) {
20
30
// `npm ci` redownloads every time and thus is too slow for local development.
21
31
cmd. arg ( "ci" ) ;
22
32
} else {
23
33
cmd. arg ( "install" ) ;
24
34
}
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.
25
38
cmd. args ( & [ "--audit=false" , "--save=false" , "--fund=false" ] ) ;
39
+ cmd. current_dir ( "build" ) ;
26
40
let mut child = cmd. spawn ( ) ?;
27
41
match child. wait ( ) {
28
42
Ok ( exit_status) => {
@@ -48,7 +62,7 @@ fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
48
62
}
49
63
50
64
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") )
52
66
. arg ( "-c" )
53
67
. arg ( config_folder. join ( ".eslintrc.js" ) )
54
68
. args ( args)
@@ -130,7 +144,7 @@ pub(super) fn lint(
130
144
131
145
pub ( super ) fn typecheck ( librustdoc_path : & Path ) -> Result < ( ) , super :: Error > {
132
146
// 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") )
134
148
. arg ( "-p" )
135
149
. arg ( librustdoc_path. join ( "html/static/js/tsconfig.json" ) )
136
150
. spawn ( ) ?;
@@ -147,7 +161,7 @@ pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
147
161
148
162
pub ( super ) fn es_check ( librustdoc_path : & Path ) -> Result < ( ) , super :: Error > {
149
163
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") ) ;
151
165
cmd. arg ( "es2019" ) ;
152
166
for f in files_to_check {
153
167
cmd. arg ( f) ;
0 commit comments