Fix 'npm help' SyntaxError on Node 8 (invalid 's' regex flag)

Change-type: patch
Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
Paulo Castro 2019-06-05 16:12:16 +01:00
parent e8325e8268
commit 3387f8f656

View File

@ -27,7 +27,9 @@ export function getOclifHelpLinePairs(): [[string, string]] {
function getCmdUsageDescriptionLinePair(cmd: typeof Command): [string, string] {
const usage = (cmd.usage || '').toString().toLowerCase();
let description = '';
const matches = /\s*(.+?)\n.*/s.exec(cmd.description || '');
// note: [^] matches any characters (including line breaks), achieving the
// same effect as the 's' regex flag which is only supported by Node 9+
const matches = /\s*([^]+?)\n[^]*/.exec(cmd.description || '');
if (matches && matches.length > 1) {
description = _.lowerFirst(_.trimEnd(matches[1], '.'));
}