Skip to content

Commit c61d50a

Browse files
committed
Load polyfills if features are unavailable, don't rely on Node.js version
1 parent a612120 commit c61d50a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

shim.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
var semver = require('semver');
2-
if (semver.satisfies(process.version, '>= 0.12.0')) {
3-
return;
1+
if (typeof Promise === 'undefined') {
2+
global.Promise = require('bluebird');
43
}
54

6-
global.Promise = require('bluebird');
7-
require('array.prototype.find').shim();
8-
require('buffer-compare-shim');
9-
require('buffer-equals-polyfill');
10-
require('crypto').createECDH = require('create-ecdh');
5+
if (!Array.prototype.find) {
6+
require('array.prototype.find').shim();
7+
}
8+
9+
if (!Buffer.prototype.compare || !Buffer.compare) {
10+
require('buffer-compare-shim');
11+
}
12+
13+
if (!Buffer.prototype.equals) {
14+
require('buffer-equals-polyfill');
15+
}
16+
17+
var crypto = require('crypto');
18+
19+
if (!crypto.createECDH) {
20+
crypto.createECDH = require('create-ecdh');
21+
}

0 commit comments

Comments
 (0)