Closed Guibod closed 7 years ago
Whats the reason anyone would want to use a different extension for "jsx" files?
I really don't know. :) My point was to allow any extensions, but to enable them to properly configure them, through an explicit option. For instance, you may want to import json, or css as JS object. I don't know.
The point is that I need to generate an index for directories mixing JS and JSX, past this point I don't know what would be the usage. I tried to be as open as possible in this implementation.
If you want to enforce only js and jsx extension, you only need to hide the -x option from command-line.
My problem is that it allows (and therefore promotes) code style that has no merits.
So, to be clear, you want to hardcode a list of allowed extensions. I guess that's limited to JS and JSX, right ? How do we handle homonyms, is .js file always wins over .jsx ?
So, to be clear, you want to hardcode a list of allowed extensions. I guess that's limited to JS and JSX, right ? How do we handle homonyms, is .js file always wins over .jsx ?
No. I am suggesting not to allow any other extensions that are non-.js
.
In #6 people are in dire need of this feature. And it is a common pattern to use the jsx extension. Well enough, your house your rules. I have nothing to add, please close if you don't want it.
Well enough, your house your rules. I have nothing to add, please close if you don't want it.
I appreciate this attitude. :-)
I the https://github.com/gajus/create-index/issues/6 issue I said I will accept the PR. Therefore, it wouldn't be fair to just close this.
Thank you for contributing.
As seen in #6 it is important to allow people to safely choose what extension they want to support.
I've created this PR to allow people to
create-index
over jsx and js, but it can be extended to anything. To achieve thatreadDirectory
acceptsextensions
in its options. If not specified, it is defaulted to 'js'.The main change is that file extension is tested against all of those extension to see if the file is eligible for export. Second important feature is that removeDuplicates also search for files that are homonyms, and will always discard homonyms with extensions matching the first listed. So if you put
extensions = ['js', 'jsx']
you'll always let your js file win over jsx files. It works as for homonyms directories.