rp.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. var Bluebird = require('bluebird').getNewLibraryCopy(),
  3. configure = require('request-promise-core/configure/request2'),
  4. stealthyRequire = require('stealthy-require');
  5. try {
  6. // Load Request freshly - so that users can require an unaltered request instance!
  7. var request = stealthyRequire(require.cache, function () {
  8. return require('request');
  9. },
  10. function () {
  11. require('tough-cookie');
  12. }, module);
  13. } catch (err) {
  14. /* istanbul ignore next */
  15. var EOL = require('os').EOL;
  16. /* istanbul ignore next */
  17. console.error(EOL + '###' + EOL + '### The "request" library is not installed automatically anymore.' + EOL + '### But is a dependency of "request-promise".' + EOL + '### Please install it with:' + EOL + '### npm install request --save' + EOL + '###' + EOL);
  18. /* istanbul ignore next */
  19. throw err;
  20. }
  21. Bluebird.config({cancellation: true});
  22. configure({
  23. request: request,
  24. PromiseImpl: Bluebird,
  25. expose: [
  26. 'then',
  27. 'catch',
  28. 'finally',
  29. 'cancel',
  30. 'promise'
  31. // Would you like to expose more Bluebird methods? Try e.g. `rp(...).promise().tap(...)` first. `.promise()` returns the full-fledged Bluebird promise.
  32. ],
  33. constructorMixin: function (resolve, reject, onCancel) {
  34. var self = this;
  35. onCancel(function () {
  36. self.abort();
  37. });
  38. }
  39. });
  40. request.bindCLS = function RP$bindCLS() {
  41. throw new Error('CLS support was dropped. To get it back read: https://github.com/request/request-promise/wiki/Getting-Back-Support-for-Continuation-Local-Storage');
  42. };
  43. module.exports = request;