| 1 |
import type Swup from 'swup'; |
| 2 |
|
| 3 |
import { versionSatisfies } from './versionSatisfies.js'; |
| 4 |
|
| 5 |
function getInstalledDependencyVersion(dependency: string, swup: Swup): string { |
| 6 |
if (dependency === 'swup') { |
| 7 |
return swup.version ?? ''; |
| 8 |
} else { |
| 9 |
// Circular type dependency? |
| 10 |
// findPlugin returns swup's Plugin type which is not up-to-date |
| 11 |
// with the actual Plugin type from index.ts |
| 12 |
const plugin = swup.findPlugin(dependency); |
| 13 |
return plugin?.version ?? ''; |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
export function checkDependencyVersion( |
| 18 |
dependency: string, |
| 19 |
requirements: string[], |
| 20 |
swup: Swup |
| 21 |
): boolean { |
| 22 |
const version = getInstalledDependencyVersion(dependency, swup); |
| 23 |
if (version) { |
| 24 |
return versionSatisfies(version, requirements); |
| 25 |
} else { |
| 26 |
return false; |
| 27 |
} |
| 28 |
} |