Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native promisified nodejs interfaces instead of util.promisify #1497

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/features/contracts/contracts-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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 });
}

Expand Down Expand Up @@ -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);
}),
);
};
Expand Down
Loading