mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
Refactored to more efficient fs call for reading packages
- we don't need to do both a `fs.readdir` and a `fs.stat` because `fs.readdir` has the `withFileTypes` which returns the directory entry info and so this avoids an extra stat syscall
This commit is contained in:
parent
14a087536f
commit
bd6a295674
@ -127,22 +127,18 @@ async function readPackage(packagePath, packageName) {
|
||||
* @returns {Promise<PackageList>}
|
||||
*/
|
||||
async function readPackages(packagePath) {
|
||||
return Bluebird.resolve(fs.readdir(packagePath))
|
||||
.filter(function (packageName) {
|
||||
return Bluebird.resolve(fs.readdir(packagePath, {withFileTypes: true}))
|
||||
.filter(function (packageFile) {
|
||||
// Filter out things which are not packages by regex
|
||||
if (packageName.match(notAPackageRegex)) {
|
||||
if (packageFile.name.match(notAPackageRegex)) {
|
||||
return;
|
||||
}
|
||||
// Check the remaining items to ensure they are a directory
|
||||
return fs.stat(join(packagePath, packageName))
|
||||
.then(function (stat) {
|
||||
return stat.isDirectory();
|
||||
})
|
||||
.catch(() => false);
|
||||
return packageFile.isDirectory();
|
||||
})
|
||||
.map(function readPackageJson(packageName) {
|
||||
const absolutePath = join(packagePath, packageName);
|
||||
return processPackage(absolutePath, packageName);
|
||||
.map(function readPackageJson(packageFile) {
|
||||
const absolutePath = join(packagePath, packageFile.name);
|
||||
return processPackage(absolutePath, packageFile.name);
|
||||
})
|
||||
.then(function (packages) {
|
||||
return _.keyBy(packages, 'name');
|
||||
|
Loading…
Reference in New Issue
Block a user