packageRootFor method

String packageRootFor(
  1. String filePath
)

Implementation

String packageRootFor(String filePath) {
  final parts = path.split(filePath);

  String root;
  if (parts.contains('test')) {
    root = parts.sublist(0, parts.indexOf('test')).join(path.separator);
  } else if (parts.contains('lib')) {
    root = parts.sublist(0, parts.indexOf('lib')).join(path.separator);
  } else {
    if (fs.isFileSync(filePath)) {
      root = path.basename(path.dirname(filePath));
    } else {
      root = path.basename(filePath);
    }
  }

  if (root.isEmpty) {
    root = '.';
  }

  return root;
}