Merge pull request #5332 from pitaj/async@2

async v2 upgrade
v1.18.x
Julian Lam 8 years ago committed by GitHub
commit 81ca10d72e

@ -17,13 +17,21 @@ Minifier.js.minify = function (scripts, minify, callback) {
});
async.filter(scripts, function (script, next) {
file.exists(script, function (exists) {
file.exists(script, function (err, exists) {
if (err) {
return next(err);
}
if (!exists) {
console.warn('[minifier] file not found, ' + script);
}
next(exists);
next(null, exists);
});
}, function (scripts) {
}, function (err, scripts) {
if (err) {
return callback(err);
}
if (minify) {
minifyScripts(scripts, callback);
} else {

@ -17,7 +17,7 @@
"coveralls": "istanbul cover _mocha --report lcovonly -- -R dot && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"dependencies": {
"async": "~1.5.0",
"async": "^2.1.4",
"autoprefixer": "^6.2.3",
"bcryptjs": "~2.3.0",
"body-parser": "^1.9.0",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

@ -7,9 +7,9 @@ var themesController = {};
themesController.get = function (req, res, next) {
var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme);
file.exists(themeDir, function (exists) {
if (!exists) {
return next();
file.exists(themeDir, function (err, exists) {
if (err || !exists) {
return next(err);
}
var themeConfig = require(path.join(themeDir, 'theme.json')),

@ -87,19 +87,27 @@ file.allowedExtensions = function () {
file.exists = function (path, callback) {
fs.stat(path, function (err, stat) {
callback(!err && stat);
if (err) {
if (err.code === 'ENOENT') {
return callback(null, false);
}
return callback(err);
}
return callback(null, true);
});
};
file.existsSync = function (path) {
var exists = false;
try {
exists = fs.statSync(path);
} catch(err) {
exists = false;
fs.statSync(path);
} catch (err) {
if (err.code === 'ENOENT') {
return false;
}
throw err;
}
return !!exists;
return true;
};
module.exports = file;

@ -19,14 +19,17 @@ module.exports = function (Meta) {
winston.verbose('Checking dependencies for outdated modules');
async.every(modules, function (module, next) {
async.each(modules, function (module, next) {
fs.readFile(path.join(__dirname, '../../node_modules/', module, 'package.json'), {
encoding: 'utf-8'
}, function (err, pkgData) {
// If a bundled plugin/theme is not present, skip the dep check (#3384)
if (err && err.code === 'ENOENT' && (module === 'nodebb-rewards-essentials' || module.startsWith('nodebb-plugin') || module.startsWith('nodebb-theme'))) {
winston.warn('[meta/dependencies] Bundled plugin ' + module + ' not found, skipping dependency check.');
return next(true);
if (err) {
// If a bundled plugin/theme is not present, skip the dep check (#3384)
if (err.code === 'ENOENT' && (module === 'nodebb-rewards-essentials' || module.startsWith('nodebb-plugin') || module.startsWith('nodebb-theme'))) {
winston.warn('[meta/dependencies] Bundled plugin ' + module + ' not found, skipping dependency check.');
return next();
}
return next(err);
}
try {
@ -34,20 +37,24 @@ module.exports = function (Meta) {
} catch(e) {
process.stdout.write('[' + 'missing'.red + '] ' + module.bold + ' is a required dependency but could not be found\n');
depsMissing = true;
return next(true);
return next();
}
var ok = !semver.validRange(pkg.dependencies[module]) || semver.satisfies(pkgData.version, pkg.dependencies[module]);
if (ok || (pkgData._resolved && pkgData._resolved.indexOf('//github.com') !== -1)) {
next(true);
next();
} else {
process.stdout.write('[' + 'outdated'.yellow + '] ' + module.bold + ' installed v' + pkgData.version + ', package.json requires ' + pkg.dependencies[module] + '\n');
depsOutdated = true;
next(true);
next();
}
});
}, function (ok) {
}, function (err) {
if (err) {
return callback(err);
}
if (depsMissing) {
callback(new Error('dependencies-missing'));
} else if (depsOutdated) {

@ -27,18 +27,28 @@ module.exports = function (Meta) {
async.filter(files, function (file, next) {
fs.stat(path.join(themePath, file), function (err, fileStat) {
if (err) {
return next(false);
if (err.code === 'ENOENT') {
return next(null, false);
}
return next(err);
}
next((fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
next(null, (fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
});
}, function (themes) {
}, function (err, themes) {
if (err) {
return callback(err);
}
async.map(themes, function (theme, next) {
var config = path.join(themePath, theme, 'theme.json');
fs.readFile(config, function (err, file) {
if (err) {
return next();
if (err.code === 'ENOENT') {
return next(null, null);
}
return next(err);
}
try {
var configObj = JSON.parse(file.toString());

@ -161,9 +161,7 @@ var middleware;
});
// Filter out plugins with invalid paths
async.filter(paths, file.exists, function (paths) {
next(null, paths);
});
async.filter(paths, file.exists, next);
},
function (paths, next) {
async.map(paths, Plugins.loadPluginInfo, next);
@ -346,11 +344,15 @@ var middleware;
async.filter(dirs, function (dir, callback) {
fs.stat(dir, function (err, stats) {
callback(!err && stats.isDirectory());
if (err) {
if (err.code === 'ENOENT') {
return callback(null, false);
}
return callback(err);
}
callback(null, stats.isDirectory());
});
}, function (plugins) {
next(null, plugins);
});
}, next);
},
function (files, next) {

@ -31,9 +31,7 @@ module.exports = function (Plugins) {
return path.join(__dirname, '../../node_modules/', plugin);
});
async.filter(plugins, file.exists, function (plugins) {
next(null, plugins);
});
async.filter(plugins, file.exists, next);
},
], callback);
};
@ -162,13 +160,13 @@ module.exports = function (Plugins) {
var realPath = pluginData.staticDirs[mappedPath];
var staticDir = path.join(pluginPath, realPath);
file.exists(staticDir, function (exists) {
file.exists(staticDir, function (err, exists) {
if (exists) {
Plugins.staticDirs[pluginData.id + '/' + mappedPath] = staticDir;
} else {
winston.warn('[plugins/' + pluginData.id + '] Mapped path \'' + mappedPath + ' => ' + staticDir + '\' not found.');
}
callback();
callback(err);
});
}
}

@ -8,12 +8,8 @@ var helpers = {};
helpers.some = function (tasks, callback) {
async.some(tasks, function (task, next) {
task(function (err, result) {
next(!err && result);
});
}, function (result) {
callback(null, result);
});
task(next);
}, callback);
};
helpers.isUserAllowedTo = function (privilege, uid, cid, callback) {

@ -37,12 +37,14 @@ rewards.checkConditionAndRewardUser = function (uid, condition, method, callback
function (rewards, next) {
async.filter(rewards, function (reward, next) {
if (!reward) {
return next(false);
return next(null, false);
}
checkCondition(reward, method, next);
}, function (eligible) {
if (!eligible) {
checkCondition(reward, method, function (result) {
next(null, result);
});
}, function (err, eligible) {
if (err || !eligible) {
return next(false);
}

@ -262,11 +262,11 @@ module.exports.testSocket = function (socketPath, callback) {
var file = require('./file');
async.series([
function (next) {
file.exists(socketPath, function (exists) {
file.exists(socketPath, function (err, exists) {
if (exists) {
next();
} else {
callback();
callback(err);
}
});
},

Loading…
Cancel
Save