{"id":16146569,"url":"https://github.com/voxpelli/node-installed-check-core","last_synced_at":"2025-09-13T00:31:50.227Z","repository":{"id":35055811,"uuid":"167352233","full_name":"voxpelli/node-installed-check-core","owner":"voxpelli","description":"Checks whether installed modules fulfills the requirements of package.json","archived":false,"fork":false,"pushed_at":"2024-04-30T07:54:41.000Z","size":209,"stargazers_count":5,"open_issues_count":9,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-01T12:23:57.971Z","etag":null,"topics":["dependency-analysis","javascript","nodejs","npm","package-json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voxpelli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-24T10:53:32.000Z","updated_at":"2024-05-07T01:37:04.158Z","dependencies_parsed_at":"2023-12-26T02:30:02.891Z","dependency_job_id":"eac83979-d0bd-457a-96ba-09d38a3f5273","html_url":"https://github.com/voxpelli/node-installed-check-core","commit_stats":{"total_commits":194,"total_committers":4,"mean_commits":48.5,"dds":"0.17525773195876293","last_synced_commit":"3eb2469611c2defbc5d715d12cb44b2f9b7b29a8"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxpelli%2Fnode-installed-check-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxpelli%2Fnode-installed-check-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxpelli%2Fnode-installed-check-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxpelli%2Fnode-installed-check-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voxpelli","download_url":"https://codeload.github.com/voxpelli/node-installed-check-core/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232802753,"owners_count":18578684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-analysis","javascript","nodejs","npm","package-json"],"created_at":"2024-10-10T00:20:37.809Z","updated_at":"2025-01-06T23:52:01.904Z","avatar_url":"https://github.com/voxpelli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg\n    src=\"installed-check-core.svg\"\n    width=\"650\"\n    height=\"auto\"\n    alt=\"installed-check-core\"\n  /\u003e\n\u003c/div\u003e\n\nChecks 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.\n\n[![npm version](https://img.shields.io/npm/v/installed-check-core.svg?style=flat)](https://www.npmjs.com/package/installed-check-core)\n[![npm downloads](https://img.shields.io/npm/dm/installed-check-core.svg?style=flat)](https://www.npmjs.com/package/installed-check-core)\n[![Module type: ESM](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)\n[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-7fffff?style=flat\u0026labelColor=ff80ff)](https://github.com/neostandard/neostandard)\n[![Follow @voxpelli@mastodon.social](https://img.shields.io/mastodon/follow/109247025527949675?domain=https%3A%2F%2Fmastodon.social\u0026style=social)](https://mastodon.social/@voxpelli)\n\nExists as a CLI as well: [installed-check](https://www.npmjs.com/package/installed-check)\n\n## Usage\n\n```javascript\nimport { installedCheck } from 'installed-check-core';\n\nconst { errors, suggestions } = await installedCheck(['version']);\n\nif (result.errors.length) {\n  console.error('Dependency errors: \\n\\n' + result.errors.join('\\n') + '\\n');\n}\nif (result.suggestions.length) {\n  console.error('Suggestions: \\n\\n' + result.suggestions.join('\\n') + '\\n');\n}\n```\n\n### In CommonJS using dynamic [`import()`](https://nodejs.org/api/esm.html#import-expressions) expression\n\n```javascript\nconst { installedCheck } = await import('installed-check-core');\n```\n\n## API\n\n### checkVersionRange()\n\nThe rich version range check that `installed-check` itself uses.\n\n#### Syntax\n\n```ts\ncheckVersionRange(pkg, key, installed, [options]) =\u003e VersionRangeResult\n```\n\n#### Arguments\n\n* `pkg`: Type [`PackageJsonLike`](#packagejsonlike) – the content of the `package.json` file to check\n* `key`: Type `string` – the key of the version range to check, eg `engines.node`\n* `installed`: Type [`InstalledDependencies`](#installeddependencies) – the `package.json` files of the installed dependencies\n* `options`: Type `VersionRangeOptions` – optional options\n\n#### Types\n\n```ts\ntype VersionRangeItem = {\n  valid: boolean | undefined,\n  suggested?: string | undefined,\n  note: string | undefined,\n}\ntype VersionRangeResult = VersionRangeItem \u0026 {\n  packageNotes: Array\u003c\n    VersionRangeItem \u0026 { name: string }\n  \u003e\n}\n```\n\n#### Options\n\n * `expectedInDependencies = false` – a warning will be issued when the key is empty or not found in a dependency\n * `noDev = false` – dev dependencies won't be included in the check\n * `ignore = string[]|((test: string) =\u003e 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)\n * `strict = false` – converts most warnings into failures.\n\n#### Example\n\n```javascript\nimport { checkVersionRange } from 'installed-check-core';\nimport { listInstalled } from 'list-installed';\nimport { readPackage } from 'read-pkg';\n\nconst cwd = '.';\n\nconst [pkg, installed] = await Promise.all([\n  readPackage({ cwd }),\n  listInstalled(cwd),\n]);\n\nconst result = await checkVersionRange(\n  pkg,\n  'engines.node',\n  installed,\n  {\n    expectedInDependencies: true,\n    noDev: true,\n    ignore: ['example'],\n    strict: true,\n  }\n);\n\nfor (const item of result.packageNotes) {\n  if (item.note) {\n    console.log(`${item.valid === false ? 'Error' : 'Warning'} in ${item.name}: ${item.note}`);\n  }\n}\n\nif (result.note) {\n  console.log(`${result.valid === false ? 'Error' : 'Warning'}: ${result.note}`);\n}\n\nif (result.valid === true) {\n  console.log('All good!');\n} else if (result.suggested) {\n  console.log('Combined engines.node needs to be narrower:', result.suggested);\n} else {\n  console.log('Incompatible combined engines.node requirements.');\n}\n```\n\n### checkVersionRangeCollection()\n\n\nWrapper around as [`checkVersionRange()`](#checkversionrange) that differs from it in three ways:\n\n* `key` is for a collection of range, eg `engines` rather than `engines.node`\n* The results for every individual version range is returned in an `object` keyed with the full key for that range, eg: `{ 'engines.node': ... }`\n* Accepts an additional optional `defaultKeys` option that's used if the collection for `key` is empty. Eg: `{ defaultKeys: ['node'] }`\n\n#### Syntax\n\n```ts\ncheckVersionRangeCollection(pkg, key, installed, [options]) =\u003e VersionRangeCollectionResult\n```\n\n#### Arguments\n\nSee main description of [`checkVersionRangeCollection()`](#checkversionrangecollection) and full docs for [`checkVersionRange()`](#checkversionrange).\n\n### installedCheck()\n\nThe full on `installed-check` experience, returning error and warning strings only.\n\n#### Syntax\n\n```ts\ninstalledCheck(checks, [lookupOptions], [options]) =\u003e Promise\u003cInstalledCheckResult\u003e\n```\n\n#### Arguments\n\n* `checks`: Type `InstalledChecks[]` – the checks to run, an array of one or more of: `'engine'`, `'peer'`, `'version'`\n* `lookupOptions`: Type `LookupOptions` – optional – defaults to `cwd='.'` and `includeWorkspaceRoot: true`\n* `options`: Type `InstalledCheckOptions` – optional\n\n#### Types\n\n```ts\ntype LookupOptions = {\n  cwd?: string | undefined;\n  ignorePaths?: string[] | undefined;\n  includeWorkspaceRoot?: boolean | undefined;\n  skipWorkspaces?: boolean | undefined;\n  workspace?: string[] | undefined;\n};\ntype InstalledChecks = 'engine' | 'peer' | 'version'\ntype InstalledCheckOptions = {\n  fix?: boolean | undefined;\n  ignore?: string[] | undefined;\n  noDev?: boolean | undefined;\n  prefix?: string | undefined;\n  strict?: boolean | undefined;\n};\ntype InstalledCheckResult = {\n  errors: string[],\n  warnings: string[],\n  suggestions: string[],\n}\n```\n\n#### Checks\n\n* `engine` – will check that the installed modules comply with the [engines requirements](https://docs.npmjs.com/files/package.json#engines) of the `package.json` and suggest an alternative requirement if the installed modules don't comply.\n* `peer` – like `engine` but for `peerDependencies` instead. Will check that the promised `peerDependencies` are not wider than those of ones required dependencies.\n* `version` – will check that the installed modules comply with the version requirements set for them the `package.json`.\n\n#### Lookup options\n\nThe same as from [`read-workspaces`](https://github.com/voxpelli/read-workspaces?tab=readme-ov-file#readworkspacesoptions) / [`list-installed`](https://github.com/voxpelli/list-installed?tab=readme-ov-file#workspacelookupoptions)\n\n#### Options\n\n* `fix = false` – when set it will modify the `package.json` files to apply fixes whenever possible\n* `ignores = string[]` – names of modules to exclude from checks. Supports [`picomatch`](https://www.npmjs.com/package/picomatch) globbing syntax, eg. `@types/*`. (Not supported by `version` checks)\n* `noDev = false` – exclude `devDependencies` from checks. `devDependencies` that are also in `peerDependencies` will not be ignored. (Not supported by `version` checks)\n* `strict = false` – converts most warnings into failures\n\n#### Example\n\n```javascript\nimport { installedCheck } from 'installed-check-core';\n\nconst { errors, warnings, suggestions } = await installedCheck(['engine', 'version'], {\n  cwd: 'path/to/module',\n  ignore: ['foo'],\n  noDev: true,\n});\n```\n\n### performInstalledCheck()\n\nSimilar to [`installedCheck()`](#installedcheck) but expects to be given package data instead of looking it up itself..\n\n#### Syntax\n\n```ts\nperformInstalledCheck(checks, pkg, installed, options) =\u003e Promise\u003cPerformInstalledCheckResult\u003e\n```\n\n#### Arguments\n\n* `checks`: Type `InstalledChecks[]` – same as for [`installedCheck()`](#installedcheck)\n* `pkg`: Type [`PackageJsonLike`](#packagejsonlike) – the content of the `package.json` file to check\n* `installed`: Type [`InstalledDependencies`](#installeddependencies) – the `package.json` files of the installed dependencies\n* `options`: Type `InstalledCheckOptions` – same as for [`installedCheck()`](#installedcheck), but without the `cwd` option\n\n## Types\n\n### PackageJsonLike\n\n```ts\n// Subset of import('type-fest').PackageJson / import('read-pkg').NormalizedPackageJson\nexport type PackageJsonLike = {\n  name?:    string | undefined;\n  version?: string | undefined;\n  engines?:              Record\u003cstring, string | undefined\u003e;\n  dependencies?:         Record\u003cstring, string | undefined\u003e;\n  devDependencies?:      Record\u003cstring, string | undefined\u003e;\n  optionalDependencies?: Record\u003cstring, string | undefined\u003e;\n  peerDependencies?:     Record\u003cstring, string | undefined\u003e;\n};\n```\n\n### InstalledDependencies\n\n```ts\n// A map is allowed since that's what import('list-installed).listInstalled returns\nexport type InstalledDependencies = Map\u003cstring, PackageJsonLike\u003e | Record\u003cstring, PackageJsonLike\u003e;\n```\n\n## Used by\n\n* Used by the [`installed-check`](https://github.com/voxpelli/node-installed-check) CLI tool\n  * ...and eg. pretty much all of my ([@voxpelli](https://github.com/voxpelli)'s) node.js projects uses the `installed-check` CLI tool\n* Find more on [GitHub](https://github.com/voxpelli/node-installed-check-core/network/dependents) or [npm](https://www.npmjs.com/package/installed-check-core?activeTab=dependents)\n\n## Similar modules\n\n* [`knip`](https://github.com/webpro/knip) – finds unused files, dependencies and exports in your JavaScript and TypeScript projects – a great companion module to `installed-check`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoxpelli%2Fnode-installed-check-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoxpelli%2Fnode-installed-check-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoxpelli%2Fnode-installed-check-core/lists"}