Merge pull request #5728 from NodeBB/patch-pitaj

Assorted Fixes
v1.18.x
Julian Lam 8 years ago committed by GitHub
commit b4870654fc

1
.gitignore vendored

@ -63,3 +63,4 @@ build
*.log *.log
test/files/normalise.jpg.png test/files/normalise.jpg.png
test/files/normalise-resized.jpg test/files/normalise-resized.jpg
package-lock.json

@ -46,7 +46,6 @@
"json-2-csv": "^2.0.22", "json-2-csv": "^2.0.22",
"less": "^2.0.0", "less": "^2.0.0",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"lodash.padstart": "^4.6.1",
"logrotate-stream": "^0.2.3", "logrotate-stream": "^0.2.3",
"lru-cache": "4.0.2", "lru-cache": "4.0.2",
"mime": "^1.3.4", "mime": "^1.3.4",

@ -1,25 +1,53 @@
'use strict'; 'use strict';
var path = require('path'); var path = require('path');
var fs = require('fs');
var async = require('async');
var file = require('../../file'); var file = require('../../file');
var themesController = {}; var themesController = {};
var defaultScreenshotPath = path.join(__dirname, '../../../public/images/themes/default.png');
themesController.get = function (req, res, next) { themesController.get = function (req, res, next) {
var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme); var themeDir = path.join(__dirname, '../../../node_modules', req.params.theme);
file.exists(themeDir, function (err, exists) { var themeConfigPath = path.join(themeDir, 'theme.json');
if (err || !exists) {
async.waterfall([
function (next) {
file.exists(themeConfigPath, function (err, exists) {
if (err) {
return next(err); return next(err);
} }
if (!exists) {
return next(Error('invalid-data'));
}
var themeConfig = require(path.join(themeDir, 'theme.json')); next();
var screenshotPath = path.join(themeDir, themeConfig.screenshot); });
if (themeConfig.screenshot && file.existsSync(screenshotPath)) { },
res.sendFile(screenshotPath); function (next) {
} else { fs.readFile(themeConfigPath, next);
res.sendFile(path.join(__dirname, '../../../public/images/themes/default.png')); },
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; module.exports = themesController;

@ -3,7 +3,7 @@
var async = require('async'); var async = require('async');
var winston = require('winston'); var winston = require('winston');
var nconf = require('nconf'); var nconf = require('nconf');
var padstart = require('lodash.padstart'); var _ = require('lodash');
var cacheBuster = require('./cacheBuster'); var cacheBuster = require('./cacheBuster');
var meta; var meta;
@ -122,7 +122,7 @@ function buildTargets(targets, parallel, callback) {
})); }));
all(targets, function (target, next) { all(targets, function (target, next) {
targetHandlers[target](parallel, step(padstart(target, length) + ' ', next)); targetHandlers[target](parallel, step(_.padStart(target, length) + ' ', next));
}, callback); }, callback);
} }

@ -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: [] };
};

@ -107,15 +107,15 @@ function getTranslationTree(callback) {
// 2. old language string (en_GB) // 2. old language string (en_GB)
// 3. corrected plugin defaultLang (en-US) // 3. corrected plugin defaultLang (en-US)
// 4. old 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 pluginLanguages = path.join(__dirname, '../../node_modules/', pluginData.id, pluginData.languages);
var defaultLang = pluginData.defaultLang || 'en-GB'; var defaultLang = pluginData.defaultLang || 'en-GB';
async.some([ async.eachSeries([
lang,
lang.replace('-', '_').replace('-x-', '@'),
defaultLang.replace('_', '-').replace('@', '-x-'),
defaultLang.replace('-', '_').replace('-x-', '@'), defaultLang.replace('-', '_').replace('-x-', '@'),
defaultLang.replace('_', '-').replace('@', '-x-'),
lang.replace('-', '_').replace('-x-', '@'),
lang,
], function (language, next) { ], function (language, next) {
fs.readFile(path.join(pluginLanguages, language, namespace + '.json'), function (err, buffer) { fs.readFile(path.join(pluginLanguages, language, namespace + '.json'), function (err, buffer) {
if (err) { if (err) {

@ -11,30 +11,9 @@ var postcss = require('postcss');
var autoprefixer = require('autoprefixer'); var autoprefixer = require('autoprefixer');
var clean = require('postcss-clean'); var clean = require('postcss-clean');
var Minifier = module.exports; var debugParams = require('./debugParams');
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: [],
};
}
return forkProcessParams; var Minifier = module.exports;
}
var pool = []; var pool = [];
var free = []; var free = [];
@ -68,7 +47,7 @@ function getChild() {
return free.shift(); return free.shift();
} }
var forkProcessParams = setupDebugging(); var forkProcessParams = debugParams();
var proc = childProcess.fork(__filename, [], Object.assign({}, forkProcessParams, { var proc = childProcess.fork(__filename, [], Object.assign({}, forkProcessParams, {
cwd: __dirname, cwd: __dirname,
env: { env: {

@ -1,9 +1,10 @@
'use strict'; 'use strict';
var fork = require('child_process').fork; var fork = require('child_process').fork;
var path = require('path'); var path = require('path');
var debugParams = require('./meta/debugParams');
exports.hash = function (rounds, password, callback) { exports.hash = function (rounds, password, callback) {
forkChild({ type: 'hash', rounds: rounds, password: password }, callback); forkChild({ type: 'hash', rounds: rounds, password: password }, callback);
}; };
@ -16,11 +17,7 @@ exports.compare = function (password, hash, callback) {
}; };
function forkChild(message, callback) { function forkChild(message, callback) {
var forkProcessParams = {}; var child = fork(path.join(__dirname, 'bcrypt'), [], debugParams());
if (global.v8debug || parseInt(process.execArgv.indexOf('--debug'), 10) !== -1) {
forkProcessParams = { execArgv: ['--debug=' + (5859), '--nolazy'] };
}
var child = fork(path.join(__dirname, 'bcrypt'), [], forkProcessParams);
child.on('message', function (msg) { child.on('message', function (msg) {
if (msg.err) { if (msg.err) {

@ -107,7 +107,7 @@ module.exports = function (Plugins) {
} }
function runNpmCommand(command, pkgName, version, callback) { 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) { if (err) {
return callback(err); return callback(err);
} }

Loading…
Cancel
Save