meta_package_manager.managers.npm

class meta_package_manager.managers.npm.NPM[source]

Bases: meta_package_manager.base.PackageManager

platforms = frozenset({'linux', 'macos', 'windows'})
requirement = '4.0.0'
name = "Node's npm"
get_version()[source]

Fetch version from npm --version output.

Raw CLI output samples:

$ npm --version
6.13.7
installed

Fetch installed packages from npm list output.

Raw CLI output samples:

$ npm list -g --json | jq
{
  "dependencies": {
    "npm": {
      "version": "4.0.5",
      "dependencies": {
        "JSONStream": {
          "version": "1.2.1",
          "from": "JSONStream@latest",
          "resolved": "https://(...)/JSONStream-1.2.1.tgz",
          "dependencies": {
            "jsonparse": {
              "version": "1.2.0",
              "from": "jsonparse@>=1.2.0 <2.0.0",
              "resolved": "https://(...)/jsonparse-1.2.0.tgz"
            },
            "through": {
              "version": "2.3.8",
              "from": "through@>=2.2.7 <3.0.0",
              "resolved": "https://(...)/through-2.3.8.tgz"
            }
          }
        },
        "abbrev": {
          "version": "1.0.9",
          "from": "abbrev@1.0.9",
          "resolved": "https://(...)/abbrev-1.0.9.tgz"
        },
        "ansi-regex": {
          "version": "2.0.0",
          "from": "ansi-regex@2.0.0",
          "resolved": "https://(...)/ansi-regex-2.0.0.tgz"
        },
(...)
search(query, extended, exact)[source]

Fetch matching packages from npm search output.

Doc: https://docs.npmjs.com/cli/search.html

$ npm search python --json | jq
[
  {
    "name": "python",
    "description": "Interact with a python child process",
    "maintainers": [
      {
        "username": "drderidder",
        "email": "drderidder@gmail.com"
      }
    ],
    "version": "0.0.4",
    "date": "2015-01-25T02:48:07.820Z"
  },
  {
    "name": "raven",
    "description": "A standalone (Node.js) client for Sentry",
    "maintainers": [
      {
        "username": "benvinegar",
        "email": "ben@benv.ca"
      },
      {
        "username": "lewisjellis",
        "email": "me@lewisjellis.com"
      },
      {
        "username": "mattrobenolt",
        "email": "m@robenolt.com"
      },
      {
        "username": "zeeg",
        "email": "dcramer@gmail.com"
      }
    ],
    "keywords": [
      "raven",
      "sentry",
      "python",
      "errors",
      "debugging",
      "exceptions"
    ],
    "version": "1.1.2",
    "date": "2017-02-09T02:54:07.723Z"
  },
  {
    "name": "brush-python",
    "description": "Python brush module for SyntaxHighlighter.",
    "maintainers": [
      {
        "username": "alexgorbatchev",
        "email": "alex.gorbatchev@gmail.com"
      }
    ],
    "keywords": [
      "syntaxhighlighter",
      "brush",
      "python"
    ],
    "version": "4.0.0",
    "date": "2016-02-07T21:32:39.597Z"
  },
  (...)
]
outdated

Fetch outdated packages from npm outdated output.

Raw CLI output samples:

$ npm -g --progress=false --json outdated
{
  "my-linked-package": {
    "current": "0.0.0-development",
    "wanted": "linked",
    "latest": "linked",
    "location": "/Users/..."
  },
  "npm": {
    "current": "3.10.3",
    "wanted": "3.10.5",
    "latest": "3.10.5",
    "location": "/Users/..."
  }
}
upgrade_cli(package_id=None, version=None)[source]

Return a bash-compatible full-CLI to upgrade a package.

upgrade_all_cli()[source]

Return a bash-compatible full-CLI to upgrade all packages.