diff --git a/lib/tech/index.js b/lib/tech/index.js index 8363afd4..eefaea62 100644 --- a/lib/tech/index.js +++ b/lib/tech/index.js @@ -6,6 +6,12 @@ var TechV1 = exports.Tech = require('./v1').Tech, Q = require('q'), U = require('../util'), + BEM, + getBem = function() { + if (!BEM) BEM = require('../..'); + + return BEM; + }; /** * Return tech class for the tech module path. * @@ -13,10 +19,13 @@ var TechV1 = exports.Tech = require('./v1').Tech, * @param {Level} [level] Level object to resolve techs by name. * @returns {Tech} Tech class. */ - getTechClass = exports.getTechClass = function(module, level) { + var getTechClass = exports.getTechClass = function(module, level) { + + var tech = typeof module === 'string'? require(module) : module; + + if (typeof tech === 'function') tech = tech(getBem()); - var tech = typeof module === 'string'? require(module) : module, - requiredVersion = tech.API_VER, + var requiredVersion = tech.API_VER, TechClass = requiredVersion > 1 ? TechV2 : TechV1; // link to tech class found in Tech property diff --git a/test/data/techs/function-tech.js b/test/data/techs/function-tech.js new file mode 100644 index 00000000..d1aaafad --- /dev/null +++ b/test/data/techs/function-tech.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = function(BEM) { + return { + techMixin: { + getBuildResults: function() { + return BEM.require.resolve('./techs/js'); + } + } + }; +}; diff --git a/test/tech.js b/test/tech.js index d9400da2..81f32297 100644 --- a/test/tech.js +++ b/test/tech.js @@ -131,6 +131,12 @@ describe('tech', function() { }); + it('for module with function-style code', function() { + var T = getTechClass(require.resolve('./data/techs/function-tech.js')); + T = new T('function-tech', 'function-tech'); + assert.equal(T.getBuildResults(), BEM.require.resolve('./techs/js.js')); + }); + it('throws an error when baseTechName is unresolvable', function() { assert.throws(function() { var level = new Level('', '');