Comparing version 1.0.1 to 1.1.0
33
cli.js
@@ -13,22 +13,20 @@ #! /usr/bin/env node | ||
var debug = function () { | ||
if (argv.v) console.log.apply(this, arguments) | ||
if (argv.v) console.error.apply(this, arguments) | ||
} | ||
var PREAMBLE = | ||
'var exoform, __module, __self, a = []\n' + | ||
'var __meta\n' + | ||
'if (typeof arguments !== \'undefined\') {\n' + | ||
' a = arguments;\n' + | ||
' exoform = a[0]\n' + | ||
' __self = a[1]\n' + | ||
' __module = a[4]\n' + | ||
' __meta = arguments[0]\n' + | ||
'} else {\n' + | ||
' exoform = require(\'exoform\')\n' + | ||
' __module = function () {}\n ' + | ||
'}\n' + | ||
'var __refs = a[2] || []\n' + | ||
'var exports = a[3]\n' + | ||
' __meta = {\n' + | ||
' exoform: require(\'exoform\'),\n' + | ||
' define: function () {},\n' + | ||
' refs: [] } }\n' + | ||
'var exoform = __meta.exoform\n' + | ||
'var exports = __meta.mod\n' + | ||
'var module = { exports: exports }\n' | ||
var POSTAMBLE = | ||
'\n__module(module.exports)\n' | ||
'\n__meta.define(module.exports)\n' | ||
@@ -180,8 +178,9 @@ var readPackageInfo = function (root) { | ||
} else if (toRequire === 'exoform') { | ||
// already defined in preamble | ||
node.update('') | ||
} else { | ||
queue.push(srcPath) | ||
var newString = 'exoform.require(__refs,\'' + srcPath + '\', ' + | ||
debug('varName', varName) | ||
var newString = '__meta.exoform.require(__meta.refs,\'' + srcPath + '\', ' + | ||
'function (' + varName + ') {\n' | ||
if (reqExp.suffix || prefix) { | ||
@@ -230,5 +229,7 @@ newString += (prefix ? prefix + '.' : '') + | ||
if (err) throw err | ||
debug('writing cache...') | ||
fs.writeFileSync(cacheFile, JSON.stringify(diskCache)+'\n') | ||
if (argv.c) { | ||
debug('writing cache...') | ||
fs.writeFileSync(cacheFile, JSON.stringify(diskCache)+'\n') | ||
} | ||
console.log(res) | ||
}) |
30
index.js
@@ -6,3 +6,3 @@ var ipfs = require('ipfs-api')('localhost', 5001) | ||
var Exoform = { | ||
var exoform = { | ||
put: function (blob, cb) { | ||
@@ -15,2 +15,3 @@ ipfs.add(new Buffer(blob), function (err, res) { | ||
require: function (refs, hash, cb) { | ||
console.log('requiering', hash) | ||
if (hash.length < 32) { | ||
@@ -28,12 +29,17 @@ var cycle = parseInt(hash) | ||
.on('data', function (data) { | ||
(new Function(data))( | ||
Exoform, // library reference | ||
hash, // the hash of self | ||
newrefs, // list of parent modules | ||
mod, // the module to be initialized | ||
function (module) { | ||
memo[hash] = module | ||
cb(module) | ||
return module | ||
})}) | ||
var meta = { | ||
exoform: exoform, | ||
self: hash, | ||
refs: newrefs, | ||
mod: mod } | ||
meta.define = function (module) { | ||
memo[hash] = module | ||
Object.defineProperty(module, '__meta', { | ||
value: meta | ||
}) | ||
cb(module) | ||
return module | ||
} | ||
new Function(data)(meta) | ||
}) | ||
.on('error', function (err) { throw err }) | ||
@@ -45,2 +51,2 @@ }) | ||
module.exports = Exoform | ||
module.exports = exoform |
{ | ||
"name": "exoform", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Transform CommonJS to asynchronous content-addressed modules.", | ||
@@ -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
9427
290