diff --git a/lib/datasource/npm/get.ts b/lib/datasource/npm/get.ts index baf57dfe7ec9ed209b2f3289783607ed1e0d3b1b..9c49d53efe41ae86272bf7c4bfa027fc1e6b4432 100644 --- a/lib/datasource/npm/get.ts +++ b/lib/datasource/npm/get.ts @@ -5,6 +5,7 @@ import registryAuthToken from 'registry-auth-token'; import parse from 'github-url-from-git'; import { isBase64 } from 'validator'; import { OutgoingHttpHeaders } from 'http'; +import is from '@sindresorhus/is'; import { logger } from '../../logger'; import got from '../../util/got'; import * as hostRules from '../../util/host-rules'; @@ -145,6 +146,10 @@ export async function getDependency( // Determine repository URL let sourceUrl: string; + if (is.string(res.repository)) { + res.repository = { url: res.repository }; + } + if (res.repository && res.repository.url) { const extraBaseUrls = []; // istanbul ignore next diff --git a/test/datasource/npm/__snapshots__/index.spec.ts.snap b/test/datasource/npm/__snapshots__/index.spec.ts.snap index edea46723783ed3c870da6b6ea232400d47c0845..c5ccd6234e8c6fe665aeb83b3080e17dd6fd372b 100644 --- a/test/datasource/npm/__snapshots__/index.spec.ts.snap +++ b/test/datasource/npm/__snapshots__/index.spec.ts.snap @@ -110,6 +110,27 @@ Object { } `; +exports[`api/npm should parse repo url (string) 1`] = ` +Object { + "homepage": undefined, + "latestVersion": "0.0.1", + "name": "foobar", + "releases": Array [ + Object { + "canBeUnpublished": false, + "gitRef": undefined, + "releaseTimestamp": "2018-05-06T07:21:53+02:00", + "version": "0.0.1", + }, + ], + "sourceUrl": "https://github.com/renovateapp/dummy", + "tags": Object { + "latest": "0.0.1", + }, + "versions": Object {}, +} +`; + exports[`api/npm should parse repo url 1`] = ` Object { "homepage": undefined, diff --git a/test/datasource/npm/index.spec.ts b/test/datasource/npm/index.spec.ts index 0870033db2d88f6a716102064b82ac9013504ef2..25cd89fadeffdf751660422d73acfdea9bc3bfd3 100644 --- a/test/datasource/npm/index.spec.ts +++ b/test/datasource/npm/index.spec.ts @@ -201,6 +201,29 @@ describe('api/npm', () => { expect(res).toMatchSnapshot(); expect(res.sourceUrl).toBeDefined(); }); + + it('should parse repo url (string)', async () => { + const pkg = { + name: 'foobar', + versions: { + '0.0.1': { + repository: 'git:github.com/renovateapp/dummy', + }, + }, + 'dist-tags': { + latest: '0.0.1', + }, + time: { + '0.0.1': '2018-05-06T07:21:53+02:00', + }, + }; + nock('https://registry.npmjs.org') + .get('/foobar') + .reply(200, pkg); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); + expect(res).toMatchSnapshot(); + expect(res.sourceUrl).toBeDefined(); + }); it('should return deprecated', async () => { const deprecatedPackage = { name: 'foobar',