Created
December 18, 2019 04:11
-
-
Save isaacs/0547571e778beb4710a1114ff5f61d8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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