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 code #1

Merged
merged 1 commit into from
Feb 18, 2018
Merged

Add code #1

merged 1 commit into from
Feb 18, 2018

Conversation

Vittly
Copy link
Collaborator

@Vittly Vittly commented Jan 31, 2018

Need to check:

  • license text in package.json and README.md
  • readability of README.md. We need more examples from real world projects but may be for now current text is enough
  • other

@awinogradov @zxqfox @Yeti-or @veged ?

* b. libraries configs (like bem-react-components) for many reasons
* example: https://github.com/bem/bem-sdk/issues/261
*/
__prepareRc(bemConfig, libs, self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разве это не должен делать bem-config?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кто ж его заставит... @tadatuta

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should be there. Now not all wanted libraries has their bemrc and adding it (via PR for example) is not simple unfortunately. I'll do detailed comment

const entityFromPath = require('./helpers/entityFromPath');

function completeRequest(request, ctx) {
// TODO: move to @bem/sdk.import-notation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Заведи ишью?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сс @Yeti-or

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const BemEntityParse = require('@bem/sdk.naming.entity.parse');

function trimFilename(filePath) {
return path.basename(filePath).split('.')[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уверен? block.react.js

Copy link
Member

@qfox qfox Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это должно быть реализовано примерно в районе @bem/sdk.naming.file.parse

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.basename('/foo/bar/b__e_m.react.js').split('.')[0]; returns 'b__e_m' @awinogradov

@zxqfox - done bem/bem-sdk#276

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ node -p "path.basename('/foo/bar/b__e_m.assets/random.png').split('.')[0];"
random

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And sdk.naming.file.parse would handle it ?

Copy link
Member

@qfox qfox Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like. But we didn't talk about it much, (bem) file here is '/foo/bar/b__e_m.assets/'

};
});

// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yeti-or Can you tell us what actually webpack-bem-loader does?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, it adds, why do you think it's unnecessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part. I think we should simple remove this comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked:

parse('b:block e:elem m:mod')
/**
 * returns [
 *   { block: 'block', elem: 'elem' }, // __elem is here
 *   { block: 'block', elem: 'elem', mod: { name: 'mod' } }
 * ]
 */

parse('b:block m:mod=val')
/**
 * returns [
 *   { block: 'block' },
 *   { block: 'block', mod: { name: 'mod' } }, // _mod is here
 *   { lock: 'block', mod: { name: 'mod', val: 'val' } }
 * ]
 */

I'll remove nasty comment

README.md Outdated

## Known issues

* Small tests
Copy link
Member

@qfox qfox Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not enough ? Too few/small?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there are too small and too fast? we need to fix it and write big heavy ones =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Described in #3

README.md Outdated
## Known issues

* Small tests
* Not picking changes in `bemrc` in watch-mode
Copy link
Member

@qfox qfox Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rereading .bemrc doesn't work in watch-mode

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in plugin. May be its a problem. May be we should fix it in newer version of plugin so I noted it

const oldSync = rc.sync;

rc.sync = function(options) {
return configsMap[options.cwd] || oldSync(options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай напишем что тут происходит, кроме тестов?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

*/
class BemRequest {
constructor(request, filePath, levels, setIndex) {
const requestNaming = namingConvention.getFromLevelsByPath(levels, filePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не получилось достать из bem-config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more info in bem/bem-sdk#277

class BemRequest {
constructor(request, filePath, levels, setIndex) {
const requestNaming = namingConvention.getFromLevelsByPath(levels, filePath);
const ctx = entityFromPath(filePath, requestNaming);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это должен быть @bem/sdk.naming.file.parse в купе с @bem/sdk.config

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

const ctx = entityFromPath(filePath, requestNaming);

// TODO: remove duplicates from array in @bem/sdk.import-notation
// https://github.com/bem/bem-sdk/issues/263
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тикет закрыт

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zxqfox я только не помню выпустили ли мы версию

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

.sort(tech => tech === 'js') // js should be the last
.map(tech => {
const generator = tech === 'js' ? jsGenerator : generalGenerator;
const existingFiles = techToFiles[tech].filter(fs.existsSync);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ммм, а нельзя это делать через webpack-овские ручки?
странно работать с фс напрямую, когда webpack должен всё контролировать

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. In my solution "No".

I do resolve bem-require b:b e:e by module implemented with source (require('b.js'),require('b_e.js')).applyDecls(). Lack of files causes module require error. To handle this we need to override requires of actual files. I want to avoid this and reduce amount of redefinitions of standard webpack mechanisms.

I can add a comment in a way "TODO: should do it more webpackable"

'use strict';

function lastRequire(file) {
return `require('${file}').default.applyDecls()`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grape, @Yeti-or мы можем перестать делать эту магию?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что ты имеешь ввиду?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я имею ввиду надо делать явное const Class = bake(decl({block: 'b'}), decl({block: 'b'}), declMod({block: 'b'}))

/**
* Returns path to file of BEM-cell using naming rules
*/
module.exports = (bemCell, convention) => BemCellStringify(convention)(bemCell);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

точно не naming.file.stringify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got cell (block/elem/.../tech/layer) and level.path (absolute) and want to build path to file. Now I do level.path + .. (because layer part is already in cell) + cell

naming.file.stringify do level (any dir) + cell.

What is level ? Layer is not equal to level ?

I don't think that:

fileStringify(
    new BemFile({
        cell,
        level: level.path + '/..'
    })
)

is better enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started conversation in bem/bem-sdk#278

// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ?
// like webpack-bem-loader does

bemDeps = bemDeps.concat(files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[].push.apply(bemDeps, files);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's better ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think its faster?

});
});

// FIXME: does it have right order ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess we can't reorder this anyway. Or you know how we can?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its rhetorical somehow. I'll remove it

levels: [{ layer: 'desktop' }],
// TODO: remove sets after https://github.com/bem/bem-sdk/issues/262
sets: {
desktop: 'desktop'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно для того, чтобы можно было использовать слой отдельно? Но ведь это некорректно.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md Outdated

|Name|Type|Description|
|----|----|-----------|
|**`test`**|`{RegExp}`|Plugin processes `require` statements in matched files. Default is `/\.js$/`|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it play nice with tech/techMap? Do we really need both?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • tech is to add css
  • techMap is to handle .react.js
  • test is to skip bemhtml.js if test: /\.react\.js$/... Should we use techMap here? Is it your proposal ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to #8

README.md Outdated

## Known issues

* Small tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there are too small and too fast? we need to fix it and write big heavy ones =)


> npm test

## Known issues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to open an issue for each one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

const ctx = entityFromPath(filePath, requestNaming);

// TODO: remove duplicates from array in @bem/sdk.import-notation
// https://github.com/bem/bem-sdk/issues/263
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zxqfox я только не помню выпустили ли мы версию


return Object
.keys(techToFiles)
.sort(tech => tech === 'js') // js should be the last
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, it should be first ¯_(ツ)_/¯

Copy link
Collaborator Author

@Vittly Vittly Feb 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nooo! why do I misunderstand it. Can you tell us what's this magic about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait this code converts ['js', 'css'] into ['css', 'js'] to build (require('x.css'), require('x.js').applyDecls()) so value of comma expression will be ReactComponent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to look at the example:

common.blocks/
  block/
    block.js
    block.css
desktop.blocks/
  block/
    block.js
    block.css
var b = require(b:block);

/**
 * Loader produces:
 *
 * var b = (
 *   require('./common.blocks/block/block.css'),
 *   require('./desktop.blocks/block/block.css'),
 *   (
 *     require('./common.blocks/block/block.js'),
 *     (
 *       require('./desktop.blocks/block/block.js').default || 
 *       require('./desktop.blocks/block/block.js')
 *     ).applyDecls()
 *   )
 * );
 */

/**
 * Plugin produces:
 * 
 * var b = (
 *   require('./common.blocks/block/block.css'),
 *   require('./desktop.blocks/block/block.css'),
 *   require('./common.blocks/block/block.js'),
 *   require('./desktop.blocks/block/block.js').default.applyDecls()
 * );
 */

Is there any problems? @Yeti-or

'use strict';

function lastRequire(file) {
return `require('${file}').default.applyDecls()`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что ты имеешь ввиду?

// a. keeping full path in config
// b. allowing to build short bem-cell path without level part
function resolveCellPath(relativePath, levelPath) {
return path.resolve(levelPath, '../' + relativePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it work on windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we should... I'll add an issue

};
});

// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, it adds, why do you think it's unnecessary?

// TODO: should we add __elem (in case of __elem_mod) and _mod (in case of _mod_val) ?
// like webpack-bem-loader does

bemDeps = bemDeps.concat(files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's better ?

@Vittly
Copy link
Collaborator Author

Vittly commented Feb 4, 2018

fixed

@Vittly
Copy link
Collaborator Author

Vittly commented Feb 9, 2018

I've fixed some problems and created issues for others. I want to improve readme.md on weekend and merge PR in the begining of the next week. Tell me if I wrong 👂

@Vittly
Copy link
Collaborator Author

Vittly commented Feb 18, 2018

I've done with readme and examples. The rest will fix later. Merge!

@Vittly Vittly merged commit fa5fdf0 into master Feb 18, 2018
@Vittly Vittly deleted the init branch February 18, 2018 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants