Skip to content

Commit

Permalink
Allow functions as shorthand commands (#118)
Browse files Browse the repository at this point in the history
The documentation declares `command` as being of type string or Function, and states that it can be "omitted by directly setting the target with the command". It made me believe that I could directly pass a function as a target, but this actually only works for strings. This PR allows passing a function as target and omitting `command`.
  • Loading branch information
teogeos authored and sindresorhus committed Dec 22, 2018
1 parent 32cac78 commit 86680b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"xo": "*"
"xo": "0.20.3"
},
"peerDependencies": {
"grunt": ">=0.4.0"
Expand Down
6 changes: 4 additions & 2 deletions tasks/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ module.exports = grunt => {
}
});

let cmd = typeof this.data === 'string' ? this.data : this.data.command;
let cmd = typeof this.data === 'string' || typeof this.data === 'function' ?
this.data :
this.data.command;

if (cmd === undefined) {
throw new Error('`command` required');
}

// increase max buffer
// Increase max buffer
opts.execOptions = Object.assign({}, opts.execOptions);
opts.execOptions.maxBuffer = opts.execOptions.maxBuffer || TEN_MEGABYTES;

Expand Down

0 comments on commit 86680b4

Please sign in to comment.