Skip to content

Commit

Permalink
Use sync checks for exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelsky committed Jan 3, 2024
1 parent 81b83ef commit d540ddc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
6 changes: 3 additions & 3 deletions server/package/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 15 additions & 16 deletions server/package/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}
}
},
Expand Down
7 changes: 0 additions & 7 deletions server/package/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d540ddc

Please sign in to comment.