From 7c7ef462b76262e288c2b5a144edd87dc969c1e2 Mon Sep 17 00:00:00 2001 From: Conor Sloan Date: Wed, 22 Nov 2023 13:03:01 +0000 Subject: [PATCH] fix or disable linting in fs-helper There is a bit of a catch-22 bere where the createArchives function should not use .then and .catch in favour of async/await according to the linter, but can't use async/await because it's discouraged to make new promise executor functions async. There is a hacky workaround to make this work, but it seems like it isn't worth making the code more fragmented, so i just disabled the linter for these lines. --- src/fs-helper.ts | 80 +++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/src/fs-helper.ts b/src/fs-helper.ts index 9b1ea0d..82f814b 100644 --- a/src/fs-helper.ts +++ b/src/fs-helper.ts @@ -35,43 +35,53 @@ export async function createArchives( const zipPath = path.join(archiveTargetPath, `archive.zip`) const tarPath = path.join(archiveTargetPath, `archive.tar.gz`) - return Promise.all([ - new Promise((resolve, reject) => { - const output = fs.createWriteStream(zipPath) - const archive = archiver.create('zip') + const createZipPromise = new Promise((resolve, reject) => { + const output = fs.createWriteStream(zipPath) + const archive = archiver.create('zip') - output.on('error', (err: Error) => { - reject(err) - }) - - archive.on('error', (err: Error) => { - reject(err) - }) - - output.on('close', () => { - resolve(fileMetadata(zipPath)) - }) - - archive.pipe(output) - archive.directory(distPath, false) - archive.finalize() - }), - new Promise((resolve, reject) => { - tar - .c( - { - file: tarPath, - C: distPath, // Change to the source directory for relative paths (TODO) - gzip: true - }, - ['.'] - ) - .then(() => { - resolve(fileMetadata(tarPath)) - }) - .catch((err: Error) => reject(err)) + output.on('error', (err: Error) => { + reject(err) }) - ]).then(([zipFile, tarFile]) => ({ zipFile, tarFile })) + + archive.on('error', (err: Error) => { + reject(err) + }) + + output.on('close', () => { + resolve(fileMetadata(zipPath)) + }) + + archive.pipe(output) + archive.directory(distPath, false) + archive.finalize() + }) + + const createTarPromise = new Promise((resolve, reject) => { + tar + .c( + { + file: tarPath, + C: distPath, // Change to the source directory for relative paths (TODO) + gzip: true + }, + ['.'] + ) + // eslint-disable-next-line github/no-then + .catch(err => { + reject(err) + }) + // eslint-disable-next-line github/no-then + .then(() => { + resolve(fileMetadata(tarPath)) + }) + }) + + const [zipFile, tarFile] = await Promise.all([ + createZipPromise, + createTarPromise + ]) + + return { zipFile, tarFile } } export function isDirectory(dirPath: string): boolean {