| 18 | |
| 19 | // Reads from path like assets/features/NAME.js |
| 20 | export function parseFeatureNameFromStack(stack: string = new Error('stack').stack!): FeatureId | undefined { |
| 21 | // The stack may show other features due to cross-feature imports, but we want the top-most caller so we need to reverse it |
| 22 | const match = stack |
| 23 | .split('\n') |
| 24 | .toReversed() |
| 25 | .join('\n') |
| 26 | // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec -- Linear code is best |
| 27 | .match(/assets\/features\/(?<id>.+)\.js/); |
| 28 | return match?.groups?.id as FeatureId | undefined; |
| 29 | } |
| 30 | |
| 31 | /* Log errors only once */ |
| 32 | const loggedStacks = new Set<string>(); |