-
-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent Browserify from shimming require('crypto') and Buffer by acce…
…ssing under _global
- Loading branch information
Showing
1 changed file
with
3 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,9 @@ | |
// Node.js crypto-based RNG - http://nodejs.org/docs/v0.6.2/api/crypto.html | ||
// | ||
// Moderately fast, high quality | ||
if (typeof(require) == 'function') { | ||
if (typeof(_global.require) == 'function') { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tracker1
|
||
try { | ||
var _rb = require('crypto').randomBytes; | ||
var _rb = _global.require('crypto').randomBytes; | ||
_rng = _rb && function() {return _rb(16);}; | ||
} catch(e) {} | ||
} | ||
|
@@ -49,7 +49,7 @@ | |
} | ||
|
||
// Buffer class to use | ||
var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array; | ||
var BufferClass = typeof(_global.Buffer) == 'function' ? _global.Buffer : Array; | ||
|
||
// Maps for number <-> hex string conversion | ||
var _byteToHex = []; | ||
|
1 comment
on commit 319dc6e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Browserify is still shimming require('crypto') for me..
sigh... 'just noticed that this breaks feature detection for the crypto API. In node.js, the
require
method isn't onglobal
- it's enclosed from elsewhere. As a result, node.js contexts are currently using Math.random instead of crypto. I'm not familiar enough with what Browserify is doing to suggest an alternative solution. Do you have any ideas?