diff --git a/README.md b/README.md index 6fea364..a0c60e1 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,8 @@ export type PackageJsonLike = { peerDependencies?: Record; }; -export type InstalledDependencies = Map; +// A map is allowed since that's what import('list-installed).listInstalled returns +export type InstalledDependencies = Map | Record; ``` #### Example diff --git a/lib/check-package-versions.js b/lib/check-package-versions.js index 4136be9..f4c312d 100644 --- a/lib/check-package-versions.js +++ b/lib/check-package-versions.js @@ -16,7 +16,7 @@ export function checkPackageVersions (mainPackage, installedDependencies) { for (const dependency of Object.keys(requiredDependencies)) { let targetVersion = requiredDependencies[dependency]; - const installed = installedDependencies.get(dependency); + const installed = installedDependencies instanceof Map ? installedDependencies.get(dependency) : installedDependencies[dependency]; const installedVersion = installed ? installed.version : undefined; if (!installed && !optionalDependencies[dependency]) { diff --git a/lib/check-version-range.js b/lib/check-version-range.js index 92574b4..b7e14a3 100644 --- a/lib/check-version-range.js +++ b/lib/check-version-range.js @@ -44,8 +44,8 @@ export function checkVersionRange (mainPackage, key, installedDependencies, opti /** @type {string | false} */ let intersection = referenceRange; - for (const dependency of Object.keys(requiredDependencies)) { - const dependencyPackage = installedDependencies.get(dependency); + for (const dependency in requiredDependencies) { + const dependencyPackage = installedDependencies instanceof Map ? installedDependencies.get(dependency) : installedDependencies[dependency]; const isOptional = !!optionalDependencies[dependency]; const dependencyNotes = checkDependencyRange(referenceRange, key, dependencyPackage, isOptional, options); @@ -79,11 +79,11 @@ export function checkVersionRange (mainPackage, key, installedDependencies, opti * @param {string} referenceRange * @param {string} key * @param {import('./get-installed-data.js').PackageJsonLike|undefined} dependencyPackage - * @param {boolean} isOptional + * @param {boolean} [isOptional] * @param {Omit} [options] - * @returns {VersionRangeItem | undefined} + * @returns {(VersionRangeItem & { valid: false | undefined }) | undefined} */ -function checkDependencyRange (referenceRange, key, dependencyPackage, isOptional, options) { +export function checkDependencyRange (referenceRange, key, dependencyPackage, isOptional, options) { const { expectedInDependencies = false, strict = false, diff --git a/lib/get-installed-data.js b/lib/get-installed-data.js index a62122c..d30b369 100644 --- a/lib/get-installed-data.js +++ b/lib/get-installed-data.js @@ -13,7 +13,7 @@ import { readPackage } from 'read-pkg'; * @property {Record} [peerDependencies] */ -/** @typedef {Map} InstalledDependencies */ +/** @typedef {Map | Record} InstalledDependencies */ /** * @typedef InstalledData