Skip to content

Commit

Permalink
use hashing function exposed by browserify
Browse files Browse the repository at this point in the history
As of version 3.31.5 browserify uses relative paths to compute the file
hash. This means the karma-browserify bundle is incorrectly
hashing file ids to be required by the tests.

The hashing function is now available directly on the browserify bundle
instance (see browserify/browserify@9499ffb9). This commit fixes the
above mentioned issue by delegating the file id hashing to this exposed
function.

At the moment though, that hashing function is prefixed with an `_`
possibly indicating that it's intended for private internal usage. So
any changes to this methods name or placement will break this code. In
that case though, the break will be much easier to detect than the
errors caused previously.
  • Loading branch information
voidlock committed Mar 3, 2014
1 parent a9484a3 commit 3afe3b7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"karma": ">=0.9",
"browserify": "~2.36 || 3.x"
"browserify": ">=3.30.5"
},
"devDependencies": {
"groc": "0.x.x",
Expand Down
5 changes: 1 addition & 4 deletions src/index.coffee
Expand Up @@ -26,9 +26,6 @@ debug = false
# The safe configuration keys to apply to the browserify bundles.
configs = ['transform', 'ignore']

# Create a MD5 hash for browserify export names.
hash = (what) -> crypto.createHash('md5').update(what).digest('base64').slice 0, 6

# Apply select keys from a configuration object to a browserify bundle.
applyConfig = (b, cfg) ->
(b[c] v for v in [].concat cfg[c] if cfg?[c]? and b?[c]?) for c in configs
Expand Down Expand Up @@ -85,7 +82,7 @@ preprocessor = (logger, config={}) ->
fileBundle.deps(opts).pipe through (row) ->
if row.id isnt file.originalPath
depsCache.push row.id unless row.id in depsCache
row.source = "module.exports=require('#{hash row.id}');"
row.source = "module.exports=require('#{fileBundle._hash row.id}');"
@queue row

# Build the file bundle.
Expand Down

0 comments on commit 3afe3b7

Please sign in to comment.