Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to extract level configuration from path #277

Open
Vittly opened this issue Feb 4, 2018 · 6 comments
Open

Add method to extract level configuration from path #277

Vittly opened this issue Feb 4, 2018 · 6 comments

Comments

@Vittly
Copy link
Collaborator

Vittly commented Feb 4, 2018

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
@qfox
Copy link
Member

qfox commented Feb 5, 2018

cc @tadatuta We need your expertise

@tadatuta
Copy link
Member

You are right, naming is project level option and can be in the root of .bemrc.
Added it to example in readme: #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.

@Vittly
Copy link
Collaborator Author

Vittly commented Feb 26, 2018

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:

  1. naming should be top level property in example. Please fix https://github.com/bem/bem-sdk/pull/286/files#r170572472
  2. somewhere should be a way to get properties from level declaration. Is it?

@tadatuta
Copy link
Member

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.

@Vittly
Copy link
Collaborator Author

Vittly commented Feb 27, 2018

Agree 👍 Here is noted that path is deprecated also

@qfox
Copy link
Member

qfox commented Mar 1, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants