Engine-version - npm package that will allow you to set the correct development environment

Some projects often require specific versions of locally installed programs. It can be either a specific version of node.js or npm (for example, npm @ 7 with workspaces support), or a specific database, package manager, and other utilities that cannot be installed from npm . I often commit the commands to the chats, readme or wiki.

npm allows you to declare the required versions of node and npm in the package.json file , but does not check them in any way. To fix this and expand the list of tools, a small npm package engine-version was written . The package works very simply: first, it reads the description of the required software from package.json , and then looks whether the program is installed and whether the installed version matches the one described. And if the checks fail, a list of errors is displayed.

To start using the package, you must first install the package from npm :

npm install --save-dev engine-version

Describe the list of required tools in package.json ( description format ) :

{
  ...
  "engines": {
    "node": ">=16.0.0",
    "npm": "~7.0.0",
    "mysql": "*"
  },
  ...
}

Add a script that triggers the check in package.json , for example, before the package build process:

{
  ...
  "scripts": {
    "prebuild": "engine-version",
    "build": "my_build_script"
  },
  ...
}
  

Further it is planned to do:

  • Make mistakes more informative

  • Configurable with arguments (warnings instead of errors)

  • Add alternative types of version checking for popular programs that do not understand the --version argument (now the installed version is checked by calling the program with the --version option in the child process)




All Articles