diff --git a/lib/modules/manager/bazel/parser.ts b/lib/modules/manager/bazel/parser.ts index 36e5f457143ef434bdae5c8df668e70fcb49974f..42905bb072490db3260bcac8145623e53df7663b 100644 --- a/lib/modules/manager/bazel/parser.ts +++ b/lib/modules/manager/bazel/parser.ts @@ -1,7 +1,7 @@ import { lang, lexer, parser, query as q } from 'good-enough-parser'; -import hasha from 'hasha'; import { logger } from '../../../logger'; import * as memCache from '../../../util/cache/memory'; +import { hash } from '../../../util/hash'; import { supportedRulesRegex } from './rules'; import type { NestedFragment, RecordFragment } from './types'; @@ -294,8 +294,8 @@ const query = q.tree<Ctx>({ }); function getCacheKey(input: string): string { - const hash = hasha(input); - return `bazel-parser-${hash}`; + const hashedInput = hash(input); + return `bazel-parser-${hashedInput}`; } const starlark = lang.createLang('starlark'); diff --git a/lib/modules/platform/comment.ts b/lib/modules/platform/comment.ts index 392b95181349130df0f89e5d8b66059a17b4530a..213d8eb6c8cb89f377b17286120c9af25b11ccbc 100644 --- a/lib/modules/platform/comment.ts +++ b/lib/modules/platform/comment.ts @@ -1,11 +1,8 @@ -import hasha from 'hasha'; import { getCache } from '../../util/cache/repository'; +import { hash } from '../../util/hash'; import type { EnsureCommentConfig, EnsureCommentRemovalConfig } from './types'; import { platform } from '.'; -// use sha512: https://www.npmjs.com/package/hasha#algorithm -const hash = (content: string): string => hasha(content); - export async function ensureComment( commentConfig: EnsureCommentConfig ): Promise<boolean> { diff --git a/lib/modules/platform/util.ts b/lib/modules/platform/util.ts index d074982889cbbdf475e4bb16f36c76cdbf3b38f3..7cb29a951e5c36a6a19774f9347cafecec4ac0cc 100644 --- a/lib/modules/platform/util.ts +++ b/lib/modules/platform/util.ts @@ -1,11 +1,11 @@ -import hasha from 'hasha'; +import { hash } from '../../util/hash'; export function repoFingerprint( repoId: number | string, endpoint: string | undefined ): string { const input = endpoint ? `${endpoint}::${repoId}` : `${repoId}`; - const fingerprint = hasha(input); + const fingerprint = hash(input); return fingerprint; } diff --git a/lib/util/cache/repository/impl/base.ts b/lib/util/cache/repository/impl/base.ts index 316adea2d293fc398dea67fac464cd4051891506..878fcad50bb2c037b94f5d5811889f5e6fb0f524 100644 --- a/lib/util/cache/repository/impl/base.ts +++ b/lib/util/cache/repository/impl/base.ts @@ -1,8 +1,8 @@ import is from '@sindresorhus/is'; -import hasha from 'hasha'; import { GlobalConfig } from '../../../../config/global'; import { logger } from '../../../../logger'; import { compress, decompress } from '../../../compress'; +import { hash } from '../../../hash'; import { safeStringify } from '../../../stringify'; import { CACHE_REVISION } from '../common'; import { RepoCacheRecord, RepoCacheV13 } from '../schema'; @@ -72,8 +72,8 @@ export abstract class RepoCacheBase implements RepoCache { async save(): Promise<void> { const jsonStr = safeStringify(this.data); - const hash = await hasha.async(jsonStr); - if (hash === this.oldHash) { + const hashedJsonStr = hash(jsonStr); + if (hashedJsonStr === this.oldHash) { return; } @@ -88,7 +88,7 @@ export abstract class RepoCacheBase implements RepoCache { repository, fingerprint, payload, - hash, + hash: hashedJsonStr, }); } @@ -101,6 +101,6 @@ export abstract class RepoCacheBase implements RepoCache { return undefined; } const jsonStr = safeStringify(this.data); - return hasha(jsonStr) !== this.oldHash; + return hash(jsonStr) !== this.oldHash; } } diff --git a/lib/util/cache/repository/impl/local.spec.ts b/lib/util/cache/repository/impl/local.spec.ts index c6f8d50b07e426835b599812b0cf318b88f3a684..e3f6e1f78b51d035264f99c4a23c9d89faa5fad5 100644 --- a/lib/util/cache/repository/impl/local.spec.ts +++ b/lib/util/cache/repository/impl/local.spec.ts @@ -1,8 +1,8 @@ -import hasha from 'hasha'; import { fs } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import { logger } from '../../../../logger'; import { compress } from '../../../compress'; +import { hash } from '../../../hash'; import { CACHE_REVISION } from '../common'; import type { RepoCacheRecord } from '../schema'; import type { RepoCacheData } from '../types'; @@ -20,7 +20,7 @@ async function createCacheRecord( const fingerprint = '0123456789abcdef'; const jsonStr = JSON.stringify(data); - const hash = hasha(jsonStr); + const hashedJsonStr = hash(jsonStr); const payload = await compress(jsonStr); return { @@ -28,7 +28,7 @@ async function createCacheRecord( repository, fingerprint, payload, - hash, + hash: hashedJsonStr, }; } diff --git a/lib/util/fingerprint.ts b/lib/util/fingerprint.ts index d4c009b93e5b587ec5ef939b224b678d4ecfdafe..724fa95ac55e0527523abd2e44c793c69bc218cc 100644 --- a/lib/util/fingerprint.ts +++ b/lib/util/fingerprint.ts @@ -1,7 +1,7 @@ -import hasha from 'hasha'; +import { hash } from './hash'; import { safeStringify } from './stringify'; export function fingerprint(input: unknown): string { const stringifiedInput = safeStringify(input); - return stringifiedInput ? hasha(stringifiedInput) : ''; + return stringifiedInput ? hash(stringifiedInput) : ''; } diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index 1846a64902de32bb87a0b6c7952fa1660811b195..bcc0037e82db05582f9589407d8db1cdd6110533 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -1,6 +1,5 @@ import merge from 'deepmerge'; import got, { Options, RequestError } from 'got'; -import hasha from 'hasha'; import type { SetRequired } from 'type-fest'; import { infer as Infer, type ZodError, ZodType } from 'zod'; import { HOST_DISABLED } from '../../constants/error-messages'; @@ -9,6 +8,7 @@ import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import * as memCache from '../cache/memory'; import { clone } from '../clone'; +import { hash } from '../hash'; import { type AsyncResult, Result } from '../result'; import { resolveBaseUrl } from '../url'; import { applyAuthorization, removeAuthorization } from './auth'; @@ -180,18 +180,16 @@ export class Http<Opts extends HttpOptions = HttpOptions> { } options = applyAuthorization(options); - // use sha512: https://www.npmjs.com/package/hasha#algorithm const memCacheKey = options.memCache !== false && (options.method === 'get' || options.method === 'head') - ? hasha([ - 'got-', - JSON.stringify({ + ? hash( + `got-${JSON.stringify({ url, headers: options.headers, method: options.method, - }), - ]) + })}` + ) : null; let resPromise: Promise<HttpResponse<T>> | null = null; diff --git a/lib/workers/repository/updates/branch-name.ts b/lib/workers/repository/updates/branch-name.ts index 9805478942316e377b246a46b0cd5e0f8b0df248..7d3a1aa6eca1df60711b4aa086775f5a13bb1fc4 100644 --- a/lib/workers/repository/updates/branch-name.ts +++ b/lib/workers/repository/updates/branch-name.ts @@ -1,9 +1,9 @@ // TODO #7154 import cleanGitRef from 'clean-git-ref'; -import hasha from 'hasha'; import slugify from 'slugify'; import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; +import { hash } from '../../../util/hash'; import { regEx } from '../../../util/regex'; import * as template from '../../../util/template'; @@ -96,10 +96,13 @@ export function generateBranchName(update: RenovateConfig): void { hashInput = template.compile(hashInput, update); hashInput = template.compile(hashInput, update); - const hash = hasha(hashInput); + const hashedInput = hash(hashInput); // TODO: types (#7154) - update.branchName = `${update.branchPrefix!}${hash.slice(0, hashLength)}`; + update.branchName = `${update.branchPrefix!}${hashedInput.slice( + 0, + hashLength + )}`; } else { update.branchName = template.compile(update.branchName!, update);