getImportPath method

String getImportPath(
  1. String libPath,
  2. String packageName
)

Returns the package import path for a given source file.

Example:

/project/lib/features/auth/login.dart
→ package:my_app/features/auth/login.dart

Implementation

String getImportPath(String libPath, String packageName) {
  final relativePath = p.relative(libPath, from: p.join(projectRoot, 'lib'));
  return 'package:$packageName/${relativePath.replaceAll(p.separator, '/')}';
}