Skip to content

Commit 413b175

Browse files
committed
fix: execa call with args
1 parent 73d6bf4 commit 413b175

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

bin/commit-message-install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function commitMessageInstall (cliArguments) {
4949
stdio: 'inherit',
5050
shell: true
5151
}
52-
return utils.callExeca(args.else, options)
52+
return utils.callExeca(args.else, [], options)
5353
}
5454
return
5555
}

src/commit-message-install-spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe.only('commit-message-install', () => {
2020

2121
context('gets last commit message', () => {
2222
beforeEach(() => {
23-
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, { shell: true }).resolves({
23+
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, [], { shell: true }).resolves({
2424
exitCode: 0,
2525
stdout: 'message body',
2626
stderr: ''
@@ -40,7 +40,7 @@ describe.only('commit-message-install', () => {
4040
const sha = '3d243ea'
4141
beforeEach(() => {
4242
const cmd = getMessageGitCommand + ' ' + sha
43-
sandbox.stub(utils, 'callExeca').withArgs(cmd, { shell: true }).resolves({
43+
sandbox.stub(utils, 'callExeca').withArgs(cmd, [], { shell: true }).resolves({
4444
exitCode: 0,
4545
stdout: 'message body',
4646
stderr: ''
@@ -71,7 +71,7 @@ describe.only('commit-message-install', () => {
7171
}
7272
\`\`\`
7373
`
74-
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, { shell: true }).resolves({
74+
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, [], { shell: true }).resolves({
7575
exitCode: 0,
7676
stdout: message,
7777
stderr: ''
@@ -97,7 +97,7 @@ describe.only('commit-message-install', () => {
9797
const json = toMarkdownJsonBlock(info)
9898
const message = `some text\n\n` + json
9999

100-
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, { shell: true }).resolves({
100+
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, [], { shell: true }).resolves({
101101
exitCode: 0,
102102
stdout: message,
103103
stderr: ''
@@ -110,7 +110,7 @@ describe.only('commit-message-install', () => {
110110

111111
it('returns undefined without valid block', () => {
112112
const message = 'this message has no json code'
113-
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, { shell: true }).resolves({
113+
sandbox.stub(utils, 'callExeca').withArgs(getMessageGitCommand, [], { shell: true }).resolves({
114114
exitCode: 0,
115115
stdout: message,
116116
stderr: ''
@@ -126,11 +126,11 @@ describe.only('commit-message-install', () => {
126126
const commitMessageInstall = require('../bin/commit-message-install')
127127

128128
beforeEach(() => {
129-
sandbox.stub(utils, 'callExeca').withArgs('git show -s --pretty=%b', { shell: true }).resolves({
129+
sandbox.stub(utils, 'callExeca').withArgs('git show -s --pretty=%b', [], { shell: true }).resolves({
130130
exitCode: 0,
131131
stdout: 'nothing to do',
132132
stderr: ''
133-
}).withArgs('echo cool', { shell: true, stdio: 'inherit' }).resolves({
133+
}).withArgs('echo cool', [], { shell: true, stdio: 'inherit' }).resolves({
134134
exitCode: 0,
135135
stdout: 'cool is working',
136136
stderr: ''

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
// @ts-check
23

34
const debug = require('debug')('commit-message-install')
45
const la = require('lazy-ass')
@@ -18,7 +19,7 @@ function getMessage (sha) {
1819
? currentMessageCommand + ' ' + sha
1920
: currentMessageCommand
2021
debug('git command "%s"', cmd)
21-
return utils.callExeca(cmd, { shell: true }).then(prop('stdout'))
22+
return utils.callExeca(cmd, [], { shell: true }).then(prop('stdout'))
2223
}
2324

2425
// parses given commit message text (body)
@@ -191,7 +192,7 @@ function runIf (command, json) {
191192
stdio: 'inherit',
192193
shell: true
193194
}
194-
return utils.callExeca(command, options)
195+
return utils.callExeca(command, [], options)
195196
}
196197

197198
function npmInstall (json) {

src/utils.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ const toMarkdownJsonBlock = object => {
3333
}
3434

3535
/**
36-
* Little utility function to make stubbing "execa" easier
37-
*/
38-
const callExeca = (cmd, options = {}) => {
36+
* Little utility function to make stubbing "execa" easier.
37+
* @param {string} cmd Command to run
38+
* @param {readonly string[]} args List of arguments
39+
* @param {object} options Child process options
40+
*/
41+
const callExeca = (cmd, args, options) => {
3942
la(is.unemptyString(cmd), 'missing command to execute', cmd)
40-
return execa(cmd, options)
43+
la(is.strings(args), 'arguments should be a list of string', args)
44+
la(is.object(options), 'options should be an object', options)
45+
return execa(cmd, args, options)
4146
}
4247

4348
module.exports = {

0 commit comments

Comments
 (0)