Skip to content

Instantly share code, notes, and snippets.

@horatio-sans-serif
Last active March 27, 2019 20:26
Show Gist options
  • Select an option

  • Save horatio-sans-serif/170646d403ff6be0606ed9c8025aef2b to your computer and use it in GitHub Desktop.

Select an option

Save horatio-sans-serif/170646d403ff6be0606ed9c8025aef2b to your computer and use it in GitHub Desktop.
Install Node.js packages from NPM for any referenced package in JavaScript under current directory
#!/bin/bash
set -eu
trap 'rm -f .all .used' 0 1 2 3 6 9 15
curl -s https://raw.githubusercontent.com/sindresorhus/builtin-modules/master/builtin-modules.json | jq -c '.[]' | sed -e 's/"//g' > .all
ack --js -h "require\('([^']+)'" --output '$1' | egrep -v '^\.' | sort -u > .used
npm i -S $(grep -Fvxf .all .used)
@horatio-sans-serif
Copy link
Copy Markdown
Author

assumes you have ack, jq, and npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment