Last active
February 28, 2024 14:07
-
-
Save mikaello/9f73c30ca40823fc93bb574fab66d969 to your computer and use it in GitHub Desktop.
Install NPM dependencies in package.json globally
This file contains hidden or 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
/** | |
* 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" }); | |
} |
This file contains hidden or 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
{ | |
"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