Reputation: 383
I am looking for best solution how to install npm package without it's dependencies described in it's package.json file.
The goal is to change dependencies versions before install package. I can do it manually for one package by downloading source, but if you have many nested dependencies it becomes a problem.
Upvotes: 8
Views: 11997
Reputation: 16915
I adapted the script from mxcl to handle scoped packages (@user/package)
#!/bin/sh
# filename suggestion: `npm-i-no-deps`
while [ $# -gt 0 ]
do
package="$1"
version=$(npm show ${package} version)
mkdir -p "node_modules/${package}"
echo "Installing ${package}-${version}"
packagename=$(echo $package | sed 's/@.*\///g')
curl --silent "https://registry.npmjs.org/${package}/-/${packagename}-${version}.tgz" | tar xz --strip-components 1 -C "node_modules/${package}"
shift
done
Warning: mac has a weird version of sed, it should work but I can't guarantee.
Upvotes: 0
Reputation: 26883
I supplemented the above script to allow the specification of multiple packages, avoid the temporary downloaded file and to install the packages straight to node_modules
:
#!/bin/sh
# filename suggestion: `npm-i-no-deps`
while [ $# -gt 0 ]
do
package="$1"
version=$(npm show ${package} version)
mkdir -p "node_modules/${package}"
echo "Installing ${package}-${version}"
curl --silent "https://registry.npmjs.org/${package}/-/${package}-${version}.tgz" | tar xz --strip-components 1 -C "node_modules/${package}"
shift
done
I found this script useful for situations where dependencies are too strict with their dependency requirements, you can install deps you know work ok without adding them to your package.json
until the upstream dependency is updated.
Upvotes: 0
Reputation: 10514
Please check simialr quesition on stackexchange: https://unix.stackexchange.com/questions/168034/is-there-an-option-to-install-an-npm-package-without-dependencies
My solution was to rename package.json to package.bak before the install, then reverting rename afterwards:
RENAME package.json package.bak
npm install <package_name> --no-save
RENAME package.bak package.json
Upvotes: 2
Reputation: 146014
Here's a shell script that seems to get you the extracted files you need.
#!/bin/bash
package="$1"
version=$(npm show ${package} version)
archive="${package}-${version}.tgz"
curl --silent --remote-name \
"https://registry.npmjs.org/${package}/-/${archive}"
mkdir "${package}"
tar xzf "${archive}" --strip-components 1 -C "${package}"
rm "${archive}"
Save it as npm_download.sh
and run it with the name of the package you want:
./npm_download.sh pathval
Upvotes: 10