diff --git a/lib/datasource/clojure/__snapshots__/index.spec.ts.snap b/lib/datasource/clojure/__snapshots__/index.spec.ts.snap index 20e9cbbd5f7794f93cef902faf490b434ebf7fc5..81e923cf1bd916f305df60f28cecf7a5bde1506b 100644 --- a/lib/datasource/clojure/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/clojure/__snapshots__/index.spec.ts.snap @@ -640,40 +640,3 @@ Array [ }, ] `; - -exports[`datasource/clojure/index supports file protocol 1`] = ` -Object { - "display": "org.example:package", - "group": "org.example", - "homepage": "https://package.example.org/about", - "name": "package", - "registryUrl": "file:///bar", - "releases": Array [ - Object { - "version": "1.0.0", - }, - Object { - "version": "1.0.1", - }, - Object { - "version": "1.0.2", - }, - Object { - "version": "2.0.0", - }, - ], -} -`; - -exports[`datasource/clojure/index supports file protocol 2`] = ` -Array [ - Array [ - "/bar/org/example/package/maven-metadata.xml", - "utf8", - ], - Array [ - "/bar/org/example/package/2.0.0/package-2.0.0.pom", - "utf8", - ], -] -`; diff --git a/lib/datasource/clojure/index.spec.ts b/lib/datasource/clojure/index.spec.ts index c9c1e7ccc83e58bd92a47734689030a6d0993154..546bb2e44192b33c509f8b51d350d71c2f908828 100644 --- a/lib/datasource/clojure/index.spec.ts +++ b/lib/datasource/clojure/index.spec.ts @@ -1,15 +1,11 @@ -import _fs from 'fs-extra'; import upath from 'upath'; import { ReleaseResult, getPkgReleases } from '..'; import * as httpMock from '../../../test/http-mock'; -import { getName, loadFixture, mocked } from '../../../test/util'; +import { getName, loadFixture } from '../../../test/util'; import * as hostRules from '../../util/host-rules'; import { id as versioning } from '../../versioning/maven'; import { ClojureDatasource } from '.'; -jest.mock('fs-extra'); -const fs = mocked(_fs); - const baseUrl = 'https://clojars.org/repo'; const baseUrlCustom = 'https://custom.registry.renovatebot.com'; @@ -241,23 +237,4 @@ describe(getName(), () => { expect(sourceUrl).toEqual('https://github.com/example/test'); }); - - it('supports file protocol', async () => { - fs.exists.mockResolvedValueOnce(false); - - fs.exists.mockResolvedValueOnce(true); - fs.readFile.mockResolvedValueOnce( - Buffer.from(loadFixture('metadata.xml', upath.join('..', 'maven'))) - ); - - fs.exists.mockResolvedValueOnce(true); - fs.readFile.mockResolvedValueOnce( - Buffer.from(loadFixture('pom.xml', upath.join('..', 'maven'))) - ); - - const res = await get('org.example:package', 'file:///foo', 'file:///bar'); - - expect(res).toMatchSnapshot(); - expect(fs.readFile.mock.calls).toMatchSnapshot(); - }); }); diff --git a/lib/datasource/maven/__snapshots__/index.spec.ts.snap b/lib/datasource/maven/__snapshots__/index.spec.ts.snap index f8e722ebb6cb33b2c20623617c33ca410db01c91..aba4930ded3c4945c08b5ad7edb68888de56d1de 100644 --- a/lib/datasource/maven/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/maven/__snapshots__/index.spec.ts.snap @@ -810,43 +810,6 @@ Array [ ] `; -exports[`datasource/maven/index supports file protocol 1`] = ` -Object { - "display": "org.example:package", - "group": "org.example", - "homepage": "https://package.example.org/about", - "name": "package", - "registryUrl": "file:///bar", - "releases": Array [ - Object { - "version": "1.0.0", - }, - Object { - "version": "1.0.1", - }, - Object { - "version": "1.0.2", - }, - Object { - "version": "2.0.0", - }, - ], -} -`; - -exports[`datasource/maven/index supports file protocol 2`] = ` -Array [ - Array [ - "/bar/org/example/package/maven-metadata.xml", - "utf8", - ], - Array [ - "/bar/org/example/package/2.0.0/package-2.0.0.pom", - "utf8", - ], -] -`; - exports[`datasource/maven/index throws EXTERNAL_HOST_ERROR for 50x 1`] = ` Array [ Object { diff --git a/lib/datasource/maven/index.spec.ts b/lib/datasource/maven/index.spec.ts index ca72d31f4f64e79b8747578595129d29df3549fa..4c9c719fcbcee48fef7eaac38fdae836ebed1f16 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -1,15 +1,11 @@ -import _fs from 'fs-extra'; import { ReleaseResult, getPkgReleases } from '..'; import * as httpMock from '../../../test/http-mock'; -import { getName, loadFixture, mocked } from '../../../test/util'; +import { getName, loadFixture } from '../../../test/util'; import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages'; import * as hostRules from '../../util/host-rules'; import { id as versioning } from '../../versioning/maven'; import { id as datasource } from '.'; -jest.mock('fs-extra'); -const fs = mocked(_fs); - const baseUrl = 'https://repo.maven.apache.org/maven2'; const baseUrlCustom = 'https://custom.registry.renovatebot.com'; @@ -309,19 +305,4 @@ describe(getName(), () => { expect(res).toMatchSnapshot(); expect(httpMock.getTrace()).toMatchSnapshot(); }); - - it('supports file protocol', async () => { - fs.exists.mockResolvedValueOnce(false); - - fs.exists.mockResolvedValueOnce(true); - fs.readFile.mockResolvedValueOnce(Buffer.from(loadFixture('metadata.xml'))); - - fs.exists.mockResolvedValueOnce(true); - fs.readFile.mockResolvedValueOnce(Buffer.from(loadFixture('pom.xml'))); - - const res = await get('org.example:package', 'file:///foo', 'file:///bar'); - - expect(res).toMatchSnapshot(); - expect(fs.readFile.mock.calls).toMatchSnapshot(); - }); }); diff --git a/lib/datasource/maven/index.ts b/lib/datasource/maven/index.ts index 8b368ed56bb6bdd1ed03ccd4e239d3e020d38963..20e6aef5764e942a14fa4ec5531d5671fab0ba32 100644 --- a/lib/datasource/maven/index.ts +++ b/lib/datasource/maven/index.ts @@ -95,18 +95,6 @@ function isValidArtifactsInfo( return versions.every((v) => info[v] !== undefined); } -async function getArtifactInfo( - version: string, - artifactUrl: url.URL -): Promise<ArtifactInfoResult> { - const proto = artifactUrl.protocol; - if (proto === 'http:' || proto === 'https:') { - const result = await isHttpResourceExists(artifactUrl); - return [version, result]; - } - return [version, true]; -} - async function filterMissingArtifacts( dependency: MavenDependency, repoUrl: string, @@ -130,8 +118,8 @@ async function filterMissingArtifacts( .filter(([_, artifactUrl]) => Boolean(artifactUrl)) .map( ([version, artifactUrl]) => - (): Promise<ArtifactInfoResult> => - getArtifactInfo(version, artifactUrl) + async (): Promise<ArtifactInfoResult> => + [version, await isHttpResourceExists(artifactUrl)] ); const results = await pAll(queue, { concurrency: 5 }); artifactsInfo = results.reduce( diff --git a/lib/datasource/maven/util.ts b/lib/datasource/maven/util.ts index 0c4670412c6302747b5f616d55c2384830f19ad5..ed7f7355ce467819f1c34ddb6cabfa127794e0ca 100644 --- a/lib/datasource/maven/util.ts +++ b/lib/datasource/maven/util.ts @@ -1,5 +1,4 @@ import url from 'url'; -import fs from 'fs-extra'; import { XmlDocument } from 'xmldoc'; import { HOST_DISABLED } from '../../constants/error-messages'; import { logger } from '../../logger'; @@ -100,14 +99,6 @@ export async function downloadHttpProtocol( } } -async function downloadFileProtocol(pkgUrl: url.URL): Promise<string | null> { - const pkgPath = pkgUrl.toString().replace('file://', ''); - if (!(await fs.exists(pkgPath))) { - return null; - } - return fs.readFile(pkgPath, 'utf8'); -} - export async function isHttpResourceExists( pkgUrl: url.URL | string, hostType = id @@ -150,9 +141,6 @@ export async function downloadMavenXml( let rawContent: string; let authorization: boolean; switch (pkgUrl.protocol) { - case 'file:': - rawContent = await downloadFileProtocol(pkgUrl); - break; case 'http:': case 'https:': ({ authorization, body: rawContent } = await downloadHttpProtocol(