Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can dependencies be included when using npm cache add?

Tags:

node.js

npm

The goal is to only populate the npm cache. This goal arises from the need to prime restrictive build environments without access to an npm registry after initial setup.

Is there a way to make npm cache add <name>@<version> include dependencies?

For example:

  1. npm cache add [email protected] creates only karma in the cache folder
  2. npm install [email protected];rm -rf node_modules creates karma and all its dependencies in the cache folder but requires removal of locally installed node_modules

In example two, executing npm install [email protected] --no-registry works without issue as hoped. Is it possible to avoid the extra steps of creating and then deleting local node_modules in order to populate the cache?

like image 563
Michael Allan Jackson Avatar asked Oct 20 '22 13:10

Michael Allan Jackson


1 Answers

  1. Generate npm-shrinkwrap.json: npm shrinkwrap --dev

  2. Install and execute cache-shrinkwrap

  3. Delete resolved keys from shrinkwrap.json

  4. Add npm-shrinkwrap.json to source control with your project to guarantee only cached versions will be requested when npm install --no-registry is executed in the future.

like image 136
Michael Allan Jackson Avatar answered Oct 30 '22 02:10

Michael Allan Jackson