From 6a6e8cada0de6687ea534d8f6969a5634ec6f243 Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Mon, 2 Jul 2018 13:17:08 -0300 Subject: [PATCH] Fix benchmark require (#4792) --- src/cli/util.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cli/util.js b/src/cli/util.js index ac5db69c..497f35b9 100644 --- a/src/cli/util.js +++ b/src/cli/util.js @@ -200,11 +200,21 @@ function format(context, input, opt) { return { formatted: pp, filepath: opt.filepath || "(stdin)\n" }; } + /* istanbul ignore if */ if (context.argv["debug-benchmark"]) { + let benchmark; + try { + benchmark = eval("require")("benchmark"); + } catch (err) { + context.logger.debug( + "'--debug-benchmark' requires the 'benchmark' package to be installed." + ); + process.exit(2); + } context.logger.debug( "'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module." ); - const suite = new require("benchmark").Suite(); + const suite = new benchmark.Suite(); suite .add("format", () => { prettier.formatWithCursor(input, opt);