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>}
|
* @returns {Promise<PackageList>}
|
||||||
*/
|
*/
|
||||||
async function readPackages(packagePath) {
|
async function readPackages(packagePath) {
|
||||||
return Bluebird.resolve(fs.readdir(packagePath))
|
return Bluebird.resolve(fs.readdir(packagePath, {withFileTypes: true}))
|
||||||
.filter(function (packageName) {
|
.filter(function (packageFile) {
|
||||||
// Filter out things which are not packages by regex
|
// Filter out things which are not packages by regex
|
||||||
if (packageName.match(notAPackageRegex)) {
|
if (packageFile.name.match(notAPackageRegex)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check the remaining items to ensure they are a directory
|
// Check the remaining items to ensure they are a directory
|
||||||
return fs.stat(join(packagePath, packageName))
|
return packageFile.isDirectory();
|
||||||
.then(function (stat) {
|
|
||||||
return stat.isDirectory();
|
|
||||||
})
|
|
||||||
.catch(() => false);
|
|
||||||
})
|
})
|
||||||
.map(function readPackageJson(packageName) {
|
.map(function readPackageJson(packageFile) {
|
||||||
const absolutePath = join(packagePath, packageName);
|
const absolutePath = join(packagePath, packageFile.name);
|
||||||
return processPackage(absolutePath, packageName);
|
return processPackage(absolutePath, packageFile.name);
|
||||||
})
|
})
|
||||||
.then(function (packages) {
|
.then(function (packages) {
|
||||||
return _.keyBy(packages, 'name');
|
return _.keyBy(packages, 'name');
|
||||||
|
Loading…
Reference in New Issue
Block a user