8000 Support module directories with index.js · lodash/babel-plugin-lodash@b7387d0 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit b7387d0

Browse files
Support module directories with index.js
1 parent 0c87f2a commit b7387d0

File tree

12 files changed

+88
-6
lines changed

12 files changed

+88
-6
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
"babel-preset-stage-0": "^6.24.1",
3232
"babel-register": "^6.24.1",
3333
"chai": "^4.0.1",
34+
"date-fns": "^1.28.5",
3435
"lodash-bound": "^1.1.2",
3536
"lodash-compat": "^3.10.2",
3637
"lodash-es": "^4.17.4",
38+
"material-ui": "^0.18.3",
3739
"mocha": "^3.4.2",
3840
"ramda": "^0.24.1",
3941
"react-bootstrap": "^0.31.0"

src/ModuleCache.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ export default class ModuleCache extends MapCache {
2828
_.each(dirPaths, dirPath => {
2929
const base = path.relative(moduleRoot, dirPath);
3030
const filePaths = glob.sync(path.join(dirPath, '*.js'));
31+
if (base && _.includes(filePaths, path.join(dirPath, 'index.js'))) {
32+
const indexEntry = path.parse(base);
33+
const parentMap = this.get(indexEntry.dir);
34+
if (parentMap && !parentMap.get(indexEntry.base.toLowerCase())) {
35+
parentMap.set(indexEntry.base.toLowerCase(), indexEntry.base);
36+
}
37+
}
3138
const pairs = _.map(filePaths, filePath => {
3239
const name = path.basename(filePath, '.js');
3340
return [name.toLowerCase(), name];

src/importModule.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import mapping from './mapping';
55

66
function resolvePath(pkgStore, name, path) {
77
let { base, id } = pkgStore;
8-
const lower = name.toLowerCase();
98
const module = mapping.modules.get(id);
10-
11-
if (!module.get(base).has(lower)) {
12-
base = base ? '' : module.findKey(map => map.has(lower));
9+
const nameCases = [name.toLowerCase(), _.kebabCase(name), _.snakeCase(name)];
10+
let realName = _.find(nameCases, n => module.get(base).has(n));
11+
12+
if (!realName) {
13+
base = base ? '' : module.findKey(map => realName = _.find(nameCases, n => map.has(n)));
1314
if (!base) {
1415
throw path.buildCodeFrameError([
1516
`The '${ id }' method \`${ name }\` is not a known module.`,
1617
'Please report bugs to https://github.com/lodash/babel-plugin-lodash/issues.'
1718
].join('\n'));
1819
}
1920
}
20-
return id + '/' + (base ? base + '/' : '') + module.get(base).get(lower);
21+
return id + '/' + (base ? base + '/' : '') + module.get(base).get(realName);
2122
}
2223

2324
function importModule(pkgStore, name, path) {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default function lodash({ types }) {
117117
},
118118

119119
ImportDeclaration(path) {
120-
if (store.get(path.node.source.value)) {
120+
if (path.node.source.loc && store.get(path.node.source.value)) {
121121
// Remove old import.
122122
path.remove();
123123
}

test/mixed-fixtures/date-fns/.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
["env", { "targets": { "node": 4 } }]
4+
]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import dt from 'date-fns';
2+
import { isToday } from 'date-fns';
3+
4+
dt.isTomorrow(Date.now());
5+
isToday(Date.now());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
var _is_today = require('date-fns/is_today');
4+
5+
var _is_today2 = _interopRequireDefault(_is_today);
6+
7+
var _is_tomorrow = require('date-fns/is_tomorrow');
8+
9+
var _is_tomorrow2 = _interopRequireDefault(_is_tomorrow);
10+
11+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12+
13+
(0, _is_tomorrow2.default)(Date.now());
14+
(0, _is_today2.default)(Date.now());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"id": "date-fns"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
["env", { "targets": { "node": 4 } }],
4+
"react"
5+
]
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
2+
import { AppBar } from 'material-ui';
3+
4+
<MuiThemeProvider>
5+
<AppBar />
6+
</MuiThemeProvider>
7+
8+
export { AutoComplete } from 'material-ui';

0 commit comments

Comments
 (0)
0