refactor: use findAsyncSequential in a few places (#6377)

* refactor: use findAsyncSequential in a few places

* fixes

* fix
This commit is contained in:
Joshua Chen 2022-01-17 08:57:06 +08:00 committed by GitHub
parent ad16f4fdd9
commit 3cb0972b79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 46 deletions

View file

@ -10,6 +10,7 @@ import {
posixPath,
escapePath,
getFileLoaderUtils,
findAsyncSequential,
} from '@docusaurus/utils';
import visit from 'unist-util-visit';
import path from 'path';
@ -79,12 +80,12 @@ async function getAssetAbsolutePath(
await ensureAssetFileExist(assetFilePath, filePath);
return assetFilePath;
} else if (path.isAbsolute(assetPath)) {
// eslint-disable-next-line no-restricted-syntax
for (const staticDir of staticDirs) {
const assetFilePath = path.join(staticDir, assetPath);
if (await fs.pathExists(assetFilePath)) {
return assetFilePath;
}
const assetFilePath = await findAsyncSequential(
staticDirs.map((dir) => path.join(dir, assetPath)),
fs.pathExists,
);
if (assetFilePath) {
return assetFilePath;
}
} else {
const assetFilePath = path.join(path.dirname(filePath), assetPath);