Skip to content

Commit

Permalink
fix: allow InstalledDependencies to be an object
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Mar 11, 2024
1 parent 9631974 commit 018ed1f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export type PackageJsonLike = {
peerDependencies?: Record<string, string | undefined>;
};

export type InstalledDependencies = Map<string, PackageJsonLike>;
// A map is allowed since that's what import('list-installed).listInstalled returns
export type InstalledDependencies = Map<string, PackageJsonLike> | Record<string, PackageJsonLike>;
```

#### Example
Expand Down
2 changes: 1 addition & 1 deletion lib/check-package-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
10 changes: 5 additions & 5 deletions lib/check-version-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<VersionRangeOptions, 'noDev'>} [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,
Expand Down
2 changes: 1 addition & 1 deletion lib/get-installed-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { readPackage } from 'read-pkg';
* @property {Record<string, string | undefined>} [peerDependencies]
*/

/** @typedef {Map<string, PackageJsonLike>} InstalledDependencies */
/** @typedef {Map<string, PackageJsonLike> | Record<string, PackageJsonLike>} InstalledDependencies */

/**
* @typedef InstalledData
Expand Down

0 comments on commit 018ed1f

Please sign in to comment.