Skip to content

Instantly share code, notes, and snippets.

@jhenriquez
Last active February 26, 2020 15:41
Show Gist options
  • Save jhenriquez/699125282da8a54398d36bc9758be3d2 to your computer and use it in GitHub Desktop.
Save jhenriquez/699125282da8a54398d36bc9758be3d2 to your computer and use it in GitHub Desktop.
Navigates the package.json dependencies and re-install them with exact version. Update and pin all current dependencies.
const Packages = require('./package.json');
const execPromise = (cmd) => new Promise((resolve) => {
require('child_process').exec(cmd, (error, stdout, stderr) => {
if (error) {
console.warn(error);
}
resolve(error ? `${cmd} failed with error: \n${stderr}\n` : `${cmd} completed.`);
});
});
const installDependency = (name, dev = false) => {
console.log(`npm install ${dev ? '-D' : ''} -E ${name}`);
return execPromise(`npm install ${dev ? '-D' : ''} -E ${name}`);
}
(async () => {
const devDependencies = Packages.devDependencies || {};
const dependencies = Packages.dependencies || {};
console.log(`Installing dev dependencies...`);
console.log(await installDependency(Object.keys(devDependencies).join(' '), true));
console.log(`Installing prod dependencies: ${dep}`);
console.log(await installDependency(Object.keys(dependencies).join(' ')));
})();
@jhenriquez
Copy link
Author

Inspired from: https://gist.github.com/kentcdodds/e3f79584d7f255fbcf29

The main difference here is this will have npm do one final installation/update before pining the dependencies.

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