dartBarrelFileGenerator icon indicating copy to clipboard operation
dartBarrelFileGenerator copied to clipboard

Cannot export a nested file with same name as outer folder

Open saschaernst opened this issue 3 years ago • 8 comments

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'

saschaernst avatar Nov 28 '22 08:11 saschaernst

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.defaultBarrelName configuration, which allows you to set up a default name for all your barrel files. Let's say you want them all named index.dart instead of using the same name as the folder. Then, you would set this option to "dartBarrelFileGenerator.defaultBarrelName": "index" in your settings.json.
  • Prepending/Appending the folder name to the generated output file. Check the configuration for dartBarrelFileGenerator.prependFolderName and for dartBarrelFileGenerator.appendFolderName. This are boolean options and you can enable them by setting them to true in the settings.json (they are disabled by default).

As I said, I will look into the problem as soon as I can.

mikededo avatar Nov 28 '22 08:11 mikededo

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

saschaernst avatar Nov 28 '22 08:11 saschaernst

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?

mikededo avatar Nov 28 '22 08:11 mikededo

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

saschaernst avatar Nov 28 '22 09:11 saschaernst

Ah, I see the issue. Okey, I will probably not be able to fix it until the weekend due to work & uni.

mikededo avatar Nov 28 '22 09:11 mikededo

Happy New Year! Is there an ETA for an update?

saschaernst avatar Jan 13 '23 19:01 saschaernst

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.

mikededo avatar Jan 17 '23 10:01 mikededo

Don't sweat it, I'll just use default names for the barrel files, that should be good enough

saschaernst avatar Jan 18 '23 16:01 saschaernst