featureOf method
The feature file belongs to: its directory under lib/, cut to
depth folders — or null for a file outside every lib/.
lib/src/ is pub's convention for "private", not a feature, so it is
looked through: at depth 1 both lib/auth/x.dart and
lib/src/auth/x.dart fall in their auth folder. A file directly in
lib/ (or lib/src/) belongs to that directory. The name is the real
path prefix, so a reader can find it.
Implementation
String? featureOf(String file, int depth) {
final root = libraryRoot(file);
if (root == null) return null;
final dirs = file.substring(root.length).split('/')..removeLast();
final skip = dirs.isNotEmpty && dirs.first == 'src' ? 1 : 0;
final kept = dirs.take(skip + (depth < 0 ? 0 : depth));
return [root.substring(0, root.length - 1), ...kept].join('/');
}