* Strip companion suffixes from a filename to get the base source name. * e.g., "Button.test.tsx" -> "Button", "auth.spec.js" -> "auth"
(fileName)
| 134 | * e.g., "Button.test.tsx" -> "Button", "auth.spec.js" -> "auth" |
| 135 | */ |
| 136 | function getBaseName(fileName) { |
| 137 | // Remove extension first |
| 138 | const ext = path.extname(fileName); |
| 139 | let name = fileName.slice(0, -ext.length); |
| 140 | |
| 141 | // Strip companion suffix if present |
| 142 | for (const suffix of COMPANION_SUFFIXES) { |
| 143 | if (name.endsWith(suffix)) { |
| 144 | return name.slice(0, -suffix.length); |
| 145 | } |
| 146 | } |
| 147 | return name; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Check if a source file exists in a given directory for a base name. |