bencoveney / barrelsby

Automatic TypeScript barrels (index.ts files) for your entire code base

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow extensions other than .ts

nicobrinkkemper opened this issue · comments

Is your feature request related to a problem? Please describe.
I use barrelsby for automatic file detection by compiler. This works well for .ts extension file, but typescript can also import other extension as valid files, such as .json.

Describe the solution you'd like
I want to allow different extensions, such as .json, to also be picked up by the barrelsby command.

Describe alternatives you've considered
Doing it by hand partially reduces the convenience of barrelsby, making you want to convert the json files in to ts. This shouldn't be needed as json can be imported perfectly fine if it is configured to do so.

Additional context

locals/en
- buttons.json
- menu.json
- index.ts <- generated

This sounds reasonable to me 👍 In #178 I have mentioned the possibility of retaining file extensions for unknown file types.

It would be interesting to think about what config would be required, so that users could specify which file types they'd like included. I think it is a common pattern to have .css files living near .tsx component files, but depending on the CSS bundling method I can see cases where users would and woudn't want those .css files included.

Nice!
Thinking about it more, there might be several pitfalls for extension

  • It might have to retain extensions in some cases [mtsx,mts, json, css]
  • It might need to figure out a name for a variable [json,css]
  • It might need to make exceptions for multi extensions [.client.ts,.spec.ts, .stories.ts]

For json extensions, I think it's a bit tricky. The best pattern I can come up with is

buttons.json (found file)

[{
  "searchLabel": "Search",
}]

buttons.ts (generated)

import buttons from './buttons.json' assert {type: 'json'}
export {buttons}

index.ts (generated)

export * from './buttons'

So the need for assert really messes up the whole idea of using different extensions. And makes it dependent on your local configuration (esnext in my case). Barrelsby might support this, but maybe it's better to leave it out of scope.

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

Hey, is there an update on this?

I'd love to use barrelsby in a React project with .tsx files, but it seems that .tsx isn't picked up yet.

commented

@PedroHase no, not that I'm aware of. I need to find time to get back into a V3 but my day job has me pretty busy recently, unfortunately.

Thanks for the heads-up @BitForger. I created a small script in the meantime as dirty workaround by basically renaming all .tsx files into .ts, run barrelsby, then change the renamed files back to .tsx 😄

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator