freedom-for-node
Advanced tools
Comparing version 0.1.9 to 0.2.0
@@ -13,3 +13,3 @@ /*globals freedom, console */ | ||
socket.listen('localhost', '8080'); | ||
socket.on('onConnect', function(acceptInfo) { | ||
socket.on('onConnection', function(acceptInfo) { | ||
var child = freedom['core.tcpsocket'](acceptInfo.socket); | ||
@@ -16,0 +16,0 @@ child.on('onData', function(readInfo) { |
@@ -9,3 +9,3 @@ /** | ||
jasmine_node: { | ||
integration: ['test'] | ||
integration: ['spec'] | ||
}, | ||
@@ -12,0 +12,0 @@ bump: { |
83
index.js
@@ -1,2 +0,2 @@ | ||
/*jslint indent:2,white:true,sloppy:true,node:true */ | ||
/*jslint node:true */ | ||
/* | ||
@@ -7,60 +7,33 @@ * freedom.js Node runtime | ||
'use strict'; | ||
var resolvers = [], | ||
providers = [ | ||
require('freedom/providers/core/core.unprivileged'), | ||
require('freedom/providers/core/echo.unprivileged'), | ||
require('freedom/providers/core/logger.console'), | ||
require('freedom/providers/core/peerconnection.unprivileged'), | ||
require('./providers/core.storage'), | ||
require('./providers/core.tcpsocket'), | ||
require('./providers/core.udpsocket') | ||
], | ||
oauth = require('freedom/providers/core/oauth'), | ||
websocket = require('freedom/providers/core/websocket.unprivileged'); | ||
if (!module.parent) { | ||
require(__dirname + '/lib/modulecontext'); | ||
return; | ||
} | ||
websocket.setSocket(require('ws'), true); | ||
global.Promise = require('es6-promise').Promise; | ||
providers.push(oauth); | ||
providers.push(websocket); | ||
var fileInfo = require('freedom'), | ||
glob = require('glob'), | ||
freedomPrefix = require.resolve('freedom').substr(0, | ||
require.resolve('freedom').lastIndexOf('freedom') + 8); | ||
if (!module.parent) { | ||
require('./lib/modulecontext'); | ||
} else { | ||
global.Promise = require('es6-promise').Promise; | ||
require('./lib/resolvers')(resolvers); | ||
fileInfo.FILES.srcCore.concat( | ||
fileInfo.FILES.srcPlatform).forEach(function(dir) { | ||
glob.sync(freedomPrefix + '/' + dir).forEach(function(file) { | ||
require(file); | ||
module.exports.freedom = require('freedom/src/entry').bind({}, { | ||
location: "node://" + module.parent.filename, | ||
portType: require('./lib/link'), | ||
providers: providers, | ||
resolvers: resolvers, | ||
isModule: false | ||
}); | ||
}); | ||
glob.sync(__dirname + '/providers/*.js').forEach(function(file) { | ||
require(file); | ||
}); | ||
fdom.resources.addResolver(function(manifest, url, resolve) { | ||
var base; | ||
if (manifest.indexOf('node://') !== 0) { | ||
return false; | ||
} | ||
base = manifest.substr(0, manifest.lastIndexOf("/")); | ||
if (url.indexOf("/") === 0) { | ||
resolve("node://" + url); | ||
} else { | ||
resolve(base + "/" + url); | ||
} | ||
return true; | ||
}); | ||
fdom.resources.addRetriever('node', function(url, resolve, reject) { | ||
var filename = url.substr(7); | ||
require('fs').readFile(filename, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
module.exports.freedom = function(fdom, manifest, options, freedomcfg) { | ||
if (typeof freedomcfg !== 'undefined') { freedomcfg(fdom.apis.register.bind(fdom.apis)); } | ||
return fdom.setup(global, undefined, fdom.util.mixin({ | ||
portType: 'Node', | ||
isModule: false, | ||
stayLocal: true, | ||
location: "node://" + module.parent.filename, | ||
manifest: manifest | ||
}, options)); | ||
}.bind(global, fdom); | ||
} |
@@ -0,34 +1,34 @@ | ||
/*jslint node:true, sloppy:true */ | ||
/*globals Uint8Array,Uint16Array,ArrayBuffer,DataView*/ | ||
var vm = require('vm'); | ||
var fs = require('fs'); | ||
var NodeLink = require('./link'); | ||
var link = new NodeLink(); | ||
// compute freedom.js source. | ||
var src = fs.readFileSync(__dirname + '/moduleentry.js'), | ||
fileInfo = require('freedom'), | ||
glob = require('glob'), | ||
freedomPrefix = require.resolve('freedom').substr(0, | ||
require.resolve('freedom').lastIndexOf('freedom') + 8); | ||
var src = fs.readFileSync(require.resolve('freedom/freedom')); | ||
src += fs.readFileSync(require.resolve('es6-promise/dist/promise-1.0.0')); | ||
var freedomVM; | ||
fileInfo.FILES.srcCore.concat( | ||
fileInfo.FILES.srcPlatform).forEach(function(dir) { | ||
glob.sync(freedomPrefix + '/' + dir).forEach(function(file) { | ||
src += fs.readFileSync(file); | ||
}); | ||
}); | ||
glob.sync(__dirname + '/../providers/*.js').forEach(function(file) { | ||
src += fs.readFileSync(file); | ||
}); | ||
// Create Minimal Context. | ||
var context = { | ||
// setTimeout - for delaying async / implementing promises. | ||
setTimeout: function(cb, time) { | ||
setTimeout: function (cb, time) { | ||
setTimeout(cb, time); | ||
}, | ||
clearTimeout: function(id) { | ||
clearTimeout: function (id) { | ||
clearTimeout(id); | ||
}, | ||
// postMessage - sending messages out of the module. | ||
postMessage: function(msg) { | ||
postMessage: function (msg) { | ||
// Convert binary blobs into native buffers pre-send | ||
if (msg && msg.message && msg.message.message && | ||
msg.message.message.binary) { | ||
var out = [], i = 0; | ||
for (i = 0; i < msg.message.message.binary.length; i += 1) { | ||
out.push(new Buffer(new Uint8Array(msg.message.message.binary[i]))); | ||
} | ||
msg.message.message.binary = out; | ||
} | ||
process.send(msg); | ||
@@ -38,4 +38,6 @@ }, | ||
_om: null, | ||
onMessage: function(cb) { | ||
context._om = cb; | ||
addEventListener: function (type, cb) { | ||
if (type === 'message' && !context._om) { | ||
context._om = cb; | ||
} | ||
}, | ||
@@ -48,7 +50,12 @@ ArrayBuffer: ArrayBuffer, | ||
// importScripts - Loading code into the module. | ||
importScripts: function(script) { | ||
importScripts: function (script) { | ||
var file, name; | ||
try { | ||
var file = fs.readFileSync(script.substr(7)); | ||
vm.runInContext(file, freedomVM, script.substr(7)); | ||
} catch(e) { | ||
//TODO: enforce constrained location of loaded files. | ||
if (script.indexOf('node://') === 0) { | ||
name = script.substr(7); | ||
} | ||
file = fs.readFileSync(name); | ||
vm.runInContext(file, freedomVM, name); | ||
} catch (e) { | ||
console.error(e); | ||
@@ -59,8 +66,9 @@ process.exit(1); | ||
}; | ||
context.global = context; | ||
var freedomVM = vm.createContext(context); | ||
freedomVM = vm.createContext(context); | ||
//console.log('Starting VM Context'); | ||
try { | ||
vm.runInContext(src, freedomVM, 'freedom.js.vm'); | ||
} catch(e) { | ||
} catch (e) { | ||
// Report Syntax error. | ||
@@ -72,5 +80,6 @@ process.send(e); | ||
process.on('message', function(msg) { | ||
process.on('message', function (msg) { | ||
if (context._om) { | ||
context._om(msg); | ||
link.fix(msg.message); | ||
context._om({data: msg}); | ||
} else { | ||
@@ -77,0 +86,0 @@ console.warn('Message dropped - VM not ready'); |
{ | ||
"name": "freedom-for-node", | ||
"description": "Embracing a distributed web", | ||
"version": "0.1.9", | ||
"version": "0.2.0", | ||
"homepage": "http://freedomjs.org", | ||
@@ -30,3 +30,3 @@ "bugs": { | ||
"es6-promise": "~1.0.0", | ||
"freedom": "~0.5.6", | ||
"freedom": "~0.6.0", | ||
"glob": "~4.0.2", | ||
@@ -40,4 +40,4 @@ "json-store": "0.0.1", | ||
"peerDependencies": { | ||
"freedom": "~0.5.0" | ||
"freedom": "~0.6.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
39451
20
855
3
5
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfreedom@0.6.36(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
- Removedfreedom@0.5.7(transitive)
Updatedfreedom@~0.6.0