From 45a11c1632c908bcc0f7312eb0bf63a723c8589d Mon Sep 17 00:00:00 2001 From: Stanislav Makarov Date: Thu, 18 Apr 2024 13:49:12 +0300 Subject: [PATCH] style: turn `@typescript-eslint/no-floating-promises` rule on --- eslint.config.mjs | 1 - src/deb/deb-builder.mts | 116 +++++++++++++++----------------- src/jfrog/artifact-provider.mts | 11 +-- 3 files changed, 58 insertions(+), 70 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 25a0258..89e8936 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -74,7 +74,6 @@ export default ts.config( '@typescript-eslint/no-use-before-define': ['error', 'nofunc'], // turn on this rules later '@typescript-eslint/await-thenable': 'off', - '@typescript-eslint/no-floating-promises': 'off', }, }, diff --git a/src/deb/deb-builder.mts b/src/deb/deb-builder.mts index 4e75ce4..5806d0a 100644 --- a/src/deb/deb-builder.mts +++ b/src/deb/deb-builder.mts @@ -142,6 +142,7 @@ export class DebBuilder implements Deployer { await Promise.all(promises); } + // eslint-disable-next-line max-statements private async handleDeb(distribution: string, component: string, deb: Artifact): Promise { const controlTarSizeRange = { start: 120, end: 129 }; const controlTarSizeData = (await this.artifactProvider.getArtifactContent(deb, controlTarSizeRange)).read() as unknown; @@ -158,74 +159,67 @@ export class DebBuilder implements Deployer { const whereExtract = path.join(this.tempPath, `control-${deb.md5}`); createDir(whereExtract); - let createFilePromise: Promise | undefined = undefined; - - await new Promise(resolve => { + await new Promise((resolve, reject) => { controlTar .pipe(tar.extract({ cwd: whereExtract, strip: 1 }, ['./control'])) // eslint-disable-next-line max-statements - .on('finish', () => { - const controlMetaContent = readFileSync(path.join(whereExtract, 'control'), 'utf-8').replaceAll(':', '='); - const controlMeta = ini.parse(controlMetaContent); - const name = controlMeta['Package'] as unknown; - assert(typeof name === 'string'); - const version = controlMeta['Version'] as unknown; - assert(typeof version === 'string'); - const arch = controlMeta['Architecture'] as unknown; - assert(typeof arch === 'string'); - - const archesSet = this.archesByDistComp.get(`${distribution}/${component}`); - - if (archesSet) { - archesSet.add(arch); - } else { - this.archesByDistComp.set(`${distribution}/${component}`, new Set([arch])); - } - - const fileName = binaryPackageFileName(name, version, arch); - - const targetMetaPath = path.join(this.distsPath, - distribution, - component, - `binary-${arch}`, - `${fileName}.meta`, - ); - createDir(path.dirname(targetMetaPath)); - renameSync(path.join(whereExtract, 'control'), targetMetaPath); - - removeDir(whereExtract); - - const debPath = path.join(this.poolPath, - component, - `${name[0]}`, - name, - distribution, - fileName, - ); - const relativeDebPath = path.relative(this.rootPath, debPath).replace(/\\/gu, '/'); - const debSize = controlTar.headers['content-range']?.split('/')[1]; - const sha1 = controlTar.headers['x-checksum-sha1']; - const sha256 = controlTar.headers['x-checksum-sha256']; - const md5 = controlTar.headers['x-checksum-md5']; - - if (typeof sha1 !== 'string' || typeof sha256 !== 'string' || typeof md5 !== 'string' || typeof debSize !== 'string') { - throw new Error('No checksum was found in headers'); - } - - const dataToAppend = `Filename: ${relativeDebPath}\nSize: ${debSize}\nSHA1: ${sha1}\nSHA256: ${sha256}\nMD5Sum: ${md5}\n`; + .on('finish', () => resolve()) + .on('error', err => reject(err)) + }); - appendFile(targetMetaPath, dataToAppend).then(() => resolve()); + const controlMetaContent = readFileSync(path.join(whereExtract, 'control'), 'utf-8').replaceAll(':', '='); + const controlMeta = ini.parse(controlMetaContent); + const name = controlMeta['Package'] as unknown; + assert(typeof name === 'string'); + const version = controlMeta['Version'] as unknown; + assert(typeof version === 'string'); + const arch = controlMeta['Architecture'] as unknown; + assert(typeof arch === 'string'); + + const archesSet = this.archesByDistComp.get(`${distribution}/${component}`); + + if (archesSet) { + archesSet.add(arch); + } else { + this.archesByDistComp.set(`${distribution}/${component}`, new Set([arch])); + } - const createFileOperation = this.packageCreator(deb.md5, debPath); + const fileName = binaryPackageFileName(name, version, arch); + + const targetMetaPath = path.join(this.distsPath, + distribution, + component, + `binary-${arch}`, + `${fileName}.meta`, + ); + createDir(path.dirname(targetMetaPath)); + renameSync(path.join(whereExtract, 'control'), targetMetaPath); + + removeDir(whereExtract); + + const debPath = path.join(this.poolPath, + component, + `${name[0]}`, + name, + distribution, + fileName, + ); + const relativeDebPath = path.relative(this.rootPath, debPath).replace(/\\/gu, '/'); + const debSize = controlTar.headers['content-range']?.split('/')[1]; + const sha1 = controlTar.headers['x-checksum-sha1']; + const sha256 = controlTar.headers['x-checksum-sha256']; + const md5 = controlTar.headers['x-checksum-md5']; + + if (typeof sha1 !== 'string' || typeof sha256 !== 'string' || typeof md5 !== 'string' || typeof debSize !== 'string') { + throw new Error('No checksum was found in headers'); + } - if (createFileOperation instanceof Promise) { - createFilePromise = createFileOperation; - } - }); - }); + const dataToAppend = `Filename: ${relativeDebPath}\nSize: ${debSize}\nSHA1: ${sha1}\nSHA256: ${sha256}\nMD5Sum: ${md5}\n`; + await appendFile(targetMetaPath, dataToAppend); - if (createFilePromise) { - await createFilePromise; + const createFileOperation = this.packageCreator(deb.md5, debPath); + if (createFileOperation instanceof Promise) { + await createFileOperation; } } diff --git a/src/jfrog/artifact-provider.mts b/src/jfrog/artifact-provider.mts index 91b4ff9..76db561 100644 --- a/src/jfrog/artifact-provider.mts +++ b/src/jfrog/artifact-provider.mts @@ -53,14 +53,9 @@ export default class JfrogArtifactProvider implements ArtifactProvider { return this.artifactoryClient.getItemUrl(await this.getArtifactoryItemMeta(artifact)); } - public getArtifactContent(artifact: Artifact, range?: ByteRange): Promise { - return new Promise((resolve, reject) => { - this.getArtifactoryItemMeta(artifact).then(meta => { - this.artifactoryClient.getContentStream(meta, range) - .then(value => resolve(value)) - .catch(err => reject(err)); - }); - }); + public async getArtifactContent(artifact: Artifact, range?: ByteRange): Promise { + const meta = await this.getArtifactoryItemMeta(artifact); + return this.artifactoryClient.getContentStream(meta, range); } private async getArtifactoryItemMeta(artifact: Artifact): Promise {