Skip to content

Commit

Permalink
fix: bugfix for wildcard naming open-cli-tools#211
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Jan 6, 2020
1 parent 84ba2de commit bb7c815
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/command-parser/expand-npm-wildcard.js
Expand Up @@ -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);
}
};
2 changes: 1 addition & 1 deletion src/command-parser/expand-npm-wildcard.spec.js
Expand Up @@ -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` },
]);
});
Expand Down

0 comments on commit bb7c815

Please sign in to comment.