@@ -19,6 +19,16 @@ const (
19
19
goimportsVersion = "v0.22.0"
20
20
goimportsPkg = "golang.org/x/tools/cmd/goimports@" + goimportsVersion
21
21
22
+ // For JS tools like eslint and prettier, these versions need to match the ones in the
23
+ // `package.json` file. To update to a new version, run a command like this:
24
+ //
25
+ // npm install --save-dev --save-exact [email protected]
26
+ //
27
+ // Then update the version in this file as well.
28
+
29
+ // This is the latest version to support a YAML config file. Updating to
30
+ // the new config file syntax did not seem trivial.
31
+ eslintVersion = "8.57.0"
22
32
golangCILintVersion = "1.59.1"
23
33
golinesVersion = "0.12.2"
24
34
gosecVersion = "2.20.0"
@@ -46,7 +56,7 @@ func SAInstallDevTools(ctx *task.Context) error {
46
56
if err := installPrecious (ctx ); err != nil {
47
57
return err
48
58
}
49
- return installPrettier (ctx )
59
+ return installJSTools (ctx )
50
60
}
51
61
52
62
// Install goimports.
@@ -251,28 +261,55 @@ func installBinaryTool(
251
261
)
252
262
}
253
263
254
- func installPrettier (ctx * task.Context ) error {
264
+ // We have to install all the JS tools at once. If we run `npm install <tool>` multiple times, each
265
+ // execution wipes the entire `node_modules` directory, so we only end up with one tool (the last
266
+ // one) installed.
267
+ func installJSTools (ctx * task.Context ) error {
268
+ eslint , err := eslintPath ()
269
+ if err != nil {
270
+ return err
271
+ }
272
+
273
+ exists , err := executableExistsWithVersion (ctx , eslint , eslintVersion )
274
+ if err != nil {
275
+ return err
276
+ }
277
+ if ! exists {
278
+ return runNPMInstall (ctx )
279
+ }
280
+
255
281
prettier , err := prettierPath ()
256
282
if err != nil {
257
283
return err
258
284
}
259
285
260
- exists , err : = executableExistsWithVersion (ctx , prettier , prettierVersion )
286
+ exists , err = executableExistsWithVersion (ctx , prettier , prettierVersion )
261
287
if err != nil {
262
288
return err
263
289
}
264
290
if exists {
265
291
return nil
266
292
}
267
293
294
+ return runNPMInstall (ctx )
295
+ }
296
+
297
+ func runNPMInstall (ctx * task.Context ) error {
268
298
return sh .Run (
269
299
ctx ,
270
300
"npm" , "install" ,
271
- "--no-save" ,
272
- fmt .Sprintf ("prettier@%s" , prettierVersion ),
273
301
)
274
302
}
275
303
304
+ func eslintPath () (string , error ) {
305
+ root , err := repoRoot ()
306
+ if err != nil {
307
+ return "" , err
308
+ }
309
+
310
+ return filepath .Join (root , "node_modules" , ".bin" , "eslint" ), nil
311
+ }
312
+
276
313
func prettierPath () (string , error ) {
277
314
root , err := repoRoot ()
278
315
if err != nil {
0 commit comments