diff --git a/server/package/index.ts b/server/package/index.ts index 3b308c8..543e1c1 100644 --- a/server/package/index.ts +++ b/server/package/index.ts @@ -1,6 +1,6 @@ import path from "path"; -import { checkFileExists, docsRootPath, getDocsPath } from "./utils"; +import { docsRootPath, getDocsPath } from "./utils"; import { resolvePackageJSON } from "./resolvers"; import semver from "semver"; import { generateDocsQueue, generateDocsQueueEvents } from "../queues"; @@ -41,7 +41,7 @@ export async function resolveDocsRequest({ packageVersion: packageVersion, }); - if (await checkFileExists(path.join(docsPathDisk, "index.html"))) + if (fs.existsSync(path.join(docsPathDisk, "index.html"))) return { type: "hit", packageName, @@ -70,7 +70,7 @@ export async function resolveDocsRequest({ }; } - if (await checkFileExists(path.join(docsPathDisk, "index.html"))) { + if (fs.existsSync(path.join(docsPathDisk, "index.html"))) { return { type: "hit", packageName: packageJSON.name, diff --git a/server/package/resolvers.ts b/server/package/resolvers.ts index 9508083..54d20f6 100644 --- a/server/package/resolvers.ts +++ b/server/package/resolvers.ts @@ -2,7 +2,6 @@ import resolve, { CachedInputFileSystem } from "enhanced-resolve"; import fs from "fs"; import path from "path"; import logger from "../../common/logger"; -import { checkFileExists } from "./utils"; import semver from "semver"; import InstallationUtils from "./installation.utils"; import pacote from "pacote"; @@ -102,21 +101,21 @@ export async function resolveTypePathInbuilt( typePath: resolvedPath, }); } else { - checkFileExists(definitionPath(resolvedPath)).then((exists) => { - if (exists) { - return resolve({ - packagePath: packagePath, - packageName: packageJSON.name, - typePath: definitionPath(resolvedPath), - }); - } else { - logger.warn( - "Failed to resolve inbuilt types for %s", - packageJSON.name, - ); - return resolve(null); - } - }); + const exists = fs.existsSync(definitionPath(resolvedPath)); + + if (exists) { + return resolve({ + packagePath: packagePath, + packageName: packageJSON.name, + typePath: definitionPath(resolvedPath), + }); + } else { + logger.warn( + "Failed to resolve inbuilt types for %s", + packageJSON.name, + ); + return resolve(null); + } } } }, diff --git a/server/package/utils.ts b/server/package/utils.ts index de35696..fb30220 100644 --- a/server/package/utils.ts +++ b/server/package/utils.ts @@ -2,13 +2,6 @@ import fs from "fs"; import path from "path"; import sanitize from "sanitize-filename"; -export function checkFileExists(file) { - return fs.promises - .access(file, fs.constants.F_OK) - .then(() => true) - .catch(() => false); -} - export const docsVersion = "1.0"; export const docsRootPath = path.join( __dirname,