browserify / sha.js

Streamable SHA hashes in pure javascript
Other
288 stars 60 forks source link

console output from hexpp.js #2

Closed josdejong closed 10 years ago

josdejong commented 10 years ago

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

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

josdejong commented 10 years ago

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?

dominictarr commented 10 years ago

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?

josdejong commented 10 years ago

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?

dominictarr commented 10 years ago

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

josdejong commented 10 years ago

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!