Skip to content

Commit

Permalink
fix: support any executable in the shell, not just node scripts (#2)
Browse files Browse the repository at this point in the history
* fix: use Github Actions, remove Travis
  • Loading branch information
shazron authored Nov 9, 2020
1 parent b742a0e commit 867f65d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ governing permissions and limitations under the License.

[![Version](https://img.shields.io/npm/v/@adobe/aio-run-detached.svg)](https://npmjs.org/package/@adobe/aio-run-detached)
[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-run-detached.svg)](https://npmjs.org/package/@adobe/aio-run-detached)
[![Build Status](https://travis-ci.com/adobe/aio-run-detached.svg?branch=master)](https://travis-ci.com/adobe/aio-run-detached)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
![Node.js CI](https://github.com/adobe/aio-run-detached/workflows/Node.js%20CI/badge.svg)[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-run-detached/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-run-detached/)

# @adobe/aio-run-detached
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const { fork } = require('child_process')
const { spawn } = require('child_process')
const { lookpath } = require('lookpath')
const npmRunPath = require('npm-run-path')
const debug = require('debug')('aio-run-detached')
Expand Down Expand Up @@ -68,9 +68,10 @@ async function run (args = []) {
const errFile = startLog(`${args[0]}.err.log`)

debug(`Running command detached: ${JSON.stringify(args)}`)
const child = fork(commandPath, args.slice(1), {
const child = spawn(commandPath, args.slice(1), {
detached: true,
windowsHide: true,
shell: true,
stdio: [
'ignore',
outFile.fd,
Expand Down
10 changes: 5 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jest.mock('fs')
jest.mock('child_process')
jest.mock('lookpath')

const { fork } = require('child_process')
const { spawn } = require('child_process')
const { lookpath } = require('lookpath')
const fs = require('fs')
const path = require('path')
Expand Down Expand Up @@ -32,7 +32,7 @@ test('run (with args, process.send available)', async () => {
pid,
unref: jest.fn()
}
fork.mockReturnValueOnce(forkMockReturn)
spawn.mockReturnValueOnce(forkMockReturn)
lookpath.mockReturnValueOnce('my/path')

const args = ['command', 'arg1']
Expand Down Expand Up @@ -61,7 +61,7 @@ test('run (with args, process.send not available)', async () => {
pid,
unref: jest.fn()
}
fork.mockReturnValueOnce(forkMockReturn)
spawn.mockReturnValueOnce(forkMockReturn)
lookpath.mockReturnValueOnce('my/path')

const args = ['command', 'arg1']
Expand All @@ -78,7 +78,7 @@ test('run (with args, logs folder exists)', async () => {
pid,
unref: jest.fn()
}
fork.mockReturnValueOnce(forkMockReturn)
spawn.mockReturnValueOnce(forkMockReturn)
lookpath.mockReturnValueOnce('my/path')
fs.existsSync.mockReturnValueOnce(true)

Expand All @@ -98,6 +98,6 @@ test('run (with args, command not found or not executable)', async () => {
await expect(index.run(args))
.rejects.toEqual(new Error(`Command "${args[0]}" was not found in the path, or is not executable.`))

expect(fork).not.toHaveBeenCalled()
expect(spawn).not.toHaveBeenCalled()
expect(lookpath).toHaveBeenCalled()
})

0 comments on commit 867f65d

Please sign in to comment.