From 4e404b943c89ff0a36959c4d7b6c68e4563d51ab Mon Sep 17 00:00:00 2001 From: Ako Tulu Date: Fri, 2 Feb 2024 06:01:25 +0200 Subject: [PATCH 1/2] Updated ssh2 library to latest and fixed file write hanging. --- index.js | 17 +++++++++-------- package.json | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 37c3e94..a0020e5 100644 --- a/index.js +++ b/index.js @@ -173,6 +173,14 @@ class GulpSSH extends EventEmitter { const write = sftp.createWriteStream(filePath, options) write + .on('open', function() { + if (file.isStream()) file.contents.pipe(write) + else if (file.isBuffer()) write.end(file.contents) + else { + err = new PluginError(packageName, 'file error!') + write.end() + } + }) .on('error', function (error) { err = error }) @@ -181,13 +189,6 @@ class GulpSSH extends EventEmitter { if (err) callback(err) else callback(null, file) }) - - if (file.isStream()) file.contents.pipe(write) - else if (file.isBuffer()) write.end(file.contents) - else { - err = new PluginError(packageName, 'file error!') - write.end() - } }) }) }, function (callback) { @@ -346,8 +347,8 @@ class GulpSSH extends EventEmitter { let lastCommand commands.forEach(function (command) { - if (command[command.length - 1] !== '\n') command += '\n' log(packageName + ' :: shell :: ' + command) + if (command[command.length - 1] !== '\n') command += '\n' stream.write(command) lastCommand = command }) diff --git a/package.json b/package.json index 807a680..ea287f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-ssh", - "version": "0.7.1", + "version": "0.7.2", "description": "SSH and SFTP tasks for gulp", "license": "MIT", "author": { @@ -32,7 +32,7 @@ "ansicolors": "^0.3.2", "fancy-log": "^1.3.2", "plugin-error": "^1.0.1", - "ssh2": "~0.5.5", + "ssh2": "^1.14.0", "through2": "^2.0.3", "vinyl": "^2.1.0" }, From cd76f7a3d1b638ebb537ae80046cf035361e63de Mon Sep 17 00:00:00 2001 From: Ako Tulu Date: Fri, 2 Feb 2024 06:06:40 +0200 Subject: [PATCH 2/2] Fixed invalid event for writing with sftp. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a0020e5..7a1d8ed 100644 --- a/index.js +++ b/index.js @@ -184,7 +184,7 @@ class GulpSSH extends EventEmitter { .on('error', function (error) { err = error }) - .on('finish', function () { + .on('close', function () { sftp.end() if (err) callback(err) else callback(null, file)