cls-bluebird
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "cls-bluebird", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Make bluebird work with the continuation-local-storage module.", | ||
@@ -27,12 +27,10 @@ "main": "shim.js", | ||
"dependencies": { | ||
"shimmer": "~1" | ||
"shimmer": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"tap": "~0.4.4", | ||
"redis": "~0.9.0" | ||
}, | ||
"peerDependencies": { | ||
"continuation-local-storage": "~3", | ||
"bluebird": ">=1.0.3" | ||
"redis": "~0.9.0", | ||
"continuation-local-storage": "^3.1.7", | ||
"bluebird": "^2.10.2" | ||
} | ||
} |
@@ -6,2 +6,15 @@ # continuation-local-storage support for bluebird promises | ||
For documentation, check the above link. | ||
It works in the same way and uses the same tests. | ||
It works in the same way and uses the same tests. | ||
Only difference is the call signature. You can provide a specific Bluebird constructor to be shimmed, rather than the default. | ||
API: `clsBluebird( ns [, Promise] )` | ||
```js | ||
var cls = require('continuation-local-storage'); | ||
var ns = cls.createNamespace('NODESPACE'); | ||
var Promise = require('bluebird'); | ||
var clsBluebird = require('clsBluebird'); | ||
clsBluebird(ns, Promise); | ||
``` |
27
shim.js
@@ -5,9 +5,20 @@ 'use strict'; | ||
module.exports = function patchBluebird(ns) { | ||
var Bluebird; | ||
try { | ||
Bluebird = require('bluebird'); | ||
} catch (err) {} | ||
module.exports = function patchBluebird(ns, Promise) { | ||
if (typeof ns.bind !== 'function') { | ||
throw new TypeError("must include namespace to patch bluebird against"); | ||
throw new TypeError('must include namespace to patch bluebird against'); | ||
} | ||
var Promise = require('bluebird'); | ||
var proto = Promise && Promise.prototype; | ||
if (!Promise) { | ||
Promise = Bluebird; | ||
if (!Promise) throw new Error('could not require bluebird'); | ||
} else if (!isBluebirdConstructor(Promise)) { | ||
throw new TypeError('promise implementation provided must be bluebird'); | ||
} | ||
var proto = Promise.prototype; | ||
shimmer.wrap(proto, '_addCallbacks', function(_addCallbacks) { | ||
@@ -23,1 +34,9 @@ return function ns_addCallbacks(fulfill, reject, progress, promise, receiver, domain) { | ||
}; | ||
function isBluebirdConstructor(Promise) { | ||
return isBluebirdPromise(new Promise(function() {})); | ||
} | ||
function isBluebirdPromise(promise) { | ||
return Object.prototype.hasOwnProperty.call(promise, '_promise0'); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9711
1
7
127
20
4
3
- Removedasync-listener@0.6.10(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedcontinuation-local-storage@3.2.1(transitive)
- Removedemitter-listener@1.1.2(transitive)
- Removedsemver@5.7.2(transitive)
Updatedshimmer@^1.1.0