lodash / babel-plugin-lodash

Modular Lodash builds without the hassle.
Other
1.95k stars 95 forks source link

Add support for index.js files #166

Closed tleunen closed 7 years ago

tleunen commented 7 years ago

Currently, if a project is structured using directories in which index.js is used, the pairs in the configuration will be [ 'index', 'index' ] which won't produce the right thing.

- src
├─ dir1
│ └─┬ index.js
└─ dir2
  └── index.js

See https://github.com/lodash/babel-plugin-lodash/blob/master/src/ModuleCache.js#L31-L34

When index.js is used, it should be the directory name instead of the file name.

jdalton commented 7 years ago

Hi @tleunen!

Are you up for creating a PR?

tleunen commented 7 years ago

Sure! Will do later today.

tleunen commented 7 years ago

Is it possible to test with a dummy local project instead of a node_modules project?

Because there a some edge cases, like it should use the directory name only if there's no file having the same name as its directory. And if it's the case, we can skip the index pair.

As an example, we should save the pair with the index in this case: https://github.com/callemall/material-ui/tree/master/src/DropDownMenu Othwerwise we'll end up with the wrong file

jdalton commented 7 years ago

Sure. Mock it up.

albertogasparin commented 7 years ago

Adding support for directories would be great, as it is one of the reasons why babel-plugin-lodash is not able to make its magic with date-fns

albertogasparin commented 7 years ago

I've decided to give this a go in #175. I've added tests for both material-ui and date-fns and it seems to work well (tested also on a private project). With this change this plugin is even more generic!

jdalton commented 7 years ago

Moved to #175.