Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function installManyTop_ (what, where, context, cb) {
var nm = path.resolve(where, "node_modules")
, names = context.explicit
? what.map(function (w) { return w.split(/@/).shift() })
: []
fs.readdir(nm, function (er, pkgs) {
if (er) return installMany(what, where, context, cb)
pkgs = pkgs.filter(function (p) {
return !p.match(/^[\._-]/)
})
asyncMap(pkgs.map(function (p) {
return path.resolve(nm, p, "package.json")
}), function (jsonfile, cb) {
readJson(jsonfile, log.warn, function (er, data) {
if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
if (er) return cb(null, [])
return cb(null, [[data.name, data.version]])
})
}, function (er, packages) {
// if there's nothing in node_modules, then don't freak out.
if (er) packages = []
// add all the existing packages to the family list.
self._watchDir(dir, function(event, dirpath) {
var relDir = cwd === dir ? '.' : path.relative(cwd, dir);
relDir = relDir || '';
fs.readdir(dirpath, function(err, current) {
if (err) { return self.emit('error', err); }
if (!current) { return; }
try {
// append path.sep to directories so they match previous.
current = current.map(function(curPath) {
if (fs.existsSync(path.join(dir, curPath)) && fs.lstatSync(path.join(dir, curPath)).isDirectory()) {
return curPath + path.sep;
} else {
return curPath;
}
});
} catch (err) {
// race condition-- sometimes the file no longer exists
}
function readdir(name) {
resolveLeft++
fs.readdir(name, function (er, inst) {
if (er) return resolveLeft--
// don't even mess with non-package looking things
inst = inst.filter(function (p) {
if (!p.match(/^[@\._-]/)) return true
// scoped packages
readdir(path.join(name, p))
})
asyncMap(inst, function (pkg, cb) {
var jsonPath = path.resolve(name, pkg, 'package.json')
log.verbose('targetResolver', 'reading package data from', jsonPath)
readJson(jsonPath, log.info, function (er, d) {
if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
// error means it's not a package, most likely.
if (er) return cb(null, [])
function copyDir (src, dest, opts, cb) {
fs.readdir(src, (err, items) => {
if (err) return cb(err)
return copyDirItems(items, src, dest, opts, cb)
})
}
DirectoryWatcher.prototype.doInitialScan = function doInitialScan() {
fs.readdir(this.path, function(err, items) {
if(err) {
this.parentWatcher = watcherManager.watchFile(this.path + "#directory", this.options, 1);
this.parentWatcher.on("change", function(mtime, type) {
if(this.watchers[withoutCase(this.path)]) {
this.watchers[withoutCase(this.path)].forEach(function(w) {
w.emit("change", this.path, mtime, type);
}, this);
}
}.bind(this));
this.initialScan = false;
return;
}
async.forEach(items, function(item, callback) {
var itemPath = path.join(this.path, item);
fs.stat(itemPath, function(err2, stat) {
if(!this.initialScan) return;
function updateFileCountProbe() {
fs.readdir(PM2_ROOT_PATH + "/logs", function (err, files) {
if (err) {
console.error(err.stack || err);
return metrics.totalcount.set(0);
}
return metrics.totalcount.set(files.length);
});
}
updateFileCountProbe();
function copyDir (dir) {
fs.readdir(dir, function (err, items) {
if (err) return onError(err)
items.forEach(function (item) {
startCopy(path.join(dir, item))
})
return doneOne()
})
}
return wrapPromise(function(resolve, reject) {
fs.readdir(filePath, function(err, filePaths) {
if (err) {
reject(err);
return;
}
resolve(filePaths);
});
});
};
var f = ff(this, function () {
fs.readdir(addonPath, f());
this.startupPlugins(f.waitPlain());
}, function (files) {
files.forEach(bind(this, installAddon, projectPath));
function list (gyp, args, callback) {
var devDir = gyp.devDir
log.verbose('list', 'using node-gyp dir:', devDir)
fs.readdir(devDir, onreaddir)
function onreaddir (err, versions) {
if (err && err.code !== 'ENOENT') {
return callback(err)
}
if (Array.isArray(versions)) {
versions = versions.filter(function (v) { return v !== 'current' })
} else {
versions = []
}
callback(null, versions)
}
}