diff --git a/src/command-parser/expand-npm-wildcard.js b/src/command-parser/expand-npm-wildcard.js index 2c9d393f..d0ece2be 100644 --- a/src/command-parser/expand-npm-wildcard.js +++ b/src/command-parser/expand-npm-wildcard.js @@ -28,7 +28,7 @@ module.exports = class ExpandNpmWildcard { .filter(script => wildcardRegex.test(script)) .map(script => Object.assign({}, commandInfo, { command: `npm run ${script}${args}`, - name: script + name: (commandInfo.name || '') + script.match(wildcardRegex)[1] })); } }; diff --git a/src/command-parser/expand-npm-wildcard.spec.js b/src/command-parser/expand-npm-wildcard.spec.js index f07a5e6f..bd0b178c 100644 --- a/src/command-parser/expand-npm-wildcard.spec.js +++ b/src/command-parser/expand-npm-wildcard.spec.js @@ -40,8 +40,8 @@ it('expands to all scripts matching pattern', () => { }); expect(parser.parse({ command: 'npm run foo-*-baz qux' })).toEqual([ - { name: 'foo-bar-baz', command: 'npm run foo-bar-baz qux' }, - { name: 'foo--baz', command: 'npm run foo--baz qux' }, + { name: 'bar', command: 'npm run foo-bar-baz qux' }, + { name: '', command: 'npm run foo--baz qux' }, ]); }); @@ -52,3 +52,17 @@ it('caches scripts upon calls', () => { expect(readPkg).toHaveBeenCalledTimes(1); }); + +it('suffix name with wildcard values', () => { + readPkg.mockReturnValue({ + scripts: { + 'watch-foo': '', + 'watch-bar': '', + } + }); + + expect(parser.parse({ name: 'w:', command: 'npm run watch-*' })).toEqual([ + { name: 'w:foo', command: 'npm run watch-foo' }, + { name: 'w:bar', command: 'npm run watch-bar' }, + ]); +});