gajus / create-index

Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.
Other
278 stars 87 forks source link

feat: babylon parser to check default/named exports #27

Closed laggingreflex closed 7 years ago

laggingreflex commented 7 years ago

Uses Babylon parser to parse the file to check if it contains a default export.

If a file now contains a default export, the behaviour will be the same as before.

But if the file doesn't contain any default exports, assuming it has only named exports, it uses * as when creating its index.

Eg. Default export: (same as before)

// foo.js

export default () => {}

will create ine the index:

import _foo from './foo'
export const foo = _foo
export {
  foo
}

Eg. Named exports:

// foo.js

export const foo1 = () => {}
export const foo2 = () => {}

will create ine the index:

import * as _foo from './foo'
export const foo = _foo
export {
  foo
}

Builds on #18, addresses #11

laggingreflex commented 7 years ago

PS: It contains a lot of previous commits (#16, #18, #23). I can rebase if needed.

gajus commented 7 years ago

PS: It contains a lot of previous commits (#16, #18, #23). I can rebase if needed.

Yes, please.

gajus commented 7 years ago

But if the file doesn't contain any default exports, assuming it has only named exports, it uses * as when creating its index.

Similar to https://github.com/gajus/create-index/pull/18

This promotes bad design.

Creating an index file that imports * as foo and requiring anything from that index will include all the files to the resulting bundle.