Skip to content

Commit

Permalink
Merge 7ce5227 into 0d15133
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Apr 22, 2016
2 parents 0d15133 + 7ce5227 commit 4a0bc5e
Show file tree
Hide file tree
Showing 13 changed files with 592 additions and 745 deletions.
2 changes: 0 additions & 2 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireMultipleVarDecl": true,
"requireBlocksOnNewline": 1,
"disallowPaddingNewlinesInBlocks": true,
"disallowSpacesInsideArrayBrackets": "nested",
Expand All @@ -27,7 +26,6 @@
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"requireSpaceBeforeBinaryOperators": true,
Expand Down
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"node": true,

"expr": true,
"sub": true
"sub": true,
"laxbreak": true
}
38 changes: 26 additions & 12 deletions exlib/deps-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
* Заимствованный.
*/

var inherit = require('inherit');
var vowFs = require('enb/lib/fs/async-fs');
var vm = require('vm');
var Vow = require('vow');

var enb = require('enb');
var vow = require('vow');
var inherit = require('inherit');
var stringifyEntity = require('bem-naming').stringify;

var vowFs = enb.asyncFs || require('enb/lib/fs/async-fs');
var MustDeps = require('./must-deps');

module.exports.OldDeps = (function () {
Expand Down Expand Up @@ -185,13 +189,13 @@ module.exports.OldDeps = (function () {
var depsCount1 = this.getCount();
var depsCount2;

return Vow.when(this.expandOnceByFS())
return vow.when(this.expandOnceByFS())
.then(function again(newDeps) {

depsCount2 = newDeps.getCount();
if (depsCount1 !== depsCount2) {
depsCount1 = depsCount2;
return Vow.when(newDeps.expandOnceByFS(), again);
return vow.when(newDeps.expandOnceByFS(), again);
}

return newDeps.clone(_this);
Expand Down Expand Up @@ -228,7 +232,7 @@ module.exports.OldDeps = (function () {
return newDeps;
});
} else {
return Vow.fulfill(newDeps);
return vow.fulfill(newDeps);
}
},

Expand All @@ -243,20 +247,30 @@ module.exports.OldDeps = (function () {
var _this = this;
var tech = this.tech;

var files = tech.levels.getFilesByDecl(item.item.block, item.item.elem, item.item.mod, item.item.val)
var dep = item.item;
var entity = { block: dep.block };

dep.elem && (entity.elem = dep.elem);
dep.mod && (entity.modName = dep.mod);
dep.val && (entity.modVal = dep.val);

var id = stringifyEntity(entity);
var files = (tech.levels[id] || [])
.filter(function (file) {
return file.suffix === 'deps.js';
return file.tech === 'deps.js';
});

var promise = Vow.fulfill();
var promise = vow.fulfill();

files.forEach(function (file) {
var filename = file.path;

promise = promise.then(function () {
return vowFs.read(file.fullname, 'utf8').then(function (content) {
return vowFs.read(filename, 'utf8').then(function (content) {
try {
_this.parse(vm.runInThisContext(content, file.fullname), item);
_this.parse(vm.runInThisContext(content, filename), item);
} catch (e) {
throw new Error('Syntax error in file "' + file.fullname + '": ' + e.message);
throw new Error('Syntax error in file "' + filename + '": ' + e.message);
}
});
});
Expand Down
51 changes: 30 additions & 21 deletions lib/deps/deps-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var inherit = require('inherit'),
vm = require('vm'),
vow = require('vow'),
vfs = require('enb/lib/fs/async-fs'),
stringifyEntity = require('bem-naming').stringify,
yaml = require('js-yaml');

function DepsError(message) {
Expand All @@ -18,8 +19,8 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
*
* @param {Level[]} levels
*/
__constructor: function (levels) {
this.levels = levels;
__constructor: function (introspection) {
this.introspection = introspection;
this.declarations = [];
this.resolved = {};
this.declarationIndex = {};
Expand All @@ -34,7 +35,6 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
* @returns {Array}
*/
normalizeDep: function (dep, blockName, elemName) {
var levels = this.levels;
if (typeof dep === 'string') {
return [{ name: dep }];
} else {
Expand Down Expand Up @@ -92,9 +92,7 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
}
Object.keys(modObj).forEach(function (modName) {
var modVals = modObj[modName];
if (modVals === '*') {
modVals = levels.getModValues(dep.block || blockName, modName);
}

if (!Array.isArray(modVals)) {
modVals = [modVals];
}
Expand Down Expand Up @@ -175,15 +173,22 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
getDeps: function (decl) {
var _this = this,
mustDecls,
files;
if (decl.elem) {
files = this.levels.getElemFiles(decl.name, decl.elem, decl.modName, decl.modVal);
} else {
files = this.levels.getBlockFiles(decl.name, decl.modName, decl.modVal);
}
files = files.filter(function (file) {
return file.suffix === 'deps.js' || file.suffix === 'deps.yaml';
files,
introspection = this.introspection,
entity = { block: decl.name };

decl.elem && (entity.elem = decl.elem);
decl.modName && (entity.modName = decl.modName);
decl.modVal && (entity.modVal = decl.modVal);

var id = stringifyEntity(entity);

files = (introspection[id] || []).filter(function (file) {
var suffix = file.tech;

return suffix === 'deps.js' || suffix === 'deps.yaml';
});

var mustDepIndex = {},
shouldDepIndex = {};
mustDepIndex[declKey(decl)] = true;
Expand Down Expand Up @@ -213,13 +218,17 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
var shouldDeps = [];

function keepWorking(file) {
return vfs.read(file.fullname, 'utf8').then(function (depContent) {
if (file.suffix === 'deps.js') {
var filename = file.path;

return vfs.read(filename, 'utf8').then(function (depContent) {
var suffix = file.tech;

if (suffix === 'deps.js') {
var depData;
try {
depData = vm.runInThisContext(depContent);
} catch (e) {
throw new Error('Syntax error in file "' + file.fullname + '": ' + e.message);
throw new Error('Syntax error in file "' + filename + '": ' + e.message);
}
depData = Array.isArray(depData) ? depData : [depData];
depData.forEach(function (dep) {
Expand Down Expand Up @@ -258,13 +267,13 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
}
}
});
} else if (file.suffix === 'deps.yaml') {
} else if (suffix === 'deps.yaml') {
var depYamlStructure = yaml.safeLoad(depContent, {
filename: file.fullname,
filename: filename,
strict: true
});
if (!Array.isArray(depYamlStructure)) {
throw new Error('Invalid yaml deps structure at: ' + file.fullname);
throw new Error('Invalid yaml deps structure at: ' + filename);
}
_this.normalizeDeps(depYamlStructure, decl.name, decl.elem).forEach(function (nd) {
var key = declKey(nd),
Expand All @@ -291,7 +300,7 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
}
}).fail(function (err) {
if (err instanceof DepsError) {
err.message += ' in file "' + file.fullname + '"';
err.message += ' in file "' + filename + '"';
}
throw err;
});
Expand Down
Loading

0 comments on commit 4a0bc5e

Please sign in to comment.