Skip to content

Commit

Permalink
Merge 07698ef into 0d15133
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Apr 27, 2016
2 parents 0d15133 + 07698ef commit 1f1ee53
Show file tree
Hide file tree
Showing 17 changed files with 619 additions and 769 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
4 changes: 3 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"unused": true,

"node": true,
"esversion": 6,

"expr": true,
"sub": true
"sub": true,
"laxbreak": true
}
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ language: node_js

matrix:
include:
- node_js: "0.10"
- node_js: "0.12"
- node_js: "4"
env: COVERALLS=1
- node_js: "5"
Expand Down
37 changes: 25 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,29 @@ 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 files = tech.levels.getFilesByEntity(entity)
.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
48 changes: 27 additions & 21 deletions lib/deps/deps-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,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 +34,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 +91,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 +172,20 @@ 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);

files = introspection.getFilesByEntity(entity).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 +215,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 +264,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 +297,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
54 changes: 54 additions & 0 deletions lib/introspection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const stringifyEntity = require('bem-naming').stringify;
const parseEntity = require('bem-naming').parse;

module.exports = class Introspection {
constructor (levels, introspections) {
this._levels = levels;
this._introspections = introspections;
}
getLevels () {
return this._levels;
}
getEntities () {
const entities = [];

this._introspections.forEach(introspection => {
Object.keys(introspection).forEach(id => {
const entity = parseEntity(id);

entities.push(entity);
});
});

return entities;
}
getFilesByEntity (entity) {
const id = stringifyEntity(entity);

let files = [];
this._introspections.forEach(introspection => {
files = files.concat(introspection[id] || []);
});

return files;
}
getFilesByTechs (techs) {
const res = [];

this._introspections.forEach(introspection => {
Object.keys(introspection).forEach(id => {
const files = introspection[id];

files.forEach(file => {
if (techs.indexOf(file.tech) !== -1) {
res.push(file);
}
});
});
});

return res;
}
};
Loading

0 comments on commit 1f1ee53

Please sign in to comment.