(packageFolder: string, { packageName }: { packageName?: string } = {})
| 12 | * - In the case where the parent folder name is not displayed and the project folder name matches the package, we only show `package:foo` |
| 13 | */ |
| 14 | export function getPackageOrFolderDisplayName(packageFolder: string, { packageName }: { packageName?: string } = {}): string { |
| 15 | // If we weren't passed one, try to get the packages name from the pubspec. |
| 16 | packageName ??= tryGetPackageName(packageFolder); |
| 17 | |
| 18 | // Get the relative path from the workspace root to the folder we're running up to two segments. |
| 19 | const containingWorkspace = vs.workspace.getWorkspaceFolder(vs.Uri.file(packageFolder)); |
| 20 | const containingWorkspacePath = containingWorkspace ? fsPath(containingWorkspace.uri) : undefined; |
| 21 | let folderDisplayName = path.basename(packageFolder); |
| 22 | if (containingWorkspacePath) { |
| 23 | const relativePath = path.relative(containingWorkspacePath, packageFolder); |
| 24 | if (relativePath) { |
| 25 | folderDisplayName = relativePath.includes(path.sep) |
| 26 | ? relativePath.split(path.sep).slice(-2).join(path.sep) |
| 27 | : relativePath; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | if (packageName && packageName !== folderDisplayName) { |
| 32 | return `package:${packageName} (${folderDisplayName})`; |
| 33 | } else if (packageName) { |
| 34 | return `package:${packageName}`; |
| 35 | } else { |
| 36 | return folderDisplayName; |
| 37 | } |
| 38 | } |
no test coverage detected