Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 18, 2019 04:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/0547571e778beb4710a1114ff5f61d8b to your computer and use it in GitHub Desktop.
Save isaacs/0547571e778beb4710a1114ff5f61d8b to your computer and use it in GitHub Desktop.
// usage: put this in your package.json
// "scripts": {
// "prepublishOnly": "node prune-dev.js",
// "postpublish": "git checkout npm-shrinkwrap.json"
// }
const prune = sw => {
if (sw.dependencies) {
for (const [name, dep] of Object.entries(sw.dependencies)) {
if (dep.dev)
delete sw.dependencies[name]
}
if (!Object.keys(sw.dependencies).length)
delete sw.dependencies
}
return sw
}
const f = 'npm-shrinkwrap.json'
const fs = require('fs')
const sw = JSON.parse(fs.readFileSync(f, 'utf8'))
prune(sw)
fs.writeFileSync(f, JSON.stringify(, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment