browser-module-sandbox
Advanced tools
Comparing version 1.0.0 to 1.1.0
26
index.js
var inherits = require('inherits') | ||
var iframe = require('iframe') | ||
var events = require('events') | ||
var extend = require('extend') | ||
var request = require('browser-request') | ||
@@ -23,6 +22,9 @@ var detective = require('detective') | ||
Sandbox.prototype.bundle = function(entry) { | ||
Sandbox.prototype.bundle = function(entry, preferredVersions) { | ||
if (!preferredVersions) preferredVersions = {} | ||
var self = this | ||
var modules = detective(entry) | ||
self.emit('bundleStart') | ||
self.emit('modules', modules) | ||
var body = { | ||
@@ -34,6 +36,16 @@ "options": { | ||
} | ||
modules.map(function(module) { | ||
body.dependencies[module] = 'latest' | ||
var version = preferredVersions[module] || 'latest' | ||
body.dependencies[module] = version | ||
}) | ||
self.emit('bundleStart') | ||
request({method: "POST", body: body, url: this.cdn + '/multi', json: true}, function(err, resp, json) { | ||
if (err) { | ||
self.emit('bundleEnd') | ||
return err | ||
} | ||
var allBundles = '' | ||
@@ -43,2 +55,3 @@ Object.keys(json).map(function(module) { | ||
}) | ||
// setTimeout is because iframes report inaccurate window.innerWidth/innerHeight, even after DOMContentLoaded! | ||
@@ -50,4 +63,5 @@ var body = self.iframeBody + | ||
'}, 0)</script>' | ||
self.iframe.setHTML({ head: self.iframeHead + self.iframeStyle, body: body }) | ||
self.emit('bundleEnd') | ||
var html = { head: self.iframeHead + self.iframeStyle, body: body } | ||
self.iframe.setHTML(html) | ||
self.emit('bundleEnd', html) | ||
}) | ||
@@ -54,0 +68,0 @@ } |
{ | ||
"name": "browser-module-sandbox", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "uses browserify-cdn to run node code in an iframe", | ||
@@ -13,3 +13,2 @@ "repository": { | ||
"inherits": "1.0.0", | ||
"extend": "1.1.3", | ||
"detective": "~2.1.2" | ||
@@ -16,0 +15,0 @@ }, |
@@ -31,4 +31,18 @@ # browser-module-sandbox | ||
## events | ||
### sandbox.on('modules', function(modules) {}) | ||
modules is the array of modules that gets parsed out of the bundle entry by the `detective` module | ||
### sandbox.on('bundleStart', function() {}) | ||
emits when the bundle request begins | ||
### sandbox.on('bundleEnd', function(html) {}) | ||
emits when the bundle request finishes. `html` is an object that has the iframe header contents and the full bundle body (made of up all the bundles + the entry in an executable form) | ||
## license | ||
BSD |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3594
4
55
47
0
- Removedextend@1.1.3
- Removedextend@1.1.3(transitive)