lego-bigpipe
Advanced tools
Comparing version 0.1.3 to 0.1.4
'use strict'; | ||
var vm = require('vm'); | ||
var ejs = require('ejs'); | ||
@@ -33,3 +34,6 @@ var tpl = { | ||
if (data.source && data.data) { | ||
pagelet.html = ejs.render(data.source, {locals: data.data}); | ||
var sandbox = {module: {}}; | ||
var code = 'var exports=module.exports={};' + data.data; | ||
vm.runInNewContext(code, sandbox); | ||
pagelet.html = ejs.render(data.source, {locals: sandbox.module.exports}); | ||
} else if (data.source) { | ||
@@ -36,0 +40,0 @@ pagelet.html = data.source; |
{ | ||
"name": "lego-bigpipe", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "a bigpipe builder for scrat-lego", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
20
test.js
@@ -12,8 +12,8 @@ // (╯°□°)╯︵oƃǝ˥ | ||
source: '<h1><%= name %></h1>', | ||
data: {name: 'unit'} | ||
data: 'module.exports = { name: "unit" };' | ||
}; | ||
var r = lego.unit(u); | ||
r.should.have.property('code', u.code); | ||
r.should.have.property('bigpipe', '<h1>unit</h1><script>lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"]});</script>'); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"],"html":"<h1>unit</h1>","css":["c/c1/c1","c/c2/c2"]});'); | ||
r.should.have.property('bigpipe', '<h1>unit</h1><script>lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"]});</script>\n'); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"],"html":"<h1>unit</h1>","css":["c/c1/c1","c/c2/c2"]});\n'); | ||
}); | ||
@@ -28,4 +28,4 @@ | ||
r.should.have.property('code', u.code); | ||
r.should.have.property('bigpipe', u.source); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","html":"<h1>Hello, world!</h1>"});'); | ||
r.should.have.property('bigpipe', u.source + '\n'); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","html":"<h1>Hello, world!</h1>"});\n'); | ||
}); | ||
@@ -40,4 +40,4 @@ | ||
r.should.have.property('code', u.code); | ||
r.should.have.property('bigpipe', '<script>lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"]});</script>'); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"]});'); | ||
r.should.have.property('bigpipe', '<script>lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"]});</script>\n'); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","js":["c/c1/c1","c/c1/c11","c/c2/c2"]});\n'); | ||
}); | ||
@@ -53,3 +53,3 @@ | ||
r.should.have.property('bigpipe', ''); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","css":["c/c1/c1","c/c2/c2"]});'); | ||
r.should.have.property('quickling', 'lego.onPageletArrive({"id":"unit","css":["c/c1/c1","c/c2/c2"]});\n'); | ||
}); | ||
@@ -168,3 +168,3 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <link rel="stylesheet" type="text/css" href="/u/u1/u11.css.js">\n <link rel="stylesheet" type="text/css" href="/u/u1/u12.css.js">\n <link rel="stylesheet" type="text/css" href="/u/u2/u21.css.js">\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <script src="/u/u1/u11.css.js"></script>\n <script src="/u/u1/u12.css.js"></script>\n <script src="/u/u2/u21.css.js"></script>\n </head>\n<body>\n'); | ||
}); | ||
@@ -189,4 +189,4 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <link rel="stylesheet" type="text/css" href="/c/u/u1/u11.css.js;u/u1/u12.css.js;u/u2/u21.css.js">\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <script src="/c/u/u1/u11.css.js;u/u1/u12.css.js;u/u2/u21.css.js"></script>\n </head>\n<body>\n'); | ||
}); | ||
}); |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
12006
329
1