npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

installed-check-core

v8.3.1

Published

Checks that all dependencies in your package.json have supported versions installed

Downloads

79,587

Readme

Checks that the installed modules fulfill the requirements of package.json, both when it comes to the version ranges of the modules themselves and when it comes to the version range of their engine requirements.

npm version npm downloads Module type: ESM Types in JS neostandard javascript style Follow @voxpelli@mastodon.social

Exists as a CLI as well: installed-check

Usage

import { installedCheck } from 'installed-check-core';

const { errors, suggestions } = await installedCheck(['version']);

if (result.errors.length) {
  console.error('Dependency errors: \n\n' + result.errors.join('\n') + '\n');
}
if (result.suggestions.length) {
  console.error('Suggestions: \n\n' + result.suggestions.join('\n') + '\n');
}

In CommonJS using dynamic import() expression

const { installedCheck } = await import('installed-check-core');

API

checkVersionRange()

The rich version range check that installed-check itself uses.

Syntax

checkVersionRange(pkg, key, installed, [options]) => VersionRangeResult

Arguments

  • pkg: Type PackageJsonLike – the content of the package.json file to check
  • key: Type string – the key of the version range to check, eg engines.node
  • installed: Type InstalledDependencies – the package.json files of the installed dependencies
  • options: Type VersionRangeOptions – optional options

Types

type VersionRangeItem = {
  valid: boolean | undefined,
  suggested?: string | undefined,
  note: string | undefined,
}
type VersionRangeResult = VersionRangeItem & {
  packageNotes: Array<
    VersionRangeItem & { name: string }
  >
}

Options

  • expectedInDependencies = false – a warning will be issued when the key is empty or not found in a dependency
  • noDev = false – dev dependencies won't be included in the check
  • ignore = string[]|((test: string) => boolean) – names of modules to exclude from checks or a function that returns true for those that should be ignores (the latter handy for supporting eg. glob patterns)
  • strict = false – converts most warnings into failures.

Example

import { checkVersionRange } from 'installed-check-core';
import { listInstalled } from 'list-installed';
import { readPackage } from 'read-pkg';

const cwd = '.';

const [pkg, installed] = await Promise.all([
  readPackage({ cwd }),
  listInstalled(cwd),
]);

const result = await checkVersionRange(
  pkg,
  'engines.node',
  installed,
  {
    expectedInDependencies: true,
    noDev: true,
    ignore: ['example'],
    strict: true,
  }
);

for (const item of result.packageNotes) {
  if (item.note) {
    console.log(`${item.valid === false ? 'Error' : 'Warning'} in ${item.name}: ${item.note}`);
  }
}

if (result.note) {
  console.log(`${result.valid === false ? 'Error' : 'Warning'}: ${result.note}`);
}

if (result.valid === true) {
  console.log('All good!');
} else if (result.suggested) {
  console.log('Combined engines.node needs to be narrower:', result.suggested);
} else {
  console.log('Incompatible combined engines.node requirements.');
}

checkVersionRangeCollection()

Wrapper around as checkVersionRange() that differs from it in three ways:

  • key is for a collection of range, eg engines rather than engines.node
  • The results for every individual version range is returned in an object keyed with the full key for that range, eg: { 'engines.node': ... }
  • Accepts an additional optional defaultKeys option that's used if the collection for key is empty. Eg: { defaultKeys: ['node'] }

Syntax

checkVersionRangeCollection(pkg, key, installed, [options]) => VersionRangeCollectionResult

Arguments

See main description of checkVersionRangeCollection() and full docs for checkVersionRange().

installedCheck()

The full on installed-check experience, returning error and warning strings only.

Syntax

installedCheck(checks, [lookupOptions], [options]) => Promise<InstalledCheckResult>

Arguments

  • checks: Type InstalledChecks[] – the checks to run, an array of one or more of: 'engine', 'peer', 'version'
  • lookupOptions: Type LookupOptions – optional – defaults to cwd='.' and includeWorkspaceRoot: true
  • options: Type InstalledCheckOptions – optional

Types

type LookupOptions = {
  cwd?: string | undefined;
  ignorePaths?: string[] | undefined;
  includeWorkspaceRoot?: boolean | undefined;
  skipWorkspaces?: boolean | undefined;
  workspace?: string[] | undefined;
};
type InstalledChecks = 'engine' | 'peer' | 'version'
type InstalledCheckOptions = {
  fix?: boolean | undefined;
  ignore?: string[] | undefined;
  noDev?: boolean | undefined;
  prefix?: string | undefined;
  strict?: boolean | undefined;
};
type InstalledCheckResult = {
  errors: string[],
  warnings: string[],
  suggestions: string[],
}

Checks

  • engine – will check that the installed modules comply with the engines requirements of the package.json and suggest an alternative requirement if the installed modules don't comply.
  • peer – like engine but for peerDependencies instead. Will check that the promised peerDependencies are not wider than those of ones required dependencies.
  • version – will check that the installed modules comply with the version requirements set for them the package.json.

Lookup options

The same as from read-workspaces / list-installed

Options

  • fix = false – when set it will modify the package.json files to apply fixes whenever possible
  • ignores = string[] – names of modules to exclude from checks. Supports picomatch globbing syntax, eg. @types/*. (Not supported by version checks)
  • noDev = false – exclude devDependencies from checks. devDependencies that are also in peerDependencies will not be ignored. (Not supported by version checks)
  • strict = false – converts most warnings into failures

Example

import { installedCheck } from 'installed-check-core';

const { errors, warnings, suggestions } = await installedCheck(['engine', 'version'], {
  cwd: 'path/to/module',
  ignore: ['foo'],
  noDev: true,
});

performInstalledCheck()

Similar to installedCheck() but expects to be given package data instead of looking it up itself..

Syntax

performInstalledCheck(checks, pkg, installed, options) => Promise<PerformInstalledCheckResult>

Arguments

Types

PackageJsonLike

// Subset of import('type-fest').PackageJson / import('read-pkg').NormalizedPackageJson
export type PackageJsonLike = {
  name?:    string | undefined;
  version?: string | undefined;
  engines?:              Record<string, string | undefined>;
  dependencies?:         Record<string, string | undefined>;
  devDependencies?:      Record<string, string | undefined>;
  optionalDependencies?: Record<string, string | undefined>;
  peerDependencies?:     Record<string, string | undefined>;
};

InstalledDependencies

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

Used by

Similar modules

  • knip – finds unused files, dependencies and exports in your JavaScript and TypeScript projects – a great companion module to installed-check