dartBarrelFileGenerator
dartBarrelFileGenerator copied to clipboard
Cannot export a nested file with same name as outer folder
Issue:
When using the option 'Current with subfolders' on a directory containing a file with the same name in a subdirectory, the file will not be exported. 'Current folder with nested folders' works as expected
Example: If you have a feature directory in your project called, i.e.:
car/
domain/
car.dart
and you execute 'Current with subfolders' on the car directory, car.dart will not be exported, car/car.dart will be empty
Expected outcome:
car/car.dart should contain: export 'domain/car.dart'
Hi @saschaernst! Thanks for opening the issue! 👋🏼
I will look into it, but that is because it looks at the top folder car and it checks if the barrel file it is already created, which, if there's not any additional configuration, is the same name as the folder. It is what happens in this case.
I do not know if it will add much complexity trying to fix this issue. Nonetheless, here are some solutions that you may want to try as of now:
- First of all you have the
dartBarrelFileGenerator.defaultBarrelNameconfiguration, which allows you to set up a default name for all your barrel files. Let's say you want them all namedindex.dartinstead of using the same name as the folder. Then, you would set this option to"dartBarrelFileGenerator.defaultBarrelName": "index"in yoursettings.json. - Prepending/Appending the folder name to the generated output file. Check the configuration for
dartBarrelFileGenerator.prependFolderNameand fordartBarrelFileGenerator.appendFolderName. This arebooleanoptions and you can enable them by setting them totruein thesettings.json(they are disabled by default).
As I said, I will look into the problem as soon as I can.
Thanks for the quick reply. I'll have a look at your suggested solutions, but it would be nice if it could at least work for files with the same name in subdirectories.
Cheers
What would your suggestions be for the generated name? In the example case you proposed, which would be the generated name of the barrel file?
It could still be car.dart as long as the other car.dart is in a subdirectory. As it actually works with the 'Current folder with nested folders' option, it was very confusing when it didn't for the subfolders option
Ah, I see the issue. Okey, I will probably not be able to fix it until the weekend due to work & uni.
Happy New Year! Is there an ETA for an update?
Hi @saschaernst! Sorry for taking too long with the issue. I have studied it and it would involve quite a lot of code changes, which will take up more time that I can have.
I encourage you to propose a PR, otherwise you will have to wait a bit more, as I'm working from time to time on it...
Again, excuse me for the delay.
Don't sweat it, I'll just use default names for the barrel files, that should be good enough