From 44e55d2a98f068d08bf02dfcc2270b23a7052409 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Mon, 29 May 2017 12:35:55 -0600 Subject: [PATCH 1/5] Less synchronous stuffs --- src/controllers/admin/themes.js | 56 ++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/src/controllers/admin/themes.js b/src/controllers/admin/themes.js index 94fdf43746..cd70522fc9 100644 --- a/src/controllers/admin/themes.js +++ b/src/controllers/admin/themes.js @@ -1,25 +1,53 @@ 'use strict'; var path = require('path'); +var fs = require('fs'); +var async = require('async'); + var file = require('../../file'); var themesController = {}; +var defaultScreenshotPath = path.join(__dirname, '../../../public/images/themes/default.png'); + themesController.get = function (req, res, next) { - var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme); - file.exists(themeDir, function (err, exists) { - if (err || !exists) { - return next(err); - } - - var themeConfig = require(path.join(themeDir, 'theme.json')); - var screenshotPath = path.join(themeDir, themeConfig.screenshot); - if (themeConfig.screenshot && file.existsSync(screenshotPath)) { - res.sendFile(screenshotPath); - } else { - res.sendFile(path.join(__dirname, '../../../public/images/themes/default.png')); - } - }); + var themeDir = path.join(__dirname, '../../../node_modules', req.params.theme); + var themeConfigPath = path.join(themeDir, 'theme.json'); + + async.waterfall([ + function (next) { + file.exists(themeConfigPath, function (err, exists) { + if (err) { + return next(err); + } + if (!exists) { + return next(Error('invalid-data')); + } + + next(); + }); + }, + function (next) { + fs.readFile(themeConfigPath, next); + }, + function (themeConfig, next) { + try { + themeConfig = JSON.parse(themeConfig); + next(null, themeConfig.screenshot ? path.join(themeDir, themeConfig.screenshot) : defaultScreenshotPath); + } catch (e) { + next(e); + } + }, + function (screenshotPath, next) { + file.exists(screenshotPath, function (err, exists) { + if (err) { + return next(err); + } + + res.sendFile(exists ? screenshotPath : defaultScreenshotPath); + }); + }, + ], next); }; module.exports = themesController; From 9a3b684228f3bd2f7439c6e4265f712f79167147 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Jun 2017 14:04:05 -0600 Subject: [PATCH 2/5] Remove dependency, ignore package-lock.json --- .gitignore | 1 + package.json | 3 +-- src/meta/build.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index cc5fd2dbf1..66ff7ab337 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ build *.log test/files/normalise.jpg.png test/files/normalise-resized.jpg +package-lock.json diff --git a/package.json b/package.json index 8828ec648a..67bbd597b5 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "json-2-csv": "^2.0.22", "less": "^2.0.0", "lodash": "^4.17.4", - "lodash.padstart": "^4.6.1", "logrotate-stream": "^0.2.3", "lru-cache": "4.0.2", "mime": "^1.3.4", @@ -138,4 +137,4 @@ "url": "https://github.com/barisusakli" } ] -} \ No newline at end of file +} diff --git a/src/meta/build.js b/src/meta/build.js index 29155d55c3..26bec8b5e8 100644 --- a/src/meta/build.js +++ b/src/meta/build.js @@ -3,7 +3,7 @@ var async = require('async'); var winston = require('winston'); var nconf = require('nconf'); -var padstart = require('lodash.padstart'); +var _ = require('lodash'); var cacheBuster = require('./cacheBuster'); var meta; @@ -122,7 +122,7 @@ function buildTargets(targets, parallel, callback) { })); all(targets, function (target, next) { - targetHandlers[target](parallel, step(padstart(target, length) + ' ', next)); + targetHandlers[target](parallel, step(_.padStart(target, length) + ' ', next)); }, callback); } From e71fb9ab24c70c65341b8a9448e22108c0bdf106 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Jun 2017 14:04:23 -0600 Subject: [PATCH 3/5] Fix `node --inspect` --- src/meta/debugParams.js | 15 +++++++++++++++ src/meta/minifier.js | 27 +++------------------------ src/password.js | 9 +++------ 3 files changed, 21 insertions(+), 30 deletions(-) create mode 100644 src/meta/debugParams.js diff --git a/src/meta/debugParams.js b/src/meta/debugParams.js new file mode 100644 index 0000000000..952dc8dd04 --- /dev/null +++ b/src/meta/debugParams.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = function () { + var debugArg = process.execArgv.find(function (arg) { + return /^--(debug|inspect)/.test(arg); + }); + if (global.v8debug || debugArg) { + debugArg = debugArg ? debugArg.split('=') : ['--debug', 5859]; + var num = parseInt(debugArg[1], 10) + 1; + + return { execArgv: [debugArg[0] + '=' + num, '--nolazy'] }; + } + + return { execArgv: [] }; +}; diff --git a/src/meta/minifier.js b/src/meta/minifier.js index e9b6243d2f..4b64420701 100644 --- a/src/meta/minifier.js +++ b/src/meta/minifier.js @@ -11,30 +11,9 @@ var postcss = require('postcss'); var autoprefixer = require('autoprefixer'); var clean = require('postcss-clean'); -var Minifier = module.exports; - -function setupDebugging() { - /** - * Check if the parent process is running with the debug option --debug (or --debug-brk) - */ - var forkProcessParams = {}; - if (global.v8debug || parseInt(process.execArgv.indexOf('--debug'), 10) !== -1) { - /** - * use the line below if you want to debug minifier.js script too (or even --debug-brk option, but - * you'll have to setup your debugger and connect to the forked process) - */ - // forkProcessParams = { execArgv: ['--debug=' + (global.process.debugPort + 1), '--nolazy'] }; - - /** - * otherwise, just clean up --debug/--debug-brk options which are set up by default from the parent one - */ - forkProcessParams = { - execArgv: [], - }; - } +var debugParams = require('./debugParams'); - return forkProcessParams; -} +var Minifier = module.exports; var pool = []; var free = []; @@ -68,7 +47,7 @@ function getChild() { return free.shift(); } - var forkProcessParams = setupDebugging(); + var forkProcessParams = debugParams(); var proc = childProcess.fork(__filename, [], Object.assign({}, forkProcessParams, { cwd: __dirname, env: { diff --git a/src/password.js b/src/password.js index 76123ed974..137382c993 100644 --- a/src/password.js +++ b/src/password.js @@ -1,9 +1,10 @@ 'use strict'; - var fork = require('child_process').fork; var path = require('path'); +var debugParams = require('./meta/debugParams'); + exports.hash = function (rounds, password, callback) { forkChild({ type: 'hash', rounds: rounds, password: password }, callback); }; @@ -16,11 +17,7 @@ exports.compare = function (password, hash, callback) { }; function forkChild(message, callback) { - var forkProcessParams = {}; - if (global.v8debug || parseInt(process.execArgv.indexOf('--debug'), 10) !== -1) { - forkProcessParams = { execArgv: ['--debug=' + (5859), '--nolazy'] }; - } - var child = fork(path.join(__dirname, 'bcrypt'), [], forkProcessParams); + var child = fork(path.join(__dirname, 'bcrypt'), [], debugParams()); child.on('message', function (msg) { if (msg.err) { From 8e5bcf61058b3560c9cedabff13a0a6b7a08ff89 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Jun 2017 14:06:23 -0600 Subject: [PATCH 4/5] Fix #5727 --- src/meta/languages.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/meta/languages.js b/src/meta/languages.js index 06c73ace2e..3cf1359f4a 100644 --- a/src/meta/languages.js +++ b/src/meta/languages.js @@ -107,15 +107,15 @@ function getTranslationTree(callback) { // 2. old language string (en_GB) // 3. corrected plugin defaultLang (en-US) // 4. old plugin defaultLang (en_US) - async.eachLimit(plugins, 10, function (pluginData, done) { + async.eachLimit(plugins, 20, function (pluginData, done) { var pluginLanguages = path.join(__dirname, '../../node_modules/', pluginData.id, pluginData.languages); var defaultLang = pluginData.defaultLang || 'en-GB'; - async.some([ - lang, - lang.replace('-', '_').replace('-x-', '@'), - defaultLang.replace('_', '-').replace('@', '-x-'), + async.eachSeries([ defaultLang.replace('-', '_').replace('-x-', '@'), + defaultLang.replace('_', '-').replace('@', '-x-'), + lang.replace('-', '_').replace('-x-', '@'), + lang, ], function (language, next) { fs.readFile(path.join(pluginLanguages, language, namespace + '.json'), function (err, buffer) { if (err) { From 34af855848423de12656d0acdcb2f693f4d40946 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Jun 2017 14:12:25 -0600 Subject: [PATCH 5/5] Fix npm@5 saving by default --- src/plugins/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/install.js b/src/plugins/install.js index a5ba2db1dd..73246d69e6 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -101,7 +101,7 @@ module.exports = function (Plugins) { } function runNpmCommand(command, pkgName, version, callback) { - require('child_process').execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', [command, pkgName + (command === 'install' ? '@' + version : '')], function (err, stdout) { + require('child_process').execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', [command, pkgName + (command === 'install' ? '@' + version : ''), '--no-save'], function (err, stdout) { if (err) { return callback(err); }