Add method to extract level configuration from path
In webpack-bem-plugin I want to get preset from path to specific file in project.
Firstly I thought that levelSync solves my problem. But It returns "nearest parent config".
Then I read Readme. This part:
"levels": [
{
"path": "path/to/level",
"scheme": "nested" // < --- Look here. May be "preset" or "naming" should be there
}
],
There is no method to get options for specific layer. My suggestions:
- add method to return level declaration by path to file
- add method to return level declaration by level (if naming.file.parse return level from path)
- tell me that "preset" or "naming" is project level option and put it in the root of
.bemrc+ add fix to readme
cc @tadatuta We need your expertise
You are right, naming is project level option and can be in the root of .bemrc.
Added it to example in readme: https://github.com/bem/bem-sdk/pull/286
I thought that levelSync solves my problem. But It returns "nearest parent config".
Actually it's not parent config but the merge of all the declarations for the level from all the configs (almost like Object.assign(levelDeclFromTopLevelConf, levelDeclFromNearestLevelConf)).
There's possibility to work with raw data with config method but for sure it's not convenient.
Actually it's not parent config but the merge of all the declarations for the level from all the configs
Yes but except fields defined in levelConf.
Lets write simple example:
// .bemrc
{
prop1: 'foo',
levels: [{ layer: 'bar', prop2: 'baz' }]
}
// code
const BemConf = require('@bem/sdk.config');
const config = new BemConf();
config.getLevelSync('bar');
// returns { prop1: 'foo' } <---- where is my prop2 ?
Issue is about two things:
-
namingshould be top level property in example. Please fix https://github.com/bem/bem-sdk/pull/286/files#r170572472 - somewhere should be a way to get properties from level declaration. Is it?
the issue here is that level() and levelSync() still expect path to level as an argument not layer name (see: https://github.com/bem/bem-sdk/blob/master/packages/config/index.js#L265).
so it your example config.levelSync('bar'); is equivalent to config.levelSync('anythingElse'); and returns just common config. with path is works how expected (https://github.com/bem/bem-sdk/pull/286/files#r170595399).
what we need is to support both path (as fallback) and layer as arguments for level methods.
Agree 👍 Here is noted that path is deprecated also
what we need is to support both path (as fallback) and layer as arguments for level methods.
Wait, what you mean about layer as arguments?
We still have levels with one or more layers. And they are still can have separate config.