Comparing version 0.8.3 to 0.8.4
@@ -21,4 +21,4 @@ import * as childProcess from 'node:child_process'; | ||
declare function exec(ssh: Client | null, command: string, callback?: ExecCallback): childProcess.ChildProcess; | ||
declare function exec(ssh: Client | null, command: string, options: ExecOptions, callbac?: ExecCallback): childProcess.ChildProcess; | ||
declare function exec(ssh: Client | null, command: string, options: ExecOptions, callback?: ExecCallback): childProcess.ChildProcess; | ||
export { type ExecCallback, type ExecOptions, exec, local, remote }; | ||
export { type ExecCallback, type ExecOptions, exec as default, exec, local, remote }; |
@@ -1,1 +0,160 @@ | ||
import{a,b,c}from"./chunk-WQ2VQ4KN.js";export{c as exec,a as local,b as remote}; | ||
// src/index.ts | ||
import * as childProcess from "node:child_process"; | ||
import * as stream from "node:stream"; | ||
var local = function(options, callback) { | ||
options.env ??= process.env; | ||
if (callback) { | ||
return childProcess.exec( | ||
options.command, | ||
options, | ||
function(err, stdout, stderr) { | ||
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); | ||
} | ||
); | ||
} else { | ||
return childProcess.spawn( | ||
options.command, | ||
[], | ||
Object.assign(options, { | ||
shell: options.shell || true | ||
}) | ||
); | ||
} | ||
}; | ||
var remote = function(options, callback) { | ||
const child = new childProcess.ChildProcess(); | ||
child.stdout = new stream.Readable(); | ||
child.stdout._read = function() { | ||
}; | ||
child.stderr = new stream.Readable(); | ||
child.stderr._read = function() { | ||
}; | ||
child.kill = function(signal) { | ||
console.warn(`Not implemented, called kill ${signal}`); | ||
return true; | ||
}; | ||
let stdout = ""; | ||
let stderr = ""; | ||
if (options.cwd) { | ||
options.command = `cd ${options.cwd}; ${options.command}`; | ||
} | ||
options.ssh.exec(options.command, options, function(errArg, stream2) { | ||
if (errArg && callback) { | ||
return callback(errArg, "", "", NaN); | ||
} | ||
if (errArg) { | ||
return child.emit("error", errArg); | ||
} | ||
let err = null; | ||
stream2.stderr.on("data", function(data) { | ||
child.stderr?.push(data); | ||
stderr += data; | ||
}); | ||
stream2.on("data", function(data) { | ||
child.stdout?.push(data); | ||
stdout += data; | ||
}); | ||
let code = 0; | ||
let signal = null; | ||
let exitCalled = false; | ||
let stdoutCalled = false; | ||
let stderrCalled = false; | ||
const exit = function() { | ||
if (!(exitCalled && stdoutCalled && stderrCalled)) { | ||
return; | ||
} | ||
child.stdout?.push(null); | ||
child.stderr?.push(null); | ||
child.emit("close", code, signal); | ||
child.emit("exit", code, signal); | ||
if (code !== 0) { | ||
let debug; | ||
if (stderr.trim().length) { | ||
debug = stderr.trim().split(/\r\n|[\n\r\u0085\u2028\u2029]/g)[0]; | ||
} | ||
err = new Error( | ||
[ | ||
"Child process exited unexpectedly: ", | ||
`code ${JSON.stringify(code)}`, | ||
signal ? `, signal ${JSON.stringify(signal)}` : ", no signal", | ||
debug ? `, got ${JSON.stringify(debug)}` : void 0 | ||
].join("") | ||
); | ||
err.code = code; | ||
} | ||
if (options.end) { | ||
options.ssh.end(); | ||
options.ssh.on("error", function(err2) { | ||
callback(err2, "", "", NaN); | ||
}); | ||
options.ssh.on("close", function() { | ||
if (callback) { | ||
callback(err || null, stdout, stderr, code); | ||
} | ||
}); | ||
} else { | ||
if (callback) { | ||
callback(err || null, stdout, stderr, code); | ||
} | ||
} | ||
}; | ||
stream2.on("error", function(code2) { | ||
console.error("error", code2); | ||
}); | ||
stream2.on("exit", function(codeArg, signalArg) { | ||
exitCalled = true; | ||
code = codeArg; | ||
signal = signalArg; | ||
exit(); | ||
}); | ||
stream2.on("end", function() { | ||
stdoutCalled = true; | ||
exit(); | ||
}); | ||
stream2.stderr.on("end", function() { | ||
stderrCalled = true; | ||
exit(); | ||
}); | ||
}); | ||
return child; | ||
}; | ||
function exec2(arg1, arg2, arg3, arg4) { | ||
const options = arg3 !== void 0 ? ( | ||
// ssh and cmd separated | ||
typeof arg3 === "function" ? { ssh: arg1, command: arg2 } : arg3 | ||
) : arg1; | ||
const callback = arg3 !== void 0 ? ( | ||
// ssh and cmd separated | ||
typeof arg3 === "function" ? arg3 : arg4 | ||
) : arg2; | ||
if (options.ssh) { | ||
return remote(options, callback); | ||
} else { | ||
return local(options, callback); | ||
} | ||
} | ||
var src_default = exec2; | ||
export { | ||
src_default as default, | ||
exec2 as exec, | ||
local, | ||
remote | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,2 @@ import { Client } from 'ssh2'; | ||
export { exec }; | ||
export { exec as default, exec }; |
@@ -1,1 +0,182 @@ | ||
import{c as i}from"./chunk-WQ2VQ4KN.js";function E(o,n,c){let x=n?{ssh:o,command:n,...c}:o;return new Promise(function(l,p){i(x,function(e,s,t,m){e?(e.stdout=s,e.stderr=t,p(e)):l({stdout:s,stderr:t,code:m})})})}export{E as exec}; | ||
// src/index.ts | ||
import * as childProcess from "node:child_process"; | ||
import * as stream from "node:stream"; | ||
var local = function(options, callback) { | ||
options.env ??= process.env; | ||
if (callback) { | ||
return childProcess.exec( | ||
options.command, | ||
options, | ||
function(err, stdout, stderr) { | ||
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); | ||
} | ||
); | ||
} else { | ||
return childProcess.spawn( | ||
options.command, | ||
[], | ||
Object.assign(options, { | ||
shell: options.shell || true | ||
}) | ||
); | ||
} | ||
}; | ||
var remote = function(options, callback) { | ||
const child = new childProcess.ChildProcess(); | ||
child.stdout = new stream.Readable(); | ||
child.stdout._read = function() { | ||
}; | ||
child.stderr = new stream.Readable(); | ||
child.stderr._read = function() { | ||
}; | ||
child.kill = function(signal) { | ||
console.warn(`Not implemented, called kill ${signal}`); | ||
return true; | ||
}; | ||
let stdout = ""; | ||
let stderr = ""; | ||
if (options.cwd) { | ||
options.command = `cd ${options.cwd}; ${options.command}`; | ||
} | ||
options.ssh.exec(options.command, options, function(errArg, stream2) { | ||
if (errArg && callback) { | ||
return callback(errArg, "", "", NaN); | ||
} | ||
if (errArg) { | ||
return child.emit("error", errArg); | ||
} | ||
let err = null; | ||
stream2.stderr.on("data", function(data) { | ||
child.stderr?.push(data); | ||
stderr += data; | ||
}); | ||
stream2.on("data", function(data) { | ||
child.stdout?.push(data); | ||
stdout += data; | ||
}); | ||
let code = 0; | ||
let signal = null; | ||
let exitCalled = false; | ||
let stdoutCalled = false; | ||
let stderrCalled = false; | ||
const exit = function() { | ||
if (!(exitCalled && stdoutCalled && stderrCalled)) { | ||
return; | ||
} | ||
child.stdout?.push(null); | ||
child.stderr?.push(null); | ||
child.emit("close", code, signal); | ||
child.emit("exit", code, signal); | ||
if (code !== 0) { | ||
let debug; | ||
if (stderr.trim().length) { | ||
debug = stderr.trim().split(/\r\n|[\n\r\u0085\u2028\u2029]/g)[0]; | ||
} | ||
err = new Error( | ||
[ | ||
"Child process exited unexpectedly: ", | ||
`code ${JSON.stringify(code)}`, | ||
signal ? `, signal ${JSON.stringify(signal)}` : ", no signal", | ||
debug ? `, got ${JSON.stringify(debug)}` : void 0 | ||
].join("") | ||
); | ||
err.code = code; | ||
} | ||
if (options.end) { | ||
options.ssh.end(); | ||
options.ssh.on("error", function(err2) { | ||
callback(err2, "", "", NaN); | ||
}); | ||
options.ssh.on("close", function() { | ||
if (callback) { | ||
callback(err || null, stdout, stderr, code); | ||
} | ||
}); | ||
} else { | ||
if (callback) { | ||
callback(err || null, stdout, stderr, code); | ||
} | ||
} | ||
}; | ||
stream2.on("error", function(code2) { | ||
console.error("error", code2); | ||
}); | ||
stream2.on("exit", function(codeArg, signalArg) { | ||
exitCalled = true; | ||
code = codeArg; | ||
signal = signalArg; | ||
exit(); | ||
}); | ||
stream2.on("end", function() { | ||
stdoutCalled = true; | ||
exit(); | ||
}); | ||
stream2.stderr.on("end", function() { | ||
stderrCalled = true; | ||
exit(); | ||
}); | ||
}); | ||
return child; | ||
}; | ||
function exec2(arg1, arg2, arg3, arg4) { | ||
const options = arg3 !== void 0 ? ( | ||
// ssh and cmd separated | ||
typeof arg3 === "function" ? { ssh: arg1, command: arg2 } : arg3 | ||
) : arg1; | ||
const callback = arg3 !== void 0 ? ( | ||
// ssh and cmd separated | ||
typeof arg3 === "function" ? arg3 : arg4 | ||
) : arg2; | ||
if (options.ssh) { | ||
return remote(options, callback); | ||
} else { | ||
return local(options, callback); | ||
} | ||
} | ||
// src/promises.ts | ||
function exec3(arg1, arg2, arg3) { | ||
const options = arg2 ? { | ||
ssh: arg1, | ||
command: arg2, | ||
...arg3 | ||
} : arg1; | ||
return new Promise(function(resolve, reject) { | ||
exec2(options, function(err, stdout, stderr, code) { | ||
if (err) { | ||
err.stdout = stdout; | ||
err.stderr = stderr; | ||
reject(err); | ||
} else { | ||
resolve({ | ||
stdout, | ||
stderr, | ||
code | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
var promises_default = exec3; | ||
export { | ||
promises_default as default, | ||
exec3 as exec | ||
}; | ||
//# sourceMappingURL=promises.js.map |
{ | ||
"name": "ssh2-exec", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "Transparent usage between `child_process.exec` and `ssh2.prototype.exec`", | ||
@@ -19,8 +19,8 @@ "keywords": [ | ||
"@commitlint/config-conventional": "^19.5.0", | ||
"@eslint/core": "^0.6.0", | ||
"@eslint/js": "^9.11.1", | ||
"@eslint/core": "^0.7.0", | ||
"@eslint/js": "^9.13.0", | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/mocha": "^10.0.8", | ||
"@types/mocha": "^10.0.9", | ||
"@types/ssh2": "^1.15.1", | ||
"eslint": "^9.11.1", | ||
"eslint": "^9.13.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
@@ -32,13 +32,13 @@ "eslint-plugin-mocha": "^10.5.0", | ||
"mocha": "^10.7.3", | ||
"mocha-they": "^0.1.8", | ||
"mocha-they": "^0.1.10", | ||
"prettier": "^3.3.3", | ||
"should": "^13.2.3", | ||
"ssh2-connect": "^4.0.3", | ||
"ssh2-connect": "^4.1.1", | ||
"standard-version": "^9.5.0", | ||
"tsup": "^8.3.0", | ||
"tsx": "^4.19.1", | ||
"typedoc": "^0.26.7", | ||
"typedoc-plugin-markdown": "^4.2.8", | ||
"typescript": "^5.6.2", | ||
"typescript-eslint": "^8.7.0" | ||
"typedoc": "^0.26.10", | ||
"typedoc-plugin-markdown": "^4.2.9", | ||
"typescript": "^5.6.3", | ||
"typescript-eslint": "^8.11.0" | ||
}, | ||
@@ -45,0 +45,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
77495
15
781
1
4
3