vihanb / babel-plugin-wildcard

Wildcard imports import a directories JS files
MIT License
186 stars 27 forks source link

Added addtional check whether dir actually exists #8

Closed pamidur closed 7 years ago

pamidur commented 7 years ago

There might be the case when file actually exists and I want to import everything from it, but specify file without extension.

Example

-model
  |-people.js
  |-work.js

...with several exported classes each

I might want

import * as model from './model'
import * as people from './model/people'

First case works as expected - it imports everything from folder Second case throws an exception

Error: server/services/reports.js: ENOENT: no such file or directory, stat 'server/model/people'

So this PR fixes this behavior by checking if folder actually exists, and assumes this was file with missing extension otherwise.