Closed josdejong closed 10 years ago
oh. this is because browserify doesn't do module.parent so it look like you are running every file from the command line.
yeah, I'm using webpack. It's not so nice having my library (packed with webpack) output these console logs all the time...
But I suppose these console.log statements shouldn't be there anyway?
how do you normally detect whether you are in the browser in webpack?
in browserify I'd do process.title === 'browser'
?
are you using this module directly or via crypto-browserify?
Yes, webpack uses sha.js via crypto-browserify (see also https://github.com/webpack/webpack/issues/245).
I see sha.js has a command line interface. I may be missing something trivial, but if these console.log statements are related to the command line interface (rather than some forgotten output for debugging), then I still don't understand why these statements are located in hexpp.js
rather than only in bin.js
? I suppose hexpp.js shouldn't need to know about it's environment anyway?
you didn't answer my question. Anyway, it was just a debugging thing - hexpp isn't even used anymore, so it's not required anymore. and I removed that bit too. upgrade to crypto-browserify@2.1.6
you didn't answer my question
o sorry... I guess this one:
how do you normally detect whether you are in the browser in webpack?
If you ask me, this hasn't to do with webpack or browserify, but with individual modules. Most modules I write are environment independent and don't need to know where they are running (node.js, browser, etc). If a module needs environment specific functionality, I normally just check for the availability of these features the ducktype way. When I need the DOM, I can for example test whether typeof window !== 'undefined'
returns true.
I'm not sure what you need to detect exactly in sha.js, but you may have a look at how UMD determines running in an AMD, commonjs, or browser environment: https://github.com/umdjs/umd
Thanks for removing the comments!
sha.js outputs hex dumps in the console, I guess this is not the intention:
https://github.com/dominictarr/sha.js/blob/master/hexpp.js#L41 https://github.com/dominictarr/sha.js/blob/master/hexpp.js#L42