Merge pull request #1292 from balena-io/1291-regex-s-flag

Fix 'npm help' SyntaxError on Node 8 (invalid 's' regex flag)
This commit is contained in:
Paulo Castro 2019-06-05 16:35:08 +01:00 committed by GitHub
commit f75ffb53f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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], '.'));
}