Skip to content

Commit

Permalink
[INTERNAL] commands/base.js: Make module name guessing more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Oct 14, 2019
1 parent 347e1f1 commit d72e433
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/cli/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ cli.usage("Usage: ui5 <command> [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];
Expand All @@ -60,7 +64,7 @@ cli.usage("Usage: ui5 <command> [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(
Expand Down
10 changes: 6 additions & 4 deletions test/lib/cli/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand All @@ -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");
});

0 comments on commit d72e433

Please sign in to comment.