mikededo / dartBarrelFileGenerator

VSCode extension that generates barrel files for Dart projects
MIT License
25 stars 9 forks source link

Don't export files with `part of` declarations #86

Closed gcwill70 closed 1 year ago

gcwill70 commented 1 year ago

Minimal example (using BLoC library):

a_bloc.dart:

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'a_event.dart';
part 'a_state.dart';

class ABloc extends Bloc<AEvent, AState> {
  ABloc() : super(AInitial()) {
    on<AEvent>((event, emit) {
      // TODO: implement event handler
    });
  }
}

a_event.dart:

part of 'a_bloc.dart';

abstract class AEvent extends Equatable {
  const AEvent();

  @override
  List<Object> get props => [];
}

a_state.dart

part of 'a_bloc.dart';
class AState extends Equatable {
  const AState();

  @override
  List<Object> get props => [];
}

Actual output:

export 'a_bloc.dart';
export 'a_event.dart';
export 'a_state.dart';

Expected output:

export 'a_bloc.dart';
mikededo commented 1 year ago

Hi @gcwill70! 👋 Thanks for opening an issue!

I can clearly see the issue here. However, the extension does not read the contents of the file. To me, it would make more sense to have a different file structure, then, the extension provides a exclude utility that it is useful.

For example, supose that you always name your part files with the following suffix .part.dart (event.part.dart and state.part.dart). With this, you can configure the extension with dartBarrelFile.excludeFileList, in which you can add a glob that matches the .part.dart suffix:

// In your vscode settings
{
    // ...
    "dartBarrelFile.excludeFileList": [
        "/**/*.part.js"
    ],
    // ...
}

Now part files will not be taken into account.

I'm afraid I'm not planning to read the files as it can take a lot of time as well as complexity! ⌛

Closing the issue as of now. Feel free to ask me anything else 💪

gcwill70 commented 1 year ago

Good point! That will work for me since the filename patterns are constant. Thanks!

For anyone running into this issue with the generated code from BLoC extension, I used the following exclude patterns:

// settings.json
{
    // ...
    "dartBarrelFile.excludeFileList": [
        "**/*_event.dart",
        "**/*_state.dart",
    ],
    // ...
}
mikededo commented 1 year ago

@gcwill70 Nice! Grateful that helped!