From 11ef3c27ed8fc813f7874c777e4703f47daffd4d Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 14:56:53 +0000 Subject: [PATCH 01/11] use Set instead of object --- services/clsi/app/js/OutputFileFinder.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index f863e0c1ed..35b8c5bef7 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -26,10 +26,9 @@ module.exports = OutputFileFinder = { if (callback == null) { callback = function (error, outputFiles, allFiles) {} } - const incomingResources = {} - for (const resource of Array.from(resources)) { - incomingResources[resource.path] = true - } + const incomingResources = new Set( + resources.map((resource) => resource.path) + ) return OutputFileFinder._getAllFiles(directory, function (error, allFiles) { if (allFiles == null) { @@ -41,10 +40,10 @@ module.exports = OutputFileFinder = { } const outputFiles = [] for (const file of Array.from(allFiles)) { - if (!incomingResources[file]) { + if (!incomingResources.has(file)) { outputFiles.push({ path: file, - type: __guard__(file.match(/\.([^\.]+)$/), (x) => x[1]) + type: __guard__(file.match(/\.([^\.]+)$/), (x) => x[1]), }) } } @@ -70,7 +69,7 @@ module.exports = OutputFileFinder = { '.archive', '-o', '-name', - '.project-*' + '.project-*', ] const args = [ directory, @@ -81,7 +80,7 @@ module.exports = OutputFileFinder = { '-o', '-type', 'f', - '-print' + '-print', ] logger.log({ args }, 'running find command') @@ -105,7 +104,7 @@ module.exports = OutputFileFinder = { }) return callback(null, fileList) }) - } + }, } function __guard__(value, transform) { From 411d69e36b99be7588375efe50bdb168e83f311a Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 14:59:48 +0000 Subject: [PATCH 02/11] remove unnecessary callback code --- services/clsi/app/js/OutputFileFinder.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 35b8c5bef7..736dfedb6f 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -23,9 +23,6 @@ const logger = require('logger-sharelatex') module.exports = OutputFileFinder = { findOutputFiles(resources, directory, callback) { - if (callback == null) { - callback = function (error, outputFiles, allFiles) {} - } const incomingResources = new Set( resources.map((resource) => resource.path) ) @@ -52,14 +49,6 @@ module.exports = OutputFileFinder = { }, _getAllFiles(directory, _callback) { - if (_callback == null) { - _callback = function (error, fileList) {} - } - const callback = function (error, fileList) { - _callback(error, fileList) - return (_callback = function () {}) - } - // don't include clsi-specific files/directories in the output list const EXCLUDE_DIRS = [ '-name', From eaec57cd017989684c51757d74c5ffef384447cc Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:01:25 +0000 Subject: [PATCH 03/11] simplify null check --- services/clsi/app/js/OutputFileFinder.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 736dfedb6f..013c6f3555 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -11,7 +11,6 @@ * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__ - * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let OutputFileFinder @@ -31,7 +30,7 @@ module.exports = OutputFileFinder = { if (allFiles == null) { allFiles = [] } - if (error != null) { + if (error) { logger.err({ err: error }, 'error finding all output files') return callback(error) } From 0bae53c7f34492b8c81be055e24a8f7e03178a3a Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:02:40 +0000 Subject: [PATCH 04/11] remove unnecessary returns --- services/clsi/app/js/OutputFileFinder.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 013c6f3555..20d1bf073c 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -9,7 +9,6 @@ /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ @@ -43,7 +42,7 @@ module.exports = OutputFileFinder = { }) } } - return callback(null, outputFiles, allFiles) + callback(null, outputFiles, allFiles) }) }, @@ -90,7 +89,7 @@ module.exports = OutputFileFinder = { let path return (path = Path.relative(directory, file)) }) - return callback(null, fileList) + callback(null, fileList) }) }, } From c044db489787f3211089e5aa303d4a44ed74bd78 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:09:48 +0000 Subject: [PATCH 05/11] remove guard helper --- services/clsi/app/js/OutputFileFinder.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 20d1bf073c..70191a2693 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -36,9 +36,10 @@ module.exports = OutputFileFinder = { const outputFiles = [] for (const file of Array.from(allFiles)) { if (!incomingResources.has(file)) { + const type = Path.extname(file) outputFiles.push({ path: file, - type: __guard__(file.match(/\.([^\.]+)$/), (x) => x[1]), + type: Path.extname(file) || undefined, }) } } From 323890cedb4f57e3a43ad1de94745ae72ddf6b41 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:10:53 +0000 Subject: [PATCH 06/11] remove Array.from --- services/clsi/app/js/OutputFileFinder.js | 27 +++--------------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 70191a2693..e62284fe41 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -1,17 +1,3 @@ -/* eslint-disable - handle-callback-err, - no-return-assign, - no-unused-vars, - no-useless-escape, -*/ -// TODO: This file was created by bulk-decaffeinate. -// Fix any style issues and re-enable lint. -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS103: Rewrite code to no longer use __guard__ - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ let OutputFileFinder const async = require('async') const fs = require('fs') @@ -34,12 +20,11 @@ module.exports = OutputFileFinder = { return callback(error) } const outputFiles = [] - for (const file of Array.from(allFiles)) { + for (const file of allFiles) { if (!incomingResources.has(file)) { - const type = Path.extname(file) outputFiles.push({ path: file, - type: Path.extname(file) || undefined, + type: Path.extname(file).replace(/^\./, '') || undefined, }) } } @@ -62,7 +47,7 @@ module.exports = OutputFileFinder = { const args = [ directory, '(', - ...Array.from(EXCLUDE_DIRS), + ...EXCLUDE_DIRS, ')', '-prune', '-o', @@ -94,9 +79,3 @@ module.exports = OutputFileFinder = { }) }, } - -function __guard__(value, transform) { - return typeof value !== 'undefined' && value !== null - ? transform(value) - : undefined -} From ae064e899773f5aa51bd360831f92aa287f6a77e Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:11:29 +0000 Subject: [PATCH 07/11] lint fix --- services/clsi/app/js/OutputFileFinder.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index e62284fe41..933222e093 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -24,7 +24,7 @@ module.exports = OutputFileFinder = { if (!incomingResources.has(file)) { outputFiles.push({ path: file, - type: Path.extname(file).replace(/^\./, '') || undefined, + type: Path.extname(file).replace(/^\./, '') || undefined }) } } @@ -42,7 +42,7 @@ module.exports = OutputFileFinder = { '.archive', '-o', '-name', - '.project-*', + '.project-*' ] const args = [ directory, @@ -53,7 +53,7 @@ module.exports = OutputFileFinder = { '-o', '-type', 'f', - '-print', + '-print' ] logger.log({ args }, 'running find command') @@ -77,5 +77,5 @@ module.exports = OutputFileFinder = { }) callback(null, fileList) }) - }, + } } From e84d6305f309ddcb0d561cf6861693dfb07d507f Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:16:07 +0000 Subject: [PATCH 08/11] remove unnecessary return --- services/clsi/app/js/OutputFileFinder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 933222e093..1f62a7568d 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -11,7 +11,7 @@ module.exports = OutputFileFinder = { resources.map((resource) => resource.path) ) - return OutputFileFinder._getAllFiles(directory, function (error, allFiles) { + OutputFileFinder._getAllFiles(directory, function (error, allFiles) { if (allFiles == null) { allFiles = [] } @@ -61,7 +61,7 @@ module.exports = OutputFileFinder = { let stdout = '' proc.stdout.setEncoding('utf8').on('data', (chunk) => (stdout += chunk)) proc.on('error', callback) - return proc.on('close', function (code) { + proc.on('close', function (code) { if (code !== 0) { logger.warn( { directory, code }, From 4169f7fc73da71f25b2c06cecce39421622a4bf2 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:16:46 +0000 Subject: [PATCH 09/11] use once for callback --- services/clsi/app/js/OutputFileFinder.js | 4 +++- services/clsi/test/unit/js/OutputFileFinderTests.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 1f62a7568d..38fdc7945e 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -2,6 +2,7 @@ let OutputFileFinder const async = require('async') const fs = require('fs') const Path = require('path') +const _ = require('lodash') const { spawn } = require('child_process') const logger = require('logger-sharelatex') @@ -32,7 +33,8 @@ module.exports = OutputFileFinder = { }) }, - _getAllFiles(directory, _callback) { + _getAllFiles(directory, callback) { + callback = _.once(callback) // don't include clsi-specific files/directories in the output list const EXCLUDE_DIRS = [ '-name', diff --git a/services/clsi/test/unit/js/OutputFileFinderTests.js b/services/clsi/test/unit/js/OutputFileFinderTests.js index 4afa25e83e..8744c6e779 100644 --- a/services/clsi/test/unit/js/OutputFileFinderTests.js +++ b/services/clsi/test/unit/js/OutputFileFinderTests.js @@ -28,6 +28,9 @@ describe('OutputFileFinder', function () { fs: (this.fs = {}), child_process: { spawn: (this.spawn = sinon.stub()) }, 'logger-sharelatex': { log: sinon.stub(), warn: sinon.stub() } + }, + globals: { + Math // used by lodash } }) this.directory = '/test/dir' From cee93a0cd962b1cd21966f524caccee3e80389f5 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:17:20 +0000 Subject: [PATCH 10/11] clean up unnecessary var --- services/clsi/app/js/OutputFileFinder.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 38fdc7945e..cd94304766 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -74,8 +74,7 @@ module.exports = OutputFileFinder = { let fileList = stdout.trim().split('\n') fileList = fileList.map(function (file) { // Strip leading directory - let path - return (path = Path.relative(directory, file)) + return Path.relative(directory, file) }) callback(null, fileList) }) From 73e09ff99f1c04ad5c5f12777a2aa474ebeb1b25 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 18 Dec 2020 15:17:48 +0000 Subject: [PATCH 11/11] remove unnecessary requires --- services/clsi/app/js/OutputFileFinder.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index cd94304766..d9d2499699 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -1,6 +1,4 @@ let OutputFileFinder -const async = require('async') -const fs = require('fs') const Path = require('path') const _ = require('lodash') const { spawn } = require('child_process')