Shamaayil Ahmed

Shamaayil Ahmed

NPM CLI 7 dev release is out now!

NPM CLI 7 dev release is out now!

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Exploring npm cli 7 features, includes workspaces, peer dependencies, package and yarn lock files, etc.

NPM?

NPM is the node javascript platform package manager, which places modules inorder so that node could find them with out any conflicts.

Most commonly, it is used to publish, discover, install, and develop node programs.

We don't really have to reinvent the wheel make use of what's out there

npm init //navigate to project folder and you're good to install dependencies

Version 7 update

npm@7.0.0 was avail as opt-in on October, but has now been promoted to “development” version. Installation instructions can be found on GitHub.

npm 7 is quite a major release, which includes many new features:

  • Workspace support
  • Automatic installation
  • npx changed
  • npm CLI command changes
  • Package and yarn lock files enhancement

Let’s go into details to explore what they are and how to use them.

Workspace support

Major and long-requested feature to look past in npm 7, which supports a method to manage multiple packages from within a singular top-level root package (i.e node_modules).

Potentially, workspaces can drastically improve the performance and memory usage of large combined projects with multiple shared dependencies.

Here the "workspace-01" represented within workspaces array is completely a different directory.

package.json

{
  "name": "npm7",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "workspaces": [
    "workspace-01"
  ]
}

Automatic installation

Automatic installing of peer dependencies, via Arborists deduplication algorithm to ensure that a matching dependency is found at or above the peer-dependent’s location in the node_module’s tree.

npx changed

No more npx with npm 7.

npx has been completely rewritten to use the npm exec command. There are various changes in functionality. Most noticeable one is a prompt if the module you are trying to run is not yet installed.

npm command lines

There are more modified npm CLI commands, such as npm fund, npm pack, npm publish, npm test, etc.

Package and yarn lock files enhancement

With npm 7, package.json files are no longer mutated to include extra metadata. Instead, the extra metadata are stored in lock files.

In package.lock.json the version changes and with a lot more details with in the files.

{
...
"lockfileVersion":2,
...
}

Let's connect 🔗

Catch me here 👇


Hope you all liked the post, share your impressions and queries below 🙌

 
Share this