Skip to content

Commit

Permalink
Fix checking for circle deps inside only js
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeti-or committed Mar 15, 2018
1 parent b342537 commit e9c1640
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ module.exports = function(source) {
namingOptions = options.naming || 'react',
bemNaming = bn(namingOptions),
// https://github.com/bem-sdk/bem-fs-scheme/issues/18
currentEntity = bemNaming.parse(path.basename(this.resourcePath).split('.')[0]),
currentEntityName = path.basename(this.resourcePath),
currentEntity = bemNaming.parse(currentEntityName.split('.')[0]),
currentEntityTech = extToTech[currentEntityName.substr(currentEntityName.indexOf('.') + 1)],
generators = getGenerators(options.generators);

generators.i18n = require('./generators/i18n').generate(langs);
Expand All @@ -55,18 +57,23 @@ module.exports = function(source) {
node.arguments[0].value,
currentEntity
)
// expand entities by all provided levels
// expand entities by all provided levels/techs
.reduce((acc, entity) => {
levels.forEach(layer => {
// if entity has tech get extensions for it or exactly it,
// otherwise expand entities by default extensions
(entity.tech? techMap[entity.tech] || [entity.tech] : defaultExts).forEach(tech => {
// don't push js block in context of block itself
// so we forewarn cycled requires
// example ``` block.react.js: import 'm:autoclosable=yes' ```
!(currentEntity.isEqual(BemEntityName.create(entity)) && tech === 'js') &&
// if entity has tech get extensions for it or exactly it,
// otherwise expand entities by default extensions
(entity.tech? techMap[entity.tech] || [entity.tech] : defaultExts).forEach(tech => {
// don't push js block in context of block itself
// so we forewarn cycled requires
// example ``` block.react.js: import 'm:autoclosable=yes' ```
if(!(
currentEntity.isEqual(BemEntityName.create(entity)) &&
currentEntityTech === 'js' &&
extToTech[tech] === 'js'
)) {
levels.forEach(layer => {
acc.push(BemCell.create({ entity, tech, layer }));
});
});
}
});
return acc;
}, [])
Expand Down
13 changes: 13 additions & 0 deletions test/order/order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,17 @@ describe('order', () => {
const jsFile = assets['main.bundle.js'];
expect(checkCycledRequires(jsFile)).toBe(true);
});

test('js: order no conflicts inside gemini.bemjson.js', async () => {
const mock = {
'gemini.bemjson.js' : `require('b:gemini')`,
'common.blocks/gemini' : {
'gemini.js' : `(1 + 1)`
}
};
const { assets } = await webpack('gemini.bemjson.js', { config : jsConfig, mock });

const jsFile = assets['main.bundle.js'];
expect(checkCycledRequires(jsFile)).toBe(true);
});
});

0 comments on commit e9c1640

Please sign in to comment.