Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spawn-default-shell

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spawn-default-shell - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

appveyor.yml

6

package.json
{
"name": "spawn-default-shell",
"version": "1.0.0",
"version": "1.1.0",
"description": "Spawn shell command with platform default shell",

@@ -31,2 +31,3 @@ "main": "src/index.js",

"eslint-plugin-import": "^1.15.0",
"lodash": "^4.16.2",
"mocha": "^3.0.2",

@@ -36,5 +37,6 @@ "releasor": "^1.2.1"

"scripts": {
"test": "mocha",
"test": "npm run test-debug-print && mocha",
"test-debug-print": "node -e \"var a = require('./src/get-shell')(); console.log('> getShell()\\n' + JSON.stringify(a, null, 2));\"",
"lint": "eslint ./src ./test"
}
}

@@ -5,5 +5,10 @@ # spawn-default-shell

Like `child_process.spawn` but with shell benefits. You can just pass the command
as a string, and it will be executed in the platform default shell.
[![Build Status](https://travis-ci.org/kimmobrunfeldt/spawn-default-shell.svg?branch=master)](https://travis-ci.org/kimmobrunfeldt/spawn-default-shell) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/kimmobrunfeldt/spawn-default-shell?branch=master&svg=true)](https://ci.appveyor.com/project/kimmobrunfeldt/spawn-default-shell) *master branch status*
[![NPM Badge](https://nodei.co/npm/spawn-default-shell.png?downloads=true)](https://www.npmjs.com/package/spawn-default-shell)
Like `child_process.spawn` with `shell: true` option but a bit more
convenient and customizable. You can just pass the command as a string,
and it will be executed in the platform default shell. Used in [concurrently](https://github.com/kimmobrunfeldt/concurrently).
```js

@@ -10,0 +15,0 @@ // If we are in Linux / Mac, this will work

@@ -1,21 +0,38 @@

function getShell() {
const env = process.env;
const DETECT_CMD_REGEX = /cmd.exe/;
// All sh variant names I found end with "sh":
// https://en.wikipedia.org/wiki/List_of_command-line_interpreters
const DETECT_SH_REGEX = /sh$/;
function detectPlatformShell() {
if (process.platform === 'darwin') {
return {
shell: env.SHELL || '/bin/bash',
executeFlag: env.SHELL_EXECUTE_FLAG || '-c',
};
return process.env.SHELL || '/bin/bash';
}
if (process.platform === 'win32') {
return {
shell: env.SHELL || env.COMSPEC || 'cmd.exe',
executeFlag: env.SHELL_EXECUTE_FLAG || '/c',
};
return process.env.SHELL || process.env.COMSPEC || 'cmd.exe';
}
return process.env.SHELL || '/bin/sh';
}
function detectExecuteFlag(shell) {
if (process.env.SHELL_EXECUTE_FLAG) {
return process.env.SHELL_EXECUTE_FLAG;
}
if (shell.match(DETECT_CMD_REGEX)) {
return '/c';
} else if (shell.match(DETECT_SH_REGEX)) {
return '-c';
}
throw new Error('Unable to detect platform shell type. Please set SHELL_EXECUTE_FLAG env variable.');
}
function getShell() {
const shell = detectPlatformShell();
return {
shell: env.SHELL || '/bin/sh',
executeFlag: env.SHELL_EXECUTE_FLAG || '-c',
shell: shell,
executeFlag: detectExecuteFlag(shell),
};

@@ -22,0 +39,0 @@ }

@@ -15,3 +15,3 @@ const childProcess = require('child_process');

module.exports = {
spawn: spawn
spawn: spawn,
};

@@ -1,19 +0,26 @@

const assert = require('assert');
const defaultShell = require('../src/index');
const _ = require('lodash');
const testBasic = require('./test-basic');
const testPlatformShared = require('./test-platform-shared');
const PLATFORMS = ['darwin', 'freebsd', 'linux', 'sunos', 'win32'];
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
describe('spawn-default-shell', () => {
it('piping should work', (done) => {
const child = defaultShell.spawn('cat test/data/test.txt | grep 1', {
stdio: 'pipe',
});
testBasic();
});
child.stdout.on('data', (data) => {
assert.strictEqual(data.toString('utf8'), '1 äö☃\n');
});
describe('shared tests on each platform (mocking)', () => {
_.each(PLATFORMS, (platform) => {
describe(`process.platform = "${platform}"`, () => {
before(() => {
Object.defineProperty(process, 'platform', { value: platform });
});
child.on('close', (code) => {
assert.strictEqual(code, 0);
done();
after(() => {
Object.defineProperty(process, 'platform', originalPlatform);
});
testPlatformShared();
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc