From 6d5b2aad86b69e68d638fa8c819398175e84bbda Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Wed, 13 Dec 2023 14:33:39 +0000 Subject: [PATCH] Use native promisified nodejs interfaces instead of `util.promisify` Change-type: patch --- src/features/contracts/contracts-directory.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/features/contracts/contracts-directory.ts b/src/features/contracts/contracts-directory.ts index 2d40e7154..93e566eb0 100644 --- a/src/features/contracts/contracts-directory.ts +++ b/src/features/contracts/contracts-directory.ts @@ -3,7 +3,6 @@ import request from 'request'; import tar from 'tar'; import glob from 'fast-glob'; import fs from 'fs'; -import util from 'util'; import stream from 'stream'; import path from 'path'; import os from 'os'; @@ -13,9 +12,6 @@ import { getBase64DataUri } from '../../lib/utils'; import { captureException } from '../../infra/error-handling'; import { CONTRACT_ALLOWLIST } from '../../lib/config'; -const pipeline = util.promisify(stream.pipeline); -const exists = util.promisify(fs.exists); - const CONTRACTS_BASE_DIR = path.join(os.tmpdir(), 'contracts'); // All assets that are stored together with the contract are encoded and stored in a dataurl format. @@ -118,7 +114,10 @@ const prepareContractDirectory = async (repo: RepositoryInfo) => { CONTRACTS_BASE_DIR, `${repo.owner}-${repo.name}`, ); - if (!(await exists(archiveDir))) { + try { + await fs.promises.access(archiveDir); + } catch { + // If the directory doesn't exist, create it await fs.promises.mkdir(archiveDir, { recursive: true }); } @@ -163,7 +162,7 @@ export const fetchContractsLocally = async (repos: RepositoryInfo[]) => { } }) as unknown as NodeJS.ReadableStream; - await pipeline(get, untar); + await stream.promises.pipeline(get, untar); }), ); };