diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index e2fd07682c..8be94a9ea3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -34,7 +34,11 @@ class NpmProcess { } void install() { - npmAwait("install", "--no-audit", "--no-package-lock", "--prefer-offline"); + npmAwait("install", + "--no-audit", + "--no-package-lock", + "--no-fund", + "--prefer-offline"); } Process start() { diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js index 3e031cedea..c1c9d62757 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js @@ -1,4 +1,5 @@ -// this file will be glued to the top of the specific xy-server.js file +// this file will be glued to the top of the specific xy-serve.js file +const debug_serve = false; // set to true for debug log output in node process const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; const express = require("express"); const app = express(); @@ -7,8 +8,14 @@ app.use(express.json({ limit: "50mb" })); const fs = require("fs"); +function debugLog() { + if (debug_serve) { + console.log.apply(this, arguments) + } +} + var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); + debugLog("Server running on port " + listener.address().port); fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { if (err) { return console.log(err); @@ -26,7 +33,7 @@ const shutdownManager = new GracefulShutdownManager(listener); app.post("/shutdown", (req, res) => { res.status(200).send("Shutting down"); setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); + shutdownManager.terminate(() => debugLog("graceful shutdown finished.")); }, 200); }); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 1f1b1fab5a..8b60e56dc8 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -9,14 +9,14 @@ app.post("/eslint/format", async (req, res) => { const ESLintOverrideConfigFile = format_data.eslint_override_config_file; if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { - res.status(501).send("Error while formatting: No config provided"); + res.status(400).send("Error while formatting: No config provided"); return; } const filePath = format_data.file_path; if (!filePath) { - res.status(501).send("Error while formatting: No file path provided"); + res.status(400).send("Error while formatting: No file path provided"); return; } @@ -41,8 +41,8 @@ app.post("/eslint/format", async (req, res) => { eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig); } - console.log("using options: " + JSON.stringify(ESLintOptions)); - console.log("format input: ", format_data.file_content); + debugLog("using options: " + JSON.stringify(ESLintOptions)); + debugLog("format input: ", format_data.file_content); const eslint = new ESLint(ESLintOptions); @@ -50,18 +50,18 @@ app.post("/eslint/format", async (req, res) => { const lintTextOptions = { filePath: filePath, } - console.log("lintTextOptions", lintTextOptions); + debugLog("lintTextOptions", lintTextOptions); // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { - res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); + res.status(500).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); return; } const result = results[0]; - console.log("result: " + JSON.stringify(result)); + debugLog("result: " + JSON.stringify(result)); if (result.fatalErrorCount && result.fatalErrorCount > 0) { - res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages)); + res.status(500).send("Fatal error while formatting: " + JSON.stringify(result.messages)); return; } const formatted = result.output || result.source || format_data.file_content; @@ -69,6 +69,6 @@ app.post("/eslint/format", async (req, res) => { res.send(formatted); } catch (err) { console.log("error", err); - res.status(501).send("Error while formatting: " + err); + res.status(500).send("Error while formatting: " + err); } }); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js index d4ce13bbbc..b60daaaa77 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js @@ -27,7 +27,7 @@ app.post("/prettier/format", (req, res) => { try { formatted_file_content = prettier.format(format_data.file_content, format_data.config_options); } catch(err) { - res.status(501).send("Error while formatting: " + err); + res.status(500).send("Error while formatting: " + err); return; } res.set("Content-Type", "text/plain"); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js index 8ec25565ff..b9f20a1472 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js @@ -25,6 +25,6 @@ app.post("/tsfmt/format", (req, res) => { res.set("Content-Type", "text/plain"); res.send(resultMap.dest); }).catch(reason => { - res.status(501).send(reason); + res.status(500).send(reason); }); }); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 9db218efb5..acc756fa31 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -116,7 +116,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo( - "Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); + "Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } }