Skip to content

Instantly share code, notes, and snippets.

@mikaello
Last active February 28, 2024 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaello/9f73c30ca40823fc93bb574fab66d969 to your computer and use it in GitHub Desktop.
Save mikaello/9f73c30ca40823fc93bb574fab66d969 to your computer and use it in GitHub Desktop.
Install NPM dependencies in package.json globally
/**
* It is not possible to install a package.json globally with NPM natively, so this script
* fascilitates such a workflow. This could be handy if you wan't e.g. Renovate to maintain the
* versions in the package.json.
*/
import { execSync } from "child_process";
import fs from "fs";
const packageJson = JSON.parse(fs.readFileSync("package.json"));
let dependencies = Object.entries(packageJson.dependencies);
for (let [dependency, version] of dependencies) {
console.log(`Installing: ${dependency}@${version} globally`);
execSync(`npm install -g ${dependency}@${version}`, { stdio: "inherit" });
}
{
"name": "ajv-dependencies",
"version": "1.0.0",
"dependencies": {
"ajv": "8.12.0",
"ajv-cli": "5.0.0",
"ajv-formats": "2.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment