Skip to content

Commit 0ffdc31

Browse files
committed
fix(node5): testing on node 4 and 5, fixed get, closes #22
1 parent a00ed3e commit 0ffdc31

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
npm-debug.log

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ cache:
66
notifications:
77
email: false
88
node_js:
9-
- '4'
9+
- '4.2.2'
10+
- '5'
1011
before_install:
1112
- npm i -g npm@^2.0.0
1213
before_script:

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,25 @@
5454
"check-more-types": "2.2.0",
5555
"debug": "2.2.0",
5656
"get-package-readme": "1.1.0",
57+
"github-readme": "1.0.0",
5758
"lazy-ass": "1.1.0",
5859
"lodash": "3.10.1",
5960
"marked": "0.3.5",
6061
"marked-terminal": "https://github.com/mikaelbr/marked-terminal.git#35f6ddac9d9f32b11e85ceb6bc5f42642f06e456",
6162
"marked-to-md": "1.0.1",
62-
"really-need": "1.7.2",
63+
"package-json": "2.3.0",
6364
"simple-bin-help": "1.5.0",
6465
"simple-get": "1.4.3",
6566
"update-notifier": "0.5.0"
6667
},
6768
"preferGlobal": true,
69+
"release": {
70+
"verifyConditions": {
71+
"path": "condition-node-version",
72+
"node": "4.2.2",
73+
"verbose": true
74+
}
75+
},
6876
"config": {
6977
"pre-git": {
7078
"commit-msg": "simple",
@@ -87,6 +95,7 @@
8795
},
8896
"devDependencies": {
8997
"ban-sensitive-files": "1.4.0",
98+
"condition-node-version": "1.2.0",
9099
"eslint": "1.10.1",
91100
"exact-semver": "1.2.0",
92101
"git-issues": "1.2.0",

src/get-readme.js

+18-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
11
var log = require('debug')('manpm');
22
var la = require('lazy-ass');
33
var check = require('check-more-types');
4-
var parseGithubRepoUrl = require('@bahmutov/parse-github-repo-url');
54
var utils = require('./utils');
65

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-
306
var Promise = require('bluebird');
31-
var getReadmeFile = Promise.promisify(require('get-package-readme'));
7+
var packageJson = require('package-json');
328
var simpleGet = require('simple-get');
339

3410
function get(url) {
@@ -77,6 +53,12 @@ function getReadmeFromGithub(name) {
7753
log('fetching url from', fullUrl);
7854

7955
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+
})
8062
.catch(function () {
8163
// probably not found
8264
fullUrl = formGithubUrl(parsed, 'readme.markdown');
@@ -115,8 +97,17 @@ function getReadme(name) {
11597
return getReadmeFromGithub(name);
11698
}
11799

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+
});
120111
}
121112

122113
module.exports = getReadme;

0 commit comments

Comments
 (0)