From 1581b3dee1ab13f3ef47168fdbe058a38aef1e81 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Mon, 14 Oct 2019 14:44:26 +0200 Subject: [PATCH] [INTERNAL] commands/base.js: Make module name guessing more robust --- lib/cli/commands/base.js | 8 ++++++-- test/lib/cli/commands/base.js | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/cli/commands/base.js b/lib/cli/commands/base.js index 7a7bfe27..555bf255 100644 --- a/lib/cli/commands/base.js +++ b/lib/cli/commands/base.js @@ -49,7 +49,11 @@ cli.usage("Usage: ui5 [options]") console.log(err.stack); // Try to guess responsible module from stack trace file paths - const moduleRegExp = /@?ui5.(?:logger|fs|builder|server|project|cli)/ig; + // This should work for the following paths: + // - @ui5/cli (npm consumption) + // - ui5-cli (local repository consumption) + // - lib/cli (local consumption without repository name in path, i.e. Azure CI) + const moduleRegExp = /@?(?:ui5|lib).(?:logger|fs|builder|server|project|cli)/ig; // Only check the lowest stack entry const rootStackEntry = err.stack.split("\n")[1]; @@ -60,7 +64,7 @@ cli.usage("Usage: ui5 [options]") let moduleNameGuess = match[match.length - 1]; // Normalize match - moduleNameGuess = moduleNameGuess.replace(/.*(ui5).(.*)/i, "$1-$2").toLowerCase(); + moduleNameGuess = moduleNameGuess.replace(/.*(?:ui5|lib).(.*)/i, "ui5-$1").toLowerCase(); const newIssueUrl = `https://github.com/SAP/${moduleNameGuess}/issues/new`; console.log(""); console.log( diff --git a/test/lib/cli/commands/base.js b/test/lib/cli/commands/base.js index 822964d9..05b5b508 100644 --- a/test/lib/cli/commands/base.js +++ b/test/lib/cli/commands/base.js @@ -39,7 +39,8 @@ test("Exception error handling", async (t) => { t.deepEqual(stdoutLines[3], "Error Message:", "Correct error log"); t.deepEqual(stdoutLines[4], "Initialization not possible: ui5.yaml already exists", "Correct error log"); t.deepEqual(stdoutLines[stdoutLines.length - 1], - "For details, execute the same command again with an additional '--verbose' parameter", "Correct error log"); + "For details, execute the same command again with an additional '--verbose' parameter", + "Correct last log line"); t.deepEqual(err.exitCode, 1, "Process was exited with code 1"); }); @@ -59,9 +60,10 @@ test("Exception error handling with verbose logging", async (t) => { t.deepEqual(stdoutLines[6], "Stack Trace:", "Correct error log"); t.deepEqual(stdoutLines[7], "Error: Initialization not possible: ui5.yaml already exists", "Correct error log"); - t.deepEqual(stdoutLines[stdoutLines.length - 1], `If you think this is an issue of the UI5 Tooling, you might ` + - `report it using the following URL: https://github.com/SAP/ui5-cli/issues/new`, - "Correct last log line"); + t.deepEqual(stdoutLines[stdoutLines.length - 1], + "If you think this is an issue of the UI5 Tooling, you might " + + "report it using the following URL: https://github.com/SAP/ui5-cli/issues/new", + "Correct last log line"); t.deepEqual(err.exitCode, 1, "Process was exited with code 1"); });