( params: WorkspaceProjectStorageKeyParams )
| 75 | } |
| 76 | |
| 77 | export function getWorkspaceProjectStorageKeys( |
| 78 | params: WorkspaceProjectStorageKeyParams |
| 79 | ): WorkspaceProjectStorageKey[] { |
| 80 | assert( |
| 81 | params.projectPath.trim().length > 0, |
| 82 | "getWorkspaceProjectStorageKeys: projectPath must be non-empty" |
| 83 | ); |
| 84 | |
| 85 | const trimmedProjectName = params.projectName?.trim(); |
| 86 | const primaryProjectName = |
| 87 | trimmedProjectName && trimmedProjectName.length > 0 |
| 88 | ? trimmedProjectName |
| 89 | : PlatformPaths.getProjectName(params.projectPath).trim(); |
| 90 | assert( |
| 91 | primaryProjectName.length > 0, |
| 92 | "getWorkspaceProjectStorageKeys: primaryProjectName must be non-empty" |
| 93 | ); |
| 94 | |
| 95 | const orderedProjects = |
| 96 | params.projects && params.projects.length > 0 |
| 97 | ? params.projects |
| 98 | : ([ |
| 99 | { |
| 100 | projectPath: params.projectPath, |
| 101 | projectName: primaryProjectName, |
| 102 | }, |
| 103 | ] satisfies ProjectRef[]); |
| 104 | |
| 105 | const expectedProjectCount = |
| 106 | params.projects && params.projects.length > 0 ? params.projects.length : 1; |
| 107 | assert( |
| 108 | orderedProjects.length === expectedProjectCount, |
| 109 | `getWorkspaceProjectStorageKeys: expected ${expectedProjectCount} projects, got ${orderedProjects.length}` |
| 110 | ); |
| 111 | |
| 112 | const usedStorageKeys = new Set<string>(); |
| 113 | const storageKeys = orderedProjects.map((project) => { |
| 114 | const projectName = project.projectName.trim(); |
| 115 | assert(projectName.length > 0, "getWorkspaceProjectStorageKeys: projectName must be non-empty"); |
| 116 | |
| 117 | const baseStorageKey = sanitizeStorageKey(projectName, project.projectPath); |
| 118 | let storageKey = baseStorageKey; |
| 119 | let suffix = 2; |
| 120 | while (usedStorageKeys.has(storageKey)) { |
| 121 | storageKey = appendStorageKeySuffix(baseStorageKey, suffix); |
| 122 | suffix += 1; |
| 123 | } |
| 124 | usedStorageKeys.add(storageKey); |
| 125 | |
| 126 | return { |
| 127 | projectPath: project.projectPath, |
| 128 | projectName, |
| 129 | storageKey, |
| 130 | } satisfies WorkspaceProjectStorageKey; |
| 131 | }); |
| 132 | |
| 133 | assert( |
| 134 | new Set(storageKeys.map((project) => project.storageKey)).size === storageKeys.length, |
no test coverage detected