From c5d3b7396fc94df8c5221600810975e97ba1f9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20L=C3=B6chle?= Date: Sat, 23 Feb 2019 07:43:23 +0100 Subject: [PATCH] fix: wrong script execution (#194) --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- src/__tests__/get-script-to-run.js | 8 ++++++++ src/get-script-to-run.js | 13 +++++++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 234ef9f..407a46c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -398,6 +398,15 @@ "bug", "code" ] + }, + { + "login": "schottilol", + "name": "Florian LΓΆchle", + "avatar_url": "https://avatars3.githubusercontent.com/u/28313487?v=4", + "profile": "https://github.com/schottilol", + "contributions": [ + "code" + ] } ], "repoType": "github" diff --git a/README.md b/README.md index ad6908f..075557b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ All the benefits of npm scripts without the cost of a bloated package.json and l [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][LICENSE] -[![All Contributors](https://img.shields.io/badge/all_contributors-39-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-40-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -489,7 +489,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Sorin Muntean](https://github.com/sxn)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=sxn "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=sxn "Tests") [πŸ“–](https://github.com/kentcdodds/p-s/commits?author=sxn "Documentation") | [
Keith Gunn](https://github.com/gunnx)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Agunnx "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=gunnx "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=gunnx "Tests") | [
Joe Martella](http://martellaj.github.io)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Amartellaj "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=martellaj "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=martellaj "Tests") | [
Martin Segado](https://github.com/msegado)
[πŸ“–](https://github.com/kentcdodds/p-s/commits?author=msegado "Documentation") | [
Bram Borggreve](http://colmena.io/)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Abeeman "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=beeman "Code") | [
Elijah Manor](http://elijahmanor.com)
[πŸ“Ή](#video-elijahmanor "Videos") | [
Ragu Ramaswamy](https://github.com/rrag)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=rrag "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=rrag "Tests") [πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Arrag "Bug reports") | | [
Erik Fox](http://www.erikfox.co/)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Aerikfox "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=erikfox "Code") [πŸ“–](https://github.com/kentcdodds/p-s/commits?author=erikfox "Documentation") [⚠️](https://github.com/kentcdodds/p-s/commits?author=erikfox "Tests") | [
Aditya Pratap Singh](http://blog.adityapsingh.com)
[πŸ‘€](#review-addityasingh "Reviewed Pull Requests") | [
bumbleblym](https://github.com/bumbleblym)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=bumbleblym "Code") [πŸ“–](https://github.com/kentcdodds/p-s/commits?author=bumbleblym "Documentation") | [
Islam Attrash](https://twitter.com/IslamAttrash)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=Attrash-Islam "Code") | [
JasonSooter](https://github.com/JasonSooter)
[πŸ“–](https://github.com/kentcdodds/p-s/commits?author=JasonSooter "Documentation") | [
Nate Cavanaugh](http://alterform.com)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=natecavanaugh "Code") | [
Wissam Abirached](https://designingforscale.com)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=wabirached "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=wabirached "Tests") | | [
PaweΕ‚ MikoΕ‚ajczyk](https://github.com/Miklet)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=Miklet "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=Miklet "Tests") | [
Kyle Welch](http://www.krwelch.com)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=kwelch "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=kwelch "Tests") | [
Lufty Wiranda](http://instagram.com/luftywiranda13)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=luftywiranda13 "Code") | [
Bhargav Ponnapalli](http://imbhargav5.com)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=imbhargav5 "Code") | [
falieson](https://github.com/Falieson)
[πŸ“–](https://github.com/kentcdodds/p-s/commits?author=Falieson "Documentation") [πŸ”§](#tool-Falieson "Tools") | [
Suhas Karanth](https://github.com/sudo-suhas)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Asudo-suhas "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=sudo-suhas "Code") | [
Eric Skram](http://www.ericskram.com)
[πŸ“–](https://github.com/kentcdodds/p-s/commits?author=Vpr99 "Documentation") | -| [
Kether Saturnius](http://www.k3th3r.com)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=iamkether "Code") [πŸ“–](https://github.com/kentcdodds/p-s/commits?author=iamkether "Documentation") | [
Sviatoslav](https://github.com/SleepWalker)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3ASleepWalker "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=SleepWalker "Code") | [
Wei Wang](https://github.com/onlywei)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=onlywei "Code") | [
Sami Jaber](http://twitter.com/samjabz)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Asamijaber "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=samijaber "Code") | +| [
Kether Saturnius](http://www.k3th3r.com)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=iamkether "Code") [πŸ“–](https://github.com/kentcdodds/p-s/commits?author=iamkether "Documentation") | [
Sviatoslav](https://github.com/SleepWalker)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3ASleepWalker "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=SleepWalker "Code") | [
Wei Wang](https://github.com/onlywei)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=onlywei "Code") | [
Sami Jaber](http://twitter.com/samjabz)
[πŸ›](https://github.com/kentcdodds/p-s/issues?q=author%3Asamijaber "Bug reports") [πŸ’»](https://github.com/kentcdodds/p-s/commits?author=samijaber "Code") | [
Florian LΓΆchle](https://github.com/schottilol)
[πŸ’»](https://github.com/kentcdodds/p-s/commits?author=schottilol "Code") | This project follows the [all-contributors][all-contributors] specification. diff --git a/src/__tests__/get-script-to-run.js b/src/__tests__/get-script-to-run.js index a73ec88..10cd504 100644 --- a/src/__tests__/get-script-to-run.js +++ b/src/__tests__/get-script-to-run.js @@ -51,3 +51,11 @@ test('fallsback to `default` if no prefix is found', () => { }) expect(script).toEqual({scriptName: 'foo.dee', script: 'echo "dee"'}) }) + +test('finds the right script if the names are similar', () => { + const script = getScriptToRun( + {testX: 'stuff', test: 'moreStuff', btest: 'buildStuff'}, + 'test', + ) + expect(script).toEqual({scriptName: 'test', script: 'moreStuff'}) +}) diff --git a/src/get-script-to-run.js b/src/get-script-to-run.js index bbc2b02..9b3c2b8 100644 --- a/src/get-script-to-run.js +++ b/src/get-script-to-run.js @@ -21,8 +21,17 @@ function getScriptToRun(config, input) { } function getScript(config, input) { - const [script] = prefixMatches(input, config) - if (script) { + // will always return an empty array if no result where found + const matchingScripts = prefixMatches(input, config) + + if (matchingScripts.length !== 0) { + const script = matchingScripts.reduce((script, possibleScript) => { + if (possibleScript[input]) { + return possibleScript + } + return script + }) + const scriptName = Object.keys(script).shift() let scriptToRun = script[scriptName] if (scriptName && isPlainObject(scriptToRun)) {