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

ssh2-exec

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh2-exec - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

.github/workflows/publish.yml

2

CHANGELOG.md

@@ -5,2 +5,4 @@ # Changelog

### [0.7.4](https://github.com/adaltas/node-ssh2-exec/compare/v0.7.3...v0.7.4) (2023-11-19)
### [0.7.3](https://github.com/adaltas/node-ssh2-exec/compare/v0.7.2...v0.7.3) (2022-03-11)

@@ -7,0 +9,0 @@

module.exports = {
extends: [
"@commitlint/config-conventional"
]
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"refactor",
"revert",
"test",
],
],
},
};

188

lib/index.js

@@ -1,47 +0,55 @@

// Generated by CoffeeScript 2.6.1
// # Module `exec`
// `exec(sshOrNull, command, [options], [callback])`
// `exec(options..., [callback])`
var EventEmitter, exec, is_object, is_ssh_connection, local, remote, spawn, stream,
indexOf = [].indexOf;
const {exec, spawn} = require('node:child_process');
const {EventEmitter} = require('node:events');
const stream = require('node:stream');
({EventEmitter} = require('events'));
// Utilities
const is_ssh_connection = function(obj) {
return !!obj?.config?.host;
};
const is_object = function(obj) {
return obj && typeof obj === 'object' && !Array.isArray(obj);
};
stream = require('stream');
const local = module.exports.local = function(options, callback) {
const commandOptions = {};
commandOptions.env = options.env || process.env;
commandOptions.cwd = options.cwd || null;
if (options.uid) {
commandOptions.uid = options.uid;
}
if (options.gid) {
commandOptions.gid = options.gid;
}
if (options.stdio) {
commandOptions.stdio = options.stdio;
}
if (callback) {
return exec(options.command, commandOptions, function(err, stdout, stderr, ...args) {
if (err) {
let debug;
if (stderr.trim().length) {
debug = stderr.trim().split(/\r\n|[\n\r\u0085\u2028\u2029]/g)[0];
}
const {code, signal} = err;
err = Error(["Child process exited unexpectedly: ", `code ${JSON.stringify(err.code)}, `, err.signal ? `signal ${JSON.stringify(err.signal)}` : "no signal", debug ? `, got ${JSON.stringify(debug)}` : void 0].join(''));
err.code = code;
err.signal = signal;
}
callback(err, stdout, stderr, (err != null ? err.code : void 0) || 0, ...args);
});
} else {
return spawn(options.command, [], Object.assign(commandOptions, {
shell: options.shell || true
}));
}
};
({exec, spawn} = require('child_process'));
// ## Options
// * `ssh`
// SSH connection if the command must run remotely
// * `command`
// Command to run unless provided as first argument
// * `cwd`
// Current working directory
// * `end`
// Close the SSH connection on exit, default to true if an ssh connection
// instance is provided.
// * `env`
// An environment to use for the execution of the command.
// * `pty`
// Set to true to allocate a pseudo-tty with defaults, or an object containing
// specific pseudo-tty settings. Apply only to SSH remote commands.
// * `cwd`
// Apply only to local commands.
// * `uid`
// Apply only to local commands.
// * `gid`
// Apply only to local commands.
// ## Source Code
module.exports = function() {
var arg, args, callback, i, j, k, len, options, v;
args = [].slice.call(arguments);
options = {};
for (i = j = 0, len = args.length; j < len; i = ++j) {
arg = args[i];
if (arg === null || arg === void 0) {
if (indexOf.call(options, 'ssh') >= 0) {
module.exports = function(...args) {
let callback;
const options = {};
for (const i in args) {
const arg = args[i];
if (arg == null) {
if (options.ssh != null) {
throw Error(`Invalid Argument: argument ${i} cannot be null, the connection is already set`);

@@ -51,3 +59,3 @@ }

} else if (is_ssh_connection(arg)) {
if (indexOf.call(options, 'ssh') >= 0) {
if (options.ssh != null) {
throw Error(`Invalid Argument: argument ${i} cannot be an SSH connection, the connection is already set`);

@@ -61,8 +69,7 @@ }

}
for (k in arg) {
v = arg[k];
options[k] = v;
for (const k in arg) {
options[k] = arg[k];
}
} else if (typeof arg === 'string') {
if (indexOf.call(options, 'command') >= 0) {
if (options.command != null) {
throw Error(`Invalid Argument: argument ${i} cannot be a string, a command already exists`);

@@ -87,5 +94,4 @@ }

remote = module.exports.remote = function(options, callback) {
var child, commandOptions, stderr, stdout;
child = new EventEmitter();
const remote = module.exports.remote = function(options, callback) {
const child = new EventEmitter();
child.stdout = new stream.Readable();

@@ -100,10 +106,10 @@ child.stdout._read = function(_size) {};

// child.stream.end '\x03'
return child.stream.signal(signal);
child.stream.signal(signal);
}
};
stdout = stderr = '';
let stdout = stderr = '';
if (options.cwd) {
options.command = `cd ${options.cwd}; ${options.command}`;
}
commandOptions = {};
const commandOptions = {};
if (options.env) {

@@ -119,3 +125,2 @@ commandOptions.env = options.env;

options.ssh.exec(options.command, commandOptions, function(err, stream) {
var code, exit, exitCalled, signal, stderrCalled, stdoutCalled;
if (err && callback) {

@@ -131,3 +136,3 @@ return callback(err);

if (callback) {
return stderr += data;
stderr += data;
}

@@ -138,9 +143,8 @@ });

if (callback) {
return stdout += data;
stdout += data;
}
});
code = signal = null;
exitCalled = stdoutCalled = stderrCalled = false;
exit = function() {
var debug;
let code = signal = null;
let exitCalled = stdoutCalled = stderrCalled = false;
const exit = function() {
if (!(exitCalled && stdoutCalled && stderrCalled)) {

@@ -154,2 +158,3 @@ return;

if (code !== 0) {
let debug;
if (stderr.trim().length) {

@@ -165,7 +170,7 @@ debug = stderr.trim().split(/\r\n|[\n\r\u0085\u2028\u2029]/g)[0];

connection.on('error', function(err) {
return callback(err);
callback(err);
});
return connection.on('close', function() {
connection.on('close', function() {
if (callback) {
return callback(err, stdout, stderr, code);
callback(err, stdout, stderr, code);
}

@@ -175,3 +180,3 @@ });

if (callback) {
return callback(err, stdout, stderr, code);
callback(err, stdout, stderr, code);
}

@@ -181,3 +186,3 @@ }

stream.on('error', function(err) {
return console.error('error', err);
console.error('error', err);
});

@@ -187,11 +192,11 @@ stream.on('exit', function() {

[code, signal] = arguments;
return exit();
exit();
});
stream.on('end', function() {
stdoutCalled = true;
return exit();
exit();
});
return stream.stderr.on('end', function() {
stream.stderr.on('end', function() {
stderrCalled = true;
return exit();
exit();
});

@@ -201,46 +206,1 @@ });

};
local = module.exports.local = function(options, callback) {
var commandOptions;
commandOptions = {};
commandOptions.env = options.env || process.env;
commandOptions.cwd = options.cwd || null;
if (options.uid) {
commandOptions.uid = options.uid;
}
if (options.gid) {
commandOptions.gid = options.gid;
}
if (options.stdio) {
commandOptions.stdio = options.stdio;
}
if (callback) {
return exec(options.command, commandOptions, function(err, stdout, stderr, ...args) {
var code, debug, signal;
if (err) {
if (stderr.trim().length) {
debug = stderr.trim().split(/\r\n|[\n\r\u0085\u2028\u2029]/g)[0];
}
({code, signal} = err);
err = Error(["Child process exited unexpectedly: ", `code ${JSON.stringify(err.code)}, `, err.signal ? `signal ${JSON.stringify(err.signal)}` : "no signal", debug ? `, got ${JSON.stringify(debug)}` : void 0].join(''));
err.code = code;
err.signal = signal;
}
return callback(err, stdout, stderr, (err != null ? err.code : void 0) || 0, ...args);
});
} else {
return spawn(options.command, [], Object.assign(commandOptions, {
shell: options.shell || true
}));
}
};
// ## Utilities
is_ssh_connection = function(obj) {
var ref;
return !!(obj != null ? (ref = obj.config) != null ? ref.host : void 0 : void 0);
};
is_object = function(obj) {
return obj && typeof obj === 'object' && !Array.isArray(obj);
};
{
"name": "ssh2-exec",
"version": "0.7.3",
"description": "Transparent use of `child_process.exec` and `ssh2.prototype.exec`",
"version": "0.7.4",
"description": "Transparent usage between `child_process.exec` and `ssh2.prototype.exec`",
"keywords": [

@@ -9,3 +9,4 @@ "child process",

"ssh2",
"ssh"
"ssh",
"promise"
],

@@ -39,3 +40,3 @@ "homepage": "https://github.com/adaltas/node-ssh2-exec",

],
"timeout": 40000,
"timeout": 5000,
"reporter": "spec",

@@ -55,12 +56,11 @@ "recursive": true

"devDependencies": {
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@commitlint/cz-commitlint": "^16.2.1",
"coffeescript": "^2.6.1",
"husky": "^7.0.4",
"mocha": "^9.2.1",
"@commitlint/cli": "^18.4.2",
"@commitlint/config-conventional": "^18.4.2",
"coffeescript": "^2.7.0",
"husky": "^8.0.3",
"mocha": "^10.2.0",
"mocha-they": "^0.1.3",
"should": "^13.2.3",
"ssh2-connect": "^3.2.2",
"standard-version": "^9.3.2"
"ssh2-connect": "^3.4.1",
"standard-version": "^9.5.0"
},

@@ -71,12 +71,8 @@ "exports": {

},
"./promise": {
"require": "./lib/promise.js"
}
"./promise": "./lib/promises.js",
"./promises": "./lib/promises.js"
},
"optionalDependencies": {},
"scripts": {
"build": "coffee -b -o lib src",
"publish": "git push --follow-tags origin master && npm publish",
"prepare": "husky install",
"pretest": "npm run build",
"release": "standard-version",

@@ -86,4 +82,5 @@ "release:minor": "standard-version --release-as minor",

"release:major": "standard-version --release-as major",
"postrelease": "git push --follow-tags origin master",
"test": "mocha 'test/**/*.coffee'"
}
}

@@ -5,3 +5,3 @@ [![Build Status](https://secure.travis-ci.org/adaltas/node-ssh2-exec.svg)][travis]

The Node.js `ssh2-exec` package extends the [`ssh2`][ssh2] module to provide transparent usage between the `child_process.exec` and `ssh2.prototype.exec` functions.
The Node.js `ssh2-exec` package extends the [`ssh2`][ssh2] module to provide transparent usage between the `child_process.exec` and `ssh2.prototype.exec` functions. It was originally developped for and is still use by [Nikita](https://nikita.js.org) to run actions both locally and over SSH.

@@ -51,4 +51,6 @@ ## Installation

## `ssh2-exec/promise` module usage
## `ssh2-exec/promises` module usage
Note, until version `0.7.3`, the module was named `ssh2-exec/promise`. The `promise` resolution is still working. However, it will be removed in an upcoming version in favor of `ssh2-exec/promises` in order to be consistent with the Node.js `node:fs/promises` module.
The promise module is an alternative to the callback usage. Like with the callback, use it if `stdout` and `stderr` are not too large and fit in memory.

@@ -55,0 +57,0 @@

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