webworkify
Advanced tools
Comparing version 1.0.2 to 1.1.0
26
index.js
@@ -11,6 +11,11 @@ var bundleFn = arguments[3]; | ||
var cacheKeys = Object.keys(cache); | ||
for (var i = 0, l = cacheKeys.length; i < l; i++) { | ||
var key = cacheKeys[i]; | ||
if (cache[key].exports === fn) { | ||
var exp = cache[key].exports; | ||
// Using babel as a transpiler to use esmodule, the export will always | ||
// be an object with the default export as a property of it. To ensure | ||
// the existing api and babel esmodule exports are both supported we | ||
// check for both | ||
if (exp === fn || exp.default === fn) { | ||
wkey = key; | ||
@@ -20,3 +25,3 @@ break; | ||
} | ||
if (!wkey) { | ||
@@ -35,9 +40,14 @@ wkey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16); | ||
var skey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16); | ||
var scache = {}; scache[wkey] = wkey; | ||
sources[skey] = [ | ||
Function(['require'],'require(' + stringify(wkey) + ')(self)'), | ||
Function(['require'], ( | ||
// try to call default if defined to also support babel esmodule | ||
// exports | ||
'var f = require(' + stringify(wkey) + ');' + | ||
'(f.default ? f.default : f)(self);' | ||
)), | ||
scache | ||
]; | ||
var src = '(' + bundleFn + ')({' | ||
@@ -52,5 +62,5 @@ + Object.keys(sources).map(function (key) { | ||
; | ||
var URL = window.URL || window.webkitURL || window.mozURL || window.msURL; | ||
return new Worker(URL.createObjectURL( | ||
@@ -57,0 +67,0 @@ new Blob([src], { type: 'text/javascript' }) |
{ | ||
"name": "webworkify", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "launch a web worker that can require() in the browser with browserify", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6384
73