1 | 'use strict';
|
2 |
|
3 | const hostedGitInfo = require(`hosted-git-info`);
|
4 | const parseRepositoryURL = require(`@hutson/parse-repository-url`);
|
5 |
|
6 | module.exports = packageData => {
|
7 | if (!packageData ||
|
8 | !packageData.repository ||
|
9 | (typeof packageData.repository !== 'string' && !packageData.repository.url)) {
|
10 | throw new Error(`No valid "repository" data found in package metadata. Please see https://docs.npmjs.com/files/package.json#repository for proper syntax.`);
|
11 | }
|
12 |
|
13 | const repositoryURL = typeof packageData.repository === 'string' ? packageData.repository : packageData.repository.url;
|
14 |
|
15 | return hostedGitInfo.fromUrl(repositoryURL) || parseRepositoryURL(repositoryURL);
|
16 | };
|