mendel-core
Advanced tools
Comparing version 4.0.0-alpha.0 to 4.0.0-alpha.1
{ | ||
"name": "mendel-core", | ||
"version": "4.0.0-alpha.0", | ||
"version": "4.0.0-alpha.1", | ||
"description": "Mendel shared dependencies production use", | ||
"main": "trees.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "tap test/*.js --coverage-map=../../.tap.coverage.map.js --no-check-coverage" | ||
}, | ||
@@ -16,3 +16,3 @@ "keywords": [ | ||
"type": "git", | ||
"url": "https://github.com/yahoo/mendel" | ||
"url": "https://github.com/considerinc/mendel" | ||
}, | ||
@@ -23,3 +23,3 @@ "dependencies": { | ||
"dissolve": "^0.2.1", | ||
"mendel-config": "^4.0.0-alpha.0", | ||
"mendel-config": "^4.0.0-alpha.1", | ||
"stream-browserify": "^2.0.1", | ||
@@ -29,3 +29,7 @@ "urlsafe-base64": "^1.0.0", | ||
}, | ||
"gitHead": "e91812ab9f13c60d431be5ce5e024d3a68073f42" | ||
"devDependencies": { | ||
"mkdirp": "^3.0.1", | ||
"tap": "^16.3.8" | ||
}, | ||
"gitHead": "6e24d114f4ff273753654df1aa5e6c124f626e25" | ||
} |
@@ -5,4 +5,4 @@ # Mendel Core - Production resolution of file system based experiments | ||
1. Given a variation array, it resolves which files should be used for a given user session. It outputs an "application tree" and a deterministic hash. | ||
2. Given a hash generated in step 1, it can recover all file dependencies for the same user session, resulting in the same exact "application tree" as step 1. | ||
1. Given a variation array, it resolves which files should be used for a given user session. It outputs an "application tree" and a deterministic hash. | ||
2. Given a hash generated in step 1, it can recover all file dependencies for the same user session, resulting in the same exact "application tree" as step 1. | ||
@@ -70,3 +70,2 @@ Mendel Core works by loading [Mendel Manifests](../../docs/Design.md) on a per-process basis, and resolves "application trees" on a per request (or per user session) basis. | ||
### Request Cycle: Hash resolution | ||
@@ -104,3 +103,2 @@ | ||
#### Mendel Hashing algorithm | ||
@@ -137,3 +135,2 @@ | ||
## Reference Usage | ||
@@ -162,7 +159,7 @@ | ||
const src = '/' + bundle + '.' + tree.hash + '.js'; | ||
const script = '<script src="'+ src + '"></script>'; | ||
response.end('<html><head>'+ script + '</head></html>'); | ||
const script = '<script src="' + src + '"></script>'; | ||
response.end('<html><head>' + script + '</head></html>'); | ||
} else { | ||
// if you have multiple bundles you will need routes based on bundle | ||
const jsPath = new RegExp('/' + bundle + '\.(.*)\.js'); | ||
const jsPath = new RegExp('/' + bundle + '.(.*).js'); | ||
if (jsPath.test(request.url)) { | ||
@@ -196,6 +193,6 @@ // your CDN can safely cache this url without cookies | ||
if (!tree || tree.error || tree.conflicts) { | ||
return response.end('Error ' + tree && tree.error || tree.conflictList); | ||
return response.end(('Error ' + tree && tree.error) || tree.conflictList); | ||
} | ||
const pack = bpack({raw: true, hasExports: true}); | ||
const pack = bpack({ raw: true, hasExports: true }); | ||
pack.pipe(response); | ||
@@ -202,0 +199,0 @@ |
@@ -6,3 +6,3 @@ /* Copyright 2015, Yahoo Inc. | ||
var Dissolve = require("dissolve"); | ||
var Dissolve = require('dissolve'); | ||
var URLSafeBase64 = require('urlsafe-base64'); | ||
@@ -19,15 +19,15 @@ | ||
.string('name', 6) | ||
.tap(function() { | ||
.tap(function () { | ||
if (this.vars.name !== 'mendel') { | ||
result.error = error("not generated by mendel"); | ||
result.error = error('not generated by mendel'); | ||
} | ||
}) | ||
.uint8('version') | ||
.tap(function() { | ||
.tap(function () { | ||
if (this.vars.version !== 1) { | ||
result.error = error(": version mismatch"); | ||
result.error = error(': version mismatch'); | ||
} | ||
}) | ||
.loop('branches', function(end) { | ||
this.uint8('data').tap(function() { | ||
.loop('branches', function (end) { | ||
this.uint8('data').tap(function () { | ||
if (this.vars.data === 255) { | ||
@@ -39,3 +39,3 @@ return end(); | ||
}) | ||
.tap(function() { | ||
.tap(function () { | ||
this.vars.branches = branches; | ||
@@ -45,3 +45,3 @@ }) | ||
.buffer('hash', 20) | ||
.tap(function() { | ||
.tap(function () { | ||
result.decoded = this.vars; | ||
@@ -53,3 +53,3 @@ }); | ||
parser.write(binary); | ||
} catch(e) { | ||
} catch (e) { | ||
result.error = error('bad base64 input'); | ||
@@ -67,5 +67,5 @@ } | ||
function error(msg) { | ||
var error = new Error("Invalid hash: " + msg); | ||
error.code = "BADHASH"; | ||
var error = new Error('Invalid hash: ' + msg); | ||
error.code = 'BADHASH'; | ||
return error; | ||
} |
@@ -29,3 +29,3 @@ /* Copyright 2015, Yahoo Inc. | ||
MendelHashWalker.prototype._resolveBranch = function(module) { | ||
MendelHashWalker.prototype._resolveBranch = function (module) { | ||
if (this.error) return {}; | ||
@@ -51,8 +51,8 @@ | ||
MendelHashWalker.prototype._error = function(msg) { | ||
MendelHashWalker.prototype._error = function (msg) { | ||
this.error = this.error || new Error(msg); | ||
this.error.code = "TRVRSL"; | ||
this.error.code = 'TRVRSL'; | ||
}; | ||
MendelHashWalker.prototype.found = function() { | ||
MendelHashWalker.prototype.found = function () { | ||
this._result = MendelWalker.prototype.found.call(this); | ||
@@ -59,0 +59,0 @@ |
@@ -6,9 +6,11 @@ /* Copyright 2015, Yahoo Inc. | ||
var Concentrate = require("concentrate"); | ||
var crypto = require("crypto"); | ||
var util = require("util"); | ||
var Concentrate = require('concentrate'); | ||
var crypto = require('crypto'); | ||
var util = require('util'); | ||
var URLSafeBase64 = require('urlsafe-base64'); | ||
function TreeSerialiser() { | ||
if (!(this instanceof TreeSerialiser)) { return new TreeSerialiser(); } | ||
if (!(this instanceof TreeSerialiser)) { | ||
return new TreeSerialiser(); | ||
} | ||
@@ -26,6 +28,6 @@ Concentrate.call(this); | ||
TreeSerialiser.prototype._metadata = function() { | ||
if (this._meta) throw new Error("Double metadata"); | ||
TreeSerialiser.prototype._metadata = function () { | ||
if (this._meta) throw new Error('Double metadata'); | ||
var name = "mendel"; | ||
var name = 'mendel'; | ||
var version = 1; | ||
@@ -36,3 +38,3 @@ this._meta = true; | ||
TreeSerialiser.prototype.pushBranch = function(index) { | ||
TreeSerialiser.prototype.pushBranch = function (index) { | ||
if (this._result) throw new Error("Can't pushPath after result"); | ||
@@ -42,3 +44,3 @@ return this.uint8(index); | ||
TreeSerialiser.prototype.pushFileHash = function(sha) { | ||
TreeSerialiser.prototype.pushFileHash = function (sha) { | ||
if (this._result) throw new Error("Can't pushFileHash after result"); | ||
@@ -52,3 +54,3 @@ if (Buffer.isBuffer(sha)) { | ||
TreeSerialiser.prototype.result = function() { | ||
TreeSerialiser.prototype.result = function () { | ||
if (this._result) return this._result; | ||
@@ -55,0 +57,0 @@ |
@@ -6,3 +6,3 @@ /* Copyright 2015, Yahoo Inc. | ||
var util = require("util"); | ||
var util = require('util'); | ||
var MendelVariationWalker = require('./tree-variation-walker'); | ||
@@ -23,3 +23,3 @@ | ||
MendelServerVariationWalker.prototype.find = function(module) { | ||
MendelServerVariationWalker.prototype.find = function (module) { | ||
var fileId = module.id; | ||
@@ -46,3 +46,3 @@ var resolved; | ||
MendelServerVariationWalker.prototype.found = function() { | ||
MendelServerVariationWalker.prototype.found = function () { | ||
// This walker doesn't care about deps index nor hashes | ||
@@ -49,0 +49,0 @@ return this._variationMap; |
@@ -26,3 +26,3 @@ /* Copyright 2015, Yahoo Inc. | ||
MendelVariationWalker.prototype._resolveBranch = function(module) { | ||
MendelVariationWalker.prototype._resolveBranch = function (module) { | ||
var fileId = module.id; | ||
@@ -35,3 +35,3 @@ var resolved; | ||
var index = module.variations.indexOf(this._lookupChains[i][j]); | ||
if(-1 !== index) { | ||
if (-1 !== index) { | ||
if (!foundIn) { | ||
@@ -50,3 +50,3 @@ // keep first match, priority by .mendelrc entry order | ||
} | ||
if (foundIn>1) { | ||
if (foundIn > 1) { | ||
this.conflicts++; | ||
@@ -61,3 +61,3 @@ this.conflictList[fileId] = true; | ||
MendelVariationWalker.prototype.found = function() { | ||
MendelVariationWalker.prototype.found = function () { | ||
return xtend(MendelWalker.prototype.found.call(this), { | ||
@@ -64,0 +64,0 @@ conflicts: this.conflicts, |
@@ -19,3 +19,3 @@ /* Copyright 2015, Yahoo Inc. | ||
MendelWalker.prototype.find = function(module) { | ||
MendelWalker.prototype.find = function (module) { | ||
var resolved; | ||
@@ -42,7 +42,7 @@ if (this.deps[module.index]) { | ||
MendelWalker.prototype._resolveBranch = function() { | ||
MendelWalker.prototype._resolveBranch = function () { | ||
throw new Error('You should extend and implement _resolveBranch'); | ||
}; | ||
MendelWalker.prototype.found = function() { | ||
MendelWalker.prototype.found = function () { | ||
var found = { | ||
@@ -49,0 +49,0 @@ deps: this.deps, |
62
trees.js
@@ -24,7 +24,7 @@ /* Copyright 2015, Yahoo Inc. | ||
this.ssrOutlet = this.config.outlets.find(outletConfig => { | ||
this.ssrOutlet = this.config.outlets.find((outletConfig) => { | ||
return outletConfig._plugin === 'mendel-outlet-server-side-render'; | ||
}); | ||
if (this.ssrOutlet) { | ||
this.ssrBundle = this.config.bundles.find(bundleConfig => { | ||
this.ssrBundle = this.config.bundles.find((bundleConfig) => { | ||
return bundleConfig.outlet === this.ssrOutlet.id; | ||
@@ -35,3 +35,3 @@ }); | ||
MendelTrees.prototype.findTreeForVariations = function(bundle, lookupChains) { | ||
MendelTrees.prototype.findTreeForVariations = function (bundle, lookupChains) { | ||
var finder = new MendelVariationWalker( | ||
@@ -47,3 +47,6 @@ lookupChains, | ||
MendelTrees.prototype.findServerVariationMap = function(bundles, lookupChains) { | ||
MendelTrees.prototype.findServerVariationMap = function ( | ||
bundles, | ||
lookupChains | ||
) { | ||
if (!this.ssrBundle) | ||
@@ -64,3 +67,3 @@ throw new Error( | ||
MendelTrees.prototype.findTreeForHash = function(bundle, hash) { | ||
MendelTrees.prototype.findTreeForHash = function (bundle, hash) { | ||
var finder = new MendelHashWalker(hash); | ||
@@ -73,3 +76,3 @@ | ||
MendelTrees.prototype._loadBundles = function() { | ||
MendelTrees.prototype._loadBundles = function () { | ||
var self = this; | ||
@@ -79,25 +82,30 @@ this.bundles = {}; | ||
confBundles.filter(bundle => bundle.manifest).forEach(function(bundle) { | ||
var bundlePath = bundle.manifest; | ||
try { | ||
self.bundles[bundle.id] = require(path.resolve(bundlePath)); | ||
} catch (error) { | ||
var newError = new Error(); | ||
newError.code = error.code; | ||
if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ENOENT') { | ||
newError.message = | ||
'Could not find "' + | ||
bundle.id + | ||
'" bundle at path ' + | ||
bundlePath; | ||
} else { | ||
newError.message = | ||
'Invalid bundle file at path ' + bundle.manifest; | ||
confBundles | ||
.filter((bundle) => bundle.manifest) | ||
.forEach(function (bundle) { | ||
var bundlePath = bundle.manifest; | ||
try { | ||
self.bundles[bundle.id] = require(path.resolve(bundlePath)); | ||
} catch (error) { | ||
var newError = new Error(); | ||
newError.code = error.code; | ||
if ( | ||
error.code === 'MODULE_NOT_FOUND' || | ||
error.code === 'ENOENT' | ||
) { | ||
newError.message = | ||
'Could not find "' + | ||
bundle.id + | ||
'" bundle at path ' + | ||
bundlePath; | ||
} else { | ||
newError.message = | ||
'Invalid bundle file at path ' + bundle.manifest; | ||
} | ||
throw newError; | ||
} | ||
throw newError; | ||
} | ||
}); | ||
}); | ||
}; | ||
MendelTrees.prototype._walkTree = function(bundle, finder) { | ||
MendelTrees.prototype._walkTree = function (bundle, finder) { | ||
var tree = this.bundles[bundle]; | ||
@@ -113,3 +121,3 @@ | ||
MendelTrees.prototype.variationsAndChains = function(lookFor) { | ||
MendelTrees.prototype.variationsAndChains = function (lookFor) { | ||
var lookupChains = []; | ||
@@ -116,0 +124,0 @@ var matchingVariations = []; |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
100697
53
1169
2
2
204
2
Updatedmendel-config@^4.0.0-alpha.1