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.
This commit is contained in:
Conor Sloan
2023-11-22 13:03:01 +00:00
parent ffca16d01f
commit 7c7ef462b7
+45 -35
View File
@@ -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<FileMetadata>((resolve, reject) => {
const output = fs.createWriteStream(zipPath)
const archive = archiver.create('zip')
const createZipPromise = new Promise<FileMetadata>((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<FileMetadata>((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<FileMetadata>((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 {