Last active
March 22, 2016 04:48
-
-
Save tlrobinson/d7ab970a10a5c3c81cf5 to your computer and use it in GitHub Desktop.
Bring sanity to npm 2's shrinkwrap. Makes "npm shrinkwrap" deterministic. Similar but simpler than Uber's npm-shrinkwrap. From https://github.com/metabase/metabase/blob/master/bin/clean-shrinkwrap
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
#!/usr/bin/env node | |
var fs = require('fs'); | |
function clean(module) { | |
// remove module.from | |
delete module.from; | |
// remove module.resolved unless it points to a git repo | |
if (module.resolved && module.resolved.indexOf("https://registry.npmjs.org/") === 0) { | |
delete module.resolved; | |
} | |
// sort module.dependencies keys, and recursively clean them | |
if (module.dependencies) { | |
module.dependencies = Object.keys(module.dependencies).sort().reduce(function(deps, name) { | |
deps[name] = clean(module.dependencies[name]); | |
return deps; | |
}, {}); | |
} | |
return module; | |
} | |
var path = require('path').join(__dirname, '..', 'npm-shrinkwrap.json'); | |
fs.writeFileSync(path, JSON.stringify(clean(JSON.parse(fs.readFileSync(path))), null, 2) + "\n"); |
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
{ | |
... | |
"scripts": { | |
"shrinkwrap": "npm prune && npm shrinkwrap --dev && ./bin/clean-shrinkwrap.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment