(err: unknown, driver: string)
| 10 | * the driver name as a substring (e.g. "pg-connection-string" does not match "pg"). |
| 11 | */ |
| 12 | export function isDriverNotInstalled(err: unknown, driver: string): boolean { |
| 13 | if ( |
| 14 | !(err instanceof Error) || |
| 15 | !("code" in err) || |
| 16 | (err as NodeJS.ErrnoException).code !== "ERR_MODULE_NOT_FOUND" |
| 17 | ) { |
| 18 | return false; |
| 19 | } |
| 20 | |
| 21 | const match = err.message.match(MISSING_MODULE_RE); |
| 22 | if (!match) { |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | const missingSpecifier = match[1]; |
| 27 | return ( |
| 28 | missingSpecifier === driver || |
| 29 | missingSpecifier.startsWith(`${driver}/`) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Check if an error is any kind of missing module error (ESM or CJS). |
no outgoing calls
no test coverage detected