Skip to content

Commit

Permalink
style: turn @typescript-eslint/no-floating-promises rule on
Browse files Browse the repository at this point in the history
  • Loading branch information
Nipheris committed Apr 18, 2024
1 parent 1fb3d08 commit 45a11c1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 70 deletions.
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',

},
},
Expand Down
116 changes: 55 additions & 61 deletions src/deb/deb-builder.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const controlTarSizeRange = { start: 120, end: 129 };
const controlTarSizeData = (await this.artifactProvider.getArtifactContent(deb, controlTarSizeRange)).read() as unknown;
Expand All @@ -158,74 +159,67 @@ export class DebBuilder implements Deployer {
const whereExtract = path.join(this.tempPath, `control-${deb.md5}`);
createDir(whereExtract);

let createFilePromise: Promise<void> | undefined = undefined;

await new Promise<void>(resolve => {
await new Promise<void>((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<string>([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<string>([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;
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/jfrog/artifact-provider.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncomingMessage> {
return new Promise<IncomingMessage>((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<IncomingMessage> {
const meta = await this.getArtifactoryItemMeta(artifact);
return this.artifactoryClient.getContentStream(meta, range);
}

private async getArtifactoryItemMeta(artifact: Artifact): Promise<ArtifactoryItemMeta> {
Expand Down

0 comments on commit 45a11c1

Please sign in to comment.