Skip to content

Commit e6d1f33

Browse files
committed
[BREAKING CHANGE] Remove preq from library
Remove preq from library entirely and replace with native fetch. This is not backwards compatible if third party users are a) using the parseAll function, and b) other features of preq, such as the internalUri parameter or wrapped errors; see https://github.com/wikimedia/preq for more details on how preq alters the Response object. Bug: T361602
1 parent a65b493 commit e6d1f33

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

index.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Import modules
1212
*/
1313
const BBPromise = require( 'bluebird' );
1414
const cheerio = require( 'cheerio' );
15-
const preq = require( 'preq' ); // Promisified Request library
1615
const fs = BBPromise.promisifyAll( require( 'fs' ) );
1716

1817
const index = require( './lib/index.js' );
@@ -27,8 +26,27 @@ const index = require( './lib/index.js' );
2726
* @return {Object} BBPromise for metadata
2827
*/
2928
exports = module.exports = function ( urlOrOpts, callback ) {
30-
return preq.get( urlOrOpts
31-
).then( ( response ) => index.parseAll( cheerio.load( response.body ) ) ).nodeify( callback );
29+
let url, opts;
30+
if ( urlOrOpts instanceof Object ) {
31+
if ( urlOrOpts.uri ) {
32+
url = urlOrOpts.uri;
33+
}
34+
opts = urlOrOpts;
35+
} else if ( typeof urlOrOpts === String ) {
36+
url = urlOrOpts;
37+
}
38+
if ( !url ) {
39+
return BBPromise.reject( 'No uri supplied in argument' ).nodeify( callback );
40+
} else {
41+
return BBPromise.resolve(
42+
fetch( url, opts ).then( ( response ) => {
43+
// todo check if either urloropts still works with fetch
44+
return response.text().then( ( body ) => {
45+
return index.parseAll( cheerio.load( body ) );
46+
} );
47+
} )
48+
).nodeify( callback );
49+
}
3250
};
3351

3452
/**

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"dependencies": {
77
"bluebird": "^3.7.1",
88
"cheerio": "1.0.0-rc.12",
9-
"microdata-node": "^0.2.1",
10-
"preq": "^0.5.12"
9+
"microdata-node": "^0.2.1"
1110
},
1211
"devDependencies": {
1312
"chai": "^4.3.0",

0 commit comments

Comments
 (0)