diff --git a/lib/modules/datasource/maven/util.ts b/lib/modules/datasource/maven/util.ts index 4b7728fee504920c07df33b00f58f2868acbc013..31dd6042def15c3b47067968a6d65cb5e89e27fc 100644 --- a/lib/modules/datasource/maven/util.ts +++ b/lib/modules/datasource/maven/util.ts @@ -1,4 +1,3 @@ -import url from 'url'; import { DateTime } from 'luxon'; import { XmlDocument } from 'xmldoc'; import { HOST_DISABLED } from '../../../constants/error-messages'; @@ -7,6 +6,7 @@ import { ExternalHostError } from '../../../types/errors/external-host-error'; import type { Http } from '../../../util/http'; import type { HttpResponse } from '../../../util/http/types'; import { regEx } from '../../../util/regex'; +import { parseUrl } from '../../../util/url'; import { normalizeDate } from '../metadata'; import type { ReleaseResult } from '../types'; @@ -17,9 +17,11 @@ import type { MavenXml, } from './types'; -const getHost = (x: string): string => new url.URL(x).host; +function getHost(url: string): string | null { + return parseUrl(url)?.host ?? null; +} -function isMavenCentral(pkgUrl: url.URL | string): boolean { +function isMavenCentral(pkgUrl: URL | string): boolean { const host = typeof pkgUrl === 'string' ? pkgUrl : pkgUrl.host; return getHost(MAVEN_REPO) === host; } @@ -58,7 +60,7 @@ function isUnsupportedHostError(err: { name: string }): boolean { export async function downloadHttpProtocol( http: Http, - pkgUrl: url.URL | string + pkgUrl: URL | string ): Promise<Partial<HttpResponse>> { let raw: HttpResponse; try { @@ -99,7 +101,7 @@ export async function downloadHttpProtocol( export async function checkHttpResource( http: Http, - pkgUrl: url.URL | string + pkgUrl: URL | string ): Promise<HttpResourceCheckResult> { try { const res = await http.head(pkgUrl.toString()); @@ -136,13 +138,13 @@ export function getMavenUrl( dependency: MavenDependency, repoUrl: string, path: string -): url.URL { - return new url.URL(`${dependency.dependencyUrl}/${path}`, repoUrl); +): URL { + return new URL(`${dependency.dependencyUrl}/${path}`, repoUrl); } export async function downloadMavenXml( http: Http, - pkgUrl: url.URL | null + pkgUrl: URL | null ): Promise<MavenXml> { /* istanbul ignore if */ if (!pkgUrl) { diff --git a/package.json b/package.json index 8e3d4226d635d3fa0dc2b19d0ed80d06f6f17e82..095e99ac5817eb0307f1bd1961e9fc9feb36c824 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "Jamie Magee <jamie.magee@gmail.com>", "Jan Sauer <jan@jansauer.de>", "Jean-Yves Couët <jycouet@gmail.com>", + "Kenneth Jørgensen <kenneth@autonomouslogic.com>", "Kevin James <KevinJames@thekev.in>", "Klaus Meinhardt <klaus.meinhardt1@gmail.com>", "Matt Lavin <matt.lavin@gmail.com>",