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

Configure project with 1 level #290

Open
Vittly opened this issue Mar 13, 2018 · 4 comments
Open

Configure project with 1 level #290

Vittly opened this issue Mar 13, 2018 · 4 comments

Comments

@Vittly
Copy link
Collaborator

Vittly commented Mar 13, 2018

bem-react-components is good example of project with 1 level. For now it has only "blocks" directory for all components and have no bemrc. My project uses "bem-react-components". I want to build it with webpack-bem-plugin. "webpack-bem-plugin" needs from all libraries to have its bemrc. So I had to write it for "bem-react-components"

My knowledge base:

  • "react-preset" transforms empty layer string to "blocks" directory: code here
  • "bem/sdk.config" can resolve set item to library layer: proof. Can we remove it? It is prohibited at index.js)
  • "bem/sdk.config" takes any non string set value as is: code

My attempt:

// bem-react-components/.bemrc
{
  levels: [
    // some nasty hacking#1 with empty layer
    { layer: '', naming: 'react' }
  ],
  sets: {
    // if set value is not a string we can do more hacking#2
    common: { layer: '' }
  }
}

// my project .bemrc
{
  levels: [...],
  sets: {
    touch: 'common@bem-react-components common touch'
  }
}

It is not working because of you cannot simply pass empty layer.

My suggestions:

  1. Remove layer? from "react-preset" or remove default layer from "naming.cell.stringify".
  2. Deny projects with 1 level (like "bem-react-components") or give simple way to write bemrc for them without hacking
@Vittly
Copy link
Collaborator Author

Vittly commented Mar 16, 2018

@tadatuta tells me that path property can directly point to custom path.

Like:

{
  levels: [{ layer: 'common', path: 'blocks' }],
  sets: { common: 'common' }
}
@Vittly
Copy link
Collaborator Author

Vittly commented Mar 17, 2018

This approach will fail when BemCell will be stringified with preset. We will get something like "blocks/common.blocks". Besides level defined with path property is deprecated

@qfox
Copy link
Member

qfox commented Mar 20, 2018

@Vittly

  1. Why you trying to use bem-react-components?
  2. By design you can't use empty layer, it is correct. But you can pass common value and make it after stringifying empty (along with dot) like it does in tests for schemes with @{layer} suffix: https://github.com/bem/bem-sdk/blob/master/packages/naming.cell.stringify/test/cell-stringify.test.js#L71-L79 — just pass in defaultLayer option.
@Vittly
Copy link
Collaborator Author

Vittly commented Mar 21, 2018

  1. @veged sends me in this direction (actually wrong one). Our projects should use another library I understand that now. We've planned to migrate from "bem-react-components"
  2. Hmm "defaultLayer" seems good (anyway I should define custom naming). So right form of "bemrc" for "bem-react-components" is:
{
  naming: {
    basedOn: 'react',
    fs: { patter: 'blocks/${entity}.${tech}' }
  },
  levels: [{ layer: 'common', path: 'blocks' }],
  sets: {
    common: 'common'
  }
}

Yes?

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