From bb7c815d7f0e557afcf86334652ae895f8104c5d Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Mon, 6 Jan 2020 07:38:53 -0500 Subject: [PATCH] fix: bugfix for wildcard naming #211 --- src/command-parser/expand-npm-wildcard.js | 18 +++++++++++++----- src/command-parser/expand-npm-wildcard.spec.js | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/command-parser/expand-npm-wildcard.js b/src/command-parser/expand-npm-wildcard.js index 02ff9511..edd635f1 100644 --- a/src/command-parser/expand-npm-wildcard.js +++ b/src/command-parser/expand-npm-wildcard.js @@ -25,10 +25,18 @@ module.exports = class ExpandNpmWildcard { const wildcardRegex = new RegExp(`^${preWildcard}(.*?)${postWildcard}$`); return this.scripts - .filter(script => wildcardRegex.test(script)) - .map(script => Object.assign({}, commandInfo, { - command: `${npmCmd} run ${script}${args}`, - name: script - })); + .map(script => { + const match = script.match(wildcardRegex); + + if (match) { + return Object.assign({}, commandInfo, { + command: `${npmCmd} run ${script}${args}`, + // Use the wildcard portion of the script match unless it's empty, + // in which case use the full name of the script + name: match[1] || script + }); + } + }) + .filter(Boolean); } }; diff --git a/src/command-parser/expand-npm-wildcard.spec.js b/src/command-parser/expand-npm-wildcard.spec.js index 940d475c..51af280d 100644 --- a/src/command-parser/expand-npm-wildcard.spec.js +++ b/src/command-parser/expand-npm-wildcard.spec.js @@ -42,7 +42,7 @@ for (const npmCmd of ['npm', 'yarn']) { }); expect(parser.parse({ command: `${npmCmd} run foo-*-baz qux` })).toEqual([ - { name: 'foo-bar-baz', command: `${npmCmd} run foo-bar-baz qux` }, + { name: 'bar', command: `${npmCmd} run foo-bar-baz qux` }, { name: 'foo--baz', command: `${npmCmd} run foo--baz qux` }, ]); });