Skip to content

Instantly share code, notes, and snippets.

@aharris
Forked from kentcdodds/package-exact.js
Last active June 12, 2018 15:26
Show Gist options
  • Save aharris/8066f64c044b23f893b1728fb710af4c to your computer and use it in GitHub Desktop.
Save aharris/8066f64c044b23f893b1728fb710af4c to your computer and use it in GitHub Desktop.
make your package.json dependencies be the exact version that's in your node_modules currently
/* jshint node:true */
/* eslint-env node */
/*
* This will look at the current version of all of your dependencies and update your package.json
* with the specific version that you currently have in node_modules. This will save you from the
* sadness that is: DEPENDENCY MANAGEMENT
*
* Place this file at the same level as your package.json and node_modules
* Then simply run: node ./package-strict
*
*
* When you're ready to update dependencies, I recommend https://github.com/bahmutov/next-update
*/
const fs = require('fs');
const path = require('path');
const packageJson = require('./package.json');
strictifyDeps('dependencies');
strictifyDeps('devDependencies');
strictifyDeps('peerDependencies');
console.log('done!');
function strictifyDeps(depsProperty) {
const deps = Object.keys(packageJson[depsProperty]);
deps.forEach(function(dep) {
var depPackageJson = require('./node_modules/' + dep + '/package.json');
packageJson[depsProperty][dep] = depPackageJson.version;
});
fs.writeFileSync(path.resolve(__dirname, './package.json'), JSON.stringify(packageJson, null, 2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment