Skip to content

Commit

Permalink
Merge pull request #1497 from balena-io/native-promise-interfaces
Browse files Browse the repository at this point in the history
Use native promisified nodejs interfaces instead of `util.promisify`
  • Loading branch information
Page- authored Dec 13, 2023
2 parents be2de28 + 6d5b2aa commit 49e3dfd
Showing 1 changed file with 5 additions and 6 deletions.
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

0 comments on commit 49e3dfd

Please sign in to comment.