Skip to content

Commit

Permalink
Prevent Browserify from shimming require('crypto') and Buffer by acce…
Browse files Browse the repository at this point in the history
…ssing under _global
  • Loading branch information
nateps committed Sep 14, 2013
1 parent 5281fea commit 319dc6e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions uuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@broofa

broofa Dec 8, 2014

Member

sigh... 'just noticed that this breaks feature detection for the crypto API. In node.js, the require method isn't on global - 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?

This comment has been minimized.

Copy link
@tracker1

tracker1 Dec 8, 2014

I've been using a wrapper around require...

//obscure to avoid browserify
function grequire(moduleName) {
  return require(moduleName);
}

using grequire in the rest of my code, which seems to work for not including in browserify.

This comment has been minimized.

Copy link
@broofa

broofa Dec 8, 2014

Member

@tracker1 - I'm confused. How does this help with this issue?

This comment has been minimized.

Copy link
@tracker1

tracker1 Dec 9, 2014

@broofa when you run your requires via another method, they don't wind up in the browserified output... for example ... i-promise when I used it via browserify, it doesn't include any of the promise implementations referenced, and doesn't blow up...

try {
var _rb = require('crypto').randomBytes;
var _rb = _global.require('crypto').randomBytes;
_rng = _rb && function() {return _rb(16);};
} catch(e) {}
}
Expand Down Expand Up @@ -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 = [];
Expand Down

1 comment on commit 319dc6e

@speigg
Copy link

@speigg speigg commented on 319dc6e May 7, 2014

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..

Please sign in to comment.