v1.18.x
Julian Lam 9 years ago
parent e49af50ac8
commit 4f84ec31f6

@ -47,17 +47,20 @@ var getRunningPid = function(callback) {
files: async.apply(fs.readdir, path.join(__dirname, 'node_modules')), files: async.apply(fs.readdir, path.join(__dirname, 'node_modules')),
deps: async.apply(fs.readFile, path.join(__dirname, 'package.json'), { encoding: 'utf-8' }) deps: async.apply(fs.readFile, path.join(__dirname, 'package.json'), { encoding: 'utf-8' })
}, function(err, payload) { }, function(err, payload) {
try {
var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w\-]+$/, var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w\-]+$/,
moduleName; moduleName, isGitRepo;
payload.files = payload.files.filter(function(file) { payload.files = payload.files.filter(function(file) {
return isNbbModule.test(file); return isNbbModule.test(file);
}); });
try {
payload.deps = JSON.parse(payload.deps).dependencies; payload.deps = JSON.parse(payload.deps).dependencies;
payload.bundled = []; payload.bundled = [];
payload.installed = []; payload.installed = [];
} catch (err) {
return callback(err);
}
for (moduleName in payload.deps) { for (moduleName in payload.deps) {
if (isNbbModule.test(moduleName)) { if (isNbbModule.test(moduleName)) {
@ -67,19 +70,24 @@ var getRunningPid = function(callback) {
// Whittle down deps to send back only extraneously installed plugins/themes/etc // Whittle down deps to send back only extraneously installed plugins/themes/etc
payload.files.forEach(function(moduleName) { payload.files.forEach(function(moduleName) {
try {
fs.accessSync(path.join(__dirname, 'node_modules/' + moduleName, '.git'));
isGitRepo = true;
} catch(e) {
isGitRepo = false;
}
if ( if (
payload.files.indexOf(moduleName) !== -1 // found in `node_modules/` payload.files.indexOf(moduleName) !== -1 // found in `node_modules/`
&& payload.bundled.indexOf(moduleName) === -1 // not found in `package.json` && payload.bundled.indexOf(moduleName) === -1 // not found in `package.json`
&& !fs.lstatSync(path.join(__dirname, 'node_modules/' + moduleName)).isSymbolicLink() // is not a symlink && !fs.lstatSync(path.join(__dirname, 'node_modules/' + moduleName)).isSymbolicLink() // is not a symlink
&& !isGitRepo // .git/ does not exist, so it is not a git repository
) { ) {
payload.installed.push(moduleName); payload.installed.push(moduleName);
} }
}); });
getModuleVersions(payload.installed, callback); getModuleVersions(payload.installed, callback);
} catch (err) {
callback(err);
}
}); });
}, },
getModuleVersions = function(modules, callback) { getModuleVersions = function(modules, callback) {

Loading…
Cancel
Save