From 7050e536b8146deb8a22b5006ab1da51451a7c9f Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Sun, 14 Feb 2021 21:17:38 -0300 Subject: [PATCH] Pass destinationRoot to spawn-command by default. --- lib/actions/spawn-command.js | 15 ++++++++++----- test/spawn-command.js | 12 ++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/actions/spawn-command.js b/lib/actions/spawn-command.js index 932a1b3e..7d714fd7 100644 --- a/lib/actions/spawn-command.js +++ b/lib/actions/spawn-command.js @@ -1,5 +1,4 @@ 'use strict'; -const _ = require('lodash'); const spawn = require('execa'); /** @@ -17,8 +16,11 @@ const spawnCommand = module.exports; * @return {String} spawned process reference */ spawnCommand.spawnCommand = (command, args, opt) => { - opt = opt || {}; - return spawn(command, args, _.defaults(opt, {stdio: 'inherit'})); + return spawn(command, args, { + stdio: 'inherit', + cwd: this.destinationRoot(), + ...opt + }); }; /** @@ -30,6 +32,9 @@ spawnCommand.spawnCommand = (command, args, opt) => { * @return {String} spawn.sync result */ spawnCommand.spawnCommandSync = (command, args, opt) => { - opt = opt || {}; - return spawn.sync(command, args, _.defaults(opt, {stdio: 'inherit'})); + return spawn.sync(command, args, { + stdio: 'inherit', + cwd: this.destinationRoot(), + ...opt + }); }; diff --git a/test/spawn-command.js b/test/spawn-command.js index d812819e..10d8fe8d 100644 --- a/test/spawn-command.js +++ b/test/spawn-command.js @@ -3,18 +3,23 @@ const proxyquire = require('proxyquire'); const sinon = require('sinon'); describe('generators.Base (actions/spawn-command)', () => { + let cwd; + beforeEach(function () { this.crossSpawn = sinon.spy(); this.crossSpawn.sync = sinon.spy(); this.spawn = proxyquire('../lib/actions/spawn-command', { execa: this.crossSpawn }); + cwd = Math.random().toString(36).slice(7); + this.spawn.destinationRoot = sinon.stub().returns(cwd); }); describe('#spawnCommand()', () => { it('provide default options', function () { this.spawn.spawnCommand('foo'); sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, { + cwd, stdio: 'inherit' }); }); @@ -22,6 +27,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('pass arguments', function () { this.spawn.spawnCommand('foo', 'bar'); sinon.assert.calledWith(this.crossSpawn, 'foo', 'bar', { + cwd, stdio: 'inherit' }); }); @@ -29,6 +35,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('pass options', function () { this.spawn.spawnCommand('foo', undefined, {foo: 1}); sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, { + cwd, foo: 1, stdio: 'inherit' }); @@ -37,6 +44,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('allow overriding default options', function () { this.spawn.spawnCommand('foo', undefined, {stdio: 'ignore'}); sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, { + cwd, stdio: 'ignore' }); }); @@ -46,6 +54,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('provide default options', function () { this.spawn.spawnCommandSync('foo'); sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, { + cwd, stdio: 'inherit' }); }); @@ -53,6 +62,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('pass arguments', function () { this.spawn.spawnCommandSync('foo', 'bar'); sinon.assert.calledWith(this.crossSpawn.sync, 'foo', 'bar', { + cwd, stdio: 'inherit' }); }); @@ -60,6 +70,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('pass options', function () { this.spawn.spawnCommandSync('foo', undefined, {foo: 1}); sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, { + cwd, foo: 1, stdio: 'inherit' }); @@ -68,6 +79,7 @@ describe('generators.Base (actions/spawn-command)', () => { it('allow overriding default options', function () { this.spawn.spawnCommandSync('foo', undefined, {stdio: 'wut'}); sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, { + cwd, stdio: 'wut' }); });