|
1 | 1 | var log = require('debug')('manpm');
|
2 | 2 | var la = require('lazy-ass');
|
3 | 3 | var check = require('check-more-types');
|
4 |
| -var parseGithubRepoUrl = require('@bahmutov/parse-github-repo-url'); |
5 | 4 | var utils = require('./utils');
|
6 | 5 |
|
7 |
| -// working around github-url-to-object used inside get-package-readme |
8 |
| -// that cannot handle www.github.com urls |
9 |
| -// this does NOT work on npm2 where it cannot find github-url-to-object |
10 |
| -// due to multi level folder |
11 |
| -/* eslint no-undef:0 */ |
12 |
| -try { |
13 |
| - require = require('really-need'); |
14 |
| - require('github-url-to-object', { |
15 |
| - post: function () { |
16 |
| - return function gh(url) { |
17 |
| - log('parsing github url %s ourselves', url); |
18 |
| - var parsed = parseGithubRepoUrl(url); |
19 |
| - return { |
20 |
| - user: parsed[0], |
21 |
| - repo: parsed[1] |
22 |
| - }; |
23 |
| - }; |
24 |
| - } |
25 |
| - }); |
26 |
| -} catch (err) { |
27 |
| - // ignore |
28 |
| -} |
29 |
| - |
30 | 6 | var Promise = require('bluebird');
|
31 |
| -var getReadmeFile = Promise.promisify(require('get-package-readme')); |
| 7 | +var packageJson = require('package-json'); |
32 | 8 | var simpleGet = require('simple-get');
|
33 | 9 |
|
34 | 10 | function get(url) {
|
@@ -77,6 +53,12 @@ function getReadmeFromGithub(name) {
|
77 | 53 | log('fetching url from', fullUrl);
|
78 | 54 |
|
79 | 55 | return get(fullUrl)
|
| 56 | + .catch(function () { |
| 57 | + // probably not found |
| 58 | + fullUrl = formGithubUrl(parsed, 'readme.md'); |
| 59 | + log('fetching url from', fullUrl); |
| 60 | + return get(fullUrl); |
| 61 | + }) |
80 | 62 | .catch(function () {
|
81 | 63 | // probably not found
|
82 | 64 | fullUrl = formGithubUrl(parsed, 'readme.markdown');
|
@@ -115,8 +97,17 @@ function getReadme(name) {
|
115 | 97 | return getReadmeFromGithub(name);
|
116 | 98 | }
|
117 | 99 |
|
118 |
| - log('fetching README for package', name); |
119 |
| - return getReadmeFile(name); |
| 100 | + log('fetching README for NPM package', name); |
| 101 | + return packageJson(name, 'latest') |
| 102 | + .then(function (json) { |
| 103 | + console.log('repository', json.repository); |
| 104 | + if (!json.repository) { |
| 105 | + throw new Error('Cannot find repository for ' + name); |
| 106 | + } |
| 107 | + la(check.unemptyString(json.repository.url), |
| 108 | + 'missing url', json.repository); |
| 109 | + return getReadmeFromGithub(json.repository.url); |
| 110 | + }); |
120 | 111 | }
|
121 | 112 |
|
122 | 113 | module.exports = getReadme;
|
0 commit comments